@@ -88,6 +88,77 @@ static void test_fq(void)
8888 bpf_qdisc_fq__destroy (fq_skel );
8989}
9090
91+ static void test_qdisc_attach_to_mq (void )
92+ {
93+ DECLARE_LIBBPF_OPTS (bpf_tc_hook , hook ,
94+ .attach_point = BPF_TC_QDISC ,
95+ .parent = TC_H_MAKE (1 << 16 , 1 ),
96+ .handle = 0x11 << 16 ,
97+ .qdisc = "bpf_fifo" );
98+ struct bpf_qdisc_fifo * fifo_skel ;
99+ struct bpf_link * link ;
100+ int err ;
101+
102+ fifo_skel = bpf_qdisc_fifo__open_and_load ();
103+ if (!ASSERT_OK_PTR (fifo_skel , "bpf_qdisc_fifo__open_and_load" ))
104+ return ;
105+
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+ }
111+
112+ SYS (out , "ip link add veth0 type veth peer veth1" );
113+ hook .ifindex = if_nametoindex ("veth0" );
114+ SYS (out , "tc qdisc add dev veth0 root handle 1: mq" );
115+
116+ err = bpf_tc_hook_create (& hook );
117+ ASSERT_OK (err , "attach qdisc" );
118+
119+ bpf_tc_hook_destroy (& hook );
120+
121+ SYS (out , "tc qdisc delete dev veth0 root mq" );
122+ out :
123+ bpf_link__destroy (link );
124+ bpf_qdisc_fifo__destroy (fifo_skel );
125+ }
126+
127+ static void test_qdisc_attach_to_non_root (void )
128+ {
129+ DECLARE_LIBBPF_OPTS (bpf_tc_hook , hook , .ifindex = LO_IFINDEX ,
130+ .attach_point = BPF_TC_QDISC ,
131+ .parent = TC_H_MAKE (1 << 16 , 1 ),
132+ .handle = 0x11 << 16 ,
133+ .qdisc = "bpf_fifo" );
134+ struct bpf_qdisc_fifo * fifo_skel ;
135+ struct bpf_link * link ;
136+ int err ;
137+
138+ fifo_skel = bpf_qdisc_fifo__open_and_load ();
139+ if (!ASSERT_OK_PTR (fifo_skel , "bpf_qdisc_fifo__open_and_load" ))
140+ return ;
141+
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+ }
147+
148+ SYS (out , "tc qdisc add dev lo root handle 1: htb" );
149+ SYS (out_del_htb , "tc class add dev lo parent 1: classid 1:1 htb rate 75Kbit" );
150+
151+ err = bpf_tc_hook_create (& hook );
152+ if (!ASSERT_ERR (err , "attach qdisc" ))
153+ bpf_tc_hook_destroy (& hook );
154+
155+ out_del_htb :
156+ SYS (out , "tc qdisc delete dev lo root htb" );
157+ out :
158+ bpf_link__destroy (link );
159+ bpf_qdisc_fifo__destroy (fifo_skel );
160+ }
161+
91162void test_bpf_qdisc (void )
92163{
93164 struct netns_obj * netns ;
@@ -100,6 +171,10 @@ void test_bpf_qdisc(void)
100171 test_fifo ();
101172 if (test__start_subtest ("fq" ))
102173 test_fq ();
174+ if (test__start_subtest ("attach to mq" ))
175+ test_qdisc_attach_to_mq ();
176+ if (test__start_subtest ("attach to non root" ))
177+ test_qdisc_attach_to_non_root ();
103178
104179 netns_free (netns );
105180}
0 commit comments