[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220921165105.1737200-1-vladimir.oltean@nxp.com>
Date: Wed, 21 Sep 2022 19:51:05 +0300
From: Vladimir Oltean <vladimir.oltean@....com>
To: netdev@...r.kernel.org
Cc: David Ahern <dsahern@...nel.org>,
Stephen Hemminger <stephen@...workplumber.org>,
Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>
Subject: [PATCH v2 iproute2-next] ip link: add sub-command to view and change DSA master
Support the "dsa" kind of rtnl_link_ops exported by the kernel, and
export reads/writes to IFLA_DSA_MASTER.
Examples:
$ ip link set swp0 type dsa master eth1
$ ip -d link show dev swp0
(...)
dsa master eth0
$ ip -d -j link show swp0
[
{
"link": "eth1",
"linkinfo": {
"info_kind": "dsa",
"info_data": {
"master": "eth1"
}
},
}
]
Note that by construction and as shown in the example, the IFLA_LINK
reported by a DSA user port is identical to what is reported through
IFLA_DSA_MASTER. However IFLA_LINK is not writable, and overloading its
meaning to make it writable would clash with other users of IFLA_LINK
(vlan etc) for which writing this property does not make sense.
Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
---
v1->v2: update man page
The kernel side patches have been merged, so this should be good to go!
https://patchwork.kernel.org/project/netdevbpf/cover/20220911010706.2137967-1-vladimir.oltean@nxp.com/
include/uapi/linux/if_link.h | 10 ++++++
ip/Makefile | 2 +-
ip/iplink_dsa.c | 67 ++++++++++++++++++++++++++++++++++++
man/man8/ip-link.8.in | 32 +++++++++++++++++
4 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 ip/iplink_dsa.c
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index e0fbbfeeb3a1..6f4d7b1ff9fb 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -1372,4 +1372,14 @@ enum {
#define IFLA_MCTP_MAX (__IFLA_MCTP_MAX - 1)
+/* DSA section */
+
+enum {
+ IFLA_DSA_UNSPEC,
+ IFLA_DSA_MASTER,
+ __IFLA_DSA_MAX,
+};
+
+#define IFLA_DSA_MAX (__IFLA_DSA_MAX - 1)
+
#endif /* _LINUX_IF_LINK_H */
diff --git a/ip/Makefile b/ip/Makefile
index 6c2e072049a2..8fd9e295f344 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -8,7 +8,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
iplink_macvlan.o ipl2tp.o link_vti.o link_vti6.o link_xfrm.o \
iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o \
- iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o \
+ iplink_bridge.o iplink_bridge_slave.o iplink_dsa.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 iplink_wwan.o ipioam6.o \
diff --git a/ip/iplink_dsa.c b/ip/iplink_dsa.c
new file mode 100644
index 000000000000..d984e8b3b534
--- /dev/null
+++ b/ip/iplink_dsa.c
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * iplink_dsa.c DSA switch support
+ */
+
+#include "utils.h"
+#include "ip_common.h"
+
+static void print_usage(FILE *f)
+{
+ fprintf(f, "Usage: ... dsa [ master DEVICE ]\n");
+}
+
+static int dsa_parse_opt(struct link_util *lu, int argc, char **argv,
+ struct nlmsghdr *n)
+{
+ while (argc > 0) {
+ if (strcmp(*argv, "master") == 0) {
+ __u32 ifindex;
+
+ NEXT_ARG();
+ ifindex = ll_name_to_index(*argv);
+ if (!ifindex)
+ invarg("Device does not exist\n", *argv);
+ addattr_l(n, 1024, IFLA_DSA_MASTER, &ifindex, 4);
+ } else if (strcmp(*argv, "help") == 0) {
+ print_usage(stderr);
+ return -1;
+ } else {
+ fprintf(stderr, "dsa: unknown command \"%s\"?\n", *argv);
+ print_usage(stderr);
+ return -1;
+ }
+ argc--;
+ argv++;
+ }
+
+ return 0;
+}
+
+static void dsa_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+{
+ if (!tb)
+ return;
+
+ if (tb[IFLA_DSA_MASTER]) {
+ __u32 master = rta_getattr_u32(tb[IFLA_DSA_MASTER]);
+
+ print_string(PRINT_ANY,
+ "master", "master %s ",
+ ll_index_to_name(master));
+ }
+}
+
+static void dsa_print_help(struct link_util *lu, int argc, char **argv,
+ FILE *f)
+{
+ print_usage(f);
+}
+
+struct link_util dsa_link_util = {
+ .id = "dsa",
+ .maxattr = IFLA_DSA_MAX,
+ .parse_opt = dsa_parse_opt,
+ .print_opt = dsa_print_opt,
+ .print_help = dsa_print_help,
+};
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index c45c10622251..cb0504793e06 100644
--- a/man/man8/ip-link.8.in
+++ b/man/man8/ip-link.8.in
@@ -213,6 +213,7 @@ ip-link \- network device configuration
.BR bond " | "
.BR bridge " | "
.BR can " | "
+.BR dsa " | "
.BR dummy " | "
.BR erspan " |"
.BR geneve " |"
@@ -304,6 +305,9 @@ Link types:
.B can
- Controller Area Network
.sp
+.B dsa
+- Distributed Switch Architecture
+.sp
.B dummy
- Dummy network interface
.sp
@@ -2637,6 +2641,29 @@ as well as the actual used bcqueuelen are listed to better help
the user understand the setting.
.in -8
+.TP
+DSA user port support
+For a link having the DSA user port type, the following additional arguments
+are supported:
+
+.B "ip link set type dsa "
+[
+.BI master " DEVICE"
+]
+
+.in +8
+.sp
+.BI master " DEVICE"
+- change the DSA master (host network interface) responsible for handling the
+local traffic termination of the given DSA switch user port. The selected
+interface must be eligible for operating as a DSA master of the switch tree
+which the DSA user port is a part of. Eligible DSA masters are those interfaces
+which have an "ethernet" reference towards their firmware node in the firmware
+description of the platform, or LAG (bond, team) interfaces which contain only
+such interfaces as their ports.
+
+.in -8
+
.SS ip link show - display device attributes
.TP
@@ -2793,6 +2820,11 @@ erspan_ver 2 erspan_dir ingress erspan_hwid 17
.RS 4
Creates a IP6ERSPAN version 2 interface named ip6erspan00.
.RE
+.PP
+ip link set dev swp0 type dsa master eth1
+.RS 4
+Changes the DSA master of the swp0 user port to eth1.
+.RE
.SH SEE ALSO
.br
--
2.34.1
Powered by blists - more mailing lists