gre: Remove ttl default value assignment (FS#312)
[openwrt/openwrt.git] / package / network / config / gre / files / gre.sh
index 38c0fc4841044ed0e66dadf8961b37e06ae9afed..58db1d1381eb63347a2b229135bf7dfc34cbc7c0 100755 (executable)
@@ -13,10 +13,11 @@ gre_generic_setup() {
        local local="$3"
        local remote="$4"
        local link="$5"
-       local mtu ttl zone ikey okey icsum ocsum iseqno oseqno
-       json_get_vars mtu ttl zone ikey okey icsum ocsum iseqno oseqno
+       local mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno multicast
+       json_get_vars mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno multicast
 
        [ -z "$zone" ] && zone="wan"
+       [ -z "$multicast" ] && multicast=1
 
        proto_init_update "$link" 1
 
@@ -24,7 +25,9 @@ gre_generic_setup() {
        json_add_string mode "$mode"
        json_add_int mtu "${mtu:-1280}"
        [ -n "$df" ] && json_add_boolean df "$df"
-       json_add_int ttl "${ttl:-64}"
+       [ -n "ttl" ] && json_add_int ttl "$ttl"
+       [ -n "$tos" ] && json_add_string tos "$tos"
+       json_add_boolean multicast "$multicast"
        json_add_string local "$local"
        json_add_string remote "$remote"
        [ -n "$tunlink" ] && json_add_string link "$tunlink"
@@ -41,17 +44,30 @@ gre_generic_setup() {
 gre_setup() {
        local cfg="$1"
        local mode="$2"
+       local remoteip
 
        local ipaddr peeraddr
        json_get_vars df ipaddr peeraddr tunlink
 
        [ -z "$peeraddr" ] && {
-               proto_notify_error "$cfg" "MISSING_ADDRESS"
+               proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
                proto_block_restart "$cfg"
                exit
        }
 
-       ( proto_add_host_dependency "$cfg" "0.0.0.0" "$tunlink" )
+       remoteip=$(resolveip -t 10 -4 "$peeraddr")
+
+       if [ -z "$remoteip" ]; then
+               proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
+               exit
+       fi
+
+       for ip in $remoteip; do
+               peeraddr=$ip
+               break
+       done
+
+       ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
 
        [ -z "$ipaddr" ] && {
                local wanif="$tunlink"
@@ -98,17 +114,30 @@ proto_gretap_setup() {
 grev6_setup() {
        local cfg="$1"
        local mode="$2"
+       local remoteip6
 
        local ip6addr peer6addr weakif
        json_get_vars ip6addr peer6addr tunlink weakif
 
        [ -z "$peer6addr" ] && {
-               proto_notify_error "$cfg" "MISSING_ADDRESS"
+               proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
                proto_block_restart "$cfg"
                exit
        }
 
-       ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
+       remoteip6=$(resolveip -t 10 -6 "$peer6addr")
+
+       if [ -z "$remoteip6" ]; then
+               proto_notify_error "$cfg" "PEER_RESOLVE_FAIL"
+               exit
+       fi
+
+       for ip6 in $remoteip6; do
+               peer6addr=$ip6
+               break
+       done
+
+       ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
 
        [ -z "$ip6addr" ] && {
                local wanif="$tunlink"
@@ -193,6 +222,7 @@ gre_generic_init_config() {
 
        proto_config_add_int "mtu"
        proto_config_add_int "ttl"
+       proto_config_add_string "tos"
        proto_config_add_string "tunlink"
        proto_config_add_string "zone"
        proto_config_add_int "ikey"
@@ -201,6 +231,7 @@ gre_generic_init_config() {
        proto_config_add_boolean "ocsum"
        proto_config_add_boolean "iseqno"
        proto_config_add_boolean "oseqno"
+       proto_config_add_boolean "multicast"
 }
 
 proto_gre_init_config() {