Skip to contentSkip to conversation

WWAN netdev creation framework tweaks

RFC New Sergey Ryazanov 1 participant 7 messages Jun 3, 2021

Subsystems (3)
lore
Share & tools
lore

Sergey Ryazanov

author maintainer
#0 lore raw

cover WWAN netdev creation framework tweaks

This is a follow-up series to the proposed generic WWAN interface creation framework [1].

The first two patches are small fixes for issues that were spotted during the original code testing. The 3rd patch completes my suggestion to make the parent device attribute (IFLA_PARENT_DEV_NAME) generic by revealing the netdev parent device to userspace using this attribute. The 4th patch was added to make it easier to test iproute2 changes, in fact it just copies the definitions from the kernel headers to iproute2. Finally, 5th and 6th patches provide an example of userspace support for WWAN links management.

At the moment I do not have access to any WWAN hardware, so the code was only lightly tested at runtime.

1. https://lore.kernel.org/netdev/[email protected]

author maintainer
#1 lore raw

RFC 1/6 rtnetlink: fix alloc() method introduction

RTNL checks for the setup() callback existing in a few place as a sanity check. The introduction of the alloc() method makes the setup() method optional. So allow RTNL families that define at least one alloc() or setup() method.

Fixes ???? ("rtnetlink: add alloc() method to rtnl_link_ops")
---
 net/core/rtnetlink.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/rtnetlink.c +3 -3
index 49a27bf6e4a7..56ac16abe0ba 100644
@@ -376,12 +376,12 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
 	if (rtnl_link_ops_get(ops->kind))
 		return -EEXIST;
 
-	/* The check for setup is here because if ops
+	/* The check for alloc/setup is here because if ops
 	 * does not have that filled up, it is not possible
 	 * to use the ops for creating device. So do not
 	 * fill up dellink as well. That disables rtnl_dellink.
 	 */
-	if (ops->setup && !ops->dellink)
+	if ((ops->alloc || ops->setup) && !ops->dellink)
 		ops->dellink = unregister_netdevice_queue;
 
 	list_add_tail(&ops->list, &link_ops);
@@ -3421,7 +3421,7 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 		return -EOPNOTSUPP;
 	}
 
-	if (!ops->setup)
+	if (!ops->alloc && !ops->setup)
 		return -EOPNOTSUPP;
 
 	if (!ifname[0]) {
Signature · 1 line
2.26.3
author maintainer
#2 lore raw

RFC 2/6 wwan: fix module initialization

In reply to Sergey Ryazanov

Recover the successful return from the module initialization function that was accidentally lost during the netdev creation support integration.

Fixes ???? ("wwan: add interface creation support")
---
 drivers/net/wwan/wwan_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wwan/wwan_core.c +2 -1
index e2490c73ac33..32b2096c5036 100644
@@ -737,7 +737,8 @@ static int __init wwan_init(void)
 		goto destroy;
 	}
 
-	err = 0;
+	return 0;
+
 destroy:
 	class_destroy(wwan_class);
 unregister:
Signature · 1 line
2.26.3
author maintainer
#3 lore raw

RFC 3/6 rtnetlink: fill IFLA_PARENT_DEV_NAME on link dump

In reply to Sergey Ryazanov

Return a parent device using the FLA_PARENT_DEV_NAME attribute during links dump. This should help a user figure out which links belong to a particular HW device. E.g. what data channels exists on a specific WWAN modem.

---
 net/core/rtnetlink.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/rtnetlink.c +5 -0
index 56ac16abe0ba..120887c892de 100644
@@ -1819,6 +1819,11 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	if (rtnl_fill_prop_list(skb, dev))
 		goto nla_put_failure;
 
+	if (dev->dev.parent &&
+	    nla_put_string(skb, IFLA_PARENT_DEV_NAME,
+			   dev_name(dev->dev.parent)))
+		goto nla_put_failure;
+
 	nlmsg_end(skb, nlh);
 	return 0;
 
Signature · 1 line
2.26.3
author maintainer
#4 lore raw

RFC 4/6 Update kernel headers

In reply to Sergey Ryazanov

A partial headers update that brings WWAN-related attributes. Included in the series mainly to make it possible to quickly compile and test the utility.

---
 include/uapi/linux/if_link.h |  6 ++++++
 include/uapi/linux/wwan.h    | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 include/uapi/linux/wwan.h
include/uapi/linux/if_link.h +6 -0
index 50193377..1cf48416 100644
@@ -341,6 +341,12 @@ enum {
 	IFLA_ALT_IFNAME, /* Alternative ifname */
 	IFLA_PERM_ADDRESS,
 	IFLA_PROTO_DOWN_REASON,
+
+	/* device (sysfs) name as parent, used instead
+	 * of IFLA_LINK where there's no parent netdev
+	 */
+	IFLA_PARENT_DEV_NAME,
+
 	__IFLA_MAX
 };
 
include/uapi/linux/wwan.h new file +16 -0
new file mode 100644
index 00000000..32a2720b
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2021 Intel Corporation.
+ */
+#ifndef _UAPI_WWAN_H_
+#define _UAPI_WWAN_H_
+
+enum {
+	IFLA_WWAN_UNSPEC,
+	IFLA_WWAN_LINK_ID, /* u32 */
+
+	__IFLA_WWAN_MAX
+};
+#define IFLA_WWAN_MAX (__IFLA_WWAN_MAX - 1)
+
+#endif /* _UAPI_WWAN_H_ */
Signature · 1 line
2.26.3
author maintainer
#5 lore raw

RFC 5/6 iplink: add support for parent device

In reply to Sergey Ryazanov

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".

---
 ip/ipaddress.c | 7 +++++++
 ip/iplink.c    | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
ip/ipaddress.c +7 -0
index cfb24f5c..98f25a5b 100644
@@ -1176,6 +1176,13 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 						   RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]),
 						   b1, sizeof(b1)));
 		}
+
+		if (tb[IFLA_PARENT_DEV_NAME]) {
+			print_string(PRINT_ANY,
+				     "parentdev_name",
+				     "parentdev-name %s ",
+				     rta_getattr_str(tb[IFLA_PARENT_DEV_NAME]));
+		}
 	}
 
 	if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
ip/iplink.c +5 -1
index faafd7e8..190ce7d9 100644
@@ -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 ] 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-name") == 0) {
+			NEXT_ARG();
+			addattr_l(&req->n, sizeof(*req), IFLA_PARENT_DEV_NAME,
+				  *argv, strlen(*argv) + 1);
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
Signature · 1 line
2.26.3
author maintainer
#6 lore raw

RFC 6/6 iplink: support for WWAN devices

In reply to Sergey Ryazanov

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.

---
 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
ip/Makefile +1 -1
index 4cad619c..b03af29b 100644
@@ -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
 
ip/iplink.c +2 -1
index 190ce7d9..4073d6e8 100644
@@ -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)
ip/iplink_wwan.c new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.26.3