@@ -1036,9 +1036,10 @@ static int call_getsockopt(bool use_io_uring, int fd, int level, int optname,
1036
1036
return getsockopt (fd , level , optname , optval , optlen );
1037
1037
}
1038
1038
1039
- static int run_test (int cgroup_fd , struct sockopt_test * test , bool use_io_uring )
1039
+ static int run_test (int cgroup_fd , struct sockopt_test * test , bool use_io_uring ,
1040
+ bool use_link )
1040
1041
{
1041
- int sock_fd , err , prog_fd ;
1042
+ int sock_fd , err , prog_fd , link_fd = -1 ;
1042
1043
void * optval = NULL ;
1043
1044
int ret = 0 ;
1044
1045
@@ -1051,7 +1052,12 @@ static int run_test(int cgroup_fd, struct sockopt_test *test, bool use_io_uring)
1051
1052
return -1 ;
1052
1053
}
1053
1054
1054
- err = bpf_prog_attach (prog_fd , cgroup_fd , test -> attach_type , 0 );
1055
+ if (use_link ) {
1056
+ err = bpf_link_create (prog_fd , cgroup_fd , test -> attach_type , NULL );
1057
+ link_fd = err ;
1058
+ } else {
1059
+ err = bpf_prog_attach (prog_fd , cgroup_fd , test -> attach_type , 0 );
1060
+ }
1055
1061
if (err < 0 ) {
1056
1062
if (test -> error == DENY_ATTACH )
1057
1063
goto close_prog_fd ;
@@ -1142,7 +1148,12 @@ static int run_test(int cgroup_fd, struct sockopt_test *test, bool use_io_uring)
1142
1148
close_sock_fd :
1143
1149
close (sock_fd );
1144
1150
detach_prog :
1145
- bpf_prog_detach2 (prog_fd , cgroup_fd , test -> attach_type );
1151
+ if (use_link ) {
1152
+ if (link_fd >= 0 )
1153
+ close (link_fd );
1154
+ } else {
1155
+ bpf_prog_detach2 (prog_fd , cgroup_fd , test -> attach_type );
1156
+ }
1146
1157
close_prog_fd :
1147
1158
close (prog_fd );
1148
1159
return ret ;
@@ -1160,10 +1171,12 @@ void test_sockopt(void)
1160
1171
if (!test__start_subtest (tests [i ].descr ))
1161
1172
continue ;
1162
1173
1163
- ASSERT_OK (run_test (cgroup_fd , & tests [i ], false),
1174
+ ASSERT_OK (run_test (cgroup_fd , & tests [i ], false, false),
1175
+ tests [i ].descr );
1176
+ ASSERT_OK (run_test (cgroup_fd , & tests [i ], false, true),
1164
1177
tests [i ].descr );
1165
1178
if (tests [i ].io_uring_support )
1166
- ASSERT_OK (run_test (cgroup_fd , & tests [i ], true),
1179
+ ASSERT_OK (run_test (cgroup_fd , & tests [i ], true, false ),
1167
1180
tests [i ].descr );
1168
1181
}
1169
1182
0 commit comments