]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipaddress.c
ip: link: add support for netdevsim device type
[mirror_iproute2.git] / ip / ipaddress.c
index 201225f74b1de38cad65dd034b095ffe841f7305..c35b6b3f1b10be9e3534376be031d359728a0df6 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <inttypes.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -75,10 +74,11 @@ static void usage(void)
        fprintf(stderr, "CONFFLAG  := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]\n");
        fprintf(stderr, "LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]\n");
        fprintf(stderr, "LFT := forever | SECONDS\n");
-       fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
+       fprintf(stderr, "TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |\n");
        fprintf(stderr, "          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |\n");
-       fprintf(stderr, "          gre | gretap | erspan | ip6gre | ip6gretap | vti | nlmon | can |\n");
-       fprintf(stderr, "          bond_slave | ipvlan | geneve | bridge_slave | vrf | hsr | macsec }\n");
+       fprintf(stderr, "          gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti |\n");
+       fprintf(stderr, "          nlmon | can | bond_slave | ipvlan | geneve | bridge_slave |\n");
+       fprintf(stderr, "          hsr | macsec | netdevsim\n");
 
        exit(-1);
 }
@@ -1146,7 +1146,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
                          "mtu", "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])
                print_string(PRINT_ANY,
                             "qdisc",
@@ -1306,7 +1306,6 @@ int print_linkinfo(const struct sockaddr_nl *who,
                }
        }
 
-
        if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
                print_string(PRINT_FP, NULL, "%s    ", _SL_);
                print_string(PRINT_ANY,
@@ -1315,6 +1314,9 @@ int print_linkinfo(const struct sockaddr_nl *who,
                             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) {
                print_string(PRINT_FP, NULL, "%s", _SL_);
                __print_link_stats(fp, tb);
@@ -1602,7 +1604,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
                                           format_host_rta(ifa->ifa_family,
                                                           rta_tb[IFA_ADDRESS]));
                }
-               print_int(PRINT_ANY, "prefixlen", "/%d", ifa->ifa_prefixlen);
+               print_int(PRINT_ANY, "prefixlen", "/%d ", ifa->ifa_prefixlen);
        }
 
        if (brief)
@@ -1799,17 +1801,31 @@ static int show_handler(const struct sockaddr_nl *nl,
 {
        struct ifaddrmsg *ifa = NLMSG_DATA(n);
 
-       printf("if%d:\n", ifa->ifa_index);
+       open_json_object(NULL);
+       print_int(PRINT_ANY, "index", "if%d:\n", ifa->ifa_index);
        print_addrinfo(NULL, n, stdout);
+       close_json_object();
        return 0;
 }
 
 static int ipaddr_showdump(void)
 {
+       int err;
+
        if (ipadd_dump_check_magic())
                exit(-1);
 
-       exit(rtnl_from_file(stdin, &show_handler, NULL));
+       new_json_obj(json);
+       open_json_object(NULL);
+       open_json_array(PRINT_JSON, "addr_info");
+
+       err = rtnl_from_file(stdin, &show_handler, NULL);
+
+       close_json_array(PRINT_JSON, NULL);
+       close_json_object();
+       delete_json_obj();
+
+       exit(err);
 }
 
 static int restore_handler(const struct sockaddr_nl *nl,
@@ -1822,7 +1838,7 @@ static int restore_handler(const struct sockaddr_nl *nl,
 
        ll_init_map(&rth);
 
-       ret = rtnl_talk(&rth, n, n, sizeof(*n));
+       ret = rtnl_talk(&rth, n, NULL);
        if ((ret < 0) && (errno == EEXIST))
                ret = 0;
 
@@ -2160,7 +2176,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
         * Initialize a json_writer and open an array object
         * if -json was specified.
         */
-       new_json_obj(json, stdout);
+       new_json_obj(json);
 
        /*
         * If only filter_dev present and none of the other
@@ -2518,7 +2534,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
                return -1;
        }
 
-       if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+       if (rtnl_talk(&rth, &req.n, NULL) < 0)
                return -2;
 
        return 0;