From patchwork Thu Jun 3 04:49:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 453788 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.8 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=unavailable 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 87C61C47096 for ; Thu, 3 Jun 2021 04:51:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 706FB60232 for ; Thu, 3 Jun 2021 04:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbhFCExI (ORCPT ); Thu, 3 Jun 2021 00:53:08 -0400 Received: from mail-lj1-f177.google.com ([209.85.208.177]:40532 "EHLO mail-lj1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229867AbhFCExH (ORCPT ); Thu, 3 Jun 2021 00:53:07 -0400 Received: by mail-lj1-f177.google.com with SMTP id u22so5456397ljh.7; Wed, 02 Jun 2021 21:51:09 -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=kYTcTtjZwGkx5E7kMKtJMXD4K6b64JEpdLABcMx78NQ=; b=CE20pSVwKLwe7CY/XHFAmVU/OGPJ1uYvAa5X7lrCRdoABAeS7Je4SFHfTB5NfhsCmW vEONblUWTJXMiT3oxhnPi0xC1/J4f763+SxVwc+oJXixTzglFTG4nx8kgrmjRZMi/2+G PagoyLwd8oPUTmRQO3hnBH0q9e7LjcDheePB48nWthXxMwoQq4OkSbSSz8eR6DlODnnB 2Cg7ky2n8lZDIurXOKzwN1NcHaAjFzDg3I3qrdf5WHXn1qcdLnoWuyGXZnNA52WPsI3i fWkinYm4mbxSfl9M+n8dDxOutUyt0HNKdFoIDqp42hwtkl2WVyTpWml4FRpWxL7eVQMC s7cw== 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=kYTcTtjZwGkx5E7kMKtJMXD4K6b64JEpdLABcMx78NQ=; b=S5VKyaoDFt4rX8b2NO8Dd0MTzxVFaF3fiRNe3SKfTvnXm06aPtZxMHDDGmY3EbpwvO AN+5VSBKM2egDoxh13sLe6oAJZpj1BoiRmw06Y3h+sY82n+kL0nR/lInFWkYnj73dAm/ hGDizP8HnO8gFweBODxCyV4nB2qHNMPSy/pEwX7EC2CumL/O7xKQybqqXQmi4Z6/uVEh NeQzIHgMbU5CWJhtvPRHYhbABwiyxOCwpbfp6gO4lM6JuEau9YFCtWsA16RJ8NemN/5e DWjneOlgx1mMQvoTfRCDOsPEKBU1BvsV06a1qxUacDYHpBAAX3oCO5nxzGZjq9HQoncm 6cHA== X-Gm-Message-State: AOAM53321BaYey4sZH+s7S6blCNfwsvJ0VZQzFgCH6JJIHmlsgTOKi+I 7zzKPDTLJ+wyQLY9y+QShkw= X-Google-Smtp-Source: ABdhPJxjQj5PILjjPSo6RIe5dOO5A4V7v+EFF0penkxLQ28ZVWlzKCeBAf7hMn9J/xVqAazTPq3C4A== X-Received: by 2002:a2e:5cc4:: with SMTP id q187mr5100292ljb.177.1622695808920; Wed, 02 Jun 2021 21:50:08 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id z2sm191328lfe.229.2021.06.02.21.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 21:50:08 -0700 (PDT) From: Sergey Ryazanov To: Johannes Berg , Loic Poulain Cc: M Chetan Kumar , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [RFC 6/6 iproute2] iplink: support for WWAN devices Date: Thu, 3 Jun 2021 07:49:54 +0300 Message-Id: <20210603044954.8091-7-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210603044954.8091-1-ryazanov.s.a@gmail.com> References: <20210603044954.8091-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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-name 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 190ce7d9..4073d6e8 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, +};