diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2014-04-14 12:17:41 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-04-25 17:45:32 +0200 |
commit | 1be55ff3a9866cbee8fcde8d8f9425cb3d8af05d (patch) | |
tree | c5b1c78c04706938446b6d18a8ae5996fe16b455 /src | |
parent | 3e1c7b67837228e6b6b6c8cbd74500a9369c77c6 (diff) |
netlink: add socket error reporting helper function
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/netlink.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/netlink.c b/src/netlink.c index 025566ad..10951f96 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -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; |