add bpf-examples and package 'preserve-dscp' example
[openwrt/staging/dangole.git] / package / network / utils / bpf-examples / files / wireguard-preserve-dscp.init
1 #!/bin/sh /etc/rc.common
2
3 START=90
4
5 USE_PROCD=1
6
7 BPF_OBJ_PATH="/usr/lib/bpf"
8 PROG="/usr/sbin/preserve-dscp"
9
10 scriptfile=$(readlink -f "$initscript")
11 PKGNAME=$(basename ${scriptfile:-$initscript})
12
13 preserve_dscp() {
14 cd "$BPF_OBJ_PATH"
15 echo "$PROG $@" | logger -t "$PKGNAME"
16 ulimit -l unlimited
17 "$PROG" "$@" 2>&1 | logger -t "$PKGNAME"
18 }
19
20 setup_preserve_if() {
21 local iiface="$1"
22 local proto oiface
23
24 config_get proto "$iiface" "proto"
25 config_get oiface "$iiface" "preserve_dscp_if"
26
27 if [ "$proto" = "wireguard" ]; then
28 procd_add_reload_interface_trigger "$iiface"
29 [ "$oiface" ] && procd_add_reload_interface_trigger "$oiface"
30 fi
31 }
32
33 check_preserve_if() {
34 local iiface="$1"
35 local action="$2"
36 local proto oiface idev odev
37
38 config_get proto "$iiface" "proto"
39 config_get oiface "$iiface" "preserve_dscp_if"
40 network_get_device odev "$oiface"
41 network_get_device idev "$iiface"
42
43 if [ "$proto" = "wireguard" ] && [ "$idev" ] && [ "$odev" ]; then
44 case "$action" in
45 start)
46 preserve_dscp "$idev" "$odev" --unload
47 preserve_dscp "$idev" "$odev"
48 ;;
49 stop)
50 preserve_dscp "$idev" "$odev" --unload
51 ;;
52 esac
53 fi
54 }
55
56 service_triggers() {
57 . "/lib/functions/network.sh"
58
59 config_load "network"
60 config_foreach setup_preserve_if "interface"
61 }
62
63 start_service() {
64 . "/lib/functions/network.sh"
65
66 config_load "network"
67 config_foreach check_preserve_if "interface" start
68 }
69
70 stop_service() {
71 . "/lib/functions/network.sh"
72
73 config_load "network"
74 config_foreach check_preserve_if "interface" stop
75 }