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