Ignore:
Timestamp:
2010-05-29T00:03:30+02:00 (6 years ago)
Author:
jow
Message:

[package] 6in4:

  • support to automatically determine the local endpoint address from the current IPv4 default gateway
  • support updating the tunnel endpoint for he.net
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/6in4/files/6in4.sh

    r21589 r21612  
    11# 6in4.sh - IPv6-in-IPv4 tunnel backend 
    22# Copyright (c) 2010 OpenWrt.org 
     3 
     4find_6in4_wanif() { 
     5        local if=$(ip -4 r l e 0/0); if="${if#default via * dev }"; if="${if%% *}" 
     6        [ -n "$if" ] && grep -qs "^ *$if:" /proc/net/dev && echo "$if" 
     7} 
     8 
     9find_6in4_wanip() { 
     10        local ip=$(ip -4 a s dev "$1"); ip="${ip#*inet }" 
     11        echo "${ip%%/[0-9]* brd *}" 
     12} 
    313 
    414# Hook into scan_interfaces() to synthesize a .device option 
     
    3747        config_get_bool defaultroute "$cfg" defaultroute 1 
    3848 
    39  
    40         # creating the tunnel below will trigger a net subsystem event 
    41         # prevent it from touching or iface by disabling .auto here 
    42         uci_set_state network "$cfg" ifname $link 
    43         uci_set_state network "$cfg" auto 0 
    44  
    45         ip tunnel add $link mode sit remote $remote4 local $local4 ttl 255 
    46         ip link set $link up 
    47         ip link set mtu ${mtu:-1280} dev $link 
    48         ip tunnel change $link ttl ${ttl:-64} 
    49         ip addr add $local6 dev $link 
    50  
    51         uci_set_state network "$cfg" ip6addr $local6 
    52  
    53         [ "$defaultroute" = 1 ] && { 
    54                 ip -6 route add ::/0 dev $link 
    55                 uci_set_state network "$cfg" defaultroute 1 
     49        # If local4 is unset, guess local IPv4 address from the 
     50        # interface used by the default route. 
     51        [ -z "$local4" ] && { 
     52                local wanif=$(find_6in4_wanif) 
     53                [ -n "$wanif" ] && { 
     54                        local4=$(find_6in4_wanip "$wanif") 
     55                        uci_set_state network "$cfg" wan_device "$wanif" 
     56                } 
    5657        } 
    5758 
    58         env -i ACTION="ifup" INTERFACE="$cfg" DEVICE="$link" PROTO=6in4 /sbin/hotplug-call "iface" & 
     59        [ -n "$local4" ] && { 
     60                # creating the tunnel below will trigger a net subsystem event 
     61                # prevent it from touching or iface by disabling .auto here 
     62                uci_set_state network "$cfg" ifname $link 
     63                uci_set_state network "$cfg" auto 0 
     64 
     65                ip tunnel add $link mode sit remote $remote4 local $local4 ttl 255 
     66                ip link set $link up 
     67                ip link set mtu ${mtu:-1280} dev $link 
     68                ip tunnel change $link ttl ${ttl:-64} 
     69                ip addr add $local6 dev $link 
     70 
     71                uci_set_state network "$cfg" ipaddr $local4 
     72                uci_set_state network "$cfg" ip6addr $local6 
     73 
     74                [ "$defaultroute" = 1 ] && { 
     75                        ip -6 route add ::/0 dev $link 
     76                        uci_set_state network "$cfg" defaultroute 1 
     77                } 
     78 
     79                env -i ACTION="ifup" INTERFACE="$cfg" DEVICE="$link" PROTO=6in4 /sbin/hotplug-call "iface" & 
     80        } || { 
     81                echo "Cannot determine local IPv4 address for 6in4 tunnel $cfg - skipping" 
     82        } 
    5983} 
    6084 
Note: See TracChangeset for help on using the changeset viewer.