} else if (strcmp(*argv, "index") == 0) {
NEXT_ARG();
*index = atoi(*argv);
+ if (*index < 0)
+ invarg("Invalid \"index\" value", *argv);
} else if (matches(*argv, "link") == 0) {
NEXT_ARG();
*link = *argv;
char *name = NULL;
char *link = NULL;
char *type = NULL;
- int index = 0;
+ int index = -1;
int group;
struct link_util *lu = NULL;
struct iplink_req req;
"argument is required.\n");
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);
if (req.i.ifi_index == 0) {