summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-08-06 20:11:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-08-06 20:11:59 -0400
commit33920f1ec5bf47c5c0a1d2113989bdd9dfb3fae9 (patch)
treedade12a1bfba22613acd3fc63cb3ce62110e779a /tools
parent76d7961ff4ee02cc70365600a52fb59ca544dc7c (diff)
parentfeac1d680233a48603213d52230f92222462a1c8 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
Pull networking fixes from David Miller: "Yeah I should have sent a pull request last week, so there is a lot more here than usual: 1) Fix memory leak in ebtables compat code, from Wenwen Wang. 2) Several kTLS bug fixes from Jakub Kicinski (circular close on disconnect etc.) 3) Force slave speed check on link state recovery in bonding 802.3ad mode, from Thomas Falcon. 4) Clear RX descriptor bits before assigning buffers to them in stmmac, from Jose Abreu. 5) Several missing of_node_put() calls, mostly wrt. for_each_*() OF loops, from Nishka Dasgupta. 6) Double kfree_skb() in peak_usb can driver, from Stephane Grosjean. 7) Need to hold sock across skb->destructor invocation, from Cong Wang. 8) IP header length needs to be validated in ipip tunnel xmit, from Haishuang Yan. 9) Use after free in ip6 tunnel driver, also from Haishuang Yan. 10) Do not use MSI interrupts on r8169 chips before RTL8168d, from Heiner Kallweit. 11) Upon bridge device init failure, we need to delete the local fdb. From Nikolay Aleksandrov. 12) Handle erros from of_get_mac_address() properly in stmmac, from Martin Blumenstingl. 13) Handle concurrent rename vs. dump in netfilter ipset, from Jozsef Kadlecsik. 14) Setting NETIF_F_LLTX on mac80211 causes complete breakage with some devices, so revert. From Johannes Berg. 15) Fix deadlock in rxrpc, from David Howells. 16) Fix Kconfig deps of enetc driver, we must have PHYLIB. From Yue Haibing. 17) Fix mvpp2 crash on module removal, from Matteo Croce. 18) Fix race in genphy_update_link, from Heiner Kallweit. 19) bpf_xdp_adjust_head() stopped working with generic XDP when we fixes generic XDP to support stacked devices properly, fix from Jesper Dangaard Brouer. 20) Unbalanced RCU locking in rt6_update_exception_stamp_rt(), from David Ahern. 21) Several memory leaks in new sja1105 driver, from Vladimir Oltean" * git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (214 commits) net: dsa: sja1105: Fix memory leak on meta state machine error path net: dsa: sja1105: Fix memory leak on meta state machine normal path net: dsa: sja1105: Really fix panic on unregistering PTP clock net: dsa: sja1105: Use the LOCKEDS bit for SJA1105 E/T as well net: dsa: sja1105: Fix broken learning with vlan_filtering disabled net: dsa: qca8k: Add of_node_put() in qca8k_setup_mdio_bus() net: sched: sample: allow accessing psample_group with rtnl net: sched: police: allow accessing police->params with rtnl net: hisilicon: Fix dma_map_single failed on arm64 net: hisilicon: fix hip04-xmit never return TX_BUSY net: hisilicon: make hip04_tx_reclaim non-reentrant tc-testing: updated vlan action tests with batch create/delete net sched: update vlan action for batched events operations net: stmmac: tc: Do not return a fragment entry net: stmmac: Fix issues when number of Queues >= 4 net: stmmac: xgmac: Fix XGMAC selftests be2net: disable bh with spin_lock in be_process_mcc net: cxgb3_main: Fix a resource leak in a error path in 'init_one()' net: ethernet: sun4i-emac: Support phy-handle property for finding PHYs net: bridge: move default pvid init/deinit to NETDEV_REGISTER/UNREGISTER ...
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/bpf/btf.c5
-rw-r--r--tools/lib/bpf/libbpf.c34
-rw-r--r--tools/lib/bpf/xsk.c11
-rw-r--r--tools/testing/selftests/bpf/Makefile3
-rw-r--r--tools/testing/selftests/bpf/progs/sendmsg6_prog.c3
-rwxr-xr-xtools/testing/selftests/bpf/test_xdp_vlan.sh57
-rwxr-xr-xtools/testing/selftests/bpf/test_xdp_vlan_mode_generic.sh9
-rwxr-xr-xtools/testing/selftests/bpf/test_xdp_vlan_mode_native.sh9
-rw-r--r--tools/testing/selftests/bpf/verifier/ctx_skb.c11
-rw-r--r--tools/testing/selftests/net/.gitignore4
-rwxr-xr-xtools/testing/selftests/net/forwarding/gre_multipath.sh28
-rw-r--r--tools/testing/selftests/net/tls.c223
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/vlan.json94
13 files changed, 443 insertions, 48 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 467224feb43b..d821107f55f9 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1,6 +1,7 @@
1// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 1// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2/* Copyright (c) 2018 Facebook */ 2/* Copyright (c) 2018 Facebook */
3 3
4#include <endian.h>
4#include <stdio.h> 5#include <stdio.h>
5#include <stdlib.h> 6#include <stdlib.h>
6#include <string.h> 7#include <string.h>
@@ -419,9 +420,9 @@ done:
419 420
420static bool btf_check_endianness(const GElf_Ehdr *ehdr) 421static bool btf_check_endianness(const GElf_Ehdr *ehdr)
421{ 422{
422#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 423#if __BYTE_ORDER == __LITTLE_ENDIAN
423 return ehdr->e_ident[EI_DATA] == ELFDATA2LSB; 424 return ehdr->e_ident[EI_DATA] == ELFDATA2LSB;
424#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 425#elif __BYTE_ORDER == __BIG_ENDIAN
425 return ehdr->e_ident[EI_DATA] == ELFDATA2MSB; 426 return ehdr->e_ident[EI_DATA] == ELFDATA2MSB;
426#else 427#else
427# error "Unrecognized __BYTE_ORDER__" 428# error "Unrecognized __BYTE_ORDER__"
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 794dd5064ae8..2586b6cb8f34 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -20,6 +20,7 @@
20#include <inttypes.h> 20#include <inttypes.h>
21#include <string.h> 21#include <string.h>
22#include <unistd.h> 22#include <unistd.h>
23#include <endian.h>
23#include <fcntl.h> 24#include <fcntl.h>
24#include <errno.h> 25#include <errno.h>
25#include <asm/unistd.h> 26#include <asm/unistd.h>
@@ -612,10 +613,10 @@ errout:
612 613
613static int bpf_object__check_endianness(struct bpf_object *obj) 614static int bpf_object__check_endianness(struct bpf_object *obj)
614{ 615{
615#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 616#if __BYTE_ORDER == __LITTLE_ENDIAN
616 if (obj->efile.ehdr.e_ident[EI_DATA] == ELFDATA2LSB) 617 if (obj->efile.ehdr.e_ident[EI_DATA] == ELFDATA2LSB)
617 return 0; 618 return 0;
618#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 619#elif __BYTE_ORDER == __BIG_ENDIAN
619 if (obj->efile.ehdr.e_ident[EI_DATA] == ELFDATA2MSB) 620 if (obj->efile.ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
620 return 0; 621 return 0;
621#else 622#else
@@ -1377,8 +1378,13 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj)
1377 if (!has_datasec && kind == BTF_KIND_VAR) { 1378 if (!has_datasec && kind == BTF_KIND_VAR) {
1378 /* replace VAR with INT */ 1379 /* replace VAR with INT */
1379 t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0); 1380 t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0);
1380 t->size = sizeof(int); 1381 /*
1381 *(int *)(t+1) = BTF_INT_ENC(0, 0, 32); 1382 * using size = 1 is the safest choice, 4 will be too
1383 * big and cause kernel BTF validation failure if
1384 * original variable took less than 4 bytes
1385 */
1386 t->size = 1;
1387 *(int *)(t+1) = BTF_INT_ENC(0, 0, 8);
1382 } else if (!has_datasec && kind == BTF_KIND_DATASEC) { 1388 } else if (!has_datasec && kind == BTF_KIND_DATASEC) {
1383 /* replace DATASEC with STRUCT */ 1389 /* replace DATASEC with STRUCT */
1384 struct btf_var_secinfo *v = (void *)(t + 1); 1390 struct btf_var_secinfo *v = (void *)(t + 1);
@@ -1500,6 +1506,12 @@ static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj)
1500 BTF_ELF_SEC, err); 1506 BTF_ELF_SEC, err);
1501 btf__free(obj->btf); 1507 btf__free(obj->btf);
1502 obj->btf = NULL; 1508 obj->btf = NULL;
1509 /* btf_ext can't exist without btf, so free it as well */
1510 if (obj->btf_ext) {
1511 btf_ext__free(obj->btf_ext);
1512 obj->btf_ext = NULL;
1513 }
1514
1503 if (bpf_object__is_btf_mandatory(obj)) 1515 if (bpf_object__is_btf_mandatory(obj))
1504 return err; 1516 return err;
1505 } 1517 }
@@ -4507,13 +4519,13 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,
4507 const struct perf_buffer_opts *opts) 4519 const struct perf_buffer_opts *opts)
4508{ 4520{
4509 struct perf_buffer_params p = {}; 4521 struct perf_buffer_params p = {};
4510 struct perf_event_attr attr = { 4522 struct perf_event_attr attr = { 0, };
4511 .config = PERF_COUNT_SW_BPF_OUTPUT, 4523
4512 .type = PERF_TYPE_SOFTWARE, 4524 attr.config = PERF_COUNT_SW_BPF_OUTPUT,
4513 .sample_type = PERF_SAMPLE_RAW, 4525 attr.type = PERF_TYPE_SOFTWARE;
4514 .sample_period = 1, 4526 attr.sample_type = PERF_SAMPLE_RAW;
4515 .wakeup_events = 1, 4527 attr.sample_period = 1;
4516 }; 4528 attr.wakeup_events = 1;
4517 4529
4518 p.attr = &attr; 4530 p.attr = &attr;
4519 p.sample_cb = opts ? opts->sample_cb : NULL; 4531 p.sample_cb = opts ? opts->sample_cb : NULL;
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 5007b5d4fd2c..680e63066cf3 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -317,17 +317,16 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
317 317
318static int xsk_get_max_queues(struct xsk_socket *xsk) 318static int xsk_get_max_queues(struct xsk_socket *xsk)
319{ 319{
320 struct ethtool_channels channels; 320 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
321 struct ifreq ifr; 321 struct ifreq ifr = {};
322 int fd, err, ret; 322 int fd, err, ret;
323 323
324 fd = socket(AF_INET, SOCK_DGRAM, 0); 324 fd = socket(AF_INET, SOCK_DGRAM, 0);
325 if (fd < 0) 325 if (fd < 0)
326 return -errno; 326 return -errno;
327 327
328 channels.cmd = ETHTOOL_GCHANNELS;
329 ifr.ifr_data = (void *)&channels; 328 ifr.ifr_data = (void *)&channels;
330 strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1); 329 memcpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1);
331 ifr.ifr_name[IFNAMSIZ - 1] = '\0'; 330 ifr.ifr_name[IFNAMSIZ - 1] = '\0';
332 err = ioctl(fd, SIOCETHTOOL, &ifr); 331 err = ioctl(fd, SIOCETHTOOL, &ifr);
333 if (err && errno != EOPNOTSUPP) { 332 if (err && errno != EOPNOTSUPP) {
@@ -335,7 +334,7 @@ static int xsk_get_max_queues(struct xsk_socket *xsk)
335 goto out; 334 goto out;
336 } 335 }
337 336
338 if (channels.max_combined == 0 || errno == EOPNOTSUPP) 337 if (err || channels.max_combined == 0)
339 /* If the device says it has no channels, then all traffic 338 /* If the device says it has no channels, then all traffic
340 * is sent to a single stream, so max queues = 1. 339 * is sent to a single stream, so max queues = 1.
341 */ 340 */
@@ -517,7 +516,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
517 err = -errno; 516 err = -errno;
518 goto out_socket; 517 goto out_socket;
519 } 518 }
520 strncpy(xsk->ifname, ifname, IFNAMSIZ - 1); 519 memcpy(xsk->ifname, ifname, IFNAMSIZ - 1);
521 xsk->ifname[IFNAMSIZ - 1] = '\0'; 520 xsk->ifname[IFNAMSIZ - 1] = '\0';
522 521
523 err = xsk_set_xdp_socket_config(&xsk->config, usr_config); 522 err = xsk_set_xdp_socket_config(&xsk->config, usr_config);
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 11c9c62c3362..c085964e1d05 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -57,7 +57,8 @@ TEST_PROGS := test_kmod.sh \
57 test_lirc_mode2.sh \ 57 test_lirc_mode2.sh \
58 test_skb_cgroup_id.sh \ 58 test_skb_cgroup_id.sh \
59 test_flow_dissector.sh \ 59 test_flow_dissector.sh \
60 test_xdp_vlan.sh \ 60 test_xdp_vlan_mode_generic.sh \
61 test_xdp_vlan_mode_native.sh \
61 test_lwt_ip_encap.sh \ 62 test_lwt_ip_encap.sh \
62 test_tcp_check_syncookie.sh \ 63 test_tcp_check_syncookie.sh \
63 test_tc_tunnel.sh \ 64 test_tc_tunnel.sh \
diff --git a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
index 5aeaa284fc47..a68062820410 100644
--- a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
+++ b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
@@ -41,8 +41,7 @@ int sendmsg_v6_prog(struct bpf_sock_addr *ctx)
41 } 41 }
42 42
43 /* Rewrite destination. */ 43 /* Rewrite destination. */
44 if ((ctx->user_ip6[0] & 0xFFFF) == bpf_htons(0xFACE) && 44 if (ctx->user_ip6[0] == bpf_htonl(0xFACEB00C)) {
45 ctx->user_ip6[0] >> 16 == bpf_htons(0xB00C)) {
46 ctx->user_ip6[0] = bpf_htonl(DST_REWRITE_IP6_0); 45 ctx->user_ip6[0] = bpf_htonl(DST_REWRITE_IP6_0);
47 ctx->user_ip6[1] = bpf_htonl(DST_REWRITE_IP6_1); 46 ctx->user_ip6[1] = bpf_htonl(DST_REWRITE_IP6_1);
48 ctx->user_ip6[2] = bpf_htonl(DST_REWRITE_IP6_2); 47 ctx->user_ip6[2] = bpf_htonl(DST_REWRITE_IP6_2);
diff --git a/tools/testing/selftests/bpf/test_xdp_vlan.sh b/tools/testing/selftests/bpf/test_xdp_vlan.sh
index 51a3a31d1aac..bb8b0da91686 100755
--- a/tools/testing/selftests/bpf/test_xdp_vlan.sh
+++ b/tools/testing/selftests/bpf/test_xdp_vlan.sh
@@ -1,6 +1,14 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3# Author: Jesper Dangaard Brouer <hawk@kernel.org>
2 4
3TESTNAME=xdp_vlan 5# Allow wrapper scripts to name test
6if [ -z "$TESTNAME" ]; then
7 TESTNAME=xdp_vlan
8fi
9
10# Default XDP mode
11XDP_MODE=xdpgeneric
4 12
5usage() { 13usage() {
6 echo "Testing XDP + TC eBPF VLAN manipulations: $TESTNAME" 14 echo "Testing XDP + TC eBPF VLAN manipulations: $TESTNAME"
@@ -9,9 +17,23 @@ usage() {
9 echo " -v | --verbose : Verbose" 17 echo " -v | --verbose : Verbose"
10 echo " --flush : Flush before starting (e.g. after --interactive)" 18 echo " --flush : Flush before starting (e.g. after --interactive)"
11 echo " --interactive : Keep netns setup running after test-run" 19 echo " --interactive : Keep netns setup running after test-run"
20 echo " --mode=XXX : Choose XDP mode (xdp | xdpgeneric | xdpdrv)"
12 echo "" 21 echo ""
13} 22}
14 23
24valid_xdp_mode()
25{
26 local mode=$1
27
28 case "$mode" in
29 xdpgeneric | xdpdrv | xdp)
30 return 0
31 ;;
32 *)
33 return 1
34 esac
35}
36
15cleanup() 37cleanup()
16{ 38{
17 local status=$? 39 local status=$?
@@ -37,7 +59,7 @@ cleanup()
37 59
38# Using external program "getopt" to get --long-options 60# Using external program "getopt" to get --long-options
39OPTIONS=$(getopt -o hvfi: \ 61OPTIONS=$(getopt -o hvfi: \
40 --long verbose,flush,help,interactive,debug -- "$@") 62 --long verbose,flush,help,interactive,debug,mode: -- "$@")
41if (( $? != 0 )); then 63if (( $? != 0 )); then
42 usage 64 usage
43 echo "selftests: $TESTNAME [FAILED] Error calling getopt, unknown option?" 65 echo "selftests: $TESTNAME [FAILED] Error calling getopt, unknown option?"
@@ -60,6 +82,11 @@ while true; do
60 cleanup 82 cleanup
61 shift 83 shift
62 ;; 84 ;;
85 --mode )
86 shift
87 XDP_MODE=$1
88 shift
89 ;;
63 -- ) 90 -- )
64 shift 91 shift
65 break 92 break
@@ -81,8 +108,14 @@ if [ "$EUID" -ne 0 ]; then
81 exit 1 108 exit 1
82fi 109fi
83 110
84ip link set dev lo xdp off 2>/dev/null > /dev/null 111valid_xdp_mode $XDP_MODE
85if [ $? -ne 0 ];then 112if [ $? -ne 0 ]; then
113 echo "selftests: $TESTNAME [FAILED] unknown XDP mode ($XDP_MODE)"
114 exit 1
115fi
116
117ip link set dev lo xdpgeneric off 2>/dev/null > /dev/null
118if [ $? -ne 0 ]; then
86 echo "selftests: $TESTNAME [SKIP] need ip xdp support" 119 echo "selftests: $TESTNAME [SKIP] need ip xdp support"
87 exit 0 120 exit 0
88fi 121fi
@@ -155,7 +188,7 @@ ip netns exec ns2 ip link set lo up
155# At this point, the hosts cannot reach each-other, 188# At this point, the hosts cannot reach each-other,
156# because ns2 are using VLAN tags on the packets. 189# because ns2 are using VLAN tags on the packets.
157 190
158ip netns exec ns2 sh -c 'ping -W 1 -c 1 100.64.41.1 || echo "Okay ping fails"' 191ip netns exec ns2 sh -c 'ping -W 1 -c 1 100.64.41.1 || echo "Success: First ping must fail"'
159 192
160 193
161# Now we can use the test_xdp_vlan.c program to pop/push these VLAN tags 194# Now we can use the test_xdp_vlan.c program to pop/push these VLAN tags
@@ -166,7 +199,7 @@ export FILE=test_xdp_vlan.o
166 199
167# First test: Remove VLAN by setting VLAN ID 0, using "xdp_vlan_change" 200# First test: Remove VLAN by setting VLAN ID 0, using "xdp_vlan_change"
168export XDP_PROG=xdp_vlan_change 201export XDP_PROG=xdp_vlan_change
169ip netns exec ns1 ip link set $DEVNS1 xdp object $FILE section $XDP_PROG 202ip netns exec ns1 ip link set $DEVNS1 $XDP_MODE object $FILE section $XDP_PROG
170 203
171# In ns1: egress use TC to add back VLAN tag 4011 204# In ns1: egress use TC to add back VLAN tag 4011
172# (del cmd) 205# (del cmd)
@@ -177,8 +210,8 @@ ip netns exec ns1 tc filter add dev $DEVNS1 egress \
177 prio 1 handle 1 bpf da obj $FILE sec tc_vlan_push 210 prio 1 handle 1 bpf da obj $FILE sec tc_vlan_push
178 211
179# Now the namespaces can reach each-other, test with ping: 212# Now the namespaces can reach each-other, test with ping:
180ip netns exec ns2 ping -W 2 -c 3 $IPADDR1 213ip netns exec ns2 ping -i 0.2 -W 2 -c 2 $IPADDR1
181ip netns exec ns1 ping -W 2 -c 3 $IPADDR2 214ip netns exec ns1 ping -i 0.2 -W 2 -c 2 $IPADDR2
182 215
183# Second test: Replace xdp prog, that fully remove vlan header 216# Second test: Replace xdp prog, that fully remove vlan header
184# 217#
@@ -187,9 +220,9 @@ ip netns exec ns1 ping -W 2 -c 3 $IPADDR2
187# ETH_P_8021Q indication, and this cause overwriting of our changes. 220# ETH_P_8021Q indication, and this cause overwriting of our changes.
188# 221#
189export XDP_PROG=xdp_vlan_remove_outer2 222export XDP_PROG=xdp_vlan_remove_outer2
190ip netns exec ns1 ip link set $DEVNS1 xdp off 223ip netns exec ns1 ip link set $DEVNS1 $XDP_MODE off
191ip netns exec ns1 ip link set $DEVNS1 xdp object $FILE section $XDP_PROG 224ip netns exec ns1 ip link set $DEVNS1 $XDP_MODE object $FILE section $XDP_PROG
192 225
193# Now the namespaces should still be able reach each-other, test with ping: 226# Now the namespaces should still be able reach each-other, test with ping:
194ip netns exec ns2 ping -W 2 -c 3 $IPADDR1 227ip netns exec ns2 ping -i 0.2 -W 2 -c 2 $IPADDR1
195ip netns exec ns1 ping -W 2 -c 3 $IPADDR2 228ip netns exec ns1 ping -i 0.2 -W 2 -c 2 $IPADDR2
diff --git a/tools/testing/selftests/bpf/test_xdp_vlan_mode_generic.sh b/tools/testing/selftests/bpf/test_xdp_vlan_mode_generic.sh
new file mode 100755
index 000000000000..c515326d6d59
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_xdp_vlan_mode_generic.sh
@@ -0,0 +1,9 @@
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Exit on failure
5set -e
6
7# Wrapper script to test generic-XDP
8export TESTNAME=xdp_vlan_mode_generic
9./test_xdp_vlan.sh --mode=xdpgeneric
diff --git a/tools/testing/selftests/bpf/test_xdp_vlan_mode_native.sh b/tools/testing/selftests/bpf/test_xdp_vlan_mode_native.sh
new file mode 100755
index 000000000000..5cf7ce1f16c1
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_xdp_vlan_mode_native.sh
@@ -0,0 +1,9 @@
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Exit on failure
5set -e
6
7# Wrapper script to test native-XDP
8export TESTNAME=xdp_vlan_mode_native
9./test_xdp_vlan.sh --mode=xdpdrv
diff --git a/tools/testing/selftests/bpf/verifier/ctx_skb.c b/tools/testing/selftests/bpf/verifier/ctx_skb.c
index b0fda2877119..d438193804b2 100644
--- a/tools/testing/selftests/bpf/verifier/ctx_skb.c
+++ b/tools/testing/selftests/bpf/verifier/ctx_skb.c
@@ -975,6 +975,17 @@
975 .prog_type = BPF_PROG_TYPE_CGROUP_SKB, 975 .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
976}, 976},
977{ 977{
978 "read gso_segs from CGROUP_SKB",
979 .insns = {
980 BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_1,
981 offsetof(struct __sk_buff, gso_segs)),
982 BPF_MOV64_IMM(BPF_REG_0, 0),
983 BPF_EXIT_INSN(),
984 },
985 .result = ACCEPT,
986 .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
987},
988{
978 "write gso_segs from CGROUP_SKB", 989 "write gso_segs from CGROUP_SKB",
979 .insns = { 990 .insns = {
980 BPF_MOV64_IMM(BPF_REG_0, 0), 991 BPF_MOV64_IMM(BPF_REG_0, 0),
diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore
index 4ce0bc1612f5..c7cced739c34 100644
--- a/tools/testing/selftests/net/.gitignore
+++ b/tools/testing/selftests/net/.gitignore
@@ -17,7 +17,7 @@ tcp_inq
17tls 17tls
18txring_overwrite 18txring_overwrite
19ip_defrag 19ip_defrag
20ipv6_flowlabel
21ipv6_flowlabel_mgr
20so_txtime 22so_txtime
21flowlabel
22flowlabel_mgr
23tcp_fastopen_backup_key 23tcp_fastopen_backup_key
diff --git a/tools/testing/selftests/net/forwarding/gre_multipath.sh b/tools/testing/selftests/net/forwarding/gre_multipath.sh
index cca2baa03fb8..a8d8e8b3dc81 100755
--- a/tools/testing/selftests/net/forwarding/gre_multipath.sh
+++ b/tools/testing/selftests/net/forwarding/gre_multipath.sh
@@ -93,18 +93,10 @@ sw1_create()
93 ip route add vrf v$ol1 192.0.2.16/28 \ 93 ip route add vrf v$ol1 192.0.2.16/28 \
94 nexthop dev g1a \ 94 nexthop dev g1a \
95 nexthop dev g1b 95 nexthop dev g1b
96
97 tc qdisc add dev $ul1 clsact
98 tc filter add dev $ul1 egress pref 111 prot ipv4 \
99 flower dst_ip 192.0.2.66 action pass
100 tc filter add dev $ul1 egress pref 222 prot ipv4 \
101 flower dst_ip 192.0.2.82 action pass
102} 96}
103 97
104sw1_destroy() 98sw1_destroy()
105{ 99{
106 tc qdisc del dev $ul1 clsact
107
108 ip route del vrf v$ol1 192.0.2.16/28 100 ip route del vrf v$ol1 192.0.2.16/28
109 101
110 ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146 102 ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
@@ -139,10 +131,18 @@ sw2_create()
139 ip route add vrf v$ol2 192.0.2.0/28 \ 131 ip route add vrf v$ol2 192.0.2.0/28 \
140 nexthop dev g2a \ 132 nexthop dev g2a \
141 nexthop dev g2b 133 nexthop dev g2b
134
135 tc qdisc add dev $ul2 clsact
136 tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
137 flower vlan_id 111 action pass
138 tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
139 flower vlan_id 222 action pass
142} 140}
143 141
144sw2_destroy() 142sw2_destroy()
145{ 143{
144 tc qdisc del dev $ul2 clsact
145
146 ip route del vrf v$ol2 192.0.2.0/28 146 ip route del vrf v$ol2 192.0.2.0/28
147 147
148 ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145 148 ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
@@ -187,12 +187,16 @@ setup_prepare()
187 sw1_create 187 sw1_create
188 sw2_create 188 sw2_create
189 h2_create 189 h2_create
190
191 forwarding_enable
190} 192}
191 193
192cleanup() 194cleanup()
193{ 195{
194 pre_cleanup 196 pre_cleanup
195 197
198 forwarding_restore
199
196 h2_destroy 200 h2_destroy
197 sw2_destroy 201 sw2_destroy
198 sw1_destroy 202 sw1_destroy
@@ -211,15 +215,15 @@ multipath4_test()
211 nexthop dev g1a weight $weight1 \ 215 nexthop dev g1a weight $weight1 \
212 nexthop dev g1b weight $weight2 216 nexthop dev g1b weight $weight2
213 217
214 local t0_111=$(tc_rule_stats_get $ul1 111 egress) 218 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
215 local t0_222=$(tc_rule_stats_get $ul1 222 egress) 219 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
216 220
217 ip vrf exec v$h1 \ 221 ip vrf exec v$h1 \
218 $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \ 222 $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
219 -d 1msec -t udp "sp=1024,dp=0-32768" 223 -d 1msec -t udp "sp=1024,dp=0-32768"
220 224
221 local t1_111=$(tc_rule_stats_get $ul1 111 egress) 225 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
222 local t1_222=$(tc_rule_stats_get $ul1 222 egress) 226 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
223 227
224 local d111=$((t1_111 - t0_111)) 228 local d111=$((t1_111 - t0_111))
225 local d222=$((t1_222 - t0_222)) 229 local d222=$((t1_222 - t0_222))
diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
index 090fff9dbc48..4c285b6e1db8 100644
--- a/tools/testing/selftests/net/tls.c
+++ b/tools/testing/selftests/net/tls.c
@@ -25,6 +25,80 @@
25#define TLS_PAYLOAD_MAX_LEN 16384 25#define TLS_PAYLOAD_MAX_LEN 16384
26#define SOL_TLS 282 26#define SOL_TLS 282
27 27
28#ifndef ENOTSUPP
29#define ENOTSUPP 524
30#endif
31
32FIXTURE(tls_basic)
33{
34 int fd, cfd;
35 bool notls;
36};
37
38FIXTURE_SETUP(tls_basic)
39{
40 struct sockaddr_in addr;
41 socklen_t len;
42 int sfd, ret;
43
44 self->notls = false;
45 len = sizeof(addr);
46
47 addr.sin_family = AF_INET;
48 addr.sin_addr.s_addr = htonl(INADDR_ANY);
49 addr.sin_port = 0;
50
51 self->fd = socket(AF_INET, SOCK_STREAM, 0);
52 sfd = socket(AF_INET, SOCK_STREAM, 0);
53
54 ret = bind(sfd, &addr, sizeof(addr));
55 ASSERT_EQ(ret, 0);
56 ret = listen(sfd, 10);
57 ASSERT_EQ(ret, 0);
58
59 ret = getsockname(sfd, &addr, &len);
60 ASSERT_EQ(ret, 0);
61
62 ret = connect(self->fd, &addr, sizeof(addr));
63 ASSERT_EQ(ret, 0);
64
65 self->cfd = accept(sfd, &addr, &len);
66 ASSERT_GE(self->cfd, 0);
67
68 close(sfd);
69
70 ret = setsockopt(self->fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
71 if (ret != 0) {
72 ASSERT_EQ(errno, ENOENT);
73 self->notls = true;
74 printf("Failure setting TCP_ULP, testing without tls\n");
75 return;
76 }
77
78 ret = setsockopt(self->cfd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
79 ASSERT_EQ(ret, 0);
80}
81
82FIXTURE_TEARDOWN(tls_basic)
83{
84 close(self->fd);
85 close(self->cfd);
86}
87
88/* Send some data through with ULP but no keys */
89TEST_F(tls_basic, base_base)
90{
91 char const *test_str = "test_read";
92 int send_len = 10;
93 char buf[10];
94
95 ASSERT_EQ(strlen(test_str) + 1, send_len);
96
97 EXPECT_EQ(send(self->fd, test_str, send_len, 0), send_len);
98 EXPECT_NE(recv(self->cfd, buf, send_len, 0), -1);
99 EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
100};
101
28FIXTURE(tls) 102FIXTURE(tls)
29{ 103{
30 int fd, cfd; 104 int fd, cfd;
@@ -165,6 +239,16 @@ TEST_F(tls, msg_more)
165 EXPECT_EQ(memcmp(buf, test_str, send_len), 0); 239 EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
166} 240}
167 241
242TEST_F(tls, msg_more_unsent)
243{
244 char const *test_str = "test_read";
245 int send_len = 10;
246 char buf[10];
247
248 EXPECT_EQ(send(self->fd, test_str, send_len, MSG_MORE), send_len);
249 EXPECT_EQ(recv(self->cfd, buf, send_len, MSG_DONTWAIT), -1);
250}
251
168TEST_F(tls, sendmsg_single) 252TEST_F(tls, sendmsg_single)
169{ 253{
170 struct msghdr msg; 254 struct msghdr msg;
@@ -610,6 +694,42 @@ TEST_F(tls, recv_lowat)
610 EXPECT_EQ(memcmp(send_mem, recv_mem + 10, 5), 0); 694 EXPECT_EQ(memcmp(send_mem, recv_mem + 10, 5), 0);
611} 695}
612 696
697TEST_F(tls, bidir)
698{
699 char const *test_str = "test_read";
700 int send_len = 10;
701 char buf[10];
702 int ret;
703
704 if (!self->notls) {
705 struct tls12_crypto_info_aes_gcm_128 tls12;
706
707 memset(&tls12, 0, sizeof(tls12));
708 tls12.info.version = TLS_1_3_VERSION;
709 tls12.info.cipher_type = TLS_CIPHER_AES_GCM_128;
710
711 ret = setsockopt(self->fd, SOL_TLS, TLS_RX, &tls12,
712 sizeof(tls12));
713 ASSERT_EQ(ret, 0);
714
715 ret = setsockopt(self->cfd, SOL_TLS, TLS_TX, &tls12,
716 sizeof(tls12));
717 ASSERT_EQ(ret, 0);
718 }
719
720 ASSERT_EQ(strlen(test_str) + 1, send_len);
721
722 EXPECT_EQ(send(self->fd, test_str, send_len, 0), send_len);
723 EXPECT_NE(recv(self->cfd, buf, send_len, 0), -1);
724 EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
725
726 memset(buf, 0, sizeof(buf));
727
728 EXPECT_EQ(send(self->cfd, test_str, send_len, 0), send_len);
729 EXPECT_NE(recv(self->fd, buf, send_len, 0), -1);
730 EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
731};
732
613TEST_F(tls, pollin) 733TEST_F(tls, pollin)
614{ 734{
615 char const *test_str = "test_poll"; 735 char const *test_str = "test_poll";
@@ -837,6 +957,109 @@ TEST_F(tls, control_msg)
837 EXPECT_EQ(memcmp(buf, test_str, send_len), 0); 957 EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
838} 958}
839 959
960TEST_F(tls, shutdown)
961{
962 char const *test_str = "test_read";
963 int send_len = 10;
964 char buf[10];
965
966 ASSERT_EQ(strlen(test_str) + 1, send_len);
967
968 EXPECT_EQ(send(self->fd, test_str, send_len, 0), send_len);
969 EXPECT_NE(recv(self->cfd, buf, send_len, 0), -1);
970 EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
971
972 shutdown(self->fd, SHUT_RDWR);
973 shutdown(self->cfd, SHUT_RDWR);
974}
975
976TEST_F(tls, shutdown_unsent)
977{
978 char const *test_str = "test_read";
979 int send_len = 10;
980
981 EXPECT_EQ(send(self->fd, test_str, send_len, MSG_MORE), send_len);
982
983 shutdown(self->fd, SHUT_RDWR);
984 shutdown(self->cfd, SHUT_RDWR);
985}
986
987TEST_F(tls, shutdown_reuse)
988{
989 struct sockaddr_in addr;
990 int ret;
991
992 shutdown(self->fd, SHUT_RDWR);
993 shutdown(self->cfd, SHUT_RDWR);
994 close(self->cfd);
995
996 addr.sin_family = AF_INET;
997 addr.sin_addr.s_addr = htonl(INADDR_ANY);
998 addr.sin_port = 0;
999
1000 ret = bind(self->fd, &addr, sizeof(addr));
1001 EXPECT_EQ(ret, 0);
1002 ret = listen(self->fd, 10);
1003 EXPECT_EQ(ret, -1);
1004 EXPECT_EQ(errno, EINVAL);
1005
1006 ret = connect(self->fd, &addr, sizeof(addr));
1007 EXPECT_EQ(ret, -1);
1008 EXPECT_EQ(errno, EISCONN);
1009}
1010
1011TEST(non_established) {
1012 struct tls12_crypto_info_aes_gcm_256 tls12;
1013 struct sockaddr_in addr;
1014 int sfd, ret, fd;
1015 socklen_t len;
1016
1017 len = sizeof(addr);
1018
1019 memset(&tls12, 0, sizeof(tls12));
1020 tls12.info.version = TLS_1_2_VERSION;
1021 tls12.info.cipher_type = TLS_CIPHER_AES_GCM_256;
1022
1023 addr.sin_family = AF_INET;
1024 addr.sin_addr.s_addr = htonl(INADDR_ANY);
1025 addr.sin_port = 0;
1026
1027 fd = socket(AF_INET, SOCK_STREAM, 0);
1028 sfd = socket(AF_INET, SOCK_STREAM, 0);
1029
1030 ret = bind(sfd, &addr, sizeof(addr));
1031 ASSERT_EQ(ret, 0);
1032 ret = listen(sfd, 10);
1033 ASSERT_EQ(ret, 0);
1034
1035 ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
1036 EXPECT_EQ(ret, -1);
1037 /* TLS ULP not supported */
1038 if (errno == ENOENT)
1039 return;
1040 EXPECT_EQ(errno, ENOTSUPP);
1041
1042 ret = setsockopt(sfd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
1043 EXPECT_EQ(ret, -1);
1044 EXPECT_EQ(errno, ENOTSUPP);
1045
1046 ret = getsockname(sfd, &addr, &len);
1047 ASSERT_EQ(ret, 0);
1048
1049 ret = connect(fd, &addr, sizeof(addr));
1050 ASSERT_EQ(ret, 0);
1051
1052 ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
1053 ASSERT_EQ(ret, 0);
1054
1055 ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
1056 EXPECT_EQ(ret, -1);
1057 EXPECT_EQ(errno, EEXIST);
1058
1059 close(fd);
1060 close(sfd);
1061}
1062
840TEST(keysizes) { 1063TEST(keysizes) {
841 struct tls12_crypto_info_aes_gcm_256 tls12; 1064 struct tls12_crypto_info_aes_gcm_256 tls12;
842 struct sockaddr_in addr; 1065 struct sockaddr_in addr;
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/vlan.json b/tools/testing/selftests/tc-testing/tc-tests/actions/vlan.json
index cc7c7d758008..6503b1ce091f 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/vlan.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/vlan.json
@@ -713,5 +713,99 @@
713 "teardown": [ 713 "teardown": [
714 "$TC actions flush action vlan" 714 "$TC actions flush action vlan"
715 ] 715 ]
716 },
717 {
718 "id": "294e",
719 "name": "Add batch of 32 vlan push actions with cookie",
720 "category": [
721 "actions",
722 "vlan"
723 ],
724 "setup": [
725 [
726 "$TC actions flush action vlan",
727 0,
728 1,
729 255
730 ]
731 ],
732 "cmdUnderTest": "bash -c \"for i in \\`seq 1 32\\`; do cmd=\\\"action vlan push protocol 802.1q id 4094 priority 7 pipe index \\$i cookie aabbccddeeff112233445566778800a1 \\\"; args=\"\\$args\\$cmd\"; done && $TC actions add \\$args\"",
733 "expExitCode": "0",
734 "verifyCmd": "$TC actions list action vlan",
735 "matchPattern": "^[ \t]+index [0-9]+ ref",
736 "matchCount": "32",
737 "teardown": [
738 "$TC actions flush action vlan"
739 ]
740 },
741 {
742 "id": "56f7",
743 "name": "Delete batch of 32 vlan push actions",
744 "category": [
745 "actions",
746 "vlan"
747 ],
748 "setup": [
749 [
750 "$TC actions flush action vlan",
751 0,
752 1,
753 255
754 ],
755 "bash -c \"for i in \\`seq 1 32\\`; do cmd=\\\"action vlan push protocol 802.1q id 4094 priority 7 pipe index \\$i \\\"; args=\\\"\\$args\\$cmd\\\"; done && $TC actions add \\$args\""
756 ],
757 "cmdUnderTest": "bash -c \"for i in \\`seq 1 32\\`; do cmd=\\\"action vlan index \\$i \\\"; args=\"\\$args\\$cmd\"; done && $TC actions del \\$args\"",
758 "expExitCode": "0",
759 "verifyCmd": "$TC actions list action vlan",
760 "matchPattern": "^[ \t]+index [0-9]+ ref",
761 "matchCount": "0",
762 "teardown": []
763 },
764 {
765 "id": "759f",
766 "name": "Add batch of 32 vlan pop actions with cookie",
767 "category": [
768 "actions",
769 "vlan"
770 ],
771 "setup": [
772 [
773 "$TC actions flush action vlan",
774 0,
775 1,
776 255
777 ]
778 ],
779 "cmdUnderTest": "bash -c \"for i in \\`seq 1 32\\`; do cmd=\\\"action vlan pop continue index \\$i cookie aabbccddeeff112233445566778800a1 \\\"; args=\"\\$args\\$cmd\"; done && $TC actions add \\$args\"",
780 "expExitCode": "0",
781 "verifyCmd": "$TC actions list action vlan",
782 "matchPattern": "^[ \t]+index [0-9]+ ref",
783 "matchCount": "32",
784 "teardown": [
785 "$TC actions flush action vlan"
786 ]
787 },
788 {
789 "id": "c84a",
790 "name": "Delete batch of 32 vlan pop actions",
791 "category": [
792 "actions",
793 "vlan"
794 ],
795 "setup": [
796 [
797 "$TC actions flush action vlan",
798 0,
799 1,
800 255
801 ],
802 "bash -c \"for i in \\`seq 1 32\\`; do cmd=\\\"action vlan pop index \\$i \\\"; args=\\\"\\$args\\$cmd\\\"; done && $TC actions add \\$args\""
803 ],
804 "cmdUnderTest": "bash -c \"for i in \\`seq 1 32\\`; do cmd=\\\"action vlan index \\$i \\\"; args=\"\\$args\\$cmd\"; done && $TC actions del \\$args\"",
805 "expExitCode": "0",
806 "verifyCmd": "$TC actions list action vlan",
807 "matchPattern": "^[ \t]+index [0-9]+ ref",
808 "matchCount": "0",
809 "teardown": []
716 } 810 }
717] 811]