]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
libnetlink: add offset for nl_dump_ext_ack_done
authorHangbin Liu <liuhangbin@gmail.com>
Tue, 27 Sep 2022 10:21:06 +0000 (18:21 +0800)
committerDavid Ahern <dsahern@kernel.org>
Wed, 28 Sep 2022 03:18:49 +0000 (21:18 -0600)
There is no rule to have an error code after NLMSG_DONE msg. The only reason
we has this offset is that kernel function netlink_dump_done() has an error
code followed by the netlink message header.

Making nl_dump_ext_ack_done() has an offset parameter. So we can adjust
this for NLMSG_DONE message without error code.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/libnetlink.h
lib/libnetlink.c
lib/mnl_utils.c

index a7b0f352367d820274a9b184ab90181892b35b3b..1c49920d637ef9cfbebefce64412bf0df2aaedc3 100644 (file)
@@ -185,7 +185,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 nl_dump_ext_ack_done(const struct nlmsghdr *nlh, unsigned int offset, int error);
 
 int addattr(struct nlmsghdr *n, int maxlen, int type);
 int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data);
index c27627fed2d57007b3efc6827eec8ffc1e33c6b3..1461b1ca3e77ce857d36764af29182e75761a883 100644 (file)
@@ -129,13 +129,12 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
        return 0;
 }
 
-int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
+int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, unsigned int offset, int error)
 {
        struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
-       unsigned int hlen = sizeof(int);
        const char *msg = NULL;
 
-       if (mnl_attr_parse(nlh, hlen, err_attr_cb, tb) != MNL_CB_OK)
+       if (mnl_attr_parse(nlh, offset, err_attr_cb, tb) != MNL_CB_OK)
                return 0;
 
        if (tb[NLMSGERR_ATTR_MSG])
@@ -159,7 +158,7 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
        return 0;
 }
 
-int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error)
+int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, unsigned int offset, int error)
 {
        return 0;
 }
@@ -747,7 +746,7 @@ static int rtnl_dump_done(struct nlmsghdr *h,
                        return 0;
 
                /* check for any messages returned from kernel */
-               if (nl_dump_ext_ack_done(h, len))
+               if (nl_dump_ext_ack_done(h, sizeof(int), len))
                        return len;
 
                switch (errno) {
index 79bac5cfd4de3d3607cb1fb0221d9d1b618bfa1c..f8e07d2f467f5e10ded015f2b205c0de8fbf9ce3 100644 (file)
@@ -79,7 +79,7 @@ static int mnlu_cb_stop(const struct nlmsghdr *nlh, void *data)
 
        if (len < 0) {
                errno = -len;
-               nl_dump_ext_ack_done(nlh, len);
+               nl_dump_ext_ack_done(nlh, sizeof(int), len);
                return MNL_CB_ERROR;
        }
        return MNL_CB_STOP;