From: David Ahern <dsahern@gmail.com>
To: Stephen Hemminger <stephen@networkplumber.org>, dsahern@kernel.org
Cc: netdev@vger.kernel.org, roopa@cumulusnetworks.com,
sharpd@cumulusnetworks.com, idosch@mellanox.com,
davem@davemloft.net
Subject: Re: [PATCH iproute2-next] ip: Add support for nexthop objects
Date: Tue, 4 Sep 2018 09:30:56 -0600 [thread overview]
Message-ID: <f6eefabb-fc06-67ce-1e3b-68aab82ff06e@gmail.com> (raw)
In-Reply-To: <20180901133753.57f96edd@xeon-e3>
On 9/1/18 2:37 PM, Stephen Hemminger wrote:
>> diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h
>> new file mode 100644
>> index 000000000000..335182e8229a
>> --- /dev/null
>> +++ b/include/uapi/linux/nexthop.h
>> @@ -0,0 +1,56 @@
>> +#ifndef __LINUX_NEXTHOP_H
>> +#define __LINUX_NEXTHOP_H
>> +
>> +#include <linux/types.h>
>> +
>> +struct nhmsg {
>> + unsigned char nh_family;
>> + unsigned char nh_scope; /* one of RT_SCOPE */
>> + unsigned char nh_protocol; /* Routing protocol that installed nh */
>> + unsigned char resvd;
>> + unsigned int nh_flags; /* RTNH_F flags */
>> +};
>
> Why not use __u8 and __u32 for these?
I want consistency with rtmsg on which nhmsg is based and has many
parallels.
>
>> +struct nexthop_grp {
>> + __u32 id;
>> + __u32 weight;
>> +};
>> +
>> +enum {
>> + NEXTHOP_GRP_TYPE_MPATH, /* default type if not specified */
>> + __NEXTHOP_GRP_TYPE_MAX,
>> +};
>> +
>> +#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
>> +
>> +
>> +/* NHA_ID 32-bit id for nexthop. id must be greater than 0.
>> + * id == 0 means assign an unused id.
>> + */
>
> Don't use dave's preferred comment style in this file.
> The reset of the file uses standard comments.
The file will eventually come from the kernel via header sync, so I have
to stick to whatever style is appropriate for the uapi files.
>> diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
>> new file mode 100644
>> index 000000000000..9fa4b7292426
>> --- /dev/null
>> +++ b/ip/ipnexthop.c
>> @@ -0,0 +1,652 @@
>> +/*
>> + * ip nexthop
>> + *
>> + * Copyright (C) 2017 Cumulus Networks
>> + * Copyright (c) 2017 David Ahern <dsa@cumulusnetworks.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + */
>>
>
> Please use SPDX and not GPL boilerplate in new files.
yes, the file pre-dates SPDX. Need to do the same with the kernel side
files.
>
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +#include <unistd.h>
>> +#include <string.h>
>> +#include <sys/socket.h>
>> +#include <netinet/in.h>
>> +#include <netinet/ip.h>
>> +#include <errno.h>
>> +#include <linux/nexthop.h>
>> +#include <libmnl/libmnl.h>
>
> Is this code really using libmnl?
no. need to fix. The iproute2 patch was only added for the RFC so people
could try out the UAPI which is the point of the RFC.
>> + if (!num || num * sizeof(*nhg) != RTA_PAYLOAD(grps_attr)) {
>> + fprintf(fp, "<invalid nexthop group>");
>> + return;
>> + }
>> +
>> + if (gtype)
>> + group_type = rta_getattr_u16(gtype);
>> +
>> + if (is_json_context()) {
>> + open_json_array(PRINT_JSON, "group");
>> + for (i = 0; i < num; ++i) {
>> + open_json_object(NULL);
>> + print_uint(PRINT_ANY, "id", "id %u ", nhg[i].id);
>> + print_uint(PRINT_ANY, "weight", "weight %u ", nhg[i].weight);
>> + close_json_object();
>> + }
>> + close_json_array(PRINT_JSON, NULL);
>> + print_string(PRINT_ANY, "type", "type %s ",
>> + nh_group_type_to_str(group_type, b1, sizeof(b1)));
>> + } else {
>> + fprintf(fp, "group ");
>> + for (i = 0; i < num; ++i) {
>> + if (i)
>> + fprintf(fp, "/");
>> + fprintf(fp, "%u", nhg[i].id);
>> + if (num > 1 && nhg[i].weight > 1)
>> + fprintf(fp, ",%u", nhg[i].weight);
>> + }
>> + }
>> +}
>
> I think this could be done by using json_print cleverly rather than having
> to use is_json_contex(). That would avoid repeating code.
>
> You are only decoding group type in the json version, why not both?
oversight. group type was a recent change.
next prev parent reply other threads:[~2018-09-04 19:56 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-01 0:49 [PATCH RFC net-next 00/18] net: Improve route scalability via support for nexthop objects dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 01/18] net: Rename net/nexthop.h net/rtnh.h dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 02/18] net: ipv4: export fib_good_nh and fib_flush dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 03/18] net/ipv4: export fib_info_update_nh_saddr dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 04/18] net/ipv4: export fib_check_nh dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 05/18] net/ipv4: Define fib_get_nhs when CONFIG_IP_ROUTE_MULTIPATH is disabled dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 06/18] net/ipv4: Create init and release helpers for fib_nh dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 07/18] net: ipv4: Add fib_nh to fib_result dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 08/18] net/ipv4: Move device validation to helper dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 09/18] net/ipv6: Create init and release helpers for fib6_nh dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 10/18] net/ipv6: Make fib6_nh optional at the end of fib6_info dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 11/18] net: Initial nexthop code dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 12/18] net/ipv4: Add nexthop helpers for ipv4 integration dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 13/18] net/ipv4: Convert existing use of fib_info to new helpers dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 14/18] net/ipv4: Allow routes to use nexthop objects dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 15/18] net/ipv6: Use helpers to access fib6_nh data dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 16/18] net/ipv6: Allow routes to use nexthop objects dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 17/18] net: Add support for nexthop groups dsahern
2018-09-01 0:49 ` [PATCH RFC net-next 18/18] net/ipv4: Optimization for fib_info lookup dsahern
2018-09-01 20:43 ` Stephen Hemminger
2018-09-04 15:27 ` David Ahern
2018-09-01 0:49 ` [PATCH iproute2-next] ip: Add support for nexthop objects dsahern
2018-09-01 20:37 ` Stephen Hemminger
2018-09-04 15:30 ` David Ahern [this message]
2018-09-02 17:34 ` [PATCH RFC net-next 00/18] net: Improve route scalability via " David Miller
2018-09-04 15:57 ` David Ahern
2018-12-11 12:52 ` Jan Maria Matejka
2018-12-12 20:27 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6eefabb-fc06-67ce-1e3b-68aab82ff06e@gmail.com \
--to=dsahern@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=idosch@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@cumulusnetworks.com \
--cc=sharpd@cumulusnetworks.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).