bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net 0/2] some fixes for selftest/net
@ 2022-10-11  9:57 Wang Yufen
  2022-10-11  9:57 ` [net 1/2] selftests/net: fix opening object file failed Wang Yufen
  2022-10-11  9:57 ` [net 2/2] selftests/net: fix missing xdp_dummy Wang Yufen
  0 siblings, 2 replies; 11+ messages in thread
From: Wang Yufen @ 2022-10-11  9:57 UTC (permalink / raw)
  To: netdev; +Cc: bpf, davem, edumazet, kuba, pabeni, lina.wang, deso

Wang Yufen (2):
  selftests/net: fix opening object file failed
  selftests/net: fix missing xdp_dummy

 tools/testing/selftests/bpf/progs/nat6to4.c   | 285 ++++++++++++++++++++++++++
 tools/testing/selftests/net/Makefile          |   2 -
 tools/testing/selftests/net/bpf/Makefile      |  14 --
 tools/testing/selftests/net/bpf/nat6to4.c     | 285 --------------------------
 tools/testing/selftests/net/udpgro.sh         |   4 +-
 tools/testing/selftests/net/udpgro_bench.sh   |   4 +-
 tools/testing/selftests/net/udpgro_frglist.sh |  12 +-
 tools/testing/selftests/net/udpgro_fwd.sh     |   2 +-
 tools/testing/selftests/net/veth.sh           |   8 +-
 9 files changed, 300 insertions(+), 316 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/nat6to4.c
 delete mode 100644 tools/testing/selftests/net/bpf/Makefile
 delete mode 100644 tools/testing/selftests/net/bpf/nat6to4.c

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [net 1/2] selftests/net: fix opening object file failed
  2022-10-11  9:57 [net 0/2] some fixes for selftest/net Wang Yufen
