Skip to content

Commit

Permalink
bpf: update skb->protocol in bpf_skb_net_grow
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Willem de Bruijn authored and Daniel Borkmann committed Apr 23, 2019
1 parent 2aad326 commit 1b00e0d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 1b00e0d

Please sign in to comment.