iproute2: allow to change slave options via type_slave
This patch adds the necessary changes to allow altering a slave device's options via ip link set <device> type <master type>_slave specific-option. It also adds support to set the bonding slaves' queue_id. Example: ip link set eth0 type bond_slave queue_id 10 Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Acked-by: Jiri Pirko <jiri@resnulli.us>
This commit is contained in:
parent
3c682146ae
commit
620ddedada
22
ip/iplink.c
22
ip/iplink.c
|
|
@ -88,7 +88,8 @@ void iplink_usage(void)
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
|
fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
|
||||||
fprintf(stderr, " bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |\n");
|
fprintf(stderr, " bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |\n");
|
||||||
fprintf(stderr, " gre | gretap | ip6gre | ip6gretap | vti | nlmon }\n");
|
fprintf(stderr, " gre | gretap | ip6gre | ip6gretap | vti | nlmon |\n");
|
||||||
|
fprintf(stderr, " bond_slave }\n");
|
||||||
}
|
}
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
@ -702,14 +703,29 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
struct rtattr *linkinfo = NLMSG_TAIL(&req.n);
|
struct rtattr *linkinfo = NLMSG_TAIL(&req.n);
|
||||||
|
char slavebuf[128], *ulinep = strchr(type, '_');
|
||||||
|
int iflatype;
|
||||||
|
|
||||||
addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
|
addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
|
||||||
addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type,
|
addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type,
|
||||||
strlen(type));
|
strlen(type));
|
||||||
|
|
||||||
lu = get_link_kind(type);
|
if (ulinep && !strcmp(ulinep, "_slave")) {
|
||||||
|
strncpy(slavebuf, type, sizeof(slavebuf));
|
||||||
|
slavebuf[sizeof(slavebuf) - 1] = '\0';
|
||||||
|
ulinep = strchr(slavebuf, '_');
|
||||||
|
/* check in case it was after sizeof(slavebuf) - 1*/
|
||||||
|
if (ulinep)
|
||||||
|
*ulinep = '\0';
|
||||||
|
lu = get_link_slave_kind(slavebuf);
|
||||||
|
iflatype = IFLA_INFO_SLAVE_DATA;
|
||||||
|
} else {
|
||||||
|
lu = get_link_kind(type);
|
||||||
|
iflatype = IFLA_INFO_DATA;
|
||||||
|
}
|
||||||
if (lu && argc) {
|
if (lu && argc) {
|
||||||
struct rtattr * data = NLMSG_TAIL(&req.n);
|
struct rtattr * data = NLMSG_TAIL(&req.n);
|
||||||
addattr_l(&req.n, sizeof(req), IFLA_INFO_DATA, NULL, 0);
|
addattr_l(&req.n, sizeof(req), iflatype, NULL, 0);
|
||||||
|
|
||||||
if (lu->parse_opt &&
|
if (lu->parse_opt &&
|
||||||
lu->parse_opt(lu, argc, argv, &req.n))
|
lu->parse_opt(lu, argc, argv, &req.n))
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,29 @@ static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *t
|
||||||
rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
|
rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||||
|
struct nlmsghdr *n)
|
||||||
|
{
|
||||||
|
__u16 queue_id;
|
||||||
|
|
||||||
|
while (argc > 0) {
|
||||||
|
if (matches(*argv, "queue_id") == 0) {
|
||||||
|
NEXT_ARG();
|
||||||
|
if (get_u16(&queue_id, *argv, 0))
|
||||||
|
invarg("queue_id is invalid", *argv);
|
||||||
|
addattr16(n, 1024, IFLA_BOND_SLAVE_QUEUE_ID, queue_id);
|
||||||
|
}
|
||||||
|
argc--, argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct link_util bond_slave_link_util = {
|
struct link_util bond_slave_link_util = {
|
||||||
.id = "bond",
|
.id = "bond",
|
||||||
.maxattr = IFLA_BOND_SLAVE_MAX,
|
.maxattr = IFLA_BOND_SLAVE_MAX,
|
||||||
.print_opt = bond_slave_print_opt,
|
.print_opt = bond_slave_print_opt,
|
||||||
|
.parse_opt = bond_slave_parse_opt,
|
||||||
.slave = true,
|
.slave = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue