From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH iptables-nft 6/7] nft-shared: add tcp flag dissection
Date: Tue, 25 Jan 2022 17:53:00 +0100 [thread overview]
Message-ID: <20220125165301.5960-7-fw@strlen.de> (raw)
In-Reply-To: <20220125165301.5960-1-fw@strlen.de>
Detect payload load of th->flags and convert it to xt tcp match
structure.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
iptables/nft-shared.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c
index 19c82854f758..74f08c8966ee 100644
--- a/iptables/nft-shared.c
+++ b/iptables/nft-shared.c
@@ -751,6 +751,22 @@ static void nft_complete_th_port_range(struct nft_xt_ctx *ctx,
}
}
+static void nft_complete_tcp_flags(struct nft_xt_ctx *ctx,
+ struct iptables_command_state *cs,
+ uint8_t op,
+ uint8_t flags,
+ uint8_t mask)
+{
+ struct xt_tcp *tcp = nft_tcp_match(ctx, cs);
+
+ if (!tcp)
+ return;
+
+ if (op == NFT_CMP_NEQ)
+ tcp->invflags |= XT_TCP_INV_FLAGS;
+ tcp->flg_cmp = flags;
+ tcp->flg_mask = mask;
+}
static void nft_complete_transport(struct nft_xt_ctx *ctx,
struct nftnl_expr *e, void *data)
@@ -797,6 +813,18 @@ static void nft_complete_transport(struct nft_xt_ctx *ctx,
return;
}
break;
+ case 13: /* th->flags */
+ if (len == 1 && proto == IPPROTO_TCP) {
+ uint8_t flags = nftnl_expr_get_u8(e, NFTNL_EXPR_CMP_DATA);
+ uint8_t mask = ~0;
+
+ if (ctx->flags & NFT_XT_CTX_BITWISE) {
+ memcpy(&mask, &ctx->bitwise.mask, sizeof(mask));
+ ctx->flags &= ~NFT_XT_CTX_BITWISE;
+ }
+ nft_complete_tcp_flags(ctx, cs, op, flags, mask);
+ }
+ return;
}
}
--
2.34.1
next prev parent reply other threads:[~2022-01-25 16:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 16:52 [PATCH iptables-nft 0/7] iptables: prefer native expressions for udp and tcp matches Florian Westphal
2022-01-25 16:52 ` [PATCH iptables-nft 1/7] nft-shared: support native tcp port delinearize Florian Westphal
2022-01-25 16:52 ` [PATCH iptables-nft 2/7] nft-shared: support native tcp port range delinearize Florian Westphal
2022-01-25 16:52 ` [PATCH iptables-nft 3/7] nft-shared: support native udp port delinearize Florian Westphal
2022-01-25 16:52 ` [PATCH iptables-nft 4/7] nft: prefer native expressions instead of udp match Florian Westphal
2022-01-25 16:52 ` [PATCH iptables-nft 5/7] nft: prefer native expressions instead of tcp match Florian Westphal
2022-01-25 16:53 ` Florian Westphal [this message]
2022-01-25 16:53 ` [PATCH iptables-nft 7/7] nft: add support for native tcp flag matching Florian Westphal
2022-01-29 12:44 ` [PATCH iptables-nft 0/7] iptables: prefer native expressions for udp and tcp matches Florian Westphal
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=20220125165301.5960-7-fw@strlen.de \
--to=fw@strlen.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.