Skip to content

Commit 8dfd8b0

Browse files
committed
netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr()
Wrap the code to rebuild the ethernet + vlan header into a function. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Acked-by: Florian Westphal <fw@strlen.de>
1 parent f41f72d commit 8dfd8b0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

net/netfilter/nft_payload.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
#include <linux/ip.h>
2424
#include <linux/ipv6.h>
2525

26+
static bool nft_payload_rebuild_vlan_hdr(const struct sk_buff *skb, int mac_off,
27+
struct vlan_ethhdr *veth)
28+
{
29+
if (skb_copy_bits(skb, mac_off, veth, ETH_HLEN))
30+
return false;
31+
32+
veth->h_vlan_proto = skb->vlan_proto;
33+
veth->h_vlan_TCI = htons(skb_vlan_tag_get(skb));
34+
veth->h_vlan_encapsulated_proto = skb->protocol;
35+
36+
return true;
37+
}
38+
2639
/* add vlan header into the user buffer for if tag was removed by offloads */
2740
static bool
2841
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)
3548
if (offset < VLAN_ETH_HLEN) {
3649
u8 ethlen = len;
3750

38-
if (skb_copy_bits(skb, mac_off, &veth, ETH_HLEN))
51+
if (!nft_payload_rebuild_vlan_hdr(skb, mac_off, &veth))
3952
return false;
4053

41-
veth.h_vlan_proto = skb->vlan_proto;
42-
veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
43-
veth.h_vlan_encapsulated_proto = skb->protocol;
44-
4554
if (offset + len > VLAN_ETH_HLEN)
4655
ethlen -= offset + len - VLAN_ETH_HLEN;
4756

0 commit comments

Comments
 (0)