File tree Expand file tree Collapse file tree 4 files changed +86
-3
lines changed Expand file tree Collapse file tree 4 files changed +86
-3
lines changed Original file line number Diff line number Diff line change @@ -592,7 +592,8 @@ union bpf_attr {
592
592
FN(get_socket_uid), \
593
593
FN(set_hash), \
594
594
FN(setsockopt), \
595
- FN(skb_adjust_room),
595
+ FN(skb_adjust_room), \
596
+ FN(redirect_map),
596
597
597
598
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
598
599
* function eBPF program intends to call
Original file line number Diff line number Diff line change @@ -15,9 +15,9 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
15
15
test_align
16
16
17
17
TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
18
- test_pkt_md_access.o
18
+ test_pkt_md_access.o test_xdp_redirect.o
19
19
20
- TEST_PROGS := test_kmod.sh
20
+ TEST_PROGS := test_kmod.sh test_xdp_redirect.sh
21
21
22
22
include ../lib.mk
23
23
Original file line number Diff line number Diff line change
1
+ /* Copyright (c) 2017 VMware
2
+ *
3
+ * This program is free software; you can redistribute it and/or
4
+ * modify it under the terms of version 2 of the GNU General Public
5
+ * License as published by the Free Software Foundation.
6
+ *
7
+ * This program is distributed in the hope that it will be useful, but
8
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ * General Public License for more details.
11
+ */
12
+ #include <linux/bpf.h>
13
+ #include "bpf_helpers.h"
14
+
15
+ int _version SEC ("version" ) = 1 ;
16
+
17
+ SEC ("redirect_to_111" )
18
+ int xdp_redirect_to_111 (struct xdp_md * xdp )
19
+ {
20
+ return bpf_redirect (111 , 0 );
21
+ }
22
+ SEC ("redirect_to_222" )
23
+ int xdp_redirect_to_222 (struct xdp_md * xdp )
24
+ {
25
+ return bpf_redirect (222 , 0 );
26
+ }
27
+
28
+ char _license [] SEC ("license" ) = "GPL" ;
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ # Create 2 namespaces with two veth peers, and
3
+ # forward packets in-between using generic XDP
4
+ #
5
+ # NS1(veth11) NS2(veth22)
6
+ # | |
7
+ # | |
8
+ # (veth1, ------ (veth2,
9
+ # id:111) id:222)
10
+ # | xdp forwarding |
11
+ # ------------------
12
+
13
+ cleanup ()
14
+ {
15
+ if [ " $? " = " 0" ]; then
16
+ echo " selftests: test_xdp_redirect [PASS]" ;
17
+ else
18
+ echo " selftests: test_xdp_redirect [FAILED]" ;
19
+ fi
20
+
21
+ set +e
22
+ ip netns del ns1 2> /dev/null
23
+ ip netns del ns2 2> /dev/null
24
+ }
25
+
26
+ set -e
27
+
28
+ ip netns add ns1
29
+ ip netns add ns2
30
+
31
+ trap cleanup 0 2 3 6 9
32
+
33
+ ip link add veth1 index 111 type veth peer name veth11
34
+ ip link add veth2 index 222 type veth peer name veth22
35
+
36
+ ip link set veth11 netns ns1
37
+ ip link set veth22 netns ns2
38
+
39
+ ip link set veth1 up
40
+ ip link set veth2 up
41
+
42
+ ip netns exec ns1 ip addr add 10.1.1.11/24 dev veth11
43
+ ip netns exec ns2 ip addr add 10.1.1.22/24 dev veth22
44
+
45
+ ip netns exec ns1 ip link set dev veth11 up
46
+ ip netns exec ns2 ip link set dev veth22 up
47
+
48
+ ip link set dev veth1 xdpgeneric obj test_xdp_redirect.o sec redirect_to_222
49
+ ip link set dev veth2 xdpgeneric obj test_xdp_redirect.o sec redirect_to_111
50
+
51
+ ip netns exec ns1 ping -c 1 10.1.1.22
52
+ ip netns exec ns2 ping -c 1 10.1.1.11
53
+
54
+ exit 0
You can’t perform that action at this time.
0 commit comments