# 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
netmask=$(uci -q get meshwizard.netconfig.$net\_netmask)
# Setup IPv6 for the interface
local ip6addr
-if [ "$profile_ipv6" = 1 ]; then
- if [ "$profile_ipv6_config" = "auto-ipv6-dhcpv6" ]; then
+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
fi
}
config_load network
- config_foreach handle_dhcpalias alias
+ config_foreach handle_dhcpalias interface
# Get IP/netmask and start-ip for $net dhcp
# If no dhcprange is given in /etc/config/meshwizard we autogenerate one
dhcprange="$($dir/helpers/gen_dhcp_ip.sh $interface_ip)/24"
uci set meshwizard.netconfig.${net}_dhcprange="$dhcprange"
fi
- eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange 1 0)
-
- # setup wifi-dhcp interface or alias
-
- # Setup alias for $net
- if [ "$vap" == 1 ]; then
- uci set network.${netrenamed}dhcp=interface
+ # If we use VAP and also offer dhcp on the adhoc interface then cut the dhcp
+ # range in two halves. one for the adhoc, one for the managed VAP interface
+ ahdhcp_when_vap="$(uci get profile_$community.profile.adhoc_dhcp_when_vap)"
+
+ if [ "$supports_vap" = 1 -a "$vap" = 1 -a "$ahdhcp_when_vap" = 1 ]; then
+ # VAPs are enabled for this interface, supported and we want to
+ # also use DHCP on the adhoc interface
+ local network
+ local mask
+ network=${dhcprange%%/*}
+ mask=${dhcprange##*/}
+ # Divide network size by adding 1 to the netmask
+ mask=$(($mask + 1))
+ # Get first ip and netmask for the adhoc dhcp network
+ eval $(sh $dir/helpers/ipcalc-cidr.sh ${network}/${mask} 1 0)
+ STARTADHOC=$START
+ NETMASKADHOC=$NETMASK
+ # Get first ip and netmask for the managed dhcp network
+ eval $(sh $dir/helpers/ipcalc-cidr.sh ${NEXTNET}/${mask} 1 0)
+ STARTVAP=$START
+ NETMASKVAP=$NETMASK
+ # Add dhcp interface
+ uci batch <<- EOF
+ set network.${netrenamed}dhcp=interface
+ set network.${netrenamed}dhcp.proto=static
+ set network.${netrenamed}dhcp.ipaddr="$STARTVAP"
+ set network.${netrenamed}dhcp.netmask="$NETMASKVAP"
+ EOF
+ uci_commitverbose "Setup interface for ${netrenamed}dhcp" network
else
- uci set network.${netrenamed}dhcp=alias
- uci set network.${netrenamed}dhcp.interface="$netrenamed"
+ eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange 1 0)
+ STARTADHOC=$START
+ NETMASKADHOC=$NETMASK
+ fi
+ if [ "$supports_vap" = 1 -a "$vap" = 1 -a "$ahdhcp_when_vap" != 1 ]; then
+ # vaps are enabled and supported and we do not use DHCP on adhoc
+ # Add dhcp interface
+ uci batch <<- EOF
+ set network.${netrenamed}dhcp=interface
+ set network.${netrenamed}dhcp.proto=static
+ set network.${netrenamed}dhcp.ipaddr="$STARTADHOC"
+ set network.${netrenamed}dhcp.netmask="$NETMASKADHOC"
+ EOF
+ uci_commitverbose "Setup interface for ${netrenamed}dhcp" network
fi
- uci batch <<- EOF
- set network.${netrenamed}dhcp.proto=static
- set network.${netrenamed}dhcp.ipaddr="$START"
- set network.${netrenamed}dhcp.netmask="$NETMASK"
- EOF
- uci_commitverbose "Setup interface for ${netrenamed}dhcp" network
+ # Setup alias for $net adhoc interface
+ if [ "$supports_vap" = 0 ] || [ "$vap" = 0 ] || [ "$supports_vap" = 1 -a "$vap" = 1 -a "$ahdhcp_when_vap" = 1 ]; then
+ # vaps are either not supported or enabled or they are supported and enabled
+ # but we also want to use DHCP on the adhoc interface
+ uci batch <<- EOF
+ set network.${netrenamed}ahdhcp=interface
+ set network.${netrenamed}ahdhcp.ifname="@${netrenamed}"
+ set network.${netrenamed}ahdhcp.proto=static
+ set network.${netrenamed}ahdhcp.ipaddr="$STARTADHOC"
+ set network.${netrenamed}ahdhcp.netmask="$NETMASKADHOC"
+ EOF
+ fi
+ uci_commitverbose "Setup interface for ${netrenamed}ahdhcp" network
fi