]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: move socket open and reopen to mnl.c
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 23 Oct 2018 16:24:31 +0000 (18:24 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 23 Oct 2018 16:26:05 +0000 (18:26 +0200)
These functions are part of the mnl backend, move them there. Remove
netlink_close_sock(), use direct call to mnl_socket_close().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/mnl.h
include/netlink.h
src/libnftables.c
src/mnl.c
src/netlink.c
src/rule.c

index 3ddc82a05cb0e928b7a2b0246da323f7340d795f..676030e6c4c65d01bb2b3dcae5f8287c9d989da7 100644 (file)
@@ -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);
index 66e400d88f19a53c605811a4ccea01ceece6759d..af9313d514537a06e5f1f9d2b577d484aa4d5a7d 100644 (file)
@@ -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);
index 44869602c875e76bcd1fec099e505c79b485ae1c..0731c532a22a75257b863457c0005d115f92b80d 100644 (file)
@@ -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);
index 9a6248aa0ad97b06d9a39e984eba0d47f157e15b..84727094e27e5e4f88586cbe90e2392e04d2616a 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
 #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)++;
index 403780ffdefb7b7ea2449de2caf9676f7ff19296..8eb2ccad2f8ca6d5310c1c7dc6fcca93f0ec2df3 100644 (file)
@@ -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)
 {
index 12ac1310034d909362f52d4fbd632a6547bfdfec..9087fd2bd193ebe50b33c355d875d47cae875286 100644 (file)
@@ -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;