]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: add socket error reporting helper function
authorArturo Borrero <arturo.borrero.glez@gmail.com>
Mon, 14 Apr 2014 10:17:41 +0000 (12:17 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 25 Apr 2014 15:45:32 +0000 (17:45 +0200)
This patch adds a simple helper function to report errors while
opening the Netlink socket.

To help users to diagnose problems, a new NFT_EXIT_NONL exit code is included,
which is 3.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/netlink.h
include/nftables.h
src/netlink.c

index 4e3f8aa757ea00e89ff6c4ee2386e9196d3b8e78..1fb035626932b0a81ddbe9bbb8751931b2bbaf29 100644 (file)
@@ -138,6 +138,7 @@ extern void netlink_dump_set(struct nft_set *nls);
 extern int netlink_batch_send(struct list_head *err_list);
 extern int netlink_io_error(struct netlink_ctx *ctx,
                            const struct location *loc, const char *fmt, ...);
+extern void netlink_open_error(void) __noreturn;
 
 extern struct nft_ruleset *netlink_dump_ruleset(struct netlink_ctx *ctx,
                                                const struct handle *h,
index 7f3968d45cf2c8b434f7b229681d821e3c1e2622..3394e3247dd7f88f0c738d1584f6862ec1dab812 100644 (file)
@@ -39,6 +39,7 @@ enum nftables_exit_codes {
        NFT_EXIT_SUCCESS        = 0,
        NFT_EXIT_FAILURE        = 1,
        NFT_EXIT_NOMEM          = 2,
+       NFT_EXIT_NONL           = 3,
 };
 
 struct input_descriptor;
index 025566ada65de998f38442172bbe1dc0b9fd61a8..10951f9607ca6bbd126aa3298be624578712abf8 100644 (file)
@@ -15,6 +15,7 @@
 #include <libmnl/libmnl.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <stdlib.h>
 
 #include <libnftnl/table.h>
 #include <libnftnl/chain.h>
@@ -46,7 +47,7 @@ static void __init netlink_open_sock(void)
 {
        nf_sock = mnl_socket_open(NETLINK_NETFILTER);
        if (nf_sock == NULL)
-               memory_allocation_error();
+               netlink_open_error();
 
        fcntl(mnl_socket_get_fd(nf_sock), F_SETFL, O_NONBLOCK);
        mnl_batch_init();
@@ -73,6 +74,13 @@ int netlink_io_error(struct netlink_ctx *ctx, const struct location *loc,
        return -1;
 }
 
+void __noreturn netlink_open_error(void)
+{
+       fprintf(stderr, "E: Unable to open Netlink socket: %s\n",
+               strerror(errno));
+       exit(NFT_EXIT_NONL);
+}
+
 struct nft_table *alloc_nft_table(const struct handle *h)
 {
        struct nft_table *nlt;