6rd: pass ipcalc as argument to eval
[openwrt/openwrt.git] / package / network / ipv6 / 6rd / files / 6rd.sh
index b48513640e848535cb51d82cdf4c7d040235e782..62a20314d9322b56a3785f9f4b5adf7523a2460d 100644 (file)
@@ -14,8 +14,8 @@ proto_6rd_setup() {
        local iface="$2"
        local link="6rd-$cfg"
 
-       local mtu df ttl tos ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen tunlink sourcerouting zone
-       json_get_vars mtu df ttl tos ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen tunlink sourcerouting zone
+       local mtu df ttl tos ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen tunlink zone
+       json_get_vars mtu df ttl tos ipaddr peeraddr ip6prefix ip6prefixlen ip4prefixlen tunlink zone
 
        [ -z "$ip6prefix" -o -z "$peeraddr" ] && {
                proto_notify_error "$cfg" "MISSING_ADDRESS"
@@ -40,8 +40,8 @@ proto_6rd_setup() {
 
        # Determine the relay prefix.
        local ip4prefixlen="${ip4prefixlen:-0}"
-       local ip4prefix=$(ipcalc.sh "$ipaddr/$ip4prefixlen" | grep NETWORK)
-       ip4prefix="${ip4prefix#NETWORK=}"
+       local ip4prefix
+       eval "$(ipcalc.sh "$ipaddr/$ip4prefixlen")";ip4prefix=$NETWORK
 
        # Determine our IPv6 address.
        local ip6subnet=$(6rdcalc "$ip6prefix/$ip6prefixlen" "$ipaddr/$ip4prefixlen")
@@ -54,13 +54,8 @@ proto_6rd_setup() {
        proto_add_ipv6_address "$ip6addr" "$ip6prefixlen"
        proto_add_ipv6_prefix "$ip6lanprefix"
 
-       if [ "$sourcerouting" != "0" ]; then
-               proto_add_ipv6_route "::" 0 "::$peeraddr" 4096 "" "::/128"
-               proto_add_ipv6_route "::" 0 "::$peeraddr" 4096 "" "$ip6addr/$ip6prefixlen"
-               proto_add_ipv6_route "::" 0 "::$peeraddr" 4096 "" "$ip6lanprefix"
-       else
-               proto_add_ipv6_route "::" 0 "::$peeraddr" 4096
-       fi
+       proto_add_ipv6_route "::" 0 "::$peeraddr" 4096 "" "$ip6addr/$ip6prefixlen"
+       proto_add_ipv6_route "::" 0 "::$peeraddr" 4096 "" "$ip6lanprefix"
 
        proto_add_tunnel
        json_add_string mode sit
@@ -69,9 +64,13 @@ proto_6rd_setup() {
        json_add_int ttl "${ttl:-64}"
        [ -n "$tos" ] && json_add_string tos "$tos"
        json_add_string local "$ipaddr"
-       json_add_string 6rd-prefix "$ip6prefix/$ip6prefixlen"
-       json_add_string 6rd-relay-prefix "$ip4prefix/$ip4prefixlen"
        [ -n "$tunlink" ] && json_add_string link "$tunlink"
+
+       json_add_object 'data'
+       json_add_string prefix "$ip6prefix/$ip6prefixlen"
+       json_add_string relay-prefix "$ip4prefix/$ip4prefixlen"
+       json_close_object
+
        proto_close_tunnel
 
        proto_add_data
@@ -99,7 +98,6 @@ proto_6rd_init_config() {
        proto_config_add_string "ip6prefixlen"
        proto_config_add_string "ip4prefixlen"
        proto_config_add_string "tunlink"
-       proto_config_add_boolean "sourcerouting"
        proto_config_add_string "zone"
 }