ds-lite: add support for fqdn peeraddrs
[openwrt/svn-archive/archive.git] / package / network / ipv6 / ds-lite / files / dslite.sh
index f4efa1c4c331a7de4df1739cc321e62fb55cc32d..7b686390b3e8bec03dc8f28bf0f5059869a3c691 100755 (executable)
@@ -14,8 +14,8 @@ proto_dslite_setup() {
        local iface="$2"
        local link="dslite-$cfg"
 
-       local mtu ttl peeraddr ip6addr tunlink zone
-       json_get_vars mtu ttl peeraddr ip6addr tunlink zone
+       local mtu ttl peeraddr ip6addr tunlink zone weakif
+       json_get_vars mtu ttl peeraddr ip6addr tunlink zone weakif
 
        [ -z "$peeraddr" ] && {
                proto_notify_error "$cfg" "MISSING_ADDRESS"
@@ -25,6 +25,17 @@ proto_dslite_setup() {
 
        ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
 
+       peeraddr=$(resolveip -6 $peeraddr)
+       if [ -z "$peeraddr" ]; then
+               sleep 3
+               peeraddr=$(resolveip -6 $peeraddr)
+               if [ -z "$peeraddr" ]; then
+                       proto_notify_error "$cfg" "AFTR_DNS_FAIL"
+                       return
+               fi
+       fi
+       peeraddr="${peeraddr%% *}"
+
        [ -z "$ip6addr" ] && {
                local wanif="$tunlink"
                if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
@@ -33,8 +44,11 @@ proto_dslite_setup() {
                fi
 
                if ! network_get_ipaddr6 ip6addr "$wanif"; then
-                       proto_notify_error "$cfg" "NO_WAN_LINK"
-                       return
+                       [ -z "$weakif" ] && weakif="lan"
+                       if ! network_get_ipaddr6 ip6addr "$weakif"; then
+                               proto_notify_error "$cfg" "NO_WAN_LINK"
+                               return
+                       fi
                fi
        }
 
@@ -53,6 +67,13 @@ proto_dslite_setup() {
 
        proto_add_data
        [ -n "$zone" ] && json_add_string zone "$zone"
+
+       json_add_array firewall
+         json_add_object ""
+           json_add_string type nat
+           json_add_string target ACCEPT
+         json_close_object
+       json_close_array
        proto_close_data
 
        proto_send_update "$cfg"
@@ -72,6 +93,7 @@ proto_dslite_init_config() {
        proto_config_add_int "mtu"
        proto_config_add_int "ttl"
        proto_config_add_string "zone"
+       proto_config_add_string "weakif"
 }
 
 [ -n "$INCLUDE_ONLY" ] || {