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>
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,
NFT_EXIT_SUCCESS = 0,
NFT_EXIT_FAILURE = 1,
NFT_EXIT_NOMEM = 2,
+ NFT_EXIT_NONL = 3,
};
struct input_descriptor;
#include <libmnl/libmnl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <stdlib.h>
#include <libnftnl/table.h>
#include <libnftnl/chain.h>
{
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();
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;