From: Stephen Hemminger <stephen@networkplumber.org>
To: David Ahern <dsa@cumulusnetworks.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2 1/6] ip vrf: Add name_is_vrf
Date: Wed, 29 Jun 2016 08:06:13 -0700 [thread overview]
Message-ID: <20160629080613.6d368b4f@xeon-e3> (raw)
In-Reply-To: <1467053461-16147-2-git-send-email-dsa@cumulusnetworks.com>
On Mon, 27 Jun 2016 11:50:56 -0700
David Ahern <dsa@cumulusnetworks.com> wrote:
> diff --git a/ip/ip_common.h b/ip/ip_common.h
> index e8da9e034b15..410eb135774a 100644
> --- a/ip/ip_common.h
> +++ b/ip/ip_common.h
> @@ -90,6 +90,8 @@ struct link_util *get_link_slave_kind(const char *slave_kind);
>
> void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
>
> +bool name_is_vrf(char *name);
> +
> #ifndef INFINITY_LIFE_TIME
> #define INFINITY_LIFE_TIME 0xFFFFFFFFU
> #endif
> diff --git a/ip/iplink_vrf.c b/ip/iplink_vrf.c
> index e3c7b4652da5..abd43c08423e 100644
> --- a/ip/iplink_vrf.c
> +++ b/ip/iplink_vrf.c
> @@ -96,3 +96,56 @@ struct link_util vrf_slave_link_util = {
> .print_opt = vrf_slave_print_opt,
> .slave = true,
> };
> +
> +bool name_is_vrf(char *name)
Why not?
bool name_is_vrf(const char *name)
> +{
> + struct {
> + struct nlmsghdr n;
> + struct ifinfomsg i;
> + char buf[1024];
> + } req = {
> + .n = {
> + .nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
> + .nlmsg_flags = NLM_F_REQUEST,
> + .nlmsg_type = RTM_GETLINK,
> + },
> + .i = {
> + .ifi_family = preferred_family,
> + },
> + };
> + struct {
> + struct nlmsghdr n;
> + char buf[8192];
> + } answer;
> + struct rtattr *tb[IFLA_MAX+1];
> + struct rtattr *li[IFLA_INFO_MAX+1];
> + struct ifinfomsg *ifi;
> + int len;
> +
> + addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, strlen(name) + 1);
> +
> + if (rtnl_talk(&rth, &req.n, &answer.n, sizeof(answer)) < 0)
> + goto err;
Just return false instead of all these goto's?
Also you might want to give some indication of error.
> +
> + ifi = NLMSG_DATA(&answer.n);
> + len = answer.n.nlmsg_len - NLMSG_LENGTH(sizeof(*ifi));
> + if (len < 0) {
> + fprintf(stderr, "BUG: Invalid response to link query.\n");
> + goto err;
> + }
> +
> + parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
> +
> + if (!tb[IFLA_LINKINFO])
> + goto err;
> +
> + parse_rtattr_nested(li, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
> +
> + if (!li[IFLA_INFO_KIND])
> + goto err;
> +
> + return strcmp(RTA_DATA(li[IFLA_INFO_KIND]), "vrf") == 0;
> +
> +err:
> + return false;
> +}
next prev parent reply other threads:[~2016-06-29 15:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-27 18:50 [PATCH v2 iproute2 0/6] Add support for vrf keyword David Ahern
2016-06-27 18:50 ` [PATCH iproute2 1/6] ip vrf: Add name_is_vrf David Ahern
2016-06-29 15:06 ` Stephen Hemminger [this message]
2016-06-29 16:57 ` David Ahern
2016-06-27 18:50 ` [PATCH v2 iproute2 2/6] ip link/addr: Add support for vrf keyword David Ahern
2016-06-27 18:50 ` [PATCH iproute2 3/6] ip neigh: Add support for keyword David Ahern
2016-06-27 18:50 ` [PATCH iproute2 4/6] ip route: Change type mask to bitmask David Ahern
2016-06-27 18:51 ` [PATCH iproute2 5/6] ip vrf: Add ipvrf_get_table David Ahern
2016-06-27 18:51 ` [PATCH iproute2 6/6] ip route: Add support for vrf keyword David Ahern
2016-06-29 15:07 ` [PATCH v2 iproute2 0/6] " Stephen Hemminger
2016-06-29 17:06 ` David Ahern
-- strict thread matches above, loose matches on Subject: below --
2016-06-14 20:59 [PATCH " David Ahern
2016-06-14 20:59 ` [PATCH iproute2 1/6] ip vrf: Add name_is_vrf 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=20160629080613.6d368b4f@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=dsa@cumulusnetworks.com \
--cc=netdev@vger.kernel.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).