@@ -26,10 +26,43 @@ static const struct nf_link_test nf_hook_link_tests[] = {
2626
2727 { .pf = NFPROTO_INET , .priority = 1 , .name = "invalid-inet-not-supported" , },
2828
29- { .pf = NFPROTO_IPV4 , .priority = -10000 , .expect_success = true, .name = "attach ipv4" , },
30- { .pf = NFPROTO_IPV6 , .priority = 10001 , .expect_success = true, .name = "attach ipv6" , },
29+ {
30+ .pf = NFPROTO_IPV4 ,
31+ .hooknum = NF_INET_POST_ROUTING ,
32+ .priority = -10000 ,
33+ .flags = 0 ,
34+ .expect_success = true,
35+ .name = "attach ipv4" ,
36+ },
37+ {
38+ .pf = NFPROTO_IPV6 ,
39+ .hooknum = NF_INET_FORWARD ,
40+ .priority = 10001 ,
41+ .flags = BPF_F_NETFILTER_IP_DEFRAG ,
42+ .expect_success = true,
43+ .name = "attach ipv6" ,
44+ },
3145};
3246
47+ static void verify_netfilter_link_info (struct bpf_link * link , const struct nf_link_test nf_expected )
48+ {
49+ struct bpf_link_info info ;
50+ __u32 len = sizeof (info );
51+ int err , fd ;
52+
53+ memset (& info , 0 , len );
54+
55+ fd = bpf_link__fd (link );
56+ err = bpf_link_get_info_by_fd (fd , & info , & len );
57+ ASSERT_OK (err , "get_link_info" );
58+
59+ ASSERT_EQ (info .type , BPF_LINK_TYPE_NETFILTER , "info link type" );
60+ ASSERT_EQ (info .netfilter .pf , nf_expected .pf , "info nf protocol family" );
61+ ASSERT_EQ (info .netfilter .hooknum , nf_expected .hooknum , "info nf hooknum" );
62+ ASSERT_EQ (info .netfilter .priority , nf_expected .priority , "info nf priority" );
63+ ASSERT_EQ (info .netfilter .flags , nf_expected .flags , "info nf flags" );
64+ }
65+
3366void test_netfilter_link_attach (void )
3467{
3568 struct test_netfilter_link_attach * skel ;
@@ -64,6 +97,8 @@ void test_netfilter_link_attach(void)
6497 if (!ASSERT_OK_PTR (link , "program attach successful" ))
6598 continue ;
6699
100+ verify_netfilter_link_info (link , nf_hook_link_tests [i ]);
101+
67102 link2 = bpf_program__attach_netfilter (prog , & opts );
68103 ASSERT_ERR_PTR (link2 , "attach program with same pf/hook/priority" );
69104
@@ -73,6 +108,9 @@ void test_netfilter_link_attach(void)
73108 link2 = bpf_program__attach_netfilter (prog , & opts );
74109 if (!ASSERT_OK_PTR (link2 , "program reattach successful" ))
75110 continue ;
111+
112+ verify_netfilter_link_info (link2 , nf_hook_link_tests [i ]);
113+
76114 if (!ASSERT_OK (bpf_link__destroy (link2 ), "link destroy" ))
77115 break ;
78116 } else {
0 commit comments