]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
bpf, net: add skb_mac_header_len helper
authorDaniel Borkmann <daniel@iogearbox.net>
Sun, 2 Jul 2017 00:13:25 +0000 (02:13 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Jul 2017 09:22:51 +0000 (02:22 -0700)
Add a small skb_mac_header_len() helper similarly as the
skb_network_header_len() we have and replace open coded
places in BPF's bpf_skb_change_proto() helper. Will also
be used in upcoming work.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/skbuff.h
net/core/filter.c

index d0b9f3846eabfceaab04359d796733e74ff3fd54..3d3ceaac13b18b49f5b459cffc027ac003530f1d 100644 (file)
@@ -2206,6 +2206,11 @@ static inline int skb_mac_offset(const struct sk_buff *skb)
        return skb_mac_header(skb) - skb->data;
 }
 
+static inline u32 skb_mac_header_len(const struct sk_buff *skb)
+{
+       return skb->network_header - skb->mac_header;
+}
+
 static inline int skb_mac_header_was_set(const struct sk_buff *skb)
 {
        return skb->mac_header != (typeof(skb->mac_header))~0U;
index e5c280aa5de60575aceb0172f930a84617da34b6..68d8cd865c4acd2395e2bb8fc52d19fe4549025e 100644 (file)
@@ -2012,7 +2012,7 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len)
 static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
 {
        const u32 len_diff = sizeof(struct ipv6hdr) - sizeof(struct iphdr);
-       u32 off = skb->network_header - skb->mac_header;
+       u32 off = skb_mac_header_len(skb);
        int ret;
 
        ret = skb_cow(skb, len_diff);
@@ -2048,7 +2048,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
 static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
 {
        const u32 len_diff = sizeof(struct ipv6hdr) - sizeof(struct iphdr);
-       u32 off = skb->network_header - skb->mac_header;
+       u32 off = skb_mac_header_len(skb);
        int ret;
 
        ret = skb_unclone(skb, GFP_ATOMIC);