]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipaddress.c
Merge branch 'iproute2-master' into iproute2-next
[mirror_iproute2.git] / ip / ipaddress.c
index c94ddba841a0b528d1c2c1d991f617003fb51789..21985a5ee6f3bb28d4a1528f7f29c2deee9fe703 100644 (file)
@@ -240,7 +240,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
                const char *kind
                        = rta_getattr_str(linkinfo[IFLA_INFO_KIND]);
 
-               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_nl();
                print_string(PRINT_ANY, "info_kind", "    %s ", kind);
 
                lu = get_link_kind(kind);
@@ -269,7 +269,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
                const char *slave_kind
                        = rta_getattr_str(linkinfo[IFLA_INFO_SLAVE_KIND]);
 
-               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_nl();
                print_string(PRINT_ANY,
                             "info_slave_kind",
                             "    %s_slave ",
@@ -765,7 +765,7 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
        parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi),
                     n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi)));
        __print_link_stats(fp, tb);
-       fprintf(fp, "%s", _SL_);
+       print_nl();
 }
 
 static int print_linkinfo_brief(FILE *fp, const char *name,
@@ -824,8 +824,7 @@ static void print_link_event(FILE *f, __u32 event)
        }
 }
 
-int print_linkinfo(const struct sockaddr_nl *who,
-                  struct nlmsghdr *n, void *arg)
+int print_linkinfo(struct nlmsghdr *n, void *arg)
 {
        FILE *fp = (FILE *)arg;
        struct ifinfomsg *ifi = NLMSG_DATA(n);
@@ -929,7 +928,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
                print_link_event(fp, rta_getattr_u32(tb[IFLA_EVENT]));
 
        if (!filter.family || filter.family == AF_PACKET || show_details) {
-               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_nl();
                print_string(PRINT_ANY,
                             "link_type",
                             "    link/%s ",
@@ -1090,7 +1089,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
                xdp_dump(fp, tb[IFLA_XDP], true, true);
 
        if (do_link && show_stats) {
-               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_nl();
                __print_link_stats(fp, tb);
        }
 
@@ -1150,7 +1149,7 @@ static unsigned int get_ifa_flags(struct ifaddrmsg *ifa,
 }
 
 /* Mapping from argument to address flag mask */
-struct {
+static const struct {
        const char *name;
        unsigned long value;
 } ifa_flag_names[] = {
@@ -1212,38 +1211,35 @@ static void print_ifa_flags(FILE *fp, const struct ifaddrmsg *ifa,
 
 static int get_filter(const char *arg)
 {
+       bool inv = false;
        unsigned int i;
 
+       if (arg[0] == '-') {
+               inv = true;
+               arg++;
+       }
+
        /* Special cases */
        if (strcmp(arg, "dynamic") == 0) {
-               filter.flags &= ~IFA_F_PERMANENT;
-               filter.flagmask |= IFA_F_PERMANENT;
+               inv = !inv;
+               arg = "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;
+               inv = !inv;
+               arg = "secondary";
+       }
 
-                       filter.flags &= ifa_flag_names[i].value;
-                       filter.flagmask |= ifa_flag_names[i].value;
-                       return 0;
-               }
+       for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+               if (strcmp(arg, ifa_flag_names[i].name))
+                       continue;
 
-               return -1;
-       } else {
-               for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
-                       if (strcmp(arg, ifa_flag_names[i].name))
-                               continue;
+               if (inv)
+                       filter.flags &= ~ifa_flag_names[i].value;
+               else
                        filter.flags |= ifa_flag_names[i].value;
-                       filter.flagmask |= ifa_flag_names[i].value;
-                       return 0;
-               }
-               return -1;
+               filter.flagmask |= ifa_flag_names[i].value;
+               return 0;
        }
-
-       return 0;
+       return -1;
 }
 
 static int ifa_label_match_rta(int ifindex, const struct rtattr *rta)
@@ -1261,8 +1257,7 @@ static int ifa_label_match_rta(int ifindex, const struct rtattr *rta)
        return fnmatch(filter.label, label, 0);
 }
 
-int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
-                  void *arg)
+int print_addrinfo(struct nlmsghdr *n, void *arg)
 {
        FILE *fp = arg;
        struct ifaddrmsg *ifa = NLMSG_DATA(n);
@@ -1418,7 +1413,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
        if (rta_tb[IFA_CACHEINFO]) {
                struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
 
-               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_nl();
                print_string(PRINT_FP, NULL, "       valid_lft ", NULL);
 
                if (ci->ifa_valid == INFINITY_LIFE_TIME) {
@@ -1478,7 +1473,7 @@ static int print_selected_addrinfo(struct ifinfomsg *ifi,
                        continue;
 
                open_json_object(NULL);
-               print_addrinfo(NULL, n, fp);
+               print_addrinfo(n, fp);
                close_json_object();
        }
        close_json_array(PRINT_JSON, NULL);
@@ -1491,8 +1486,7 @@ static int print_selected_addrinfo(struct ifinfomsg *ifi,
 }
 
 
-static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
-                      void *arg)
+static int store_nlmsg(struct nlmsghdr *n, void *arg)
 {
        struct nlmsg_chain *lchain = (struct nlmsg_chain *)arg;
        struct nlmsg_list *h;
@@ -1510,7 +1504,7 @@ static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
                lchain->head = h;
        lchain->tail = h;
 
-       ll_remember_index(who, n, NULL);
+       ll_remember_index(n, NULL);
        return 0;
 }
 
@@ -1553,8 +1547,7 @@ static int ipadd_dump_check_magic(void)
        return 0;
 }
 
-static int save_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
-                      void *arg)
+static int save_nlmsg(struct nlmsghdr *n, void *arg)
 {
        int ret;
 
@@ -1567,15 +1560,14 @@ static int save_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
        return ret == n->nlmsg_len ? 0 : ret;
 }
 
-static int show_handler(const struct sockaddr_nl *nl,
-                       struct rtnl_ctrl_data *ctrl,
+static int show_handler(struct rtnl_ctrl_data *ctrl,
                        struct nlmsghdr *n, void *arg)
 {
        struct ifaddrmsg *ifa = NLMSG_DATA(n);
 
        open_json_object(NULL);
        print_int(PRINT_ANY, "index", "if%d:\n", ifa->ifa_index);
-       print_addrinfo(NULL, n, stdout);
+       print_addrinfo(n, stdout);
        close_json_object();
        return 0;
 }
@@ -1600,8 +1592,7 @@ static int ipaddr_showdump(void)
        exit(err);
 }
 
-static int restore_handler(const struct sockaddr_nl *nl,
-                          struct rtnl_ctrl_data *ctrl,
+static int restore_handler(struct rtnl_ctrl_data *ctrl,
                           struct nlmsghdr *n, void *arg)
 {
        int ret;
@@ -1698,7 +1689,7 @@ static int ipaddr_flush(void)
        filter.flushe = sizeof(flushb);
 
        while ((max_flush_loops == 0) || (round < max_flush_loops)) {
-               if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
+               if (rtnl_addrdump_req(&rth, filter.family) < 0) {
                        perror("Cannot send dump request");
                        exit(1);
                }
@@ -1778,7 +1769,7 @@ static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
 int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
                     struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
 {
-       if (rtnl_wilddump_req_filter_fn(&rth, preferred_family, RTM_GETLINK,
+       if (rtnl_linkdump_req_filter_fn(&rth, preferred_family,
                                        filter_fn) < 0) {
                perror("Cannot send dump request");
                return 1;
@@ -1790,7 +1781,7 @@ int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
        }
 
        if (ainfo) {
-               if (rtnl_wilddump_request(&rth, family, RTM_GETADDR) < 0) {
+               if (rtnl_addrdump_req(&rth, family) < 0) {
                        perror("Cannot send dump request");
                        return 1;
                }
@@ -1915,7 +1906,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                if (ipadd_save_prep())
                        exit(1);
 
-               if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETADDR) < 0) {
+               if (rtnl_addrdump_req(&rth, preferred_family) < 0) {
                        perror("Cannot send dump request");
                        exit(1);
                }
@@ -1940,7 +1931,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(0, filter_dev, RTEXT_FILTER_VF) < 0) {
+               if (iplink_get(filter_dev, RTEXT_FILTER_VF) < 0) {
                        perror("Cannot send link get request");
                        delete_json_obj();
                        exit(1);
@@ -1970,7 +1961,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
 
                open_json_object(NULL);
                if (brief || !no_link)
-                       res = print_linkinfo(NULL, n, stdout);
+                       res = print_linkinfo(n, stdout);
                if (res >= 0 && filter.family != AF_PACKET)
                        print_selected_addrinfo(ifi, ainfo->head, stdout);
                if (res > 0 && !do_link && show_stats)
@@ -2031,7 +2022,7 @@ void ipaddr_get_vf_rate(int vfnum, int *min, int *max, const char *dev)
                exit(1);
        }
 
-       if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETLINK) < 0) {
+       if (rtnl_linkdump_req(&rth, AF_UNSPEC) < 0) {
                perror("Cannot send dump request");
                exit(1);
        }