Commit 0daf4349 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller

bpf, net: add skb_mac_header_len helper

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: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a68491f8
...@@ -2206,6 +2206,11 @@ static inline int skb_mac_offset(const struct sk_buff *skb) ...@@ -2206,6 +2206,11 @@ static inline int skb_mac_offset(const struct sk_buff *skb)
return skb_mac_header(skb) - skb->data; 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) static inline int skb_mac_header_was_set(const struct sk_buff *skb)
{ {
return skb->mac_header != (typeof(skb->mac_header))~0U; return skb->mac_header != (typeof(skb->mac_header))~0U;
......
...@@ -2012,7 +2012,7 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len) ...@@ -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) static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
{ {
const u32 len_diff = sizeof(struct ipv6hdr) - sizeof(struct iphdr); 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; int ret;
ret = skb_cow(skb, len_diff); ret = skb_cow(skb, len_diff);
...@@ -2048,7 +2048,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb) ...@@ -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) static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
{ {
const u32 len_diff = sizeof(struct ipv6hdr) - sizeof(struct iphdr); 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; int ret;
ret = skb_unclone(skb, GFP_ATOMIC); ret = skb_unclone(skb, GFP_ATOMIC);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment