aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/nvdimm/dimm_devs.c4
-rw-r--r--tools/testing/selftests/Makefile1
-rw-r--r--tools/testing/selftests/bpf/.gitignore1
-rw-r--r--tools/testing/selftests/bpf/Makefile5
-rw-r--r--tools/testing/selftests/bpf/bpf_util.h30
-rw-r--r--tools/testing/selftests/bpf/cgroup_helpers.c6
-rw-r--r--tools/testing/selftests/bpf/test_btf.c38
-rw-r--r--tools/testing/selftests/bpf/test_cgroup_storage.c2
-rw-r--r--tools/testing/selftests/bpf/test_dev_cgroup.c2
-rw-r--r--tools/testing/selftests/bpf/test_lpm_map.c10
-rw-r--r--tools/testing/selftests/bpf/test_netcnt.c2
-rw-r--r--tools/testing/selftests/bpf/test_progs.c30
-rw-r--r--tools/testing/selftests/bpf/test_skb_cgroup_id_user.c2
-rw-r--r--tools/testing/selftests/bpf/test_sock.c2
-rw-r--r--tools/testing/selftests/bpf/test_sock_addr.c55
-rw-r--r--tools/testing/selftests/bpf/test_socket_cookie.c2
-rw-r--r--tools/testing/selftests/bpf/test_tcpbpf_user.c2
-rw-r--r--tools/testing/selftests/bpf/test_tcpnotify_user.c2
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c120
-rwxr-xr-xtools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh13
-rwxr-xr-xtools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh20
-rwxr-xr-xtools/testing/selftests/drivers/net/mlxsw/vxlan.sh18
-rw-r--r--tools/testing/selftests/filesystems/binderfs/.gitignore1
-rw-r--r--tools/testing/selftests/filesystems/binderfs/Makefile6
-rw-r--r--tools/testing/selftests/filesystems/binderfs/binderfs_test.c275
-rw-r--r--tools/testing/selftests/filesystems/binderfs/config3
-rw-r--r--tools/testing/selftests/gpio/gpio-mockup-chardev.c9
-rw-r--r--tools/testing/selftests/ir/Makefile2
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c9
-rw-r--r--tools/testing/selftests/kvm/x86_64/evmcs_test.c6
-rw-r--r--tools/testing/selftests/net/Makefile2
-rwxr-xr-xtools/testing/selftests/net/fib_tests.sh1
-rwxr-xr-xtools/testing/selftests/net/forwarding/bridge_vlan_aware.sh47
-rwxr-xr-xtools/testing/selftests/net/forwarding/vxlan_bridge_1d.sh2
-rw-r--r--tools/testing/selftests/net/ip_defrag.c96
-rwxr-xr-xtools/testing/selftests/net/ip_defrag.sh9
-rwxr-xr-xtools/testing/selftests/net/xfrm_policy.sh153
-rw-r--r--tools/testing/selftests/netfilter/Makefile2
-rw-r--r--tools/testing/selftests/netfilter/config2
-rwxr-xr-xtools/testing/selftests/netfilter/nft_nat.sh762
-rw-r--r--tools/testing/selftests/networking/timestamping/Makefile3
-rw-r--r--tools/testing/selftests/networking/timestamping/txtimestamp.c2
-rw-r--r--tools/testing/selftests/proc/.gitignore1
-rw-r--r--tools/testing/selftests/proc/Makefile1
-rw-r--r--tools/testing/selftests/proc/setns-dcache.c129
-rw-r--r--tools/testing/selftests/rtc/rtctest.c109
-rw-r--r--tools/testing/selftests/seccomp/Makefile2
-rw-r--r--tools/testing/selftests/seccomp/seccomp_bpf.c82
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/ife.json88
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json31
-rw-r--r--tools/testing/selftests/timers/Makefile2
-rw-r--r--tools/testing/selftests/vm/gup_benchmark.c1
-rw-r--r--tools/testing/selftests/x86/mpx-mini-test.c2
-rw-r--r--tools/testing/selftests/x86/protection_keys.c41
-rw-r--r--tools/testing/selftests/x86/unwind_vdso.c1
55 files changed, 2040 insertions, 209 deletions
diff --git a/tools/testing/nvdimm/dimm_devs.c b/tools/testing/nvdimm/dimm_devs.c
index e75238404555..2d4baf57822f 100644
--- a/tools/testing/nvdimm/dimm_devs.c
+++ b/tools/testing/nvdimm/dimm_devs.c
@@ -18,8 +18,8 @@ ssize_t security_show(struct device *dev,
18 * For the test version we need to poll the "hardware" in order 18 * For the test version we need to poll the "hardware" in order
19 * to get the updated status for unlock testing. 19 * to get the updated status for unlock testing.
20 */ 20 */
21 nvdimm->sec.state = nvdimm_security_state(nvdimm, false); 21 nvdimm->sec.state = nvdimm_security_state(nvdimm, NVDIMM_USER);
22 nvdimm->sec.ext_state = nvdimm_security_state(nvdimm, true); 22 nvdimm->sec.ext_state = nvdimm_security_state(nvdimm, NVDIMM_MASTER);
23 23
24 switch (nvdimm->sec.state) { 24 switch (nvdimm->sec.state) {
25 case NVDIMM_SECURITY_DISABLED: 25 case NVDIMM_SECURITY_DISABLED:
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 1a2bd15c5b6e..400ee81a3043 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -10,6 +10,7 @@ TARGETS += drivers/dma-buf
10TARGETS += efivarfs 10TARGETS += efivarfs
11TARGETS += exec 11TARGETS += exec
12TARGETS += filesystems 12TARGETS += filesystems
13TARGETS += filesystems/binderfs
13TARGETS += firmware 14TARGETS += firmware
14TARGETS += ftrace 15TARGETS += ftrace
15TARGETS += futex 16TARGETS += futex
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 4a9785043a39..dd093bd91aa9 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -28,3 +28,4 @@ flow_dissector_load
28test_netcnt 28test_netcnt
29test_section_names 29test_section_names
30test_tcpnotify_user 30test_tcpnotify_user
31test_libbpf
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 73aa6d8f4a2f..41ab7a3668b3 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -55,7 +55,10 @@ TEST_PROGS := test_kmod.sh \
55 test_flow_dissector.sh \ 55 test_flow_dissector.sh \
56 test_xdp_vlan.sh 56 test_xdp_vlan.sh
57 57
58TEST_PROGS_EXTENDED := with_addr.sh 58TEST_PROGS_EXTENDED := with_addr.sh \
59 with_tunnels.sh \
60 tcp_client.py \
61 tcp_server.py
59 62
60# Compile but not part of 'make run_tests' 63# Compile but not part of 'make run_tests'
61TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr test_skb_cgroup_id_user \ 64TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr test_skb_cgroup_id_user \
diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
index 315a44fa32af..84fd6f1bf33e 100644
--- a/tools/testing/selftests/bpf/bpf_util.h
+++ b/tools/testing/selftests/bpf/bpf_util.h
@@ -13,7 +13,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
13 unsigned int start, end, possible_cpus = 0; 13 unsigned int start, end, possible_cpus = 0;
14 char buff[128]; 14 char buff[128];
15 FILE *fp; 15 FILE *fp;
16 int n; 16 int len, n, i, j = 0;
17 17
18 fp = fopen(fcpu, "r"); 18 fp = fopen(fcpu, "r");
19 if (!fp) { 19 if (!fp) {
@@ -21,17 +21,27 @@ static inline unsigned int bpf_num_possible_cpus(void)
21 exit(1); 21 exit(1);
22 } 22 }
23 23
24 while (fgets(buff, sizeof(buff), fp)) { 24 if (!fgets(buff, sizeof(buff), fp)) {
25 n = sscanf(buff, "%u-%u", &start, &end); 25 printf("Failed to read %s!\n", fcpu);
26 if (n == 0) { 26 exit(1);
27 printf("Failed to retrieve # possible CPUs!\n"); 27 }
28 exit(1); 28
29 } else if (n == 1) { 29 len = strlen(buff);
30 end = start; 30 for (i = 0; i <= len; i++) {
31 if (buff[i] == ',' || buff[i] == '\0') {
32 buff[i] = '\0';
33 n = sscanf(&buff[j], "%u-%u", &start, &end);
34 if (n <= 0) {
35 printf("Failed to retrieve # possible CPUs!\n");
36 exit(1);
37 } else if (n == 1) {
38 end = start;
39 }
40 possible_cpus += end - start + 1;
41 j = i + 1;
31 } 42 }
32 possible_cpus = start == 0 ? end + 1 : 0;
33 break;
34 } 43 }
44
35 fclose(fp); 45 fclose(fp);
36 46
37 return possible_cpus; 47 return possible_cpus;
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
index cf16948aad4a..6692a40a6979 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.c
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -155,7 +155,7 @@ void cleanup_cgroup_environment(void)
155 * This function creates a cgroup under the top level workdir and returns the 155 * This function creates a cgroup under the top level workdir and returns the
156 * file descriptor. It is idempotent. 156 * file descriptor. It is idempotent.
157 * 157 *
158 * On success, it returns the file descriptor. On failure it returns 0. 158 * On success, it returns the file descriptor. On failure it returns -1.
159 * If there is a failure, it prints the error to stderr. 159 * If there is a failure, it prints the error to stderr.
160 */ 160 */
161int create_and_get_cgroup(const char *path) 161int create_and_get_cgroup(const char *path)
@@ -166,13 +166,13 @@ int create_and_get_cgroup(const char *path)
166 format_cgroup_path(cgroup_path, path); 166 format_cgroup_path(cgroup_path, path);
167 if (mkdir(cgroup_path, 0777) && errno != EEXIST) { 167 if (mkdir(cgroup_path, 0777) && errno != EEXIST) {
168 log_err("mkdiring cgroup %s .. %s", path, cgroup_path); 168 log_err("mkdiring cgroup %s .. %s", path, cgroup_path);
169 return 0; 169 return -1;
170 } 170 }
171 171
172 fd = open(cgroup_path, O_RDONLY); 172 fd = open(cgroup_path, O_RDONLY);
173 if (fd < 0) { 173 if (fd < 0) {
174 log_err("Opening Cgroup"); 174 log_err("Opening Cgroup");
175 return 0; 175 return -1;
176 } 176 }
177 177
178 return fd; 178 return fd;
diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c
index 8bcd38010582..91420fa83b08 100644
--- a/tools/testing/selftests/bpf/test_btf.c
+++ b/tools/testing/selftests/bpf/test_btf.c
@@ -1881,13 +1881,12 @@ static struct btf_raw_test raw_tests[] = {
1881}, 1881},
1882 1882
1883{ 1883{
1884 .descr = "func proto (CONST=>TYPEDEF=>FUNC_PROTO)", 1884 .descr = "func proto (TYPEDEF=>FUNC_PROTO)",
1885 .raw_types = { 1885 .raw_types = {
1886 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ 1886 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1887 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */ 1887 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
1888 BTF_CONST_ENC(4), /* [3] */ 1888 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
1889 BTF_TYPEDEF_ENC(NAME_TBD, 5), /* [4] */ 1889 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
1890 BTF_FUNC_PROTO_ENC(0, 2), /* [5] */
1891 BTF_FUNC_PROTO_ARG_ENC(0, 1), 1890 BTF_FUNC_PROTO_ARG_ENC(0, 1),
1892 BTF_FUNC_PROTO_ARG_ENC(0, 2), 1891 BTF_FUNC_PROTO_ARG_ENC(0, 2),
1893 BTF_END_RAW, 1892 BTF_END_RAW,
@@ -1901,8 +1900,6 @@ static struct btf_raw_test raw_tests[] = {
1901 .key_type_id = 1, 1900 .key_type_id = 1,
1902 .value_type_id = 1, 1901 .value_type_id = 1,
1903 .max_entries = 4, 1902 .max_entries = 4,
1904 .btf_load_err = true,
1905 .err_str = "Invalid type_id",
1906}, 1903},
1907 1904
1908{ 1905{
@@ -3526,6 +3523,8 @@ struct pprint_mapv {
3526 ENUM_TWO, 3523 ENUM_TWO,
3527 ENUM_THREE, 3524 ENUM_THREE,
3528 } aenum; 3525 } aenum;
3526 uint32_t ui32b;
3527 uint32_t bits2c:2;
3529}; 3528};
3530 3529
3531static struct btf_raw_test pprint_test_template[] = { 3530static struct btf_raw_test pprint_test_template[] = {
@@ -3568,7 +3567,7 @@ static struct btf_raw_test pprint_test_template[] = {
3568 BTF_ENUM_ENC(NAME_TBD, 2), 3567 BTF_ENUM_ENC(NAME_TBD, 2),
3569 BTF_ENUM_ENC(NAME_TBD, 3), 3568 BTF_ENUM_ENC(NAME_TBD, 3),
3570 /* struct pprint_mapv */ /* [16] */ 3569 /* struct pprint_mapv */ /* [16] */
3571 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 8), 32), 3570 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 10), 40),
3572 BTF_MEMBER_ENC(NAME_TBD, 11, 0), /* uint32_t ui32 */ 3571 BTF_MEMBER_ENC(NAME_TBD, 11, 0), /* uint32_t ui32 */
3573 BTF_MEMBER_ENC(NAME_TBD, 10, 32), /* uint16_t ui16 */ 3572 BTF_MEMBER_ENC(NAME_TBD, 10, 32), /* uint16_t ui16 */
3574 BTF_MEMBER_ENC(NAME_TBD, 12, 64), /* int32_t si32 */ 3573 BTF_MEMBER_ENC(NAME_TBD, 12, 64), /* int32_t si32 */
@@ -3577,9 +3576,11 @@ static struct btf_raw_test pprint_test_template[] = {
3577 BTF_MEMBER_ENC(NAME_TBD, 6, 126), /* unused_bits2b */ 3576 BTF_MEMBER_ENC(NAME_TBD, 6, 126), /* unused_bits2b */
3578 BTF_MEMBER_ENC(0, 14, 128), /* union (anon) */ 3577 BTF_MEMBER_ENC(0, 14, 128), /* union (anon) */
3579 BTF_MEMBER_ENC(NAME_TBD, 15, 192), /* aenum */ 3578 BTF_MEMBER_ENC(NAME_TBD, 15, 192), /* aenum */
3579 BTF_MEMBER_ENC(NAME_TBD, 11, 224), /* uint32_t ui32b */
3580 BTF_MEMBER_ENC(NAME_TBD, 6, 256), /* bits2c */
3580 BTF_END_RAW, 3581 BTF_END_RAW,
3581 }, 3582 },
3582 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum"), 3583 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c"),
3583 .key_size = sizeof(unsigned int), 3584 .key_size = sizeof(unsigned int),
3584 .value_size = sizeof(struct pprint_mapv), 3585 .value_size = sizeof(struct pprint_mapv),
3585 .key_type_id = 3, /* unsigned int */ 3586 .key_type_id = 3, /* unsigned int */
@@ -3628,7 +3629,7 @@ static struct btf_raw_test pprint_test_template[] = {
3628 BTF_ENUM_ENC(NAME_TBD, 2), 3629 BTF_ENUM_ENC(NAME_TBD, 2),
3629 BTF_ENUM_ENC(NAME_TBD, 3), 3630 BTF_ENUM_ENC(NAME_TBD, 3),
3630 /* struct pprint_mapv */ /* [16] */ 3631 /* struct pprint_mapv */ /* [16] */
3631 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 8), 32), 3632 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 10), 40),
3632 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */ 3633 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
3633 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */ 3634 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
3634 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */ 3635 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
@@ -3637,9 +3638,11 @@ static struct btf_raw_test pprint_test_template[] = {
3637 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 126)), /* unused_bits2b */ 3638 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 126)), /* unused_bits2b */
3638 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */ 3639 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
3639 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */ 3640 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
3641 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
3642 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
3640 BTF_END_RAW, 3643 BTF_END_RAW,
3641 }, 3644 },
3642 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum"), 3645 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c"),
3643 .key_size = sizeof(unsigned int), 3646 .key_size = sizeof(unsigned int),
3644 .value_size = sizeof(struct pprint_mapv), 3647 .value_size = sizeof(struct pprint_mapv),
3645 .key_type_id = 3, /* unsigned int */ 3648 .key_type_id = 3, /* unsigned int */
@@ -3690,7 +3693,7 @@ static struct btf_raw_test pprint_test_template[] = {
3690 BTF_ENUM_ENC(NAME_TBD, 2), 3693 BTF_ENUM_ENC(NAME_TBD, 2),
3691 BTF_ENUM_ENC(NAME_TBD, 3), 3694 BTF_ENUM_ENC(NAME_TBD, 3),
3692 /* struct pprint_mapv */ /* [16] */ 3695 /* struct pprint_mapv */ /* [16] */
3693 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 8), 32), 3696 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 10), 40),
3694 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */ 3697 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
3695 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */ 3698 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
3696 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */ 3699 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
@@ -3699,13 +3702,15 @@ static struct btf_raw_test pprint_test_template[] = {
3699 BTF_MEMBER_ENC(NAME_TBD, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */ 3702 BTF_MEMBER_ENC(NAME_TBD, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */
3700 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */ 3703 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
3701 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */ 3704 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
3705 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
3706 BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
3702 /* typedef unsigned int ___int */ /* [17] */ 3707 /* typedef unsigned int ___int */ /* [17] */
3703 BTF_TYPEDEF_ENC(NAME_TBD, 18), 3708 BTF_TYPEDEF_ENC(NAME_TBD, 18),
3704 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 6), /* [18] */ 3709 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 6), /* [18] */
3705 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 15), /* [19] */ 3710 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 15), /* [19] */
3706 BTF_END_RAW, 3711 BTF_END_RAW,
3707 }, 3712 },
3708 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0___int"), 3713 BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0___int"),
3709 .key_size = sizeof(unsigned int), 3714 .key_size = sizeof(unsigned int),
3710 .value_size = sizeof(struct pprint_mapv), 3715 .value_size = sizeof(struct pprint_mapv),
3711 .key_type_id = 3, /* unsigned int */ 3716 .key_type_id = 3, /* unsigned int */
@@ -3793,6 +3798,8 @@ static void set_pprint_mapv(struct pprint_mapv *v, uint32_t i,
3793 v->unused_bits2b = 3; 3798 v->unused_bits2b = 3;
3794 v->ui64 = i; 3799 v->ui64 = i;
3795 v->aenum = i & 0x03; 3800 v->aenum = i & 0x03;
3801 v->ui32b = 4;
3802 v->bits2c = 1;
3796 v = (void *)v + rounded_value_size; 3803 v = (void *)v + rounded_value_size;
3797 } 3804 }
3798} 3805}
@@ -3955,7 +3962,8 @@ static int do_test_pprint(int test_num)
3955 3962
3956 nexpected_line = snprintf(expected_line, sizeof(expected_line), 3963 nexpected_line = snprintf(expected_line, sizeof(expected_line),
3957 "%s%u: {%u,0,%d,0x%x,0x%x,0x%x," 3964 "%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
3958 "{%lu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s}\n", 3965 "{%lu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
3966 "%u,0x%x}\n",
3959 percpu_map ? "\tcpu" : "", 3967 percpu_map ? "\tcpu" : "",
3960 percpu_map ? cpu : next_key, 3968 percpu_map ? cpu : next_key,
3961 cmapv->ui32, cmapv->si32, 3969 cmapv->ui32, cmapv->si32,
@@ -3967,7 +3975,9 @@ static int do_test_pprint(int test_num)
3967 cmapv->ui8a[2], cmapv->ui8a[3], 3975 cmapv->ui8a[2], cmapv->ui8a[3],
3968 cmapv->ui8a[4], cmapv->ui8a[5], 3976 cmapv->ui8a[4], cmapv->ui8a[5],
3969 cmapv->ui8a[6], cmapv->ui8a[7], 3977 cmapv->ui8a[6], cmapv->ui8a[7],
3970 pprint_enum_str[cmapv->aenum]); 3978 pprint_enum_str[cmapv->aenum],
3979 cmapv->ui32b,
3980 cmapv->bits2c);
3971 3981
3972 err = check_line(expected_line, nexpected_line, 3982 err = check_line(expected_line, nexpected_line,
3973 sizeof(expected_line), line); 3983 sizeof(expected_line), line);
diff --git a/tools/testing/selftests/bpf/test_cgroup_storage.c b/tools/testing/selftests/bpf/test_cgroup_storage.c
index f44834155f25..2fc4625c1a15 100644
--- a/tools/testing/selftests/bpf/test_cgroup_storage.c
+++ b/tools/testing/selftests/bpf/test_cgroup_storage.c
@@ -81,7 +81,7 @@ int main(int argc, char **argv)
81 81
82 /* Create a cgroup, get fd, and join it */ 82 /* Create a cgroup, get fd, and join it */
83 cgroup_fd = create_and_get_cgroup(TEST_CGROUP); 83 cgroup_fd = create_and_get_cgroup(TEST_CGROUP);
84 if (!cgroup_fd) { 84 if (cgroup_fd < 0) {
85 printf("Failed to create test cgroup\n"); 85 printf("Failed to create test cgroup\n");
86 goto err; 86 goto err;
87 } 87 }
diff --git a/tools/testing/selftests/bpf/test_dev_cgroup.c b/tools/testing/selftests/bpf/test_dev_cgroup.c
index 9c8b50bac7e0..76e4993b7c16 100644
--- a/tools/testing/selftests/bpf/test_dev_cgroup.c
+++ b/tools/testing/selftests/bpf/test_dev_cgroup.c
@@ -43,7 +43,7 @@ int main(int argc, char **argv)
43 43
44 /* Create a cgroup, get fd, and join it */ 44 /* Create a cgroup, get fd, and join it */
45 cgroup_fd = create_and_get_cgroup(TEST_CGROUP); 45 cgroup_fd = create_and_get_cgroup(TEST_CGROUP);
46 if (!cgroup_fd) { 46 if (cgroup_fd < 0) {
47 printf("Failed to create test cgroup\n"); 47 printf("Failed to create test cgroup\n");
48 goto err; 48 goto err;
49 } 49 }
diff --git a/tools/testing/selftests/bpf/test_lpm_map.c b/tools/testing/selftests/bpf/test_lpm_map.c
index 147e34cfceb7..02d7c871862a 100644
--- a/tools/testing/selftests/bpf/test_lpm_map.c
+++ b/tools/testing/selftests/bpf/test_lpm_map.c
@@ -474,6 +474,16 @@ static void test_lpm_delete(void)
474 assert(bpf_map_lookup_elem(map_fd, key, &value) == -1 && 474 assert(bpf_map_lookup_elem(map_fd, key, &value) == -1 &&
475 errno == ENOENT); 475 errno == ENOENT);
476 476
477 key->prefixlen = 30; // unused prefix so far
478 inet_pton(AF_INET, "192.255.0.0", key->data);
479 assert(bpf_map_delete_elem(map_fd, key) == -1 &&
480 errno == ENOENT);
481
482 key->prefixlen = 16; // same prefix as the root node
483 inet_pton(AF_INET, "192.255.0.0", key->data);
484 assert(bpf_map_delete_elem(map_fd, key) == -1 &&
485 errno == ENOENT);
486
477 /* assert initial lookup */ 487 /* assert initial lookup */
478 key->prefixlen = 32; 488 key->prefixlen = 32;
479 inet_pton(AF_INET, "192.168.0.1", key->data); 489 inet_pton(AF_INET, "192.168.0.1", key->data);
diff --git a/tools/testing/selftests/bpf/test_netcnt.c b/tools/testing/selftests/bpf/test_netcnt.c
index 44ed7f29f8ab..c1da5404454a 100644
--- a/tools/testing/selftests/bpf/test_netcnt.c
+++ b/tools/testing/selftests/bpf/test_netcnt.c
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
65 65
66 /* Create a cgroup, get fd, and join it */ 66 /* Create a cgroup, get fd, and join it */
67 cgroup_fd = create_and_get_cgroup(TEST_CGROUP); 67 cgroup_fd = create_and_get_cgroup(TEST_CGROUP);
68 if (!cgroup_fd) { 68 if (cgroup_fd < 0) {
69 printf("Failed to create test cgroup\n"); 69 printf("Failed to create test cgroup\n");
70 goto err; 70 goto err;
71 } 71 }
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 126fc624290d..25f0083a9b2e 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -1188,7 +1188,9 @@ static void test_stacktrace_build_id(void)
1188 int i, j; 1188 int i, j;
1189 struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH]; 1189 struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
1190 int build_id_matches = 0; 1190 int build_id_matches = 0;
1191 int retry = 1;
1191 1192
1193retry:
1192 err = bpf_prog_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd); 1194 err = bpf_prog_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd);
1193 if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno)) 1195 if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno))
1194 goto out; 1196 goto out;
@@ -1301,6 +1303,19 @@ static void test_stacktrace_build_id(void)
1301 previous_key = key; 1303 previous_key = key;
1302 } while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0); 1304 } while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
1303 1305
1306 /* stack_map_get_build_id_offset() is racy and sometimes can return
1307 * BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
1308 * try it one more time.
1309 */
1310 if (build_id_matches < 1 && retry--) {
1311 ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
1312 close(pmu_fd);
1313 bpf_object__close(obj);
1314 printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
1315 __func__);
1316 goto retry;
1317 }
1318
1304 if (CHECK(build_id_matches < 1, "build id match", 1319 if (CHECK(build_id_matches < 1, "build id match",
1305 "Didn't find expected build ID from the map\n")) 1320 "Didn't find expected build ID from the map\n"))
1306 goto disable_pmu; 1321 goto disable_pmu;
@@ -1341,7 +1356,9 @@ static void test_stacktrace_build_id_nmi(void)
1341 int i, j; 1356 int i, j;
1342 struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH]; 1357 struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
1343 int build_id_matches = 0; 1358 int build_id_matches = 0;
1359 int retry = 1;
1344 1360
1361retry:
1345 err = bpf_prog_load(file, BPF_PROG_TYPE_PERF_EVENT, &obj, &prog_fd); 1362 err = bpf_prog_load(file, BPF_PROG_TYPE_PERF_EVENT, &obj, &prog_fd);
1346 if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno)) 1363 if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno))
1347 return; 1364 return;
@@ -1436,6 +1453,19 @@ static void test_stacktrace_build_id_nmi(void)
1436 previous_key = key; 1453 previous_key = key;
1437 } while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0); 1454 } while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
1438 1455
1456 /* stack_map_get_build_id_offset() is racy and sometimes can return
1457 * BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
1458 * try it one more time.
1459 */
1460 if (build_id_matches < 1 && retry--) {
1461 ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
1462 close(pmu_fd);
1463 bpf_object__close(obj);
1464 printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
1465 __func__);
1466 goto retry;
1467 }
1468
1439 if (CHECK(build_id_matches < 1, "build id match", 1469 if (CHECK(build_id_matches < 1, "build id match",
1440 "Didn't find expected build ID from the map\n")) 1470 "Didn't find expected build ID from the map\n"))
1441 goto disable_pmu; 1471 goto disable_pmu;
diff --git a/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c b/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
index c121cc59f314..9220747c069d 100644
--- a/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
+++ b/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
164 goto err; 164 goto err;
165 165
166 cgfd = create_and_get_cgroup(CGROUP_PATH); 166 cgfd = create_and_get_cgroup(CGROUP_PATH);
167 if (!cgfd) 167 if (cgfd < 0)
168 goto err; 168 goto err;
169 169
170 if (join_cgroup(CGROUP_PATH)) 170 if (join_cgroup(CGROUP_PATH))
diff --git a/tools/testing/selftests/bpf/test_sock.c b/tools/testing/selftests/bpf/test_sock.c
index b8ebe2f58074..561ffb6d6433 100644
--- a/tools/testing/selftests/bpf/test_sock.c
+++ b/tools/testing/selftests/bpf/test_sock.c
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
458 goto err; 458 goto err;
459 459
460 cgfd = create_and_get_cgroup(CG_PATH); 460 cgfd = create_and_get_cgroup(CG_PATH);
461 if (!cgfd) 461 if (cgfd < 0)
462 goto err; 462 goto err;
463 463
464 if (join_cgroup(CG_PATH)) 464 if (join_cgroup(CG_PATH))
diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c
index 73b7493d4120..3f110eaaf29c 100644
--- a/tools/testing/selftests/bpf/test_sock_addr.c
+++ b/tools/testing/selftests/bpf/test_sock_addr.c
@@ -44,6 +44,7 @@
44#define SERV6_V4MAPPED_IP "::ffff:192.168.0.4" 44#define SERV6_V4MAPPED_IP "::ffff:192.168.0.4"
45#define SRC6_IP "::1" 45#define SRC6_IP "::1"
46#define SRC6_REWRITE_IP "::6" 46#define SRC6_REWRITE_IP "::6"
47#define WILDCARD6_IP "::"
47#define SERV6_PORT 6060 48#define SERV6_PORT 6060
48#define SERV6_REWRITE_PORT 6666 49#define SERV6_REWRITE_PORT 6666
49 50
@@ -85,12 +86,14 @@ static int bind4_prog_load(const struct sock_addr_test *test);
85static int bind6_prog_load(const struct sock_addr_test *test); 86static int bind6_prog_load(const struct sock_addr_test *test);
86static int connect4_prog_load(const struct sock_addr_test *test); 87static int connect4_prog_load(const struct sock_addr_test *test);
87static int connect6_prog_load(const struct sock_addr_test *test); 88static int connect6_prog_load(const struct sock_addr_test *test);
89static int sendmsg_allow_prog_load(const struct sock_addr_test *test);
88static int sendmsg_deny_prog_load(const struct sock_addr_test *test); 90static int sendmsg_deny_prog_load(const struct sock_addr_test *test);
89static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test); 91static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test);
90static int sendmsg4_rw_c_prog_load(const struct sock_addr_test *test); 92static int sendmsg4_rw_c_prog_load(const struct sock_addr_test *test);
91static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test); 93static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
92static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test); 94static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test);
93static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test); 95static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test);
96static int sendmsg6_rw_wildcard_prog_load(const struct sock_addr_test *test);
94 97
95static struct sock_addr_test tests[] = { 98static struct sock_addr_test tests[] = {
96 /* bind */ 99 /* bind */
@@ -463,6 +466,34 @@ static struct sock_addr_test tests[] = {
463 SYSCALL_ENOTSUPP, 466 SYSCALL_ENOTSUPP,
464 }, 467 },
465 { 468 {
469 "sendmsg6: set dst IP = [::] (BSD'ism)",
470 sendmsg6_rw_wildcard_prog_load,
471 BPF_CGROUP_UDP6_SENDMSG,
472 BPF_CGROUP_UDP6_SENDMSG,
473 AF_INET6,
474 SOCK_DGRAM,
475 SERV6_IP,
476 SERV6_PORT,
477 SERV6_REWRITE_IP,
478 SERV6_REWRITE_PORT,
479 SRC6_REWRITE_IP,
480 SUCCESS,
481 },
482 {
483 "sendmsg6: preserve dst IP = [::] (BSD'ism)",
484 sendmsg_allow_prog_load,
485 BPF_CGROUP_UDP6_SENDMSG,
486 BPF_CGROUP_UDP6_SENDMSG,
487 AF_INET6,
488 SOCK_DGRAM,
489 WILDCARD6_IP,
490 SERV6_PORT,
491 SERV6_REWRITE_IP,
492 SERV6_PORT,
493 SRC6_IP,
494 SUCCESS,
495 },
496 {
466 "sendmsg6: deny call", 497 "sendmsg6: deny call",
467 sendmsg_deny_prog_load, 498 sendmsg_deny_prog_load,
468 BPF_CGROUP_UDP6_SENDMSG, 499 BPF_CGROUP_UDP6_SENDMSG,
@@ -734,16 +765,27 @@ static int connect6_prog_load(const struct sock_addr_test *test)
734 return load_path(test, CONNECT6_PROG_PATH); 765 return load_path(test, CONNECT6_PROG_PATH);
735} 766}
736 767
737static int sendmsg_deny_prog_load(const struct sock_addr_test *test) 768static int sendmsg_ret_only_prog_load(const struct sock_addr_test *test,
769 int32_t rc)
738{ 770{
739 struct bpf_insn insns[] = { 771 struct bpf_insn insns[] = {
740 /* return 0 */ 772 /* return rc */
741 BPF_MOV64_IMM(BPF_REG_0, 0), 773 BPF_MOV64_IMM(BPF_REG_0, rc),
742 BPF_EXIT_INSN(), 774 BPF_EXIT_INSN(),
743 }; 775 };
744 return load_insns(test, insns, sizeof(insns) / sizeof(struct bpf_insn)); 776 return load_insns(test, insns, sizeof(insns) / sizeof(struct bpf_insn));
745} 777}
746 778
779static int sendmsg_allow_prog_load(const struct sock_addr_test *test)
780{
781 return sendmsg_ret_only_prog_load(test, /*rc*/ 1);
782}
783
784static int sendmsg_deny_prog_load(const struct sock_addr_test *test)
785{
786 return sendmsg_ret_only_prog_load(test, /*rc*/ 0);
787}
788
747static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test) 789static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test)
748{ 790{
749 struct sockaddr_in dst4_rw_addr; 791 struct sockaddr_in dst4_rw_addr;
@@ -864,6 +906,11 @@ static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test)
864 return sendmsg6_rw_dst_asm_prog_load(test, SERV6_V4MAPPED_IP); 906 return sendmsg6_rw_dst_asm_prog_load(test, SERV6_V4MAPPED_IP);
865} 907}
866 908
909static int sendmsg6_rw_wildcard_prog_load(const struct sock_addr_test *test)
910{
911 return sendmsg6_rw_dst_asm_prog_load(test, WILDCARD6_IP);
912}
913
867static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test) 914static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test)
868{ 915{
869 return load_path(test, SENDMSG6_PROG_PATH); 916 return load_path(test, SENDMSG6_PROG_PATH);
@@ -1395,7 +1442,7 @@ int main(int argc, char **argv)
1395 goto err; 1442 goto err;
1396 1443
1397 cgfd = create_and_get_cgroup(CG_PATH); 1444 cgfd = create_and_get_cgroup(CG_PATH);
1398 if (!cgfd) 1445 if (cgfd < 0)
1399 goto err; 1446 goto err;
1400 1447
1401 if (join_cgroup(CG_PATH)) 1448 if (join_cgroup(CG_PATH))
diff --git a/tools/testing/selftests/bpf/test_socket_cookie.c b/tools/testing/selftests/bpf/test_socket_cookie.c
index b6c2c605d8c0..fc7832ee566b 100644
--- a/tools/testing/selftests/bpf/test_socket_cookie.c
+++ b/tools/testing/selftests/bpf/test_socket_cookie.c
@@ -202,7 +202,7 @@ int main(int argc, char **argv)
202 goto err; 202 goto err;
203 203
204 cgfd = create_and_get_cgroup(CG_PATH); 204 cgfd = create_and_get_cgroup(CG_PATH);
205 if (!cgfd) 205 if (cgfd < 0)
206 goto err; 206 goto err;
207 207
208 if (join_cgroup(CG_PATH)) 208 if (join_cgroup(CG_PATH))
diff --git a/tools/testing/selftests/bpf/test_tcpbpf_user.c b/tools/testing/selftests/bpf/test_tcpbpf_user.c
index e6eebda7d112..716b4e3be581 100644
--- a/tools/testing/selftests/bpf/test_tcpbpf_user.c
+++ b/tools/testing/selftests/bpf/test_tcpbpf_user.c
@@ -103,7 +103,7 @@ int main(int argc, char **argv)
103 goto err; 103 goto err;
104 104
105 cg_fd = create_and_get_cgroup(cg_path); 105 cg_fd = create_and_get_cgroup(cg_path);
106 if (!cg_fd) 106 if (cg_fd < 0)
107 goto err; 107 goto err;
108 108
109 if (join_cgroup(cg_path)) 109 if (join_cgroup(cg_path))
diff --git a/tools/testing/selftests/bpf/test_tcpnotify_user.c b/tools/testing/selftests/bpf/test_tcpnotify_user.c
index ff3c4522aed6..4e4353711a86 100644
--- a/tools/testing/selftests/bpf/test_tcpnotify_user.c
+++ b/tools/testing/selftests/bpf/test_tcpnotify_user.c
@@ -115,7 +115,7 @@ int main(int argc, char **argv)
115 goto err; 115 goto err;
116 116
117 cg_fd = create_and_get_cgroup(cg_path); 117 cg_fd = create_and_get_cgroup(cg_path);
118 if (!cg_fd) 118 if (cg_fd < 0)
119 goto err; 119 goto err;
120 120
121 if (join_cgroup(cg_path)) 121 if (join_cgroup(cg_path))
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 10d44446e801..2fd90d456892 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -6934,6 +6934,126 @@ static struct bpf_test tests[] = {
6934 .retval = 1, 6934 .retval = 1,
6935 }, 6935 },
6936 { 6936 {
6937 "map access: mixing value pointer and scalar, 1",
6938 .insns = {
6939 // load map value pointer into r0 and r2
6940 BPF_MOV64_IMM(BPF_REG_0, 1),
6941 BPF_LD_MAP_FD(BPF_REG_ARG1, 0),
6942 BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_FP),
6943 BPF_ALU64_IMM(BPF_ADD, BPF_REG_ARG2, -16),
6944 BPF_ST_MEM(BPF_DW, BPF_REG_FP, -16, 0),
6945 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
6946 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
6947 BPF_EXIT_INSN(),
6948 // load some number from the map into r1
6949 BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
6950 // depending on r1, branch:
6951 BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 3),
6952 // branch A
6953 BPF_MOV64_REG(BPF_REG_2, BPF_REG_0),
6954 BPF_MOV64_IMM(BPF_REG_3, 0),
6955 BPF_JMP_A(2),
6956 // branch B
6957 BPF_MOV64_IMM(BPF_REG_2, 0),
6958 BPF_MOV64_IMM(BPF_REG_3, 0x100000),
6959 // common instruction
6960 BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_3),
6961 // depending on r1, branch:
6962 BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 1),
6963 // branch A
6964 BPF_JMP_A(4),
6965 // branch B
6966 BPF_MOV64_IMM(BPF_REG_0, 0x13371337),
6967 // verifier follows fall-through
6968 BPF_JMP_IMM(BPF_JNE, BPF_REG_2, 0x100000, 2),
6969 BPF_MOV64_IMM(BPF_REG_0, 0),
6970 BPF_EXIT_INSN(),
6971 // fake-dead code; targeted from branch A to
6972 // prevent dead code sanitization
6973 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
6974 BPF_MOV64_IMM(BPF_REG_0, 0),
6975 BPF_EXIT_INSN(),
6976 },
6977 .fixup_map_array_48b = { 1 },
6978 .result = ACCEPT,
6979 .result_unpriv = REJECT,
6980 .errstr_unpriv = "R2 tried to add from different pointers or scalars",
6981 .retval = 0,
6982 },
6983 {
6984 "map access: mixing value pointer and scalar, 2",
6985 .insns = {
6986 // load map value pointer into r0 and r2
6987 BPF_MOV64_IMM(BPF_REG_0, 1),
6988 BPF_LD_MAP_FD(BPF_REG_ARG1, 0),
6989 BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_FP),
6990 BPF_ALU64_IMM(BPF_ADD, BPF_REG_ARG2, -16),
6991 BPF_ST_MEM(BPF_DW, BPF_REG_FP, -16, 0),
6992 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
6993 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
6994 BPF_EXIT_INSN(),
6995 // load some number from the map into r1
6996 BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
6997 // depending on r1, branch:
6998 BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 3),
6999 // branch A
7000 BPF_MOV64_IMM(BPF_REG_2, 0),
7001 BPF_MOV64_IMM(BPF_REG_3, 0x100000),
7002 BPF_JMP_A(2),
7003 // branch B
7004 BPF_MOV64_REG(BPF_REG_2, BPF_REG_0),
7005 BPF_MOV64_IMM(BPF_REG_3, 0),
7006 // common instruction
7007 BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_3),
7008 // depending on r1, branch:
7009 BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 1),
7010 // branch A
7011 BPF_JMP_A(4),
7012 // branch B
7013 BPF_MOV64_IMM(BPF_REG_0, 0x13371337),
7014 // verifier follows fall-through
7015 BPF_JMP_IMM(BPF_JNE, BPF_REG_2, 0x100000, 2),
7016 BPF_MOV64_IMM(BPF_REG_0, 0),
7017 BPF_EXIT_INSN(),
7018 // fake-dead code; targeted from branch A to
7019 // prevent dead code sanitization
7020 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
7021 BPF_MOV64_IMM(BPF_REG_0, 0),
7022 BPF_EXIT_INSN(),
7023 },
7024 .fixup_map_array_48b = { 1 },
7025 .result = ACCEPT,
7026 .result_unpriv = REJECT,
7027 .errstr_unpriv = "R2 tried to add from different maps or paths",
7028 .retval = 0,
7029 },
7030 {
7031 "sanitation: alu with different scalars",
7032 .insns = {
7033 BPF_MOV64_IMM(BPF_REG_0, 1),
7034 BPF_LD_MAP_FD(BPF_REG_ARG1, 0),
7035 BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_FP),
7036 BPF_ALU64_IMM(BPF_ADD, BPF_REG_ARG2, -16),
7037 BPF_ST_MEM(BPF_DW, BPF_REG_FP, -16, 0),
7038 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
7039 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
7040 BPF_EXIT_INSN(),
7041 BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
7042 BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 3),
7043 BPF_MOV64_IMM(BPF_REG_2, 0),
7044 BPF_MOV64_IMM(BPF_REG_3, 0x100000),
7045 BPF_JMP_A(2),
7046 BPF_MOV64_IMM(BPF_REG_2, 42),
7047 BPF_MOV64_IMM(BPF_REG_3, 0x100001),
7048 BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_3),
7049 BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
7050 BPF_EXIT_INSN(),
7051 },
7052 .fixup_map_array_48b = { 1 },
7053 .result = ACCEPT,
7054 .retval = 0x100000,
7055 },
7056 {
6937 "map access: value_ptr += known scalar, upper oob arith, test 1", 7057 "map access: value_ptr += known scalar, upper oob arith, test 1",
6938 .insns = { 7058 .insns = {
6939 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0), 7059 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
diff --git a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
index bab13dd025a6..0d26b5e3f966 100755
--- a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
+++ b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
@@ -37,6 +37,10 @@ prerequisite()
37 exit $ksft_skip 37 exit $ksft_skip
38 fi 38 fi
39 39
40 present_cpus=`cat $SYSFS/devices/system/cpu/present`
41 present_max=${present_cpus##*-}
42 echo "present_cpus = $present_cpus present_max = $present_max"
43
40 echo -e "\t Cpus in online state: $online_cpus" 44 echo -e "\t Cpus in online state: $online_cpus"
41 45
42 offline_cpus=`cat $SYSFS/devices/system/cpu/offline` 46 offline_cpus=`cat $SYSFS/devices/system/cpu/offline`
@@ -151,6 +155,8 @@ online_cpus=0
151online_max=0 155online_max=0
152offline_cpus=0 156offline_cpus=0
153offline_max=0 157offline_max=0
158present_cpus=0
159present_max=0
154 160
155while getopts e:ahp: opt; do 161while getopts e:ahp: opt; do
156 case $opt in 162 case $opt in
@@ -190,9 +196,10 @@ if [ $allcpus -eq 0 ]; then
190 online_cpu_expect_success $online_max 196 online_cpu_expect_success $online_max
191 197
192 if [[ $offline_cpus -gt 0 ]]; then 198 if [[ $offline_cpus -gt 0 ]]; then
193 echo -e "\t offline to online to offline: cpu $offline_max" 199 echo -e "\t offline to online to offline: cpu $present_max"
194 online_cpu_expect_success $offline_max 200 online_cpu_expect_success $present_max
195 offline_cpu_expect_success $offline_max 201 offline_cpu_expect_success $present_max
202 online_cpu $present_max
196 fi 203 fi
197 exit 0 204 exit 0
198else 205else
diff --git a/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh b/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh
index 94fdbf215c14..c4cf6e6d800e 100755
--- a/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh
+++ b/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh
@@ -25,6 +25,7 @@ ALL_TESTS="
25 lag_unlink_slaves_test 25 lag_unlink_slaves_test
26 lag_dev_deletion_test 26 lag_dev_deletion_test
27 vlan_interface_uppers_test 27 vlan_interface_uppers_test
28 bridge_extern_learn_test
28 devlink_reload_test 29 devlink_reload_test
29" 30"
30NUM_NETIFS=2 31NUM_NETIFS=2
@@ -541,6 +542,25 @@ vlan_interface_uppers_test()
541 ip link del dev br0 542 ip link del dev br0
542} 543}
543 544
545bridge_extern_learn_test()
546{
547 # Test that externally learned entries added from user space are
548 # marked as offloaded
549 RET=0
550
551 ip link add name br0 type bridge
552 ip link set dev $swp1 master br0
553
554 bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn
555
556 bridge fdb show brport $swp1 | grep de:ad:be:ef:13:37 | grep -q offload
557 check_err $? "fdb entry not marked as offloaded when should"
558
559 log_test "externally learned fdb entry"
560
561 ip link del dev br0
562}
563
544devlink_reload_test() 564devlink_reload_test()
545{ 565{
546 # Test that after executing all the above configuration tests, a 566 # Test that after executing all the above configuration tests, a
diff --git a/tools/testing/selftests/drivers/net/mlxsw/vxlan.sh b/tools/testing/selftests/drivers/net/mlxsw/vxlan.sh
index dcf9f4e913e0..ae6146ec5afd 100755
--- a/tools/testing/selftests/drivers/net/mlxsw/vxlan.sh
+++ b/tools/testing/selftests/drivers/net/mlxsw/vxlan.sh
@@ -847,6 +847,24 @@ sanitization_vlan_aware_test()
847 847
848 log_test "vlan-aware - failed enslavement to vlan-aware bridge" 848 log_test "vlan-aware - failed enslavement to vlan-aware bridge"
849 849
850 bridge vlan del vid 10 dev vxlan20
851 bridge vlan add vid 20 dev vxlan20 pvid untagged
852
853 # Test that offloading of an unsupported tunnel fails when it is
854 # triggered by addition of VLAN to a local port
855 RET=0
856
857 # TOS must be set to inherit
858 ip link set dev vxlan10 type vxlan tos 42
859
860 ip link set dev $swp1 master br0
861 bridge vlan add vid 10 dev $swp1 &> /dev/null
862 check_fail $?
863
864 log_test "vlan-aware - failed vlan addition to a local port"
865
866 ip link set dev vxlan10 type vxlan tos inherit
867
850 ip link del dev vxlan20 868 ip link del dev vxlan20
851 ip link del dev vxlan10 869 ip link del dev vxlan10
852 ip link del dev br0 870 ip link del dev br0
diff --git a/tools/testing/selftests/filesystems/binderfs/.gitignore b/tools/testing/selftests/filesystems/binderfs/.gitignore
new file mode 100644
index 000000000000..8a5d9bf63dd4
--- /dev/null
+++ b/tools/testing/selftests/filesystems/binderfs/.gitignore
@@ -0,0 +1 @@
binderfs_test
diff --git a/tools/testing/selftests/filesystems/binderfs/Makefile b/tools/testing/selftests/filesystems/binderfs/Makefile
new file mode 100644
index 000000000000..58cb659b56b4
--- /dev/null
+++ b/tools/testing/selftests/filesystems/binderfs/Makefile
@@ -0,0 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0
2
3CFLAGS += -I../../../../../usr/include/
4TEST_GEN_PROGS := binderfs_test
5
6include ../../lib.mk
diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
new file mode 100644
index 000000000000..8c2ed962e1c7
--- /dev/null
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -0,0 +1,275 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#define _GNU_SOURCE
4#include <errno.h>
5#include <fcntl.h>
6#include <sched.h>
7#include <stdbool.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <sys/ioctl.h>
12#include <sys/mount.h>
13#include <sys/stat.h>
14#include <sys/types.h>
15#include <unistd.h>
16#include <linux/android/binder.h>
17#include <linux/android/binderfs.h>
18#include "../../kselftest.h"
19
20static ssize_t write_nointr(int fd, const void *buf, size_t count)
21{
22 ssize_t ret;
23again:
24 ret = write(fd, buf, count);
25 if (ret < 0 && errno == EINTR)
26 goto again;
27
28 return ret;
29}
30
31static void write_to_file(const char *filename, const void *buf, size_t count,
32 int allowed_errno)
33{
34 int fd, saved_errno;
35 ssize_t ret;
36
37 fd = open(filename, O_WRONLY | O_CLOEXEC);
38 if (fd < 0)
39 ksft_exit_fail_msg("%s - Failed to open file %s\n",
40 strerror(errno), filename);
41
42 ret = write_nointr(fd, buf, count);
43 if (ret < 0) {
44 if (allowed_errno && (errno == allowed_errno)) {
45 close(fd);
46 return;
47 }
48
49 goto on_error;
50 }
51
52 if ((size_t)ret != count)
53 goto on_error;
54
55 close(fd);
56 return;
57
58on_error:
59 saved_errno = errno;
60 close(fd);
61 errno = saved_errno;
62
63 if (ret < 0)
64 ksft_exit_fail_msg("%s - Failed to write to file %s\n",
65 strerror(errno), filename);
66
67 ksft_exit_fail_msg("Failed to write to file %s\n", filename);
68}
69
70static void change_to_userns(void)
71{
72 int ret;
73 uid_t uid;
74 gid_t gid;
75 /* {g,u}id_map files only allow a max of 4096 bytes written to them */
76 char idmap[4096];
77
78 uid = getuid();
79 gid = getgid();
80
81 ret = unshare(CLONE_NEWUSER);
82 if (ret < 0)
83 ksft_exit_fail_msg("%s - Failed to unshare user namespace\n",
84 strerror(errno));
85
86 write_to_file("/proc/self/setgroups", "deny", strlen("deny"), ENOENT);
87
88 ret = snprintf(idmap, sizeof(idmap), "0 %d 1", uid);
89 if (ret < 0 || (size_t)ret >= sizeof(idmap))
90 ksft_exit_fail_msg("%s - Failed to prepare uid mapping\n",
91 strerror(errno));
92
93 write_to_file("/proc/self/uid_map", idmap, strlen(idmap), 0);
94
95 ret = snprintf(idmap, sizeof(idmap), "0 %d 1", gid);
96 if (ret < 0 || (size_t)ret >= sizeof(idmap))
97 ksft_exit_fail_msg("%s - Failed to prepare uid mapping\n",
98 strerror(errno));
99
100 write_to_file("/proc/self/gid_map", idmap, strlen(idmap), 0);
101
102 ret = setgid(0);
103 if (ret)
104 ksft_exit_fail_msg("%s - Failed to setgid(0)\n",
105 strerror(errno));
106
107 ret = setuid(0);
108 if (ret)
109 ksft_exit_fail_msg("%s - Failed to setgid(0)\n",
110 strerror(errno));
111}
112
113static void change_to_mountns(void)
114{
115 int ret;
116
117 ret = unshare(CLONE_NEWNS);
118 if (ret < 0)
119 ksft_exit_fail_msg("%s - Failed to unshare mount namespace\n",
120 strerror(errno));
121
122 ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
123 if (ret < 0)
124 ksft_exit_fail_msg("%s - Failed to mount / as private\n",
125 strerror(errno));
126}
127
128static void rmdir_protect_errno(const char *dir)
129{
130 int saved_errno = errno;
131 (void)rmdir(dir);
132 errno = saved_errno;
133}
134
135static void __do_binderfs_test(void)
136{
137 int fd, ret, saved_errno;
138 size_t len;
139 ssize_t wret;
140 bool keep = false;
141 struct binderfs_device device = { 0 };
142 struct binder_version version = { 0 };
143
144 change_to_mountns();
145
146 ret = mkdir("/dev/binderfs", 0755);
147 if (ret < 0) {
148 if (errno != EEXIST)
149 ksft_exit_fail_msg(
150 "%s - Failed to create binderfs mountpoint\n",
151 strerror(errno));
152
153 keep = true;
154 }
155
156 ret = mount(NULL, "/dev/binderfs", "binder", 0, 0);
157 if (ret < 0) {
158 if (errno != ENODEV)
159 ksft_exit_fail_msg("%s - Failed to mount binderfs\n",
160 strerror(errno));
161
162 keep ? : rmdir_protect_errno("/dev/binderfs");
163 ksft_exit_skip(
164 "The Android binderfs filesystem is not available\n");
165 }
166
167 /* binderfs mount test passed */
168 ksft_inc_pass_cnt();
169
170 memcpy(device.name, "my-binder", strlen("my-binder"));
171
172 fd = open("/dev/binderfs/binder-control", O_RDONLY | O_CLOEXEC);
173 if (fd < 0)
174 ksft_exit_fail_msg(
175 "%s - Failed to open binder-control device\n",
176 strerror(errno));
177
178 ret = ioctl(fd, BINDER_CTL_ADD, &device);
179 saved_errno = errno;
180 close(fd);
181 errno = saved_errno;
182 if (ret < 0) {
183 keep ? : rmdir_protect_errno("/dev/binderfs");
184 ksft_exit_fail_msg(
185 "%s - Failed to allocate new binder device\n",
186 strerror(errno));
187 }
188
189 ksft_print_msg(
190 "Allocated new binder device with major %d, minor %d, and name %s\n",
191 device.major, device.minor, device.name);
192
193 /* binder device allocation test passed */
194 ksft_inc_pass_cnt();
195
196 fd = open("/dev/binderfs/my-binder", O_CLOEXEC | O_RDONLY);
197 if (fd < 0) {
198 keep ? : rmdir_protect_errno("/dev/binderfs");
199 ksft_exit_fail_msg("%s - Failed to open my-binder device\n",
200 strerror(errno));
201 }
202
203 ret = ioctl(fd, BINDER_VERSION, &version);
204 saved_errno = errno;
205 close(fd);
206 errno = saved_errno;
207 if (ret < 0) {
208 keep ? : rmdir_protect_errno("/dev/binderfs");
209 ksft_exit_fail_msg(
210 "%s - Failed to open perform BINDER_VERSION request\n",
211 strerror(errno));
212 }
213
214 ksft_print_msg("Detected binder version: %d\n",
215 version.protocol_version);
216
217 /* binder transaction with binderfs binder device passed */
218 ksft_inc_pass_cnt();
219
220 ret = unlink("/dev/binderfs/my-binder");
221 if (ret < 0) {
222 keep ? : rmdir_protect_errno("/dev/binderfs");
223 ksft_exit_fail_msg("%s - Failed to delete binder device\n",
224 strerror(errno));
225 }
226
227 /* binder device removal passed */
228 ksft_inc_pass_cnt();
229
230 ret = unlink("/dev/binderfs/binder-control");
231 if (!ret) {
232 keep ? : rmdir_protect_errno("/dev/binderfs");
233 ksft_exit_fail_msg("Managed to delete binder-control device\n");
234 } else if (errno != EPERM) {
235 keep ? : rmdir_protect_errno("/dev/binderfs");
236 ksft_exit_fail_msg(
237 "%s - Failed to delete binder-control device but exited with unexpected error code\n",
238 strerror(errno));
239 }
240
241 /* binder-control device removal failed as expected */
242 ksft_inc_xfail_cnt();
243
244on_error:
245 ret = umount2("/dev/binderfs", MNT_DETACH);
246 keep ?: rmdir_protect_errno("/dev/binderfs");
247 if (ret < 0)
248 ksft_exit_fail_msg("%s - Failed to unmount binderfs\n",
249 strerror(errno));
250
251 /* binderfs unmount test passed */
252 ksft_inc_pass_cnt();
253}
254
255static void binderfs_test_privileged()
256{
257 if (geteuid() != 0)
258 ksft_print_msg(
259 "Tests are not run as root. Skipping privileged tests\n");
260 else
261 __do_binderfs_test();
262}
263
264static void binderfs_test_unprivileged()
265{
266 change_to_userns();
267 __do_binderfs_test();
268}
269
270int main(int argc, char *argv[])
271{
272 binderfs_test_privileged();
273 binderfs_test_unprivileged();
274 ksft_exit_pass();
275}
diff --git a/tools/testing/selftests/filesystems/binderfs/config b/tools/testing/selftests/filesystems/binderfs/config
new file mode 100644
index 000000000000..02dd6cc9cf99
--- /dev/null
+++ b/tools/testing/selftests/filesystems/binderfs/config
@@ -0,0 +1,3 @@
1CONFIG_ANDROID=y
2CONFIG_ANDROID_BINDERFS=y
3CONFIG_ANDROID_BINDER_IPC=y
diff --git a/tools/testing/selftests/gpio/gpio-mockup-chardev.c b/tools/testing/selftests/gpio/gpio-mockup-chardev.c
index f8d468f54e98..aaa1e9f083c3 100644
--- a/tools/testing/selftests/gpio/gpio-mockup-chardev.c
+++ b/tools/testing/selftests/gpio/gpio-mockup-chardev.c
@@ -37,7 +37,7 @@ static int get_debugfs(char **path)
37 struct libmnt_table *tb; 37 struct libmnt_table *tb;
38 struct libmnt_iter *itr = NULL; 38 struct libmnt_iter *itr = NULL;
39 struct libmnt_fs *fs; 39 struct libmnt_fs *fs;
40 int found = 0; 40 int found = 0, ret;
41 41
42 cxt = mnt_new_context(); 42 cxt = mnt_new_context();
43 if (!cxt) 43 if (!cxt)
@@ -58,8 +58,11 @@ static int get_debugfs(char **path)
58 break; 58 break;
59 } 59 }
60 } 60 }
61 if (found) 61 if (found) {
62 asprintf(path, "%s/gpio", mnt_fs_get_target(fs)); 62 ret = asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
63 if (ret < 0)
64 err(EXIT_FAILURE, "failed to format string");
65 }
63 66
64 mnt_free_iter(itr); 67 mnt_free_iter(itr);
65 mnt_free_context(cxt); 68 mnt_free_context(cxt);
diff --git a/tools/testing/selftests/ir/Makefile b/tools/testing/selftests/ir/Makefile
index f4ba8eb84b95..ad06489c22a5 100644
--- a/tools/testing/selftests/ir/Makefile
+++ b/tools/testing/selftests/ir/Makefile
@@ -1,5 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2TEST_PROGS := ir_loopback.sh 2TEST_PROGS := ir_loopback.sh
3TEST_GEN_PROGS_EXTENDED := ir_loopback 3TEST_GEN_PROGS_EXTENDED := ir_loopback
4APIDIR := ../../../include/uapi
5CFLAGS += -Wall -O2 -I$(APIDIR)
4 6
5include ../lib.mk 7include ../lib.mk
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 23022e9d32eb..b52cfdefecbf 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -571,7 +571,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
571 * already exist. 571 * already exist.
572 */ 572 */
573 region = (struct userspace_mem_region *) userspace_mem_region_find( 573 region = (struct userspace_mem_region *) userspace_mem_region_find(
574 vm, guest_paddr, guest_paddr + npages * vm->page_size); 574 vm, guest_paddr, (guest_paddr + npages * vm->page_size) - 1);
575 if (region != NULL) 575 if (region != NULL)
576 TEST_ASSERT(false, "overlapping userspace_mem_region already " 576 TEST_ASSERT(false, "overlapping userspace_mem_region already "
577 "exists\n" 577 "exists\n"
@@ -587,15 +587,10 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
587 region = region->next) { 587 region = region->next) {
588 if (region->region.slot == slot) 588 if (region->region.slot == slot)
589 break; 589 break;
590 if ((guest_paddr <= (region->region.guest_phys_addr
591 + region->region.memory_size))
592 && ((guest_paddr + npages * vm->page_size)
593 >= region->region.guest_phys_addr))
594 break;
595 } 590 }
596 if (region != NULL) 591 if (region != NULL)
597 TEST_ASSERT(false, "A mem region with the requested slot " 592 TEST_ASSERT(false, "A mem region with the requested slot "
598 "or overlapping physical memory range already exists.\n" 593 "already exists.\n"
599 " requested slot: %u paddr: 0x%lx npages: 0x%lx\n" 594 " requested slot: %u paddr: 0x%lx npages: 0x%lx\n"
600 " existing slot: %u paddr: 0x%lx size: 0x%lx", 595 " existing slot: %u paddr: 0x%lx size: 0x%lx",
601 slot, guest_paddr, npages, 596 slot, guest_paddr, npages,
diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
index ea3c73e8f4f6..c49c2a28b0eb 100644
--- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
@@ -103,6 +103,12 @@ int main(int argc, char *argv[])
103 103
104 vcpu_ioctl(vm, VCPU_ID, KVM_ENABLE_CAP, &enable_evmcs_cap); 104 vcpu_ioctl(vm, VCPU_ID, KVM_ENABLE_CAP, &enable_evmcs_cap);
105 105
106 /* KVM should return supported EVMCS version range */
107 TEST_ASSERT(((evmcs_ver >> 8) >= (evmcs_ver & 0xff)) &&
108 (evmcs_ver & 0xff) > 0,
109 "Incorrect EVMCS version range: %x:%x\n",
110 evmcs_ver & 0xff, evmcs_ver >> 8);
111
106 run = vcpu_state(vm, VCPU_ID); 112 run = vcpu_state(vm, VCPU_ID);
107 113
108 vcpu_regs_get(vm, VCPU_ID, &regs1); 114 vcpu_regs_get(vm, VCPU_ID, &regs1);
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index f8f3e90700c0..1e6d14d2825c 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -21,6 +21,6 @@ TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
21KSFT_KHDR_INSTALL := 1 21KSFT_KHDR_INSTALL := 1
22include ../lib.mk 22include ../lib.mk
23 23
24$(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma 24$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
25$(OUTPUT)/tcp_mmap: LDFLAGS += -lpthread 25$(OUTPUT)/tcp_mmap: LDFLAGS += -lpthread
26$(OUTPUT)/tcp_inq: LDFLAGS += -lpthread 26$(OUTPUT)/tcp_inq: LDFLAGS += -lpthread
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index 802b4af18729..1080ff55a788 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -388,6 +388,7 @@ fib_carrier_unicast_test()
388 388
389 set -e 389 set -e
390 $IP link set dev dummy0 carrier off 390 $IP link set dev dummy0 carrier off
391 sleep 1
391 set +e 392 set +e
392 393
393 echo " Carrier down" 394 echo " Carrier down"
diff --git a/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh b/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh
index d8313d0438b7..b90dff8d3a94 100755
--- a/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh
+++ b/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh
@@ -1,7 +1,7 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3 3
4ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding" 4ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn"
5NUM_NETIFS=4 5NUM_NETIFS=4
6CHECK_TC="yes" 6CHECK_TC="yes"
7source lib.sh 7source lib.sh
@@ -96,6 +96,51 @@ flooding()
96 flood_test $swp2 $h1 $h2 96 flood_test $swp2 $h1 $h2
97} 97}
98 98
99vlan_deletion()
100{
101 # Test that the deletion of a VLAN on a bridge port does not affect
102 # the PVID VLAN
103 log_info "Add and delete a VLAN on bridge port $swp1"
104
105 bridge vlan add vid 10 dev $swp1
106 bridge vlan del vid 10 dev $swp1
107
108 ping_ipv4
109 ping_ipv6
110}
111
112extern_learn()
113{
114 local mac=de:ad:be:ef:13:37
115 local ageing_time
116
117 # Test that externally learned FDB entries can roam, but not age out
118 RET=0
119
120 bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn vlan 1
121
122 bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
123 check_err $? "Did not find FDB entry when should"
124
125 # Wait for 10 seconds after the ageing time to make sure the FDB entry
126 # was not aged out
127 ageing_time=$(bridge_ageing_time_get br0)
128 sleep $((ageing_time + 10))
129
130 bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
131 check_err $? "FDB entry was aged out when should not"
132
133 $MZ $h2 -c 1 -p 64 -a $mac -t ip -q
134
135 bridge fdb show brport $swp2 | grep -q de:ad:be:ef:13:37
136 check_err $? "FDB entry did not roam when should"
137
138 log_test "Externally learned FDB entry - ageing & roaming"
139
140 bridge fdb del de:ad:be:ef:13:37 dev $swp2 master vlan 1 &> /dev/null
141 bridge fdb del de:ad:be:ef:13:37 dev $swp1 master vlan 1 &> /dev/null
142}
143
99trap cleanup EXIT 144trap cleanup EXIT
100 145
101setup_prepare 146setup_prepare
diff --git a/tools/testing/selftests/net/forwarding/vxlan_bridge_1d.sh b/tools/testing/selftests/net/forwarding/vxlan_bridge_1d.sh
index 56cef3b1c194..bb10e33690b2 100755
--- a/tools/testing/selftests/net/forwarding/vxlan_bridge_1d.sh
+++ b/tools/testing/selftests/net/forwarding/vxlan_bridge_1d.sh
@@ -629,7 +629,7 @@ __test_ecn_decap()
629 RET=0 629 RET=0
630 630
631 tc filter add dev $h1 ingress pref 77 prot ip \ 631 tc filter add dev $h1 ingress pref 77 prot ip \
632 flower ip_tos $decapped_tos action pass 632 flower ip_tos $decapped_tos action drop
633 sleep 1 633 sleep 1
634 vxlan_encapped_ping_test v2 v1 192.0.2.17 \ 634 vxlan_encapped_ping_test v2 v1 192.0.2.17 \
635 $orig_inner_tos $orig_outer_tos \ 635 $orig_inner_tos $orig_outer_tos \
diff --git a/tools/testing/selftests/net/ip_defrag.c b/tools/testing/selftests/net/ip_defrag.c
index 61ae2782388e..5d56cc0838f6 100644
--- a/tools/testing/selftests/net/ip_defrag.c
+++ b/tools/testing/selftests/net/ip_defrag.c
@@ -203,6 +203,7 @@ static void send_udp_frags(int fd_raw, struct sockaddr *addr,
203{ 203{
204 struct ip *iphdr = (struct ip *)ip_frame; 204 struct ip *iphdr = (struct ip *)ip_frame;
205 struct ip6_hdr *ip6hdr = (struct ip6_hdr *)ip_frame; 205 struct ip6_hdr *ip6hdr = (struct ip6_hdr *)ip_frame;
206 const bool ipv4 = !ipv6;
206 int res; 207 int res;
207 int offset; 208 int offset;
208 int frag_len; 209 int frag_len;
@@ -239,19 +240,53 @@ static void send_udp_frags(int fd_raw, struct sockaddr *addr,
239 iphdr->ip_sum = 0; 240 iphdr->ip_sum = 0;
240 } 241 }
241 242
243 /* Occasionally test in-order fragments. */
244 if (!cfg_overlap && (rand() % 100 < 15)) {
245 offset = 0;
246 while (offset < (UDP_HLEN + payload_len)) {
247 send_fragment(fd_raw, addr, alen, offset, ipv6);
248 offset += max_frag_len;
249 }
250 return;
251 }
252
253 /* Occasionally test IPv4 "runs" (see net/ipv4/ip_fragment.c) */
254 if (ipv4 && !cfg_overlap && (rand() % 100 < 20) &&
255 (payload_len > 9 * max_frag_len)) {
256 offset = 6 * max_frag_len;
257 while (offset < (UDP_HLEN + payload_len)) {
258 send_fragment(fd_raw, addr, alen, offset, ipv6);
259 offset += max_frag_len;
260 }
261 offset = 3 * max_frag_len;
262 while (offset < 6 * max_frag_len) {
263 send_fragment(fd_raw, addr, alen, offset, ipv6);
264 offset += max_frag_len;
265 }
266 offset = 0;
267 while (offset < 3 * max_frag_len) {
268 send_fragment(fd_raw, addr, alen, offset, ipv6);
269 offset += max_frag_len;
270 }
271 return;
272 }
273
242 /* Odd fragments. */ 274 /* Odd fragments. */
243 offset = max_frag_len; 275 offset = max_frag_len;
244 while (offset < (UDP_HLEN + payload_len)) { 276 while (offset < (UDP_HLEN + payload_len)) {
245 send_fragment(fd_raw, addr, alen, offset, ipv6); 277 send_fragment(fd_raw, addr, alen, offset, ipv6);
278 /* IPv4 ignores duplicates, so randomly send a duplicate. */
279 if (ipv4 && (1 == rand() % 100))
280 send_fragment(fd_raw, addr, alen, offset, ipv6);
246 offset += 2 * max_frag_len; 281 offset += 2 * max_frag_len;
247 } 282 }
248 283
249 if (cfg_overlap) { 284 if (cfg_overlap) {
250 /* Send an extra random fragment. */ 285 /* Send an extra random fragment. */
251 offset = rand() % (UDP_HLEN + payload_len - 1);
252 /* sendto() returns EINVAL if offset + frag_len is too small. */
253 if (ipv6) { 286 if (ipv6) {
254 struct ip6_frag *fraghdr = (struct ip6_frag *)(ip_frame + IP6_HLEN); 287 struct ip6_frag *fraghdr = (struct ip6_frag *)(ip_frame + IP6_HLEN);
288 /* sendto() returns EINVAL if offset + frag_len is too small. */
289 offset = rand() % (UDP_HLEN + payload_len - 1);
255 frag_len = max_frag_len + rand() % 256; 290 frag_len = max_frag_len + rand() % 256;
256 /* In IPv6 if !!(frag_len % 8), the fragment is dropped. */ 291 /* In IPv6 if !!(frag_len % 8), the fragment is dropped. */
257 frag_len &= ~0x7; 292 frag_len &= ~0x7;
@@ -259,13 +294,29 @@ static void send_udp_frags(int fd_raw, struct sockaddr *addr,
259 ip6hdr->ip6_plen = htons(frag_len); 294 ip6hdr->ip6_plen = htons(frag_len);
260 frag_len += IP6_HLEN; 295 frag_len += IP6_HLEN;
261 } else { 296 } else {
262 frag_len = IP4_HLEN + UDP_HLEN + rand() % 256; 297 /* In IPv4, duplicates and some fragments completely inside
298 * previously sent fragments are dropped/ignored. So
299 * random offset and frag_len can result in a dropped
300 * fragment instead of a dropped queue/packet. So we
301 * hard-code offset and frag_len.
302 *
303 * See ade446403bfb ("net: ipv4: do not handle duplicate
304 * fragments as overlapping").
305 */
306 if (max_frag_len * 4 < payload_len || max_frag_len < 16) {
307 /* not enough payload to play with random offset and frag_len. */
308 offset = 8;
309 frag_len = IP4_HLEN + UDP_HLEN + max_frag_len;
310 } else {
311 offset = rand() % (payload_len / 2);
312 frag_len = 2 * max_frag_len + 1 + rand() % 256;
313 }
263 iphdr->ip_off = htons(offset / 8 | IP4_MF); 314 iphdr->ip_off = htons(offset / 8 | IP4_MF);
264 iphdr->ip_len = htons(frag_len); 315 iphdr->ip_len = htons(frag_len);
265 } 316 }
266 res = sendto(fd_raw, ip_frame, frag_len, 0, addr, alen); 317 res = sendto(fd_raw, ip_frame, frag_len, 0, addr, alen);
267 if (res < 0) 318 if (res < 0)
268 error(1, errno, "sendto overlap"); 319 error(1, errno, "sendto overlap: %d", frag_len);
269 if (res != frag_len) 320 if (res != frag_len)
270 error(1, 0, "sendto overlap: %d vs %d", (int)res, frag_len); 321 error(1, 0, "sendto overlap: %d vs %d", (int)res, frag_len);
271 frag_counter++; 322 frag_counter++;
@@ -275,6 +326,9 @@ static void send_udp_frags(int fd_raw, struct sockaddr *addr,
275 offset = 0; 326 offset = 0;
276 while (offset < (UDP_HLEN + payload_len)) { 327 while (offset < (UDP_HLEN + payload_len)) {
277 send_fragment(fd_raw, addr, alen, offset, ipv6); 328 send_fragment(fd_raw, addr, alen, offset, ipv6);
329 /* IPv4 ignores duplicates, so randomly send a duplicate. */
330 if (ipv4 && (1 == rand() % 100))
331 send_fragment(fd_raw, addr, alen, offset, ipv6);
278 offset += 2 * max_frag_len; 332 offset += 2 * max_frag_len;
279 } 333 }
280} 334}
@@ -282,7 +336,11 @@ static void send_udp_frags(int fd_raw, struct sockaddr *addr,
282static void run_test(struct sockaddr *addr, socklen_t alen, bool ipv6) 336static void run_test(struct sockaddr *addr, socklen_t alen, bool ipv6)
283{ 337{
284 int fd_tx_raw, fd_rx_udp; 338 int fd_tx_raw, fd_rx_udp;
285 struct timeval tv = { .tv_sec = 0, .tv_usec = 10 * 1000 }; 339 /* Frag queue timeout is set to one second in the calling script;
340 * socket timeout should be just a bit longer to avoid tests interfering
341 * with each other.
342 */
343 struct timeval tv = { .tv_sec = 1, .tv_usec = 10 };
286 int idx; 344 int idx;
287 int min_frag_len = ipv6 ? 1280 : 8; 345 int min_frag_len = ipv6 ? 1280 : 8;
288 346
@@ -308,12 +366,32 @@ static void run_test(struct sockaddr *addr, socklen_t alen, bool ipv6)
308 payload_len += (rand() % 4096)) { 366 payload_len += (rand() % 4096)) {
309 if (cfg_verbose) 367 if (cfg_verbose)
310 printf("payload_len: %d\n", payload_len); 368 printf("payload_len: %d\n", payload_len);
311 max_frag_len = min_frag_len; 369
312 do { 370 if (cfg_overlap) {
371 /* With overlaps, one send/receive pair below takes
372 * at least one second (== timeout) to run, so there
373 * is not enough test time to run a nested loop:
374 * the full overlap test takes 20-30 seconds.
375 */
376 max_frag_len = min_frag_len +
377 rand() % (1500 - FRAG_HLEN - min_frag_len);
313 send_udp_frags(fd_tx_raw, addr, alen, ipv6); 378 send_udp_frags(fd_tx_raw, addr, alen, ipv6);
314 recv_validate_udp(fd_rx_udp); 379 recv_validate_udp(fd_rx_udp);
315 max_frag_len += 8 * (rand() % 8); 380 } else {
316 } while (max_frag_len < (1500 - FRAG_HLEN) && max_frag_len <= payload_len); 381 /* Without overlaps, each packet reassembly (== one
382 * send/receive pair below) takes very little time to
383 * run, so we can easily afford more thourough testing
384 * with a nested loop: the full non-overlap test takes
385 * less than one second).
386 */
387 max_frag_len = min_frag_len;
388 do {
389 send_udp_frags(fd_tx_raw, addr, alen, ipv6);
390 recv_validate_udp(fd_rx_udp);
391 max_frag_len += 8 * (rand() % 8);
392 } while (max_frag_len < (1500 - FRAG_HLEN) &&
393 max_frag_len <= payload_len);
394 }
317 } 395 }
318 396
319 /* Cleanup. */ 397 /* Cleanup. */
diff --git a/tools/testing/selftests/net/ip_defrag.sh b/tools/testing/selftests/net/ip_defrag.sh
index f34672796044..7dd79a9efb17 100755
--- a/tools/testing/selftests/net/ip_defrag.sh
+++ b/tools/testing/selftests/net/ip_defrag.sh
@@ -11,10 +11,17 @@ readonly NETNS="ns-$(mktemp -u XXXXXX)"
11setup() { 11setup() {
12 ip netns add "${NETNS}" 12 ip netns add "${NETNS}"
13 ip -netns "${NETNS}" link set lo up 13 ip -netns "${NETNS}" link set lo up
14
14 ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_high_thresh=9000000 >/dev/null 2>&1 15 ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_high_thresh=9000000 >/dev/null 2>&1
15 ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_low_thresh=7000000 >/dev/null 2>&1 16 ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_low_thresh=7000000 >/dev/null 2>&1
17 ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_time=1 >/dev/null 2>&1
18
16 ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_high_thresh=9000000 >/dev/null 2>&1 19 ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_high_thresh=9000000 >/dev/null 2>&1
17 ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_low_thresh=7000000 >/dev/null 2>&1 20 ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_low_thresh=7000000 >/dev/null 2>&1
21 ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_time=1 >/dev/null 2>&1
22
23 # DST cache can get full with a lot of frags, with GC not keeping up with the test.
24 ip netns exec "${NETNS}" sysctl -w net.ipv6.route.max_size=65536 >/dev/null 2>&1
18} 25}
19 26
20cleanup() { 27cleanup() {
@@ -27,7 +34,6 @@ setup
27echo "ipv4 defrag" 34echo "ipv4 defrag"
28ip netns exec "${NETNS}" ./ip_defrag -4 35ip netns exec "${NETNS}" ./ip_defrag -4
29 36
30
31echo "ipv4 defrag with overlaps" 37echo "ipv4 defrag with overlaps"
32ip netns exec "${NETNS}" ./ip_defrag -4o 38ip netns exec "${NETNS}" ./ip_defrag -4o
33 39
@@ -37,3 +43,4 @@ ip netns exec "${NETNS}" ./ip_defrag -6
37echo "ipv6 defrag with overlaps" 43echo "ipv6 defrag with overlaps"
38ip netns exec "${NETNS}" ./ip_defrag -6o 44ip netns exec "${NETNS}" ./ip_defrag -6o
39 45
46echo "all tests done"
diff --git a/tools/testing/selftests/net/xfrm_policy.sh b/tools/testing/selftests/net/xfrm_policy.sh
index 8db35b99457c..71d7fdc513c1 100755
--- a/tools/testing/selftests/net/xfrm_policy.sh
+++ b/tools/testing/selftests/net/xfrm_policy.sh
@@ -28,6 +28,19 @@ KEY_AES=0x0123456789abcdef0123456789012345
28SPI1=0x1 28SPI1=0x1
29SPI2=0x2 29SPI2=0x2
30 30
31do_esp_policy() {
32 local ns=$1
33 local me=$2
34 local remote=$3
35 local lnet=$4
36 local rnet=$5
37
38 # to encrypt packets as they go out (includes forwarded packets that need encapsulation)
39 ip -net $ns xfrm policy add src $lnet dst $rnet dir out tmpl src $me dst $remote proto esp mode tunnel priority 100 action allow
40 # to fwd decrypted packets after esp processing:
41 ip -net $ns xfrm policy add src $rnet dst $lnet dir fwd tmpl src $remote dst $me proto esp mode tunnel priority 100 action allow
42}
43
31do_esp() { 44do_esp() {
32 local ns=$1 45 local ns=$1
33 local me=$2 46 local me=$2
@@ -40,10 +53,59 @@ do_esp() {
40 ip -net $ns xfrm state add src $remote dst $me proto esp spi $spi_in enc aes $KEY_AES auth sha1 $KEY_SHA mode tunnel sel src $rnet dst $lnet 53 ip -net $ns xfrm state add src $remote dst $me proto esp spi $spi_in enc aes $KEY_AES auth sha1 $KEY_SHA mode tunnel sel src $rnet dst $lnet
41 ip -net $ns xfrm state add src $me dst $remote proto esp spi $spi_out enc aes $KEY_AES auth sha1 $KEY_SHA mode tunnel sel src $lnet dst $rnet 54 ip -net $ns xfrm state add src $me dst $remote proto esp spi $spi_out enc aes $KEY_AES auth sha1 $KEY_SHA mode tunnel sel src $lnet dst $rnet
42 55
43 # to encrypt packets as they go out (includes forwarded packets that need encapsulation) 56 do_esp_policy $ns $me $remote $lnet $rnet
44 ip -net $ns xfrm policy add src $lnet dst $rnet dir out tmpl src $me dst $remote proto esp mode tunnel priority 100 action allow 57}
45 # to fwd decrypted packets after esp processing: 58
46 ip -net $ns xfrm policy add src $rnet dst $lnet dir fwd tmpl src $remote dst $me proto esp mode tunnel priority 100 action allow 59# add policies with different netmasks, to make sure kernel carries
60# the policies contained within new netmask over when search tree is
61# re-built.
62# peer netns that are supposed to be encapsulated via esp have addresses
63# in the 10.0.1.0/24 and 10.0.2.0/24 subnets, respectively.
64#
65# Adding a policy for '10.0.1.0/23' will make it necessary to
66# alter the prefix of 10.0.1.0 subnet.
67# In case new prefix overlaps with existing node, the node and all
68# policies it carries need to be merged with the existing one(s).
69#
70# Do that here.
71do_overlap()
72{
73 local ns=$1
74
75 # adds new nodes to tree (neither network exists yet in policy database).
76 ip -net $ns xfrm policy add src 10.1.0.0/24 dst 10.0.0.0/24 dir fwd priority 200 action block
77
78 # adds a new node in the 10.0.0.0/24 tree (dst node exists).
79 ip -net $ns xfrm policy add src 10.2.0.0/24 dst 10.0.0.0/24 dir fwd priority 200 action block
80
81 # adds a 10.2.0.0/23 node, but for different dst.
82 ip -net $ns xfrm policy add src 10.2.0.0/23 dst 10.0.1.0/24 dir fwd priority 200 action block
83
84 # dst now overlaps with the 10.0.1.0/24 ESP policy in fwd.
85 # kernel must 'promote' existing one (10.0.0.0/24) to 10.0.0.0/23.
86 # But 10.0.0.0/23 also includes existing 10.0.1.0/24, so that node
87 # also has to be merged too, including source-sorted subtrees.
88 # old:
89 # 10.0.0.0/24 (node 1 in dst tree of the bin)
90 # 10.1.0.0/24 (node in src tree of dst node 1)
91 # 10.2.0.0/24 (node in src tree of dst node 1)
92 # 10.0.1.0/24 (node 2 in dst tree of the bin)
93 # 10.0.2.0/24 (node in src tree of dst node 2)
94 # 10.2.0.0/24 (node in src tree of dst node 2)
95 #
96 # The next 'policy add' adds dst '10.0.0.0/23', which means
97 # that dst node 1 and dst node 2 have to be merged including
98 # the sub-tree. As no duplicates are allowed, policies in
99 # the two '10.0.2.0/24' are also merged.
100 #
101 # after the 'add', internal search tree should look like this:
102 # 10.0.0.0/23 (node in dst tree of bin)
103 # 10.0.2.0/24 (node in src tree of dst node)
104 # 10.1.0.0/24 (node in src tree of dst node)
105 # 10.2.0.0/24 (node in src tree of dst node)
106 #
107 # 10.0.0.0/24 and 10.0.1.0/24 nodes have been merged as 10.0.0.0/23.
108 ip -net $ns xfrm policy add src 10.1.0.0/24 dst 10.0.0.0/23 dir fwd priority 200 action block
47} 109}
48 110
49do_esp_policy_get_check() { 111do_esp_policy_get_check() {
@@ -160,6 +222,41 @@ check_xfrm() {
160 return $lret 222 return $lret
161} 223}
162 224
225check_exceptions()
226{
227 logpostfix="$1"
228 local lret=0
229
230 # ping to .254 should be excluded from the tunnel (exception is in place).
231 check_xfrm 0 254
232 if [ $? -ne 0 ]; then
233 echo "FAIL: expected ping to .254 to fail ($logpostfix)"
234 lret=1
235 else
236 echo "PASS: ping to .254 bypassed ipsec tunnel ($logpostfix)"
237 fi
238
239 # ping to .253 should use use ipsec due to direct policy exception.
240 check_xfrm 1 253
241 if [ $? -ne 0 ]; then
242 echo "FAIL: expected ping to .253 to use ipsec tunnel ($logpostfix)"
243 lret=1
244 else
245 echo "PASS: direct policy matches ($logpostfix)"
246 fi
247
248 # ping to .2 should use ipsec.
249 check_xfrm 1 2
250 if [ $? -ne 0 ]; then
251 echo "FAIL: expected ping to .2 to use ipsec tunnel ($logpostfix)"
252 lret=1
253 else
254 echo "PASS: policy matches ($logpostfix)"
255 fi
256
257 return $lret
258}
259
163#check for needed privileges 260#check for needed privileges
164if [ "$(id -u)" -ne 0 ];then 261if [ "$(id -u)" -ne 0 ];then
165 echo "SKIP: Need root privileges" 262 echo "SKIP: Need root privileges"
@@ -270,33 +367,45 @@ do_exception ns4 10.0.3.10 10.0.3.1 10.0.1.253 10.0.1.240/28
270do_exception ns3 dead:3::1 dead:3::10 dead:2::fd dead:2:f0::/96 367do_exception ns3 dead:3::1 dead:3::10 dead:2::fd dead:2:f0::/96
271do_exception ns4 dead:3::10 dead:3::1 dead:1::fd dead:1:f0::/96 368do_exception ns4 dead:3::10 dead:3::1 dead:1::fd dead:1:f0::/96
272 369
273# ping to .254 should now be excluded from the tunnel 370check_exceptions "exceptions"
274check_xfrm 0 254
275if [ $? -ne 0 ]; then 371if [ $? -ne 0 ]; then
276 echo "FAIL: expected ping to .254 to fail"
277 ret=1 372 ret=1
278else
279 echo "PASS: ping to .254 bypassed ipsec tunnel"
280fi 373fi
281 374
282# ping to .253 should use use ipsec due to direct policy exception. 375# insert block policies with adjacent/overlapping netmasks
283check_xfrm 1 253 376do_overlap ns3
284if [ $? -ne 0 ]; then
285 echo "FAIL: expected ping to .253 to use ipsec tunnel"
286 ret=1
287else
288 echo "PASS: direct policy matches"
289fi
290 377
291# ping to .2 should use ipsec. 378check_exceptions "exceptions and block policies"
292check_xfrm 1 2
293if [ $? -ne 0 ]; then 379if [ $? -ne 0 ]; then
294 echo "FAIL: expected ping to .2 to use ipsec tunnel"
295 ret=1 380 ret=1
296else
297 echo "PASS: policy matches"
298fi 381fi
299 382
383for n in ns3 ns4;do
384 ip -net $n xfrm policy set hthresh4 28 24 hthresh6 126 125
385 sleep $((RANDOM%5))
386done
387
388check_exceptions "exceptions and block policies after hresh changes"
389
390# full flush of policy db, check everything gets freed incl. internal meta data
391ip -net ns3 xfrm policy flush
392
393do_esp_policy ns3 10.0.3.1 10.0.3.10 10.0.1.0/24 10.0.2.0/24
394do_exception ns3 10.0.3.1 10.0.3.10 10.0.2.253 10.0.2.240/28
395
396# move inexact policies to hash table
397ip -net ns3 xfrm policy set hthresh4 16 16
398
399sleep $((RANDOM%5))
400check_exceptions "exceptions and block policies after hthresh change in ns3"
401
402# restore original hthresh settings -- move policies back to tables
403for n in ns3 ns4;do
404 ip -net $n xfrm policy set hthresh4 32 32 hthresh6 128 128
405 sleep $((RANDOM%5))
406done
407check_exceptions "exceptions and block policies after hresh change to normal"
408
300for i in 1 2 3 4;do ip netns del ns$i;done 409for i in 1 2 3 4;do ip netns del ns$i;done
301 410
302exit $ret 411exit $ret
diff --git a/tools/testing/selftests/netfilter/Makefile b/tools/testing/selftests/netfilter/Makefile
index 47ed6cef93fb..c9ff2b47bd1c 100644
--- a/tools/testing/selftests/netfilter/Makefile
+++ b/tools/testing/selftests/netfilter/Makefile
@@ -1,6 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Makefile for netfilter selftests 2# Makefile for netfilter selftests
3 3
4TEST_PROGS := nft_trans_stress.sh 4TEST_PROGS := nft_trans_stress.sh nft_nat.sh
5 5
6include ../lib.mk 6include ../lib.mk
diff --git a/tools/testing/selftests/netfilter/config b/tools/testing/selftests/netfilter/config
index 1017313e41a8..59caa8f71cd8 100644
--- a/tools/testing/selftests/netfilter/config
+++ b/tools/testing/selftests/netfilter/config
@@ -1,2 +1,2 @@
1CONFIG_NET_NS=y 1CONFIG_NET_NS=y
2NF_TABLES_INET=y 2CONFIG_NF_TABLES_INET=y
diff --git a/tools/testing/selftests/netfilter/nft_nat.sh b/tools/testing/selftests/netfilter/nft_nat.sh
new file mode 100755
index 000000000000..8ec76681605c
--- /dev/null
+++ b/tools/testing/selftests/netfilter/nft_nat.sh
@@ -0,0 +1,762 @@
1#!/bin/bash
2#
3# This test is for basic NAT functionality: snat, dnat, redirect, masquerade.
4#
5
6# Kselftest framework requirement - SKIP code is 4.
7ksft_skip=4
8ret=0
9
10nft --version > /dev/null 2>&1
11if [ $? -ne 0 ];then
12 echo "SKIP: Could not run test without nft tool"
13 exit $ksft_skip
14fi
15
16ip -Version > /dev/null 2>&1
17if [ $? -ne 0 ];then
18 echo "SKIP: Could not run test without ip tool"
19 exit $ksft_skip
20fi
21
22ip netns add ns0
23ip netns add ns1
24ip netns add ns2
25
26ip link add veth0 netns ns0 type veth peer name eth0 netns ns1
27ip link add veth1 netns ns0 type veth peer name eth0 netns ns2
28
29ip -net ns0 link set lo up
30ip -net ns0 link set veth0 up
31ip -net ns0 addr add 10.0.1.1/24 dev veth0
32ip -net ns0 addr add dead:1::1/64 dev veth0
33
34ip -net ns0 link set veth1 up
35ip -net ns0 addr add 10.0.2.1/24 dev veth1
36ip -net ns0 addr add dead:2::1/64 dev veth1
37
38for i in 1 2; do
39 ip -net ns$i link set lo up
40 ip -net ns$i link set eth0 up
41 ip -net ns$i addr add 10.0.$i.99/24 dev eth0
42 ip -net ns$i route add default via 10.0.$i.1
43 ip -net ns$i addr add dead:$i::99/64 dev eth0
44 ip -net ns$i route add default via dead:$i::1
45done
46
47bad_counter()
48{
49 local ns=$1
50 local counter=$2
51 local expect=$3
52
53 echo "ERROR: $counter counter in $ns has unexpected value (expected $expect)" 1>&2
54 ip netns exec $ns nft list counter inet filter $counter 1>&2
55}
56
57check_counters()
58{
59 ns=$1
60 local lret=0
61
62 cnt=$(ip netns exec $ns nft list counter inet filter ns0in | grep -q "packets 1 bytes 84")
63 if [ $? -ne 0 ]; then
64 bad_counter $ns ns0in "packets 1 bytes 84"
65 lret=1
66 fi
67 cnt=$(ip netns exec $ns nft list counter inet filter ns0out | grep -q "packets 1 bytes 84")
68 if [ $? -ne 0 ]; then
69 bad_counter $ns ns0out "packets 1 bytes 84"
70 lret=1
71 fi
72
73 expect="packets 1 bytes 104"
74 cnt=$(ip netns exec $ns nft list counter inet filter ns0in6 | grep -q "$expect")
75 if [ $? -ne 0 ]; then
76 bad_counter $ns ns0in6 "$expect"
77 lret=1
78 fi
79 cnt=$(ip netns exec $ns nft list counter inet filter ns0out6 | grep -q "$expect")
80 if [ $? -ne 0 ]; then
81 bad_counter $ns ns0out6 "$expect"
82 lret=1
83 fi
84
85 return $lret
86}
87
88check_ns0_counters()
89{
90 local ns=$1
91 local lret=0
92
93 cnt=$(ip netns exec ns0 nft list counter inet filter ns0in | grep -q "packets 0 bytes 0")
94 if [ $? -ne 0 ]; then
95 bad_counter ns0 ns0in "packets 0 bytes 0"
96 lret=1
97 fi
98
99 cnt=$(ip netns exec ns0 nft list counter inet filter ns0in6 | grep -q "packets 0 bytes 0")
100 if [ $? -ne 0 ]; then
101 bad_counter ns0 ns0in6 "packets 0 bytes 0"
102 lret=1
103 fi
104
105 cnt=$(ip netns exec ns0 nft list counter inet filter ns0out | grep -q "packets 0 bytes 0")
106 if [ $? -ne 0 ]; then
107 bad_counter ns0 ns0out "packets 0 bytes 0"
108 lret=1
109 fi
110 cnt=$(ip netns exec ns0 nft list counter inet filter ns0out6 | grep -q "packets 0 bytes 0")
111 if [ $? -ne 0 ]; then
112 bad_counter ns0 ns0out6 "packets 0 bytes 0"
113 lret=1
114 fi
115
116 for dir in "in" "out" ; do
117 expect="packets 1 bytes 84"
118 cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir} | grep -q "$expect")
119 if [ $? -ne 0 ]; then
120 bad_counter ns0 $ns$dir "$expect"
121 lret=1
122 fi
123
124 expect="packets 1 bytes 104"
125 cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir}6 | grep -q "$expect")
126 if [ $? -ne 0 ]; then
127 bad_counter ns0 $ns$dir6 "$expect"
128 lret=1
129 fi
130 done
131
132 return $lret
133}
134
135reset_counters()
136{
137 for i in 0 1 2;do
138 ip netns exec ns$i nft reset counters inet > /dev/null
139 done
140}
141
142test_local_dnat6()
143{
144 local lret=0
145ip netns exec ns0 nft -f - <<EOF
146table ip6 nat {
147 chain output {
148 type nat hook output priority 0; policy accept;
149 ip6 daddr dead:1::99 dnat to dead:2::99
150 }
151}
152EOF
153 if [ $? -ne 0 ]; then
154 echo "SKIP: Could not add add ip6 dnat hook"
155 return $ksft_skip
156 fi
157
158 # ping netns1, expect rewrite to netns2
159 ip netns exec ns0 ping -q -c 1 dead:1::99 > /dev/null
160 if [ $? -ne 0 ]; then
161 lret=1
162 echo "ERROR: ping6 failed"
163 return $lret
164 fi
165
166 expect="packets 0 bytes 0"
167 for dir in "in6" "out6" ; do
168 cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
169 if [ $? -ne 0 ]; then
170 bad_counter ns0 ns1$dir "$expect"
171 lret=1
172 fi
173 done
174
175 expect="packets 1 bytes 104"
176 for dir in "in6" "out6" ; do
177 cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
178 if [ $? -ne 0 ]; then
179 bad_counter ns0 ns2$dir "$expect"
180 lret=1
181 fi
182 done
183
184 # expect 0 count in ns1
185 expect="packets 0 bytes 0"
186 for dir in "in6" "out6" ; do
187 cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
188 if [ $? -ne 0 ]; then
189 bad_counter ns1 ns0$dir "$expect"
190 lret=1
191 fi
192 done
193
194 # expect 1 packet in ns2
195 expect="packets 1 bytes 104"
196 for dir in "in6" "out6" ; do
197 cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
198 if [ $? -ne 0 ]; then
199 bad_counter ns2 ns0$dir "$expect"
200 lret=1
201 fi
202 done
203
204 test $lret -eq 0 && echo "PASS: ipv6 ping to ns1 was NATted to ns2"
205 ip netns exec ns0 nft flush chain ip6 nat output
206
207 return $lret
208}
209
210test_local_dnat()
211{
212 local lret=0
213ip netns exec ns0 nft -f - <<EOF
214table ip nat {
215 chain output {
216 type nat hook output priority 0; policy accept;
217 ip daddr 10.0.1.99 dnat to 10.0.2.99
218 }
219}
220EOF
221 # ping netns1, expect rewrite to netns2
222 ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
223 if [ $? -ne 0 ]; then
224 lret=1
225 echo "ERROR: ping failed"
226 return $lret
227 fi
228
229 expect="packets 0 bytes 0"
230 for dir in "in" "out" ; do
231 cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
232 if [ $? -ne 0 ]; then
233 bad_counter ns0 ns1$dir "$expect"
234 lret=1
235 fi
236 done
237
238 expect="packets 1 bytes 84"
239 for dir in "in" "out" ; do
240 cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
241 if [ $? -ne 0 ]; then
242 bad_counter ns0 ns2$dir "$expect"
243 lret=1
244 fi
245 done
246
247 # expect 0 count in ns1
248 expect="packets 0 bytes 0"
249 for dir in "in" "out" ; do
250 cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
251 if [ $? -ne 0 ]; then
252 bad_counter ns1 ns0$dir "$expect"
253 lret=1
254 fi
255 done
256
257 # expect 1 packet in ns2
258 expect="packets 1 bytes 84"
259 for dir in "in" "out" ; do
260 cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
261 if [ $? -ne 0 ]; then
262 bad_counter ns2 ns0$dir "$expect"
263 lret=1
264 fi
265 done
266
267 test $lret -eq 0 && echo "PASS: ping to ns1 was NATted to ns2"
268
269 ip netns exec ns0 nft flush chain ip nat output
270
271 reset_counters
272 ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
273 if [ $? -ne 0 ]; then
274 lret=1
275 echo "ERROR: ping failed"
276 return $lret
277 fi
278
279 expect="packets 1 bytes 84"
280 for dir in "in" "out" ; do
281 cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
282 if [ $? -ne 0 ]; then
283 bad_counter ns1 ns1$dir "$expect"
284 lret=1
285 fi
286 done
287 expect="packets 0 bytes 0"
288 for dir in "in" "out" ; do
289 cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
290 if [ $? -ne 0 ]; then
291 bad_counter ns0 ns2$dir "$expect"
292 lret=1
293 fi
294 done
295
296 # expect 1 count in ns1
297 expect="packets 1 bytes 84"
298 for dir in "in" "out" ; do
299 cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
300 if [ $? -ne 0 ]; then
301 bad_counter ns0 ns0$dir "$expect"
302 lret=1
303 fi
304 done
305
306 # expect 0 packet in ns2
307 expect="packets 0 bytes 0"
308 for dir in "in" "out" ; do
309 cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
310 if [ $? -ne 0 ]; then
311 bad_counter ns2 ns2$dir "$expect"
312 lret=1
313 fi
314 done
315
316 test $lret -eq 0 && echo "PASS: ping to ns1 OK after nat output chain flush"
317
318 return $lret
319}
320
321
322test_masquerade6()
323{
324 local lret=0
325
326 ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
327
328 ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
329 if [ $? -ne 0 ] ; then
330 echo "ERROR: cannot ping ns1 from ns2 via ipv6"
331 return 1
332 lret=1
333 fi
334
335 expect="packets 1 bytes 104"
336 for dir in "in6" "out6" ; do
337 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
338 if [ $? -ne 0 ]; then
339 bad_counter ns1 ns2$dir "$expect"
340 lret=1
341 fi
342
343 cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
344 if [ $? -ne 0 ]; then
345 bad_counter ns2 ns1$dir "$expect"
346 lret=1
347 fi
348 done
349
350 reset_counters
351
352# add masquerading rule
353ip netns exec ns0 nft -f - <<EOF
354table ip6 nat {
355 chain postrouting {
356 type nat hook postrouting priority 0; policy accept;
357 meta oif veth0 masquerade
358 }
359}
360EOF
361 ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
362 if [ $? -ne 0 ] ; then
363 echo "ERROR: cannot ping ns1 from ns2 with active ipv6 masquerading"
364 lret=1
365 fi
366
367 # ns1 should have seen packets from ns0, due to masquerade
368 expect="packets 1 bytes 104"
369 for dir in "in6" "out6" ; do
370
371 cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
372 if [ $? -ne 0 ]; then
373 bad_counter ns1 ns0$dir "$expect"
374 lret=1
375 fi
376
377 cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
378 if [ $? -ne 0 ]; then
379 bad_counter ns2 ns1$dir "$expect"
380 lret=1
381 fi
382 done
383
384 # ns1 should not have seen packets from ns2, due to masquerade
385 expect="packets 0 bytes 0"
386 for dir in "in6" "out6" ; do
387 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
388 if [ $? -ne 0 ]; then
389 bad_counter ns1 ns0$dir "$expect"
390 lret=1
391 fi
392
393 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
394 if [ $? -ne 0 ]; then
395 bad_counter ns2 ns1$dir "$expect"
396 lret=1
397 fi
398 done
399
400 ip netns exec ns0 nft flush chain ip6 nat postrouting
401 if [ $? -ne 0 ]; then
402 echo "ERROR: Could not flush ip6 nat postrouting" 1>&2
403 lret=1
404 fi
405
406 test $lret -eq 0 && echo "PASS: IPv6 masquerade for ns2"
407
408 return $lret
409}
410
411test_masquerade()
412{
413 local lret=0
414
415 ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
416 ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
417
418 ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
419 if [ $? -ne 0 ] ; then
420 echo "ERROR: canot ping ns1 from ns2"
421 lret=1
422 fi
423
424 expect="packets 1 bytes 84"
425 for dir in "in" "out" ; do
426 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
427 if [ $? -ne 0 ]; then
428 bad_counter ns1 ns2$dir "$expect"
429 lret=1
430 fi
431
432 cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
433 if [ $? -ne 0 ]; then
434 bad_counter ns2 ns1$dir "$expect"
435 lret=1
436 fi
437 done
438
439 reset_counters
440
441# add masquerading rule
442ip netns exec ns0 nft -f - <<EOF
443table ip nat {
444 chain postrouting {
445 type nat hook postrouting priority 0; policy accept;
446 meta oif veth0 masquerade
447 }
448}
449EOF
450 ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
451 if [ $? -ne 0 ] ; then
452 echo "ERROR: cannot ping ns1 from ns2 with active ip masquerading"
453 lret=1
454 fi
455
456 # ns1 should have seen packets from ns0, due to masquerade
457 expect="packets 1 bytes 84"
458 for dir in "in" "out" ; do
459 cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
460 if [ $? -ne 0 ]; then
461 bad_counter ns1 ns0$dir "$expect"
462 lret=1
463 fi
464
465 cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
466 if [ $? -ne 0 ]; then
467 bad_counter ns2 ns1$dir "$expect"
468 lret=1
469 fi
470 done
471
472 # ns1 should not have seen packets from ns2, due to masquerade
473 expect="packets 0 bytes 0"
474 for dir in "in" "out" ; do
475 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
476 if [ $? -ne 0 ]; then
477 bad_counter ns1 ns0$dir "$expect"
478 lret=1
479 fi
480
481 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
482 if [ $? -ne 0 ]; then
483 bad_counter ns2 ns1$dir "$expect"
484 lret=1
485 fi
486 done
487
488 ip netns exec ns0 nft flush chain ip nat postrouting
489 if [ $? -ne 0 ]; then
490 echo "ERROR: Could not flush nat postrouting" 1>&2
491 lret=1
492 fi
493
494 test $lret -eq 0 && echo "PASS: IP masquerade for ns2"
495
496 return $lret
497}
498
499test_redirect6()
500{
501 local lret=0
502
503 ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
504
505 ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
506 if [ $? -ne 0 ] ; then
507 echo "ERROR: cannnot ping ns1 from ns2 via ipv6"
508 lret=1
509 fi
510
511 expect="packets 1 bytes 104"
512 for dir in "in6" "out6" ; do
513 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
514 if [ $? -ne 0 ]; then
515 bad_counter ns1 ns2$dir "$expect"
516 lret=1
517 fi
518
519 cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
520 if [ $? -ne 0 ]; then
521 bad_counter ns2 ns1$dir "$expect"
522 lret=1
523 fi
524 done
525
526 reset_counters
527
528# add redirect rule
529ip netns exec ns0 nft -f - <<EOF
530table ip6 nat {
531 chain prerouting {
532 type nat hook prerouting priority 0; policy accept;
533 meta iif veth1 meta l4proto icmpv6 ip6 saddr dead:2::99 ip6 daddr dead:1::99 redirect
534 }
535}
536EOF
537 ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
538 if [ $? -ne 0 ] ; then
539 echo "ERROR: cannot ping ns1 from ns2 with active ip6 redirect"
540 lret=1
541 fi
542
543 # ns1 should have seen no packets from ns2, due to redirection
544 expect="packets 0 bytes 0"
545 for dir in "in6" "out6" ; do
546 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
547 if [ $? -ne 0 ]; then
548 bad_counter ns1 ns0$dir "$expect"
549 lret=1
550 fi
551 done
552
553 # ns0 should have seen packets from ns2, due to masquerade
554 expect="packets 1 bytes 104"
555 for dir in "in6" "out6" ; do
556 cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
557 if [ $? -ne 0 ]; then
558 bad_counter ns1 ns0$dir "$expect"
559 lret=1
560 fi
561 done
562
563 ip netns exec ns0 nft delete table ip6 nat
564 if [ $? -ne 0 ]; then
565 echo "ERROR: Could not delete ip6 nat table" 1>&2
566 lret=1
567 fi
568
569 test $lret -eq 0 && echo "PASS: IPv6 redirection for ns2"
570
571 return $lret
572}
573
574test_redirect()
575{
576 local lret=0
577
578 ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
579 ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
580
581 ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
582 if [ $? -ne 0 ] ; then
583 echo "ERROR: cannot ping ns1 from ns2"
584 lret=1
585 fi
586
587 expect="packets 1 bytes 84"
588 for dir in "in" "out" ; do
589 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
590 if [ $? -ne 0 ]; then
591 bad_counter ns1 ns2$dir "$expect"
592 lret=1
593 fi
594
595 cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
596 if [ $? -ne 0 ]; then
597 bad_counter ns2 ns1$dir "$expect"
598 lret=1
599 fi
600 done
601
602 reset_counters
603
604# add redirect rule
605ip netns exec ns0 nft -f - <<EOF
606table ip nat {
607 chain prerouting {
608 type nat hook prerouting priority 0; policy accept;
609 meta iif veth1 ip protocol icmp ip saddr 10.0.2.99 ip daddr 10.0.1.99 redirect
610 }
611}
612EOF
613 ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
614 if [ $? -ne 0 ] ; then
615 echo "ERROR: cannot ping ns1 from ns2 with active ip redirect"
616 lret=1
617 fi
618
619 # ns1 should have seen no packets from ns2, due to redirection
620 expect="packets 0 bytes 0"
621 for dir in "in" "out" ; do
622
623 cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
624 if [ $? -ne 0 ]; then
625 bad_counter ns1 ns0$dir "$expect"
626 lret=1
627 fi
628 done
629
630 # ns0 should have seen packets from ns2, due to masquerade
631 expect="packets 1 bytes 84"
632 for dir in "in" "out" ; do
633 cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
634 if [ $? -ne 0 ]; then
635 bad_counter ns1 ns0$dir "$expect"
636 lret=1
637 fi
638 done
639
640 ip netns exec ns0 nft delete table ip nat
641 if [ $? -ne 0 ]; then
642 echo "ERROR: Could not delete nat table" 1>&2
643 lret=1
644 fi
645
646 test $lret -eq 0 && echo "PASS: IP redirection for ns2"
647
648 return $lret
649}
650
651
652# ip netns exec ns0 ping -c 1 -q 10.0.$i.99
653for i in 0 1 2; do
654ip netns exec ns$i nft -f - <<EOF
655table inet filter {
656 counter ns0in {}
657 counter ns1in {}
658 counter ns2in {}
659
660 counter ns0out {}
661 counter ns1out {}
662 counter ns2out {}
663
664 counter ns0in6 {}
665 counter ns1in6 {}
666 counter ns2in6 {}
667
668 counter ns0out6 {}
669 counter ns1out6 {}
670 counter ns2out6 {}
671
672 map nsincounter {
673 type ipv4_addr : counter
674 elements = { 10.0.1.1 : "ns0in",
675 10.0.2.1 : "ns0in",
676 10.0.1.99 : "ns1in",
677 10.0.2.99 : "ns2in" }
678 }
679
680 map nsincounter6 {
681 type ipv6_addr : counter
682 elements = { dead:1::1 : "ns0in6",
683 dead:2::1 : "ns0in6",
684 dead:1::99 : "ns1in6",
685 dead:2::99 : "ns2in6" }
686 }
687
688 map nsoutcounter {
689 type ipv4_addr : counter
690 elements = { 10.0.1.1 : "ns0out",
691 10.0.2.1 : "ns0out",
692 10.0.1.99: "ns1out",
693 10.0.2.99: "ns2out" }
694 }
695
696 map nsoutcounter6 {
697 type ipv6_addr : counter
698 elements = { dead:1::1 : "ns0out6",
699 dead:2::1 : "ns0out6",
700 dead:1::99 : "ns1out6",
701 dead:2::99 : "ns2out6" }
702 }
703
704 chain input {
705 type filter hook input priority 0; policy accept;
706 counter name ip saddr map @nsincounter
707 icmpv6 type { "echo-request", "echo-reply" } counter name ip6 saddr map @nsincounter6
708 }
709 chain output {
710 type filter hook output priority 0; policy accept;
711 counter name ip daddr map @nsoutcounter
712 icmpv6 type { "echo-request", "echo-reply" } counter name ip6 daddr map @nsoutcounter6
713 }
714}
715EOF
716done
717
718sleep 3
719# test basic connectivity
720for i in 1 2; do
721 ip netns exec ns0 ping -c 1 -q 10.0.$i.99 > /dev/null
722 if [ $? -ne 0 ];then
723 echo "ERROR: Could not reach other namespace(s)" 1>&2
724 ret=1
725 fi
726
727 ip netns exec ns0 ping -c 1 -q dead:$i::99 > /dev/null
728 if [ $? -ne 0 ];then
729 echo "ERROR: Could not reach other namespace(s) via ipv6" 1>&2
730 ret=1
731 fi
732 check_counters ns$i
733 if [ $? -ne 0 ]; then
734 ret=1
735 fi
736
737 check_ns0_counters ns$i
738 if [ $? -ne 0 ]; then
739 ret=1
740 fi
741 reset_counters
742done
743
744if [ $ret -eq 0 ];then
745 echo "PASS: netns routing/connectivity: ns0 can reach ns1 and ns2"
746fi
747
748reset_counters
749test_local_dnat
750test_local_dnat6
751
752reset_counters
753test_masquerade
754test_masquerade6
755
756reset_counters
757test_redirect
758test_redirect6
759
760for i in 0 1 2; do ip netns del ns$i;done
761
762exit $ret
diff --git a/tools/testing/selftests/networking/timestamping/Makefile b/tools/testing/selftests/networking/timestamping/Makefile
index 9050eeea5f5f..1de8bd8ccf5d 100644
--- a/tools/testing/selftests/networking/timestamping/Makefile
+++ b/tools/testing/selftests/networking/timestamping/Makefile
@@ -9,6 +9,3 @@ all: $(TEST_PROGS)
9top_srcdir = ../../../../.. 9top_srcdir = ../../../../..
10KSFT_KHDR_INSTALL := 1 10KSFT_KHDR_INSTALL := 1
11include ../../lib.mk 11include ../../lib.mk
12
13clean:
14 rm -fr $(TEST_GEN_FILES)
diff --git a/tools/testing/selftests/networking/timestamping/txtimestamp.c b/tools/testing/selftests/networking/timestamping/txtimestamp.c
index 2e563d17cf0c..d1bbafb16f47 100644
--- a/tools/testing/selftests/networking/timestamping/txtimestamp.c
+++ b/tools/testing/selftests/networking/timestamping/txtimestamp.c
@@ -240,7 +240,7 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len)
240 cm->cmsg_type == IP_RECVERR) || 240 cm->cmsg_type == IP_RECVERR) ||
241 (cm->cmsg_level == SOL_IPV6 && 241 (cm->cmsg_level == SOL_IPV6 &&
242 cm->cmsg_type == IPV6_RECVERR) || 242 cm->cmsg_type == IPV6_RECVERR) ||
243 (cm->cmsg_level = SOL_PACKET && 243 (cm->cmsg_level == SOL_PACKET &&
244 cm->cmsg_type == PACKET_TX_TIMESTAMP)) { 244 cm->cmsg_type == PACKET_TX_TIMESTAMP)) {
245 serr = (void *) CMSG_DATA(cm); 245 serr = (void *) CMSG_DATA(cm);
246 if (serr->ee_errno != ENOMSG || 246 if (serr->ee_errno != ENOMSG ||
diff --git a/tools/testing/selftests/proc/.gitignore b/tools/testing/selftests/proc/.gitignore
index 82121a81681f..29bac5ef9a93 100644
--- a/tools/testing/selftests/proc/.gitignore
+++ b/tools/testing/selftests/proc/.gitignore
@@ -10,4 +10,5 @@
10/proc-uptime-002 10/proc-uptime-002
11/read 11/read
12/self 12/self
13/setns-dcache
13/thread-self 14/thread-self
diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftests/proc/Makefile
index 1c12c34cf85d..434d033ee067 100644
--- a/tools/testing/selftests/proc/Makefile
+++ b/tools/testing/selftests/proc/Makefile
@@ -14,6 +14,7 @@ TEST_GEN_PROGS += proc-uptime-001
14TEST_GEN_PROGS += proc-uptime-002 14TEST_GEN_PROGS += proc-uptime-002
15TEST_GEN_PROGS += read 15TEST_GEN_PROGS += read
16TEST_GEN_PROGS += self 16TEST_GEN_PROGS += self
17TEST_GEN_PROGS += setns-dcache
17TEST_GEN_PROGS += thread-self 18TEST_GEN_PROGS += thread-self
18 19
19include ../lib.mk 20include ../lib.mk
diff --git a/tools/testing/selftests/proc/setns-dcache.c b/tools/testing/selftests/proc/setns-dcache.c
new file mode 100644
index 000000000000..60ab197a73fc
--- /dev/null
+++ b/tools/testing/selftests/proc/setns-dcache.c
@@ -0,0 +1,129 @@
1/*
2 * Copyright © 2019 Alexey Dobriyan <adobriyan@gmail.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/*
17 * Test that setns(CLONE_NEWNET) points to new /proc/net content even
18 * if old one is in dcache.
19 *
20 * FIXME /proc/net/unix is under CONFIG_UNIX which can be disabled.
21 */
22#undef NDEBUG
23#include <assert.h>
24#include <errno.h>
25#include <sched.h>
26#include <signal.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <fcntl.h>
34#include <sys/socket.h>
35
36static pid_t pid = -1;
37
38static void f(void)
39{
40 if (pid > 0) {
41 kill(pid, SIGTERM);
42 }
43}
44
45int main(void)
46{
47 int fd[2];
48 char _ = 0;
49 int nsfd;
50
51 atexit(f);
52
53 /* Check for priviledges and syscall availability straight away. */
54 if (unshare(CLONE_NEWNET) == -1) {
55 if (errno == ENOSYS || errno == EPERM) {
56 return 4;
57 }
58 return 1;
59 }
60 /* Distinguisher between two otherwise empty net namespaces. */
61 if (socket(AF_UNIX, SOCK_STREAM, 0) == -1) {
62 return 1;
63 }
64
65 if (pipe(fd) == -1) {
66 return 1;
67 }
68
69 pid = fork();
70 if (pid == -1) {
71 return 1;
72 }
73
74 if (pid == 0) {
75 if (unshare(CLONE_NEWNET) == -1) {
76 return 1;
77 }
78
79 if (write(fd[1], &_, 1) != 1) {
80 return 1;
81 }
82
83 pause();
84
85 return 0;
86 }
87
88 if (read(fd[0], &_, 1) != 1) {
89 return 1;
90 }
91
92 {
93 char buf[64];
94 snprintf(buf, sizeof(buf), "/proc/%u/ns/net", pid);
95 nsfd = open(buf, O_RDONLY);
96 if (nsfd == -1) {
97 return 1;
98 }
99 }
100
101 /* Reliably pin dentry into dcache. */
102 (void)open("/proc/net/unix", O_RDONLY);
103
104 if (setns(nsfd, CLONE_NEWNET) == -1) {
105 return 1;
106 }
107
108 kill(pid, SIGTERM);
109 pid = 0;
110
111 {
112 char buf[4096];
113 ssize_t rv;
114 int fd;
115
116 fd = open("/proc/net/unix", O_RDONLY);
117 if (fd == -1) {
118 return 1;
119 }
120
121#define S "Num RefCount Protocol Flags Type St Inode Path\n"
122 rv = read(fd, buf, sizeof(buf));
123
124 assert(rv == strlen(S));
125 assert(memcmp(buf, S, strlen(S)) == 0);
126 }
127
128 return 0;
129}
diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c
index e20b017e7073..b2065536d407 100644
--- a/tools/testing/selftests/rtc/rtctest.c
+++ b/tools/testing/selftests/rtc/rtctest.c
@@ -145,15 +145,12 @@ TEST_F(rtc, alarm_alm_set) {
145 145
146 rc = select(self->fd + 1, &readfds, NULL, NULL, &tv); 146 rc = select(self->fd + 1, &readfds, NULL, NULL, &tv);
147 ASSERT_NE(-1, rc); 147 ASSERT_NE(-1, rc);
148 EXPECT_NE(0, rc); 148 ASSERT_NE(0, rc);
149 149
150 /* Disable alarm interrupts */ 150 /* Disable alarm interrupts */
151 rc = ioctl(self->fd, RTC_AIE_OFF, 0); 151 rc = ioctl(self->fd, RTC_AIE_OFF, 0);
152 ASSERT_NE(-1, rc); 152 ASSERT_NE(-1, rc);
153 153
154 if (rc == 0)
155 return;
156
157 rc = read(self->fd, &data, sizeof(unsigned long)); 154 rc = read(self->fd, &data, sizeof(unsigned long));
158 ASSERT_NE(-1, rc); 155 ASSERT_NE(-1, rc);
159 TH_LOG("data: %lx", data); 156 TH_LOG("data: %lx", data);
@@ -202,7 +199,109 @@ TEST_F(rtc, alarm_wkalm_set) {
202 199
203 rc = select(self->fd + 1, &readfds, NULL, NULL, &tv); 200 rc = select(self->fd + 1, &readfds, NULL, NULL, &tv);
204 ASSERT_NE(-1, rc); 201 ASSERT_NE(-1, rc);
205 EXPECT_NE(0, rc); 202 ASSERT_NE(0, rc);
203
204 rc = read(self->fd, &data, sizeof(unsigned long));
205 ASSERT_NE(-1, rc);
206
207 rc = ioctl(self->fd, RTC_RD_TIME, &tm);
208 ASSERT_NE(-1, rc);
209
210 new = timegm((struct tm *)&tm);
211 ASSERT_EQ(new, secs);
212}
213
214TEST_F(rtc, alarm_alm_set_minute) {
215 struct timeval tv = { .tv_sec = 62 };
216 unsigned long data;
217 struct rtc_time tm;
218 fd_set readfds;
219 time_t secs, new;
220 int rc;
221
222 rc = ioctl(self->fd, RTC_RD_TIME, &tm);
223 ASSERT_NE(-1, rc);
224
225 secs = timegm((struct tm *)&tm) + 60 - tm.tm_sec;
226 gmtime_r(&secs, (struct tm *)&tm);
227
228 rc = ioctl(self->fd, RTC_ALM_SET, &tm);
229 if (rc == -1) {
230 ASSERT_EQ(EINVAL, errno);
231 TH_LOG("skip alarms are not supported.");
232 return;
233 }
234
235 rc = ioctl(self->fd, RTC_ALM_READ, &tm);
236 ASSERT_NE(-1, rc);
237
238 TH_LOG("Alarm time now set to %02d:%02d:%02d.",
239 tm.tm_hour, tm.tm_min, tm.tm_sec);
240
241 /* Enable alarm interrupts */
242 rc = ioctl(self->fd, RTC_AIE_ON, 0);
243 ASSERT_NE(-1, rc);
244
245 FD_ZERO(&readfds);
246 FD_SET(self->fd, &readfds);
247
248 rc = select(self->fd + 1, &readfds, NULL, NULL, &tv);
249 ASSERT_NE(-1, rc);
250 ASSERT_NE(0, rc);
251
252 /* Disable alarm interrupts */
253 rc = ioctl(self->fd, RTC_AIE_OFF, 0);
254 ASSERT_NE(-1, rc);
255
256 rc = read(self->fd, &data, sizeof(unsigned long));
257 ASSERT_NE(-1, rc);
258 TH_LOG("data: %lx", data);
259
260 rc = ioctl(self->fd, RTC_RD_TIME, &tm);
261 ASSERT_NE(-1, rc);
262
263 new = timegm((struct tm *)&tm);
264 ASSERT_EQ(new, secs);
265}
266
267TEST_F(rtc, alarm_wkalm_set_minute) {
268 struct timeval tv = { .tv_sec = 62 };
269 struct rtc_wkalrm alarm = { 0 };
270 struct rtc_time tm;
271 unsigned long data;
272 fd_set readfds;
273 time_t secs, new;
274 int rc;
275
276 rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time);
277 ASSERT_NE(-1, rc);
278
279 secs = timegm((struct tm *)&alarm.time) + 60 - alarm.time.tm_sec;
280 gmtime_r(&secs, (struct tm *)&alarm.time);
281
282 alarm.enabled = 1;
283
284 rc = ioctl(self->fd, RTC_WKALM_SET, &alarm);
285 if (rc == -1) {
286 ASSERT_EQ(EINVAL, errno);
287 TH_LOG("skip alarms are not supported.");
288 return;
289 }
290
291 rc = ioctl(self->fd, RTC_WKALM_RD, &alarm);
292 ASSERT_NE(-1, rc);
293
294 TH_LOG("Alarm time now set to %02d/%02d/%02d %02d:%02d:%02d.",
295 alarm.time.tm_mday, alarm.time.tm_mon + 1,
296 alarm.time.tm_year + 1900, alarm.time.tm_hour,
297 alarm.time.tm_min, alarm.time.tm_sec);
298
299 FD_ZERO(&readfds);
300 FD_SET(self->fd, &readfds);
301
302 rc = select(self->fd + 1, &readfds, NULL, NULL, &tv);
303 ASSERT_NE(-1, rc);
304 ASSERT_NE(0, rc);
206 305
207 rc = read(self->fd, &data, sizeof(unsigned long)); 306 rc = read(self->fd, &data, sizeof(unsigned long));
208 ASSERT_NE(-1, rc); 307 ASSERT_NE(-1, rc);
diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
index fce7f4ce0692..1760b3e39730 100644
--- a/tools/testing/selftests/seccomp/Makefile
+++ b/tools/testing/selftests/seccomp/Makefile
@@ -9,7 +9,7 @@ BINARIES := seccomp_bpf seccomp_benchmark
9CFLAGS += -Wl,-no-as-needed -Wall 9CFLAGS += -Wl,-no-as-needed -Wall
10 10
11seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h 11seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
12 $(CC) $(CFLAGS) $(LDFLAGS) -lpthread $< -o $@ 12 $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
13 13
14TEST_PROGS += $(BINARIES) 14TEST_PROGS += $(BINARIES)
15EXTRA_CLEAN := $(BINARIES) 15EXTRA_CLEAN := $(BINARIES)
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 067cb4607d6c..7e632b465ab4 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -1608,7 +1608,16 @@ TEST_F(TRACE_poke, getpid_runs_normally)
1608#ifdef SYSCALL_NUM_RET_SHARE_REG 1608#ifdef SYSCALL_NUM_RET_SHARE_REG
1609# define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(-1, action) 1609# define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(-1, action)
1610#else 1610#else
1611# define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(val, action) 1611# define EXPECT_SYSCALL_RETURN(val, action) \
1612 do { \
1613 errno = 0; \
1614 if (val < 0) { \
1615 EXPECT_EQ(-1, action); \
1616 EXPECT_EQ(-(val), errno); \
1617 } else { \
1618 EXPECT_EQ(val, action); \
1619 } \
1620 } while (0)
1612#endif 1621#endif
1613 1622
1614/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for 1623/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for
@@ -1647,7 +1656,7 @@ int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
1647 1656
1648/* Architecture-specific syscall changing routine. */ 1657/* Architecture-specific syscall changing routine. */
1649void change_syscall(struct __test_metadata *_metadata, 1658void change_syscall(struct __test_metadata *_metadata,
1650 pid_t tracee, int syscall) 1659 pid_t tracee, int syscall, int result)
1651{ 1660{
1652 int ret; 1661 int ret;
1653 ARCH_REGS regs; 1662 ARCH_REGS regs;
@@ -1706,7 +1715,7 @@ void change_syscall(struct __test_metadata *_metadata,
1706#ifdef SYSCALL_NUM_RET_SHARE_REG 1715#ifdef SYSCALL_NUM_RET_SHARE_REG
1707 TH_LOG("Can't modify syscall return on this architecture"); 1716 TH_LOG("Can't modify syscall return on this architecture");
1708#else 1717#else
1709 regs.SYSCALL_RET = EPERM; 1718 regs.SYSCALL_RET = result;
1710#endif 1719#endif
1711 1720
1712#ifdef HAVE_GETREGS 1721#ifdef HAVE_GETREGS
@@ -1734,14 +1743,19 @@ void tracer_syscall(struct __test_metadata *_metadata, pid_t tracee,
1734 case 0x1002: 1743 case 0x1002:
1735 /* change getpid to getppid. */ 1744 /* change getpid to getppid. */
1736 EXPECT_EQ(__NR_getpid, get_syscall(_metadata, tracee)); 1745 EXPECT_EQ(__NR_getpid, get_syscall(_metadata, tracee));
1737 change_syscall(_metadata, tracee, __NR_getppid); 1746 change_syscall(_metadata, tracee, __NR_getppid, 0);
1738 break; 1747 break;
1739 case 0x1003: 1748 case 0x1003:
1740 /* skip gettid. */ 1749 /* skip gettid with valid return code. */
1741 EXPECT_EQ(__NR_gettid, get_syscall(_metadata, tracee)); 1750 EXPECT_EQ(__NR_gettid, get_syscall(_metadata, tracee));
1742 change_syscall(_metadata, tracee, -1); 1751 change_syscall(_metadata, tracee, -1, 45000);
1743 break; 1752 break;
1744 case 0x1004: 1753 case 0x1004:
1754 /* skip openat with error. */
1755 EXPECT_EQ(__NR_openat, get_syscall(_metadata, tracee));
1756 change_syscall(_metadata, tracee, -1, -ESRCH);
1757 break;
1758 case 0x1005:
1745 /* do nothing (allow getppid) */ 1759 /* do nothing (allow getppid) */
1746 EXPECT_EQ(__NR_getppid, get_syscall(_metadata, tracee)); 1760 EXPECT_EQ(__NR_getppid, get_syscall(_metadata, tracee));
1747 break; 1761 break;
@@ -1774,9 +1788,11 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
1774 nr = get_syscall(_metadata, tracee); 1788 nr = get_syscall(_metadata, tracee);
1775 1789
1776 if (nr == __NR_getpid) 1790 if (nr == __NR_getpid)
1777 change_syscall(_metadata, tracee, __NR_getppid); 1791 change_syscall(_metadata, tracee, __NR_getppid, 0);
1792 if (nr == __NR_gettid)
1793 change_syscall(_metadata, tracee, -1, 45000);
1778 if (nr == __NR_openat) 1794 if (nr == __NR_openat)
1779 change_syscall(_metadata, tracee, -1); 1795 change_syscall(_metadata, tracee, -1, -ESRCH);
1780} 1796}
1781 1797
1782FIXTURE_DATA(TRACE_syscall) { 1798FIXTURE_DATA(TRACE_syscall) {
@@ -1793,8 +1809,10 @@ FIXTURE_SETUP(TRACE_syscall)
1793 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1002), 1809 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1002),
1794 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_gettid, 0, 1), 1810 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_gettid, 0, 1),
1795 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1003), 1811 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1003),
1796 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getppid, 0, 1), 1812 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_openat, 0, 1),
1797 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1004), 1813 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1004),
1814 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getppid, 0, 1),
1815 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRACE | 0x1005),
1798 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), 1816 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
1799 }; 1817 };
1800 1818
@@ -1842,15 +1860,26 @@ TEST_F(TRACE_syscall, ptrace_syscall_redirected)
1842 EXPECT_NE(self->mypid, syscall(__NR_getpid)); 1860 EXPECT_NE(self->mypid, syscall(__NR_getpid));
1843} 1861}
1844 1862
1845TEST_F(TRACE_syscall, ptrace_syscall_dropped) 1863TEST_F(TRACE_syscall, ptrace_syscall_errno)
1864{
1865 /* Swap SECCOMP_RET_TRACE tracer for PTRACE_SYSCALL tracer. */
1866 teardown_trace_fixture(_metadata, self->tracer);
1867 self->tracer = setup_trace_fixture(_metadata, tracer_ptrace, NULL,
1868 true);
1869
1870 /* Tracer should skip the open syscall, resulting in ESRCH. */
1871 EXPECT_SYSCALL_RETURN(-ESRCH, syscall(__NR_openat));
1872}
1873
1874TEST_F(TRACE_syscall, ptrace_syscall_faked)
1846{ 1875{
1847 /* Swap SECCOMP_RET_TRACE tracer for PTRACE_SYSCALL tracer. */ 1876 /* Swap SECCOMP_RET_TRACE tracer for PTRACE_SYSCALL tracer. */
1848 teardown_trace_fixture(_metadata, self->tracer); 1877 teardown_trace_fixture(_metadata, self->tracer);
1849 self->tracer = setup_trace_fixture(_metadata, tracer_ptrace, NULL, 1878 self->tracer = setup_trace_fixture(_metadata, tracer_ptrace, NULL,
1850 true); 1879 true);
1851 1880
1852 /* Tracer should skip the open syscall, resulting in EPERM. */ 1881 /* Tracer should skip the gettid syscall, resulting fake pid. */
1853 EXPECT_SYSCALL_RETURN(EPERM, syscall(__NR_openat)); 1882 EXPECT_SYSCALL_RETURN(45000, syscall(__NR_gettid));
1854} 1883}
1855 1884
1856TEST_F(TRACE_syscall, syscall_allowed) 1885TEST_F(TRACE_syscall, syscall_allowed)
@@ -1883,7 +1912,21 @@ TEST_F(TRACE_syscall, syscall_redirected)
1883 EXPECT_NE(self->mypid, syscall(__NR_getpid)); 1912 EXPECT_NE(self->mypid, syscall(__NR_getpid));
1884} 1913}
1885 1914
1886TEST_F(TRACE_syscall, syscall_dropped) 1915TEST_F(TRACE_syscall, syscall_errno)
1916{
1917 long ret;
1918
1919 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
1920 ASSERT_EQ(0, ret);
1921
1922 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->prog, 0, 0);
1923 ASSERT_EQ(0, ret);
1924
1925 /* openat has been skipped and an errno return. */
1926 EXPECT_SYSCALL_RETURN(-ESRCH, syscall(__NR_openat));
1927}
1928
1929TEST_F(TRACE_syscall, syscall_faked)
1887{ 1930{
1888 long ret; 1931 long ret;
1889 1932
@@ -1894,8 +1937,7 @@ TEST_F(TRACE_syscall, syscall_dropped)
1894 ASSERT_EQ(0, ret); 1937 ASSERT_EQ(0, ret);
1895 1938
1896 /* gettid has been skipped and an altered return value stored. */ 1939 /* gettid has been skipped and an altered return value stored. */
1897 EXPECT_SYSCALL_RETURN(EPERM, syscall(__NR_gettid)); 1940 EXPECT_SYSCALL_RETURN(45000, syscall(__NR_gettid));
1898 EXPECT_NE(self->mytid, syscall(__NR_gettid));
1899} 1941}
1900 1942
1901TEST_F(TRACE_syscall, skip_after_RET_TRACE) 1943TEST_F(TRACE_syscall, skip_after_RET_TRACE)
@@ -3044,7 +3086,7 @@ TEST(user_notification_basic)
3044 /* Check that the basic notification machinery works */ 3086 /* Check that the basic notification machinery works */
3045 listener = user_trap_syscall(__NR_getpid, 3087 listener = user_trap_syscall(__NR_getpid,
3046 SECCOMP_FILTER_FLAG_NEW_LISTENER); 3088 SECCOMP_FILTER_FLAG_NEW_LISTENER);
3047 EXPECT_GE(listener, 0); 3089 ASSERT_GE(listener, 0);
3048 3090
3049 /* Installing a second listener in the chain should EBUSY */ 3091 /* Installing a second listener in the chain should EBUSY */
3050 EXPECT_EQ(user_trap_syscall(__NR_getpid, 3092 EXPECT_EQ(user_trap_syscall(__NR_getpid,
@@ -3103,7 +3145,7 @@ TEST(user_notification_kill_in_middle)
3103 3145
3104 listener = user_trap_syscall(__NR_getpid, 3146 listener = user_trap_syscall(__NR_getpid,
3105 SECCOMP_FILTER_FLAG_NEW_LISTENER); 3147 SECCOMP_FILTER_FLAG_NEW_LISTENER);
3106 EXPECT_GE(listener, 0); 3148 ASSERT_GE(listener, 0);
3107 3149
3108 /* 3150 /*
3109 * Check that nothing bad happens when we kill the task in the middle 3151 * Check that nothing bad happens when we kill the task in the middle
@@ -3152,7 +3194,7 @@ TEST(user_notification_signal)
3152 3194
3153 listener = user_trap_syscall(__NR_gettid, 3195 listener = user_trap_syscall(__NR_gettid,
3154 SECCOMP_FILTER_FLAG_NEW_LISTENER); 3196 SECCOMP_FILTER_FLAG_NEW_LISTENER);
3155 EXPECT_GE(listener, 0); 3197 ASSERT_GE(listener, 0);
3156 3198
3157 pid = fork(); 3199 pid = fork();
3158 ASSERT_GE(pid, 0); 3200 ASSERT_GE(pid, 0);
@@ -3215,7 +3257,7 @@ TEST(user_notification_closed_listener)
3215 3257
3216 listener = user_trap_syscall(__NR_getpid, 3258 listener = user_trap_syscall(__NR_getpid,
3217 SECCOMP_FILTER_FLAG_NEW_LISTENER); 3259 SECCOMP_FILTER_FLAG_NEW_LISTENER);
3218 EXPECT_GE(listener, 0); 3260 ASSERT_GE(listener, 0);
3219 3261
3220 /* 3262 /*
3221 * Check that we get an ENOSYS when the listener is closed. 3263 * Check that we get an ENOSYS when the listener is closed.
@@ -3376,7 +3418,7 @@ TEST(seccomp_get_notif_sizes)
3376{ 3418{
3377 struct seccomp_notif_sizes sizes; 3419 struct seccomp_notif_sizes sizes;
3378 3420
3379 EXPECT_EQ(seccomp(SECCOMP_GET_NOTIF_SIZES, 0, &sizes), 0); 3421 ASSERT_EQ(seccomp(SECCOMP_GET_NOTIF_SIZES, 0, &sizes), 0);
3380 EXPECT_EQ(sizes.seccomp_notif, sizeof(struct seccomp_notif)); 3422 EXPECT_EQ(sizes.seccomp_notif, sizeof(struct seccomp_notif));
3381 EXPECT_EQ(sizes.seccomp_notif_resp, sizeof(struct seccomp_notif_resp)); 3423 EXPECT_EQ(sizes.seccomp_notif_resp, sizeof(struct seccomp_notif_resp));
3382} 3424}
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json b/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json
index 637ea0219617..0da3545cabdb 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json
@@ -17,7 +17,7 @@
17 "cmdUnderTest": "$TC actions add action ife encode allow mark pass index 2", 17 "cmdUnderTest": "$TC actions add action ife encode allow mark pass index 2",
18 "expExitCode": "0", 18 "expExitCode": "0",
19 "verifyCmd": "$TC actions get action ife index 2", 19 "verifyCmd": "$TC actions get action ife index 2",
20 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*allow mark.*index 2", 20 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*allow mark.*index 2",
21 "matchCount": "1", 21 "matchCount": "1",
22 "teardown": [ 22 "teardown": [
23 "$TC actions flush action ife" 23 "$TC actions flush action ife"
@@ -41,7 +41,7 @@
41 "cmdUnderTest": "$TC actions add action ife encode use mark 10 pipe index 2", 41 "cmdUnderTest": "$TC actions add action ife encode use mark 10 pipe index 2",
42 "expExitCode": "0", 42 "expExitCode": "0",
43 "verifyCmd": "$TC actions get action ife index 2", 43 "verifyCmd": "$TC actions get action ife index 2",
44 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*use mark.*index 2", 44 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*use mark.*index 2",
45 "matchCount": "1", 45 "matchCount": "1",
46 "teardown": [ 46 "teardown": [
47 "$TC actions flush action ife" 47 "$TC actions flush action ife"
@@ -65,7 +65,7 @@
65 "cmdUnderTest": "$TC actions add action ife encode allow mark continue index 2", 65 "cmdUnderTest": "$TC actions add action ife encode allow mark continue index 2",
66 "expExitCode": "0", 66 "expExitCode": "0",
67 "verifyCmd": "$TC actions get action ife index 2", 67 "verifyCmd": "$TC actions get action ife index 2",
68 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0xED3E.*allow mark.*index 2", 68 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0[xX]ED3E.*allow mark.*index 2",
69 "matchCount": "1", 69 "matchCount": "1",
70 "teardown": [ 70 "teardown": [
71 "$TC actions flush action ife" 71 "$TC actions flush action ife"
@@ -89,7 +89,7 @@
89 "cmdUnderTest": "$TC actions add action ife encode use mark 789 drop index 2", 89 "cmdUnderTest": "$TC actions add action ife encode use mark 789 drop index 2",
90 "expExitCode": "0", 90 "expExitCode": "0",
91 "verifyCmd": "$TC actions get action ife index 2", 91 "verifyCmd": "$TC actions get action ife index 2",
92 "matchPattern": "action order [0-9]*: ife encode action drop.*type 0xED3E.*use mark 789.*index 2", 92 "matchPattern": "action order [0-9]*: ife encode action drop.*type 0[xX]ED3E.*use mark 789.*index 2",
93 "matchCount": "1", 93 "matchCount": "1",
94 "teardown": [ 94 "teardown": [
95 "$TC actions flush action ife" 95 "$TC actions flush action ife"
@@ -113,7 +113,7 @@
113 "cmdUnderTest": "$TC actions add action ife encode use mark 656768 reclassify index 2", 113 "cmdUnderTest": "$TC actions add action ife encode use mark 656768 reclassify index 2",
114 "expExitCode": "0", 114 "expExitCode": "0",
115 "verifyCmd": "$TC actions get action ife index 2", 115 "verifyCmd": "$TC actions get action ife index 2",
116 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xED3E.*use mark 656768.*index 2", 116 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ED3E.*use mark 656768.*index 2",
117 "matchCount": "1", 117 "matchCount": "1",
118 "teardown": [ 118 "teardown": [
119 "$TC actions flush action ife" 119 "$TC actions flush action ife"
@@ -137,7 +137,7 @@
137 "cmdUnderTest": "$TC actions add action ife encode use mark 65 jump 1 index 2", 137 "cmdUnderTest": "$TC actions add action ife encode use mark 65 jump 1 index 2",
138 "expExitCode": "0", 138 "expExitCode": "0",
139 "verifyCmd": "$TC actions get action ife index 2", 139 "verifyCmd": "$TC actions get action ife index 2",
140 "matchPattern": "action order [0-9]*: ife encode action jump 1.*type 0xED3E.*use mark 65.*index 2", 140 "matchPattern": "action order [0-9]*: ife encode action jump 1.*type 0[xX]ED3E.*use mark 65.*index 2",
141 "matchCount": "1", 141 "matchCount": "1",
142 "teardown": [ 142 "teardown": [
143 "$TC actions flush action ife" 143 "$TC actions flush action ife"
@@ -161,7 +161,7 @@
161 "cmdUnderTest": "$TC actions add action ife encode use mark 4294967295 reclassify index 90", 161 "cmdUnderTest": "$TC actions add action ife encode use mark 4294967295 reclassify index 90",
162 "expExitCode": "0", 162 "expExitCode": "0",
163 "verifyCmd": "$TC actions get action ife index 90", 163 "verifyCmd": "$TC actions get action ife index 90",
164 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xED3E.*use mark 4294967295.*index 90", 164 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ED3E.*use mark 4294967295.*index 90",
165 "matchCount": "1", 165 "matchCount": "1",
166 "teardown": [ 166 "teardown": [
167 "$TC actions flush action ife" 167 "$TC actions flush action ife"
@@ -185,7 +185,7 @@
185 "cmdUnderTest": "$TC actions add action ife encode use mark 4294967295999 pipe index 90", 185 "cmdUnderTest": "$TC actions add action ife encode use mark 4294967295999 pipe index 90",
186 "expExitCode": "255", 186 "expExitCode": "255",
187 "verifyCmd": "$TC actions get action ife index 90", 187 "verifyCmd": "$TC actions get action ife index 90",
188 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*use mark 4294967295999.*index 90", 188 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*use mark 4294967295999.*index 90",
189 "matchCount": "0", 189 "matchCount": "0",
190 "teardown": [] 190 "teardown": []
191 }, 191 },
@@ -207,7 +207,7 @@
207 "cmdUnderTest": "$TC actions add action ife encode allow prio pass index 9", 207 "cmdUnderTest": "$TC actions add action ife encode allow prio pass index 9",
208 "expExitCode": "0", 208 "expExitCode": "0",
209 "verifyCmd": "$TC actions get action ife index 9", 209 "verifyCmd": "$TC actions get action ife index 9",
210 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*allow prio.*index 9", 210 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*allow prio.*index 9",
211 "matchCount": "1", 211 "matchCount": "1",
212 "teardown": [ 212 "teardown": [
213 "$TC actions flush action ife" 213 "$TC actions flush action ife"
@@ -231,7 +231,7 @@
231 "cmdUnderTest": "$TC actions add action ife encode use prio 7 pipe index 9", 231 "cmdUnderTest": "$TC actions add action ife encode use prio 7 pipe index 9",
232 "expExitCode": "0", 232 "expExitCode": "0",
233 "verifyCmd": "$TC actions get action ife index 9", 233 "verifyCmd": "$TC actions get action ife index 9",
234 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*use prio 7.*index 9", 234 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*use prio 7.*index 9",
235 "matchCount": "1", 235 "matchCount": "1",
236 "teardown": [ 236 "teardown": [
237 "$TC actions flush action ife" 237 "$TC actions flush action ife"
@@ -255,7 +255,7 @@
255 "cmdUnderTest": "$TC actions add action ife encode use prio 3 continue index 9", 255 "cmdUnderTest": "$TC actions add action ife encode use prio 3 continue index 9",
256 "expExitCode": "0", 256 "expExitCode": "0",
257 "verifyCmd": "$TC actions get action ife index 9", 257 "verifyCmd": "$TC actions get action ife index 9",
258 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0xED3E.*use prio 3.*index 9", 258 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0[xX]ED3E.*use prio 3.*index 9",
259 "matchCount": "1", 259 "matchCount": "1",
260 "teardown": [ 260 "teardown": [
261 "$TC actions flush action ife" 261 "$TC actions flush action ife"
@@ -279,7 +279,7 @@
279 "cmdUnderTest": "$TC actions add action ife encode allow prio drop index 9", 279 "cmdUnderTest": "$TC actions add action ife encode allow prio drop index 9",
280 "expExitCode": "0", 280 "expExitCode": "0",
281 "verifyCmd": "$TC actions get action ife index 9", 281 "verifyCmd": "$TC actions get action ife index 9",
282 "matchPattern": "action order [0-9]*: ife encode action drop.*type 0xED3E.*allow prio.*index 9", 282 "matchPattern": "action order [0-9]*: ife encode action drop.*type 0[xX]ED3E.*allow prio.*index 9",
283 "matchCount": "1", 283 "matchCount": "1",
284 "teardown": [ 284 "teardown": [
285 "$TC actions flush action ife" 285 "$TC actions flush action ife"
@@ -303,7 +303,7 @@
303 "cmdUnderTest": "$TC actions add action ife encode use prio 998877 reclassify index 9", 303 "cmdUnderTest": "$TC actions add action ife encode use prio 998877 reclassify index 9",
304 "expExitCode": "0", 304 "expExitCode": "0",
305 "verifyCmd": "$TC actions get action ife index 9", 305 "verifyCmd": "$TC actions get action ife index 9",
306 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xED3E.*use prio 998877.*index 9", 306 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ED3E.*use prio 998877.*index 9",
307 "matchCount": "1", 307 "matchCount": "1",
308 "teardown": [ 308 "teardown": [
309 "$TC actions flush action ife" 309 "$TC actions flush action ife"
@@ -327,7 +327,7 @@
327 "cmdUnderTest": "$TC actions add action ife encode use prio 998877 jump 10 index 9", 327 "cmdUnderTest": "$TC actions add action ife encode use prio 998877 jump 10 index 9",
328 "expExitCode": "0", 328 "expExitCode": "0",
329 "verifyCmd": "$TC actions get action ife index 9", 329 "verifyCmd": "$TC actions get action ife index 9",
330 "matchPattern": "action order [0-9]*: ife encode action jump 10.*type 0xED3E.*use prio 998877.*index 9", 330 "matchPattern": "action order [0-9]*: ife encode action jump 10.*type 0[xX]ED3E.*use prio 998877.*index 9",
331 "matchCount": "1", 331 "matchCount": "1",
332 "teardown": [ 332 "teardown": [
333 "$TC actions flush action ife" 333 "$TC actions flush action ife"
@@ -351,7 +351,7 @@
351 "cmdUnderTest": "$TC actions add action ife encode use prio 4294967295 reclassify index 99", 351 "cmdUnderTest": "$TC actions add action ife encode use prio 4294967295 reclassify index 99",
352 "expExitCode": "0", 352 "expExitCode": "0",
353 "verifyCmd": "$TC actions get action ife index 99", 353 "verifyCmd": "$TC actions get action ife index 99",
354 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xED3E.*use prio 4294967295.*index 99", 354 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ED3E.*use prio 4294967295.*index 99",
355 "matchCount": "1", 355 "matchCount": "1",
356 "teardown": [ 356 "teardown": [
357 "$TC actions flush action ife" 357 "$TC actions flush action ife"
@@ -375,7 +375,7 @@
375 "cmdUnderTest": "$TC actions add action ife encode use prio 4294967298 pipe index 99", 375 "cmdUnderTest": "$TC actions add action ife encode use prio 4294967298 pipe index 99",
376 "expExitCode": "255", 376 "expExitCode": "255",
377 "verifyCmd": "$TC actions get action ife index 99", 377 "verifyCmd": "$TC actions get action ife index 99",
378 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*use prio 4294967298.*index 99", 378 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*use prio 4294967298.*index 99",
379 "matchCount": "0", 379 "matchCount": "0",
380 "teardown": [] 380 "teardown": []
381 }, 381 },
@@ -397,7 +397,7 @@
397 "cmdUnderTest": "$TC actions add action ife encode allow tcindex pass index 1", 397 "cmdUnderTest": "$TC actions add action ife encode allow tcindex pass index 1",
398 "expExitCode": "0", 398 "expExitCode": "0",
399 "verifyCmd": "$TC actions get action ife index 1", 399 "verifyCmd": "$TC actions get action ife index 1",
400 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*allow tcindex.*index 1", 400 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*allow tcindex.*index 1",
401 "matchCount": "1", 401 "matchCount": "1",
402 "teardown": [ 402 "teardown": [
403 "$TC actions flush action ife" 403 "$TC actions flush action ife"
@@ -421,7 +421,7 @@
421 "cmdUnderTest": "$TC actions add action ife encode use tcindex 111 pipe index 1", 421 "cmdUnderTest": "$TC actions add action ife encode use tcindex 111 pipe index 1",
422 "expExitCode": "0", 422 "expExitCode": "0",
423 "verifyCmd": "$TC actions get action ife index 1", 423 "verifyCmd": "$TC actions get action ife index 1",
424 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*use tcindex 111.*index 1", 424 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*use tcindex 111.*index 1",
425 "matchCount": "1", 425 "matchCount": "1",
426 "teardown": [ 426 "teardown": [
427 "$TC actions flush action ife" 427 "$TC actions flush action ife"
@@ -445,7 +445,7 @@
445 "cmdUnderTest": "$TC actions add action ife encode use tcindex 1 continue index 1", 445 "cmdUnderTest": "$TC actions add action ife encode use tcindex 1 continue index 1",
446 "expExitCode": "0", 446 "expExitCode": "0",
447 "verifyCmd": "$TC actions get action ife index 1", 447 "verifyCmd": "$TC actions get action ife index 1",
448 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0xED3E.*use tcindex 1.*index 1", 448 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0[xX]ED3E.*use tcindex 1.*index 1",
449 "matchCount": "1", 449 "matchCount": "1",
450 "teardown": [ 450 "teardown": [
451 "$TC actions flush action ife" 451 "$TC actions flush action ife"
@@ -469,7 +469,7 @@
469 "cmdUnderTest": "$TC actions add action ife encode use tcindex 1 continue index 1", 469 "cmdUnderTest": "$TC actions add action ife encode use tcindex 1 continue index 1",
470 "expExitCode": "0", 470 "expExitCode": "0",
471 "verifyCmd": "$TC actions get action ife index 1", 471 "verifyCmd": "$TC actions get action ife index 1",
472 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0xED3E.*use tcindex 1.*index 1", 472 "matchPattern": "action order [0-9]*: ife encode action continue.*type 0[xX]ED3E.*use tcindex 1.*index 1",
473 "matchCount": "1", 473 "matchCount": "1",
474 "teardown": [ 474 "teardown": [
475 "$TC actions flush action ife" 475 "$TC actions flush action ife"
@@ -493,7 +493,7 @@
493 "cmdUnderTest": "$TC actions add action ife encode allow tcindex drop index 77", 493 "cmdUnderTest": "$TC actions add action ife encode allow tcindex drop index 77",
494 "expExitCode": "0", 494 "expExitCode": "0",
495 "verifyCmd": "$TC actions get action ife index 77", 495 "verifyCmd": "$TC actions get action ife index 77",
496 "matchPattern": "action order [0-9]*: ife encode action drop.*type 0xED3E.*allow tcindex.*index 77", 496 "matchPattern": "action order [0-9]*: ife encode action drop.*type 0[xX]ED3E.*allow tcindex.*index 77",
497 "matchCount": "1", 497 "matchCount": "1",
498 "teardown": [ 498 "teardown": [
499 "$TC actions flush action ife" 499 "$TC actions flush action ife"
@@ -517,7 +517,7 @@
517 "cmdUnderTest": "$TC actions add action ife encode allow tcindex reclassify index 77", 517 "cmdUnderTest": "$TC actions add action ife encode allow tcindex reclassify index 77",
518 "expExitCode": "0", 518 "expExitCode": "0",
519 "verifyCmd": "$TC actions get action ife index 77", 519 "verifyCmd": "$TC actions get action ife index 77",
520 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xED3E.*allow tcindex.*index 77", 520 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ED3E.*allow tcindex.*index 77",
521 "matchCount": "1", 521 "matchCount": "1",
522 "teardown": [ 522 "teardown": [
523 "$TC actions flush action ife" 523 "$TC actions flush action ife"
@@ -541,7 +541,7 @@
541 "cmdUnderTest": "$TC actions add action ife encode allow tcindex jump 999 index 77", 541 "cmdUnderTest": "$TC actions add action ife encode allow tcindex jump 999 index 77",
542 "expExitCode": "0", 542 "expExitCode": "0",
543 "verifyCmd": "$TC actions get action ife index 77", 543 "verifyCmd": "$TC actions get action ife index 77",
544 "matchPattern": "action order [0-9]*: ife encode action jump 999.*type 0xED3E.*allow tcindex.*index 77", 544 "matchPattern": "action order [0-9]*: ife encode action jump 999.*type 0[xX]ED3E.*allow tcindex.*index 77",
545 "matchCount": "1", 545 "matchCount": "1",
546 "teardown": [ 546 "teardown": [
547 "$TC actions flush action ife" 547 "$TC actions flush action ife"
@@ -565,7 +565,7 @@
565 "cmdUnderTest": "$TC actions add action ife encode use tcindex 65535 pass index 1", 565 "cmdUnderTest": "$TC actions add action ife encode use tcindex 65535 pass index 1",
566 "expExitCode": "0", 566 "expExitCode": "0",
567 "verifyCmd": "$TC actions get action ife index 1", 567 "verifyCmd": "$TC actions get action ife index 1",
568 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*use tcindex 65535.*index 1", 568 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*use tcindex 65535.*index 1",
569 "matchCount": "1", 569 "matchCount": "1",
570 "teardown": [ 570 "teardown": [
571 "$TC actions flush action ife" 571 "$TC actions flush action ife"
@@ -589,7 +589,7 @@
589 "cmdUnderTest": "$TC actions add action ife encode use tcindex 65539 pipe index 1", 589 "cmdUnderTest": "$TC actions add action ife encode use tcindex 65539 pipe index 1",
590 "expExitCode": "255", 590 "expExitCode": "255",
591 "verifyCmd": "$TC actions get action ife index 1", 591 "verifyCmd": "$TC actions get action ife index 1",
592 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*use tcindex 65539.*index 1", 592 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*use tcindex 65539.*index 1",
593 "matchCount": "0", 593 "matchCount": "0",
594 "teardown": [] 594 "teardown": []
595 }, 595 },
@@ -611,7 +611,7 @@
611 "cmdUnderTest": "$TC actions add action ife encode allow mark src 00:11:22:33:44:55 pipe index 1", 611 "cmdUnderTest": "$TC actions add action ife encode allow mark src 00:11:22:33:44:55 pipe index 1",
612 "expExitCode": "0", 612 "expExitCode": "0",
613 "verifyCmd": "$TC actions get action ife index 1", 613 "verifyCmd": "$TC actions get action ife index 1",
614 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*allow mark src 00:11:22:33:44:55.*index 1", 614 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*allow mark src 00:11:22:33:44:55.*index 1",
615 "matchCount": "1", 615 "matchCount": "1",
616 "teardown": [ 616 "teardown": [
617 "$TC actions flush action ife" 617 "$TC actions flush action ife"
@@ -635,7 +635,7 @@
635 "cmdUnderTest": "$TC actions add action ife encode use prio 9876 dst 00:11:22:33:44:55 reclassify index 1", 635 "cmdUnderTest": "$TC actions add action ife encode use prio 9876 dst 00:11:22:33:44:55 reclassify index 1",
636 "expExitCode": "0", 636 "expExitCode": "0",
637 "verifyCmd": "$TC actions get action ife index 1", 637 "verifyCmd": "$TC actions get action ife index 1",
638 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xED3E.*use prio 9876 dst 00:11:22:33:44:55.*index 1", 638 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ED3E.*use prio 9876 dst 00:11:22:33:44:55.*index 1",
639 "matchCount": "1", 639 "matchCount": "1",
640 "teardown": [ 640 "teardown": [
641 "$TC actions flush action ife" 641 "$TC actions flush action ife"
@@ -659,7 +659,7 @@
659 "cmdUnderTest": "$TC actions add action ife encode allow tcindex src 00:aa:bb:cc:dd:ee dst 00:11:22:33:44:55 pass index 11", 659 "cmdUnderTest": "$TC actions add action ife encode allow tcindex src 00:aa:bb:cc:dd:ee dst 00:11:22:33:44:55 pass index 11",
660 "expExitCode": "0", 660 "expExitCode": "0",
661 "verifyCmd": "$TC actions get action ife index 11", 661 "verifyCmd": "$TC actions get action ife index 11",
662 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*allow tcindex dst 00:11:22:33:44:55 src 00:aa:bb:cc:dd:ee .*index 11", 662 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*allow tcindex dst 00:11:22:33:44:55 src 00:aa:bb:cc:dd:ee .*index 11",
663 "matchCount": "1", 663 "matchCount": "1",
664 "teardown": [ 664 "teardown": [
665 "$TC actions flush action ife" 665 "$TC actions flush action ife"
@@ -683,7 +683,7 @@
683 "cmdUnderTest": "$TC actions add action ife encode use mark 7 type 0xfefe pass index 1", 683 "cmdUnderTest": "$TC actions add action ife encode use mark 7 type 0xfefe pass index 1",
684 "expExitCode": "0", 684 "expExitCode": "0",
685 "verifyCmd": "$TC actions get action ife index 1", 685 "verifyCmd": "$TC actions get action ife index 1",
686 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xFEFE.*use mark 7.*index 1", 686 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]FEFE.*use mark 7.*index 1",
687 "matchCount": "1", 687 "matchCount": "1",
688 "teardown": [ 688 "teardown": [
689 "$TC actions flush action ife" 689 "$TC actions flush action ife"
@@ -707,7 +707,7 @@
707 "cmdUnderTest": "$TC actions add action ife encode use prio 444 type 0xabba pipe index 21", 707 "cmdUnderTest": "$TC actions add action ife encode use prio 444 type 0xabba pipe index 21",
708 "expExitCode": "0", 708 "expExitCode": "0",
709 "verifyCmd": "$TC actions get action ife index 21", 709 "verifyCmd": "$TC actions get action ife index 21",
710 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xABBA.*use prio 444.*index 21", 710 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ABBA.*use prio 444.*index 21",
711 "matchCount": "1", 711 "matchCount": "1",
712 "teardown": [ 712 "teardown": [
713 "$TC actions flush action ife" 713 "$TC actions flush action ife"
@@ -731,7 +731,7 @@
731 "cmdUnderTest": "$TC actions add action ife encode use tcindex 5000 type 0xabcd reclassify index 21", 731 "cmdUnderTest": "$TC actions add action ife encode use tcindex 5000 type 0xabcd reclassify index 21",
732 "expExitCode": "0", 732 "expExitCode": "0",
733 "verifyCmd": "$TC actions get action ife index 21", 733 "verifyCmd": "$TC actions get action ife index 21",
734 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0xABCD.*use tcindex 5000.*index 21", 734 "matchPattern": "action order [0-9]*: ife encode action reclassify.*type 0[xX]ABCD.*use tcindex 5000.*index 21",
735 "matchCount": "1", 735 "matchCount": "1",
736 "teardown": [ 736 "teardown": [
737 "$TC actions flush action ife" 737 "$TC actions flush action ife"
@@ -739,7 +739,7 @@
739 }, 739 },
740 { 740 {
741 "id": "fac3", 741 "id": "fac3",
742 "name": "Create valid ife encode action with index at 32-bit maximnum", 742 "name": "Create valid ife encode action with index at 32-bit maximum",
743 "category": [ 743 "category": [
744 "actions", 744 "actions",
745 "ife" 745 "ife"
@@ -755,7 +755,7 @@
755 "cmdUnderTest": "$TC actions add action ife encode allow mark pass index 4294967295", 755 "cmdUnderTest": "$TC actions add action ife encode allow mark pass index 4294967295",
756 "expExitCode": "0", 756 "expExitCode": "0",
757 "verifyCmd": "$TC actions get action ife index 4294967295", 757 "verifyCmd": "$TC actions get action ife index 4294967295",
758 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*allow mark.*index 4294967295", 758 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*allow mark.*index 4294967295",
759 "matchCount": "1", 759 "matchCount": "1",
760 "teardown": [ 760 "teardown": [
761 "$TC actions flush action ife" 761 "$TC actions flush action ife"
@@ -779,7 +779,7 @@
779 "cmdUnderTest": "$TC actions add action ife decode pass index 1", 779 "cmdUnderTest": "$TC actions add action ife decode pass index 1",
780 "expExitCode": "0", 780 "expExitCode": "0",
781 "verifyCmd": "$TC actions get action ife index 1", 781 "verifyCmd": "$TC actions get action ife index 1",
782 "matchPattern": "action order [0-9]*: ife decode action pass.*type 0x0.*allow mark allow tcindex allow prio.*index 1", 782 "matchPattern": "action order [0-9]*: ife decode action pass.*type 0(x0)?.*allow mark allow tcindex allow prio.*index 1",
783 "matchCount": "1", 783 "matchCount": "1",
784 "teardown": [ 784 "teardown": [
785 "$TC actions flush action ife" 785 "$TC actions flush action ife"
@@ -803,7 +803,7 @@
803 "cmdUnderTest": "$TC actions add action ife decode pipe index 1", 803 "cmdUnderTest": "$TC actions add action ife decode pipe index 1",
804 "expExitCode": "0", 804 "expExitCode": "0",
805 "verifyCmd": "$TC actions get action ife index 1", 805 "verifyCmd": "$TC actions get action ife index 1",
806 "matchPattern": "action order [0-9]*: ife decode action pipe.*type 0x0.*allow mark allow tcindex allow prio.*index 1", 806 "matchPattern": "action order [0-9]*: ife decode action pipe.*type 0(x0)?.*allow mark allow tcindex allow prio.*index 1",
807 "matchCount": "1", 807 "matchCount": "1",
808 "teardown": [ 808 "teardown": [
809 "$TC actions flush action ife" 809 "$TC actions flush action ife"
@@ -827,7 +827,7 @@
827 "cmdUnderTest": "$TC actions add action ife decode continue index 1", 827 "cmdUnderTest": "$TC actions add action ife decode continue index 1",
828 "expExitCode": "0", 828 "expExitCode": "0",
829 "verifyCmd": "$TC actions get action ife index 1", 829 "verifyCmd": "$TC actions get action ife index 1",
830 "matchPattern": "action order [0-9]*: ife decode action continue.*type 0x0.*allow mark allow tcindex allow prio.*index 1", 830 "matchPattern": "action order [0-9]*: ife decode action continue.*type 0(x0)?.*allow mark allow tcindex allow prio.*index 1",
831 "matchCount": "1", 831 "matchCount": "1",
832 "teardown": [ 832 "teardown": [
833 "$TC actions flush action ife" 833 "$TC actions flush action ife"
@@ -851,7 +851,7 @@
851 "cmdUnderTest": "$TC actions add action ife decode drop index 1", 851 "cmdUnderTest": "$TC actions add action ife decode drop index 1",
852 "expExitCode": "0", 852 "expExitCode": "0",
853 "verifyCmd": "$TC actions get action ife index 1", 853 "verifyCmd": "$TC actions get action ife index 1",
854 "matchPattern": "action order [0-9]*: ife decode action drop.*type 0x0.*allow mark allow tcindex allow prio.*index 1", 854 "matchPattern": "action order [0-9]*: ife decode action drop.*type 0(x0)?.*allow mark allow tcindex allow prio.*index 1",
855 "matchCount": "1", 855 "matchCount": "1",
856 "teardown": [ 856 "teardown": [
857 "$TC actions flush action ife" 857 "$TC actions flush action ife"
@@ -875,7 +875,7 @@
875 "cmdUnderTest": "$TC actions add action ife decode reclassify index 1", 875 "cmdUnderTest": "$TC actions add action ife decode reclassify index 1",
876 "expExitCode": "0", 876 "expExitCode": "0",
877 "verifyCmd": "$TC actions get action ife index 1", 877 "verifyCmd": "$TC actions get action ife index 1",
878 "matchPattern": "action order [0-9]*: ife decode action reclassify.*type 0x0.*allow mark allow tcindex allow prio.*index 1", 878 "matchPattern": "action order [0-9]*: ife decode action reclassify.*type 0(x0)?.*allow mark allow tcindex allow prio.*index 1",
879 "matchCount": "1", 879 "matchCount": "1",
880 "teardown": [ 880 "teardown": [
881 "$TC actions flush action ife" 881 "$TC actions flush action ife"
@@ -899,7 +899,7 @@
899 "cmdUnderTest": "$TC actions add action ife decode jump 10 index 1", 899 "cmdUnderTest": "$TC actions add action ife decode jump 10 index 1",
900 "expExitCode": "0", 900 "expExitCode": "0",
901 "verifyCmd": "$TC actions get action ife index 1", 901 "verifyCmd": "$TC actions get action ife index 1",
902 "matchPattern": "action order [0-9]*: ife decode action jump 10.*type 0x0.*allow mark allow tcindex allow prio.*index 1", 902 "matchPattern": "action order [0-9]*: ife decode action jump 10.*type 0(x0)?.*allow mark allow tcindex allow prio.*index 1",
903 "matchCount": "1", 903 "matchCount": "1",
904 "teardown": [ 904 "teardown": [
905 "$TC actions flush action ife" 905 "$TC actions flush action ife"
@@ -923,7 +923,7 @@
923 "cmdUnderTest": "$TC actions add action ife encode allow mark pass index 4294967295999", 923 "cmdUnderTest": "$TC actions add action ife encode allow mark pass index 4294967295999",
924 "expExitCode": "255", 924 "expExitCode": "255",
925 "verifyCmd": "$TC actions get action ife index 4294967295999", 925 "verifyCmd": "$TC actions get action ife index 4294967295999",
926 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0xED3E.*allow mark.*index 4294967295999", 926 "matchPattern": "action order [0-9]*: ife encode action pass.*type 0[xX]ED3E.*allow mark.*index 4294967295999",
927 "matchCount": "0", 927 "matchCount": "0",
928 "teardown": [] 928 "teardown": []
929 }, 929 },
@@ -945,7 +945,7 @@
945 "cmdUnderTest": "$TC actions add action ife encode allow mark kuka index 4", 945 "cmdUnderTest": "$TC actions add action ife encode allow mark kuka index 4",
946 "expExitCode": "255", 946 "expExitCode": "255",
947 "verifyCmd": "$TC actions get action ife index 4", 947 "verifyCmd": "$TC actions get action ife index 4",
948 "matchPattern": "action order [0-9]*: ife encode action kuka.*type 0xED3E.*allow mark.*index 4", 948 "matchPattern": "action order [0-9]*: ife encode action kuka.*type 0[xX]ED3E.*allow mark.*index 4",
949 "matchCount": "0", 949 "matchCount": "0",
950 "teardown": [] 950 "teardown": []
951 }, 951 },
@@ -967,7 +967,7 @@
967 "cmdUnderTest": "$TC actions add action ife encode allow prio pipe index 4 cookie aabbccddeeff112233445566778800a1", 967 "cmdUnderTest": "$TC actions add action ife encode allow prio pipe index 4 cookie aabbccddeeff112233445566778800a1",
968 "expExitCode": "0", 968 "expExitCode": "0",
969 "verifyCmd": "$TC actions get action ife index 4", 969 "verifyCmd": "$TC actions get action ife index 4",
970 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*allow prio.*index 4.*cookie aabbccddeeff112233445566778800a1", 970 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*allow prio.*index 4.*cookie aabbccddeeff112233445566778800a1",
971 "matchCount": "1", 971 "matchCount": "1",
972 "teardown": [ 972 "teardown": [
973 "$TC actions flush action ife" 973 "$TC actions flush action ife"
@@ -991,7 +991,7 @@
991 "cmdUnderTest": "$TC actions add action ife encode allow foo pipe index 4", 991 "cmdUnderTest": "$TC actions add action ife encode allow foo pipe index 4",
992 "expExitCode": "255", 992 "expExitCode": "255",
993 "verifyCmd": "$TC actions get action ife index 4", 993 "verifyCmd": "$TC actions get action ife index 4",
994 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0xED3E.*allow foo.*index 4", 994 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]ED3E.*allow foo.*index 4",
995 "matchCount": "0", 995 "matchCount": "0",
996 "teardown": [] 996 "teardown": []
997 }, 997 },
@@ -1013,7 +1013,7 @@
1013 "cmdUnderTest": "$TC actions add action ife encode allow prio type 70000 pipe index 4", 1013 "cmdUnderTest": "$TC actions add action ife encode allow prio type 70000 pipe index 4",
1014 "expExitCode": "255", 1014 "expExitCode": "255",
1015 "verifyCmd": "$TC actions get action ife index 4", 1015 "verifyCmd": "$TC actions get action ife index 4",
1016 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0x11170.*allow prio.*index 4", 1016 "matchPattern": "action order [0-9]*: ife encode action pipe.*type 0[xX]11170.*allow prio.*index 4",
1017 "matchCount": "0", 1017 "matchCount": "0",
1018 "teardown": [] 1018 "teardown": []
1019 }, 1019 },
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json b/tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json
index 10b2d894e436..e7e15a7336b6 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json
@@ -82,35 +82,6 @@
82 ] 82 ]
83 }, 83 },
84 { 84 {
85 "id": "ba4e",
86 "name": "Add tunnel_key set action with missing mandatory id parameter",
87 "category": [
88 "actions",
89 "tunnel_key"
90 ],
91 "setup": [
92 [
93 "$TC actions flush action tunnel_key",
94 0,
95 1,
96 255
97 ]
98 ],
99 "cmdUnderTest": "$TC actions add action tunnel_key set src_ip 10.10.10.1 dst_ip 20.20.20.2",
100 "expExitCode": "255",
101 "verifyCmd": "$TC actions list action tunnel_key",
102 "matchPattern": "action order [0-9]+: tunnel_key set.*src_ip 10.10.10.1.*dst_ip 20.20.20.2",
103 "matchCount": "0",
104 "teardown": [
105 [
106 "$TC actions flush action tunnel_key",
107 0,
108 1,
109 255
110 ]
111 ]
112 },
113 {
114 "id": "a5e0", 85 "id": "a5e0",
115 "name": "Add tunnel_key set action with invalid src_ip parameter", 86 "name": "Add tunnel_key set action with invalid src_ip parameter",
116 "category": [ 87 "category": [
@@ -634,7 +605,7 @@
634 "cmdUnderTest": "$TC actions add action tunnel_key set src_ip 10.10.10.1 dst_ip 10.10.10.2 id 7 index 4 cookie aa11bb22cc33dd44ee55ff66aa11b1b2", 605 "cmdUnderTest": "$TC actions add action tunnel_key set src_ip 10.10.10.1 dst_ip 10.10.10.2 id 7 index 4 cookie aa11bb22cc33dd44ee55ff66aa11b1b2",
635 "expExitCode": "0", 606 "expExitCode": "0",
636 "verifyCmd": "$TC actions get action tunnel_key index 4", 607 "verifyCmd": "$TC actions get action tunnel_key index 4",
637 "matchPattern": "action order [0-9]+: tunnel_key.*set.*src_ip 10.10.10.1.*dst_ip 10.10.10.2.*key_id 7.*dst_port 0.*csum pipe.*index 4 ref.*cookie aa11bb22cc33dd44ee55ff66aa11b1b2", 608 "matchPattern": "action order [0-9]+: tunnel_key.*set.*src_ip 10.10.10.1.*dst_ip 10.10.10.2.*key_id 7.*csum pipe.*index 4 ref.*cookie aa11bb22cc33dd44ee55ff66aa11b1b2",
638 "matchCount": "1", 609 "matchCount": "1",
639 "teardown": [ 610 "teardown": [
640 "$TC actions flush action tunnel_key" 611 "$TC actions flush action tunnel_key"
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index c02683cfb6c9..7656c7ce79d9 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -1,6 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2CFLAGS += -O3 -Wl,-no-as-needed -Wall 2CFLAGS += -O3 -Wl,-no-as-needed -Wall
3LDFLAGS += -lrt -lpthread -lm 3LDLIBS += -lrt -lpthread -lm
4 4
5# these are all "safe" tests that don't modify 5# these are all "safe" tests that don't modify
6# system time or require escalated privileges 6# system time or require escalated privileges
diff --git a/tools/testing/selftests/vm/gup_benchmark.c b/tools/testing/selftests/vm/gup_benchmark.c
index 880b96fc80d4..c0534e298b51 100644
--- a/tools/testing/selftests/vm/gup_benchmark.c
+++ b/tools/testing/selftests/vm/gup_benchmark.c
@@ -25,6 +25,7 @@ struct gup_benchmark {
25 __u64 size; 25 __u64 size;
26 __u32 nr_pages_per_call; 26 __u32 nr_pages_per_call;
27 __u32 flags; 27 __u32 flags;
28 __u64 expansion[10]; /* For future use */
28}; 29};
29 30
30int main(int argc, char **argv) 31int main(int argc, char **argv)
diff --git a/tools/testing/selftests/x86/mpx-mini-test.c b/tools/testing/selftests/x86/mpx-mini-test.c
index 50f7e9272481..bf1bb15b6fbe 100644
--- a/tools/testing/selftests/x86/mpx-mini-test.c
+++ b/tools/testing/selftests/x86/mpx-mini-test.c
@@ -1503,7 +1503,7 @@ exit:
1503 exit(20); 1503 exit(20);
1504 } 1504 }
1505 if (successes != total_nr_tests) { 1505 if (successes != total_nr_tests) {
1506 eprintf("ERROR: succeded fewer than number of tries (%d != %d)\n", 1506 eprintf("ERROR: succeeded fewer than number of tries (%d != %d)\n",
1507 successes, total_nr_tests); 1507 successes, total_nr_tests);
1508 exit(21); 1508 exit(21);
1509 } 1509 }
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index 460b4bdf4c1e..5d546dcdbc80 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -1133,6 +1133,21 @@ void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
1133 pkey_assert(err); 1133 pkey_assert(err);
1134} 1134}
1135 1135
1136void become_child(void)
1137{
1138 pid_t forkret;
1139
1140 forkret = fork();
1141 pkey_assert(forkret >= 0);
1142 dprintf3("[%d] fork() ret: %d\n", getpid(), forkret);
1143
1144 if (!forkret) {
1145 /* in the child */
1146 return;
1147 }
1148 exit(0);
1149}
1150
1136/* Assumes that all pkeys other than 'pkey' are unallocated */ 1151/* Assumes that all pkeys other than 'pkey' are unallocated */
1137void test_pkey_alloc_exhaust(int *ptr, u16 pkey) 1152void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
1138{ 1153{
@@ -1141,7 +1156,7 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
1141 int nr_allocated_pkeys = 0; 1156 int nr_allocated_pkeys = 0;
1142 int i; 1157 int i;
1143 1158
1144 for (i = 0; i < NR_PKEYS*2; i++) { 1159 for (i = 0; i < NR_PKEYS*3; i++) {
1145 int new_pkey; 1160 int new_pkey;
1146 dprintf1("%s() alloc loop: %d\n", __func__, i); 1161 dprintf1("%s() alloc loop: %d\n", __func__, i);
1147 new_pkey = alloc_pkey(); 1162 new_pkey = alloc_pkey();
@@ -1152,21 +1167,27 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
1152 if ((new_pkey == -1) && (errno == ENOSPC)) { 1167 if ((new_pkey == -1) && (errno == ENOSPC)) {
1153 dprintf2("%s() failed to allocate pkey after %d tries\n", 1168 dprintf2("%s() failed to allocate pkey after %d tries\n",
1154 __func__, nr_allocated_pkeys); 1169 __func__, nr_allocated_pkeys);
1155 break; 1170 } else {
1171 /*
1172 * Ensure the number of successes never
1173 * exceeds the number of keys supported
1174 * in the hardware.
1175 */
1176 pkey_assert(nr_allocated_pkeys < NR_PKEYS);
1177 allocated_pkeys[nr_allocated_pkeys++] = new_pkey;
1156 } 1178 }
1157 pkey_assert(nr_allocated_pkeys < NR_PKEYS); 1179
1158 allocated_pkeys[nr_allocated_pkeys++] = new_pkey; 1180 /*
1181 * Make sure that allocation state is properly
1182 * preserved across fork().
1183 */
1184 if (i == NR_PKEYS*2)
1185 become_child();
1159 } 1186 }
1160 1187
1161 dprintf3("%s()::%d\n", __func__, __LINE__); 1188 dprintf3("%s()::%d\n", __func__, __LINE__);
1162 1189
1163 /* 1190 /*
1164 * ensure it did not reach the end of the loop without
1165 * failure:
1166 */
1167 pkey_assert(i < NR_PKEYS*2);
1168
1169 /*
1170 * There are 16 pkeys supported in hardware. Three are 1191 * There are 16 pkeys supported in hardware. Three are
1171 * allocated by the time we get here: 1192 * allocated by the time we get here:
1172 * 1. The default key (0) 1193 * 1. The default key (0)
diff --git a/tools/testing/selftests/x86/unwind_vdso.c b/tools/testing/selftests/x86/unwind_vdso.c
index 00a26a82fa98..97311333700e 100644
--- a/tools/testing/selftests/x86/unwind_vdso.c
+++ b/tools/testing/selftests/x86/unwind_vdso.c
@@ -44,7 +44,6 @@ int main()
44#include <stdbool.h> 44#include <stdbool.h>
45#include <sys/ptrace.h> 45#include <sys/ptrace.h>
46#include <sys/user.h> 46#include <sys/user.h>
47#include <sys/ucontext.h>
48#include <link.h> 47#include <link.h>
49#include <sys/auxv.h> 48#include <sys/auxv.h>
50#include <dlfcn.h> 49#include <dlfcn.h>