Deleted Added
full compact
device.subr (259054) device.subr (264840)
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 (INCLUDING, 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 (INCLUDING, 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 259054 2013-12-07 00:31:01Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/networking/share/device.subr 264840 2014-04-23 22:04:04Z 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/media/tcpip.subr
37f_include $BSDCFG_SHARE/networking/common.subr
38f_include $BSDCFG_SHARE/networking/ipaddr.subr
39f_include $BSDCFG_SHARE/networking/media.subr
40f_include $BSDCFG_SHARE/networking/netmask.subr
41f_include $BSDCFG_SHARE/networking/resolv.subr
42f_include $BSDCFG_SHARE/networking/routing.subr
43f_include $BSDCFG_SHARE/strings.subr
44f_include $BSDCFG_SHARE/sysrc.subr
45
46BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
47f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
48
49############################################################ GLOBALS
50
51#
52# Settings used while interacting with various dialog(1) menus
53#
54: ${DIALOG_MENU_NETDEV_KICK_INTERFACES=1}
55: ${DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK=3}
56
57############################################################ FUNCTIONS
58
59# f_dialog_menu_netdev [$default]
60#
61# Display a list of network devices with descriptions. Optionally, if present
62# and non-NULL, initially highlight $default interface.
63#
64f_dialog_menu_netdev()
65{
66 local menu_list # Calculated below
67 local defaultitem="${1%\*}" # Trim trailing asterisk if present
68
69 #
70 # Display a message to let the user know we're working...
71 # (message will remain until we throw up the next dialog)
72 #
73 f_dialog_info "$msg_probing_network_interfaces"
74
75 #
76 # Get list of usable network interfaces
77 #
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/media/tcpip.subr
37f_include $BSDCFG_SHARE/networking/common.subr
38f_include $BSDCFG_SHARE/networking/ipaddr.subr
39f_include $BSDCFG_SHARE/networking/media.subr
40f_include $BSDCFG_SHARE/networking/netmask.subr
41f_include $BSDCFG_SHARE/networking/resolv.subr
42f_include $BSDCFG_SHARE/networking/routing.subr
43f_include $BSDCFG_SHARE/strings.subr
44f_include $BSDCFG_SHARE/sysrc.subr
45
46BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
47f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
48
49############################################################ GLOBALS
50
51#
52# Settings used while interacting with various dialog(1) menus
53#
54: ${DIALOG_MENU_NETDEV_KICK_INTERFACES=1}
55: ${DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK=3}
56
57############################################################ FUNCTIONS
58
59# f_dialog_menu_netdev [$default]
60#
61# Display a list of network devices with descriptions. Optionally, if present
62# and non-NULL, initially highlight $default interface.
63#
64f_dialog_menu_netdev()
65{
66 local menu_list # Calculated below
67 local defaultitem="${1%\*}" # Trim trailing asterisk if present
68
69 #
70 # Display a message to let the user know we're working...
71 # (message will remain until we throw up the next dialog)
72 #
73 f_dialog_info "$msg_probing_network_interfaces"
74
75 #
76 # Get list of usable network interfaces
77 #
78 local devs if iflist= # Calculated below
78 local dev devs if iflist= # Calculated below
79 f_device_rescan_network
80 f_device_find "" $DEVICE_TYPE_NETWORK devs
79 f_device_rescan_network
80 f_device_find "" $DEVICE_TYPE_NETWORK devs
81 for if in $devs; do
81 for dev in $devs; do
82 f_struct "$dev" get name if || continue
82 # Skip unsavory interfaces
83 case "$if" in
84 lo[0-9]*|ppp[0-9]*|sl[0-9]*|faith[0-9]*) continue ;;
85 esac
86 iflist="$iflist $if"
87 done
88 iflist="${iflist# }"
89
90 #
91 # Optionally kick interfaces in the head to get them to accurately
92 # track the carrier status in realtime (required on FreeBSD).
93 #
94 if [ "$DIALOG_MENU_NETDEV_KICK_INTERFACES" ]; then
95 DIALOG_MENU_NETDEV_KICK_INTERFACES=
96
97 for if in $iflist; do
98 f_quietly ifconfig $if up
99 done
100
101 if [ "$DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK" ]; then
102 # interfaces need time to update carrier status
103 sleep $DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK
104 fi
105 fi
106
107 #
108 # Mark any "active" interfaces with an asterisk (*)
109 # to the right of the device name.
110 #
111 menu_list=$(
112 for if in $iflist; do
113 f_device_desc $if $DEVICE_TYPE_NETWORK desc
114 f_shell_escape "$desc" desc
115 if f_device_is_active $if; then
116 printf "'%s\*' '%s'\n" $if "$desc"
117 else
118 printf "'%s' '%s'\n" $if "$desc"
119 fi
120 done
121 )
122 if [ ! "$menu_list" ]; then
123 f_show_msg "$msg_no_network_interfaces"
124 return $DIALOG_CANCEL
125 fi
126
127 # Maybe the default item was marked as active
128 f_device_is_active "$defaultitem" && defaultitem="$defaultitem*"
129
130 #
131 # Ask user to select an interface
132 #
133 local prompt="$msg_select_network_interface"
134 local hline="$hline_arrows_tab_enter"
135 local height width rows
136 eval f_dialog_menu_size height width rows \
137 \"\$DIALOG_TITLE\" \
138 \"\$DIALOG_BACKTITLE\" \
139 \"\$prompt\" \
140 \"\$hline\" \
141 $menu_list
142 local menu_choice
143 menu_choice=$( eval $DIALOG \
144 --title \"\$DIALOG_TITLE\" \
145 --backtitle \"\$DIALOG_BACKTITLE\" \
146 --hline \"\$hline\" \
147 --ok-label \"\$msg_ok\" \
148 --cancel-label \"\$msg_cancel\" \
149 --default-item \"\$defaultitem\" \
150 --menu \"\$prompt\" \
151 $height $width $rows \
152 $menu_list \
153 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
154 )
155 local retval=$?
156 f_dialog_menutag_store -s "$menu_choice"
157 return $retval
158}
159
160# f_dialog_menu_netdev_edit $interface $ipaddr $netmask $options $dhcp
161#
162# Allow a user to edit network interface settings. Current values are not
163# probed but rather taken from the positional arguments.
164#
165f_dialog_menu_netdev_edit()
166{
167 local funcname=f_dialog_menu_netdev_edit
168 local interface="$1" ipaddr="$2" netmask="$3" options="$4" dhcp="$5"
169 local prompt menu_list height width rows
170
171 #
172 # Create a duplicate set of variables for change-tracking...
173 #
174 local ipaddr_orig="$2" \
175 netmask_orig="$3" \
176 options_orig="$4" \
177 dhcp_orig="$5"
178
179 local hline="$hline_arrows_tab_enter"
180 f_sprintf prompt "$msg_network_configuration" "$interface"
181
182 #
183 # Loop forever until the user has finished configuring the different
184 # components of the network interface.
185 #
186 # To apply the settings, we need to know each of the following:
187 # - IP Address
188 # - Network subnet mask
189 # - Additional ifconfig(8) options
190 #
191 # It is only when we have all of the above values that we can make the
192 # changes effective because all three options must be specified at-once
193 # to ifconfig(8).
194 #
195 local defaultitem=
196 while :; do
197 local dhcp_status="$msg_disabled"
198 [ "$dhcp" ] && dhcp_status="$msg_enabled"
199
200 #
201 # Display configuration-edit menu
202 #
203 menu_list="
204 'X $msg_save_exit' '$msg_return_to_previous_menu'
205 '2 $msg_dhcp' '$dhcp_status'
206 '3 $msg_ipaddr4' '$ipaddr'
207 '4 $msg_netmask' '$netmask'
208 '5 $msg_options' '$options'
209 "
210 eval f_dialog_menu_size height width rows \
211 \"\$DIALOG_TITLE\" \
212 \"\$DIALOG_BACKTITLE\" \
213 \"\$prompt\" \
214 \"\$hline\" \
215 $menu_list
216 local tag
217 tag=$( eval $DIALOG \
218 --title \"\$DIALOG_TITLE\" \
219 --backtitle \"\$DIALOG_BACKTITLE\" \
220 --hline \"\$hline\" \
221 --ok-label \"\$msg_ok\" \
222 --cancel-label \"\$msg_cancel\" \
223 --help-button \
224 --help-label \"\$msg_help\" \
225 ${USE_XDIALOG:+--help \"\"} \
226 --default-item \"\$defaultitem\" \
227 --menu \"\$prompt\" \
228 $height $width $rows \
229 $menu_list \
230 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
231 )
232 local retval=$?
233 f_dialog_data_sanitize tag
234
235 if [ $retval -eq $DIALOG_HELP ]; then
236 f_show_help "$TCP_HELPFILE"
237 continue
238 elif [ $retval -ne $DIALOG_OK ]; then
239 return $retval
240 else
241 # Only update default-item on success
242 defaultitem="$tag"
243 fi
244
245 #
246 # Call the below ``modifier functions'' whose job it is to take
247 # input from the user and assign the newly-acquired values back
248 # to the ipaddr, netmask, and options variables for us to re-
249 # read and display in the summary dialog.
250 #
251 case "$tag" in
252 X\ *) break ;;
253 2\ *) #
254 # Proceed cautiously (confirm with the user) if/when NFS-
255 # mounts are active. If the network on which these mounts
256 # are made is changed parts of the system may hang.
257 #
258 if f_nfs_mounted && ! f_jailed; then
259 local setting
260 f_sprintf setting "$msg_current_dhcp_status" \
261 "$interface" "$dhcp_status"
262 f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
263 continue
264 fi
265
266 #
267 # Toggle DHCP status
268 #
269 if [ "$dhcp_status" = "$msg_enabled" ]; then
270 dhcp=
271 else
272 trap - SIGINT
273 ( # Execute within sub-shell to allow/catch Ctrl-C
274 trap 'exit $FAILURE' SIGINT
275 f_sprintf msg "$msg_scanning_for_dhcp" "$interface"
276 if [ "$USE_XDIALOG" ]; then
277 (
278 f_quietly ifconfig "$interface" delete
279 f_quietly dhclient "$interface"
280 ) |
281 f_xdialog_info "$msg"
282 else
283 f_dialog_info "$msg"
284 f_quietly ifconfig "$interface" delete
285 f_quietly dhclient "$interface"
286 fi
287 )
288 retval=$?
289 trap 'interrupt' SIGINT
290 if [ $retval -eq $DIALOG_OK ]; then
291 dhcp=1
292 f_ifconfig_inet "$interface" ipaddr
293 f_ifconfig_inet6 "$interface" ipaddr6
294 f_ifconfig_netmask "$interface" netmask
295 options=
296
297 # Fixup search/domain in resolv.conf(5)
298 hostname=$( f_sysrc_get \
299 'hostname:-$(hostname)' )
300 f_dialog_resolv_conf_update "$hostname"
301 fi
302 fi
303 ;;
304 3\ *) f_dialog_input_ipaddr "$interface" "$ipaddr"
305 [ $? -eq $DIALOG_OK ] && dhcp= ;;
306 4\ *) f_dialog_input_netmask "$interface" "$netmask"
307 [ $? -eq $DIALOG_OK -a "$_netmask" ] && dhcp= ;;
308 5\ *) f_dialog_menu_media_options "$interface" "$options"
309 [ $? -eq $DIALOG_OK ] && dhcp= ;;
310 esac
311 done
312
313 #
314 # Save only if the user changed at least one feature of the interface
315 #
316 if [ "$ipaddr" != "$ipaddr_orig" -o \
317 "$netmask" != "$netmask_orig" -o \
318 "$options" != "$options_orig" -o \
319 "$dhcp" != "$dhcp_orig" ]
320 then
321 f_show_info "$msg_saving_network_interface" "$interface"
322
323 local value=
324 if [ "$dhcp" ]; then
325 f_eval_catch $funcname f_sysrc_delete \
326 'f_sysrc_delete defaultrouter'
327 value=DHCP
328 else
329 value="inet $ipaddr netmask $netmask"
330 value="$value${options:+ }$options"
331 fi
332
333 f_eval_catch $funcname f_sysrc_set \
334 'f_sysrc_set "ifconfig_%s" "%s"' "$interface" "$value"
335 fi
336
337 #
338 # Re/Apply the settings if desired
339 #
340 if [ ! "$dhcp" ]; then
341 if f_yesno "$msg_bring_interface_up" "$interface"
342 then
343 f_show_info "$msg_bring_interface_up" "$interface"
344
345 local dr="$( f_sysrc_get defaultrouter )"
346 if [ "$dr" = "NO" -o ! "$dr" ]; then
347 f_route_get_default dr
348 [ "$dr" ] && f_eval_catch \
349 $funcname f_sysrc_set \
350 'f_sysrc_set defaultrouter "%s"' "$dr"
351 fi
352 #
353 # Make a backup of resolv.conf(5) before using
354 # ifconfig(8) and then restore it afterward. This
355 # allows preservation of nameservers acquired via
356 # DHCP on FreeBSD-8.x (normally lost as ifconfig(8)
357 # usage causes dhclient(8) to exit which scrubs
358 # resolv.conf(5) by-default upon termination).
359 #
360 f_quietly cp -fp "$RESOLV_CONF" "$RESOLV_CONF.$$"
361 if f_eval_catch $funcname ifconfig \
362 'ifconfig "%s" inet "%s" netmask "%s" %s' \
363 "$interface" "$ipaddr" "$netmask" "$options"
364 then
365 [ "$dr" -a "$dr" != "NO" ] &&
366 f_eval_catch $funcname route \
367 'route add default "%s"' "$dr"
368 fi
369 if cmp -s "$RESOLV_CONF" "$RESOLV_CONF.$$"; then
370 f_quietly rm -f "$RESOLV_CONF.$$"
371 else
372 f_quietly mv -f "$RESOLV_CONF.$$" "$RESOLV_CONF"
373 fi
374 fi
375 fi
376
377 return $DIALOG_OK
378}
379
380############################################################ MAIN
381
382f_dprintf "%s: Successfully loaded." networking/device.subr
383
384fi # ! $_NETWORKING_DEVICE_SUBR
83 # Skip unsavory interfaces
84 case "$if" in
85 lo[0-9]*|ppp[0-9]*|sl[0-9]*|faith[0-9]*) continue ;;
86 esac
87 iflist="$iflist $if"
88 done
89 iflist="${iflist# }"
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 for if in $iflist; do
99 f_quietly ifconfig $if up
100 done
101
102 if [ "$DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK" ]; then
103 # interfaces need time to update carrier status
104 sleep $DIALOG_MENU_NETDEV_SLEEP_AFTER_KICK
105 fi
106 fi
107
108 #
109 # Mark any "active" interfaces with an asterisk (*)
110 # to the right of the device name.
111 #
112 menu_list=$(
113 for if in $iflist; do
114 f_device_desc $if $DEVICE_TYPE_NETWORK desc
115 f_shell_escape "$desc" desc
116 if f_device_is_active $if; then
117 printf "'%s\*' '%s'\n" $if "$desc"
118 else
119 printf "'%s' '%s'\n" $if "$desc"
120 fi
121 done
122 )
123 if [ ! "$menu_list" ]; then
124 f_show_msg "$msg_no_network_interfaces"
125 return $DIALOG_CANCEL
126 fi
127
128 # Maybe the default item was marked as active
129 f_device_is_active "$defaultitem" && defaultitem="$defaultitem*"
130
131 #
132 # Ask user to select an interface
133 #
134 local prompt="$msg_select_network_interface"
135 local hline="$hline_arrows_tab_enter"
136 local height width rows
137 eval f_dialog_menu_size height width rows \
138 \"\$DIALOG_TITLE\" \
139 \"\$DIALOG_BACKTITLE\" \
140 \"\$prompt\" \
141 \"\$hline\" \
142 $menu_list
143 local menu_choice
144 menu_choice=$( eval $DIALOG \
145 --title \"\$DIALOG_TITLE\" \
146 --backtitle \"\$DIALOG_BACKTITLE\" \
147 --hline \"\$hline\" \
148 --ok-label \"\$msg_ok\" \
149 --cancel-label \"\$msg_cancel\" \
150 --default-item \"\$defaultitem\" \
151 --menu \"\$prompt\" \
152 $height $width $rows \
153 $menu_list \
154 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
155 )
156 local retval=$?
157 f_dialog_menutag_store -s "$menu_choice"
158 return $retval
159}
160
161# f_dialog_menu_netdev_edit $interface $ipaddr $netmask $options $dhcp
162#
163# Allow a user to edit network interface settings. Current values are not
164# probed but rather taken from the positional arguments.
165#
166f_dialog_menu_netdev_edit()
167{
168 local funcname=f_dialog_menu_netdev_edit
169 local interface="$1" ipaddr="$2" netmask="$3" options="$4" dhcp="$5"
170 local prompt menu_list height width rows
171
172 #
173 # Create a duplicate set of variables for change-tracking...
174 #
175 local ipaddr_orig="$2" \
176 netmask_orig="$3" \
177 options_orig="$4" \
178 dhcp_orig="$5"
179
180 local hline="$hline_arrows_tab_enter"
181 f_sprintf prompt "$msg_network_configuration" "$interface"
182
183 #
184 # Loop forever until the user has finished configuring the different
185 # components of the network interface.
186 #
187 # To apply the settings, we need to know each of the following:
188 # - IP Address
189 # - Network subnet mask
190 # - Additional ifconfig(8) options
191 #
192 # It is only when we have all of the above values that we can make the
193 # changes effective because all three options must be specified at-once
194 # to ifconfig(8).
195 #
196 local defaultitem=
197 while :; do
198 local dhcp_status="$msg_disabled"
199 [ "$dhcp" ] && dhcp_status="$msg_enabled"
200
201 #
202 # Display configuration-edit menu
203 #
204 menu_list="
205 'X $msg_save_exit' '$msg_return_to_previous_menu'
206 '2 $msg_dhcp' '$dhcp_status'
207 '3 $msg_ipaddr4' '$ipaddr'
208 '4 $msg_netmask' '$netmask'
209 '5 $msg_options' '$options'
210 "
211 eval f_dialog_menu_size height width rows \
212 \"\$DIALOG_TITLE\" \
213 \"\$DIALOG_BACKTITLE\" \
214 \"\$prompt\" \
215 \"\$hline\" \
216 $menu_list
217 local tag
218 tag=$( eval $DIALOG \
219 --title \"\$DIALOG_TITLE\" \
220 --backtitle \"\$DIALOG_BACKTITLE\" \
221 --hline \"\$hline\" \
222 --ok-label \"\$msg_ok\" \
223 --cancel-label \"\$msg_cancel\" \
224 --help-button \
225 --help-label \"\$msg_help\" \
226 ${USE_XDIALOG:+--help \"\"} \
227 --default-item \"\$defaultitem\" \
228 --menu \"\$prompt\" \
229 $height $width $rows \
230 $menu_list \
231 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
232 )
233 local retval=$?
234 f_dialog_data_sanitize tag
235
236 if [ $retval -eq $DIALOG_HELP ]; then
237 f_show_help "$TCP_HELPFILE"
238 continue
239 elif [ $retval -ne $DIALOG_OK ]; then
240 return $retval
241 else
242 # Only update default-item on success
243 defaultitem="$tag"
244 fi
245
246 #
247 # Call the below ``modifier functions'' whose job it is to take
248 # input from the user and assign the newly-acquired values back
249 # to the ipaddr, netmask, and options variables for us to re-
250 # read and display in the summary dialog.
251 #
252 case "$tag" in
253 X\ *) break ;;
254 2\ *) #
255 # Proceed cautiously (confirm with the user) if/when NFS-
256 # mounts are active. If the network on which these mounts
257 # are made is changed parts of the system may hang.
258 #
259 if f_nfs_mounted && ! f_jailed; then
260 local setting
261 f_sprintf setting "$msg_current_dhcp_status" \
262 "$interface" "$dhcp_status"
263 f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
264 continue
265 fi
266
267 #
268 # Toggle DHCP status
269 #
270 if [ "$dhcp_status" = "$msg_enabled" ]; then
271 dhcp=
272 else
273 trap - SIGINT
274 ( # Execute within sub-shell to allow/catch Ctrl-C
275 trap 'exit $FAILURE' SIGINT
276 f_sprintf msg "$msg_scanning_for_dhcp" "$interface"
277 if [ "$USE_XDIALOG" ]; then
278 (
279 f_quietly ifconfig "$interface" delete
280 f_quietly dhclient "$interface"
281 ) |
282 f_xdialog_info "$msg"
283 else
284 f_dialog_info "$msg"
285 f_quietly ifconfig "$interface" delete
286 f_quietly dhclient "$interface"
287 fi
288 )
289 retval=$?
290 trap 'interrupt' SIGINT
291 if [ $retval -eq $DIALOG_OK ]; then
292 dhcp=1
293 f_ifconfig_inet "$interface" ipaddr
294 f_ifconfig_inet6 "$interface" ipaddr6
295 f_ifconfig_netmask "$interface" netmask
296 options=
297
298 # Fixup search/domain in resolv.conf(5)
299 hostname=$( f_sysrc_get \
300 'hostname:-$(hostname)' )
301 f_dialog_resolv_conf_update "$hostname"
302 fi
303 fi
304 ;;
305 3\ *) f_dialog_input_ipaddr "$interface" "$ipaddr"
306 [ $? -eq $DIALOG_OK ] && dhcp= ;;
307 4\ *) f_dialog_input_netmask "$interface" "$netmask"
308 [ $? -eq $DIALOG_OK -a "$_netmask" ] && dhcp= ;;
309 5\ *) f_dialog_menu_media_options "$interface" "$options"
310 [ $? -eq $DIALOG_OK ] && dhcp= ;;
311 esac
312 done
313
314 #
315 # Save only if the user changed at least one feature of the interface
316 #
317 if [ "$ipaddr" != "$ipaddr_orig" -o \
318 "$netmask" != "$netmask_orig" -o \
319 "$options" != "$options_orig" -o \
320 "$dhcp" != "$dhcp_orig" ]
321 then
322 f_show_info "$msg_saving_network_interface" "$interface"
323
324 local value=
325 if [ "$dhcp" ]; then
326 f_eval_catch $funcname f_sysrc_delete \
327 'f_sysrc_delete defaultrouter'
328 value=DHCP
329 else
330 value="inet $ipaddr netmask $netmask"
331 value="$value${options:+ }$options"
332 fi
333
334 f_eval_catch $funcname f_sysrc_set \
335 'f_sysrc_set "ifconfig_%s" "%s"' "$interface" "$value"
336 fi
337
338 #
339 # Re/Apply the settings if desired
340 #
341 if [ ! "$dhcp" ]; then
342 if f_yesno "$msg_bring_interface_up" "$interface"
343 then
344 f_show_info "$msg_bring_interface_up" "$interface"
345
346 local dr="$( f_sysrc_get defaultrouter )"
347 if [ "$dr" = "NO" -o ! "$dr" ]; then
348 f_route_get_default dr
349 [ "$dr" ] && f_eval_catch \
350 $funcname f_sysrc_set \
351 'f_sysrc_set defaultrouter "%s"' "$dr"
352 fi
353 #
354 # Make a backup of resolv.conf(5) before using
355 # ifconfig(8) and then restore it afterward. This
356 # allows preservation of nameservers acquired via
357 # DHCP on FreeBSD-8.x (normally lost as ifconfig(8)
358 # usage causes dhclient(8) to exit which scrubs
359 # resolv.conf(5) by-default upon termination).
360 #
361 f_quietly cp -fp "$RESOLV_CONF" "$RESOLV_CONF.$$"
362 if f_eval_catch $funcname ifconfig \
363 'ifconfig "%s" inet "%s" netmask "%s" %s' \
364 "$interface" "$ipaddr" "$netmask" "$options"
365 then
366 [ "$dr" -a "$dr" != "NO" ] &&
367 f_eval_catch $funcname route \
368 'route add default "%s"' "$dr"
369 fi
370 if cmp -s "$RESOLV_CONF" "$RESOLV_CONF.$$"; then
371 f_quietly rm -f "$RESOLV_CONF.$$"
372 else
373 f_quietly mv -f "$RESOLV_CONF.$$" "$RESOLV_CONF"
374 fi
375 fi
376 fi
377
378 return $DIALOG_OK
379}
380
381############################################################ MAIN
382
383f_dprintf "%s: Successfully loaded." networking/device.subr
384
385fi # ! $_NETWORKING_DEVICE_SUBR