]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipaddress.c
bpf: consolidate dumps to use bpf_dump_prog_info
[mirror_iproute2.git] / ip / ipaddress.c
index f06f5829fb613700e7fc7d43469bb34c0e967b16..dbdd839cfe495700a245a58a1c69f6a1983b4184 100644 (file)
@@ -18,7 +18,6 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <sys/ioctl.h>
 #include <sys/param.h>
 #include <errno.h>
 #include <netinet/in.h>
@@ -838,7 +837,7 @@ 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_XDP])
-               xdp_dump(fp, tb[IFLA_XDP]);
+               xdp_dump(fp, tb[IFLA_XDP], do_link, false);
        if (tb[IFLA_QDISC])
                fprintf(fp, "qdisc %s ", rta_getattr_str(tb[IFLA_QDISC]));
        if (tb[IFLA_MASTER]) {
@@ -952,12 +951,14 @@ int print_linkinfo(const struct sockaddr_nl *who,
                }
        }
 
-
        if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
                fprintf(fp, "%s    alias %s", _SL_,
                        rta_getattr_str(tb[IFLA_IFALIAS]));
        }
 
+       if ((do_link || show_details) && tb[IFLA_XDP])
+               xdp_dump(fp, tb[IFLA_XDP], true, true);
+
        if (do_link && show_stats) {
                fprintf(fp, "%s", _SL_);
                __print_link_stats(fp, tb);
@@ -1013,14 +1014,95 @@ static unsigned int get_ifa_flags(struct ifaddrmsg *ifa,
                                ifa->ifa_flags;
 }
 
+/* Mapping from argument to address flag mask */
+struct {
+       const char *name;
+       unsigned long value;
+} ifa_flag_names[] = {
+       { "secondary",          IFA_F_SECONDARY },
+       { "temporary",          IFA_F_SECONDARY },
+       { "nodad",              IFA_F_NODAD },
+       { "optimistic",         IFA_F_OPTIMISTIC },
+       { "dadfailed",          IFA_F_DADFAILED },
+       { "home",               IFA_F_HOMEADDRESS },
+       { "deprecated",         IFA_F_DEPRECATED },
+       { "tentative",          IFA_F_TENTATIVE },
+       { "permanent",          IFA_F_PERMANENT },
+       { "mngtmpaddr",         IFA_F_MANAGETEMPADDR },
+       { "noprefixroute",      IFA_F_NOPREFIXROUTE },
+       { "autojoin",           IFA_F_MCAUTOJOIN },
+       { "stable-privacy",     IFA_F_STABLE_PRIVACY },
+};
+
+static void print_ifa_flags(FILE *fp, const struct ifaddrmsg *ifa,
+                           unsigned int flags)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+               unsigned long mask = ifa_flag_names[i].value;
+
+               if (mask == IFA_F_PERMANENT) {
+                       if (!(flags & mask))
+                               fprintf(fp, "dynamic ");
+               } else if (flags & mask) {
+                       if (mask == IFA_F_SECONDARY &&
+                           ifa->ifa_family == AF_INET6)
+                               fprintf(fp, "temporary ");
+                       else
+                               fprintf(fp, "%s ", ifa_flag_names[i].name);
+               }
+
+               flags &= ~mask;
+       }
+
+       if (flags)
+               fprintf(fp, "flags %02x ", flags);
+
+}
+
+static int get_filter(const char *arg)
+{
+       unsigned int i;
+
+       /* Special cases */
+       if (strcmp(arg, "dynamic") == 0) {
+               filter.flags &= ~IFA_F_PERMANENT;
+               filter.flagmask |= IFA_F_PERMANENT;
+       } else if (strcmp(arg, "primary") == 0) {
+               filter.flags &= ~IFA_F_SECONDARY;
+               filter.flagmask |= IFA_F_SECONDARY;
+       } else if (*arg == '-') {
+               for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+                       if (strcmp(arg + 1, ifa_flag_names[i].name))
+                               continue;
+
+                       filter.flags &= ifa_flag_names[i].value;
+                       filter.flagmask |= ifa_flag_names[i].value;
+                       return 0;
+               }
+
+               return -1;
+       } else {
+               for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+                       if (strcmp(arg, ifa_flag_names[i].name))
+                               continue;
+                       filter.flags |= ifa_flag_names[i].value;
+                       filter.flagmask |= ifa_flag_names[i].value;
+                       return 0;
+               }
+               return -1;
+       }
+
+       return 0;
+}
+
 int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
                   void *arg)
 {
        FILE *fp = arg;
        struct ifaddrmsg *ifa = NLMSG_DATA(n);
        int len = n->nlmsg_len;
-       int deprecated = 0;
-       /* Use local copy of ifa_flags to not interfere with filtering code */
        unsigned int ifa_flags;
        struct rtattr *rta_tb[IFA_MAX+1];
 
@@ -1145,52 +1227,9 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
                                              rta_tb[IFA_ANYCAST]));
        }
        fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
