summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-10-22 21:20:44 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-22 21:45:37 +0200
commitd7ef1e206bd9b36607dddcf337fada11d743b61f (patch)
tree11885479b860f6e9ec278ace76e4c1c7f01ee47e
parent2dc07bcd7eaa56369dff01b596acf010308007d3 (diff)
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>
-rw-r--r--include/netlink.h2
-rw-r--r--src/netlink.c4
-rw-r--r--src/rule.c3
3 files changed, 4 insertions, 5 deletions
diff --git a/include/netlink.h b/include/netlink.h
index b26ef459..66e400d8 100644
--- a/include/netlink.h
+++ b/include/netlink.h
@@ -157,7 +157,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 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 755949c9..403780ff 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();
}
void __noreturn __netlink_abi_error(const char *file, int line,
diff --git a/src/rule.c b/src/rule.c
index 9e24c35c..12ac1310 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -229,7 +229,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:
@@ -244,7 +243,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;