Skip to contentSkip to conversation

update skb->protocol in bpf_skb_net_grow

PATCH Applied Willem de Bruijn 3 participants 5 messages Apr 23, 2019

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover update skb->protocol in bpf_skb_net_grow

From: Willem de Bruijn <[email protected]>

Expand the tc tunnel encap support with protocols that convert the network layer protocol, such as 6in4. This is analogous to existing support in bpf_skb_proto_6_to_4.

Patch 1 implements the straightforward logic
Patch 2 tests it with a 6in4 tunnel

Changes v1->v2
- improve documentation in test

Willem de Bruijn (2):
bpf: update skb->protocol in bpf_skb_net_grow selftests/bpf: expand test_tc_tunnel with SIT encap

 net/core/filter.c                             |  8 +++
 tools/testing/selftests/bpf/config            |  1 +
 .../selftests/bpf/progs/test_tc_tunnel.c      | 64 +++++++++++++++++--
 tools/testing/selftests/bpf/test_tc_tunnel.sh | 20 +++++-
 4 files changed, 88 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.0.593.g511ec345e18-goog
#1 lore raw

PATCH v2 1/2 bpf: update skb->protocol in bpf_skb_net_grow

From: Willem de Bruijn <[email protected]>

Some tunnels, like sit, change the network protocol of packet. If so, update skb->protocol to match the new type.

---
 net/core/filter.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/core/filter.c +8 -0
index edb3a7c22f6c3..2f88baf39cc20 100644
@@ -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)) {
Signature · 1 line
2.21.0.593.g511ec345e18-goog
#2 lore raw

PATCH v2 2/2 selftests/bpf: expand test_tc_tunnel with SIT encap

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

So far, all BPF tc tunnel testcases encapsulate in the same network protocol. Add an encap testcase that requires updating skb->protocol.

The 6in4 tunnel encapsulates an IPv6 packet inside an IPv4 tunnel. Verify that bpf_skb_net_grow correctly updates skb->protocol to select the right protocol handler in __netif_receive_skb_core.

The BPF program should also manually update the link layer header to encode the right network protocol.

Changes v1->v2
- improve documentation of non-obvious logic

---
 tools/testing/selftests/bpf/config            |  1 +
 .../selftests/bpf/progs/test_tc_tunnel.c      | 64 +++++++++++++++++--
 tools/testing/selftests/bpf/test_tc_tunnel.sh | 20 +++++-
 3 files changed, 80 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/config +1 -0
index 8c976476f6fdc..f7a0744db31e1 100644
@@ -33,3 +33,4 @@ CONFIG_MPLS=y
 CONFIG_NET_MPLS_GSO=m
 CONFIG_MPLS_ROUTING=m
 CONFIG_MPLS_IPTUNNEL=m
+CONFIG_IPV6_SIT=m
tools/testing/selftests/bpf/progs/test_tc_tunnel.c +60 -4

95 lines not on this page · raw message

tools/testing/selftests/bpf/test_tc_tunnel.sh +19 -1
index d4d8d5d3b06e1..ff0d31d38061f 100755
@@ -97,6 +97,9 @@ if [[ "$#" -eq "0" ]]; then
 	echo "ip6ip6"
 	$0 ipv6 ip6tnl none 100
 
+	echo "sit"
+	$0 ipv6 sit none 100
+
 	for mac in none mpls eth ; do
 		echo "ip gre $mac"
 		$0 ipv4 gre $mac 100
@@ -211,11 +214,20 @@ else
 	targs=""
 fi
 
+# tunnel address family differs from inner for SIT
+if [[ "${tuntype}" == "sit" ]]; then
+	link_addr1="${ns1_v4}"
+	link_addr2="${ns2_v4}"
+else
+	link_addr1="${addr1}"
+	link_addr2="${addr2}"
+fi
+
 # serverside, insert decap module
 # server is still running
 # client can connect again
 ip netns exec "${ns2}" ip link add name testtun0 type "${ttype}" \
-	${tmode} remote "${addr1}" local "${addr2}" $targs
+	${tmode} remote "${link_addr1}" local "${link_addr2}" $targs
 
 expect_tun_fail=0
 
@@ -260,6 +272,12 @@ else
 	server_listen
 fi
 
+# bpf_skb_net_shrink does not take tunnel flags yet, cannot update L3.
+if [[ "${tuntype}" == "sit" ]]; then
+	echo OK
+	exit 0
+fi
+
 # serverside, use BPF for decap
 ip netns exec "${ns2}" ip link del dev testtun0
 ip netns exec "${ns2}" tc qdisc add dev veth2 clsact
Signature · 1 line
2.21.0.593.g511ec345e18-goog
Acked-by on v2 2/2
#3 lore raw

Re: [PATCH bpf-next v2 2/2] selftests/bpf: expand test_tc_tunnel with SIT encap

Quoted 9 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

So far, all BPF tc tunnel testcases encapsulate in the same network protocol. Add an encap testcase that requires updating skb->protocol.

The 6in4 tunnel encapsulates an IPv6 packet inside an IPv4 tunnel. Verify that bpf_skb_net_grow correctly updates skb->protocol to select the right protocol handler in __netif_receive_skb_core.

Quoted 8 lines

The BPF program should also manually update the link layer header to encode the right network protocol.

Changes v1->v2
- improve documentation of non-obvious logic

maintainer Applied
#4 lore raw
In reply to Willem de Bruijn
Quoted 16 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Expand the tc tunnel encap support with protocols that convert the network layer protocol, such as 6in4. This is analogous to existing support in bpf_skb_proto_6_to_4.

Patch 1 implements the straightforward logic
Patch 2 tests it with a 6in4 tunnel

Changes v1->v2
- improve documentation in test

Willem de Bruijn (2):
bpf: update skb->protocol in bpf_skb_net_grow selftests/bpf: expand test_tc_tunnel with SIT encap

Quoted 6 lines
 net/core/filter.c                             |  8 +++
 tools/testing/selftests/bpf/config            |  1 +
 .../selftests/bpf/progs/test_tc_tunnel.c      | 64 +++++++++++++++++--
 tools/testing/selftests/bpf/test_tc_tunnel.sh | 20 +++++-
 4 files changed, 88 insertions(+), 5 deletions(-)

Applied, thanks!