]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iplink: add support for parent device
authorSergey Ryazanov <ryazanov.s.a@gmail.com>
Tue, 22 Jun 2021 23:52:55 +0000 (02:52 +0300)
committerDavid Ahern <dsahern@kernel.org>
Sat, 26 Jun 2021 04:40:22 +0000 (04:40 +0000)
Add support for specifying a parent device (struct device) by its name
during the link creation and printing parent name in the links list.
This option will be used to create WWAN links and possibly by other
device classes that do not have a "natural parent netdev".

Add the parent device bus name printing for links list info
completeness. But do not add a corresponding command line argument, as
we do not have a use case for this attribute.

Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipaddress.c
ip/iplink.c

index 06ca7273c531ef81e8699d2d2b1599e38f096810..85534aaf59898f637f2762252bb4a6cec7f5496d 100644 (file)
@@ -1242,6 +1242,20 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
                                                   RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]),
                                                   b1, sizeof(b1)));
                }
+
+               if (tb[IFLA_PARENT_DEV_BUS_NAME]) {
+                       print_string(PRINT_ANY,
+                                    "parentbus",
+                                    "parentbus %s ",
+                                    rta_getattr_str(tb[IFLA_PARENT_DEV_BUS_NAME]));
+               }
+
+               if (tb[IFLA_PARENT_DEV_NAME]) {
+                       print_string(PRINT_ANY,
+                                    "parentdev",
+                                    "parentdev %s ",
+                                    rta_getattr_str(tb[IFLA_PARENT_DEV_NAME]));
+               }
        }
 
        if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
index faafd7e89d6c1cf4350bfcd4e23186afe2d268f5..33b7be301434edd9eb10868dddf2c115490adacc 100644 (file)
@@ -63,7 +63,7 @@ void iplink_usage(void)
 {
        if (iplink_have_newlink()) {
                fprintf(stderr,
-                       "Usage: ip link add [link DEV] [ name ] NAME\n"
+                       "Usage: ip link add [link DEV | parentdev NAME] [ name ] NAME\n"
                        "                   [ txqueuelen PACKETS ]\n"
                        "                   [ address LLADDR ]\n"
                        "                   [ broadcast LLADDR ]\n"
@@ -938,6 +938,10 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
                                       *argv);
                        addattr32(&req->n, sizeof(*req),
                                  IFLA_GSO_MAX_SEGS, max_segs);
+               } else if (strcmp(*argv, "parentdev") == 0) {
+                       NEXT_ARG();
+                       addattr_l(&req->n, sizeof(*req), IFLA_PARENT_DEV_NAME,
+                                 *argv, strlen(*argv) + 1);
                } else {
                        if (matches(*argv, "help") == 0)
                                usage();