[package] 6in4:
[openwrt/svn-archive/archive.git] / package / 6in4 / files / 6in4.hotplug
1 #!/bin/sh
2
3 if [ "$ACTION" = ifup ]; then
4 . /etc/functions.sh
5
6 include /lib/network
7 scan_interfaces
8
9 update_tunnel() {
10 local cfg="$1"
11
12 local proto
13 config_get proto "$cfg" proto
14 [ "$proto" = 6in4 ] || return 0
15
16 local wandev
17 config_get wandev "$cfg" wan_device
18 [ "$wandev" = "$DEVICE" ] || return 0
19
20 local oldip
21 local wanip=$(find_6in4_wanip "$wandev")
22 config_get oldip "$cfg" ipaddr
23
24 [ -n "$wanip" ] && [ "$oldip" != "$wanip" ] && {
25 local tunnelid
26 config_get tunnelid "$cfg" tunnelid
27
28 local username
29 config_get username "$cfg" username
30
31 local password
32 config_get password "$cfg" password
33
34 [ -n "$tunnelid" ] && [ -n "$username" ] && [ -n "$password" ] && {
35 password="$(echo -n "$password" | md5sum)"; password="${password%% *}"
36 uci_set_state network "$cfg" ipaddr "$wanip"
37
38 ( wget -qO/dev/null "http://ipv4.tunnelbroker.net/ipv4_end.php?ipv4b=AUTO&user_id=$username&pass=$password&tunnel_id=$tunnelid" && ifup "$cfg" )&
39 }
40 }
41 }
42
43 config_foreach update_tunnel interface
44 fi