@@ -256,12 +256,13 @@ void test_xdp_context_veth(void)
256
256
netns_free (tx_ns );
257
257
}
258
258
259
- void test_xdp_context_tuntap (void )
259
+ static void test_tuntap (struct bpf_program * xdp_prog ,
260
+ struct bpf_program * tc_prog ,
261
+ struct bpf_map * result_map )
260
262
{
261
263
LIBBPF_OPTS (bpf_tc_hook , tc_hook , .attach_point = BPF_TC_INGRESS );
262
264
LIBBPF_OPTS (bpf_tc_opts , tc_opts , .handle = 1 , .priority = 1 );
263
265
struct netns_obj * ns = NULL ;
264
- struct test_xdp_meta * skel = NULL ;
265
266
__u8 packet [sizeof (struct ethhdr ) + TEST_PAYLOAD_LEN ];
266
267
int tap_fd = -1 ;
267
268
int tap_ifindex ;
@@ -277,10 +278,6 @@ void test_xdp_context_tuntap(void)
277
278
278
279
SYS (close , "ip link set dev " TAP_NAME " up" );
279
280
280
- skel = test_xdp_meta__open_and_load ();
281
- if (!ASSERT_OK_PTR (skel , "open and load skeleton" ))
282
- goto close ;
283
-
284
281
tap_ifindex = if_nametoindex (TAP_NAME );
285
282
if (!ASSERT_GE (tap_ifindex , 0 , "if_nametoindex" ))
286
283
goto close ;
@@ -290,12 +287,12 @@ void test_xdp_context_tuntap(void)
290
287
if (!ASSERT_OK (ret , "bpf_tc_hook_create" ))
291
288
goto close ;
292
289
293
- tc_opts .prog_fd = bpf_program__fd (skel -> progs . ing_cls );
290
+ tc_opts .prog_fd = bpf_program__fd (tc_prog );
294
291
ret = bpf_tc_attach (& tc_hook , & tc_opts );
295
292
if (!ASSERT_OK (ret , "bpf_tc_attach" ))
296
293
goto close ;
297
294
298
- ret = bpf_xdp_attach (tap_ifindex , bpf_program__fd (skel -> progs . ing_xdp ),
295
+ ret = bpf_xdp_attach (tap_ifindex , bpf_program__fd (xdp_prog ),
299
296
0 , NULL );
300
297
if (!ASSERT_GE (ret , 0 , "bpf_xdp_attach" ))
301
298
goto close ;
@@ -312,11 +309,25 @@ void test_xdp_context_tuntap(void)
312
309
if (!ASSERT_EQ (ret , sizeof (packet ), "write packet" ))
313
310
goto close ;
314
311
315
- assert_test_result (skel -> maps . test_result );
312
+ assert_test_result (result_map );
316
313
317
314
close :
318
315
if (tap_fd >= 0 )
319
316
close (tap_fd );
320
- test_xdp_meta__destroy (skel );
321
317
netns_free (ns );
322
318
}
319
+
320
+ void test_xdp_context_tuntap (void )
321
+ {
322
+ struct test_xdp_meta * skel = NULL ;
323
+
324
+ skel = test_xdp_meta__open_and_load ();
325
+ if (!ASSERT_OK_PTR (skel , "open and load skeleton" ))
326
+ return ;
327
+
328
+ if (test__start_subtest ("data_meta" ))
329
+ test_tuntap (skel -> progs .ing_xdp , skel -> progs .ing_cls ,
330
+ skel -> maps .test_result );
331
+
332
+ test_xdp_meta__destroy (skel );
333
+ }
0 commit comments