]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
devlink: mnlg: Catch returned error value of dumpit commands
authorMoshe Shemesh <moshe@mellanox.com>
Tue, 11 Jun 2019 16:11:09 +0000 (19:11 +0300)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 12 Jun 2019 15:43:14 +0000 (08:43 -0700)
Devlink commands which implements the dumpit callback may return error.
The netlink function netlink_dump() sends the errno value as the payload
of the message, while answering user space with NLMSG_DONE.
To enable receiving errno value for dumpit commands we have to check for
it in the message. If it is a negative value then the dump returned an
error so we should set errno accordingly and check for ext_ack in case
it was set.

Fixes: 049c58539f5d ("devlink: mnlg: Add support for extended ack")
Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
devlink/mnlg.c
include/libnetlink.h
lib/libnetlink.c

index 37cc25ddf4909f8bb156f4565410b44b3c064151..ee125df042f0ecb5bd30892279860c264eb19ec0 100644 (file)
@@ -85,6 +85,13 @@ static int mnlg_cb_error(const struct nlmsghdr *nlh, void *data)
 
 static int mnlg_cb_stop(const struct nlmsghdr *nlh, void *data)
 {
+       int len = *(int *)NLMSG_DATA(nlh);
+
+       if (len < 0) {
+               errno = -len;
+               nl_dump_ext_ack_done(nlh, len);
+               return MNL_CB_ERROR;
+       }
        return MNL_CB_STOP;
 }
 
index 503b3ec11bb6bda345e663f04adedde39289c338..0205af80ed304e3cd20b0012e6bbb62038d1e0dc 100644 (file)
@@ -129,6 +129,7 @@ int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
 int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int)
        __attribute__((warn_unused_result));
 int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn);
+int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error);
 
 int addattr(struct nlmsghdr *n, int maxlen, int type);
 int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data);
index 0d48a3d43cf03065dacbd419578ab10af56431a4..028d55026064509cdf6e9e1a8fadb418fdc10013 100644 (file)
@@ -125,7 +125,7 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
        return 0;
 }
 
-static int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
+int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
 {
        struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
        unsigned int hlen = sizeof(int);
@@ -155,7 +155,7 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
        return 0;
 }
 
-static int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
+int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
 {
        return 0;
 }