Skip to content

Commit 0f9ff4c

Browse files
bastien-curutchetMartin KaFai Lau
authored andcommitted
selftests/bpf: test_xdp_vlan: Rename BPF sections
The __load() helper expects BPF sections to be names 'xdp' or 'tc' Rename BPF sections so they can be loaded with the __load() helper in upcoming patch. Rename the BPF functions with their previous section's name. Update the 'ip link' commands in the script to use the program name instead of the section name to load the BPF program. Acked-by: Stanislav Fomichev <sdf@fomichev.me> Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://patch.msgid.link/20250221-xdp_vlan-v1-1-7d29847169af@bootlin.com
1 parent a259804 commit 0f9ff4c

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

tools/testing/selftests/bpf/progs/test_xdp_vlan.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ bool parse_eth_frame(struct ethhdr *eth, void *data_end, struct parse_pkt *pkt)
102102
#define TESTVLAN 4011 /* 0xFAB */
103103
// #define TO_VLAN 4000 /* 0xFA0 (hint 0xOA0 = 160) */
104104

105-
SEC("xdp_drop_vlan_4011")
106-
int xdp_prognum0(struct xdp_md *ctx)
105+
SEC("xdp")
106+
int xdp_drop_vlan_4011(struct xdp_md *ctx)
107107
{
108108
void *data_end = (void *)(long)ctx->data_end;
109109
void *data = (void *)(long)ctx->data;
@@ -144,8 +144,8 @@ Load prog with ip tool:
144144
/* Changing VLAN to zero, have same practical effect as removing the VLAN. */
145145
#define TO_VLAN 0
146146

147-
SEC("xdp_vlan_change")
148-
int xdp_prognum1(struct xdp_md *ctx)
147+
SEC("xdp")
148+
int xdp_vlan_change(struct xdp_md *ctx)
149149
{
150150
void *data_end = (void *)(long)ctx->data_end;
151151
void *data = (void *)(long)ctx->data;
@@ -178,8 +178,8 @@ int xdp_prognum1(struct xdp_md *ctx)
178178
#endif
179179
#define VLAN_HDR_SZ 4 /* bytes */
180180

181-
SEC("xdp_vlan_remove_outer")
182-
int xdp_prognum2(struct xdp_md *ctx)
181+
SEC("xdp")
182+
int xdp_vlan_remove_outer(struct xdp_md *ctx)
183183
{
184184
void *data_end = (void *)(long)ctx->data_end;
185185
void *data = (void *)(long)ctx->data;
@@ -224,8 +224,8 @@ void shift_mac_4bytes_32bit(void *data)
224224
p[1] = p[0];
225225
}
226226

227-
SEC("xdp_vlan_remove_outer2")
228-
int xdp_prognum3(struct xdp_md *ctx)
227+
SEC("xdp")
228+
int xdp_vlan_remove_outer2(struct xdp_md *ctx)
229229
{
230230
void *data_end = (void *)(long)ctx->data_end;
231231
void *data = (void *)(long)ctx->data;
@@ -254,8 +254,8 @@ int xdp_prognum3(struct xdp_md *ctx)
254254
* The TC-clsact eBPF programs (currently) need to be attach via TC commands
255255
*/
256256

257-
SEC("tc_vlan_push")
258-
int _tc_progA(struct __sk_buff *ctx)
257+
SEC("tc")
258+
int tc_vlan_push(struct __sk_buff *ctx)
259259
{
260260
bpf_skb_vlan_push(ctx, bpf_htons(ETH_P_8021Q), TESTVLAN);
261261

tools/testing/selftests/bpf/test_xdp_vlan.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ export BPF_FILE=test_xdp_vlan.bpf.o
204204

205205
# First test: Remove VLAN by setting VLAN ID 0, using "xdp_vlan_change"
206206
export XDP_PROG=xdp_vlan_change
207-
ip netns exec ${NS1} ip link set $DEVNS1 $XDP_MODE object $BPF_FILE section $XDP_PROG
207+
ip netns exec ${NS1} ip link set $DEVNS1 $XDP_MODE object $BPF_FILE program $XDP_PROG
208208

209209
# In ns1: egress use TC to add back VLAN tag 4011
210210
# (del cmd)
211211
# tc qdisc del dev $DEVNS1 clsact 2> /dev/null
212212
#
213213
ip netns exec ${NS1} tc qdisc add dev $DEVNS1 clsact
214214
ip netns exec ${NS1} tc filter add dev $DEVNS1 egress \
215-
prio 1 handle 1 bpf da obj $BPF_FILE sec tc_vlan_push
215+
prio 1 handle 1 bpf da obj $BPF_FILE program tc_vlan_push
216216

217217
# Now the namespaces can reach each-other, test with ping:
218218
ip netns exec ${NS2} ping -i 0.2 -W 2 -c 2 $IPADDR1
@@ -226,7 +226,7 @@ ip netns exec ${NS1} ping -i 0.2 -W 2 -c 2 $IPADDR2
226226
#
227227
export XDP_PROG=xdp_vlan_remove_outer2
228228
ip netns exec ${NS1} ip link set $DEVNS1 $XDP_MODE off
229-
ip netns exec ${NS1} ip link set $DEVNS1 $XDP_MODE object $BPF_FILE section $XDP_PROG
229+
ip netns exec ${NS1} ip link set $DEVNS1 $XDP_MODE object $BPF_FILE program $XDP_PROG
230230

231231
# Now the namespaces should still be able reach each-other, test with ping:
232232
ip netns exec ${NS2} ping -i 0.2 -W 2 -c 2 $IPADDR1

0 commit comments

Comments
 (0)