OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 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 | vti_generic_setup() { |
||
11 | local cfg="$1" |
||
12 | local mode="$2" |
||
13 | local local="$3" |
||
14 | local remote="$4" |
||
15 | local link="$5" |
||
16 | local mtu zone ikey |
||
17 | json_get_vars mtu zone ikey okey |
||
18 | |||
19 | proto_init_update "$link" 1 |
||
20 | |||
21 | proto_add_tunnel |
||
22 | json_add_string mode "$mode" |
||
23 | json_add_int mtu "${mtu:-1280}" |
||
24 | json_add_string local "$local" |
||
25 | json_add_string remote "$remote" |
||
26 | [ -n "$tunlink" ] && json_add_string link "$tunlink" |
||
27 | |||
28 | json_add_object 'data' |
||
29 | [ -n "$ikey" ] && json_add_int ikey "$ikey" |
||
30 | [ -n "$okey" ] && json_add_int okey "$okey" |
||
31 | json_close_object |
||
32 | |||
33 | proto_close_tunnel |
||
34 | |||
35 | proto_add_data |
||
36 | [ -n "$zone" ] && json_add_string zone "$zone" |
||
37 | proto_close_data |
||
38 | |||
39 | proto_send_update "$cfg" |
||
40 | } |
||
41 | |||
42 | vti_setup() { |
||
43 | local cfg="$1" |
||
44 | local mode="$2" |
||
45 | |||
46 | local ipaddr peeraddr |
||
47 | json_get_vars df ipaddr peeraddr tunlink |
||
48 | |||
49 | [ -z "$peeraddr" ] && { |
||
50 | proto_notify_error "$cfg" "MISSING_ADDRESS" |
||
51 | proto_block_restart "$cfg" |
||
52 | exit |
||
53 | } |
||
54 | |||
55 | ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" ) |
||
56 | |||
57 | [ -z "$ipaddr" ] && { |
||
58 | local wanif="$tunlink" |
||
59 | if [ -z $wanif ] && ! network_find_wan wanif; then |
||
60 | proto_notify_error "$cfg" "NO_WAN_LINK" |
||
61 | exit |
||
62 | fi |
||
63 | |||
64 | if ! network_get_ipaddr ipaddr "$wanif"; then |
||
65 | proto_notify_error "$cfg" "NO_WAN_LINK" |
||
66 | exit |
||
67 | fi |
||
68 | } |
||
69 | |||
70 | vti_generic_setup $cfg $mode $ipaddr $peeraddr "vti-$cfg" |
||
71 | } |
||
72 | |||
73 | proto_vti_setup() { |
||
74 | local cfg="$1" |
||
75 | |||
76 | vti_setup $cfg "vtiip" |
||
77 | } |
||
78 | |||
79 | vti6_setup() { |
||
80 | local cfg="$1" |
||
81 | local mode="$2" |
||
82 | |||
83 | local ip6addr peer6addr weakif |
||
84 | json_get_vars ip6addr peer6addr tunlink weakif |
||
85 | |||
86 | [ -z "$peer6addr" ] && { |
||
87 | proto_notify_error "$cfg" "MISSING_ADDRESS" |
||
88 | proto_block_restart "$cfg" |
||
89 | exit |
||
90 | } |
||
91 | |||
92 | ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" ) |
||
93 | |||
94 | [ -z "$ip6addr" ] && { |
||
95 | local wanif="$tunlink" |
||
96 | if [ -z $wanif ] && ! network_find_wan6 wanif; then |
||
97 | proto_notify_error "$cfg" "NO_WAN_LINK" |
||
98 | exit |
||
99 | fi |
||
100 | |||
101 | if ! network_get_ipaddr6 ip6addr "$wanif"; then |
||
102 | [ -z "$weakif" ] && weakif="lan" |
||
103 | if ! network_get_ipaddr6 ip6addr "$weakif"; then |
||
104 | proto_notify_error "$cfg" "NO_WAN_LINK" |
||
105 | exit |
||
106 | fi |
||
107 | fi |
||
108 | } |
||
109 | |||
110 | vti_generic_setup $cfg $mode $ip6addr $peer6addr "vti6-$cfg" |
||
111 | } |
||
112 | |||
113 | proto_vti6_setup() { |
||
114 | local cfg="$1" |
||
115 | |||
116 | vti6_setup $cfg "vtiip6" |
||
117 | } |
||
118 | |||
119 | proto_vti_teardown() { |
||
120 | local cfg="$1" |
||
121 | } |
||
122 | |||
123 | proto_vti6_teardown() { |
||
124 | local cfg="$1" |
||
125 | } |
||
126 | |||
127 | vti_generic_init_config() { |
||
128 | no_device=1 |
||
129 | available=1 |
||
130 | |||
131 | proto_config_add_int "mtu" |
||
132 | proto_config_add_string "tunlink" |
||
133 | proto_config_add_string "zone" |
||
134 | proto_config_add_int "ikey" |
||
135 | proto_config_add_int "okey" |
||
136 | } |
||
137 | |||
138 | proto_vti_init_config() { |
||
139 | vti_generic_init_config |
||
140 | proto_config_add_string "ipaddr" |
||
141 | proto_config_add_string "peeraddr" |
||
142 | } |
||
143 | |||
144 | proto_vti6_init_config() { |
||
145 | vti_generic_init_config |
||
146 | proto_config_add_string "ip6addr" |
||
147 | proto_config_add_string "peer6addr" |
||
148 | proto_config_add_string "weakif" |
||
149 | } |
||
150 | |||
151 | [ -n "$INCLUDE_ONLY" ] || { |
||
152 | [ -f /lib/modules/$(uname -r)/ip_vti.ko ] && add_protocol vti |
||
153 | [ -f /lib/modules/$(uname -r)/ip6_vti.ko ] && add_protocol vti6 |
||
154 | } |