xfrm: simplify the check for necessary kernel support
[openwrt/staging/dedeckeh.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 multicast
15 json_get_vars tunlink ifid mtu zone multicast
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_boolean multicast "${multicast:-1}"
40
41 json_add_object 'data'
42 [ -n "$ifid" ] && json_add_int ifid "$ifid"
43 json_close_object
44
45 proto_close_tunnel
46
47 proto_add_data
48 [ -n "$zone" ] && json_add_string zone "$zone"
49 proto_close_data
50
51 proto_send_update "$cfg"
52 }
53
54 proto_xfrm_teardown() {
55 local cfg="$1"
56 }
57
58 proto_xfrm_init_config() {
59 no_device=1
60 available=1
61
62 proto_config_add_int "mtu"
63 proto_config_add_string "tunlink"
64 proto_config_add_string "zone"
65 proto_config_add_int "ifid"
66 proto_config_add_boolean "multicast"
67 }
68
69
70 [ -n "$INCLUDE_ONLY" ] || {
71 [ -d /sys/module/xfrm_interface ] && add_protocol xfrm
72 }