@@ -24,6 +24,7 @@ enum sockopt_test_error {
24
24
static struct sockopt_test {
25
25
const char * descr ;
26
26
const struct bpf_insn insns [64 ];
27
+ enum bpf_prog_type prog_type ;
27
28
enum bpf_attach_type attach_type ;
28
29
enum bpf_attach_type expected_attach_type ;
29
30
@@ -928,9 +929,40 @@ static struct sockopt_test {
928
929
929
930
.error = EPERM_SETSOCKOPT ,
930
931
},
932
+
933
+ /* ==================== prog_type ==================== */
934
+
935
+ {
936
+ .descr = "can attach only BPF_CGROUP_SETSOCKOP" ,
937
+ .insns = {
938
+ /* return 1 */
939
+ BPF_MOV64_IMM (BPF_REG_0 , 1 ),
940
+ BPF_EXIT_INSN (),
941
+
942
+ },
943
+ .prog_type = BPF_PROG_TYPE_CGROUP_SKB ,
944
+ .attach_type = BPF_CGROUP_SETSOCKOPT ,
945
+ .expected_attach_type = 0 ,
946
+ .error = DENY_ATTACH ,
947
+ },
948
+
949
+ {
950
+ .descr = "can attach only BPF_CGROUP_GETSOCKOP" ,
951
+ .insns = {
952
+ /* return 1 */
953
+ BPF_MOV64_IMM (BPF_REG_0 , 1 ),
954
+ BPF_EXIT_INSN (),
955
+
956
+ },
957
+ .prog_type = BPF_PROG_TYPE_CGROUP_SKB ,
958
+ .attach_type = BPF_CGROUP_GETSOCKOPT ,
959
+ .expected_attach_type = 0 ,
960
+ .error = DENY_ATTACH ,
961
+ },
931
962
};
932
963
933
964
static int load_prog (const struct bpf_insn * insns ,
965
+ enum bpf_prog_type prog_type ,
934
966
enum bpf_attach_type expected_attach_type )
935
967
{
936
968
LIBBPF_OPTS (bpf_prog_load_opts , opts ,
@@ -947,7 +979,7 @@ static int load_prog(const struct bpf_insn *insns,
947
979
}
948
980
insns_cnt ++ ;
949
981
950
- fd = bpf_prog_load (BPF_PROG_TYPE_CGROUP_SOCKOPT , NULL , "GPL" , insns , insns_cnt , & opts );
982
+ fd = bpf_prog_load (prog_type , NULL , "GPL" , insns , insns_cnt , & opts );
951
983
if (verbose && fd < 0 )
952
984
fprintf (stderr , "%s\n" , bpf_log_buf );
953
985
@@ -1039,11 +1071,15 @@ static int call_getsockopt(bool use_io_uring, int fd, int level, int optname,
1039
1071
static int run_test (int cgroup_fd , struct sockopt_test * test , bool use_io_uring ,
1040
1072
bool use_link )
1041
1073
{
1074
+ int prog_type = BPF_PROG_TYPE_CGROUP_SOCKOPT ;
1042
1075
int sock_fd , err , prog_fd , link_fd = -1 ;
1043
1076
void * optval = NULL ;
1044
1077
int ret = 0 ;
1045
1078
1046
- prog_fd = load_prog (test -> insns , test -> expected_attach_type );
1079
+ if (test -> prog_type )
1080
+ prog_type = test -> prog_type ;
1081
+
1082
+ prog_fd = load_prog (test -> insns , prog_type , test -> expected_attach_type );
1047
1083
if (prog_fd < 0 ) {
1048
1084
if (test -> error == DENY_LOAD )
1049
1085
return 0 ;
0 commit comments