@ 2022-10-11  9:57 ` Wang Yufen
  2022-10-13  1:51   ` Martin KaFai Lau
  2022-10-11  9:57 ` [net 2/2] selftests/net: fix missing xdp_dummy Wang Yufen
  1 sibling, 1 reply; 11+ messages in thread
From: Wang Yufen @ 2022-10-11  9:57 UTC (permalink / raw)
  To: netdev; +Cc: bpf, davem, edumazet, kuba, pabeni, lina.wang, deso

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="y", Size: 26704 bytes --]

The program file used in the udpgro_frglist testcase is "../bpf/nat6to4.o",
but the actual nat6to4.o file is in "bpf/" not "../bpf".
The following error occurs:
  Error opening object ../bpf/nat6to4.o: No such file or directory
  Cannot initialize ELF context!
  Unable to load program

In addition, all the kernel bpf source files are centred under the subdir
"progs" after commit bd4aed0ee73c ("selftests: bpf: centre kernel bpf
objects under new subdir "progs""). So mv nat6to4.c to "../bpf/progs" and
use "../bpf/nat6to4.bpf.o".

Fixes: edae34a3ed92 ("selftests net: add UDP GRO fraglist + bpf self-tests")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
---
 tools/testing/selftests/bpf/progs/nat6to4.c   | 285 ++++++++++++++++++++++++++
 tools/testing/selftests/net/Makefile          |   2 -
 tools/testing/selftests/net/bpf/Makefile      |  14 --
 tools/testing/selftests/net/bpf/nat6to4.c     | 285 --------------------------
 tools/testing/selftests/net/udpgro_frglist.sh |   8 +-
 5 files changed, 289 insertions(+), 305 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/nat6to4.c
 delete mode 100644 tools/testing/selftests/net/bpf/Makefile
 delete mode 100644 tools/testing/selftests/net/bpf/nat6to4.c

diff --git a/tools/testing/selftests/bpf/progs/nat6to4.c b/tools/testing/selftests/bpf/progs/nat6to4.c
new file mode 100644
index 0000000..ac54c36
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/nat6to4.c
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * This code is taken from the Android Open Source Project and the author
+ * (Maciej Żenczykowski) has gave permission to relicense it under the
+ * GPLv2. Therefore this program is free software;
+ * You can redistribute it and/or modify it under the terms of the GNU
+ * General Public License version 2 as published by the Free Software
+ * Foundation
+
+ * The original headers, including the original license headers, are
+ * included below for completeness.
+ *
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <linux/bpf.h>
+#include <linux/if.h>
+#include <linux/if_ether.h>
+#include <linux/if_packet.h>
+#include <linux/in.h>
+#include <linux/in6.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/pkt_cls.h>
+#include <linux/swab.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+
+#include <linux/udp.h>
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_endian.h>
+
+#define IP_DF 0x4000  // Flag: "Don't Fragment"
+
+SEC("schedcls/ingress6/nat_6")
+int sched_cls_ingress6_nat_6_prog(struct __sk_buff *skb)
+{
+	const int l2_header_size =  sizeof(struct ethhdr);
+	void *data = (void *)(long)skb->data;
+	const void *data_end = (void *)(long)skb->data_end;
+	const struct ethhdr * const eth = data;  // used iff is_ethernet
+	const struct ipv6hdr * const ip6 =  (void *)(eth + 1);
+
+	// Require ethernet dst mac address to be our unicast address.
+	if  (skb->pkt_type != PACKET_HOST)
+		return TC_ACT_OK;
+
+	// Must be meta-ethernet IPv6 frame
+	if (skb->protocol != bpf_htons(ETH_P_IPV6))
+		return TC_ACT_OK;
+
+	// Must have (ethernet and) ipv6 header
+	if (data + l2_header_size + sizeof(*ip6) > data_end)
+		return TC_ACT_OK;
+
+	// Ethertype - if present - must be IPv6
+	if (eth->h_proto != bpf_htons(ETH_P_IPV6))
+		return TC_ACT_OK;
+
+	// IP version must be 6
+	if (ip6->version != 6)
+		return TC_ACT_OK;
+	// Maximum IPv6 payload length that can be translated to IPv4
+	if (bpf_ntohs(ip6->payload_len) > 0xFFFF - sizeof(struct iphdr))
+		return TC_ACT_OK;
+	switch (ip6->nexthdr) {
+	case IPPROTO_TCP:  // For TCP & UDP the checksum neutrality of the chosen IPv6
+	case IPPROTO_UDP:  // address means there is no need to update their checksums.
+	case IPPROTO_GRE:  // We do not need to bother looking at GRE/ESP headers,
+	case IPPROTO_ESP:  // since there is never a checksum to update.
+		break;
+	default:  // do not know how to handle anything else
+		return TC_ACT_OK;
+	}
+
+	struct ethhdr eth2;  // used iff is_ethernet
+
+	eth2 = *eth;                     // Copy over the ethernet header (src/dst mac)
+	eth2.h_proto = bpf_htons(ETH_P_IP);  // But replace the ethertype
+
+	struct iphdr ip = {
+		.version = 4,                                                      // u4
+		.ihl = sizeof(struct iphdr) / sizeof(__u32),                       // u4
+		.tos = (ip6->priority << 4) + (ip6->flow_lbl[0] >> 4),             // u8
+		.tot_len = bpf_htons(bpf_ntohs(ip6->payload_len) + sizeof(struct iphdr)),  // u16
+		.id = 0,                                                           // u16
+		.frag_off = bpf_htons(IP_DF),                                          // u16
+		.ttl = ip6->hop_limit,                                             // u8
+		.protocol = ip6->nexthdr,                                          // u8
+		.check = 0,                                                        // u16
+		.saddr = 0x0201a8c0,                            // u32
+		.daddr = 0x0101a8c0,                                         // u32
+	};
+
+	// Calculate the IPv4 one's complement checksum of the IPv4 header.
+	__wsum sum4 = 0;
+
+	for (int i = 0; i < sizeof(ip) / sizeof(__u16); ++i)
+		sum4 += ((__u16 *)&ip)[i];
+
+	// Note that sum4 is guaranteed to be non-zero by virtue of ip.version == 4
+	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse u32 into range 1 .. 0x1FFFE
+	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse any potential carry into u16
+	ip.check = (__u16)~sum4;                // sum4 cannot be zero, so this is never 0xFFFF
+
+	// Calculate the *negative* IPv6 16-bit one's complement checksum of the IPv6 header.
+	__wsum sum6 = 0;
+	// We'll end up with a non-zero sum due to ip6->version == 6 (which has '0' bits)
+	for (int i = 0; i < sizeof(*ip6) / sizeof(__u16); ++i)
+		sum6 += ~((__u16 *)ip6)[i];  // note the bitwise negation
+
+	// Note that there is no L4 checksum update: we are relying on the checksum neutrality
+	// of the ipv6 address chosen by netd's ClatdController.
+
+	// Packet mutations begin - point of no return, but if this first modification fails
+	// the packet is probably still pristine, so let clatd handle it.
+	if (bpf_skb_change_proto(skb, bpf_htons(ETH_P_IP), 0))
+		return TC_ACT_OK;
+	bpf_csum_update(skb, sum6);
+
+	data = (void *)(long)skb->data;
+	data_end = (void *)(long)skb->data_end;
+	if (data + l2_header_size + sizeof(struct iphdr) > data_end)
+		return TC_ACT_SHOT;
+
+	struct ethhdr *new_eth = data;
+
+	// Copy over the updated ethernet header
+	*new_eth = eth2;
+
+	// Copy over the new ipv4 header.
+	*(struct iphdr *)(new_eth + 1) = ip;
+	return bpf_redirect(skb->ifindex, BPF_F_INGRESS);
+}
+
+SEC("schedcls/egress4/snat4")
+int sched_cls_egress4_snat4_prog(struct __sk_buff *skb)
+{
+	const int l2_header_size =  sizeof(struct ethhdr);
+	void *data = (void *)(long)skb->data;
+	const void *data_end = (void *)(long)skb->data_end;
+	const struct ethhdr *const eth = data;  // used iff is_ethernet
+	const struct iphdr *const ip4 = (void *)(eth + 1);
+
+	// Must be meta-ethernet IPv4 frame
+	if (skb->protocol != bpf_htons(ETH_P_IP))
+		return TC_ACT_OK;
+
+	// Must have ipv4 header
+	if (data + l2_header_size + sizeof(struct ipv6hdr) > data_end)
+		return TC_ACT_OK;
+
+	// Ethertype - if present - must be IPv4
+	if (eth->h_proto != bpf_htons(ETH_P_IP))
+		return TC_ACT_OK;
+
+	// IP version must be 4
+	if (ip4->version != 4)
+		return TC_ACT_OK;
+
+	// We cannot handle IP options, just standard 20 byte == 5 dword minimal IPv4 header
+	if (ip4->ihl != 5)
+		return TC_ACT_OK;
+
+	// Maximum IPv6 payload length that can be translated to IPv4
+	if (bpf_htons(ip4->tot_len) > 0xFFFF - sizeof(struct ipv6hdr))
+		return TC_ACT_OK;
+
+	// Calculate the IPv4 one's complement checksum of the IPv4 header.
+	__wsum sum4 = 0;
+
+	for (int i = 0; i < sizeof(*ip4) / sizeof(__u16); ++i)
+		sum4 += ((__u16 *)ip4)[i];
+
+	// Note that sum4 is guaranteed to be non-zero by virtue of ip4->version == 4
+	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse u32 into range 1 .. 0x1FFFE
+	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse any potential carry into u16
+	// for a correct checksum we should get *a* zero, but sum4 must be positive, ie 0xFFFF
+	if (sum4 != 0xFFFF)
+		return TC_ACT_OK;
+
+	// Minimum IPv4 total length is the size of the header
+	if (bpf_ntohs(ip4->tot_len) < sizeof(*ip4))
+		return TC_ACT_OK;
+
+	// We are incapable of dealing with IPv4 fragments
+	if (ip4->frag_off & ~bpf_htons(IP_DF))
+		return TC_ACT_OK;
+
+	switch (ip4->protocol) {
+	case IPPROTO_TCP:  // For TCP & UDP the checksum neutrality of the chosen IPv6
+	case IPPROTO_GRE:  // address means there is no need to update their checksums.
+	case IPPROTO_ESP:  // We do not need to bother looking at GRE/ESP headers,
+		break;         // since there is never a checksum to update.
+
+	case IPPROTO_UDP:  // See above comment, but must also have UDP header...
+		if (data + sizeof(*ip4) + sizeof(struct udphdr) > data_end)
+			return TC_ACT_OK;
+		const struct udphdr *uh = (const struct udphdr *)(ip4 + 1);
+		// If IPv4/UDP checksum is 0 then fallback to clatd so it can calculate the
+		// checksum.  Otherwise the network or more likely the NAT64 gateway might
+		// drop the packet because in most cases IPv6/UDP packets with a zero checksum
+		// are invalid. See RFC 6935.  TODO: calculate checksum via bpf_csum_diff()
+		if (!uh->check)
+			return TC_ACT_OK;
+		break;
+
+	default:  // do not know how to handle anything else
+		return TC_ACT_OK;
+	}
+	struct ethhdr eth2;  // used iff is_ethernet
+
+	eth2 = *eth;                     // Copy over the ethernet header (src/dst mac)
+	eth2.h_proto = bpf_htons(ETH_P_IPV6);  // But replace the ethertype
+
+	struct ipv6hdr ip6 = {
+		.version = 6,                                    // __u8:4
+		.priority = ip4->tos >> 4,                       // __u8:4
+		.flow_lbl = {(ip4->tos & 0xF) << 4, 0, 0},       // __u8[3]
+		.payload_len = bpf_htons(bpf_ntohs(ip4->tot_len) - 20),  // __be16
+		.nexthdr = ip4->protocol,                        // __u8
+		.hop_limit = ip4->ttl,                           // __u8
+	};
+	ip6.saddr.in6_u.u6_addr32[0] = bpf_htonl(0x20010db8);
+	ip6.saddr.in6_u.u6_addr32[1] = 0;
+	ip6.saddr.in6_u.u6_addr32[2] = 0;
+	ip6.saddr.in6_u.u6_addr32[3] = bpf_htonl(1);
+	ip6.daddr.in6_u.u6_addr32[0] = bpf_htonl(0x20010db8);
+	ip6.daddr.in6_u.u6_addr32[1] = 0;
+	ip6.daddr.in6_u.u6_addr32[2] = 0;
+	ip6.daddr.in6_u.u6_addr32[3] = bpf_htonl(2);
+
+	// Calculate the IPv6 16-bit one's complement checksum of the IPv6 header.
+	__wsum sum6 = 0;
+	// We'll end up with a non-zero sum due to ip6.version == 6
+	for (int i = 0; i < sizeof(ip6) / sizeof(__u16); ++i)
+		sum6 += ((__u16 *)&ip6)[i];
+
+	// Packet mutations begin - point of no return, but if this first modification fails
+	// the packet is probably still pristine, so let clatd handle it.
+	if (bpf_skb_change_proto(skb, bpf_htons(ETH_P_IPV6), 0))
+		return TC_ACT_OK;
+
+	// This takes care of updating the skb->csum field for a CHECKSUM_COMPLETE packet.
+	// In such a case, skb->csum is a 16-bit one's complement sum of the entire payload,
+	// thus we need to subtract out the ipv4 header's sum, and add in the ipv6 header's sum.
+	// However, we've already verified the ipv4 checksum is correct and thus 0.
+	// Thus we only need to add the ipv6 header's sum.
+	//
+	// bpf_csum_update() always succeeds if the skb is CHECKSUM_COMPLETE and returns an error
+	// (-ENOTSUPP) if it isn't.  So we just ignore the return code (see above for more details).
+	bpf_csum_update(skb, sum6);
+
+	// bpf_skb_change_proto() invalidates all pointers - reload them.
+	data = (void *)(long)skb->data;
+	data_end = (void *)(long)skb->data_end;
+
+	// I cannot think of any valid way for this error condition to trigger, however I do
+	// believe the explicit check is required to keep the in kernel ebpf verifier happy.
+	if (data + l2_header_size + sizeof(ip6) > data_end)
+		return TC_ACT_SHOT;
+
+	struct ethhdr *new_eth = data;
+
+	// Copy over the updated ethernet header
+	*new_eth = eth2;
+	// Copy over the new ipv4 header.
+	*(struct ipv6hdr *)(new_eth + 1) = ip6;
+	return TC_ACT_OK;
+}
+
+char _license[] SEC("license") = ("GPL");
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 2a6b0bc..79bc35e 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -75,8 +75,6 @@ TEST_FILES := settings
 
 include ../lib.mk
 
-include bpf/Makefile
-
 $(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
 $(OUTPUT)/tcp_mmap: LDLIBS += -lpthread
 $(OUTPUT)/tcp_inq: LDLIBS += -lpthread
diff --git a/tools/testing/selftests/net/bpf/Makefile b/tools/testing/selftests/net/bpf/Makefile
deleted file mode 100644
index 8ccaf87..0000000
--- a/tools/testing/selftests/net/bpf/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-
-CLANG ?= clang
-CCINCLUDE += -I../../bpf
-CCINCLUDE += -I../../../../lib
-CCINCLUDE += -I../../../../../usr/include/
-
-TEST_CUSTOM_PROGS = $(OUTPUT)/bpf/nat6to4.o
-all: $(TEST_CUSTOM_PROGS)
-
-$(OUTPUT)/%.o: %.c
-	$(CLANG) -O2 -target bpf -c $< $(CCINCLUDE) -o $@
-
-EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)
diff --git a/tools/testing/selftests/net/bpf/nat6to4.c b/tools/testing/selftests/net/bpf/nat6to4.c
deleted file mode 100644
index ac54c36..0000000
--- a/tools/testing/selftests/net/bpf/nat6to4.c
+++ /dev/null
@@ -1,285 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * This code is taken from the Android Open Source Project and the author
- * (Maciej Żenczykowski) has gave permission to relicense it under the
- * GPLv2. Therefore this program is free software;
- * You can redistribute it and/or modify it under the terms of the GNU
- * General Public License version 2 as published by the Free Software
- * Foundation
-
- * The original headers, including the original license headers, are
- * included below for completeness.
- *
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <linux/bpf.h>
-#include <linux/if.h>
-#include <linux/if_ether.h>
-#include <linux/if_packet.h>
-#include <linux/in.h>
-#include <linux/in6.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
-#include <linux/pkt_cls.h>
-#include <linux/swab.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-
-#include <linux/udp.h>
-
-#include <bpf/bpf_helpers.h>
-#include <bpf/bpf_endian.h>
-
-#define IP_DF 0x4000  // Flag: "Don't Fragment"
-
-SEC("schedcls/ingress6/nat_6")
-int sched_cls_ingress6_nat_6_prog(struct __sk_buff *skb)
-{
-	const int l2_header_size =  sizeof(struct ethhdr);
-	void *data = (void *)(long)skb->data;
-	const void *data_end = (void *)(long)skb->data_end;
-	const struct ethhdr * const eth = data;  // used iff is_ethernet
-	const struct ipv6hdr * const ip6 =  (void *)(eth + 1);
-
-	// Require ethernet dst mac address to be our unicast address.
-	if  (skb->pkt_type != PACKET_HOST)
-		return TC_ACT_OK;
-
-	// Must be meta-ethernet IPv6 frame
-	if (skb->protocol != bpf_htons(ETH_P_IPV6))
-		return TC_ACT_OK;
-
-	// Must have (ethernet and) ipv6 header
-	if (data + l2_header_size + sizeof(*ip6) > data_end)
-		return TC_ACT_OK;
-
-	// Ethertype - if present - must be IPv6
-	if (eth->h_proto != bpf_htons(ETH_P_IPV6))
-		return TC_ACT_OK;
-
-	// IP version must be 6
-	if (ip6->version != 6)
-		return TC_ACT_OK;
-	// Maximum IPv6 payload length that can be translated to IPv4
-	if (bpf_ntohs(ip6->payload_len) > 0xFFFF - sizeof(struct iphdr))
-		return TC_ACT_OK;
-	switch (ip6->nexthdr) {
-	case IPPROTO_TCP:  // For TCP & UDP the checksum neutrality of the chosen IPv6
-	case IPPROTO_UDP:  // address means there is no need to update their checksums.
-	case IPPROTO_GRE:  // We do not need to bother looking at GRE/ESP headers,
-	case IPPROTO_ESP:  // since there is never a checksum to update.
-		break;
-	default:  // do not know how to handle anything else
-		return TC_ACT_OK;
-	}
-
-	struct ethhdr eth2;  // used iff is_ethernet
-
-	eth2 = *eth;                     // Copy over the ethernet header (src/dst mac)
-	eth2.h_proto = bpf_htons(ETH_P_IP);  // But replace the ethertype
-
-	struct iphdr ip = {
-		.version = 4,                                                      // u4
-		.ihl = sizeof(struct iphdr) / sizeof(__u32),                       // u4
-		.tos = (ip6->priority << 4) + (ip6->flow_lbl[0] >> 4),             // u8
-		.tot_len = bpf_htons(bpf_ntohs(ip6->payload_len) + sizeof(struct iphdr)),  // u16
-		.id = 0,                                                           // u16
-		.frag_off = bpf_htons(IP_DF),                                          // u16
-		.ttl = ip6->hop_limit,                                             // u8
-		.protocol = ip6->nexthdr,                                          // u8
-		.check = 0,                                                        // u16
-		.saddr = 0x0201a8c0,                            // u32
-		.daddr = 0x0101a8c0,                                         // u32
-	};
-
-	// Calculate the IPv4 one's complement checksum of the IPv4 header.
-	__wsum sum4 = 0;
-
-	for (int i = 0; i < sizeof(ip) / sizeof(__u16); ++i)
-		sum4 += ((__u16 *)&ip)[i];
-
-	// Note that sum4 is guaranteed to be non-zero by virtue of ip.version == 4
-	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse u32 into range 1 .. 0x1FFFE
-	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse any potential carry into u16
-	ip.check = (__u16)~sum4;                // sum4 cannot be zero, so this is never 0xFFFF
-
-	// Calculate the *negative* IPv6 16-bit one's complement checksum of the IPv6 header.
-	__wsum sum6 = 0;
-	// We'll end up with a non-zero sum due to ip6->version == 6 (which has '0' bits)
-	for (int i = 0; i < sizeof(*ip6) / sizeof(__u16); ++i)
-		sum6 += ~((__u16 *)ip6)[i];  // note the bitwise negation
-
-	// Note that there is no L4 checksum update: we are relying on the checksum neutrality
-	// of the ipv6 address chosen by netd's ClatdController.
-
-	// Packet mutations begin - point of no return, but if this first modification fails
-	// the packet is probably still pristine, so let clatd handle it.
-	if (bpf_skb_change_proto(skb, bpf_htons(ETH_P_IP), 0))
-		return TC_ACT_OK;
-	bpf_csum_update(skb, sum6);
-
-	data = (void *)(long)skb->data;
-	data_end = (void *)(long)skb->data_end;
-	if (data + l2_header_size + sizeof(struct iphdr) > data_end)
-		return TC_ACT_SHOT;
-
-	struct ethhdr *new_eth = data;
-
-	// Copy over the updated ethernet header
-	*new_eth = eth2;
-
-	// Copy over the new ipv4 header.
-	*(struct iphdr *)(new_eth + 1) = ip;
-	return bpf_redirect(skb->ifindex, BPF_F_INGRESS);
-}
-
-SEC("schedcls/egress4/snat4")
-int sched_cls_egress4_snat4_prog(struct __sk_buff *skb)
-{
-	const int l2_header_size =  sizeof(struct ethhdr);
-	void *data = (void *)(long)skb->data;
-	const void *data_end = (void *)(long)skb->data_end;
-	const struct ethhdr *const eth = data;  // used iff is_ethernet
-	const struct iphdr *const ip4 = (void *)(eth + 1);
-
-	// Must be meta-ethernet IPv4 frame
-	if (skb->protocol != bpf_htons(ETH_P_IP))
-		return TC_ACT_OK;
-
-	// Must have ipv4 header
-	if (data + l2_header_size + sizeof(struct ipv6hdr) > data_end)
-		return TC_ACT_OK;
-
-	// Ethertype - if present - must be IPv4
-	if (eth->h_proto != bpf_htons(ETH_P_IP))
-		return TC_ACT_OK;
-
-	// IP version must be 4
-	if (ip4->version != 4)
-		return TC_ACT_OK;
-
-	// We cannot handle IP options, just standard 20 byte == 5 dword minimal IPv4 header
-	if (ip4->ihl != 5)
-		return TC_ACT_OK;
-
-	// Maximum IPv6 payload length that can be translated to IPv4
-	if (bpf_htons(ip4->tot_len) > 0xFFFF - sizeof(struct ipv6hdr))
-		return TC_ACT_OK;
-
-	// Calculate the IPv4 one's complement checksum of the IPv4 header.
-	__wsum sum4 = 0;
-
-	for (int i = 0; i < sizeof(*ip4) / sizeof(__u16); ++i)
-		sum4 += ((__u16 *)ip4)[i];
-
-	// Note that sum4 is guaranteed to be non-zero by virtue of ip4->version == 4
-	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse u32 into range 1 .. 0x1FFFE
-	sum4 = (sum4 & 0xFFFF) + (sum4 >> 16);  // collapse any potential carry into u16
-	// for a correct checksum we should get *a* zero, but sum4 must be positive, ie 0xFFFF
-	if (sum4 != 0xFFFF)
-		return TC_ACT_OK;
-
-	// Minimum IPv4 total length is the size of the header
-	if (bpf_ntohs(ip4->tot_len) < sizeof(*ip4))
-		return TC_ACT_OK;
-
-	// We are incapable of dealing with IPv4 fragments
-	if (ip4->frag_off & ~bpf_htons(IP_DF))
-		return TC_ACT_OK;
-
-	switch (ip4->protocol) {
-	case IPPROTO_TCP:  // For TCP & UDP the checksum neutrality of the chosen IPv6
-	case IPPROTO_GRE:  // address means there is no need to update their checksums.
-	case IPPROTO_ESP:  // We do not need to bother looking at GRE/ESP headers,
-		break;         // since there is never a checksum to update.
-
-	case IPPROTO_UDP:  // See above comment, but must also have UDP header...
-		if (data + sizeof(*ip4) + sizeof(struct udphdr) > data_end)
-			return TC_ACT_OK;
-		const struct udphdr *uh = (const struct udphdr *)(ip4 + 1);
-		// If IPv4/UDP checksum is 0 then fallback to clatd so it can calculate the
-		// checksum.  Otherwise the network or more likely the NAT64 gateway might
-		// drop the packet because in most cases IPv6/UDP packets with a zero checksum
-		// are invalid. See RFC 6935.  TODO: calculate checksum via bpf_csum_diff()
-		if (!uh->check)
-			return TC_ACT_OK;
-		break;
-
-	default:  // do not know how to handle anything else
-		return TC_ACT_OK;
-	}
-	struct ethhdr eth2;  // used iff is_ethernet
-
-	eth2 = *eth;                     // Copy over the ethernet header (src/dst mac)
-	eth2.h_proto = bpf_htons(ETH_P_IPV6);  // But replace the ethertype
-
-	struct ipv6hdr ip6 = {
-		.version = 6,                                    // __u8:4
-		.priority = ip4->tos >> 4,                       // __u8:4
-		.flow_lbl = {(ip4->tos & 0xF) << 4, 0, 0},       // __u8[3]
-		.payload_len = bpf_htons(bpf_ntohs(ip4->tot_len) - 20),  // __be16
-		.nexthdr = ip4->protocol,                        // __u8
-		.hop_limit = ip4->ttl,                           // __u8
-	};
-	ip6.saddr.in6_u.u6_addr32[0] = bpf_htonl(0x20010db8);
-	ip6.saddr.in6_u.u6_addr32[1] = 0;
-	ip6.saddr.in6_u.u6_addr32[2] = 0;
-	ip6.saddr.in6_u.u6_addr32[3] = bpf_htonl(1);
-	ip6.daddr.in6_u.u6_addr32[0] = bpf_htonl(0x20010db8);
-	ip6.daddr.in6_u.u6_addr32[1] = 0;
-	ip6.daddr.in6_u.u6_addr32[2] = 0;
-	ip6.daddr.in6_u.u6_addr32[3] = bpf_htonl(2);
-
-	// Calculate the IPv6 16-bit one's complement checksum of the IPv6 header.
-	__wsum sum6 = 0;
-	// We'll end up with a non-zero sum due to ip6.version == 6
-	for (int i = 0; i < sizeof(ip6) / sizeof(__u16); ++i)
-		sum6 += ((__u16 *)&ip6)[i];
-
-	// Packet mutations begin - point of no return, but if this first modification fails
-	// the packet is probably still pristine, so let clatd handle it.
-	if (bpf_skb_change_proto(skb, bpf_htons(ETH_P_IPV6), 0))
-		return TC_ACT_OK;
-
-	// This takes care of updating the skb->csum field for a CHECKSUM_COMPLETE packet.
-	// In such a case, skb->csum is a 16-bit one's complement sum of the entire payload,
-	// thus we need to subtract out the ipv4 header's sum, and add in the ipv6 header's sum.
-	// However, we've already verified the ipv4 checksum is correct and thus 0.
-	// Thus we only need to add the ipv6 header's sum.
-	//
-	// bpf_csum_update() always succeeds if the skb is CHECKSUM_COMPLETE and returns an error
-	// (-ENOTSUPP) if it isn't.  So we just ignore the return code (see above for more details).
-	bpf_csum_update(skb, sum6);
-
-	// bpf_skb_change_proto() invalidates all pointers - reload them.
-	data = (void *)(long)skb->data;
-	data_end = (void *)(long)skb->data_end;
-
-	// I cannot think of any valid way for this error condition to trigger, however I do
-	// believe the explicit check is required to keep the in kernel ebpf verifier happy.
-	if (data + l2_header_size + sizeof(ip6) > data_end)
-		return TC_ACT_SHOT;
-
-	struct ethhdr *new_eth = data;
-
-	// Copy over the updated ethernet header
-	*new_eth = eth2;
-	// Copy over the new ipv4 header.
-	*(struct ipv6hdr *)(new_eth + 1) = ip6;
-	return TC_ACT_OK;
-}
-
-char _license[] SEC("license") = ("GPL");
diff --git a/tools/testing/selftests/net/udpgro_frglist.sh b/tools/testing/selftests/net/udpgro_frglist.sh
index 832c738..be71583 100755
--- a/tools/testing/selftests/net/udpgro_frglist.sh
+++ b/tools/testing/selftests/net/udpgro_frglist.sh
@@ -38,8 +38,8 @@ run_one() {
 
 	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
 	tc -n "${PEER_NS}" qdisc add dev veth1 clsact
-	tc -n "${PEER_NS}" filter add dev veth1 ingress prio 4 protocol ipv6 bpf object-file ../bpf/nat6to4.o section schedcls/ingress6/nat_6  direct-action
-	tc -n "${PEER_NS}" filter add dev veth1 egress prio 4 protocol ip bpf object-file ../bpf/nat6to4.o section schedcls/egress4/snat4 direct-action
+	tc -n "${PEER_NS}" filter add dev veth1 ingress prio 4 protocol ipv6 bpf object-file ../bpf/nat6to4.bpf.o section schedcls/ingress6/nat_6  direct-action
+	tc -n "${PEER_NS}" filter add dev veth1 egress prio 4 protocol ip bpf object-file ../bpf/nat6to4.bpf.o section schedcls/egress4/snat4 direct-action
         echo ${rx_args}
 	ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
 
@@ -86,8 +86,8 @@ if [ ! -f ../bpf/xdp_dummy.o ]; then
 	exit -1
 fi
 
-if [ ! -f bpf/nat6to4.o ]; then
-	echo "Missing nat6to4 helper. Build bpfnat6to4.o selftest first"
+if [ ! -f ../bpf/nat6to4.bpf.o ]; then
+	echo "Missing nat6to4 helper. Build bpf selftest first"
 	exit -1
 fi
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [net 2/2] selftests/net: fix missing xdp_dummy
  2022-10-11  9:57 [net 0/2] some fixes for selftest/net Wang Yufen
  2022-10-11  9:57 ` [net 1/2] selftests/net: fix opening object file failed Wang Yufen
