Commit 6579feea authored by Varun Chandramohan's avatar Varun Chandramohan Committed by Stephen Hemminger

Display Correct Error For Addrlabel Info

The command "ip addrlabel add/del" displays incorrect error message when provided with insufficient inputs. This patch fixes it in par with "ip addr add/del".

Currently:
# ./ip addrlabel add
RTNETLINK answers: Numerical result out of range

# ./ip addr add
Not enough information: "dev" argument is required.

After patch:
# ./ip addrlabel add
Not enough information: "prefix" argument is required.
Signed-off-by: default avatarVarun Chandramohan <varunc@linux.vnet.ibm.com>
Signed-off-by: default avatarStephen Hemminger <stephen.hemminger@vyatta.com>
parent 01eb17a6
......@@ -139,6 +139,8 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
inet_prefix prefix;
uint32_t label = 0xffffffffUL;
char *p = NULL;
char *l = NULL;
memset(&req, 0, sizeof(req));
memset(&prefix, 0, sizeof(prefix));
......@@ -157,6 +159,7 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
while (argc > 0) {
if (strcmp(*argv, "prefix") == 0) {
NEXT_ARG();
p = *argv;
get_prefix(&prefix, *argv, preferred_family);
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
......@@ -164,13 +167,21 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
invarg("dev is invalid\n", *argv);
} else if (strcmp(*argv, "label") == 0) {
NEXT_ARG();
l = *argv;
if (get_u32(&label, *argv, 0) || label == 0xffffffffUL)
invarg("label is invalid\n", *argv);
}
argc--;
argv++;
}
if (p == NULL) {
fprintf(stderr, "Not enough information: \"prefix\" argument is required.\n");
return -1;
}
if (l == NULL) {
fprintf(stderr, "Not enough information: \"label\" argument is required.\n");
return -1;
}
addattr32(&req.n, sizeof(req), IFAL_LABEL, label);
addattr_l(&req.n, sizeof(req), IFAL_ADDRESS, &prefix.data, prefix.bytelen);
req.ifal.ifal_prefixlen = prefix.bitlen;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment