From: Stephen Hemminger <stephen@networkplumber.org>
To: roopa@cumulusnetworks.com
Cc: davem@davemloft.net, netdev@vger.kernel.org,
shm@cumulusnetworks.com, nolan@cumulusnetworks.com,
sfeldma@cumulusnetworks.com, jhs@mojatatu.com
Subject: Re: [RFC PATCH iproute2] link dump filter
Date: Mon, 7 Jul 2014 08:49:06 -0700 [thread overview]
Message-ID: <20140707084906.264c6cd3@samsung-9> (raw)
In-Reply-To: <1404428835-21011-1-git-send-email-roopa@cumulusnetworks.com>
On Thu, 3 Jul 2014 16:07:15 -0700
roopa@cumulusnetworks.com wrote:
> From: Roopa Prabhu <roopa@cumulusnetworks.com>
>
> This patch avoids a full link wildump request when the user has specified
> a single link. Uses RTM_GETLINK without the NLM_F_DUMP flag.
>
> This helps on a system with large number of interfaces.
>
> This patch currently only uses the link ifindex in the filter.
> Hoping to provide a subsequent kernel patch to do link dump filtering on
> other attributes in the kernel.
>
> In iplink_get, to be safe, this patch currently sets the answer buffer
> size to the max size that libnetlink rtnl_talk can copy. The current api
> does not seem to provide a way to indicate the answer buf size.
Good, should be same size as all the other buffers.
>
> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
> ---
> ip/ip_common.h | 1 +
> ip/ipaddress.c | 20 +++++++++++++++++---
> ip/iplink.c | 32 ++++++++++++++++++++++++++++++++
> 3 files changed, 50 insertions(+), 3 deletions(-)
>
> diff --git a/ip/ip_common.h b/ip/ip_common.h
> index ac1e4c1..e56d1ac 100644
> --- a/ip/ip_common.h
> +++ b/ip/ip_common.h
> @@ -51,6 +51,7 @@ extern int do_ipl2tp(int argc, char **argv);
> extern int do_tcp_metrics(int argc, char **argv);
> extern int do_ipnetconf(int argc, char **argv);
> extern int do_iptoken(int argc, char **argv);
> +extern int iplink_get(unsigned int flags, char *name, __u32 filt_mask);
>
> static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
> {
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index 8138e86..d111fab 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
> @@ -1241,9 +1241,23 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
> exit(0);
> }
>
> - if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) {
> - perror("Cannot send dump request");
> - exit(1);
> + if (filter_dev && filter.group == -1 && do_link == 1) {
> + /*
> + * If only filter_dev present and none of the other
> + * link filters are present, use RTM_GETLINK to get
> + * the link device
> + */
move comment before if
> + if (iplink_get(0, filter_dev, RTEXT_FILTER_VF) < 0) {
> + perror("Cannot send link get request");
> + exit(1);
> + }
> + exit(0);
> + } else {
Since code always does exit, the else is redundant.
> + if (rtnl_wilddump_request(&rth, preferred_family,
> + RTM_GETLINK) < 0) {
> + perror("Cannot send dump request");
> + exit(1);
> + }
> }
>
> if (rtnl_dump_filter(&rth, store_nlmsg, &linfo) < 0) {
> diff --git a/ip/iplink.c b/ip/iplink.c
> index 0d020ef..7ac2813 100644
> --- a/ip/iplink.c
> +++ b/ip/iplink.c
> @@ -703,6 +703,38 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
> return 0;
> }
>
> +int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
> +{
> + int len;
> + struct iplink_req req;
> + char answer[16384];
> +
> + memset(&req, 0, sizeof(req));
> +
> + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
> + req.n.nlmsg_flags = NLM_F_REQUEST|flags;
> + req.n.nlmsg_type = RTM_GETLINK;
> + req.i.ifi_family = preferred_family;
> +
> + if (name) {
> + len = strlen(name) + 1;
> + if (len == 1)
> + invarg("\"\" is not a valid device identifier\n",
> + "name");
> + if (len > IFNAMSIZ)
> + invarg("\"name\" too long\n", name);
> + addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, len);
> + }
> + addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
> +
> + if (rtnl_talk(&rth, &req.n, 0, 0, (struct nlmsghdr *)answer) < 0)
> + return -2;
> +
> + print_linkinfo(NULL, (struct nlmsghdr *)answer, stdout);
> +
> + return 0;
> +}
> +
> #if IPLINK_IOCTL_COMPAT
> static int get_ctl_fd(void)
> {
prev parent reply other threads:[~2014-07-09 16:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-03 23:07 [RFC PATCH iproute2] link dump filter roopa
2014-07-07 15:49 ` Stephen Hemminger [this message]
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=20140707084906.264c6cd3@samsung-9 \
--to=stephen@networkplumber.org \
--cc=davem@davemloft.net \
--cc=jhs@mojatatu.com \
--cc=netdev@vger.kernel.org \
--cc=nolan@cumulusnetworks.com \
--cc=roopa@cumulusnetworks.com \
--cc=sfeldma@cumulusnetworks.com \
--cc=shm@cumulusnetworks.com \
/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).