summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/mnl.h4
-rw-r--r--include/netlink.h1
-rw-r--r--src/libnftables.c4
-rw-r--r--src/mnl.c22
-rw-r--r--src/netlink.c27
-rw-r--r--src/rule.c2
6 files changed, 27 insertions, 33 deletions
diff --git a/include/mnl.h b/include/mnl.h
index 3ddc82a0..676030e6 100644
--- a/include/mnl.h
+++ b/include/mnl.h
@@ -6,8 +6,8 @@
#include <rule.h>
#include <libmnl/libmnl.h>
-struct mnl_socket *netlink_open_sock(void);
-void netlink_close_sock(struct mnl_socket *nf_sock);
+struct mnl_socket *nft_mnl_socket_open(void);
+struct mnl_socket *nft_mnl_socket_reopen(struct mnl_socket *nf_sock);
uint32_t mnl_seqnum_alloc(uint32_t *seqnum);
uint16_t mnl_genid_get(struct netlink_ctx *ctx);
diff --git a/include/netlink.h b/include/netlink.h
index 66e400d8..af9313d5 100644
--- a/include/netlink.h
+++ b/include/netlink.h
@@ -157,7 +157,6 @@ extern void netlink_dump_obj(struct nftnl_obj *nlo, struct netlink_ctx *ctx);
extern int netlink_batch_send(struct netlink_ctx *ctx, struct list_head *err_list);
-extern struct mnl_socket *netlink_restart(struct mnl_socket *nf_sock);
#define netlink_abi_error() \
__netlink_abi_error(__FILE__, __LINE__, strerror(errno));
extern void __noreturn __netlink_abi_error(const char *file, int line, const char *reason);
diff --git a/src/libnftables.c b/src/libnftables.c
index 44869602..0731c532 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -129,7 +129,7 @@ void nft_ctx_clear_include_paths(struct nft_ctx *ctx)
static void nft_ctx_netlink_init(struct nft_ctx *ctx)
{
- ctx->nf_sock = netlink_open_sock();
+ ctx->nf_sock = nft_mnl_socket_open();
}
struct nft_ctx *nft_ctx_new(uint32_t flags)
@@ -266,7 +266,7 @@ const char *nft_ctx_get_error_buffer(struct nft_ctx *ctx)
void nft_ctx_free(struct nft_ctx *ctx)
{
if (ctx->nf_sock)
- netlink_close_sock(ctx->nf_sock);
+ mnl_socket_close(ctx->nf_sock);
exit_cookie(&ctx->output.output_cookie);
exit_cookie(&ctx->output.error_cookie);
diff --git a/src/mnl.c b/src/mnl.c
index 9a6248aa..84727094 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -28,10 +28,32 @@
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <fcntl.h>
#include <errno.h>
#include <utils.h>
#include <nftables.h>
+struct mnl_socket *nft_mnl_socket_open(void)
+{
+ struct mnl_socket *nf_sock;
+
+ nf_sock = mnl_socket_open(NETLINK_NETFILTER);
+ if (!nf_sock)
+ netlink_init_error();
+
+ if (fcntl(mnl_socket_get_fd(nf_sock), F_SETFL, O_NONBLOCK))
+ netlink_init_error();
+
+ return nf_sock;
+}
+
+struct mnl_socket *nft_mnl_socket_reopen(struct mnl_socket *nf_sock)
+{
+ mnl_socket_close(nf_sock);
+
+ return nft_mnl_socket_open();
+}
+
uint32_t mnl_seqnum_alloc(unsigned int *seqnum)
{
return (*seqnum)++;
diff --git a/src/netlink.c b/src/netlink.c
index 403780ff..8eb2ccad 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -10,7 +10,6 @@
*/
#include <string.h>
-#include <fcntl.h>
#include <errno.h>
#include <libmnl/libmnl.h>
#include <netinet/in.h>
@@ -53,32 +52,6 @@ const struct location netlink_location = {
.indesc = &indesc_netlink,
};
-struct mnl_socket *netlink_open_sock(void)
-{
- struct mnl_socket *nf_sock;
-
- nf_sock = mnl_socket_open(NETLINK_NETFILTER);
- if (nf_sock == NULL)
- netlink_init_error();
-
- if (fcntl(mnl_socket_get_fd(nf_sock), F_SETFL, O_NONBLOCK))
- netlink_init_error();
-
- return nf_sock;
-}
-
-void netlink_close_sock(struct mnl_socket *nf_sock)
-{
- if (nf_sock)
- mnl_socket_close(nf_sock);
-}
-
-struct mnl_socket *netlink_restart(struct mnl_socket *nf_sock)
-{
- netlink_close_sock(nf_sock);
- return netlink_open_sock();
-}
-
void __noreturn __netlink_abi_error(const char *file, int line,
const char *reason)
{
diff --git a/src/rule.c b/src/rule.c
index 12ac1310..9087fd2b 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -243,7 +243,7 @@ replay:
if (ret < 0) {
cache_release(cache);
if (errno == EINTR) {
- nft->nf_sock = netlink_restart(nft->nf_sock);
+ nft->nf_sock = nft_mnl_socket_reopen(nft->nf_sock);
goto replay;
}
return -1;