From patchwork Tue Jun 22 00:32:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12336177 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAE3AC48BC2 for ; Tue, 22 Jun 2021 00:32:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D23F60FE5 for ; Tue, 22 Jun 2021 00:32:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbhFVAef (ORCPT ); Mon, 21 Jun 2021 20:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbhFVAec (ORCPT ); Mon, 21 Jun 2021 20:34:32 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5286BC061756 for ; Mon, 21 Jun 2021 17:32:16 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id f13so526350ljp.10 for ; Mon, 21 Jun 2021 17:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BA9HGIuc8Qj6/+qoR09OFbEmyF+uxHI8WojZtzgQ3fQ=; b=j6N2riJsV/Jg2O/faRQLc9WhNhoacbI0y7DEXrZ0DkuwsD4ZKW2gAiPzrTbV8OMVTw X22CDHVGMJWoZZEmkEDCRfdpVuzKgF0cuKOVgUmzgwX+xVFnfLpZfH2Gv5o7DM7NpZl8 ckB3nrPhgCRhqCLm7kSqLSUoS/TP8VbLle701CeSWM9a0ywV6HWMfa5DviC46DZqL7lc QgFB9Ze03qRqqVYqnAqSnnzq6+cCslQL230UsIKufsDoHKjzO1vaF2PWPuUDmyklDqnU xyhbuyaEZwPsIvVp4tLUEFAAw27qw/oOEsVVqp2/27TPIUgv15XQlP8FXoJwg+edA+F0 Jj7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BA9HGIuc8Qj6/+qoR09OFbEmyF+uxHI8WojZtzgQ3fQ=; b=XzZdp1FS+u3fl8duwcGqQNjKVQoP3hA2ENZc95ylsDkfMHVT0+PNmEDyFS1Jsq4sCH vc5C99tFYp+GucNidMEVjiFCeqknUZ12dowa+k6V6+AfMoxuD17qIW2bX4aPj7S5do+x XTMKv/g/+Ll1X6CWs1mcPkJrWjE45+W62InVgf45jSsOTxoXMGrrbOQKNsVg5PRKhWV5 +BCZkbZn8cxGB73T6s4xTt/1dSoFbwG0MFlttf3my1DmozOunmWdgJLjkdVKyqCrYc8K +2gdN2VOAtIDYt+p1I0l9/9kSijL8C5LWAuiF4mN8qEBB1IGl7zUheWu4CmilhG4s67S xG3w== X-Gm-Message-State: AOAM532mcLVzTZ/xiYVR6xMLzYgO136CCQi44+Ny4wcNjW/K5q4hFMaV HUlusL+jgowvkaqtEi6Ixdo= X-Google-Smtp-Source: ABdhPJxHEdGF53SD0pH1caTnWVj3CNSAkzzqzd3+8J7QqXJN6/aIKQAkfGpgmbKCiim0FpTXFRhnGA== X-Received: by 2002:a2e:8946:: with SMTP id b6mr698540ljk.99.1624321934710; Mon, 21 Jun 2021 17:32:14 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id br36sm404767lfb.296.2021.06.21.17.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 17:32:14 -0700 (PDT) From: Sergey Ryazanov To: David Ahern , Stephen Hemminger Cc: netdev@vger.kernel.org, Loic Poulain Subject: [PATCH iproute2-next 1/2] iplink: add support for parent device Date: Tue, 22 Jun 2021 03:32:09 +0300 Message-Id: <20210622003210.22765-2-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210622003210.22765-1-ryazanov.s.a@gmail.com> References: <20210622003210.22765-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com 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 --- ip/ipaddress.c | 14 ++++++++++++++ ip/iplink.c | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 06ca7273..7dc38ff1 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -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, + "parentdevbus", + "parentdevbus %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]) { diff --git a/ip/iplink.c b/ip/iplink.c index faafd7e8..33b7be30 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -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(); From patchwork Tue Jun 22 00:32:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12336179 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96CF1C4743C for ; Tue, 22 Jun 2021 00:32:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CDBC61245 for ; Tue, 22 Jun 2021 00:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbhFVAeg (ORCPT ); Mon, 21 Jun 2021 20:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbhFVAed (ORCPT ); Mon, 21 Jun 2021 20:34:33 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79D7CC061574 for ; Mon, 21 Jun 2021 17:32:17 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id d16so25600626lfn.3 for ; Mon, 21 Jun 2021 17:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UYXcSfjCQMkntp4BHtgmpyQaO5twG6KM2+bU91hpi3Q=; b=CBSeX0K7hL1y7JbnSIpDpA8q0FtrDb8r9ogWnDEpN2UiHC4uGGO0WqVtj/cr1AeVKn M6zxWRjCnxS4pQfSa2RL3CQDoyDlUnAYIwP3HkKWPPDp+OvF7GaOseWmB5GsGm22pE/L CW/rzS+4G/60bEOy+C8Yc3LcbznMQhg0N9PhfAYJaWJQyhgKR0xGpUr6YsWx1+32ZFBs 9pg3FZIVoyUYDisaJp5zifpBLJ0SejWfmFhLDQKrkRJanctXbmtAAZNcudk5WRdvoMNx KZQRhvzA9khovSi2XjMQhGegEhY7QtnyGfhGsNyrg3wLXGjyp6nNaqPbrMYtT7W1l5rm sfoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UYXcSfjCQMkntp4BHtgmpyQaO5twG6KM2+bU91hpi3Q=; b=cllhg0MwSsGRJB9ZCOjNl4u7NOy21esMy2JlwKGUL/k82yV1oUqRHggaUAlb3ZNR/c CVXGIVgVu2lCnD2Bs6viQpPGIW71ahNc99uEJtBNmfkDWRPoVtca/M19VBh0tY2QWWhW DwKxwtLjkB+zyNJ07yvFkvY/w0vmQiQAFnHQmN7Y6Cy3Rci+uvOqKRXEX/cTSYrIF43G XWVI2MH4UBnAkf6aA85nK+CXZ+KBBS9vROXRBN3RX8s61Q+EAVfYziTXQuAp4mw9uV+d /1yRoVRX1M5k3kcqDTgLN4LEeJg5CbUZ9FhfgtF1XzZE1JBYQwfCkNalbusbrXjVquYU bH0w== X-Gm-Message-State: AOAM530zMkqAegmIP73u9VEygtfGighPIpLpxs7hpNBLrXtwiVxoSzty kkY3WUKESUB0KNqghmjJ3XgPtoQL36M= X-Google-Smtp-Source: ABdhPJxpZbvqLZY8qOv1zsRGtS6E4d2BwgtPIs0eEVqNOAfgiAodKkISm4Nn9q76b7GUNk+K1CPhhA== X-Received: by 2002:ac2:4ed3:: with SMTP id p19mr716455lfr.256.1624321935865; Mon, 21 Jun 2021 17:32:15 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id br36sm404767lfb.296.2021.06.21.17.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 17:32:15 -0700 (PDT) From: Sergey Ryazanov To: David Ahern , Stephen Hemminger Cc: netdev@vger.kernel.org, Loic Poulain Subject: [PATCH iproute2-next 2/2] iplink: support for WWAN devices Date: Tue, 22 Jun 2021 03:32:10 +0300 Message-Id: <20210622003210.22765-3-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210622003210.22765-1-ryazanov.s.a@gmail.com> References: <20210622003210.22765-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com The WWAN subsystem has been extended to generalize the per data channel network interfaces management. This change implements support for WWAN links handling. And actively uses the earlier introduced ip-link capability to specify the parent by its device name. The WWAN interface for a new data channel should be created with a command like this: ip link add dev wwan0-2 parentdev wwan0 type wwan linkid 2 Where: wwan0 is the modem HW device name (should be taken from /sys/class/wwan) and linkid is an identifier of the opened data channel. Signed-off-by: Sergey Ryazanov --- ip/Makefile | 2 +- ip/iplink.c | 3 +- ip/iplink_wwan.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 ip/iplink_wwan.c diff --git a/ip/Makefile b/ip/Makefile index 4cad619c..b03af29b 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -11,7 +11,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o \ iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \ ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \ - ipnexthop.o ipmptcp.o iplink_bareudp.o + ipnexthop.o ipmptcp.o iplink_bareudp.o iplink_wwan.o RTMONOBJ=rtmon.o diff --git a/ip/iplink.c b/ip/iplink.c index 33b7be30..18b2ea25 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -56,7 +56,8 @@ void iplink_types_usage(void) " ipip | ipoib | ipvlan | ipvtap |\n" " macsec | macvlan | macvtap |\n" " netdevsim | nlmon | rmnet | sit | team | team_slave |\n" - " vcan | veth | vlan | vrf | vti | vxcan | vxlan | xfrm }\n"); + " vcan | veth | vlan | vrf | vti | vxcan | vxlan | wwan |\n" + " xfrm }\n"); } void iplink_usage(void) diff --git a/ip/iplink_wwan.c b/ip/iplink_wwan.c new file mode 100644 index 00000000..3510477a --- /dev/null +++ b/ip/iplink_wwan.c @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include + +#include "utils.h" +#include "ip_common.h" + +static void print_explain(FILE *f) +{ + fprintf(f, + "Usage: ... wwan linkid LINKID\n" + "\n" + "Where: LINKID := 0-4294967295\n" + ); +} + +static void explain(void) +{ + print_explain(stderr); +} + +static int wwan_parse_opt(struct link_util *lu, int argc, char **argv, + struct nlmsghdr *n) +{ + while (argc > 0) { + if (matches(*argv, "linkid") == 0) { + __u32 linkid; + + NEXT_ARG(); + if (get_u32(&linkid, *argv, 0)) + invarg("linkid", *argv); + addattr32(n, 1024, IFLA_WWAN_LINK_ID, linkid); + } else if (matches(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "wwan: unknown command \"%s\"?\n", + *argv); + explain(); + return -1; + } + argc--, argv++; + } + + return 0; +} + +static void wwan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) +{ + if (!tb) + return; + + if (tb[IFLA_WWAN_LINK_ID]) + print_uint(PRINT_ANY, "linkid", "linkid %u ", + rta_getattr_u32(tb[IFLA_WWAN_LINK_ID])); +} + +static void wwan_print_help(struct link_util *lu, int argc, char **argv, + FILE *f) +{ + print_explain(f); +} + +struct link_util wwan_link_util = { + .id = "wwan", + .maxattr = IFLA_WWAN_MAX, + .parse_opt = wwan_parse_opt, + .print_opt = wwan_print_opt, + .print_help = wwan_print_help, +};