@@ -861,6 +861,19 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
return ret - argc;
}
+static int iplink_extack(const char *errmsg, __u32 off,
+ struct nlmsghdr *err_nlh)
+{
+ int rc = 0;
+
+ if (errmsg) {
+ rc++;
+ fprintf(stderr, "Error: %s\n", errmsg);
+ }
+
+ return rc;
+}
+
static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
{
int len;
@@ -906,7 +919,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
req.i.ifi_index = 0;
addattr32(&req.n, sizeof(req), IFLA_GROUP, group);
- if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+ if (rtnl_talk_extack(&rth, &req.n, NULL, 0,
+ iplink_extack) < 0)
return -2;
return 0;
}
@@ -1001,7 +1015,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
return -1;
}
- if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+ if (rtnl_talk_extack(&rth, &req.n, NULL, 0, iplink_extack) < 0)
return -2;
return 0;
Flip iplink_modify to rtnl_talk_extack. For this first patch only error messages returned from the kernel are displayed to the user. Follow on patches can add parsing of the returned message and the error offset to show which attribute caused an error. Signed-off-by: David Ahern <dsa@cumulusnetworks.com> --- ip/iplink.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)