-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstand
executable file
·60 lines (50 loc) · 1.35 KB
/
stand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
[ $# -ge 1 ] || { echo >&2 "Usage: $0 {up|down|status|attach|detach|log|exec|listen}"; exit 1; }
[ $UID -eq 0 ] || { echo >&2 "This script requires root."; exit 1; }
action="$1"
netns=xdp-test
local=xdp-local
remote=xdp-remote
dummy=xdp_dummy.o
filter=xdp_filter.o
case "$action" in
up)
ip netns add ${netns}
ip link add ${remote} type veth peer name ${local}
ip link set ${remote} netns ${netns}
ip netns exec ${netns} ip address add 192.0.2.2/24 dev ${remote}
ip netns exec ${netns} ip link set ${remote} up
ip address add 192.0.2.1/24 dev ${local}
ip link set ${local} up
;;
down)
ip netns delete ${netns}
ip link delete ${local}
;;
status)
if ip netns list | grep ${netns} 2>&1 >/dev/null; then
echo "Stand is UP."
else
echo "Stand is DOWN."
fi
;;
attach)
ip netns exec ${netns} ip -force link set dev ${remote} xdp object ${dummy} >/dev/null
ip -force link set dev ${local} xdp object ${filter} verbose
;;
detach)
ip netns exec ${netns} ip link set dev ${remote} xdp off
ip link set dev ${local} xdp off
;;
log)
echo -n 1 > /sys/kernel/debug/tracing/options/trace_printk
cat /sys/kernel/debug/tracing/trace_pipe
;;
exec)
shift
ip netns exec ${netns} $@
;;
listen)
ip netns exec ${netns} tcpdump -tnevi ${remote} not ip6
;;
esac