7
7
#include "network_helpers.h"
8
8
#include "bpf_qdisc_fifo.skel.h"
9
9
#include "bpf_qdisc_fq.skel.h"
10
+ #include "bpf_qdisc_fail__incompl_ops.skel.h"
10
11
11
12
#define LO_IFINDEX 1
12
13
@@ -49,42 +50,32 @@ static void do_test(char *qdisc)
49
50
static void test_fifo (void )
50
51
{
51
52
struct bpf_qdisc_fifo * fifo_skel ;
52
- struct bpf_link * link ;
53
53
54
54
fifo_skel = bpf_qdisc_fifo__open_and_load ();
55
55
if (!ASSERT_OK_PTR (fifo_skel , "bpf_qdisc_fifo__open_and_load" ))
56
56
return ;
57
57
58
- link = bpf_map__attach_struct_ops (fifo_skel -> maps .fifo );
59
- if (!ASSERT_OK_PTR (link , "bpf_map__attach_struct_ops" )) {
60
- bpf_qdisc_fifo__destroy (fifo_skel );
61
- return ;
62
- }
58
+ if (!ASSERT_OK (bpf_qdisc_fifo__attach (fifo_skel ), "bpf_qdisc_fifo__attach" ))
59
+ goto out ;
63
60
64
61
do_test ("bpf_fifo" );
65
-
66
- bpf_link__destroy (link );
62
+ out :
67
63
bpf_qdisc_fifo__destroy (fifo_skel );
68
64
}
69
65
70
66
static void test_fq (void )
71
67
{
72
68
struct bpf_qdisc_fq * fq_skel ;
73
- struct bpf_link * link ;
74
69
75
70
fq_skel = bpf_qdisc_fq__open_and_load ();
76
71
if (!ASSERT_OK_PTR (fq_skel , "bpf_qdisc_fq__open_and_load" ))
77
72
return ;
78
73
79
- link = bpf_map__attach_struct_ops (fq_skel -> maps .fq );
80
- if (!ASSERT_OK_PTR (link , "bpf_map__attach_struct_ops" )) {
81
- bpf_qdisc_fq__destroy (fq_skel );
82
- return ;
83
- }
74
+ if (!ASSERT_OK (bpf_qdisc_fq__attach (fq_skel ), "bpf_qdisc_fq__attach" ))
75
+ goto out ;
84
76
85
77
do_test ("bpf_fq" );
86
-
87
- bpf_link__destroy (link );
78
+ out :
88
79
bpf_qdisc_fq__destroy (fq_skel );
89
80
}
90
81
@@ -96,18 +87,14 @@ static void test_qdisc_attach_to_mq(void)
96
87
.handle = 0x11 << 16 ,
97
88
.qdisc = "bpf_fifo" );
98
89
struct bpf_qdisc_fifo * fifo_skel ;
99
- struct bpf_link * link ;
100
90
int err ;
101
91
102
92
fifo_skel = bpf_qdisc_fifo__open_and_load ();
103
93
if (!ASSERT_OK_PTR (fifo_skel , "bpf_qdisc_fifo__open_and_load" ))
104
94
return ;
105
95
106
- link = bpf_map__attach_struct_ops (fifo_skel -> maps .fifo );
107
- if (!ASSERT_OK_PTR (link , "bpf_map__attach_struct_ops" )) {
108
- bpf_qdisc_fifo__destroy (fifo_skel );
109
- return ;
110
- }
96
+ if (!ASSERT_OK (bpf_qdisc_fifo__attach (fifo_skel ), "bpf_qdisc_fifo__attach" ))
97
+ goto out ;
111
98
112
99
SYS (out , "ip link add veth0 type veth peer veth1" );
113
100
hook .ifindex = if_nametoindex ("veth0" );
@@ -120,7 +107,6 @@ static void test_qdisc_attach_to_mq(void)
120
107
121
108
SYS (out , "tc qdisc delete dev veth0 root mq" );
122
109
out :
123
- bpf_link__destroy (link );
124
110
bpf_qdisc_fifo__destroy (fifo_skel );
125
111
}
126
112
@@ -132,18 +118,14 @@ static void test_qdisc_attach_to_non_root(void)
132
118
.handle = 0x11 << 16 ,
133
119
.qdisc = "bpf_fifo" );
134
120
struct bpf_qdisc_fifo * fifo_skel ;
135
- struct bpf_link * link ;
136
121
int err ;
137
122
138
123
fifo_skel = bpf_qdisc_fifo__open_and_load ();
139
124
if (!ASSERT_OK_PTR (fifo_skel , "bpf_qdisc_fifo__open_and_load" ))
140
125
return ;
141
126
142
- link = bpf_map__attach_struct_ops (fifo_skel -> maps .fifo );
143
- if (!ASSERT_OK_PTR (link , "bpf_map__attach_struct_ops" )) {
144
- bpf_qdisc_fifo__destroy (fifo_skel );
145
- return ;
146
- }
127
+ if (!ASSERT_OK (bpf_qdisc_fifo__attach (fifo_skel ), "bpf_qdisc_fifo__attach" ))
128
+ goto out ;
147
129
148
130
SYS (out , "tc qdisc add dev lo root handle 1: htb" );
149
131
SYS (out_del_htb , "tc class add dev lo parent 1: classid 1:1 htb rate 75Kbit" );
@@ -155,18 +137,82 @@ static void test_qdisc_attach_to_non_root(void)
155
137
out_del_htb :
156
138
SYS (out , "tc qdisc delete dev lo root htb" );
157
139
out :
158
- bpf_link__destroy (link );
159
140
bpf_qdisc_fifo__destroy (fifo_skel );
160
141
}
161
142
162
- void test_bpf_qdisc (void )
143
+ static void test_incompl_ops (void )
144
+ {
145
+ struct bpf_qdisc_fail__incompl_ops * skel ;
146
+ struct bpf_link * link ;
147
+
148
+ skel = bpf_qdisc_fail__incompl_ops__open_and_load ();
149
+ if (!ASSERT_OK_PTR (skel , "bpf_qdisc_fifo__open_and_load" ))
150
+ return ;
151
+
152
+ link = bpf_map__attach_struct_ops (skel -> maps .test );
153
+ if (!ASSERT_ERR_PTR (link , "bpf_map__attach_struct_ops" ))
154
+ bpf_link__destroy (link );
155
+
156
+ bpf_qdisc_fail__incompl_ops__destroy (skel );
157
+ }
158
+
159
+ static int get_default_qdisc (char * qdisc_name )
163
160
{
164
- struct netns_obj * netns ;
161
+ FILE * f ;
162
+ int num ;
163
+
164
+ f = fopen ("/proc/sys/net/core/default_qdisc" , "r" );
165
+ if (!f )
166
+ return - errno ;
167
+
168
+ num = fscanf (f , "%s" , qdisc_name );
169
+ fclose (f );
170
+
171
+ return num == 1 ? 0 : - EFAULT ;
172
+ }
173
+
174
+ static void test_default_qdisc_attach_to_mq (void )
175
+ {
176
+ char default_qdisc [IFNAMSIZ ] = {};
177
+ struct bpf_qdisc_fifo * fifo_skel ;
178
+ struct netns_obj * netns = NULL ;
179
+ int err ;
180
+
181
+ fifo_skel = bpf_qdisc_fifo__open_and_load ();
182
+ if (!ASSERT_OK_PTR (fifo_skel , "bpf_qdisc_fifo__open_and_load" ))
183
+ return ;
184
+
185
+ if (!ASSERT_OK (bpf_qdisc_fifo__attach (fifo_skel ), "bpf_qdisc_fifo__attach" ))
186
+ goto out ;
187
+
188
+ err = get_default_qdisc (default_qdisc );
189
+ if (!ASSERT_OK (err , "read sysctl net.core.default_qdisc" ))
190
+ goto out ;
191
+
192
+ err = write_sysctl ("/proc/sys/net/core/default_qdisc" , "bpf_fifo" );
193
+ if (!ASSERT_OK (err , "write sysctl net.core.default_qdisc" ))
194
+ goto out ;
165
195
166
196
netns = netns_new ("bpf_qdisc_ns" , true);
167
197
if (!ASSERT_OK_PTR (netns , "netns_new" ))
168
- return ;
198
+ goto out ;
199
+
200
+ SYS (out , "ip link add veth0 type veth peer veth1" );
201
+ SYS (out , "tc qdisc add dev veth0 root handle 1: mq" );
169
202
203
+ ASSERT_EQ (fifo_skel -> bss -> init_called , true, "init_called" );
204
+
205
+ SYS (out , "tc qdisc delete dev veth0 root mq" );
206
+ out :
207
+ netns_free (netns );
208
+ if (default_qdisc [0 ])
209
+ write_sysctl ("/proc/sys/net/core/default_qdisc" , default_qdisc );
210
+
211
+ bpf_qdisc_fifo__destroy (fifo_skel );
212
+ }
213
+
214
+ void test_ns_bpf_qdisc (void )
215
+ {
170
216
if (test__start_subtest ("fifo" ))
171
217
test_fifo ();
172
218
if (test__start_subtest ("fq" ))
@@ -175,6 +221,11 @@ void test_bpf_qdisc(void)
175
221
test_qdisc_attach_to_mq ();
176
222
if (test__start_subtest ("attach to non root" ))
177
223
test_qdisc_attach_to_non_root ();
224
+ if (test__start_subtest ("incompl_ops" ))
225
+ test_incompl_ops ();
226
+ }
178
227
179
- netns_free (netns );
228
+ void serial_test_bpf_qdisc_default (void )
229
+ {
230
+ test_default_qdisc_attach_to_mq ();
180
231
}
0 commit comments