]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
mnl: fix error handling in mnl_batch_talk
authorEric Leblond <eric@regit.org>
Thu, 24 Aug 2017 15:07:37 +0000 (17:07 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 24 Aug 2017 17:20:31 +0000 (19:20 +0200)
If one of the command is failing we should return an error.

Pablo says: "This is not a real issue since nft_netlink() returns an
error in case the list of errors is not empty. But we can indeed
simplify things by removing that explicit assignment in nft_netlink() so
mnl_batch_talk() consistently reports when if an error has happened.

Signee-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/main.c
src/mnl.c

index 21bd74aa5fcf1cf5567c517b48d08dd3f7c0efb7..4abbdc066756bf0b305d5cc9f081b6e62fb0a444 100644 (file)
@@ -220,7 +220,6 @@ static int nft_netlink(struct nft_ctx *nft,
                                netlink_io_error(&ctx, &cmd->location,
                                                 "Could not process rule: %s",
                                                 strerror(err->err));
-                               ret = -1;
                                errno = err->err;
                                if (err->seqnum == cmd->seqnum) {
                                        mnl_err_list_free(err);
index a770dc567d9fb51bfad5990070c36571fed9a404..69e24071b8f1c304a97518980e0c672dbd821cd3 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -249,6 +249,7 @@ int mnl_batch_talk(struct netlink_ctx *ctx, struct list_head *err_list)
                .tv_sec         = 0,
                .tv_usec        = 0
        };
+       int err = 0;
 
        ret = mnl_nft_socket_sendmsg(ctx);
        if (ret == -1)
@@ -271,8 +272,10 @@ int mnl_batch_talk(struct netlink_ctx *ctx, struct list_head *err_list)
 
                ret = mnl_cb_run(rcv_buf, ret, 0, portid, &netlink_echo_callback, ctx);
                /* Continue on error, make sure we get all acknowledgments */
-               if (ret == -1)
+               if (ret == -1) {
                        mnl_err_list_node_add(err_list, errno, nlh->nlmsg_seq);
+                       err = -1;
+               }
 
                ret = select(fd+1, &readfds, NULL, NULL, &tv);
                if (ret == -1)
@@ -281,7 +284,7 @@ int mnl_batch_talk(struct netlink_ctx *ctx, struct list_head *err_list)
                FD_ZERO(&readfds);
                FD_SET(fd, &readfds);
        }
-       return ret;
+       return err;
 }
 
 int mnl_nft_rule_batch_add(struct nftnl_rule *nlr, struct nftnl_batch *batch,