summaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorWillem de Bruijn <willemb@google.com>2019-04-23 14:43:48 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2019-04-24 01:32:26 +0200
commit1b00e0dfe7d08a17d818c34d4c9968047a3f3e4b (patch)
tree5f8271f622c43b9ad32530d484dfdb28cf65297d /net/core
parent2aad32613c353b1e05da5994324bc5f20d0dd55a (diff)
downloadlinux-1b00e0dfe7d08a17d818c34d4c9968047a3f3e4b.tar.gz
linux-1b00e0dfe7d08a17d818c34d4c9968047a3f3e4b.tar.bz2
linux-1b00e0dfe7d08a17d818c34d4c9968047a3f3e4b.zip
bpf: update skb->protocol in bpf_skb_net_grow
Some tunnels, like sit, change the network protocol of packet. If so, update skb->protocol to match the new type. Signed-off-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/filter.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index edb3a7c22f6c..2f88baf39cc2 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3081,6 +3081,14 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
skb_set_transport_header(skb, mac_len + nh_len);
}
+
+ /* Match skb->protocol to new outer l3 protocol */
+ if (skb->protocol == htons(ETH_P_IP) &&
+ flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6)
+ skb->protocol = htons(ETH_P_IPV6);
+ else if (skb->protocol == htons(ETH_P_IPV6) &&
+ flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV4)
+ skb->protocol = htons(ETH_P_IP);
}
if (skb_is_gso(skb)) {