-       if (ifa_flags & IFA_F_SECONDARY) {
-               ifa_flags &= ~IFA_F_SECONDARY;
-               if (ifa->ifa_family == AF_INET6)
-                       fprintf(fp, "temporary ");
-               else
-                       fprintf(fp, "secondary ");
-       }
-       if (ifa_flags & IFA_F_TENTATIVE) {
-               ifa_flags &= ~IFA_F_TENTATIVE;
-               fprintf(fp, "tentative ");
-       }
-       if (ifa_flags & IFA_F_DEPRECATED) {
-               ifa_flags &= ~IFA_F_DEPRECATED;
-               deprecated = 1;
-               fprintf(fp, "deprecated ");
-       }
-       if (ifa_flags & IFA_F_HOMEADDRESS) {
-               ifa_flags &= ~IFA_F_HOMEADDRESS;
-               fprintf(fp, "home ");
-       }
-       if (ifa_flags & IFA_F_NODAD) {
-               ifa_flags &= ~IFA_F_NODAD;
-               fprintf(fp, "nodad ");
-       }
-       if (ifa_flags & IFA_F_MANAGETEMPADDR) {
-               ifa_flags &= ~IFA_F_MANAGETEMPADDR;
-               fprintf(fp, "mngtmpaddr ");
-       }
-       if (ifa_flags & IFA_F_NOPREFIXROUTE) {
-               ifa_flags &= ~IFA_F_NOPREFIXROUTE;
-               fprintf(fp, "noprefixroute ");
-       }
-       if (ifa_flags & IFA_F_MCAUTOJOIN) {
-               ifa_flags &= ~IFA_F_MCAUTOJOIN;
-               fprintf(fp, "autojoin ");
-       }
-       if (!(ifa_flags & IFA_F_PERMANENT))
-               fprintf(fp, "dynamic ");
-       else
-               ifa_flags &= ~IFA_F_PERMANENT;
-       if (ifa_flags & IFA_F_DADFAILED) {
-               ifa_flags &= ~IFA_F_DADFAILED;
-               fprintf(fp, "dadfailed ");
-       }
-       if (ifa_flags)
-               fprintf(fp, "flags %02x ", ifa_flags);
+
+       print_ifa_flags(fp, ifa, ifa_flags);
+
        if (rta_tb[IFA_LABEL])
                fprintf(fp, "%s", rta_getattr_str(rta_tb[IFA_LABEL]));
        if (rta_tb[IFA_CACHEINFO]) {
@@ -1206,7 +1245,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
                if (ci->ifa_prefered == INFINITY_LIFE_TIME)
                        fprintf(fp, "forever");
                else {
-                       if (deprecated)
+                       if (ifa_flags & IFA_F_DEPRECATED)
                                fprintf(fp, "%dsec", ci->ifa_prefered);
                        else
                                fprintf(fp, "%usec", ci->ifa_prefered);
@@ -1609,52 +1648,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                        filter.scope = scope;
                } else if (strcmp(*argv, "up") == 0) {
                        filter.up = 1;
-               } else if (strcmp(*argv, "dynamic") == 0) {
-                       filter.flags &= ~IFA_F_PERMANENT;
-                       filter.flagmask |= IFA_F_PERMANENT;
-               } else if (strcmp(*argv, "permanent") == 0) {
-                       filter.flags |= IFA_F_PERMANENT;
-                       filter.flagmask |= IFA_F_PERMANENT;
-               } else if (strcmp(*argv, "secondary") == 0 ||
-                          strcmp(*argv, "temporary") == 0) {
-                       filter.flags |= IFA_F_SECONDARY;
-                       filter.flagmask |= IFA_F_SECONDARY;
-               } else if (strcmp(*argv, "primary") == 0) {
-                       filter.flags &= ~IFA_F_SECONDARY;
-                       filter.flagmask |= IFA_F_SECONDARY;
-               } else if (strcmp(*argv, "tentative") == 0) {
-                       filter.flags |= IFA_F_TENTATIVE;
-                       filter.flagmask |= IFA_F_TENTATIVE;
-               } else if (strcmp(*argv, "-tentative") == 0) {
-                       filter.flags &= ~IFA_F_TENTATIVE;
-                       filter.flagmask |= IFA_F_TENTATIVE;
-               } else if (strcmp(*argv, "deprecated") == 0) {
-                       filter.flags |= IFA_F_DEPRECATED;
-                       filter.flagmask |= IFA_F_DEPRECATED;
-               } else if (strcmp(*argv, "-deprecated") == 0) {
-                       filter.flags &= ~IFA_F_DEPRECATED;
-                       filter.flagmask |= IFA_F_DEPRECATED;
-               } else if (strcmp(*argv, "home") == 0) {
-                       filter.flags |= IFA_F_HOMEADDRESS;
-                       filter.flagmask |= IFA_F_HOMEADDRESS;
-               } else if (strcmp(*argv, "nodad") == 0) {
-                       filter.flags |= IFA_F_NODAD;
-                       filter.flagmask |= IFA_F_NODAD;
-               } else if (strcmp(*argv, "mngtmpaddr") == 0) {
-                       filter.flags |= IFA_F_MANAGETEMPADDR;
-                       filter.flagmask |= IFA_F_MANAGETEMPADDR;
-               } else if (strcmp(*argv, "noprefixroute") == 0) {
-                       filter.flags |= IFA_F_NOPREFIXROUTE;
-                       filter.flagmask |= IFA_F_NOPREFIXROUTE;
-               } else if (strcmp(*argv, "autojoin") == 0) {
-                       filter.flags |= IFA_F_MCAUTOJOIN;
-                       filter.flagmask |= IFA_F_MCAUTOJOIN;
-               } else if (strcmp(*argv, "dadfailed") == 0) {
-                       filter.flags |= IFA_F_DADFAILED;
-                       filter.flagmask |= IFA_F_DADFAILED;
-               } else if (strcmp(*argv, "-dadfailed") == 0) {
-                       filter.flags &= ~IFA_F_DADFAILED;
-                       filter.flagmask |= IFA_F_DADFAILED;
+               } else if (get_filter(*argv) == 0) {
+
                } else if (strcmp(*argv, "label") == 0) {
                        NEXT_ARG();
                        filter.label = *argv;
@@ -1895,7 +1890,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
        char  *lcl_arg = NULL;
        char  *valid_lftp = NULL;
        char  *preferred_lftp = NULL;
-       inet_prefix lcl;
+       inet_prefix lcl = {};
        inet_prefix peer;
        int local_len = 0;
        int peer_len = 0;