From nobody Wed Dec 4 19:22:07 2024 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 266F615CD41; Wed, 20 Nov 2024 07:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732088629; cv=none; b=ogc/Kuq+k46iVaqiC8ToQKFChG8JJx6o4SwOCraQh4rgFCRG4LcshRT37B6609xxPkgwNo7mzJ1JJCwtjQa/mdN3BkQRimDF4m+g9o3JbR7uyKTx+eqDVoz65z6DGXAUjMzsSHCXwBNb1JRzsEPENK/tTaTtI89p+Dda0QI6JEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732088629; c=relaxed/simple; bh=d5JgCAHQX++TG+5t01KzdAYKUKsEDeX16L9ApMIfKZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ctypg0QItVOV0M88VA3KMDcpBBOzfXDb70C9Z5kQY3TYFSfc8bnMAj+IpmH1N8GPNAqTO4HiKEjrWpLSbe3KJxDbgbP19vYg4e3+VNd8UiP3/SKP3toQg7BpmSYNorGmRY4W4FcaU7voNNkhrCzdLNmsc7A+j//FvT3bUtivIgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=WQ/YzyVV; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="WQ/YzyVV" Received: by mail.gandi.net (Postfix) with ESMTPSA id 784E924000B; Wed, 20 Nov 2024 07:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732088624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AnS2bDn7T3R9sRDp3boZ+QRxTPhb6KczAtLf0qSev7Q=; b=WQ/YzyVVPirykXEv5V8uxQZ6xiNLQ940CM8cPkqjFBdcilcrxaW3k3L4xg0Vv4vRRpBzF5 HJqkeSblV2lWK8GNNVwIETE3rcFCR5TwfCK+07zeRFNAliiifgYK9NB9XQt6BPoJdOZEnL PpLVwucYq+45RWC43NKzB/s6EbQE1qsf3KBs9xHibDMyJ5APNsdjCFGWWWpWePmamAj53g WKzCkhs+oCJi4r6P30bHKkOaMf7Yh9kHFjD8NprRYVv74g85jzdmN6IdYZq04xYYzdczc8 LPZinCDkunZpf8wyBC0owWeYv0HibKYbyOUrg8qBct6m6tG37rBjePvcJWfn6Q== From: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= Date: Wed, 20 Nov 2024 08:43:24 +0100 Subject: [PATCH bpf-next v3 14/14] selftests/bpf: remove test_flow_dissector.sh Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241120-flow_dissector-v3-14-45b46494f937@bootlin.com> References: <20241120-flow_dissector-v3-0-45b46494f937@bootlin.com> In-Reply-To: <20241120-flow_dissector-v3-0-45b46494f937@bootlin.com> To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer Cc: ebpf@linuxfoundation.org, Thomas Petazzoni , Bastien Curutchet , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29?= X-Mailer: b4 0.14.2 X-GND-Sasl: alexis.lothore@bootlin.com Now that test_flow_dissector.sh has been converted to test_progs, remove the legacy test. Acked-by: Stanislav Fomichev Signed-off-by: Alexis Lothor=C3=A9 (eBPF Foundation) --- Changes in v3: - none Changes in v2: - fetch Acked-by tag --- tools/testing/selftests/bpf/.gitignore | 1 - tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/test_flow_dissector.c | 780 -----------------= ---- tools/testing/selftests/bpf/test_flow_dissector.sh | 178 ----- 4 files changed, 1 insertion(+), 961 deletions(-) diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftes= ts/bpf/.gitignore index d45c9a9b304d4710ee66f4ffdf4d7e1c785c99bc..0bbc9b8ba8527b2c02009ea75b9= fc98d02f2eb2b 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore @@ -19,7 +19,6 @@ feature urandom_read test_sockmap test_lirc_mode2_user -test_flow_dissector flow_dissector_load test_tcpnotify_user test_libbpf diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index b1080284522d6615b753bd98f9d5135db55f922a..2439749dfc86651aa2afa79b572= cb32570c6bdbd 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -133,7 +133,6 @@ TEST_PROGS :=3D test_kmod.sh \ test_tunnel.sh \ test_lwt_seg6local.sh \ test_lirc_mode2.sh \ - test_flow_dissector.sh \ test_xdp_vlan_mode_generic.sh \ test_xdp_vlan_mode_native.sh \ test_lwt_ip_encap.sh \ @@ -154,7 +153,7 @@ TEST_PROGS_EXTENDED :=3D with_addr.sh \ =20 # Compile but not part of 'make run_tests' TEST_GEN_PROGS_EXTENDED =3D \ - flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ + flow_dissector_load test_tcp_check_syncookie_user \ test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \ xdp_features bpf_test_no_cfi.ko bpf_test_modorder_x.ko \ diff --git a/tools/testing/selftests/bpf/test_flow_dissector.c b/tools/test= ing/selftests/bpf/test_flow_dissector.c deleted file mode 100644 index 571cc076dd7db7f2254c4593e979ac5a8d89f273..000000000000000000000000000= 0000000000000 --- a/tools/testing/selftests/bpf/test_flow_dissector.c +++ /dev/null @@ -1,780 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Inject packets with all sorts of encapsulation into the kernel. - * - * IPv4/IPv6 outer layer 3 - * GRE/GUE/BARE outer layer 4, where bare is IPIP/SIT/IPv4-in-IPv6/.. - * IPv4/IPv6 inner layer 3 - */ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CFG_PORT_INNER 8000 - -/* Add some protocol definitions that do not exist in userspace */ - -struct grehdr { - uint16_t unused; - uint16_t protocol; -} __attribute__((packed)); - -struct guehdr { - union { - struct { -#if defined(__LITTLE_ENDIAN_BITFIELD) - __u8 hlen:5, - control:1, - version:2; -#elif defined (__BIG_ENDIAN_BITFIELD) - __u8 version:2, - control:1, - hlen:5; -#else -#error "Please fix " -#endif - __u8 proto_ctype; - __be16 flags; - }; - __be32 word; - }; -}; - -static uint8_t cfg_dsfield_inner; -static uint8_t cfg_dsfield_outer; -static uint8_t cfg_encap_proto; -static bool cfg_expect_failure =3D false; -static int cfg_l3_extra =3D AF_UNSPEC; /* optional SIT prefix */ -static int cfg_l3_inner =3D AF_UNSPEC; -static int cfg_l3_outer =3D AF_UNSPEC; -static int cfg_num_pkt =3D 10; -static int cfg_num_secs =3D 0; -static char cfg_payload_char =3D 'a'; -static int cfg_payload_len =3D 100; -static int cfg_port_gue =3D 6080; -static bool cfg_only_rx; -static bool cfg_only_tx; -static int cfg_src_port =3D 9; - -static char buf[ETH_DATA_LEN]; - -#define INIT_ADDR4(name, addr4, port) \ - static struct sockaddr_in name =3D { \ - .sin_family =3D AF_INET, \ - .sin_port =3D __constant_htons(port), \ - .sin_addr.s_addr =3D __constant_htonl(addr4), \ - }; - -#define INIT_ADDR6(name, addr6, port) \ - static struct sockaddr_in6 name =3D { \ - .sin6_family =3D AF_INET6, \ - .sin6_port =3D __constant_htons(port), \ - .sin6_addr =3D addr6, \ - }; - -INIT_ADDR4(in_daddr4, INADDR_LOOPBACK, CFG_PORT_INNER) -INIT_ADDR4(in_saddr4, INADDR_LOOPBACK + 2, 0) -INIT_ADDR4(out_daddr4, INADDR_LOOPBACK, 0) -INIT_ADDR4(out_saddr4, INADDR_LOOPBACK + 1, 0) -INIT_ADDR4(extra_daddr4, INADDR_LOOPBACK, 0) -INIT_ADDR4(extra_saddr4, INADDR_LOOPBACK + 1, 0) - -INIT_ADDR6(in_daddr6, IN6ADDR_LOOPBACK_INIT, CFG_PORT_INNER) -INIT_ADDR6(in_saddr6, IN6ADDR_LOOPBACK_INIT, 0) -INIT_ADDR6(out_daddr6, IN6ADDR_LOOPBACK_INIT, 0) -INIT_ADDR6(out_saddr6, IN6ADDR_LOOPBACK_INIT, 0) -INIT_ADDR6(extra_daddr6, IN6ADDR_LOOPBACK_INIT, 0) -INIT_ADDR6(extra_saddr6, IN6ADDR_LOOPBACK_INIT, 0) - -static unsigned long util_gettime(void) -{ - struct timeval tv; - - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); -} - -static void util_printaddr(const char *msg, struct sockaddr *addr) -{ - unsigned long off =3D 0; - char nbuf[INET6_ADDRSTRLEN]; - - switch (addr->sa_family) { - case PF_INET: - off =3D __builtin_offsetof(struct sockaddr_in, sin_addr); - break; - case PF_INET6: - off =3D __builtin_offsetof(struct sockaddr_in6, sin6_addr); - break; - default: - error(1, 0, "printaddr: unsupported family %u\n", - addr->sa_family); - } - - if (!inet_ntop(addr->sa_family, ((void *) addr) + off, nbuf, - sizeof(nbuf))) - error(1, errno, "inet_ntop"); - - fprintf(stderr, "%s: %s\n", msg, nbuf); -} - -static unsigned long add_csum_hword(const uint16_t *start, int num_u16) -{ - unsigned long sum =3D 0; - int i; - - for (i =3D 0; i < num_u16; i++) - sum +=3D start[i]; - - return sum; -} - -static uint16_t build_ip_csum(const uint16_t *start, int num_u16, - unsigned long sum) -{ - sum +=3D add_csum_hword(start, num_u16); - - while (sum >> 16) - sum =3D (sum & 0xffff) + (sum >> 16); - - return ~sum; -} - -static void build_ipv4_header(void *header, uint8_t proto, - uint32_t src, uint32_t dst, - int payload_len, uint8_t tos) -{ - struct iphdr *iph =3D header; - - iph->ihl =3D 5; - iph->version =3D 4; - iph->tos =3D tos; - iph->ttl =3D 8; - iph->tot_len =3D htons(sizeof(*iph) + payload_len); - iph->id =3D htons(1337); - iph->protocol =3D proto; - iph->saddr =3D src; - iph->daddr =3D dst; - iph->check =3D build_ip_csum((void *) iph, iph->ihl << 1, 0); -} - -static void ipv6_set_dsfield(struct ipv6hdr *ip6h, uint8_t dsfield) -{ - uint16_t val, *ptr =3D (uint16_t *)ip6h; - - val =3D ntohs(*ptr); - val &=3D 0xF00F; - val |=3D ((uint16_t) dsfield) << 4; - *ptr =3D htons(val); -} - -static void build_ipv6_header(void *header, uint8_t proto, - struct sockaddr_in6 *src, - struct sockaddr_in6 *dst, - int payload_len, uint8_t dsfield) -{ - struct ipv6hdr *ip6h =3D header; - - ip6h->version =3D 6; - ip6h->payload_len =3D htons(payload_len); - ip6h->nexthdr =3D proto; - ip6h->hop_limit =3D 8; - ipv6_set_dsfield(ip6h, dsfield); - - memcpy(&ip6h->saddr, &src->sin6_addr, sizeof(ip6h->saddr)); - memcpy(&ip6h->daddr, &dst->sin6_addr, sizeof(ip6h->daddr)); -} - -static uint16_t build_udp_v4_csum(const struct iphdr *iph, - const struct udphdr *udph, - int num_words) -{ - unsigned long pseudo_sum; - int num_u16 =3D sizeof(iph->saddr); /* halfwords: twice byte len */ - - pseudo_sum =3D add_csum_hword((void *) &iph->saddr, num_u16); - pseudo_sum +=3D htons(IPPROTO_UDP); - pseudo_sum +=3D udph->len; - return build_ip_csum((void *) udph, num_words, pseudo_sum); -} - -static uint16_t build_udp_v6_csum(const struct ipv6hdr *ip6h, - const struct udphdr *udph, - int num_words) -{ - unsigned long pseudo_sum; - int num_u16 =3D sizeof(ip6h->saddr); /* halfwords: twice byte len */ - - pseudo_sum =3D add_csum_hword((void *) &ip6h->saddr, num_u16); - pseudo_sum +=3D htons(ip6h->nexthdr); - pseudo_sum +=3D ip6h->payload_len; - return build_ip_csum((void *) udph, num_words, pseudo_sum); -} - -static void build_udp_header(void *header, int payload_len, - uint16_t dport, int family) -{ - struct udphdr *udph =3D header; - int len =3D sizeof(*udph) + payload_len; - - udph->source =3D htons(cfg_src_port); - udph->dest =3D htons(dport); - udph->len =3D htons(len); - udph->check =3D 0; - if (family =3D=3D AF_INET) - udph->check =3D build_udp_v4_csum(header - sizeof(struct iphdr), - udph, len >> 1); - else - udph->check =3D build_udp_v6_csum(header - sizeof(struct ipv6hdr), - udph, len >> 1); -} - -static void build_gue_header(void *header, uint8_t proto) -{ - struct guehdr *gueh =3D header; - - gueh->proto_ctype =3D proto; -} - -static void build_gre_header(void *header, uint16_t proto) -{ - struct grehdr *greh =3D header; - - greh->protocol =3D htons(proto); -} - -static int l3_length(int family) -{ - if (family =3D=3D AF_INET) - return sizeof(struct iphdr); - else - return sizeof(struct ipv6hdr); -} - -static int build_packet(void) -{ - int ol3_len =3D 0, ol4_len =3D 0, il3_len =3D 0, il4_len =3D 0; - int el3_len =3D 0; - - if (cfg_l3_extra) - el3_len =3D l3_length(cfg_l3_extra); - - /* calculate header offsets */ - if (cfg_encap_proto) { - ol3_len =3D l3_length(cfg_l3_outer); - - if (cfg_encap_proto =3D=3D IPPROTO_GRE) - ol4_len =3D sizeof(struct grehdr); - else if (cfg_encap_proto =3D=3D IPPROTO_UDP) - ol4_len =3D sizeof(struct udphdr) + sizeof(struct guehdr); - } - - il3_len =3D l3_length(cfg_l3_inner); - il4_len =3D sizeof(struct udphdr); - - if (el3_len + ol3_len + ol4_len + il3_len + il4_len + cfg_payload_len >= =3D - sizeof(buf)) - error(1, 0, "packet too large\n"); - - /* - * Fill packet from inside out, to calculate correct checksums. - * But create ip before udp headers, as udp uses ip for pseudo-sum. - */ - memset(buf + el3_len + ol3_len + ol4_len + il3_len + il4_len, - cfg_payload_char, cfg_payload_len); - - /* add zero byte for udp csum padding */ - buf[el3_len + ol3_len + ol4_len + il3_len + il4_len + cfg_payload_len] = =3D 0; - - switch (cfg_l3_inner) { - case PF_INET: - build_ipv4_header(buf + el3_len + ol3_len + ol4_len, - IPPROTO_UDP, - in_saddr4.sin_addr.s_addr, - in_daddr4.sin_addr.s_addr, - il4_len + cfg_payload_len, - cfg_dsfield_inner); - break; - case PF_INET6: - build_ipv6_header(buf + el3_len + ol3_len + ol4_len, - IPPROTO_UDP, - &in_saddr6, &in_daddr6, - il4_len + cfg_payload_len, - cfg_dsfield_inner); - break; - } - - build_udp_header(buf + el3_len + ol3_len + ol4_len + il3_len, - cfg_payload_len, CFG_PORT_INNER, cfg_l3_inner); - - if (!cfg_encap_proto) - return il3_len + il4_len + cfg_payload_len; - - switch (cfg_l3_outer) { - case PF_INET: - build_ipv4_header(buf + el3_len, cfg_encap_proto, - out_saddr4.sin_addr.s_addr, - out_daddr4.sin_addr.s_addr, - ol4_len + il3_len + il4_len + cfg_payload_len, - cfg_dsfield_outer); - break; - case PF_INET6: - build_ipv6_header(buf + el3_len, cfg_encap_proto, - &out_saddr6, &out_daddr6, - ol4_len + il3_len + il4_len + cfg_payload_len, - cfg_dsfield_outer); - break; - } - - switch (cfg_encap_proto) { - case IPPROTO_UDP: - build_gue_header(buf + el3_len + ol3_len + ol4_len - - sizeof(struct guehdr), - cfg_l3_inner =3D=3D PF_INET ? IPPROTO_IPIP - : IPPROTO_IPV6); - build_udp_header(buf + el3_len + ol3_len, - sizeof(struct guehdr) + il3_len + il4_len + - cfg_payload_len, - cfg_port_gue, cfg_l3_outer); - break; - case IPPROTO_GRE: - build_gre_header(buf + el3_len + ol3_len, - cfg_l3_inner =3D=3D PF_INET ? ETH_P_IP - : ETH_P_IPV6); - break; - } - - switch (cfg_l3_extra) { - case PF_INET: - build_ipv4_header(buf, - cfg_l3_outer =3D=3D PF_INET ? IPPROTO_IPIP - : IPPROTO_IPV6, - extra_saddr4.sin_addr.s_addr, - extra_daddr4.sin_addr.s_addr, - ol3_len + ol4_len + il3_len + il4_len + - cfg_payload_len, 0); - break; - case PF_INET6: - build_ipv6_header(buf, - cfg_l3_outer =3D=3D PF_INET ? IPPROTO_IPIP - : IPPROTO_IPV6, - &extra_saddr6, &extra_daddr6, - ol3_len + ol4_len + il3_len + il4_len + - cfg_payload_len, 0); - break; - } - - return el3_len + ol3_len + ol4_len + il3_len + il4_len + - cfg_payload_len; -} - -/* sender transmits encapsulated over RAW or unencap'd over UDP */ -static int setup_tx(void) -{ - int family, fd, ret; - - if (cfg_l3_extra) - family =3D cfg_l3_extra; - else if (cfg_l3_outer) - family =3D cfg_l3_outer; - else - family =3D cfg_l3_inner; - - fd =3D socket(family, SOCK_RAW, IPPROTO_RAW); - if (fd =3D=3D -1) - error(1, errno, "socket tx"); - - if (cfg_l3_extra) { - if (cfg_l3_extra =3D=3D PF_INET) - ret =3D connect(fd, (void *) &extra_daddr4, - sizeof(extra_daddr4)); - else - ret =3D connect(fd, (void *) &extra_daddr6, - sizeof(extra_daddr6)); - if (ret) - error(1, errno, "connect tx"); - } else if (cfg_l3_outer) { - /* connect to destination if not encapsulated */ - if (cfg_l3_outer =3D=3D PF_INET) - ret =3D connect(fd, (void *) &out_daddr4, - sizeof(out_daddr4)); - else - ret =3D connect(fd, (void *) &out_daddr6, - sizeof(out_daddr6)); - if (ret) - error(1, errno, "connect tx"); - } else { - /* otherwise using loopback */ - if (cfg_l3_inner =3D=3D PF_INET) - ret =3D connect(fd, (void *) &in_daddr4, - sizeof(in_daddr4)); - else - ret =3D connect(fd, (void *) &in_daddr6, - sizeof(in_daddr6)); - if (ret) - error(1, errno, "connect tx"); - } - - return fd; -} - -/* receiver reads unencapsulated UDP */ -static int setup_rx(void) -{ - int fd, ret; - - fd =3D socket(cfg_l3_inner, SOCK_DGRAM, 0); - if (fd =3D=3D -1) - error(1, errno, "socket rx"); - - if (cfg_l3_inner =3D=3D PF_INET) - ret =3D bind(fd, (void *) &in_daddr4, sizeof(in_daddr4)); - else - ret =3D bind(fd, (void *) &in_daddr6, sizeof(in_daddr6)); - if (ret) - error(1, errno, "bind rx"); - - return fd; -} - -static int do_tx(int fd, const char *pkt, int len) -{ - int ret; - - ret =3D write(fd, pkt, len); - if (ret =3D=3D -1) - error(1, errno, "send"); - if (ret !=3D len) - error(1, errno, "send: len (%d < %d)\n", ret, len); - - return 1; -} - -static int do_poll(int fd, short events, int timeout) -{ - struct pollfd pfd; - int ret; - - pfd.fd =3D fd; - pfd.events =3D events; - - ret =3D poll(&pfd, 1, timeout); - if (ret =3D=3D -1) - error(1, errno, "poll"); - if (ret && !(pfd.revents & POLLIN)) - error(1, errno, "poll: unexpected event 0x%x\n", pfd.revents); - - return ret; -} - -static int do_rx(int fd) -{ - char rbuf; - int ret, num =3D 0; - - while (1) { - ret =3D recv(fd, &rbuf, 1, MSG_DONTWAIT); - if (ret =3D=3D -1 && errno =3D=3D EAGAIN) - break; - if (ret =3D=3D -1) - error(1, errno, "recv"); - if (rbuf !=3D cfg_payload_char) - error(1, 0, "recv: payload mismatch"); - num++; - } - - return num; -} - -static int do_main(void) -{ - unsigned long tstop, treport, tcur; - int fdt =3D -1, fdr =3D -1, len, tx =3D 0, rx =3D 0; - - if (!cfg_only_tx) - fdr =3D setup_rx(); - if (!cfg_only_rx) - fdt =3D setup_tx(); - - len =3D build_packet(); - - tcur =3D util_gettime(); - treport =3D tcur + 1000; - tstop =3D tcur + (cfg_num_secs * 1000); - - while (1) { - if (!cfg_only_rx) - tx +=3D do_tx(fdt, buf, len); - - if (!cfg_only_tx) - rx +=3D do_rx(fdr); - - if (cfg_num_secs) { - tcur =3D util_gettime(); - if (tcur >=3D tstop) - break; - if (tcur >=3D treport) { - fprintf(stderr, "pkts: tx=3D%u rx=3D%u\n", tx, rx); - tx =3D 0; - rx =3D 0; - treport =3D tcur + 1000; - } - } else { - if (tx =3D=3D cfg_num_pkt) - break; - } - } - - /* read straggler packets, if any */ - if (rx < tx) { - tstop =3D util_gettime() + 100; - while (rx < tx) { - tcur =3D util_gettime(); - if (tcur >=3D tstop) - break; - - do_poll(fdr, POLLIN, tstop - tcur); - rx +=3D do_rx(fdr); - } - } - - fprintf(stderr, "pkts: tx=3D%u rx=3D%u\n", tx, rx); - - if (fdr !=3D -1 && close(fdr)) - error(1, errno, "close rx"); - if (fdt !=3D -1 && close(fdt)) - error(1, errno, "close tx"); - - /* - * success (=3D=3D 0) only if received all packets - * unless failure is expected, in which case none must arrive. - */ - if (cfg_expect_failure) - return rx !=3D 0; - else - return rx !=3D tx; -} - - -static void __attribute__((noreturn)) usage(const char *filepath) -{ - fprintf(stderr, "Usage: %s [-e gre|gue|bare|none] [-i 4|6] [-l len] " - "[-O 4|6] [-o 4|6] [-n num] [-t secs] [-R] [-T] " - "[-s [-d ] [-S ] [-D ] " - "[-x ] [-X ] [-f ] [-F]\n", - filepath); - exit(1); -} - -static void parse_addr(int family, void *addr, const char *optarg) -{ - int ret; - - ret =3D inet_pton(family, optarg, addr); - if (ret =3D=3D -1) - error(1, errno, "inet_pton"); - if (ret =3D=3D 0) - error(1, 0, "inet_pton: bad string"); -} - -static void parse_addr4(struct sockaddr_in *addr, const char *optarg) -{ - parse_addr(AF_INET, &addr->sin_addr, optarg); -} - -static void parse_addr6(struct sockaddr_in6 *addr, const char *optarg) -{ - parse_addr(AF_INET6, &addr->sin6_addr, optarg); -} - -static int parse_protocol_family(const char *filepath, const char *optarg) -{ - if (!strcmp(optarg, "4")) - return PF_INET; - if (!strcmp(optarg, "6")) - return PF_INET6; - - usage(filepath); -} - -static void parse_opts(int argc, char **argv) -{ - int c; - - while ((c =3D getopt(argc, argv, "d:D:e:f:Fhi:l:n:o:O:Rs:S:t:Tx:X:")) != =3D -1) { - switch (c) { - case 'd': - if (cfg_l3_outer =3D=3D AF_UNSPEC) - error(1, 0, "-d must be preceded by -o"); - if (cfg_l3_outer =3D=3D AF_INET) - parse_addr4(&out_daddr4, optarg); - else - parse_addr6(&out_daddr6, optarg); - break; - case 'D': - if (cfg_l3_inner =3D=3D AF_UNSPEC) - error(1, 0, "-D must be preceded by -i"); - if (cfg_l3_inner =3D=3D AF_INET) - parse_addr4(&in_daddr4, optarg); - else - parse_addr6(&in_daddr6, optarg); - break; - case 'e': - if (!strcmp(optarg, "gre")) - cfg_encap_proto =3D IPPROTO_GRE; - else if (!strcmp(optarg, "gue")) - cfg_encap_proto =3D IPPROTO_UDP; - else if (!strcmp(optarg, "bare")) - cfg_encap_proto =3D IPPROTO_IPIP; - else if (!strcmp(optarg, "none")) - cfg_encap_proto =3D IPPROTO_IP; /* =3D=3D 0 */ - else - usage(argv[0]); - break; - case 'f': - cfg_src_port =3D strtol(optarg, NULL, 0); - break; - case 'F': - cfg_expect_failure =3D true; - break; - case 'h': - usage(argv[0]); - break; - case 'i': - if (!strcmp(optarg, "4")) - cfg_l3_inner =3D PF_INET; - else if (!strcmp(optarg, "6")) - cfg_l3_inner =3D PF_INET6; - else - usage(argv[0]); - break; - case 'l': - cfg_payload_len =3D strtol(optarg, NULL, 0); - break; - case 'n': - cfg_num_pkt =3D strtol(optarg, NULL, 0); - break; - case 'o': - cfg_l3_outer =3D parse_protocol_family(argv[0], optarg); - break; - case 'O': - cfg_l3_extra =3D parse_protocol_family(argv[0], optarg); - break; - case 'R': - cfg_only_rx =3D true; - break; - case 's': - if (cfg_l3_outer =3D=3D AF_INET) - parse_addr4(&out_saddr4, optarg); - else - parse_addr6(&out_saddr6, optarg); - break; - case 'S': - if (cfg_l3_inner =3D=3D AF_INET) - parse_addr4(&in_saddr4, optarg); - else - parse_addr6(&in_saddr6, optarg); - break; - case 't': - cfg_num_secs =3D strtol(optarg, NULL, 0); - break; - case 'T': - cfg_only_tx =3D true; - break; - case 'x': - cfg_dsfield_outer =3D strtol(optarg, NULL, 0); - break; - case 'X': - cfg_dsfield_inner =3D strtol(optarg, NULL, 0); - break; - } - } - - if (cfg_only_rx && cfg_only_tx) - error(1, 0, "options: cannot combine rx-only and tx-only"); - - if (cfg_encap_proto && cfg_l3_outer =3D=3D AF_UNSPEC) - error(1, 0, "options: must specify outer with encap"); - else if ((!cfg_encap_proto) && cfg_l3_outer !=3D AF_UNSPEC) - error(1, 0, "options: cannot combine no-encap and outer"); - else if ((!cfg_encap_proto) && cfg_l3_extra !=3D AF_UNSPEC) - error(1, 0, "options: cannot combine no-encap and extra"); - - if (cfg_l3_inner =3D=3D AF_UNSPEC) - cfg_l3_inner =3D AF_INET6; - if (cfg_l3_inner =3D=3D AF_INET6 && cfg_encap_proto =3D=3D IPPROTO_IPIP) - cfg_encap_proto =3D IPPROTO_IPV6; - - /* RFC 6040 4.2: - * on decap, if outer encountered congestion (CE =3D=3D 0x3), - * but inner cannot encode ECN (NoECT =3D=3D 0x0), then drop packet. - */ - if (((cfg_dsfield_outer & 0x3) =3D=3D 0x3) && - ((cfg_dsfield_inner & 0x3) =3D=3D 0x0)) - cfg_expect_failure =3D true; -} - -static void print_opts(void) -{ - if (cfg_l3_inner =3D=3D PF_INET6) { - util_printaddr("inner.dest6", (void *) &in_daddr6); - util_printaddr("inner.source6", (void *) &in_saddr6); - } else { - util_printaddr("inner.dest4", (void *) &in_daddr4); - util_printaddr("inner.source4", (void *) &in_saddr4); - } - - if (!cfg_l3_outer) - return; - - fprintf(stderr, "encap proto: %u\n", cfg_encap_proto); - - if (cfg_l3_outer =3D=3D PF_INET6) { - util_printaddr("outer.dest6", (void *) &out_daddr6); - util_printaddr("outer.source6", (void *) &out_saddr6); - } else { - util_printaddr("outer.dest4", (void *) &out_daddr4); - util_printaddr("outer.source4", (void *) &out_saddr4); - } - - if (!cfg_l3_extra) - return; - - if (cfg_l3_outer =3D=3D PF_INET6) { - util_printaddr("extra.dest6", (void *) &extra_daddr6); - util_printaddr("extra.source6", (void *) &extra_saddr6); - } else { - util_printaddr("extra.dest4", (void *) &extra_daddr4); - util_printaddr("extra.source4", (void *) &extra_saddr4); - } - -} - -int main(int argc, char **argv) -{ - parse_opts(argc, argv); - print_opts(); - return do_main(); -} diff --git a/tools/testing/selftests/bpf/test_flow_dissector.sh b/tools/tes= ting/selftests/bpf/test_flow_dissector.sh deleted file mode 100755 index 4b298863797a28a1762d1f06d6c89c481498b505..000000000000000000000000000= 0000000000000 --- a/tools/testing/selftests/bpf/test_flow_dissector.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 -# -# Load BPF flow dissector and verify it correctly dissects traffic - -BPF_FILE=3D"bpf_flow.bpf.o" -export TESTNAME=3Dtest_flow_dissector -unmount=3D0 - -# Kselftest framework requirement - SKIP code is 4. -ksft_skip=3D4 - -msg=3D"skip all tests:" -if [ $UID !=3D 0 ]; then - echo $msg please run this as root >&2 - exit $ksft_skip -fi - -# This test needs to be run in a network namespace with in_netns.sh. Check= if -# this is the case and run it with in_netns.sh if it is being run in the r= oot -# namespace. -if [[ -z $(ip netns identify $$) ]]; then - err=3D0 - if bpftool=3D"$(which bpftool)"; then - echo "Testing global flow dissector..." - - $bpftool prog loadall $BPF_FILE /sys/fs/bpf/flow \ - type flow_dissector - - if ! unshare --net $bpftool prog attach pinned \ - /sys/fs/bpf/flow/_dissect flow_dissector; then - echo "Unexpected unsuccessful attach in namespace" >&2 - err=3D1 - fi - - $bpftool prog attach pinned /sys/fs/bpf/flow/_dissect \ - flow_dissector - - if unshare --net $bpftool prog attach pinned \ - /sys/fs/bpf/flow/_dissect flow_dissector; then - echo "Unexpected successful attach in namespace" >&2 - err=3D1 - fi - - if ! $bpftool prog detach pinned \ - /sys/fs/bpf/flow/_dissect flow_dissector; then - echo "Failed to detach flow dissector" >&2 - err=3D1 - fi - - rm -rf /sys/fs/bpf/flow - else - echo "Skipping root flow dissector test, bpftool not found" >&2 - fi - - # Run the rest of the tests in a net namespace. - ../net/in_netns.sh "$0" "$@" - err=3D$(( $err + $? )) - - if (( $err =3D=3D 0 )); then - echo "selftests: $TESTNAME [PASS]"; - else - echo "selftests: $TESTNAME [FAILED]"; - fi - - exit $err -fi - -# Determine selftest success via shell exit code -exit_handler() -{ - set +e - - # Cleanup - tc filter del dev lo ingress pref 1337 2> /dev/null - tc qdisc del dev lo ingress 2> /dev/null - ./flow_dissector_load -d 2> /dev/null - if [ $unmount -ne 0 ]; then - umount bpffs 2> /dev/null - fi -} - -# Exit script immediately (well catched by trap handler) if any -# program/thing exits with a non-zero status. -set -e - -# (Use 'trap -l' to list meaning of numbers) -trap exit_handler 0 2 3 6 9 - -# Mount BPF file system -if /bin/mount | grep /sys/fs/bpf > /dev/null; then - echo "bpffs already mounted" -else - echo "bpffs not mounted. Mounting..." - unmount=3D1 - /bin/mount bpffs /sys/fs/bpf -t bpf -fi - -# Attach BPF program -./flow_dissector_load -p $BPF_FILE -s _dissect - -# Setup -tc qdisc add dev lo ingress -echo 0 > /proc/sys/net/ipv4/conf/default/rp_filter -echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter -echo 0 > /proc/sys/net/ipv4/conf/lo/rp_filter - -echo "Testing IPv4..." -# Drops all IP/UDP packets coming from port 9 -tc filter add dev lo parent ffff: protocol ip pref 1337 flower ip_proto \ - udp src_port 9 action drop - -# Send 10 IPv4/UDP packets from port 8. Filter should not drop any. -./test_flow_dissector -i 4 -f 8 -# Send 10 IPv4/UDP packets from port 9. Filter should drop all. -./test_flow_dissector -i 4 -f 9 -F -# Send 10 IPv4/UDP packets from port 10. Filter should not drop any. -./test_flow_dissector -i 4 -f 10 - -echo "Testing IPv4 from 127.0.0.127 (fallback to generic dissector)..." -# Send 10 IPv4/UDP packets from port 8. Filter should not drop any. -./test_flow_dissector -i 4 -S 127.0.0.127 -f 8 -# Send 10 IPv4/UDP packets from port 9. Filter should drop all. -./test_flow_dissector -i 4 -S 127.0.0.127 -f 9 -F -# Send 10 IPv4/UDP packets from port 10. Filter should not drop any. -./test_flow_dissector -i 4 -S 127.0.0.127 -f 10 - -echo "Testing IPIP..." -# Send 10 IPv4/IPv4/UDP packets from port 8. Filter should not drop any. -./with_addr.sh ./with_tunnels.sh ./test_flow_dissector -o 4 -e bare -i 4 \ - -D 192.168.0.1 -S 1.1.1.1 -f 8 -# Send 10 IPv4/IPv4/UDP packets from port 9. Filter should drop all. -./with_addr.sh ./with_tunnels.sh ./test_flow_dissector -o 4 -e bare -i 4 \ - -D 192.168.0.1 -S 1.1.1.1 -f 9 -F -# Send 10 IPv4/IPv4/UDP packets from port 10. Filter should not drop any. -./with_addr.sh ./with_tunnels.sh ./test_flow_dissector -o 4 -e bare -i 4 \ - -D 192.168.0.1 -S 1.1.1.1 -f 10 - -echo "Testing IPv4 + GRE..." -# Send 10 IPv4/GRE/IPv4/UDP packets from port 8. Filter should not drop an= y. -./with_addr.sh ./with_tunnels.sh ./test_flow_dissector -o 4 -e gre -i 4 \ - -D 192.168.0.1 -S 1.1.1.1 -f 8 -# Send 10 IPv4/GRE/IPv4/UDP packets from port 9. Filter should drop all. -./with_addr.sh ./with_tunnels.sh ./test_flow_dissector -o 4 -e gre -i 4 \ - -D 192.168.0.1 -S 1.1.1.1 -f 9 -F -# Send 10 IPv4/GRE/IPv4/UDP packets from port 10. Filter should not drop a= ny. -./with_addr.sh ./with_tunnels.sh ./test_flow_dissector -o 4 -e gre -i 4 \ - -D 192.168.0.1 -S 1.1.1.1 -f 10 - -tc filter del dev lo ingress pref 1337 - -echo "Testing port range..." -# Drops all IP/UDP packets coming from port 8-10 -tc filter add dev lo parent ffff: protocol ip pref 1337 flower ip_proto \ - udp src_port 8-10 action drop - -# Send 10 IPv4/UDP packets from port 7. Filter should not drop any. -./test_flow_dissector -i 4 -f 7 -# Send 10 IPv4/UDP packets from port 9. Filter should drop all. -./test_flow_dissector -i 4 -f 9 -F -# Send 10 IPv4/UDP packets from port 11. Filter should not drop any. -./test_flow_dissector -i 4 -f 11 - -tc filter del dev lo ingress pref 1337 - -echo "Testing IPv6..." -# Drops all IPv6/UDP packets coming from port 9 -tc filter add dev lo parent ffff: protocol ipv6 pref 1337 flower ip_proto \ - udp src_port 9 action drop - -# Send 10 IPv6/UDP packets from port 8. Filter should not drop any. -./test_flow_dissector -i 6 -f 8 -# Send 10 IPv6/UDP packets from port 9. Filter should drop all. -./test_flow_dissector -i 6 -f 9 -F -# Send 10 IPv6/UDP packets from port 10. Filter should not drop any. -./test_flow_dissector -i 6 -f 10 - -exit 0 --=20 2.47.0