1 if [ ! "$_NETWORKING_ROUTING_SUBR" ]; then _NETWORKING_ROUTING_SUBR=1
3 # Copyright (c) 2006-2013 Devin Teske
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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
29 ############################################################ INCLUDES
31 BSDCFG_SHARE="/usr/share/bsdconfig"
32 . $BSDCFG_SHARE/common.subr || exit 1
33 f_dprintf "%s: loading includes..." networking/routing.subr
34 f_include $BSDCFG_SHARE/dialog.subr
35 f_include $BSDCFG_SHARE/media/tcpip.subr
36 f_include $BSDCFG_SHARE/networking/common.subr
37 f_include $BSDCFG_SHARE/networking/ipaddr.subr
38 f_include $BSDCFG_SHARE/sysrc.subr
40 BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
41 f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
43 ############################################################ FUNCTIONS
45 # f_dialog_input_defaultrouter
47 # Edits the default router.
49 f_dialog_input_defaultrouter()
52 # Get the defaultrouter. When this is not configured, the default is
53 # "NO", however we don't ever want to present this default to the user
54 # in the following dialog. If the current value is "NO", then try to
55 # obtain the value from the running system using route(8).
57 # NOTE: Our `f_route_get_default' function will return NULL if the
58 # system does not have an active default router set (which is what we
61 local defaultrouter="$( f_sysrc_get 'defaultrouter:-NO' )"
62 local defaultrouter_orig="$defaultrouter" # for change-tracking
63 case "$defaultrouter" in
65 defaultrouter=$( f_route_get_default )
70 # Return with-error when there are NFS-mounts currently active. If the
71 # default router/gateway is changed while NFS-exported directories are
72 # mounted, the system will hang.
74 if f_nfs_mounted && ! f_jailed; then
75 local setting="$( printf "$msg_current_default_router" \
77 f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
82 # Loop until the user provides taint-free input.
86 f_dialog_input defaultrouter \
87 "$msg_please_enter_default_router" \
88 "$defaultrouter" "$hline_num_punc_tab_enter"
90 [ "$defaultrouter" ] || return $SUCCESS
91 [ $retval -eq $SUCCESS ] || return $retval
93 # Taint-check the user's input
94 f_dialog_validate_ipaddr "$defaultrouter" && break
98 # Save only if the user changed the default router/gateway.
100 if [ "$defaultrouter" != "$defaultrouter_orig" ]; then
101 f_dialog_info "$msg_saving_default_router"
103 # Save the default router/gateway
104 f_sysrc_set defaultrouter "$defaultrouter"
108 # Only ask to apply setting if the current defaultrouter is different
109 # than the stored configuration (in rc.conf(5)).
111 if [ "$( f_route_get_default )" != "$defaultrouter" ]; then
113 f_yesno "$msg_activate_default_router" \
114 "$( f_route_get_default )" "$defaultrouter"
115 if [ $? -eq $SUCCESS ]; then
118 # Apply the default router/gateway
119 f_quietly route delete default
120 err=$( route add default "$defaultrouter" 2>&1 )
121 if [ $? -ne $SUCCESS ]; then
122 f_dialog_msgbox "$err"
129 ############################################################ MAIN
131 f_dprintf "%s: Successfully loaded." networking/routing.subr
133 fi # ! $_NETWORKING_ROUTING_SUBR