xref: /freebsd/usr.sbin/bsdconfig/networking/share/device.subr (revision d3a0f9181641cfebdceac242e7a496001c67c28e)
1ab2043b8SDevin Teskeif [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1
2ab2043b8SDevin Teske#
37323adacSDevin Teske# Copyright (c) 2006-2013 Devin Teske
4ab2043b8SDevin Teske# All Rights Reserved.
5ab2043b8SDevin Teske#
6ab2043b8SDevin Teske# Redistribution and use in source and binary forms, with or without
7ab2043b8SDevin Teske# modification, are permitted provided that the following conditions
8ab2043b8SDevin Teske# are met:
9ab2043b8SDevin Teske# 1. Redistributions of source code must retain the above copyright
10ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer.
11ab2043b8SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
12ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer in the
13ab2043b8SDevin Teske#    documentation and/or other materials provided with the distribution.
14ab2043b8SDevin Teske#
15ab2043b8SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16ab2043b8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17ab2043b8SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ab2043b8SDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ab2043b8SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ab2043b8SDevin Teske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21ab2043b8SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ab2043b8SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ab2043b8SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ab2043b8SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ab2043b8SDevin Teske# SUCH DAMAGE.
26ab2043b8SDevin Teske#
27ab2043b8SDevin Teske# $FreeBSD$
28ab2043b8SDevin Teske#
29ab2043b8SDevin Teske############################################################ INCLUDES
30ab2043b8SDevin Teske
31ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
32ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
3356961fd7SDevin Teskef_dprintf "%s: loading includes..." networking/device.subr
347323adacSDevin Teskef_include $BSDCFG_SHARE/device.subr
35ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr
36ab2043b8SDevin Teskef_include $BSDCFG_SHARE/sysrc.subr
377323adacSDevin Teskef_include $BSDCFG_SHARE/media/tcpip.subr
38ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/common.subr
39ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/ipaddr.subr
40ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/media.subr
41ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/netmask.subr
42ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/resolv.subr
43ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/routing.subr
44ab2043b8SDevin Teske
45ab2043b8SDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
46ab2043b8SDevin Teskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
47ab2043b8SDevin Teske
48ab2043b8SDevin Teske############################################################ GLOBALS
49ab2043b8SDevin Teske
50ab2043b8SDevin Teske#
51ab2043b8SDevin Teske# Settings used while interacting with various dialog(1) menus
52ab2043b8SDevin Teske#
53ab2043b8SDevin Teske: ${DIALOG_MENU_NETDEV_KICK_INTERFACES=1}
54ab2043b8SDevin Teske: ${DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK=3}
55ab2043b8SDevin Teske
56ab2043b8SDevin Teske############################################################ FUNCTIONS
57ab2043b8SDevin Teske
58*d3a0f918SDevin Teske# f_dialog_menu_netdev [$default]
59ab2043b8SDevin Teske#
60*d3a0f918SDevin Teske# Display a list of network devices with descriptions. Optionally, if present
61*d3a0f918SDevin Teske# and non-NULL, initially highlight $default interface.
62ab2043b8SDevin Teske#
63ab2043b8SDevin Teskef_dialog_menu_netdev()
64ab2043b8SDevin Teske{
65*d3a0f918SDevin Teske	local defaultitem="${1%\*}" # Tim trailing asterisk if present
66*d3a0f918SDevin Teske
67ab2043b8SDevin Teske	#
68ab2043b8SDevin Teske	# Display a message to let the user know we're working...
69ab2043b8SDevin Teske	# (message will remain until we throw up the next dialog)
70ab2043b8SDevin Teske	#
71ab2043b8SDevin Teske	f_dialog_info "$msg_probing_network_interfaces"
72ab2043b8SDevin Teske
73ab2043b8SDevin Teske	#
74ab2043b8SDevin Teske	# Get list of usable network interfaces
75ab2043b8SDevin Teske	#
76ab2043b8SDevin Teske	local d='[[:digit:]]+:'
77ab2043b8SDevin Teske	local iflist="`echo "$(ifconfig -l):" | sed -E -e "
78ab2043b8SDevin Teske		# Convert all spaces to colons
79ab2043b8SDevin Teske		y/ /:/
80ab2043b8SDevin Teske
81ab2043b8SDevin Teske		# Prune unsavory interfaces
82ab2043b8SDevin Teske		s/lo$d//g
83ab2043b8SDevin Teske		s/ppp$d//g
84ab2043b8SDevin Teske		s/sl$d//g
85ab2043b8SDevin Teske		s/faith$d//g
86ab2043b8SDevin Teske
87ab2043b8SDevin Teske		# Convert all colons back into spaces
88ab2043b8SDevin Teske		y/:/ /
89ab2043b8SDevin Teske	"`"
90ab2043b8SDevin Teske
91ab2043b8SDevin Teske	#
92ab2043b8SDevin Teske	# Optionally kick interfaces in the head to get them to accurately
93ab2043b8SDevin Teske	# track the carrier status in realtime (required on FreeBSD).
94ab2043b8SDevin Teske	#
95ab2043b8SDevin Teske	if [ "$DIALOG_MENU_NETDEV_KICK_INTERFACES" ]; then
96ab2043b8SDevin Teske		DIALOG_MENU_NETDEV_KICK_INTERFACES=
97ab2043b8SDevin Teske
98ab2043b8SDevin Teske		local ifn
99ab2043b8SDevin Teske		for ifn in $iflist; do
100ab2043b8SDevin Teske			f_quietly ifconfig $ifn up
101ab2043b8SDevin Teske		done
102ab2043b8SDevin Teske
103ab2043b8SDevin Teske		if [ "$DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK" ]; then
104ab2043b8SDevin Teske			# interfaces need time to update carrier status
105ab2043b8SDevin Teske			sleep $DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK
106ab2043b8SDevin Teske		fi
107ab2043b8SDevin Teske	fi
108ab2043b8SDevin Teske
109ab2043b8SDevin Teske	#
110ab2043b8SDevin Teske	# Mark any "active" interfaces with an asterisk (*)
111ab2043b8SDevin Teske	# to the right of the device name.
112ab2043b8SDevin Teske	#
113ab2043b8SDevin Teske	interfaces=$(
114ab2043b8SDevin Teske		for ifn in $iflist; do
115ab2043b8SDevin Teske			active=$( ifconfig $ifn | awk \
116ab2043b8SDevin Teske			'
117ab2043b8SDevin Teske				( $1 == "status:" ) \
118ab2043b8SDevin Teske				{
119ab2043b8SDevin Teske					if ( $2 == "active" ) { print 1; exit }
120ab2043b8SDevin Teske				}
121ab2043b8SDevin Teske			' )
122ab2043b8SDevin Teske			printf "'%s%s' '%s'\n" \
123ffb5f454SDevin Teske				$ifn "${active:+*}" "$( f_device_desc $ifn )"
124ab2043b8SDevin Teske		done
125ab2043b8SDevin Teske	)
126ab2043b8SDevin Teske	if [ ! "$interfaces" ]; then
127ab2043b8SDevin Teske		f_dialog_msgbox "$msg_no_network_interfaces"
128ab2043b8SDevin Teske		return $FAILURE
129ab2043b8SDevin Teske	fi
130ab2043b8SDevin Teske
131*d3a0f918SDevin Teske	#
132*d3a0f918SDevin Teske	# Maybe the default item was marked as active
133*d3a0f918SDevin Teske	#
134*d3a0f918SDevin Teske	if [ "$defaultitem" ]; then
135*d3a0f918SDevin Teske		ifconfig "$defaultitem" 2> /dev/null | awk \
136*d3a0f918SDevin Teske			'( $1 == "status:" && $2 != "active" ) { exit 0 }' ||
137*d3a0f918SDevin Teske			defaultitem="$defaultitem*"
138*d3a0f918SDevin Teske	fi
139*d3a0f918SDevin Teske
140ab2043b8SDevin Teske	local hline="$hline_arrows_tab_enter"
141ab2043b8SDevin Teske
142ab2043b8SDevin Teske	#
143ab2043b8SDevin Teske	# Ask user to select an interface
144ab2043b8SDevin Teske	#
145ab2043b8SDevin Teske	local prompt size
146ab2043b8SDevin Teske	prompt="$msg_select_network_interface"
147ab2043b8SDevin Teske	size=$( eval f_dialog_menu_size \
148ab2043b8SDevin Teske	        	\"\$DIALOG_TITLE\"     \
149ab2043b8SDevin Teske	        	\"\$DIALOG_BACKTITLE\" \
150ab2043b8SDevin Teske	        	\"\$prompt\"           \
151ab2043b8SDevin Teske	        	\"\$hline\"            \
152ab2043b8SDevin Teske	        	$interfaces            )
15389498fdfSDevin Teske	local dialog_menu
15489498fdfSDevin Teske	dialog_menu=$( eval $DIALOG \
155*d3a0f918SDevin Teske		--title \"\$DIALOG_TITLE\"         \
156ab2043b8SDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
157ab2043b8SDevin Teske		--hline \"\$hline\"                \
158ab2043b8SDevin Teske		--ok-label \"\$msg_ok\"            \
159ab2043b8SDevin Teske		--cancel-label \"\$msg_cancel\"    \
160*d3a0f918SDevin Teske		--default-item \"\$defaultitem\"   \
161ab2043b8SDevin Teske		--menu \"\$prompt\" $size          \
162ab2043b8SDevin Teske		$interfaces                        \
16389498fdfSDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
16489498fdfSDevin Teske	)
16589498fdfSDevin Teske	local retval=$?
16689498fdfSDevin Teske	setvar DIALOG_MENU_$$ "$dialog_menu"
16789498fdfSDevin Teske	return $retval
168ab2043b8SDevin Teske}
169ab2043b8SDevin Teske
170ab2043b8SDevin Teske# f_dialog_menu_netdev_edit $interface $ipaddr $netmask $options $dhcp
171ab2043b8SDevin Teske#
172ab2043b8SDevin Teske# Allow a user to edit network interface settings. Current values are not
173ab2043b8SDevin Teske# probed but rather taken from the positional arguments.
174ab2043b8SDevin Teske#
175ab2043b8SDevin Teskef_dialog_menu_netdev_edit()
176ab2043b8SDevin Teske{
177ab2043b8SDevin Teske	local interface="$1" ipaddr="$2" netmask="$3" options="$4" dhcp="$5"
178ab2043b8SDevin Teske	local prompt menu_list size
179ab2043b8SDevin Teske
180ab2043b8SDevin Teske	#
181ab2043b8SDevin Teske	# Create a duplicate set of variables for change-tracking...
182ab2043b8SDevin Teske	#
183ab2043b8SDevin Teske	local ipaddr_orig="$2"  \
184ab2043b8SDevin Teske	      netmask_orig="$3" \
185ab2043b8SDevin Teske	      options_orig="$4" \
186ab2043b8SDevin Teske	      dhcp_orig="$5"
187ab2043b8SDevin Teske
188ab2043b8SDevin Teske	local hline="$hline_arrows_tab_enter"
189ab2043b8SDevin Teske	prompt=$( printf "$msg_network_configuration" "$interface" )
190ab2043b8SDevin Teske
191ab2043b8SDevin Teske	#
192ab2043b8SDevin Teske	# Loop forever until the user has finished configuring the different
193ab2043b8SDevin Teske	# components of the network interface.
194ab2043b8SDevin Teske	#
195ab2043b8SDevin Teske	# To apply the settings, we need to know each of the following:
196ab2043b8SDevin Teske	# 	- IP Address
197ab2043b8SDevin Teske	# 	- Network subnet mask
198ab2043b8SDevin Teske	# 	- Additional ifconfig(8) options
199ab2043b8SDevin Teske	#
200ab2043b8SDevin Teske	# It is only when we have all of the above values that we can make the
201ab2043b8SDevin Teske	# changes effective because all three options must be specified at-once
202ab2043b8SDevin Teske	# to ifconfig(8).
203ab2043b8SDevin Teske	#
204*d3a0f918SDevin Teske	local defaultitem=
205ab2043b8SDevin Teske	while :; do
206ab2043b8SDevin Teske		local dhcp_status="$msg_disabled"
207ab2043b8SDevin Teske		[ "$dhcp" ] && dhcp_status="$msg_enabled"
208ab2043b8SDevin Teske
209ab2043b8SDevin Teske		#
210ab2043b8SDevin Teske		# Display configuration-edit menu
211ab2043b8SDevin Teske		#
212ab2043b8SDevin Teske		menu_list="
213ab2043b8SDevin Teske			'X $msg_save_exit' '$msg_return_to_previous_menu'
214ab2043b8SDevin Teske			'2 $msg_dhcp'      '$dhcp_status'
215ab2043b8SDevin Teske			'3 $msg_ipaddr4'   '$ipaddr'
216ab2043b8SDevin Teske			'4 $msg_netmask'   '$netmask'
217ab2043b8SDevin Teske			'5 $msg_options'   '$options'
218ab2043b8SDevin Teske		"
219ab2043b8SDevin Teske		size=$( eval f_dialog_menu_size \
220ab2043b8SDevin Teske		        	\"\$DIALOG_TITLE\"     \
221ab2043b8SDevin Teske		        	\"\$DIALOG_BACKTITLE\" \
222ab2043b8SDevin Teske		        	\"\$prompt\"           \
223ab2043b8SDevin Teske		        	\"\$hline\"            \
224ab2043b8SDevin Teske		        	$menu_list             )
22589498fdfSDevin Teske		local dialog_menu
22689498fdfSDevin Teske		dialog_menu=$( eval $DIALOG \
227*d3a0f918SDevin Teske			--title \"\$DIALOG_TITLE\"         \
228ab2043b8SDevin Teske			--backtitle \"\$DIALOG_BACKTITLE\" \
229ab2043b8SDevin Teske			--hline \"\$hline\"                \
230ab2043b8SDevin Teske			--ok-label \"\$msg_ok\"            \
231ab2043b8SDevin Teske			--cancel-label \"\$msg_cancel\"    \
232198a44b5SDevin Teske			--help-button                      \
2333c91c65aSDevin Teske			--help-label \"\$msg_help\"        \
234198a44b5SDevin Teske			${USE_XDIALOG:+--help \"\"}        \
235*d3a0f918SDevin Teske			--default-item \"\$defaultitem\"   \
236ab2043b8SDevin Teske			--menu \"\$prompt\" $size          \
237ab2043b8SDevin Teske			$menu_list                         \
23889498fdfSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
23989498fdfSDevin Teske		)
240ab2043b8SDevin Teske
241ab2043b8SDevin Teske		local retval=$?
24289498fdfSDevin Teske		setvar DIALOG_MENU_$$ "$dialog_menu"
243ab2043b8SDevin Teske		local tag="$( f_dialog_menutag )"
244ab2043b8SDevin Teske
245198a44b5SDevin Teske		if [ $retval -eq 2 ]; then
246198a44b5SDevin Teske			# The Help button was pressed
247198a44b5SDevin Teske			f_show_help "$TCP_HELPFILE"
248198a44b5SDevin Teske			continue
249198a44b5SDevin Teske		elif [ $retval -ne $SUCCESS ]; then
250198a44b5SDevin Teske			# "Cancel" was chosen (-1) or ESC was pressed (255)
251198a44b5SDevin Teske			return $retval
252*d3a0f918SDevin Teske		else
253*d3a0f918SDevin Teske			# Only update default-item on success
254*d3a0f918SDevin Teske			defaultitem="$tag"
255198a44b5SDevin Teske		fi
256ab2043b8SDevin Teske
257ab2043b8SDevin Teske		#
258ab2043b8SDevin Teske		# Call the below ``modifier functions'' whose job it is to take
259ab2043b8SDevin Teske		# input from the user and assign the newly-acquired values back
260ab2043b8SDevin Teske		# to the ipaddr, netmask, and options variables for us to re-
261ab2043b8SDevin Teske		# read and display in the summary dialog.
262ab2043b8SDevin Teske		#
263ab2043b8SDevin Teske		case "$tag" in
264ab2043b8SDevin Teske		X\ *) break;;
265ab2043b8SDevin Teske		2\ *) #
266ab2043b8SDevin Teske		      # Do not proceed if/when there are NFS-mounts currently
267ab2043b8SDevin Teske		      # active. If the network is changed while NFS-exported
268ab2043b8SDevin Teske		      # directories are mounted, the system may hang (if any
269ab2043b8SDevin Teske		      # NFS mounts are using that interface).
270ab2043b8SDevin Teske		      #
271ab2043b8SDevin Teske		      if f_nfs_mounted && ! f_jailed; then
272ab2043b8SDevin Teske		      	local setting="$( printf "$msg_current_dhcp_status" \
273ab2043b8SDevin Teske		      	                         "$interface" "$dhcp_status" )"
274fa2e39c8SDevin Teske			f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
275ab2043b8SDevin Teske		      	continue
276ab2043b8SDevin Teske		      fi
277ab2043b8SDevin Teske
278ab2043b8SDevin Teske		      #
279ab2043b8SDevin Teske		      # Toggle DHCP status
280ab2043b8SDevin Teske		      #
281ab2043b8SDevin Teske		      if [ "$dhcp_status" = "$msg_enabled" ]; then
282ab2043b8SDevin Teske		      	dhcp=
283ab2043b8SDevin Teske		      else
284ab2043b8SDevin Teske		      	trap - SIGINT
285ab2043b8SDevin Teske		      	( # Execute within sub-shell to allow/catch Ctrl-C
286ab2043b8SDevin Teske		      	  trap 'exit $FAILURE' SIGINT
287ab2043b8SDevin Teske		      	  msg=$( printf "$msg_scanning_for_dhcp" "$interface" )
288ab2043b8SDevin Teske		      	  if [ "$USE_XDIALOG" ]; then
289ab2043b8SDevin Teske		      	  	(
290ab2043b8SDevin Teske		      	  	  f_quietly ifconfig $interface delete
291ab2043b8SDevin Teske		      	  	  f_quietly dhclient $interface
292ab2043b8SDevin Teske		      	  	) |
293ab2043b8SDevin Teske		      	  	  f_xdialog_info "$msg"
294ab2043b8SDevin Teske		      	  else
295ab2043b8SDevin Teske		      	  	f_dialog_info "$msg"
296ab2043b8SDevin Teske		      	  	f_quietly ifconfig $interface delete
297ab2043b8SDevin Teske		      	  	f_quietly dhclient $interface
298ab2043b8SDevin Teske		      	  fi
299ab2043b8SDevin Teske		      	)
300ab2043b8SDevin Teske		      	retval=$?
301ab2043b8SDevin Teske		      	trap 'interrupt' SIGINT
302ab2043b8SDevin Teske		      	if [ $retval -eq $SUCCESS ]; then
303ab2043b8SDevin Teske		      		dhcp=1
304ab2043b8SDevin Teske		      		ipaddr=$( f_ifconfig_inet $interface )
305ab2043b8SDevin Teske		      		netmask=$( f_ifconfig_netmask $interface )
306ab2043b8SDevin Teske		      		options=
307ab2043b8SDevin Teske
308ab2043b8SDevin Teske		      		# Fixup search/domain in resolv.conf(5)
309ab2043b8SDevin Teske		      		hostname=$( f_sysrc_get \
310ab2043b8SDevin Teske				            	'hostname:-$(hostname)' )
311ab2043b8SDevin Teske		      		f_dialog_resolv_conf_update "$hostname"
312ab2043b8SDevin Teske		      	fi
313ab2043b8SDevin Teske		      fi
314ab2043b8SDevin Teske		      ;;
315ab2043b8SDevin Teske		3\ *) f_dialog_input_ipaddr "$interface" "$ipaddr"
316ab2043b8SDevin Teske		      [ $? -eq $SUCCESS ] && dhcp=;;
317ab2043b8SDevin Teske		4\ *) f_dialog_input_netmask "$interface" "$netmask"
318ab2043b8SDevin Teske		      [ $? -eq $SUCCESS -a "$_netmask" ] && dhcp=;;
319ab2043b8SDevin Teske		5\ *) f_dialog_menu_media_options "$interface" "$options"
320ab2043b8SDevin Teske		      [ $? -eq $SUCCESS ] && dhcp=;;
321ab2043b8SDevin Teske		esac
322ab2043b8SDevin Teske	done
323ab2043b8SDevin Teske
324ab2043b8SDevin Teske	#
325ab2043b8SDevin Teske	# Save only if the user changed at least one feature of the interface
326ab2043b8SDevin Teske	#
327ab2043b8SDevin Teske	if [ "$ipaddr"  != "$ipaddr_orig"  -o \
328ab2043b8SDevin Teske	     "$netmask" != "$netmask_orig" -o \
329ab2043b8SDevin Teske	     "$options" != "$options_orig" -o \
330ab2043b8SDevin Teske	     "$dhcp"    != "$dhcp_orig" ]
331ab2043b8SDevin Teske	then
33213aadd84SDevin Teske		f_show_info "$msg_saving_network_interface" "$interface"
333ab2043b8SDevin Teske
334ab2043b8SDevin Teske		local value=
335ab2043b8SDevin Teske		if [ "$dhcp" ]; then
336ab2043b8SDevin Teske			f_sysrc_delete defaultrouter
337ab2043b8SDevin Teske			value=DHCP
338ab2043b8SDevin Teske		else
339ab2043b8SDevin Teske			value="inet $ipaddr netmask $netmask"
340ab2043b8SDevin Teske			value="$value${options:+ }$options"
341ab2043b8SDevin Teske		fi
342ab2043b8SDevin Teske
343ab2043b8SDevin Teske		f_sysrc_set ifconfig_$interface "$value"
344ab2043b8SDevin Teske	fi
345ab2043b8SDevin Teske
346ab2043b8SDevin Teske	#
347ab2043b8SDevin Teske	# Re/Apply the settings if desired
348ab2043b8SDevin Teske	#
349ab2043b8SDevin Teske	if [ ! "$dhcp" ]; then
35027ff90aaSDevin Teske		if f_yesno "$msg_bring_interface_up" "$interface"
35127ff90aaSDevin Teske		then
35213aadd84SDevin Teske			f_show_info "$msg_bring_interface_up" "$interface"
353ab2043b8SDevin Teske
354ab2043b8SDevin Teske			local dr="$( f_sysrc_get defaultrouter )" err
355ab2043b8SDevin Teske			if [ "$dr" = "NO" -o ! "$dr" ]; then
356ab2043b8SDevin Teske				dr=$( f_route_get_default )
357ab2043b8SDevin Teske				[ "$dr" ] && f_sysrc_set defaultrouter "$dr"
358ab2043b8SDevin Teske			fi
359ab2043b8SDevin Teske			#
360ab2043b8SDevin Teske			# Make a backup of resolv.conf(5) before using
361ab2043b8SDevin Teske			# ifconfig(8) and then restore it afterward. This
362ab2043b8SDevin Teske			# allows preservation of nameservers acquired via
363ab2043b8SDevin Teske			# DHCP on FreeBSD-8.x (normally lost as ifconfig(8)
364ab2043b8SDevin Teske			# usage causes dhclient(8) to exit which scrubs
365ab2043b8SDevin Teske			# resolv.conf(5) by-default upon termination).
366ab2043b8SDevin Teske			#
367ab2043b8SDevin Teske			f_quietly cp -fp "$RESOLV_CONF" "$RESOLV_CONF.$$"
368ab2043b8SDevin Teske			err=$( ifconfig $interface inet $ipaddr \
369ab2043b8SDevin Teske			       	netmask $netmask $options 2>&1 )
370ab2043b8SDevin Teske			if [ $? -eq $SUCCESS ]; then
371ab2043b8SDevin Teske				if [ "$dr" -a "$dr" != "NO" ]; then
372ab2043b8SDevin Teske					err=$( route add default "$dr" 2>&1 )
373ab2043b8SDevin Teske					[ $? -eq $SUCCESS ] || \
374ab2043b8SDevin Teske						dialog_msgbox "$err"
375ab2043b8SDevin Teske				fi
376ab2043b8SDevin Teske			else
377ab2043b8SDevin Teske				dialog_msgbox "$err"
378ab2043b8SDevin Teske			fi
379ab2043b8SDevin Teske			if cmp -s "$RESOLV_CONF" "$RESOLV_CONF.$$"; then
380ab2043b8SDevin Teske				f_quietly rm -f "$RESOLV_CONF.$$"
381ab2043b8SDevin Teske			else
382ab2043b8SDevin Teske				f_quietly mv -f "$RESOLV_CONF.$$" "$RESOLV_CONF"
383ab2043b8SDevin Teske			fi
384ab2043b8SDevin Teske		fi
385ab2043b8SDevin Teske	fi
386ab2043b8SDevin Teske
387ab2043b8SDevin Teske	return $SUCCESS
388ab2043b8SDevin Teske}
389ab2043b8SDevin Teske
39056961fd7SDevin Teske############################################################ MAIN
39156961fd7SDevin Teske
39256961fd7SDevin Teskef_dprintf "%s: Successfully loaded." networking/device.subr
39356961fd7SDevin Teske
394ab2043b8SDevin Teskefi # ! $_NETWORKING_DEVICE_SUBR
395