netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf-next 0/2] Revisit vlan support
@ 2019-10-31 14:51 Pablo Neira Ayuso
  2019-10-31 14:51 ` [PATCH nf-next 1/2] netfilter: nft_payload: simplify vlan header handling Pablo Neira Ayuso
  2019-10-31 14:51 ` [PATCH nf-next 2/2] netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr() Pablo Neira Ayuso
  0 siblings, 2 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-31 14:51 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fw

Hi Florian,

This is an preparation patchset that revisits the vlan support.

I have a few more patches waiting in my queue, please, have a look and
let me know if I'm overlooking anything in this clean-up.

Thanks.

Pablo Neira Ayuso (2):
  netfilter: nft_payload: simplify vlan header handling
  netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr()

 net/netfilter/nft_payload.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

-- 
2.11.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH nf-next 1/2] netfilter: nft_payload: simplify vlan header handling
  2019-10-31 14:51 [PATCH nf-next 0/2] Revisit vlan support Pablo Neira Ayuso
@ 2019-10-31 14:51 ` Pablo Neira Ayuso
  2019-10-31 16:18   ` Florian Westphal
  2019-10-31 14:51 ` [PATCH nf-next 2/2] netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr() Pablo Neira Ayuso
  1 sibling, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-31 14:51 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fw

If the offset is within the ethernet + vlan header size boundary, then
rebuild the ethernet + vlan header and use it to copy the bytes to the
register. Otherwise, subtract the vlan header size from the offset and
fall back to use skb_copy_bits().

There is one corner case though: If the offset plus the length of the
payload instruction goes over the ethernet + vlan header boundary, then,
fetch as many bytes as possible from the rebuilt ethernet + vlan header
and fall back to copy the remaining bytes through skb_copy_bits().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_payload.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 22a80eb60222..87f6f5269be6 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -28,17 +28,22 @@ static bool
 nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len)
 {
 	int mac_off = skb_mac_header(skb) - skb->data;
-	u8 vlan_len, *vlanh, *dst_u8 = (u8 *) d;
+	u8 *vlanh, *dst_u8 = (u8 *) d;
 	struct vlan_ethhdr veth;
 
 	vlanh = (u8 *) &veth;
-	if (offset < ETH_HLEN) {
-		u8 ethlen = min_t(u8, len, ETH_HLEN - offset);
+	if (offset < VLAN_ETH_HLEN) {
+		u8 ethlen = len;
 
 		if (skb_copy_bits(skb, mac_off, &veth, ETH_HLEN))
 			return false;
 
 		veth.h_vlan_proto = skb->vlan_proto;
+		veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
+		veth.h_vlan_encapsulated_proto = skb->protocol;
+
+		if (offset + len > VLAN_ETH_HLEN)
+			ethlen -= offset + len - VLAN_ETH_HLEN;
 
 		memcpy(dst_u8, vlanh + offset, ethlen);
 
@@ -48,25 +53,10 @@ nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len)
 
 		dst_u8 += ethlen;
 		offset = ETH_HLEN;
-	} else if (offset >= VLAN_ETH_HLEN) {
+	} else {
 		offset -= VLAN_HLEN;
-		goto skip;
 	}
 
-	veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
-	veth.h_vlan_encapsulated_proto = skb->protocol;
-
-	vlanh += offset;
-
-	vlan_len = min_t(u8, len, VLAN_ETH_HLEN - offset);
-	memcpy(dst_u8, vlanh, vlan_len);
-
-	len -= vlan_len;
-	if (!len)
-		return true;
-
-	dst_u8 += vlan_len;
- skip:
 	return skb_copy_bits(skb, offset + mac_off, dst_u8, len) == 0;
 }
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH nf-next 2/2] netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr()
  2019-10-31 14:51 [PATCH nf-next 0/2] Revisit vlan support Pablo Neira Ayuso
  2019-10-31 14:51 ` [PATCH nf-next 1/2] netfilter: nft_payload: simplify vlan header handling Pablo Neira Ayuso
@ 2019-10-31 14:51 ` Pablo Neira Ayuso
  2019-10-31 16:14   ` Florian Westphal
  1 sibling, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-31 14:51 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fw

Wrap the code to rebuild the ethernet + vlan header into a function.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_payload.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 87f6f5269be6..5676e22b36bc 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -23,6 +23,19 @@
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 
+static bool nft_payload_rebuild_vlan_hdr(const struct sk_buff *skb, int mac_off,
+					 struct vlan_ethhdr *veth)
+{
+	if (skb_copy_bits(skb, mac_off, veth, ETH_HLEN))
+		return false;
+
+	veth->h_vlan_proto = skb->vlan_proto;
+	veth->h_vlan_TCI = htons(skb_vlan_tag_get(skb));
+	veth->h_vlan_encapsulated_proto = skb->protocol;
+
+	return true;
+}
+
 /* add vlan header into the user buffer for if tag was removed by offloads */
 static bool
 nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len)
@@ -35,13 +48,9 @@ nft_payload_copy_vlan(u32 *d, const struct sk_buff *skb, u8 offset, u8 len)
 	if (offset < VLAN_ETH_HLEN) {
 		u8 ethlen = len;
 
-		if (skb_copy_bits(skb, mac_off, &veth, ETH_HLEN))
+		if (!nft_payload_rebuild_vlan_hdr(skb, mac_off, &veth))
 			return false;
 
-		veth.h_vlan_proto = skb->vlan_proto;
-		veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
-		veth.h_vlan_encapsulated_proto = skb->protocol;
-
 		if (offset + len > VLAN_ETH_HLEN)
 			ethlen -= offset + len - VLAN_ETH_HLEN;
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH nf-next 2/2] netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr()
  2019-10-31 14:51 ` [PATCH nf-next 2/2] netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr() Pablo Neira Ayuso
@ 2019-10-31 16:14   ` Florian Westphal
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2019-10-31 16:14 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, fw

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> Wrap the code to rebuild the ethernet + vlan header into a function.

Acked-by: Florian Westphal <fw@strlen.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH nf-next 1/2] netfilter: nft_payload: simplify vlan header handling
  2019-10-31 14:51 ` [PATCH nf-next 1/2] netfilter: nft_payload: simplify vlan header handling Pablo Neira Ayuso
@ 2019-10-31 16:18   ` Florian Westphal
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2019-10-31 16:18 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, fw

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> If the offset is within the ethernet + vlan header size boundary, then
> rebuild the ethernet + vlan header and use it to copy the bytes to the
> register. Otherwise, subtract the vlan header size from the offset and
> fall back to use skb_copy_bits().
> 
> There is one corner case though: If the offset plus the length of the
> payload instruction goes over the ethernet + vlan header boundary, then,
> fetch as many bytes as possible from the rebuilt ethernet + vlan header
> and fall back to copy the remaining bytes through skb_copy_bits().

This looks simpler indeed.

Acked-by: Florian Westphal <fw@strlen.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-31 16:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 14:51 [PATCH nf-next 0/2] Revisit vlan support Pablo Neira Ayuso
2019-10-31 14:51 ` [PATCH nf-next 1/2] netfilter: nft_payload: simplify vlan header handling Pablo Neira Ayuso
2019-10-31 16:18   ` Florian Westphal
2019-10-31 14:51 ` [PATCH nf-next 2/2] netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr() Pablo Neira Ayuso
2019-10-31 16:14   ` Florian Westphal

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).