View | Details | Raw Unified | Return to bug 221379 | Differences between
and this patch

Collapse All | Expand All

(-)b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 (-6 / +47 lines)
Lines 75-86 IF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuratio Link Here
75
if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
75
if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
76
exec 3>&-
76
exec 3>&-
77
77
78
echo $INTERFACE $IF_CONFIG |
78
read IP_ADDRESS NETMASK ROUTER <<EOF
79
    awk -v prefix="$IFCONFIG_PREFIX" '{
79
$IF_CONFIG
80
	printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3);
80
EOF
81
	printf("defaultrouter=\"%s\"\n", $4);
81
82
    }' >> $BSDINSTALL_TMPETC/._rc.conf.net
82
inside_subnet() {
83
retval=$?
83
	local ip1="$1"
84
	local ip2="$2"
85
	local mask="$3"
86
	local ip1_int=$(echo "$ip1" | awk -F. '{if ($1 ~ /^0x/) {print $1 + 0} else {x = 0; for (i = 1; i <= 4; i++) {x += $i * 256^(4-i)} print(x)} }')
87
	local ip2_int=$(echo "$ip2" | awk -F. '{if ($1 ~ /^0x/) {print $1 + 0} else {x = 0; for (i = 1; i <= 4; i++) {x += $i * 256^(4-i)} print(x)} }')
88
	local mask_int=$(echo "$mask" | awk -F. '{if ($1 ~ /^0x/) {print $1 + 0} else {x = 0; for (i = 1; i <= 4; i++) {x += $i * 256^(4-i)} print(x)} }')
89
	local mask_bin=$(awk -v x="$mask_int" 'BEGIN {while (x >= 1) {out = sprintf("%d", x%2) out; x/=2} print(out)}')
90
91
	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}}'
92
}
93
94
# Check if router is in our subnet. If not, we need to add a route to the router
95
if ! inside_subnet $ROUTER $IP_ADDRESS $NETMASK
96
then
97
98
	# $1 = Interface
99
	# $2 = IP Address
100
	# $3 = Subnet Mask
101
	# $4 = Default Router
102
	echo $INTERFACE $IF_CONFIG |
103
		awk -v prefix="$IFCONFIG_PREFIX" '{
104
		printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3);
105
		printf("gateway_if=\"%s\"\n", $1);
106
		printf("gateway_ip=\"%s\"\n", $4);
107
		printf("static_routes=\"gateway\"\n");
108
		printf("route_gateway=\"-host $gateway_ip -interface $gateway_if\"\n");
109
		printf("defaultrouter=\"%s\"\n", $4);
110
		}' >> $BSDINSTALL_TMPETC/._rc.conf.net
111
	retval=$?
112
113
else
114
115
	echo $INTERFACE $IF_CONFIG |
116
		awk -v prefix="$IFCONFIG_PREFIX" '{
117
		printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3);
118
		printf("defaultrouter=\"%s\"\n", $4);
119
		}' >> $BSDINSTALL_TMPETC/._rc.conf.net
120
	retval=$?
121
122
fi
84
123
85
if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
124
if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
86
	. $BSDINSTALL_TMPETC/._rc.conf.net
125
	. $BSDINSTALL_TMPETC/._rc.conf.net
Lines 91-96 if [ "$BSDINSTALL_CONFIGCURRENT" ]; then Link Here
91
	fi
130
	fi
92
	if [ "$defaultrouter" ]; then
131
	if [ "$defaultrouter" ]; then
93
		route delete -inet default
132
		route delete -inet default
133
		# add route to router (just in case it's outside our subnet)
134
		route add -host $defaultrouter -interface $INTERFACE
94
		route add -inet default $defaultrouter
135
		route add -inet default $defaultrouter
95
		retval=$?
136
		retval=$?
96
	fi
137
	fi

Return to bug 221379