Skip to content

Commit

Permalink
netfilter: nf_tables: add nft_payload_rebuild_vlan_hdr()
Browse files Browse the repository at this point in the history
Wrap the code to rebuild the ethernet + vlan header into a function.

Signed-off-by: Pablo Neira Ayuso <[email protected]>
Acked-by: Florian Westphal <[email protected]>
  • Loading branch information
ummakynes committed Nov 13, 2019
1 parent f41f72d commit 8dfd8b0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions net/netfilter/nft_payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand Down

0 comments on commit 8dfd8b0

Please sign in to comment.