]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - bridge/link.c
iplink: Use ll_index_to_name() instead of if_indextoname()
[mirror_iproute2.git] / bridge / link.c
index d3a211ef01dc66b9f00115cc4121ec4b601d3b24..870ebe0504777bdede5d55c4cbfb91a6a048f955 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -25,8 +26,6 @@ static const char *port_states[] = {
        [BR_STATE_BLOCKING] = "blocking",
 };
 
-extern char *if_indextoname(unsigned int __ifindex, char *__ifname);
-
 static void print_link_flags(FILE *fp, unsigned int flags)
 {
        fprintf(fp, "<");
@@ -103,7 +102,6 @@ int print_linkinfo(const struct sockaddr_nl *who,
        int len = n->nlmsg_len;
        struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct rtattr *tb[IFLA_MAX+1];
-       char b1[IFNAMSIZ];
 
        len -= NLMSG_LENGTH(sizeof(*ifi));
        if (len < 0) {
@@ -134,14 +132,10 @@ int print_linkinfo(const struct sockaddr_nl *who,
                print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
 
        if (tb[IFLA_LINK]) {
-               SPRINT_BUF(b1);
                int iflink = rta_getattr_u32(tb[IFLA_LINK]);
 
-               if (iflink == 0)
-                       fprintf(fp, "@NONE: ");
-               else
-                       fprintf(fp, "@%s: ",
-                               if_indextoname(iflink, b1));
+               fprintf(fp, "@%s: ",
+                       iflink ? ll_index_to_name(iflink) : "NONE");
        } else
                fprintf(fp, ": ");
 
@@ -150,9 +144,11 @@ int print_linkinfo(const struct sockaddr_nl *who,
        if (tb[IFLA_MTU])
                fprintf(fp, "mtu %u ", rta_getattr_u32(tb[IFLA_MTU]));
 
-       if (tb[IFLA_MASTER])
-               fprintf(fp, "master %s ",
-                       if_indextoname(rta_getattr_u32(tb[IFLA_MASTER]), b1));
+       if (tb[IFLA_MASTER]) {
+               int master = rta_getattr_u32(tb[IFLA_MASTER]);
+
+               fprintf(fp, "master %s ", ll_index_to_name(master));
+       }
 
        if (tb[IFLA_PROTINFO]) {
                if (tb[IFLA_PROTINFO]->rta_type & NLA_F_NESTED) {
@@ -201,6 +197,9 @@ int print_linkinfo(const struct sockaddr_nl *who,
                                if (prtb[IFLA_BRPORT_NEIGH_SUPPRESS])
                                        print_onoff(fp, "neigh_suppress",
                                                    rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS]));
+                               if (prtb[IFLA_BRPORT_VLAN_TUNNEL])
+                                       print_onoff(fp, "vlan_tunnel",
+                                                   rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL]));
                        }
                } else
                        print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO]));
@@ -216,6 +215,13 @@ int print_linkinfo(const struct sockaddr_nl *who,
 
                if (aftb[IFLA_BRIDGE_MODE])
                        print_hwmode(fp, rta_getattr_u16(aftb[IFLA_BRIDGE_MODE]));
+               if (show_details) {
+                       if (aftb[IFLA_BRIDGE_VLAN_INFO]) {
+                               fprintf(fp, "\n");
+                               print_vlan_info(fp, tb[IFLA_AF_SPEC],
+                                               ifi->ifi_index);
+                       }
+               }
        }
 
        fprintf(fp, "\n");
@@ -234,6 +240,8 @@ static void usage(void)
        fprintf(stderr, "                               [ learning_sync {on | off} ]\n");
        fprintf(stderr, "                               [ flood {on | off} ]\n");
        fprintf(stderr, "                               [ mcast_flood {on | off} ]\n");
+       fprintf(stderr, "                               [ neigh_suppress {on | off} ]\n");
+       fprintf(stderr, "                               [ vlan_tunnel {on | off} ]\n");
        fprintf(stderr, "                               [ hwmode {vepa | veb} ]\n");
        fprintf(stderr, "                               [ self ] [ master ]\n");
        fprintf(stderr, "       bridge link show [dev DEV]\n");
@@ -273,6 +281,7 @@ static int brlink_modify(int argc, char **argv)
        __s8 learning = -1;
        __s8 learning_sync = -1;
        __s8 flood = -1;
+       __s8 vlan_tunnel = -1;
        __s8 mcast_flood = -1;
        __s8 hairpin = -1;
        __s8 bpdu_guard = -1;
@@ -364,6 +373,11 @@ static int brlink_modify(int argc, char **argv)
                        if (!on_off("neigh_suppress", &neigh_suppress,
                                    *argv))
                                return -1;
+               } else if (strcmp(*argv, "vlan_tunnel") == 0) {
+                       NEXT_ARG();
+                       if (!on_off("vlan_tunnel", &vlan_tunnel,
+                                   *argv))
+                               return -1;
                } else {
                        usage();
                }
@@ -419,6 +433,9 @@ static int brlink_modify(int argc, char **argv)
        if (neigh_suppress != -1)
                addattr8(&req.n, sizeof(req), IFLA_BRPORT_NEIGH_SUPPRESS,
                         neigh_suppress);
+       if (vlan_tunnel != -1)
+               addattr8(&req.n, sizeof(req), IFLA_BRPORT_VLAN_TUNNEL,
+                        vlan_tunnel);
 
        addattr_nest_end(&req.n, nest);
 
@@ -439,7 +456,7 @@ static int brlink_modify(int argc, char **argv)
                addattr_nest_end(&req.n, nest);
        }
 
-       if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+       if (rtnl_talk(&rth, &req.n, NULL) < 0)
                return -1;
 
        return 0;
@@ -467,9 +484,19 @@ static int brlink_show(int argc, char **argv)
                }
        }
 
-       if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETLINK) < 0) {
-               perror("Cannon send dump request");
-               exit(1);
+       if (show_details) {
+               if (rtnl_wilddump_req_filter(&rth, PF_BRIDGE, RTM_GETLINK,
+                                            (compress_vlans ?
+                                             RTEXT_FILTER_BRVLAN_COMPRESSED :
+                                             RTEXT_FILTER_BRVLAN)) < 0) {
+                       perror("Cannon send dump request");
+                       exit(1);
+               }
+       } else {
+               if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETLINK) < 0) {
+                       perror("Cannon send dump request");
+                       exit(1);
+               }
        }
 
        if (rtnl_dump_filter(&rth, print_linkinfo, stdout) < 0) {