Commit 8fffa0e3 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Normalize XDP section names in selftests

Convert almost all SEC("xdp_blah") uses to strict SEC("xdp") to comply
with strict libbpf 1.0 logic of exact section name match for XDP program
types. There is only one exception, which is only tested through
iproute2 and defines multiple XDP programs within the same BPF object.
Given iproute2 still works in non-strict libbpf mode and it doesn't have
means to specify XDP programs by its name (not section name/title),
leave that single file alone for now until iproute2 gains lookup by
function/program name.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/bpf/20210928161946.2512801-3-andrii@kernel.org
parent 9673268f
...@@ -23,7 +23,7 @@ struct { ...@@ -23,7 +23,7 @@ struct {
__uint(value_size, sizeof(__u32)); __uint(value_size, sizeof(__u32));
} mim_hash SEC(".maps"); } mim_hash SEC(".maps");
SEC("xdp_mimtest") SEC("xdp")
int xdp_mimtest0(struct xdp_md *ctx) int xdp_mimtest0(struct xdp_md *ctx)
{ {
int value = 123; int value = 123;
......
...@@ -156,7 +156,7 @@ int check_syncookie_clsact(struct __sk_buff *skb) ...@@ -156,7 +156,7 @@ int check_syncookie_clsact(struct __sk_buff *skb)
return TC_ACT_OK; return TC_ACT_OK;
} }
SEC("xdp/check_syncookie") SEC("xdp")
int check_syncookie_xdp(struct xdp_md *ctx) int check_syncookie_xdp(struct xdp_md *ctx)
{ {
check_syncookie(ctx, (void *)(long)ctx->data, check_syncookie(ctx, (void *)(long)ctx->data,
......
...@@ -210,7 +210,7 @@ static __always_inline int handle_ipv6(struct xdp_md *xdp) ...@@ -210,7 +210,7 @@ static __always_inline int handle_ipv6(struct xdp_md *xdp)
return XDP_TX; return XDP_TX;
} }
SEC("xdp_tx_iptunnel") SEC("xdp")
int _xdp_tx_iptunnel(struct xdp_md *xdp) int _xdp_tx_iptunnel(struct xdp_md *xdp)
{ {
void *data_end = (void *)(long)xdp->data_end; void *data_end = (void *)(long)xdp->data_end;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
SEC("xdp_adjust_tail_grow") SEC("xdp")
int _xdp_adjust_tail_grow(struct xdp_md *xdp) int _xdp_adjust_tail_grow(struct xdp_md *xdp)
{ {
void *data_end = (void *)(long)xdp->data_end; void *data_end = (void *)(long)xdp->data_end;
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
int _version SEC("version") = 1; SEC("xdp")
SEC("xdp_adjust_tail_shrink")
int _xdp_adjust_tail_shrink(struct xdp_md *xdp) int _xdp_adjust_tail_shrink(struct xdp_md *xdp)
{ {
void *data_end = (void *)(long)xdp->data_end; void *data_end = (void *)(long)xdp->data_end;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
SEC("xdp_dm_log") SEC("xdp")
int xdpdm_devlog(struct xdp_md *ctx) int xdpdm_devlog(struct xdp_md *ctx)
{ {
char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n"; char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n";
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
char LICENSE[] SEC("license") = "GPL"; char LICENSE[] SEC("license") = "GPL";
SEC("xdp/handler") SEC("xdp")
int xdp_handler(struct xdp_md *xdp) int xdp_handler(struct xdp_md *xdp)
{ {
return 0; return 0;
......
...@@ -206,7 +206,7 @@ static __always_inline int handle_ipv6(struct xdp_md *xdp) ...@@ -206,7 +206,7 @@ static __always_inline int handle_ipv6(struct xdp_md *xdp)
return XDP_TX; return XDP_TX;
} }
SEC("xdp_tx_iptunnel") SEC("xdp")
int _xdp_tx_iptunnel(struct xdp_md *xdp) int _xdp_tx_iptunnel(struct xdp_md *xdp)
{ {
void *data_end = (void *)(long)xdp->data_end; void *data_end = (void *)(long)xdp->data_end;
......
...@@ -797,7 +797,7 @@ static int process_packet(void *data, __u64 off, void *data_end, ...@@ -797,7 +797,7 @@ static int process_packet(void *data, __u64 off, void *data_end,
return XDP_DROP; return XDP_DROP;
} }
SEC("xdp-test-v4") SEC("xdp")
int balancer_ingress_v4(struct xdp_md *ctx) int balancer_ingress_v4(struct xdp_md *ctx)
{ {
void *data = (void *)(long)ctx->data; void *data = (void *)(long)ctx->data;
...@@ -816,7 +816,7 @@ int balancer_ingress_v4(struct xdp_md *ctx) ...@@ -816,7 +816,7 @@ int balancer_ingress_v4(struct xdp_md *ctx)
return XDP_DROP; return XDP_DROP;
} }
SEC("xdp-test-v6") SEC("xdp")
int balancer_ingress_v6(struct xdp_md *ctx) int balancer_ingress_v6(struct xdp_md *ctx)
{ {
void *data = (void *)(long)ctx->data; void *data = (void *)(long)ctx->data;
......
...@@ -12,13 +12,13 @@ struct { ...@@ -12,13 +12,13 @@ struct {
__uint(max_entries, 4); __uint(max_entries, 4);
} cpu_map SEC(".maps"); } cpu_map SEC(".maps");
SEC("xdp_redir") SEC("xdp")
int xdp_redir_prog(struct xdp_md *ctx) int xdp_redir_prog(struct xdp_md *ctx)
{ {
return bpf_redirect_map(&cpu_map, 1, 0); return bpf_redirect_map(&cpu_map, 1, 0);
} }
SEC("xdp_dummy") SEC("xdp")
int xdp_dummy_prog(struct xdp_md *ctx) int xdp_dummy_prog(struct xdp_md *ctx)
{ {
return XDP_PASS; return XDP_PASS;
......
...@@ -9,7 +9,7 @@ struct { ...@@ -9,7 +9,7 @@ struct {
__uint(max_entries, 4); __uint(max_entries, 4);
} dm_ports SEC(".maps"); } dm_ports SEC(".maps");
SEC("xdp_redir") SEC("xdp")
int xdp_redir_prog(struct xdp_md *ctx) int xdp_redir_prog(struct xdp_md *ctx)
{ {
return bpf_redirect_map(&dm_ports, 1, 0); return bpf_redirect_map(&dm_ports, 1, 0);
...@@ -18,7 +18,7 @@ int xdp_redir_prog(struct xdp_md *ctx) ...@@ -18,7 +18,7 @@ int xdp_redir_prog(struct xdp_md *ctx)
/* invalid program on DEVMAP entry; /* invalid program on DEVMAP entry;
* SEC name means expected attach type not set * SEC name means expected attach type not set
*/ */
SEC("xdp_dummy") SEC("xdp")
int xdp_dummy_prog(struct xdp_md *ctx) int xdp_dummy_prog(struct xdp_md *ctx)
{ {
return XDP_PASS; return XDP_PASS;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
SEC("xdp_dummy") SEC("xdp")
int xdp_dummy_prog(struct xdp_md *ctx) int xdp_dummy_prog(struct xdp_md *ctx)
{ {
return XDP_PASS; return XDP_PASS;
......
...@@ -34,7 +34,7 @@ struct { ...@@ -34,7 +34,7 @@ struct {
__uint(max_entries, 128); __uint(max_entries, 128);
} mac_map SEC(".maps"); } mac_map SEC(".maps");
SEC("xdp_redirect_map_multi") SEC("xdp")
int xdp_redirect_map_multi_prog(struct xdp_md *ctx) int xdp_redirect_map_multi_prog(struct xdp_md *ctx)
{ {
void *data_end = (void *)(long)ctx->data_end; void *data_end = (void *)(long)ctx->data_end;
...@@ -63,7 +63,7 @@ int xdp_redirect_map_multi_prog(struct xdp_md *ctx) ...@@ -63,7 +63,7 @@ int xdp_redirect_map_multi_prog(struct xdp_md *ctx)
} }
/* The following 2 progs are for 2nd devmap prog testing */ /* The following 2 progs are for 2nd devmap prog testing */
SEC("xdp_redirect_map_ingress") SEC("xdp")
int xdp_redirect_map_all_prog(struct xdp_md *ctx) int xdp_redirect_map_all_prog(struct xdp_md *ctx)
{ {
return bpf_redirect_map(&map_egress, 0, return bpf_redirect_map(&map_egress, 0,
......
...@@ -86,7 +86,7 @@ static __always_inline int icmp_check(struct xdp_md *ctx, int type) ...@@ -86,7 +86,7 @@ static __always_inline int icmp_check(struct xdp_md *ctx, int type)
return XDP_TX; return XDP_TX;
} }
SEC("xdpclient") SEC("xdp")
int xdping_client(struct xdp_md *ctx) int xdping_client(struct xdp_md *ctx)
{ {
void *data_end = (void *)(long)ctx->data_end; void *data_end = (void *)(long)ctx->data_end;
...@@ -150,7 +150,7 @@ int xdping_client(struct xdp_md *ctx) ...@@ -150,7 +150,7 @@ int xdping_client(struct xdp_md *ctx)
return XDP_TX; return XDP_TX;
} }
SEC("xdpserver") SEC("xdp")
int xdping_server(struct xdp_md *ctx) int xdping_server(struct xdp_md *ctx)
{ {
void *data_end = (void *)(long)ctx->data_end; void *data_end = (void *)(long)ctx->data_end;
......
...@@ -77,7 +77,7 @@ TEST_IF=lo ...@@ -77,7 +77,7 @@ TEST_IF=lo
MAX_PING_TRIES=5 MAX_PING_TRIES=5
BPF_PROG_OBJ="${DIR}/test_tcp_check_syncookie_kern.o" BPF_PROG_OBJ="${DIR}/test_tcp_check_syncookie_kern.o"
CLSACT_SECTION="clsact/check_syncookie" CLSACT_SECTION="clsact/check_syncookie"
XDP_SECTION="xdp/check_syncookie" XDP_SECTION="xdp"
BPF_PROG_ID=0 BPF_PROG_ID=0
PROG="${DIR}/test_tcp_check_syncookie_user" PROG="${DIR}/test_tcp_check_syncookie_user"
......
...@@ -52,8 +52,8 @@ test_xdp_redirect() ...@@ -52,8 +52,8 @@ test_xdp_redirect()
return 0 return 0
fi fi
ip -n ns1 link set veth11 $xdpmode obj xdp_dummy.o sec xdp_dummy &> /dev/null ip -n ns1 link set veth11 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null
ip -n ns2 link set veth22 $xdpmode obj xdp_dummy.o sec xdp_dummy &> /dev/null ip -n ns2 link set veth22 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null
ip link set dev veth1 $xdpmode obj test_xdp_redirect.o sec redirect_to_222 &> /dev/null ip link set dev veth1 $xdpmode obj test_xdp_redirect.o sec redirect_to_222 &> /dev/null
ip link set dev veth2 $xdpmode obj test_xdp_redirect.o sec redirect_to_111 &> /dev/null ip link set dev veth2 $xdpmode obj test_xdp_redirect.o sec redirect_to_111 &> /dev/null
......
...@@ -88,7 +88,7 @@ setup_ns() ...@@ -88,7 +88,7 @@ setup_ns()
# Add a neigh entry for IPv4 ping test # Add a neigh entry for IPv4 ping test
ip -n ns$i neigh add 192.0.2.253 lladdr 00:00:00:00:00:01 dev veth0 ip -n ns$i neigh add 192.0.2.253 lladdr 00:00:00:00:00:01 dev veth0
ip -n ns$i link set veth0 $mode obj \ ip -n ns$i link set veth0 $mode obj \
xdp_dummy.o sec xdp_dummy &> /dev/null || \ xdp_dummy.o sec xdp &> /dev/null || \
{ test_fail "Unable to load dummy xdp" && exit 1; } { test_fail "Unable to load dummy xdp" && exit 1; }
IFACES="$IFACES veth$i" IFACES="$IFACES veth$i"
veth_mac[$i]=$(ip link show veth$i | awk '/link\/ether/ {print $2}') veth_mac[$i]=$(ip link show veth$i | awk '/link\/ether/ {print $2}')
......
...@@ -107,9 +107,9 @@ ip link set dev veth1 xdp pinned $BPF_DIR/progs/redirect_map_0 ...@@ -107,9 +107,9 @@ ip link set dev veth1 xdp pinned $BPF_DIR/progs/redirect_map_0
ip link set dev veth2 xdp pinned $BPF_DIR/progs/redirect_map_1 ip link set dev veth2 xdp pinned $BPF_DIR/progs/redirect_map_1
ip link set dev veth3 xdp pinned $BPF_DIR/progs/redirect_map_2 ip link set dev veth3 xdp pinned $BPF_DIR/progs/redirect_map_2
ip -n ns1 link set dev veth11 xdp obj xdp_dummy.o sec xdp_dummy ip -n ns1 link set dev veth11 xdp obj xdp_dummy.o sec xdp
ip -n ns2 link set dev veth22 xdp obj xdp_tx.o sec xdp ip -n ns2 link set dev veth22 xdp obj xdp_tx.o sec xdp
ip -n ns3 link set dev veth33 xdp obj xdp_dummy.o sec xdp_dummy ip -n ns3 link set dev veth33 xdp obj xdp_dummy.o sec xdp
trap cleanup EXIT trap cleanup EXIT
......
...@@ -178,9 +178,8 @@ int main(int argc, char **argv) ...@@ -178,9 +178,8 @@ int main(int argc, char **argv)
return 1; return 1;
} }
main_prog = bpf_object__find_program_by_title(obj, main_prog = bpf_object__find_program_by_name(obj,
server ? "xdpserver" : server ? "xdping_server" : "xdping_client");
"xdpclient");
if (main_prog) if (main_prog)
prog_fd = bpf_program__fd(main_prog); prog_fd = bpf_program__fd(main_prog);
if (!main_prog || prog_fd < 0) { if (!main_prog || prog_fd < 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment