meshwizard: ipv6 fixes, fix uhttpd setup
[oweals/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / setup_network.sh
index 90e6248c4e35fe8fc1cfae49966f3f3c45421dd7..325475fa6ebffcf9acc815ea4e42898748478cf1 100755 (executable)
@@ -1,23 +1,41 @@
 # setup entry in /etc/config/network for a interface
 # Argument $1: network interface
-
 net="$1"
-. /etc/functions.sh
+. /lib/functions.sh
 . $dir/functions.sh
 
 # Setup a (new) interface section for $net
 
-ipaddr=$(uci get meshwizard.netconfig.$net\_ip4addr)
+ipaddr=$(uci -q get meshwizard.netconfig.$net\_ip4addr)
+ip6addr=$(uci -q get meshwizard.netconfig.$net\_ip6addr)
 [ -z "$ipaddr" ] && msg_missing_value meshwizard $net\_ip4addr
-[ -z "$interface_netmask" ] && interface netmask="255.255.0.0"
+
+netmask=$(uci -q get meshwizard.netconfig.$net\_netmask)
+[ -z "$netmask" ] && netmask="$interface_netmask"
+[ -z "$netmask" ] && netmask="255.255.0.0"
+
+uci set network.$netrenamed="interface"
+set_defaults "interface_" network.$netrenamed
 
 uci batch << EOF
-       set network.$netrenamed="interface"
        set network.$netrenamed.proto="static"
        set network.$netrenamed.ipaddr="$ipaddr"
+       set network.$netrenamed.netmask="$netmask"
 EOF
 
-set_defaults "interface_" network.$netrenamed
+# Setup IPv6 for the interface
+local ip6addr
+if [ "$ipv6_enabled" = 1 ]; then
+       if [ "$ipv6_config" = "auto-ipv6-dhcpv6" ]; then
+               ip6addr="$($dir/helpers/gen_auto-ipv6-dhcpv6-ip.sh $netrenamed)"
+               uci set network.$netrenamed.ip6addr="${ip6addr}/112"
+       fi
+       if [ "$ipv6_config" = "static" ] && [ -n "$ip6addr" ]; then
+               uci set network.$netrenamed.ip6addr="$ip6addr"
+       fi
+fi
+
 uci_commitverbose "Setup interface $netrenamed" network
 
 # setup dhcp alias/interface
@@ -66,8 +84,7 @@ if [ "$net_dhcp" == 1 ]; then
                set network.${netrenamed}dhcp.proto=static
                set network.${netrenamed}dhcp.ipaddr="$START"
                set network.${netrenamed}dhcp.netmask="$NETMASK"
-               uci_commitverbose  "Setup interface for ${netrenamed}dhcp" network
        EOF
+       uci_commitverbose  "Setup interface for ${netrenamed}dhcp" network
 
 fi
-