diff mbox series

[bpf-next,1/2] bpf: update skb->protocol in bpf_skb_net_grow

Message ID 20190422145059.125561-2-willemdebruijn.kernel@gmail.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series update skb->protocol in bpf_skb_net_grow | expand

Commit Message

Willem de Bruijn April 22, 2019, 2:50 p.m. UTC
From: Willem de Bruijn <willemb@google.com>

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>
---
 net/core/filter.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Y Song April 22, 2019, 11:35 p.m. UTC | #1
On Mon, Apr 22, 2019 at 7:58 AM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> From: Willem de Bruijn <willemb@google.com>
>
> 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>

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>  net/core/filter.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 1833926a63fc1..bd4d498fabfa4 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3047,6 +3047,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)) {
> --
> 2.21.0.593.g511ec345e18-goog
>
diff mbox series

Patch

diff --git a/net/core/filter.c b/net/core/filter.c
index 1833926a63fc1..bd4d498fabfa4 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3047,6 +3047,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)) {