config: add xfrm interface support scripts
[openwrt/openwrt.git] / package / network / config / xfrm / files / xfrm.sh
1 #!/bin/sh
2
3 [ -n "$INCLUDE_ONLY" ] || {
4 . /lib/functions.sh
5 . /lib/functions/network.sh
6 . ../netifd-proto.sh
7 init_proto "$@"
8 }
9
10 proto_xfrm_setup() {
11 local cfg="$1"
12 local mode="xfrm"
13
14 local tunlink ifid mtu zone
15 json_get_vars tunlink ifid mtu zone
16
17 proto_init_update "$cfg" 1
18
19 proto_add_tunnel
20 json_add_string mode "$mode"
21 json_add_int mtu "${mtu:-1280}"
22
23 [ -z "$tunlink" ] && {
24 proto_notify_error "$cfg" NO_TUNLINK
25 proto_block_restart "$cfg"
26 exit
27 }
28 json_add_string link "$tunlink"
29
30 [ -z "$ifid" ] && {
31 proto_notify_error "$cfg" NO_IFID
32 proto_block_restart "$cfg"
33 exit
34 }
35 json_add_object 'data'
36 [ -n "$ifid" ] && json_add_int ifid "$ifid"
37 json_close_object
38
39 proto_close_tunnel
40
41 proto_add_data
42 [ -n "$zone" ] && json_add_string zone "$zone"
43 proto_close_data
44
45 proto_send_update "$cfg"
46 }
47
48 proto_xfrm_teardown() {
49 local cfg="$1"
50 }
51
52 proto_xfrm_init_config() {
53 no_device=1
54 available=1
55
56 proto_config_add_int "mtu"
57 proto_config_add_string "tunlink"
58 proto_config_add_string "zone"
59 proto_config_add_int "ifid"
60 }
61
62
63 [ -n "$INCLUDE_ONLY" ] || {
64 [ -f /lib/modules/$(uname -r)/xfrm_interface.ko -o -d /sys/module/xfrm_interface ] && add_protocol xfrm
65 }