]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: Support filter links with no VF info
authorrenmingshuai <renmingshuai@huawei.com>
Thu, 11 Apr 2024 02:43:19 +0000 (10:43 +0800)
committerDavid Ahern <dsahern@kernel.org>
Sat, 13 Apr 2024 16:30:07 +0000 (16:30 +0000)
Kernel has add IFLA_EXT_MASK attribute for indicating that certain
extended ifinfo values are requested by the user application. The ip
link show cmd always request VFs extended ifinfo.

In this case, RTM_GETLINK for greater than about 220 VFs truncates
IFLA_VFINFO_LIST due to the maximum reach of nlattr's nla_len being
exceeded. As a result, ip link show command only show the truncated
VFs info sucn as:

    #ip link show dev eth0
    1: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 ...
        link/ether ...
        vf 0     link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff ...
    Truncated VF list: eth0

This patch add novf to support filter links with no VF info:
ip link show novf

v2:
- use an one word option instead of an option with on/off.
- fix the issue that break changes made for the link filter
  already done for VF's.

v3:
- "novf" set vfinfo to 0 and the RTEXT_FILTER_VF flag is not added.

Signed-off-by: Mingshuai Ren <renmingshuai@huawei.com>
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ip_common.h
ip/ipaddress.c
ip/iplink.c
man/man8/ip-link.8.in

index b65c2b41dc8739920a396ee24960f44092f1f31c..d3645a2cd126dd880c17b192b8c62689e6f89992 100644 (file)
@@ -30,6 +30,7 @@ struct link_filter {
        int target_nsid;
        bool have_proto;
        int proto;
+       int vfinfo;
 };
 
 const char *get_ip_lib_dir(void);
index e536912fc603791dc06f4f4188ff1279dec11542..e3cb75418c1fdce6a8c7be20b3bcabe23f723a60 100644 (file)
@@ -2029,10 +2029,11 @@ static int ipaddr_flush(void)
 
 static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
 {
-       __u32 filt_mask;
+       __u32 filt_mask = 0;
        int err;
 
-       filt_mask = RTEXT_FILTER_VF;
+       if (filter.vfinfo)
+               filt_mask |= RTEXT_FILTER_VF;
        if (!show_stats)
                filt_mask |= RTEXT_FILTER_SKIP_STATS;
        err = addattr32(nlh, reqlen, IFLA_EXT_MASK, filt_mask);
@@ -2070,12 +2071,13 @@ static int ipaddr_link_get(int index, struct nlmsg_chain *linfo)
                .i.ifi_family = filter.family,
                .i.ifi_index = index,
        };
-       __u32 filt_mask = RTEXT_FILTER_VF;
+       __u32 filt_mask = 0;
        struct nlmsghdr *answer;
 
+       if (filter.vfinfo)
+               filt_mask |= RTEXT_FILTER_VF;
        if (!show_stats)
                filt_mask |= RTEXT_FILTER_SKIP_STATS;
-
        addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 
        if (rtnl_talk(&rth, &req.n, &answer) < 0) {
@@ -2139,6 +2141,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
        ipaddr_reset_filter(oneline, 0);
        filter.showqueue = 1;
        filter.family = preferred_family;
+       filter.vfinfo = 1;
 
        if (action == IPADD_FLUSH) {
                if (argc <= 0) {
@@ -2221,6 +2224,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                                invarg("\"proto\" value is invalid\n", *argv);
                        filter.have_proto = true;
                        filter.proto = proto;
+               } else if (strcmp(*argv, "novf") == 0) {
+                       filter.vfinfo = 0;
                } else {
                        if (strcmp(*argv, "dev") == 0)
                                NEXT_ARG();
@@ -2274,7 +2279,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
         * the link device
         */
        if (filter_dev && filter.group == -1 && do_link == 1) {
-               if (iplink_get(filter_dev, RTEXT_FILTER_VF) < 0) {
+               if (iplink_get(filter_dev, filter.vfinfo ? RTEXT_FILTER_VF : 0) < 0) {
                        perror("Cannot send link get request");
                        delete_json_obj();
                        exit(1);
index 95314af5ab1c88ec7fb3c517344f3a51c7ac70cf..1bb4a99863b0f4dfee94860b2fe673f4cc6b7fe8 100644 (file)
@@ -111,7 +111,7 @@ void iplink_usage(void)
                "               [ gro_max_size BYTES ] [ gro_ipv4_max_size BYTES ]\n"
                "\n"
                "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n"
-               "               [nomaster]\n"
+               "               [nomaster] [ novf ]\n"
                "\n"
                "       ip link xstats type TYPE [ ARGS ]\n"
                "\n"
index 31e2d7f0f5b81cb6bf23092db69407fc43711b2f..066ad874eb0d6cc1d96f7b489a712a6e8cd0da05 100644 (file)
@@ -202,7 +202,8 @@ ip-link \- network device configuration
 .IR ETYPE " ] ["
 .B vrf
 .IR NAME " ] ["
-.BR nomaster " ]"
+.BR nomaster " ] ["
+.BR novf " ]"
 
 .ti -8
 .B ip link xstats
@@ -2898,6 +2899,10 @@ output.
 .B nomaster
 only show devices with no master
 
+.TP
+.B novf
+only show devices with no VF info
+
 .SS  ip link xstats - display extended statistics
 
 .TP