diff mbox series

selftests/bpf: fix build errors if CONFIG_NF_CONNTRACK_MARK not set.

Message ID 20230723093806.2850822-1-mahmoudmatook.mm@gmail.com (mailing list archive)
State New
Headers show
Series selftests/bpf: fix build errors if CONFIG_NF_CONNTRACK_MARK not set. | expand

Commit Message

Mahmoud Matook July 23, 2023, 9:38 a.m. UTC
'mark' member in 'struct nf_conn' is conditionally defined
 by CONFIG_NF_CONNTRACK_MARK
 so any reference to it should follow the same.

 $ make -C tools/testing/selftests/bpf
	progs/test_bpf_nf.c:219:12: error: no member named 'mark' in 'struct nf_conn'
	                        if (ct->mark == 42) {
	                            ~~  ^
	progs/test_bpf_nf.c:220:9: error: no member named 'mark' in 'struct nf_conn'
	                                ct->mark++;
	                                ~~  ^
	progs/test_bpf_nf.c:221:34: error: no member named 'mark' in 'struct nf_conn'
                                test_exist_lookup_mark = ct->mark;

Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
---
 .../testing/selftests/bpf/progs/test_bpf_nf.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

Comments

Alexei Starovoitov July 24, 2023, 6:04 p.m. UTC | #1
On Sun, Jul 23, 2023 at 2:38 AM Mahmoud Maatuq
<mahmoudmatook.mm@gmail.com> wrote:
>
> 'mark' member in 'struct nf_conn' is conditionally defined
>  by CONFIG_NF_CONNTRACK_MARK
>  so any reference to it should follow the same.
>
>  $ make -C tools/testing/selftests/bpf
>         progs/test_bpf_nf.c:219:12: error: no member named 'mark' in 'struct nf_conn'
>                                 if (ct->mark == 42) {
>                                     ~~  ^
>         progs/test_bpf_nf.c:220:9: error: no member named 'mark' in 'struct nf_conn'
>                                         ct->mark++;
>                                         ~~  ^
>         progs/test_bpf_nf.c:221:34: error: no member named 'mark' in 'struct nf_conn'
>                                 test_exist_lookup_mark = ct->mark;
>
> Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
> ---
>  .../testing/selftests/bpf/progs/test_bpf_nf.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> index 77ad8adf68da..0b285de8b7e7 100644
> --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> @@ -157,7 +157,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,
>                 struct nf_conn *ct_ins;
>
>                 bpf_ct_set_timeout(ct, 10000);
> -               ct->mark = 77;
> +               #if defined(CONFIG_NF_CONNTRACK_MARK)
> +                       ct->mark = 77;
> +               #endif
> +
>
>                 /* snat */
>                 saddr.ip = bpf_get_prandom_u32();
> @@ -188,7 +191,9 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,
>                                 bpf_ct_change_timeout(ct_lk, 10000);
>                                 test_delta_timeout = ct_lk->timeout - bpf_jiffies64();
>                                 test_delta_timeout /= CONFIG_HZ;
> -                               test_insert_lookup_mark = ct_lk->mark;
> +                               #if defined(CONFIG_NF_CONNTRACK_MARK)
> +                                       test_insert_lookup_mark = ct_lk->mark;
> +                               #endif
>                                 bpf_ct_change_status(ct_lk,
>                                                      IPS_CONFIRMED | IPS_SEEN_REPLY);
>                                 test_status = ct_lk->status;
> @@ -210,10 +215,12 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,
>                        sizeof(opts_def));
>         if (ct) {
>                 test_exist_lookup = 0;
> -               if (ct->mark == 42) {
> -                       ct->mark++;
> -                       test_exist_lookup_mark = ct->mark;
> -               }
> +               #if defined(CONFIG_NF_CONNTRACK_MARK)
> +                       if (ct->mark == 42) {
> +                               ct->mark++;
> +                               test_exist_lookup_mark = ct->mark;
> +                       }
> +               #endif

That's not a fix.
The test has to have CONFIG_NF_CONNTRACK_MARK enabled in the kernel.
Make sure your kernel is built with _all_ configs specified in
tools/testing/selftests/bpf/config*
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
index 77ad8adf68da..0b285de8b7e7 100644
--- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c
+++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
@@ -157,7 +157,10 @@  nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,
 		struct nf_conn *ct_ins;
 
 		bpf_ct_set_timeout(ct, 10000);
-		ct->mark = 77;
+		#if defined(CONFIG_NF_CONNTRACK_MARK)
+			ct->mark = 77;
+		#endif
+
 
 		/* snat */
 		saddr.ip = bpf_get_prandom_u32();
@@ -188,7 +191,9 @@  nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,
 				bpf_ct_change_timeout(ct_lk, 10000);
 				test_delta_timeout = ct_lk->timeout - bpf_jiffies64();
 				test_delta_timeout /= CONFIG_HZ;
-				test_insert_lookup_mark = ct_lk->mark;
+				#if defined(CONFIG_NF_CONNTRACK_MARK)
+					test_insert_lookup_mark = ct_lk->mark;
+				#endif
 				bpf_ct_change_status(ct_lk,
 						     IPS_CONFIRMED | IPS_SEEN_REPLY);
 				test_status = ct_lk->status;
@@ -210,10 +215,12 @@  nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,
 		       sizeof(opts_def));
 	if (ct) {
 		test_exist_lookup = 0;
-		if (ct->mark == 42) {
-			ct->mark++;
-			test_exist_lookup_mark = ct->mark;
-		}
+		#if defined(CONFIG_NF_CONNTRACK_MARK)
+			if (ct->mark == 42) {
+				ct->mark++;
+				test_exist_lookup_mark = ct->mark;
+			}
+		#endif
 		bpf_ct_release(ct);
 	} else {
 		test_exist_lookup = opts_def.error;