diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-10-31 17:51:22 +0300 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-11-13 12:41:35 +0300 |
commit | 8dfd8b09aa347ec96db3b355ad5c82fc6c837bfa (patch) | |
tree | 2a79ea78872d353bbe49ea4dba85fadebb4b04fe /net/netfilter | |
parent | f41f72d09ee1e9a980a1675be31120f547f2a648 (diff) | |
download | linux-8dfd8b09aa347ec96db3b355ad5c82fc6c837bfa.tar.xz |
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>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/nft_payload.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c index 247799801165..3db9c802ea62 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; |