#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);
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);
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)
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);
#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)++;
*/
#include <string.h>
-#include <fcntl.h>
#include <errno.h>
#include <libmnl/libmnl.h>
#include <netinet/in.h>
.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)
{
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;