From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nf-next,v3 1/6] netfilter: nft_payload: access GRE payload via inner offset
Date: Fri, 7 Oct 2022 11:16:09 +0200 [thread overview]
Message-ID: <20221007091614.339582-2-pablo@netfilter.org> (raw)
In-Reply-To: <20221007091614.339582-1-pablo@netfilter.org>
Parse GRE packets to properly set up inner offset, this allow for
matching on inner headers. This includes support for GRE v0 and v1.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v3: handle GREv0 and GREv1.
net/netfilter/nft_payload.c | 38 +++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 99d971fc54ad..448e32750fa0 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -19,6 +19,8 @@
/* For layer 4 checksum field offset. */
#include <linux/tcp.h>
#include <linux/udp.h>
+#include <net/gre.h>
+#include <net/pptp.h>
#include <linux/icmpv6.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
@@ -100,6 +102,42 @@ static int __nft_payload_inner_offset(struct nft_pktinfo *pkt)
pkt->inneroff = thoff + __tcp_hdrlen(th);
}
break;
+ case IPPROTO_GRE: {
+ u32 offset = sizeof(struct gre_base_hdr), version;
+ struct gre_base_hdr *gre, _gre;
+
+ gre = skb_header_pointer(pkt->skb, thoff, sizeof(_gre), &_gre);
+ if (!gre)
+ return -1;
+
+ version = gre->flags & GRE_VERSION;
+ switch (version) {
+ case GRE_VERSION_0:
+ if (gre->flags & GRE_CSUM) {
+ offset += sizeof_field(struct gre_full_hdr, csum) +
+ sizeof_field(struct gre_full_hdr, reserved1);
+ }
+ if (gre->flags & GRE_KEY)
+ offset += sizeof_field(struct gre_full_hdr, key);
+
+ if (gre->flags & GRE_SEQ)
+ offset += sizeof_field(struct pptp_gre_header, seq);
+ break;
+ case GRE_VERSION_1:
+ offset += sizeof_field(struct pptp_gre_header, payload_len) +
+ sizeof_field(struct pptp_gre_header, call_id);
+
+ if (gre->flags & GRE_SEQ)
+ offset += sizeof_field(struct pptp_gre_header, seq);
+
+ if (gre->flags & GRE_ACK)
+ offset += sizeof_field(struct pptp_gre_header, ack);
+ break;
+ }
+
+ pkt->inneroff = thoff + offset;
+ }
+ break;
default:
return -1;
}
--
2.30.2
next prev parent reply other threads:[~2022-10-07 9:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-07 9:16 [PATCH nf-next,v3 0/6] nf_tables inner tunnel header match support Pablo Neira Ayuso
2022-10-07 9:16 ` Pablo Neira Ayuso [this message]
2022-10-07 9:16 ` [PATCH nf-next,v3 2/6] netfilter: nft_payload: access ipip payload for inner offset Pablo Neira Ayuso
2022-10-07 9:16 ` [PATCH nf-next,v3 3/6] netfilter: nft_inner: support for inner tunnel header matching Pablo Neira Ayuso
2022-10-07 9:16 ` [PATCH nf-next,v3 4/6] netfilter: nft_inner: add percpu inner context Pablo Neira Ayuso
2022-10-07 9:16 ` [PATCH nf-next,v3 5/6] netfilter: nft_meta: add inner match support Pablo Neira Ayuso
2022-10-07 9:16 ` [PATCH nf-next,v3 6/6] netfilter: nft_inner: add geneve support 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=20221007091614.339582-2-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).