network/config/xfrm: add host-dependency for xfrm interface parent
[librecmc/librecmc.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         [ -z "$tunlink" ] && {
18                 proto_notify_error "$cfg" NO_TUNLINK
19                 proto_block_restart "$cfg"
20                 exit
21         }
22
23         [ -z "$ifid" ] && {
24                 proto_notify_error "$cfg" NO_IFID
25                 proto_block_restart "$cfg"
26                 exit
27         }
28
29         ( proto_add_host_dependency "$cfg" '' "$tunlink" )
30
31         proto_init_update "$cfg" 1
32
33         proto_add_tunnel
34         json_add_string mode "$mode"
35         json_add_int mtu "${mtu:-1280}"
36
37         json_add_string link "$tunlink"
38
39         json_add_object 'data'
40         [ -n "$ifid" ] && json_add_int ifid "$ifid"
41         json_close_object
42
43         proto_close_tunnel
44
45         proto_add_data
46         [ -n "$zone" ] && json_add_string zone "$zone"
47         proto_close_data
48
49         proto_send_update "$cfg"
50 }
51
52 proto_xfrm_teardown() {
53         local cfg="$1"
54 }
55
56 proto_xfrm_init_config() {
57         no_device=1
58         available=1
59
60         proto_config_add_int "mtu"
61         proto_config_add_string "tunlink"
62         proto_config_add_string "zone"
63         proto_config_add_int "ifid"
64 }
65
66
67 [ -n "$INCLUDE_ONLY" ] || {
68         [ -f /lib/modules/$(uname -r)/xfrm_interface.ko -o -d /sys/module/xfrm_interface ] && add_protocol xfrm
69 }