mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-08-24 08:01:11 +00:00
iplink: forbid negative ifindex and modifying ifindex
Cc: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
This commit is contained in:
parent
9464a5f26c
commit
3c682146ae
@ -400,6 +400,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
|||||||
} else if (strcmp(*argv, "index") == 0) {
|
} else if (strcmp(*argv, "index") == 0) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
*index = atoi(*argv);
|
*index = atoi(*argv);
|
||||||
|
if (*index < 0)
|
||||||
|
invarg("Invalid \"index\" value", *argv);
|
||||||
} else if (matches(*argv, "link") == 0) {
|
} else if (matches(*argv, "link") == 0) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
*link = *argv;
|
*link = *argv;
|
||||||
@ -607,7 +609,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char *link = NULL;
|
char *link = NULL;
|
||||||
char *type = NULL;
|
char *type = NULL;
|
||||||
int index = 0;
|
int index = -1;
|
||||||
int group;
|
int group;
|
||||||
struct link_util *lu = NULL;
|
struct link_util *lu = NULL;
|
||||||
struct iplink_req req;
|
struct iplink_req req;
|
||||||
@ -658,6 +660,11 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|||||||
"argument is required.\n");
|
"argument is required.\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
if (cmd == RTM_NEWLINK && index != -1) {
|
||||||
|
fprintf(stderr, "index can be used only when "
|
||||||
|
"creating devices.\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
req.i.ifi_index = ll_name_to_index(dev);
|
req.i.ifi_index = ll_name_to_index(dev);
|
||||||
if (req.i.ifi_index == 0) {
|
if (req.i.ifi_index == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user