@ 2022-10-11  9:57 ` Wang Yufen
  2022-10-11 16:27   ` Daniel Müller
  1 sibling, 1 reply; 11+ messages in thread
From: Wang Yufen @ 2022-10-11  9:57 UTC (permalink / raw)
  To: netdev; +Cc: bpf, davem, edumazet, kuba, pabeni, lina.wang, deso

After commit afef88e65554 ("selftests/bpf: Store BPF object files with
.bpf.o extension"), we should use xdp_dummy.bpf.o instade of xdp_dummy.o.

Fixes: afef88e65554 ("selftests/bpf: Store BPF object files with .bpf.o extension")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
---
 tools/testing/selftests/net/udpgro.sh         | 4 ++--
 tools/testing/selftests/net/udpgro_bench.sh   | 4 ++--
 tools/testing/selftests/net/udpgro_frglist.sh | 4 ++--
 tools/testing/selftests/net/udpgro_fwd.sh     | 2 +-
 tools/testing/selftests/net/veth.sh           | 8 ++++----
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/net/udpgro.sh b/tools/testing/selftests/net/udpgro.sh
index ebbd0b2..e339e62 100755
--- a/tools/testing/selftests/net/udpgro.sh
+++ b/tools/testing/selftests/net/udpgro.sh
@@ -34,7 +34,7 @@ cfg_veth() {
 	ip -netns "${PEER_NS}" addr add dev veth1 192.168.1.1/24
 	ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad
 	ip -netns "${PEER_NS}" link set dev veth1 up
-	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
+	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.bpf.o section xdp
 }
 
 run_one() {
@@ -195,7 +195,7 @@ run_all() {
 	return $ret
 }
 
-if [ ! -f ../bpf/xdp_dummy.o ]; then
+if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
 	echo "Missing xdp_dummy helper. Build bpf selftest first"
 	exit -1
 fi
diff --git a/tools/testing/selftests/net/udpgro_bench.sh b/tools/testing/selftests/net/udpgro_bench.sh
index fad2d1a..94372ea 100755
--- a/tools/testing/selftests/net/udpgro_bench.sh
+++ b/tools/testing/selftests/net/udpgro_bench.sh
@@ -34,7 +34,7 @@ run_one() {
 	ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad
 	ip -netns "${PEER_NS}" link set dev veth1 up
 
-	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
+	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.bpf.o section xdp
 	ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
 	ip netns exec "${PEER_NS}" ./udpgso_bench_rx -t ${rx_args} -r &
 
@@ -80,7 +80,7 @@ run_all() {
 	run_udp "${ipv6_args}"
 }
 
-if [ ! -f ../bpf/xdp_dummy.o ]; then
+if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
 	echo "Missing xdp_dummy helper. Build bpf selftest first"
 	exit -1
 fi
diff --git a/tools/testing/selftests/net/udpgro_frglist.sh b/tools/testing/selftests/net/udpgro_frglist.sh
index be71583..6d51156 100755
--- a/tools/testing/selftests/net/udpgro_frglist.sh
+++ b/tools/testing/selftests/net/udpgro_frglist.sh
@@ -36,7 +36,7 @@ run_one() {
 	ip netns exec "${PEER_NS}" ethtool -K veth1 rx-gro-list on
 
 
-	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
+	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.bpf.o section xdp
 	tc -n "${PEER_NS}" qdisc add dev veth1 clsact
 	tc -n "${PEER_NS}" filter add dev veth1 ingress prio 4 protocol ipv6 bpf object-file ../bpf/nat6to4.bpf.o section schedcls/ingress6/nat_6  direct-action
 	tc -n "${PEER_NS}" filter add dev veth1 egress prio 4 protocol ip bpf object-file ../bpf/nat6to4.bpf.o section schedcls/egress4/snat4 direct-action
@@ -81,7 +81,7 @@ run_all() {
 	run_udp "${ipv6_args}"
 }
 
-if [ ! -f ../bpf/xdp_dummy.o ]; then
+if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
 	echo "Missing xdp_dummy helper. Build bpf selftest first"
 	exit -1
 fi
diff --git a/tools/testing/selftests/net/udpgro_fwd.sh b/tools/testing/selftests/net/udpgro_fwd.sh
index 1bcd82e..0c32ee4 100755
--- a/tools/testing/selftests/net/udpgro_fwd.sh
+++ b/tools/testing/selftests/net/udpgro_fwd.sh
@@ -46,7 +46,7 @@ create_ns() {
 		ip -n $BASE$ns addr add dev veth$ns $BM_NET_V4$ns/24
 		ip -n $BASE$ns addr add dev veth$ns $BM_NET_V6$ns/64 nodad
 	done
-	ip -n $NS_DST link set veth$DST xdp object ../bpf/xdp_dummy.o section xdp 2>/dev/null
+	ip -n $NS_DST link set veth$DST xdp object ../bpf/xdp_dummy.bpf.o section xdp 2>/dev/null
 }
 
 create_vxlan_endpoint() {
diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh
index 430895d..704cba3 100755
--- a/tools/testing/selftests/net/veth.sh
+++ b/tools/testing/selftests/net/veth.sh
@@ -216,7 +216,7 @@ while getopts "hs:" option; do
 	esac
 done
 
-if [ ! -f ../bpf/xdp_dummy.o ]; then
+if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
 	echo "Missing xdp_dummy helper. Build bpf selftest first"
 	exit 1
 fi
@@ -288,14 +288,14 @@ if [ $CPUS -gt 1 ]; then
 	ip netns exec $NS_DST ethtool -L veth$DST rx 1 tx 2 2>/dev/null
 	ip netns exec $NS_SRC ethtool -L veth$SRC rx 1 tx 2 2>/dev/null
 	printf "%-60s" "bad setting: XDP with RX nr less than TX"
-	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o \
+	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.bpf.o \
 		section xdp 2>/dev/null &&\
 		echo "fail - set operation successful ?!?" || echo " ok "
 
 	# the following tests will run with multiple channels active
 	ip netns exec $NS_SRC ethtool -L veth$SRC rx 2
 	ip netns exec $NS_DST ethtool -L veth$DST rx 2
-	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o \
+	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.bpf.o \
 		section xdp 2>/dev/null
 	printf "%-60s" "bad setting: reducing RX nr below peer TX with XDP set"
 	ip netns exec $NS_DST ethtool -L veth$DST rx 1 2>/dev/null &&\
@@ -311,7 +311,7 @@ if [ $CPUS -gt 2 ]; then
 	chk_channels "setting invalid channels nr" $DST 2 2
 fi
 
-ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o section xdp 2>/dev/null
+ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.bpf.o section xdp 2>/dev/null
 chk_gro_flag "with xdp attached - gro flag" $DST on
 chk_gro_flag "        - peer gro flag" $SRC off
 chk_tso_flag "        - tso flag" $SRC off
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [net 2/2] selftests/net: fix missing xdp_dummy
  2022-10-11  9:57 ` [net 2/2] selftests/net: fix missing xdp_dummy Wang Yufen
@ 2022-10-11 16:27   ` Daniel Müller
  0 siblings, 0 replies; 11+ messages in thread
From: Daniel Müller @ 2022-10-11 16:27 UTC (permalink / raw)
  To: Wang Yufen; +Cc: netdev, bpf, davem, edumazet, kuba, pabeni, lina.wang

On Tue, Oct 11, 2022 at 05:57:47PM +0800, Wang Yufen wrote:
> After commit afef88e65554 ("selftests/bpf: Store BPF object files with
> .bpf.o extension"), we should use xdp_dummy.bpf.o instade of xdp_dummy.o.

*instead

> 
> Fixes: afef88e65554 ("selftests/bpf: Store BPF object files with .bpf.o extension")
> Signed-off-by: Wang Yufen <wangyufen@huawei.com>
> ---
>  tools/testing/selftests/net/udpgro.sh         | 4 ++--
>  tools/testing/selftests/net/udpgro_bench.sh   | 4 ++--
>  tools/testing/selftests/net/udpgro_frglist.sh | 4 ++--
>  tools/testing/selftests/net/udpgro_fwd.sh     | 2 +-
>  tools/testing/selftests/net/veth.sh           | 8 ++++----
>  5 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/udpgro.sh b/tools/testing/selftests/net/udpgro.sh
> index ebbd0b2..e339e62 100755
> --- a/tools/testing/selftests/net/udpgro.sh
> +++ b/tools/testing/selftests/net/udpgro.sh
> @@ -34,7 +34,7 @@ cfg_veth() {
>  	ip -netns "${PEER_NS}" addr add dev veth1 192.168.1.1/24
>  	ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad
>  	ip -netns "${PEER_NS}" link set dev veth1 up
> -	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
> +	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.bpf.o section xdp
>  }
>  
>  run_one() {
> @@ -195,7 +195,7 @@ run_all() {
>  	return $ret
>  }
>  
> -if [ ! -f ../bpf/xdp_dummy.o ]; then
> +if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
>  	echo "Missing xdp_dummy helper. Build bpf selftest first"
>  	exit -1
>  fi
> diff --git a/tools/testing/selftests/net/udpgro_bench.sh b/tools/testing/selftests/net/udpgro_bench.sh
> index fad2d1a..94372ea 100755
> --- a/tools/testing/selftests/net/udpgro_bench.sh
> +++ b/tools/testing/selftests/net/udpgro_bench.sh
> @@ -34,7 +34,7 @@ run_one() {
>  	ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad
>  	ip -netns "${PEER_NS}" link set dev veth1 up
>  
> -	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
> +	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.bpf.o section xdp
>  	ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
>  	ip netns exec "${PEER_NS}" ./udpgso_bench_rx -t ${rx_args} -r &
>  
> @@ -80,7 +80,7 @@ run_all() {
>  	run_udp "${ipv6_args}"
>  }
>  
> -if [ ! -f ../bpf/xdp_dummy.o ]; then
> +if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
>  	echo "Missing xdp_dummy helper. Build bpf selftest first"
>  	exit -1
>  fi
> diff --git a/tools/testing/selftests/net/udpgro_frglist.sh b/tools/testing/selftests/net/udpgro_frglist.sh
> index be71583..6d51156 100755
> --- a/tools/testing/selftests/net/udpgro_frglist.sh
> +++ b/tools/testing/selftests/net/udpgro_frglist.sh
> @@ -36,7 +36,7 @@ run_one() {
>  	ip netns exec "${PEER_NS}" ethtool -K veth1 rx-gro-list on
>  
>  
> -	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
> +	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.bpf.o section xdp
>  	tc -n "${PEER_NS}" qdisc add dev veth1 clsact
>  	tc -n "${PEER_NS}" filter add dev veth1 ingress prio 4 protocol ipv6 bpf object-file ../bpf/nat6to4.bpf.o section schedcls/ingress6/nat_6  direct-action
>  	tc -n "${PEER_NS}" filter add dev veth1 egress prio 4 protocol ip bpf object-file ../bpf/nat6to4.bpf.o section schedcls/egress4/snat4 direct-action
> @@ -81,7 +81,7 @@ run_all() {
>  	run_udp "${ipv6_args}"
>  }
>  
> -if [ ! -f ../bpf/xdp_dummy.o ]; then
> +if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
>  	echo "Missing xdp_dummy helper. Build bpf selftest first"
>  	exit -1
>  fi
> diff --git a/tools/testing/selftests/net/udpgro_fwd.sh b/tools/testing/selftests/net/udpgro_fwd.sh
> index 1bcd82e..0c32ee4 100755
> --- a/tools/testing/selftests/net/udpgro_fwd.sh
> +++ b/tools/testing/selftests/net/udpgro_fwd.sh
> @@ -46,7 +46,7 @@ create_ns() {
>  		ip -n $BASE$ns addr add dev veth$ns $BM_NET_V4$ns/24
>  		ip -n $BASE$ns addr add dev veth$ns $BM_NET_V6$ns/64 nodad
>  	done
> -	ip -n $NS_DST link set veth$DST xdp object ../bpf/xdp_dummy.o section xdp 2>/dev/null
> +	ip -n $NS_DST link set veth$DST xdp object ../bpf/xdp_dummy.bpf.o section xdp 2>/dev/null
>  }
>  
>  create_vxlan_endpoint() {
> diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh
> index 430895d..704cba3 100755
> --- a/tools/testing/selftests/net/veth.sh
> +++ b/tools/testing/selftests/net/veth.sh
> @@ -216,7 +216,7 @@ while getopts "hs:" option; do
>  	esac
>  done
>  
> -if [ ! -f ../bpf/xdp_dummy.o ]; then
> +if [ ! -f ../bpf/xdp_dummy.bpf.o ]; then
>  	echo "Missing xdp_dummy helper. Build bpf selftest first"
>  	exit 1
>  fi
> @@ -288,14 +288,14 @@ if [ $CPUS -gt 1 ]; then
>  	ip netns exec $NS_DST ethtool -L veth$DST rx 1 tx 2 2>/dev/null
>  	ip netns exec $NS_SRC ethtool -L veth$SRC rx 1 tx 2 2>/dev/null
>  	printf "%-60s" "bad setting: XDP with RX nr less than TX"
> -	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o \
> +	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.bpf.o \
>  		section xdp 2>/dev/null &&\
>  		echo "fail - set operation successful ?!?" || echo " ok "
>  
>  	# the following tests will run with multiple channels active
>  	ip netns exec $NS_SRC ethtool -L veth$SRC rx 2
>  	ip netns exec $NS_DST ethtool -L veth$DST rx 2
> -	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o \
> +	ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.bpf.o \
>  		section xdp 2>/dev/null
>  	printf "%-60s" "bad setting: reducing RX nr below peer TX with XDP set"
>  	ip netns exec $NS_DST ethtool -L veth$DST rx 1 2>/dev/null &&\
> @@ -311,7 +311,7 @@ if [ $CPUS -gt 2 ]; then
>  	chk_channels "setting invalid channels nr" $DST 2 2
>  fi
>  
> -ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o section xdp 2>/dev/null
> +ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.bpf.o section xdp 2>/dev/null
>  chk_gro_flag "with xdp attached - gro flag" $DST on
>  chk_gro_flag "        - peer gro flag" $SRC off
>  chk_tso_flag "        - tso flag" $SRC off
> -- 
> 1.8.3.1
> 

The change looks good to me. Sorry for the breakage. We should probably figure
out if it would make sense tun run these tests in BPF CI (assuming that would be
doable with reasonable effort).

Acked-by: Daniel Müller <deso@posteo.net>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-11  9:57 ` [net 1/2] selftests/net: fix opening object file failed Wang Yufen
@ 2022-10-13  1:51   ` Martin KaFai Lau
  2022-10-18  2:57     ` wangyufen
  0 siblings, 1 reply; 11+ messages in thread
From: Martin KaFai Lau @ 2022-10-13  1:51 UTC (permalink / raw)
  To: Wang Yufen, Lina Wang
  Cc: bpf, davem, edumazet, kuba, pabeni, lina.wang, deso, netdev

On 10/11/22 2:57 AM, Wang Yufen wrote:
> The program file used in the udpgro_frglist testcase is "../bpf/nat6to4.o",
> but the actual nat6to4.o file is in "bpf/" not "../bpf".
> The following error occurs:
>    Error opening object ../bpf/nat6to4.o: No such file or directory

hmm... so it sounds like the test never works...

The test seems like mostly exercising the tc-bpf?  It makes sense to move it to 
the selftests/bpf. or staying in net is also fine for now and only need to fix 
up the path here.

However, if moving to selftests/bpf, I don't think it is a good idea to only 
move the bpf prog but not moving the actual test program (the script here) such 
that the bpf CI can continuously testing it.  Otherwise, it will just drift and 
rot slowly like patch 2.

Also, if you prefer to move it to selftests/bpf, the bpf prog cannot be moved in 
the current form.  eg. There is some convention on the SEC name in the 
selftests/bpf/progs.  Also, the testing script needs to be adapted to the 
selftests/bpf/test_progs infra.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-13  1:51   ` Martin KaFai Lau
@ 2022-10-18  2:57     ` wangyufen
  2022-10-18  9:50       ` wangyufen
  0 siblings, 1 reply; 11+ messages in thread
From: wangyufen @ 2022-10-18  2:57 UTC (permalink / raw)
  To: Martin KaFai Lau, Lina Wang
  Cc: bpf, davem, edumazet, kuba, pabeni, deso, netdev


在 2022/10/13 9:51, Martin KaFai Lau 写道:
> On 10/11/22 2:57 AM, Wang Yufen wrote:
>> The program file used in the udpgro_frglist testcase is 
>> "../bpf/nat6to4.o",
>> but the actual nat6to4.o file is in "bpf/" not "../bpf".
>> The following error occurs:
>>    Error opening object ../bpf/nat6to4.o: No such file or directory
>
> hmm... so it sounds like the test never works...
>
> The test seems like mostly exercising the tc-bpf?  It makes sense to 
> move it to the selftests/bpf. or staying in net is also fine for now 
> and only need to fix up the path here.
>
> However, if moving to selftests/bpf, I don't think it is a good idea 
> to only move the bpf prog but not moving the actual test program (the 
> script here) such that the bpf CI can continuously testing it.  
> Otherwise, it will just drift and rot slowly like patch 2.
>
> Also, if you prefer to move it to selftests/bpf, the bpf prog cannot 
> be moved in the current form.  eg. There is some convention on the SEC 
> name in the selftests/bpf/progs.  Also, the testing script needs to be 
> adapted to the selftests/bpf/test_progs infra.

hmm... if moving to selftests/bpf, the actual test programs also needs 
to move to selftests/bpf, e.g. udpgso_bench_*, in_netns.sh, udpgso*.sh, 
which may not be a good idea.

So, only fix up the path here.

Also fix up the bpf/nat6to4.o compile error as following:

     make -C tools/testing/selftests/net got the following err:
     bpf/nat6to4.c:43:10: fatal error: 'bpf/bpf_helpers.h' file not found
              ^~~~~~~~~~~~~~~~~~~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-18  2:57     ` wangyufen
@ 2022-10-18  9:50       ` wangyufen
  2022-10-18 16:26         ` Alexei Starovoitov
  2022-10-18 18:00         ` Jakub Kicinski
  0 siblings, 2 replies; 11+ messages in thread
From: wangyufen @ 2022-10-18  9:50 UTC (permalink / raw)
  To: Martin KaFai Lau, Lina Wang
  Cc: bpf, davem, edumazet, kuba, pabeni, deso, netdev


在 2022/10/18 10:57, wangyufen 写道:
>
> 在 2022/10/13 9:51, Martin KaFai Lau 写道:
>> On 10/11/22 2:57 AM, Wang Yufen wrote:
>>> The program file used in the udpgro_frglist testcase is 
>>> "../bpf/nat6to4.o",
>>> but the actual nat6to4.o file is in "bpf/" not "../bpf".
>>> The following error occurs:
>>>    Error opening object ../bpf/nat6to4.o: No such file or directory
>>
>> hmm... so it sounds like the test never works...
>>
>> The test seems like mostly exercising the tc-bpf?  It makes sense to 
>> move it to the selftests/bpf. or staying in net is also fine for now 
>> and only need to fix up the path here.
>>
>> However, if moving to selftests/bpf, I don't think it is a good idea 
>> to only move the bpf prog but not moving the actual test program (the 
>> script here) such that the bpf CI can continuously testing it.  
>> Otherwise, it will just drift and rot slowly like patch 2.
>>
>> Also, if you prefer to move it to selftests/bpf, the bpf prog cannot 
>> be moved in the current form.  eg. There is some convention on the 
>> SEC name in the selftests/bpf/progs.  Also, the testing script needs 
>> to be adapted to the selftests/bpf/test_progs infra.
>
> hmm... if moving to selftests/bpf, the actual test programs also needs 
> to move to selftests/bpf, e.g. udpgso_bench_*, in_netns.sh, 
> udpgso*.sh, which may not be a good idea.
>
> So, only fix up the path here.
>
> Also fix up the bpf/nat6to4.o compile error as following:
>
>     make -C tools/testing/selftests/net got the following err:
>     bpf/nat6to4.c:43:10: fatal error: 'bpf/bpf_helpers.h' file not found
>              ^~~~~~~~~~~~~~~~~~~
>
>
After revert commit 7b92aa9e61350("selftests net: fix kselftest net 
fatal error"),

make -C tools/testing/selftests got the following err:

In file included from bpf/nat6to4.c:43:
../../../lib/bpf/bpf_helpers.h:11:10: fatal error: 'bpf_helper_defs.h' 
file not found
#include "bpf_helper_defs.h"
          ^~~~~~~~~~~~~~~~~~~

"bpf_helper_defs.h"  is generated by libbpf;


So, there are two possible approaches:  the first moving nat6to4.c and 
the actual test programs to selftests/bpf;

second add make dependency on libbpf for the nat6to4.c.

Which one is better?




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-18  9:50       ` wangyufen
@ 2022-10-18 16:26         ` Alexei Starovoitov
  2022-10-18 18:00         ` Jakub Kicinski
  1 sibling, 0 replies; 11+ messages in thread
From: Alexei Starovoitov @ 2022-10-18 16:26 UTC (permalink / raw)
  To: wangyufen
  Cc: Martin KaFai Lau, Lina Wang, bpf, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Daniel Müller,
	Network Development

On Tue, Oct 18, 2022 at 2:58 AM wangyufen <wangyufen@huawei.com> wrote:
>
>
> 在 2022/10/18 10:57, wangyufen 写道:
> >
> > 在 2022/10/13 9:51, Martin KaFai Lau 写道:
> >> On 10/11/22 2:57 AM, Wang Yufen wrote:
> >>> The program file used in the udpgro_frglist testcase is
> >>> "../bpf/nat6to4.o",
> >>> but the actual nat6to4.o file is in "bpf/" not "../bpf".
> >>> The following error occurs:
> >>>    Error opening object ../bpf/nat6to4.o: No such file or directory
> >>
> >> hmm... so it sounds like the test never works...
> >>
> >> The test seems like mostly exercising the tc-bpf?  It makes sense to
> >> move it to the selftests/bpf. or staying in net is also fine for now
> >> and only need to fix up the path here.
> >>
> >> However, if moving to selftests/bpf, I don't think it is a good idea
> >> to only move the bpf prog but not moving the actual test program (the
> >> script here) such that the bpf CI can continuously testing it.
> >> Otherwise, it will just drift and rot slowly like patch 2.
> >>
> >> Also, if you prefer to move it to selftests/bpf, the bpf prog cannot
> >> be moved in the current form.  eg. There is some convention on the
> >> SEC name in the selftests/bpf/progs.  Also, the testing script needs
> >> to be adapted to the selftests/bpf/test_progs infra.
> >
> > hmm... if moving to selftests/bpf, the actual test programs also needs
> > to move to selftests/bpf, e.g. udpgso_bench_*, in_netns.sh,
> > udpgso*.sh, which may not be a good idea.
> >
> > So, only fix up the path here.
> >
> > Also fix up the bpf/nat6to4.o compile error as following:
> >
> >     make -C tools/testing/selftests/net got the following err:
> >     bpf/nat6to4.c:43:10: fatal error: 'bpf/bpf_helpers.h' file not found
> >              ^~~~~~~~~~~~~~~~~~~
> >
> >
> After revert commit 7b92aa9e61350("selftests net: fix kselftest net
> fatal error"),
>
> make -C tools/testing/selftests got the following err:
>
> In file included from bpf/nat6to4.c:43:
> ../../../lib/bpf/bpf_helpers.h:11:10: fatal error: 'bpf_helper_defs.h'
> file not found
> #include "bpf_helper_defs.h"
>           ^~~~~~~~~~~~~~~~~~~
>
> "bpf_helper_defs.h"  is generated by libbpf;
>
>
> So, there are two possible approaches:  the first moving nat6to4.c and
> the actual test programs to selftests/bpf;
>
> second add make dependency on libbpf for the nat6to4.c.
>
> Which one is better?

Neither.
Martin already explained that the whole thing needs to move to selftests/bpf.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-18  9:50       ` wangyufen
  2022-10-18 16:26         ` Alexei Starovoitov
@ 2022-10-18 18:00         ` Jakub Kicinski
  2022-10-19  1:30           ` Martin KaFai Lau
  1 sibling, 1 reply; 11+ messages in thread
From: Jakub Kicinski @ 2022-10-18 18:00 UTC (permalink / raw)
  To: wangyufen
  Cc: Martin KaFai Lau, Lina Wang, bpf, davem, edumazet, pabeni, deso, netdev

On Tue, 18 Oct 2022 17:50:19 +0800 wangyufen wrote:
> So, there are two possible approaches:  the first moving nat6to4.c and 
> the actual test programs to selftests/bpf;
> 
> second add make dependency on libbpf for the nat6to4.c.
> 
> Which one is better?

Can we move the programs and create a dependency from them back 
to networking? Perhaps shared components like udpgso_* need to live
under tools/net so they can be easily "depended on"?

Either that or they need to switch to a different traffic generator for
the BPF test, cause there's more networking selftests using the UDP
generators :(

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-18 18:00         ` Jakub Kicinski
@ 2022-10-19  1:30           ` Martin KaFai Lau
  2022-10-19  1:53             ` Jakub Kicinski
  0 siblings, 1 reply; 11+ messages in thread
From: Martin KaFai Lau @ 2022-10-19  1:30 UTC (permalink / raw)
  To: wangyufen
  Cc: Lina Wang, bpf, davem, edumazet, pabeni, deso, netdev, Jakub Kicinski

On 10/18/22 11:00 AM, Jakub Kicinski wrote:
> On Tue, 18 Oct 2022 17:50:19 +0800 wangyufen wrote:
>> So, there are two possible approaches:  the first moving nat6to4.c and
>> the actual test programs to selftests/bpf;
>>
>> second add make dependency on libbpf for the nat6to4.c.
>>
>> Which one is better?
> 
> Can we move the programs and create a dependency from them back
> to networking? Perhaps shared components like udpgso_* need to live
> under tools/net so they can be easily "depended on"?
> 
> Either that or they need to switch to a different traffic generator for
> the BPF test, cause there's more networking selftests using the UDP
> generators :(

All (at least most) of the selftests/bpf/test_prog's tests generate its own 
traffic for unit test purpose such that each test is self contained.  The 
udpgro_frglist test should do the same in selftests/bpf/test_prog (meaning the 
test itself should generate its own testing traffic).  Also, it does not look 
like it is actually using udpgso_bench_* to do benchmarking.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [net 1/2] selftests/net: fix opening object file failed
  2022-10-19  1:30           ` Martin KaFai Lau
@ 2022-10-19  1:53             ` Jakub Kicinski
  0 siblings, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2022-10-19  1:53 UTC (permalink / raw)
  To: Martin KaFai Lau
  Cc: wangyufen, Lina Wang, bpf, davem, edumazet, pabeni, deso, netdev

On Tue, 18 Oct 2022 18:30:07 -0700 Martin KaFai Lau wrote:
> > Can we move the programs and create a dependency from them back
> > to networking? Perhaps shared components like udpgso_* need to live
> > under tools/net so they can be easily "depended on"?
> > 
> > Either that or they need to switch to a different traffic generator for
> > the BPF test, cause there's more networking selftests using the UDP
> > generators :(  
> 
> All (at least most) of the selftests/bpf/test_prog's tests generate its own 
> traffic for unit test purpose such that each test is self contained.  The 
> udpgro_frglist test should do the same in selftests/bpf/test_prog (meaning the 
> test itself should generate its own testing traffic).  Also, it does not look 
> like it is actually using udpgso_bench_* to do benchmarking.

Sure, copy & paste of the right snippet will work too. 
Shouldn't be a lot of code to send and receive a few UDP GSOs.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-10-19  1:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11  9:57 [net 0/2] some fixes for selftest/net Wang Yufen
2022-10-11  9:57 ` [net 1/2] selftests/net: fix opening object file failed Wang Yufen
2022-10-13  1:51   ` Martin KaFai Lau
2022-10-18  2:57     ` wangyufen
2022-10-18  9:50       ` wangyufen
2022-10-18 16:26         ` Alexei Starovoitov
2022-10-18 18:00         ` Jakub Kicinski
2022-10-19  1:30           ` Martin KaFai Lau
2022-10-19  1:53             ` Jakub Kicinski
2022-10-11  9:57 ` [net 2/2] selftests/net: fix missing xdp_dummy Wang Yufen
2022-10-11 16:27   ` Daniel Müller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).