1818#include <bpf/libbpf.h>
1919
2020#define ARRAY_SIZE (_x ) (sizeof(_x) / sizeof((_x)[0]))
21+ #define EXIT_SKIPPED 249
2122
2223static bool kern_compat ;
2324
@@ -81,7 +82,8 @@ static int check_attached_progs(int ifindex, int count, bool devbound)
8182static void print_test_result (const char * func , int ret )
8283{
8384 fflush (stderr );
84- fprintf (stderr , "%s:\t%s\n" , func , ret ? "FAILED" : "PASSED" );
85+ fprintf (stderr , "%s:\t%s\n" , func ,
86+ ret ? (ret == EXIT_SKIPPED ? "SKIPPED" : "FAILED" ) : "PASSED" );
8587 fflush (stdout );
8688}
8789
@@ -104,9 +106,17 @@ static int load_attach_prog(struct xdp_program **prog, int ifindex,
104106static int _check_load (int ifindex , bool devbound , bool should_succeed )
105107{
106108 struct xdp_program * prog = NULL ;
107- bool attached ;
109+ bool attached = false ;
108110 int ret ;
109111
112+ /* If the kernel does not support device binding, we always expect
113+ * device binding support to be disabled on a returned dispatcher
114+ */
115+ if (!kern_compat && devbound ) {
116+ ret = EXIT_SKIPPED ;
117+ goto out ;
118+ }
119+
110120 ret = load_attach_prog (& prog , ifindex , devbound );
111121 attached = !ret ;
112122
@@ -146,6 +156,14 @@ static int check_load_devbound_multi(int ifindex)
146156 struct xdp_program * prog1 = NULL , * prog2 = NULL ;
147157 int ret ;
148158
159+ /* If the kernel does not support device binding, we always expect
160+ * device binding support to be disabled on a returned dispatcher
161+ */
162+ if (!kern_compat ) {
163+ ret = EXIT_SKIPPED ;
164+ goto out ;
165+ }
166+
149167 ret = load_attach_prog (& prog1 , ifindex , true);
150168 if (ret )
151169 goto out ;
@@ -171,6 +189,14 @@ static int _check_load_mix(int ifindex, bool devbound1, bool devbound2)
171189 struct xdp_program * prog1 = NULL , * prog2 = NULL ;
172190 int ret ;
173191
192+ /* If the kernel does not support device binding, we always expect
193+ * device binding support to be disabled on a returned dispatcher
194+ */
195+ if (!kern_compat && (devbound1 || devbound2 )) {
196+ ret = EXIT_SKIPPED ;
197+ goto out ;
198+ }
199+
174200 ret = load_attach_prog (& prog1 , ifindex , devbound1 );
175201 if (ret )
176202 goto out ;
@@ -218,6 +244,14 @@ static int check_load_devbound_multiple_ifindex(int ifindex1, int ifindex2)
218244 struct xdp_program * prog = NULL ;
219245 int ret ;
220246
247+ /* If the kernel does not support device binding, we always expect
248+ * device binding support to be disabled on a returned dispatcher
249+ */
250+ if (!kern_compat ) {
251+ ret = EXIT_SKIPPED ;
252+ goto out ;
253+ }
254+
221255 prog = load_prog ();
222256
223257 ret = xdp_program__attach (prog , ifindex1 , XDP_MODE_NATIVE ,
@@ -243,7 +277,7 @@ static int check_load_devbound_multiple_ifindex(int ifindex1, int ifindex2)
243277out :
244278 xdp_program__detach (prog , ifindex1 , XDP_MODE_NATIVE , 0 );
245279 xdp_program__close (prog );
246- print_test_result (__func__ , !ret );
280+ print_test_result (__func__ , ret == EXIT_SKIPPED ? ret : !ret );
247281 return !ret ;
248282}
249283
@@ -252,6 +286,14 @@ static int check_load_mixed_multiple_ifindex(int ifindex1, int ifindex2)
252286 struct xdp_program * prog = NULL ;
253287 int ret ;
254288
289+ /* If the kernel does not support device binding, we always expect
290+ * device binding support to be disabled on a returned dispatcher
291+ */
292+ if (!kern_compat ) {
293+ ret = EXIT_SKIPPED ;
294+ goto out ;
295+ }
296+
255297 prog = load_prog ();
256298
257299 ret = xdp_program__attach (prog , ifindex1 , XDP_MODE_NATIVE ,
@@ -274,7 +316,7 @@ static int check_load_mixed_multiple_ifindex(int ifindex1, int ifindex2)
274316 xdp_program__detach (prog , ifindex1 , XDP_MODE_NATIVE , 0 );
275317out :
276318 xdp_program__close (prog );
277- print_test_result (__func__ , !ret );
319+ print_test_result (__func__ , ret == EXIT_SKIPPED ? ret : !ret );
278320 return !ret ;
279321}
280322
@@ -283,6 +325,14 @@ static int check_load2_mixed_multiple_ifindex(int ifindex1, int ifindex2)
283325 struct xdp_program * prog1 = NULL , * prog2 = NULL ;
284326 int ret ;
285327
328+ /* If the kernel does not support device binding, we always expect
329+ * device binding support to be disabled on a returned dispatcher
330+ */
331+ if (!kern_compat ) {
332+ ret = EXIT_SKIPPED ;
333+ goto out ;
334+ }
335+
286336 ret = load_attach_prog (& prog1 , ifindex1 , true);
287337 if (ret )
288338 goto out ;
@@ -389,17 +439,14 @@ int main(int argc, char **argv)
389439 }
390440
391441 kern_compat = check_devbound_compat ();
392-
393- ret = check_load_devbound (kern_compat ? ifindex1 : 0 );
394- ret = check_load_nodevbound_success (ifindex1 ) || ret ;
395- if (kern_compat ) {
396- ret = check_load_devbound_multi (ifindex1 ) || ret ;
397- ret = check_load_mix_devbound_nodevbound (ifindex1 ) || ret ;
398- ret = check_load_mix_nodevbound_devbound (ifindex1 ) || ret ;
399- ret = check_load_devbound_multiple_ifindex (ifindex1 , ifindex2 ) || ret ;
400- ret = check_load_mixed_multiple_ifindex (ifindex1 , ifindex2 ) || ret ;
401- ret = check_load2_mixed_multiple_ifindex (ifindex1 , ifindex2 ) || ret ;
402- }
442+ ret = check_load_devbound (ifindex1 );
443+ ret |= check_load_nodevbound_success (ifindex1 );
444+ ret |= check_load_devbound_multi (ifindex1 );
445+ ret |= check_load_mix_devbound_nodevbound (ifindex1 );
446+ ret |= check_load_mix_nodevbound_devbound (ifindex1 );
447+ ret |= check_load_devbound_multiple_ifindex (ifindex1 , ifindex2 );
448+ ret |= check_load_mixed_multiple_ifindex (ifindex1 , ifindex2 );
449+ ret |= check_load2_mixed_multiple_ifindex (ifindex1 , ifindex2 );
403450
404451 return ret ;
405452}
0 commit comments