diff --git a/usr.sbin/bsdinstall/scripts/netconfig_ipv4 b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 index 393a6ef..aade88d 100755 --- a/usr.sbin/bsdinstall/scripts/netconfig_ipv4 +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 @@ -75,12 +75,51 @@ IF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuratio if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi exec 3>&- -echo $INTERFACE $IF_CONFIG | - awk -v prefix="$IFCONFIG_PREFIX" '{ - printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); - printf("defaultrouter=\"%s\"\n", $4); - }' >> $BSDINSTALL_TMPETC/._rc.conf.net -retval=$? +read IP_ADDRESS NETMASK ROUTER <= 1) {out = sprintf("%d", x%2) out; x/=2} print(out)}') + + awk -v mask=$mask_bin -v ip1=$ip1_int -v ip2=$ip2_int 'BEGIN {match(mask, /1+/); mask_len = RLENGTH; local_len = 32 - mask_len; ip1 = ip1 / (2^local_len); ip2 = ip2 / (2^local_len); if (sprintf("%d", ip1) != sprintf("%d", ip2)) {exit 1}}' +} + +# Check if router is in our subnet. If not, we need to add a route to the router +if ! inside_subnet $ROUTER $IP_ADDRESS $NETMASK +then + + # $1 = Interface + # $2 = IP Address + # $3 = Subnet Mask + # $4 = Default Router + echo $INTERFACE $IF_CONFIG | + awk -v prefix="$IFCONFIG_PREFIX" '{ + printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); + printf("gateway_if=\"%s\"\n", $1); + printf("gateway_ip=\"%s\"\n", $4); + printf("static_routes=\"gateway\"\n"); + printf("route_gateway=\"-host $gateway_ip -interface $gateway_if\"\n"); + printf("defaultrouter=\"%s\"\n", $4); + }' >> $BSDINSTALL_TMPETC/._rc.conf.net + retval=$? + +else + + echo $INTERFACE $IF_CONFIG | + awk -v prefix="$IFCONFIG_PREFIX" '{ + printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); + printf("defaultrouter=\"%s\"\n", $4); + }' >> $BSDINSTALL_TMPETC/._rc.conf.net + retval=$? + +fi if [ "$BSDINSTALL_CONFIGCURRENT" ]; then . $BSDINSTALL_TMPETC/._rc.conf.net @@ -91,6 +130,8 @@ if [ "$BSDINSTALL_CONFIGCURRENT" ]; then fi if [ "$defaultrouter" ]; then route delete -inet default + # add route to router (just in case it's outside our subnet) + route add -host $defaultrouter -interface $INTERFACE route add -inet default $defaultrouter retval=$? fi