[backfire] merge r27449
[openwrt-10.03/.git] / package / 6to4 / files / 6to4.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" = 6to4 ] || return 0
15
16                 local wandev
17                 config_get wandev "$cfg" wan_device "$(find_6to4_wanif)"
18                 [ "$wandev" = "$DEVICE" ] || return 0
19
20                 local wanip=$(find_6to4_wanip "$wandev")
21
22                 [ -n "$wanip" ] && {
23                         lsmod | grep -q ^sit || {
24                                 logger -t 6to4 "Tunneling driver not loaded yet, deferring action"
25                                 exit 0
26                         }
27
28                         uci_set_state network "$cfg" ipaddr "$wanip"
29                         ( ifup "$cfg" )&
30                 }
31         }
32
33         config_foreach update_tunnel interface
34 fi