From c8b6092b4fec23b823695c0c9b10325f9c33150c Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Mon, 22 Oct 2018 21:20:44 +0200
Subject: [PATCH] netlink: reset mnl_socket field in struct nft_ctx on EINTR
Otherwise we keep using the old netlink socket if we hit EINTR.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
(cherry picked from commit d7ef1e206bd9b36607dddcf337fada11d743b61f)
Conflicts:
include/netlink.h
-> Missing upstream commit 0562beb6544d3 ("src: get rid of netlink_genid_get()")
Signed-off-by: Phil Sutter <psutter@redhat.com>
---
include/netlink.h | 2 +-
src/netlink.c | 4 ++--
src/rule.c | 3 +--
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/include/netlink.h b/include/netlink.h
index 31465ff16822e..894bf6fc98487 100644
--- a/include/netlink.h
+++ b/include/netlink.h
@@ -191,7 +191,7 @@ 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 uint16_t netlink_genid_get(struct netlink_ctx *ctx);
-extern void netlink_restart(struct mnl_socket *nf_sock);
+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/netlink.c b/src/netlink.c
index e16eb504fdef8..c178be3c9ee26 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -73,10 +73,10 @@ void netlink_close_sock(struct mnl_socket *nf_sock)
mnl_socket_close(nf_sock);
}
-void netlink_restart(struct mnl_socket *nf_sock)
+struct mnl_socket *netlink_restart(struct mnl_socket *nf_sock)
{
netlink_close_sock(nf_sock);
- nf_sock = netlink_open_sock();
+ return netlink_open_sock();
}
uint16_t netlink_genid_get(struct netlink_ctx *ctx)
diff --git a/src/rule.c b/src/rule.c
index 6acfa3ac1695c..47b0d30cbed18 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -161,7 +161,6 @@ int cache_update(struct nft_ctx *nft, enum cmd_ops cmd, struct list_head *msgs)
.msgs = msgs,
.nft = nft,
};
- struct mnl_socket *nf_sock = nft->nf_sock;
struct nft_cache *cache = &nft->cache;
replay:
@@ -176,7 +175,7 @@ replay:
if (ret < 0) {
cache_release(cache);
if (errno == EINTR) {
- netlink_restart(nf_sock);
+ nft->nf_sock = netlink_restart(nft->nf_sock);
goto replay;
}
return -1;
--
2.21.0