Message ID | 20210410133454.4768-5-ansuelsmth@gmail.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | David Ahern |
Headers | show |
Series | [RFC,iproute2-next] iplink: allow to change iplink value | expand |
On Sat, 10 Apr 2021 15:34:50 +0200 Ansuel Smith <ansuelsmth@gmail.com> wrote: > Allow to change the interface to which a given interface is linked to. > This is useful in the case of multi-CPU port DSA, for changing the CPU > port of a given user port. > > Signed-off-by: Marek Behún <marek.behun@nic.cz> > Cc: David Ahern <dsahern@gmail.com> > Cc: Stephen Hemminger <stephen@networkplumber.org> This may work for DSA but it won't work for all the device types vlan/macsec/... that now use the link attribute. It looks like the change link handling for those device types just ignores the link attribute (maybe ok). But before supporting this as an API, it would be better if all the other drivers that use IFLA_LINK had error checks in their change link handling. Please add error checks in kernel first.
On Sun, Apr 11, 2021 at 10:04:11AM -0700, Stephen Hemminger wrote: > On Sat, 10 Apr 2021 15:34:50 +0200 > Ansuel Smith <ansuelsmth@gmail.com> wrote: > > > Allow to change the interface to which a given interface is linked to. > > This is useful in the case of multi-CPU port DSA, for changing the CPU > > port of a given user port. > > > > Signed-off-by: Marek Behún <marek.behun@nic.cz> > > Cc: David Ahern <dsahern@gmail.com> > > Cc: Stephen Hemminger <stephen@networkplumber.org> > > This may work for DSA but it won't work for all the device types vlan/macsec/... that > now use the link attribute. It looks like the change link handling for those > device types just ignores the link attribute (maybe ok). But before supporting this > as an API, it would be better if all the other drivers that use IFLA_LINK > had error checks in their change link handling. > > Please add error checks in kernel first. Would it be better to expose this as a netlink attribute specific to DSA, instead of iflink which as you point out has uses for other virtual interfaces like veth, and the semantics there are not quite the same?
diff --git a/ip/iplink.c b/ip/iplink.c index 212a0885..d52c0aaf 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -579,7 +579,6 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) { char *name = NULL; char *dev = NULL; - char *link = NULL; int ret, len; char abuf[32]; int qlen = -1; @@ -590,6 +589,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) int numrxqueues = -1; int link_netnsid = -1; int index = 0; + int link = -1; int group = -1; int addr_len = 0; @@ -620,7 +620,10 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) invarg("Invalid \"index\" value", *argv); } else if (matches(*argv, "link") == 0) { NEXT_ARG(); - link = *argv; + link = ll_name_to_index(*argv); + if (!link) + return nodev(*argv); + addattr32(&req->n, sizeof(*req), IFLA_LINK, link); } else if (matches(*argv, "address") == 0) { NEXT_ARG(); addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv); @@ -1004,15 +1007,6 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) exit(-1); } - if (link) { - int ifindex; - - ifindex = ll_name_to_index(link); - if (!ifindex) - return nodev(link); - addattr32(&req->n, sizeof(*req), IFLA_LINK, ifindex); - } - req->i.ifi_index = index; } diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index a8ae72d2..800aed05 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -149,6 +149,9 @@ ip-link \- network device configuration .br .RB "[ " nomaster " ]" .br +.RB "[ " link +.IR DEVICE " ]" +.br .RB "[ " vrf .IR NAME " ]" .br @@ -2131,6 +2134,10 @@ set master device of the device (enslave device). .BI nomaster unset master device of the device (release device). +.TP +.BI link " DEVICE" +set device to which this device is linked to. + .TP .BI addrgenmode " eui64|none|stable_secret|random" set the IPv6 address generation mode
Allow to change the interface to which a given interface is linked to. This is useful in the case of multi-CPU port DSA, for changing the CPU port of a given user port. Signed-off-by: Marek Behún <marek.behun@nic.cz> Cc: David Ahern <dsahern@gmail.com> Cc: Stephen Hemminger <stephen@networkplumber.org> --- ip/iplink.c | 16 +++++----------- man/man8/ip-link.8.in | 7 +++++++ 2 files changed, 12 insertions(+), 11 deletions(-)