Merge branch 'iplink-parse' into iproute2-next
Serhey Popovych says: ==================== This is main routine to parse ip-link(8) configuration parameters. Move all code related to command line parsing and validation to it from iptables_modify(). As benefit we reduce number of arguments as well as checking for most of weired cases in single place to give benefit to iptables_parse() users. See individual patch description message for more information. v4 Drop patches intended to reduce number of arguments to iptables_parse(): postpone to the series with real use cases. Save only ifi_index in iplink_vxcan.c and link_veth.c: no need to save whole ifinfomsg data structure. Note that there is no sense to introduce custom version of iplink_parse() to use in iplink_vxcan.c and link_veth.c because there is too much parameters we need to support (except VF and few others) making huge code duplication. v3 Move vxlan/veth ifinfomsg save/restore to separate patch to make clear change that perform most of request buffer setups and checks in iplink_parse(). Update commit message descriptions and extra new line from "utils: Introduce and use nodev() helper routine" patch. v2 Terminate via exit() when failing to parse command line arguments to help identify failing line in batch mode. ==================== Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
commit
bea42e6c24
17
bridge/fdb.c
17
bridge/fdb.c
|
|
@ -311,11 +311,8 @@ static int fdb_show(int argc, char **argv)
|
|||
/*we'll keep around filter_dev for older kernels */
|
||||
if (filter_dev) {
|
||||
filter_index = ll_name_to_index(filter_dev);
|
||||
if (filter_index == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
filter_dev);
|
||||
return -1;
|
||||
}
|
||||
if (!filter_index)
|
||||
return nodev(filter_dev);
|
||||
req.ifm.ifi_index = filter_index;
|
||||
}
|
||||
|
||||
|
|
@ -391,8 +388,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
|
|||
} else if (strcmp(*argv, "via") == 0) {
|
||||
NEXT_ARG();
|
||||
via = ll_name_to_index(*argv);
|
||||
if (via == 0)
|
||||
invarg("invalid device\n", *argv);
|
||||
if (!via)
|
||||
exit(nodev(*argv));
|
||||
} else if (strcmp(*argv, "self") == 0) {
|
||||
req.ndm.ndm_flags |= NTF_SELF;
|
||||
} else if (matches(*argv, "master") == 0) {
|
||||
|
|
@ -467,10 +464,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
|
|||
addattr32(&req.n, sizeof(req), NDA_IFINDEX, via);
|
||||
|
||||
req.ndm.ndm_ifindex = ll_name_to_index(d);
|
||||
if (req.ndm.ndm_ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return -1;
|
||||
}
|
||||
if (!req.ndm.ndm_ifindex)
|
||||
return nodev(d);
|
||||
|
||||
if (rtnl_talk(&rth, &req.n, NULL) < 0)
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -485,11 +485,9 @@ static int brlink_show(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (filter_dev) {
|
||||
if ((filter_index = ll_name_to_index(filter_dev)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
filter_dev);
|
||||
return -1;
|
||||
}
|
||||
filter_index = ll_name_to_index(filter_dev);
|
||||
if (!filter_index)
|
||||
return nodev(filter_dev);
|
||||
}
|
||||
|
||||
if (show_details) {
|
||||
|
|
|
|||
19
bridge/mdb.c
19
bridge/mdb.c
|
|
@ -287,11 +287,8 @@ static int mdb_show(int argc, char **argv)
|
|||
|
||||
if (filter_dev) {
|
||||
filter_index = ll_name_to_index(filter_dev);
|
||||
if (filter_index == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
filter_dev);
|
||||
return -1;
|
||||
}
|
||||
if (!filter_index)
|
||||
return nodev(filter_dev);
|
||||
}
|
||||
|
||||
new_json_obj(json);
|
||||
|
|
@ -360,16 +357,12 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
|
|||
}
|
||||
|
||||
req.bpm.ifindex = ll_name_to_index(d);
|
||||
if (req.bpm.ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return -1;
|
||||
}
|
||||
if (!req.bpm.ifindex)
|
||||
return nodev(d);
|
||||
|
||||
entry.ifindex = ll_name_to_index(p);
|
||||
if (entry.ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", p);
|
||||
return -1;
|
||||
}
|
||||
if (!entry.ifindex)
|
||||
return nodev(p);
|
||||
|
||||
if (!inet_pton(AF_INET, grp, &entry.addr.u.ip4)) {
|
||||
if (!inet_pton(AF_INET6, grp, &entry.addr.u.ip6)) {
|
||||
|
|
|
|||
|
|
@ -554,11 +554,8 @@ static int vlan_show(int argc, char **argv)
|
|||
|
||||
if (filter_dev) {
|
||||
filter_index = ll_name_to_index(filter_dev);
|
||||
if (filter_index == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
filter_dev);
|
||||
return -1;
|
||||
}
|
||||
if (!filter_index)
|
||||
return nodev(filter_dev);
|
||||
}
|
||||
|
||||
new_json_obj(json);
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ void missarg(const char *) __attribute__((noreturn));
|
|||
void invarg(const char *, const char *) __attribute__((noreturn));
|
||||
void duparg(const char *, const char *) __attribute__((noreturn));
|
||||
void duparg2(const char *, const char *) __attribute__((noreturn));
|
||||
int nodev(const char *dev);
|
||||
int check_ifname(const char *);
|
||||
int get_ifname(char *, const char *);
|
||||
const char *get_ifname_rta(int ifindex, const struct rtattr *rta);
|
||||
|
|
|
|||
|
|
@ -296,10 +296,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
|
|||
}
|
||||
if (medium) {
|
||||
p->link = ll_name_to_index(medium);
|
||||
if (p->link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", medium);
|
||||
return -1;
|
||||
}
|
||||
if (!p->link)
|
||||
return nodev(medium);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,9 +132,7 @@ struct link_util {
|
|||
|
||||
struct link_util *get_link_kind(const char *kind);
|
||||
|
||||
int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
||||
char **name, char **type, char **link, char **dev,
|
||||
int *group, int *index);
|
||||
int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type);
|
||||
|
||||
/* iplink_bridge.c */
|
||||
void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
|
||||
|
|
|
|||
|
|
@ -2211,10 +2211,9 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
|
|||
if (!scoped && cmd != RTM_DELADDR)
|
||||
req.ifa.ifa_scope = default_scope(&lcl);
|
||||
|
||||
if ((req.ifa.ifa_index = ll_name_to_index(d)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return -1;
|
||||
}
|
||||
req.ifa.ifa_index = ll_name_to_index(d);
|
||||
if (!req.ifa.ifa_index)
|
||||
return nodev(d);
|
||||
|
||||
if (valid_lftp || preferred_lftp) {
|
||||
struct ifa_cacheinfo cinfo = {};
|
||||
|
|
|
|||
201
ip/iplink.c
201
ip/iplink.c
|
|
@ -569,10 +569,11 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
||||
char **name, char **type, char **link, char **dev,
|
||||
int *group, int *index)
|
||||
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;
|
||||
|
|
@ -583,9 +584,10 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
int numrxqueues = -1;
|
||||
int dev_index = 0;
|
||||
int link_netnsid = -1;
|
||||
int index = 0;
|
||||
int group = -1;
|
||||
int addr_len = 0;
|
||||
|
||||
*group = -1;
|
||||
ret = argc;
|
||||
|
||||
while (argc > 0) {
|
||||
|
|
@ -597,19 +599,25 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
req->i.ifi_flags &= ~IFF_UP;
|
||||
} else if (strcmp(*argv, "name") == 0) {
|
||||
NEXT_ARG();
|
||||
if (name)
|
||||
duparg("name", *argv);
|
||||
if (check_ifname(*argv))
|
||||
invarg("\"name\" not a valid ifname", *argv);
|
||||
*name = *argv;
|
||||
name = *argv;
|
||||
if (!dev) {
|
||||
dev = name;
|
||||
dev_index = ll_name_to_index(dev);
|
||||
}
|
||||
} else if (strcmp(*argv, "index") == 0) {
|
||||
NEXT_ARG();
|
||||
if (*index)
|
||||
if (index)
|
||||
duparg("index", *argv);
|
||||
*index = atoi(*argv);
|
||||
if (*index <= 0)
|
||||
index = atoi(*argv);
|
||||
if (index <= 0)
|
||||
invarg("Invalid \"index\" value", *argv);
|
||||
} else if (matches(*argv, "link") == 0) {
|
||||
NEXT_ARG();
|
||||
*link = *argv;
|
||||
link = *argv;
|
||||
} else if (matches(*argv, "address") == 0) {
|
||||
NEXT_ARG();
|
||||
addr_len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
|
||||
|
|
@ -654,6 +662,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
if (xdp_parse(&argc, &argv, req, dev_index,
|
||||
generic, drv, offload))
|
||||
exit(-1);
|
||||
|
||||
if (offload && name == dev)
|
||||
dev = NULL;
|
||||
} else if (strcmp(*argv, "netns") == 0) {
|
||||
NEXT_ARG();
|
||||
if (netns != -1)
|
||||
|
|
@ -745,6 +756,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
if (len < 0)
|
||||
return -1;
|
||||
addattr_nest_end(&req->n, vflist);
|
||||
|
||||
if (name == dev)
|
||||
dev = NULL;
|
||||
} else if (matches(*argv, "master") == 0) {
|
||||
int ifindex;
|
||||
|
||||
|
|
@ -794,10 +808,11 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
*argv, len);
|
||||
} else if (strcmp(*argv, "group") == 0) {
|
||||
NEXT_ARG();
|
||||
if (*group != -1)
|
||||
if (group != -1)
|
||||
duparg("group", *argv);
|
||||
if (rtnl_group_a2n(group, *argv))
|
||||
if (rtnl_group_a2n(&group, *argv))
|
||||
invarg("Invalid \"group\" value\n", *argv);
|
||||
addattr32(&req->n, sizeof(*req), IFLA_GROUP, group);
|
||||
} else if (strcmp(*argv, "mode") == 0) {
|
||||
int mode;
|
||||
|
||||
|
|
@ -895,16 +910,26 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
|
||||
if (strcmp(*argv, "dev") == 0)
|
||||
NEXT_ARG();
|
||||
if (*dev)
|
||||
if (dev != name)
|
||||
duparg2("dev", *argv);
|
||||
if (check_ifname(*argv))
|
||||
invarg("\"dev\" not a valid ifname", *argv);
|
||||
*dev = *argv;
|
||||
dev_index = ll_name_to_index(*dev);
|
||||
dev = *argv;
|
||||
dev_index = ll_name_to_index(dev);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
ret -= argc;
|
||||
|
||||
/* Allow "ip link add dev" and "ip link add name" */
|
||||
if (!name)
|
||||
name = dev;
|
||||
else if (!dev)
|
||||
dev = name;
|
||||
else if (!strcmp(name, dev))
|
||||
name = dev;
|
||||
|
||||
if (dev_index && addr_len) {
|
||||
int halen = nl_get_ll_addr_len(dev_index);
|
||||
|
||||
|
|
@ -916,18 +941,75 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||
}
|
||||
}
|
||||
|
||||
return ret - argc;
|
||||
if (!(req->n.nlmsg_flags & NLM_F_CREATE) && index) {
|
||||
fprintf(stderr,
|
||||
"index can be used only when creating devices.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (group != -1) {
|
||||
if (!dev) {
|
||||
if (argc) {
|
||||
fprintf(stderr,
|
||||
"Garbage instead of arguments \"%s ...\". Try \"ip link help\".\n",
|
||||
*argv);
|
||||
exit(-1);
|
||||
}
|
||||
if (req->n.nlmsg_flags & NLM_F_CREATE) {
|
||||
fprintf(stderr,
|
||||
"group cannot be used when creating devices.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
*type = NULL;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(req->n.nlmsg_flags & NLM_F_CREATE)) {
|
||||
if (!dev) {
|
||||
fprintf(stderr,
|
||||
"Not enough information: \"dev\" argument is required.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
req->i.ifi_index = ll_name_to_index(dev);
|
||||
if (!req->i.ifi_index)
|
||||
return nodev(dev);
|
||||
|
||||
/* Not renaming to the same name */
|
||||
if (name == dev)
|
||||
name = NULL;
|
||||
} else {
|
||||
if (name != dev) {
|
||||
fprintf(stderr,
|
||||
"both \"name\" and \"dev\" cannot be used when creating devices.\n");
|
||||
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;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
addattr_l(&req->n, sizeof(*req),
|
||||
IFLA_IFNAME, name, strlen(name) + 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||
{
|
||||
char *dev = NULL;
|
||||
char *name = NULL;
|
||||
char *link = NULL;
|
||||
char *type = NULL;
|
||||
int index = 0;
|
||||
int group;
|
||||
struct link_util *lu = NULL;
|
||||
struct iplink_req req = {
|
||||
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
|
||||
.n.nlmsg_flags = NLM_F_REQUEST | flags,
|
||||
|
|
@ -936,81 +1018,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||
};
|
||||
int ret;
|
||||
|
||||
ret = iplink_parse(argc, argv,
|
||||
&req, &name, &type, &link, &dev, &group, &index);
|
||||
ret = iplink_parse(argc, argv, &req, &type);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
argc -= ret;
|
||||
argv += ret;
|
||||
|
||||
if (group != -1) {
|
||||
if (dev)
|
||||
addattr_l(&req.n, sizeof(req), IFLA_GROUP,
|
||||
&group, sizeof(group));
|
||||
else {
|
||||
if (argc) {
|
||||
fprintf(stderr,
|
||||
"Garbage instead of arguments \"%s ...\". Try \"ip link help\".\n",
|
||||
*argv);
|
||||
return -1;
|
||||
}
|
||||
if (flags & NLM_F_CREATE) {
|
||||
fprintf(stderr,
|
||||
"group cannot be used when creating devices.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
addattr32(&req.n, sizeof(req), IFLA_GROUP, group);
|
||||
if (rtnl_talk(&rth, &req.n, NULL) < 0)
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(flags & NLM_F_CREATE)) {
|
||||
if (!dev) {
|
||||
fprintf(stderr,
|
||||
"Not enough information: \"dev\" argument is required.\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (cmd == RTM_NEWLINK && index) {
|
||||
fprintf(stderr,
|
||||
"index can be used only when creating devices.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
req.i.ifi_index = ll_name_to_index(dev);
|
||||
if (req.i.ifi_index == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", dev);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* Allow "ip link add dev" and "ip link add name" */
|
||||
if (!name)
|
||||
name = dev;
|
||||
|
||||
if (link) {
|
||||
int ifindex;
|
||||
|
||||
ifindex = ll_name_to_index(link);
|
||||
if (ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
link);
|
||||
return -1;
|
||||
}
|
||||
addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifindex, 4);
|
||||
}
|
||||
|
||||
req.i.ifi_index = index;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
addattr_l(&req.n, sizeof(req),
|
||||
IFLA_IFNAME, name, strlen(name) + 1);
|
||||
}
|
||||
|
||||
if (type) {
|
||||
struct link_util *lu;
|
||||
struct rtattr *linkinfo;
|
||||
char *ulinep = strchr(type, '_');
|
||||
int iflatype;
|
||||
|
|
@ -1024,6 +1037,10 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||
iflatype = IFLA_INFO_SLAVE_DATA;
|
||||
else
|
||||
iflatype = IFLA_INFO_DATA;
|
||||
|
||||
argc -= ret;
|
||||
argv += ret;
|
||||
|
||||
if (lu && argc) {
|
||||
struct rtattr *data;
|
||||
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||
NEXT_ARG();
|
||||
ifindex = ll_name_to_index(*argv);
|
||||
if (!ifindex)
|
||||
return -1;
|
||||
return nodev(*argv);
|
||||
addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
|
||||
} else if (matches(*argv, "clear_active_slave") == 0) {
|
||||
addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);
|
||||
|
|
@ -242,7 +242,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||
NEXT_ARG();
|
||||
ifindex = ll_name_to_index(*argv);
|
||||
if (!ifindex)
|
||||
return -1;
|
||||
return nodev(*argv);
|
||||
addattr32(n, 1024, IFLA_BOND_PRIMARY, ifindex);
|
||||
} else if (matches(*argv, "primary_reselect") == 0) {
|
||||
NEXT_ARG();
|
||||
|
|
|
|||
|
|
@ -793,11 +793,8 @@ int bridge_parse_xstats(struct link_util *lu, int argc, char **argv)
|
|||
} else if (strcmp(*argv, "dev") == 0) {
|
||||
NEXT_ARG();
|
||||
filter_index = ll_name_to_index(*argv);
|
||||
if (filter_index == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
*argv);
|
||||
return -1;
|
||||
}
|
||||
if (!filter_index)
|
||||
return nodev(*argv);
|
||||
} else if (strcmp(*argv, "help") == 0) {
|
||||
bridge_print_xstats_help(lu, stdout);
|
||||
exit(0);
|
||||
|
|
|
|||
|
|
@ -33,16 +33,11 @@ static void usage(void)
|
|||
static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||
struct nlmsghdr *n)
|
||||
{
|
||||
char *dev = NULL;
|
||||
char *name = NULL;
|
||||
char *link = NULL;
|
||||
char *type = NULL;
|
||||
int index = 0;
|
||||
int err;
|
||||
struct rtattr *data;
|
||||
int group;
|
||||
struct ifinfomsg *ifm, *peer_ifm;
|
||||
unsigned int ifi_flags, ifi_change;
|
||||
unsigned int ifi_flags, ifi_change, ifi_index;
|
||||
|
||||
if (strcmp(argv[0], "peer") != 0) {
|
||||
usage();
|
||||
|
|
@ -52,35 +47,29 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||
ifm = NLMSG_DATA(n);
|
||||
ifi_flags = ifm->ifi_flags;
|
||||
ifi_change = ifm->ifi_change;
|
||||
ifi_index = ifm->ifi_index;
|
||||
ifm->ifi_flags = 0;
|
||||
ifm->ifi_change = 0;
|
||||
ifm->ifi_index = 0;
|
||||
|
||||
data = addattr_nest(n, 1024, VXCAN_INFO_PEER);
|
||||
|
||||
n->nlmsg_len += sizeof(struct ifinfomsg);
|
||||
|
||||
err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n,
|
||||
&name, &type, &link, &dev, &group, &index);
|
||||
err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (type)
|
||||
duparg("type", argv[err]);
|
||||
|
||||
if (name) {
|
||||
addattr_l(n, 1024,
|
||||
IFLA_IFNAME, name, strlen(name) + 1);
|
||||
}
|
||||
|
||||
peer_ifm = RTA_DATA(data);
|
||||
peer_ifm->ifi_index = index;
|
||||
peer_ifm->ifi_index = ifm->ifi_index;
|
||||
peer_ifm->ifi_flags = ifm->ifi_flags;
|
||||
peer_ifm->ifi_change = ifm->ifi_change;
|
||||
ifm->ifi_flags = ifi_flags;
|
||||
ifm->ifi_change = ifi_change;
|
||||
|
||||
if (group != -1)
|
||||
addattr32(n, 1024, IFLA_GROUP, group);
|
||||
ifm->ifi_index = ifi_index;
|
||||
|
||||
addattr_nest_end(n, data);
|
||||
return argc - 1 - err;
|
||||
|
|
|
|||
|
|
@ -133,11 +133,8 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||
NEXT_ARG();
|
||||
check_duparg(&attrs, IFLA_VXLAN_LINK, "dev", *argv);
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
*argv);
|
||||
exit(-1);
|
||||
}
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
addattr32(n, 1024, IFLA_VXLAN_LINK, link);
|
||||
} else if (!matches(*argv, "ttl") ||
|
||||
!matches(*argv, "hoplimit")) {
|
||||
|
|
|
|||
|
|
@ -244,10 +244,9 @@ static int mroute_list(int argc, char **argv)
|
|||
if (id) {
|
||||
int idx;
|
||||
|
||||
if ((idx = ll_name_to_index(id)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", id);
|
||||
return -1;
|
||||
}
|
||||
idx = ll_name_to_index(id);
|
||||
if (!idx)
|
||||
return nodev(id);
|
||||
filter.iif = idx;
|
||||
}
|
||||
|
||||
|
|
|
|||
14
ip/ipneigh.c
14
ip/ipneigh.c
|
|
@ -179,9 +179,10 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
|
|||
|
||||
ll_init_map(&rth);
|
||||
|
||||
if (dev && (req.ndm.ndm_ifindex = ll_name_to_index(dev)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", dev);
|
||||
return -1;
|
||||
if (dev) {
|
||||
req.ndm.ndm_ifindex = ll_name_to_index(dev);
|
||||
if (!req.ndm.ndm_ifindex)
|
||||
return nodev(dev);
|
||||
}
|
||||
|
||||
if (rtnl_talk(&rth, &req.n, NULL) < 0)
|
||||
|
|
@ -467,10 +468,9 @@ static int do_show_or_flush(int argc, char **argv, int flush)
|
|||
ll_init_map(&rth);
|
||||
|
||||
if (filter_dev) {
|
||||
if ((filter.index = ll_name_to_index(filter_dev)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev);
|
||||
return -1;
|
||||
}
|
||||
filter.index = ll_name_to_index(filter_dev);
|
||||
if (!filter.index)
|
||||
return nodev(filter_dev);
|
||||
addattr32(&req.n, sizeof(req), NDA_IFINDEX, filter.index);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,10 +140,8 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
|
|||
|
||||
NEXT_ARG();
|
||||
ifindex = ll_name_to_index(*argv);
|
||||
if (ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
|
||||
return -1;
|
||||
}
|
||||
if (!ifindex)
|
||||
return nodev(*argv);
|
||||
|
||||
rta_addattr32(parms_rta, sizeof(parms_buf),
|
||||
NDTPA_IFINDEX, ifindex);
|
||||
|
|
|
|||
36
ip/iproute.c
36
ip/iproute.c
|
|
@ -973,10 +973,8 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
|
|||
} else if (strcmp(*argv, "dev") == 0) {
|
||||
NEXT_ARG();
|
||||
rtnh->rtnh_ifindex = ll_name_to_index(*argv);
|
||||
if (rtnh->rtnh_ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
|
||||
return -1;
|
||||
}
|
||||
if (!rtnh->rtnh_ifindex)
|
||||
return nodev(*argv);
|
||||
} else if (strcmp(*argv, "weight") == 0) {
|
||||
unsigned int w;
|
||||
|
||||
|
|
@ -1474,10 +1472,8 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||
if (d) {
|
||||
int idx = ll_name_to_index(d);
|
||||
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return -1;
|
||||
}
|
||||
if (!idx)
|
||||
return nodev(d);
|
||||
addattr32(&req.n, sizeof(req), RTA_OIF, idx);
|
||||
}
|
||||
|
||||
|
|
@ -1866,19 +1862,15 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
|
|||
|
||||
if (id) {
|
||||
idx = ll_name_to_index(id);
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", id);
|
||||
return -1;
|
||||
}
|
||||
if (!idx)
|
||||
return nodev(id);
|
||||
filter.iif = idx;
|
||||
filter.iifmask = -1;
|
||||
}
|
||||
if (od) {
|
||||
idx = ll_name_to_index(od);
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", od);
|
||||
return -1;
|
||||
}
|
||||
if (!idx)
|
||||
return nodev(od);
|
||||
filter.oif = idx;
|
||||
filter.oifmask = -1;
|
||||
}
|
||||
|
|
@ -2028,18 +2020,14 @@ static int iproute_get(int argc, char **argv)
|
|||
|
||||
if (idev) {
|
||||
idx = ll_name_to_index(idev);
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", idev);
|
||||
return -1;
|
||||
}
|
||||
if (!idx)
|
||||
return nodev(idev);
|
||||
addattr32(&req.n, sizeof(req), RTA_IIF, idx);
|
||||
}
|
||||
if (odev) {
|
||||
idx = ll_name_to_index(odev);
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", odev);
|
||||
return -1;
|
||||
}
|
||||
if (!idx)
|
||||
return nodev(odev);
|
||||
addattr32(&req.n, sizeof(req), RTA_OIF, idx);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -594,7 +594,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
|
|||
duparg2("iif", *argv);
|
||||
iif = ll_name_to_index(*argv);
|
||||
if (!iif)
|
||||
invarg("\"iif\" interface not found\n", *argv);
|
||||
exit(nodev(*argv));
|
||||
rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif);
|
||||
} else if (strcmp(*argv, "oif") == 0) {
|
||||
NEXT_ARG();
|
||||
|
|
@ -602,7 +602,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
|
|||
duparg2("oif", *argv);
|
||||
oif = ll_name_to_index(*argv);
|
||||
if (!oif)
|
||||
invarg("\"oif\" interface not found\n", *argv);
|
||||
exit(nodev(*argv));
|
||||
rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif);
|
||||
} else if (strcmp(*argv, "srh") == 0) {
|
||||
NEXT_ARG();
|
||||
|
|
|
|||
|
|
@ -213,10 +213,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
|
|||
|
||||
if (medium) {
|
||||
p->link = ll_name_to_index(medium);
|
||||
if (p->link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", medium);
|
||||
return -1;
|
||||
}
|
||||
if (!p->link)
|
||||
return nodev(medium);
|
||||
}
|
||||
|
||||
if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
|
||||
|
|
|
|||
|
|
@ -245,11 +245,8 @@ get_failed:
|
|||
} else if (!matches(*argv, "dev")) {
|
||||
NEXT_ARG();
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
*argv);
|
||||
exit(-1);
|
||||
}
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
} else if (!matches(*argv, "ttl") ||
|
||||
!matches(*argv, "hoplimit") ||
|
||||
!matches(*argv, "hlim")) {
|
||||
|
|
|
|||
|
|
@ -251,11 +251,8 @@ get_failed:
|
|||
} else if (!matches(*argv, "dev")) {
|
||||
NEXT_ARG();
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
*argv);
|
||||
exit(-1);
|
||||
}
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
} else if (!matches(*argv, "ttl") ||
|
||||
!matches(*argv, "hoplimit") ||
|
||||
!matches(*argv, "hlim")) {
|
||||
|
|
|
|||
|
|
@ -197,8 +197,8 @@ get_failed:
|
|||
} else if (matches(*argv, "dev") == 0) {
|
||||
NEXT_ARG();
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0)
|
||||
invarg("\"dev\" is invalid", *argv);
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
} else if (strcmp(*argv, "ttl") == 0 ||
|
||||
strcmp(*argv, "hoplimit") == 0 ||
|
||||
strcmp(*argv, "hlim") == 0) {
|
||||
|
|
|
|||
|
|
@ -225,8 +225,8 @@ get_failed:
|
|||
} else if (matches(*argv, "dev") == 0) {
|
||||
NEXT_ARG();
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0)
|
||||
invarg("\"dev\" is invalid", *argv);
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
} else if (strcmp(*argv, "ttl") == 0 ||
|
||||
strcmp(*argv, "hoplimit") == 0 ||
|
||||
strcmp(*argv, "hlim") == 0) {
|
||||
|
|
|
|||
|
|
@ -31,16 +31,11 @@ static void usage(void)
|
|||
static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||
struct nlmsghdr *n)
|
||||
{
|
||||
char *dev = NULL;
|
||||
char *name = NULL;
|
||||
char *link = NULL;
|
||||
char *type = NULL;
|
||||
int index = 0;
|
||||
int err;
|
||||
struct rtattr *data;
|
||||
int group;
|
||||
struct ifinfomsg *ifm, *peer_ifm;
|
||||
unsigned int ifi_flags, ifi_change;
|
||||
unsigned int ifi_flags, ifi_change, ifi_index;
|
||||
|
||||
if (strcmp(argv[0], "peer") != 0) {
|
||||
usage();
|
||||
|
|
@ -50,35 +45,29 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||
ifm = NLMSG_DATA(n);
|
||||
ifi_flags = ifm->ifi_flags;
|
||||
ifi_change = ifm->ifi_change;
|
||||
ifi_index = ifm->ifi_index;
|
||||
ifm->ifi_flags = 0;
|
||||
ifm->ifi_change = 0;
|
||||
ifm->ifi_index = 0;
|
||||
|
||||
data = addattr_nest(n, 1024, VETH_INFO_PEER);
|
||||
|
||||
n->nlmsg_len += sizeof(struct ifinfomsg);
|
||||
|
||||
err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n,
|
||||
&name, &type, &link, &dev, &group, &index);
|
||||
err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (type)
|
||||
duparg("type", argv[err]);
|
||||
|
||||
if (name) {
|
||||
addattr_l(n, 1024,
|
||||
IFLA_IFNAME, name, strlen(name) + 1);
|
||||
}
|
||||
|
||||
peer_ifm = RTA_DATA(data);
|
||||
peer_ifm->ifi_index = index;
|
||||
peer_ifm->ifi_index = ifm->ifi_index;
|
||||
peer_ifm->ifi_flags = ifm->ifi_flags;
|
||||
peer_ifm->ifi_change = ifm->ifi_change;
|
||||
ifm->ifi_flags = ifi_flags;
|
||||
ifm->ifi_change = ifi_change;
|
||||
|
||||
if (group != -1)
|
||||
addattr32(n, 1024, IFLA_GROUP, group);
|
||||
ifm->ifi_index = ifi_index;
|
||||
|
||||
addattr_nest_end(n, data);
|
||||
return argc - 1 - err;
|
||||
|
|
|
|||
|
|
@ -142,11 +142,8 @@ get_failed:
|
|||
} else if (!matches(*argv, "dev")) {
|
||||
NEXT_ARG();
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
*argv);
|
||||
exit(-1);
|
||||
}
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
} else if (strcmp(*argv, "fwmark") == 0) {
|
||||
NEXT_ARG();
|
||||
if (get_u32(&fwmark, *argv, 0))
|
||||
|
|
|
|||
|
|
@ -144,11 +144,8 @@ get_failed:
|
|||
} else if (!matches(*argv, "dev")) {
|
||||
NEXT_ARG();
|
||||
link = ll_name_to_index(*argv);
|
||||
if (link == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n",
|
||||
*argv);
|
||||
exit(-1);
|
||||
}
|
||||
if (!link)
|
||||
exit(nodev(*argv));
|
||||
} else if (strcmp(*argv, "fwmark") == 0) {
|
||||
NEXT_ARG();
|
||||
if (get_u32(&fwmark, *argv, 0))
|
||||
|
|
|
|||
|
|
@ -845,6 +845,12 @@ void duparg2(const char *key, const char *arg)
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
int nodev(const char *dev)
|
||||
{
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", dev);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int check_ifname(const char *name)
|
||||
{
|
||||
/* These checks mimic kernel checks in dev_valid_name */
|
||||
|
|
|
|||
|
|
@ -193,10 +193,8 @@ parse_direction(struct action_util *a, int *argc_p, char ***argv_p,
|
|||
ll_init_map(&rth);
|
||||
|
||||
idx = ll_name_to_index(d);
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return -1;
|
||||
}
|
||||
if (!idx)
|
||||
return nodev(d);
|
||||
|
||||
p.ifindex = idx;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,10 +142,9 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||
if (d[0]) {
|
||||
ll_init_map(&rth);
|
||||
|
||||
if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
req.t.tcm_ifindex = ll_name_to_index(d);
|
||||
if (!req.t.tcm_ifindex)
|
||||
return -nodev(d);
|
||||
}
|
||||
|
||||
if (rtnl_talk(&rth, &req.n, NULL) < 0)
|
||||
|
|
@ -440,10 +439,9 @@ static int tc_class_list(int argc, char **argv)
|
|||
ll_init_map(&rth);
|
||||
|
||||
if (d[0]) {
|
||||
if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
t.tcm_ifindex = ll_name_to_index(d);
|
||||
if (!t.tcm_ifindex)
|
||||
return -nodev(d);
|
||||
filter_ifindex = t.tcm_ifindex;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,10 +198,8 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv,
|
|||
ll_init_map(&rth);
|
||||
|
||||
req->t.tcm_ifindex = ll_name_to_index(d);
|
||||
if (req->t.tcm_ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
if (!req->t.tcm_ifindex)
|
||||
return -nodev(d);
|
||||
} else if (block_index) {
|
||||
req->t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
|
||||
req->t.tcm_block_index = block_index;
|
||||
|
|
@ -529,10 +527,8 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)
|
|||
ll_init_map(&rth);
|
||||
|
||||
req.t.tcm_ifindex = ll_name_to_index(d);
|
||||
if (req.t.tcm_ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
if (!req.t.tcm_ifindex)
|
||||
return -nodev(d);
|
||||
filter_ifindex = req.t.tcm_ifindex;
|
||||
} else if (block_index) {
|
||||
req.t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
|
||||
|
|
@ -695,10 +691,8 @@ static int tc_filter_list(int argc, char **argv)
|
|||
|
||||
if (d[0]) {
|
||||
req.t.tcm_ifindex = ll_name_to_index(d);
|
||||
if (req.t.tcm_ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
if (!req.t.tcm_ifindex)
|
||||
return -nodev(d);
|
||||
filter_ifindex = req.t.tcm_ifindex;
|
||||
} else if (block_index) {
|
||||
if (!tc_qdisc_block_exists(block_index)) {
|
||||
|
|
|
|||
|
|
@ -199,10 +199,8 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||
ll_init_map(&rth);
|
||||
|
||||
idx = ll_name_to_index(d);
|
||||
if (idx == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
if (!idx)
|
||||
return -nodev(d);
|
||||
req.t.tcm_ifindex = idx;
|
||||
}
|
||||
|
||||
|
|
@ -378,10 +376,8 @@ static int tc_qdisc_list(int argc, char **argv)
|
|||
|
||||
if (d[0]) {
|
||||
t.tcm_ifindex = ll_name_to_index(d);
|
||||
if (t.tcm_ifindex == 0) {
|
||||
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
||||
return 1;
|
||||
}
|
||||
if (!t.tcm_ifindex)
|
||||
return -nodev(d);
|
||||
filter_ifindex = t.tcm_ifindex;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue