From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] mnl: remove nft_mnl_socket_reopen()
Date: Tue, 2 Mar 2021 12:48:46 +0100 [thread overview]
Message-ID: <20210302114847.3865-1-pablo@netfilter.org> (raw)
nft_mnl_socket_reopen() was introduced to deal with the EINTR case.
By reopening the netlink socket, pending netlink messages that are part
part of a stale netlink dump are implicitly drop. This patch replaces
the nft_mnl_socket_reopen() strategy by pulling out all of the remaining
netlink message to restart in a clean state.
This is implicitly fixing up a bug in the table ownership support, which
assumes that the netlink socket remains open until nft_ctx_free() is
invoked.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/mnl.h | 1 -
src/mnl.c | 20 +++++++++++---------
src/rule.c | 5 ++---
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/include/mnl.h b/include/mnl.h
index 74b1b56fd686..979929c31c17 100644
--- a/include/mnl.h
+++ b/include/mnl.h
@@ -7,7 +7,6 @@
#include <libmnl/libmnl.h>
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);
uint32_t mnl_genid_get(struct netlink_ctx *ctx);
diff --git a/src/mnl.c b/src/mnl.c
index 84cfb2380f55..2ae69c6f185e 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -52,13 +52,6 @@ struct mnl_socket *nft_mnl_socket_open(void)
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)++;
@@ -77,17 +70,26 @@ nft_mnl_recv(struct netlink_ctx *ctx, uint32_t portid,
int (*cb)(const struct nlmsghdr *nlh, void *data), void *cb_data)
{
char buf[NFT_NLMSG_MAXSIZE];
+ bool eintr = false;
int ret;
ret = mnl_socket_recvfrom(ctx->nft->nf_sock, buf, sizeof(buf));
while (ret > 0) {
ret = mnl_cb_run(buf, ret, ctx->seqnum, portid, cb, cb_data);
- if (ret <= 0)
- goto out;
+ if (ret <= 0) {
+ if (errno != EINTR)
+ goto out;
+
+ eintr = true;
+ }
ret = mnl_socket_recvfrom(ctx->nft->nf_sock, buf, sizeof(buf));
}
out:
+ if (eintr) {
+ ret = -1;
+ errno = EINTR;
+ }
if (ret < 0 && errno == EAGAIN)
return 0;
diff --git a/src/rule.c b/src/rule.c
index acb10f65a517..367c5c8be952 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -292,10 +292,9 @@ replay:
ret = cache_init(&ctx, flags);
if (ret < 0) {
cache_release(cache);
- if (errno == EINTR) {
- nft->nf_sock = nft_mnl_socket_reopen(nft->nf_sock);
+ if (errno == EINTR)
goto replay;
- }
+
return -1;
}
--
2.20.1
next reply other threads:[~2021-03-02 23:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 11:48 Pablo Neira Ayuso [this message]
2021-03-02 11:48 ` [PATCH nft] cache: memleak list of chain Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210302114847.3865-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).