mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-15 14:05:22 +08:00
08e6ee96b5
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 conduit eth1 $ ip -d link show dev swp0 (...) dsa conduit eth0 $ ip -d -j link show swp0 [ { "link": "eth1", "linkinfo": { "info_kind": "dsa", "info_data": { "conduit": "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@nxp.com> Signed-off-by: David Ahern <dsahern@kernel.org>
69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
/* 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 [ conduit DEVICE ]\n");
|
|
}
|
|
|
|
static int dsa_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
struct nlmsghdr *n)
|
|
{
|
|
while (argc > 0) {
|
|
if (strcmp(*argv, "conduit") == 0 ||
|
|
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 conduit = rta_getattr_u32(tb[IFLA_DSA_MASTER]);
|
|
|
|
print_string(PRINT_ANY,
|
|
"conduit", "conduit %s ",
|
|
ll_index_to_name(conduit));
|
|
}
|
|
}
|
|
|
|
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,
|
|
};
|