1ab2043b8SDevin Teskeif [ ! "$_NETWORKING_ROUTING_SUBR" ]; then _NETWORKING_ROUTING_SUBR=1 2ab2043b8SDevin Teske# 37323adacSDevin Teske# Copyright (c) 2006-2013 Devin Teske 4f8ea072aSDevin 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 168e37a7c8SDevin 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 208e37a7c8SDevin Teske# DAMAGES (INCLUDING, 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# 28ab2043b8SDevin Teske############################################################ INCLUDES 29ab2043b8SDevin Teske 30ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 31ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 3256961fd7SDevin Teskef_dprintf "%s: loading includes..." networking/routing.subr 33ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr 347323adacSDevin Teskef_include $BSDCFG_SHARE/media/tcpip.subr 35ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/common.subr 36ab2043b8SDevin Teskef_include $BSDCFG_SHARE/networking/ipaddr.subr 37*d4ae33f0SDevin Teskef_include $BSDCFG_SHARE/strings.subr 381de60ff0SDevin Teskef_include $BSDCFG_SHARE/sysrc.subr 39ab2043b8SDevin Teske 40ab2043b8SDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" 41ab2043b8SDevin Teskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 42ab2043b8SDevin Teske 43ab2043b8SDevin Teske############################################################ FUNCTIONS 44ab2043b8SDevin Teske 45ab2043b8SDevin Teske# f_dialog_input_defaultrouter 46ab2043b8SDevin Teske# 47ab2043b8SDevin Teske# Edits the default router. 48ab2043b8SDevin Teske# 49ab2043b8SDevin Teskef_dialog_input_defaultrouter() 50ab2043b8SDevin Teske{ 51*d4ae33f0SDevin Teske local funcname=f_dialog_input_defaultrouter 52*d4ae33f0SDevin Teske 53ab2043b8SDevin Teske # 54ab2043b8SDevin Teske # Get the defaultrouter. When this is not configured, the default is 55ab2043b8SDevin Teske # "NO", however we don't ever want to present this default to the user 56ab2043b8SDevin Teske # in the following dialog. If the current value is "NO", then try to 57ab2043b8SDevin Teske # obtain the value from the running system using route(8). 58ab2043b8SDevin Teske # 59ab2043b8SDevin Teske # NOTE: Our `f_route_get_default' function will return NULL if the 60ab2043b8SDevin Teske # system does not have an active default router set (which is what we 61ab2043b8SDevin Teske # want). 62ab2043b8SDevin Teske # 63ab2043b8SDevin Teske local defaultrouter="$( f_sysrc_get 'defaultrouter:-NO' )" 64ab2043b8SDevin Teske local defaultrouter_orig="$defaultrouter" # for change-tracking 65ab2043b8SDevin Teske case "$defaultrouter" in 66*d4ae33f0SDevin Teske [Nn][Oo]) f_route_get_default defaultrouter ;; 67ab2043b8SDevin Teske esac 68ab2043b8SDevin Teske 69ab2043b8SDevin Teske # 70ab2043b8SDevin Teske # Return with-error when there are NFS-mounts currently active. If the 71ab2043b8SDevin Teske # default router/gateway is changed while NFS-exported directories are 72ab2043b8SDevin Teske # mounted, the system will hang. 73ab2043b8SDevin Teske # 74ab2043b8SDevin Teske if f_nfs_mounted && ! f_jailed; then 75*d4ae33f0SDevin Teske local setting 76*d4ae33f0SDevin Teske f_sprintf setting "$msg_current_default_router" \ 77*d4ae33f0SDevin Teske "$defaultrouter" 7839c22926SDevin Teske f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" || 79f677a9e2SDevin Teske return $DIALOG_CANCEL 80ab2043b8SDevin Teske fi 81ab2043b8SDevin Teske 82ab2043b8SDevin Teske # 83ab2043b8SDevin Teske # Loop until the user provides taint-free input. 84ab2043b8SDevin Teske # 85298cf604SDevin Teske local retval 86ab2043b8SDevin Teske while :; do 87ec7120b5SDevin Teske f_dialog_input defaultrouter \ 88298cf604SDevin Teske "$msg_please_enter_default_router" \ 89298cf604SDevin Teske "$defaultrouter" "$hline_num_punc_tab_enter" 90298cf604SDevin Teske retval=$? 91f677a9e2SDevin Teske [ "$defaultrouter" ] || return $DIALOG_OK 92f677a9e2SDevin Teske [ $retval -eq $DIALOG_OK ] || return $retval 93ab2043b8SDevin Teske 94ab2043b8SDevin Teske # Taint-check the user's input 95ab2043b8SDevin Teske f_dialog_validate_ipaddr "$defaultrouter" && break 96ab2043b8SDevin Teske done 97ab2043b8SDevin Teske 98ab2043b8SDevin Teske # 99ab2043b8SDevin Teske # Save only if the user changed the default router/gateway. 100ab2043b8SDevin Teske # 101ab2043b8SDevin Teske if [ "$defaultrouter" != "$defaultrouter_orig" ]; then 102ab2043b8SDevin Teske f_dialog_info "$msg_saving_default_router" 103ab2043b8SDevin Teske 104ab2043b8SDevin Teske # Save the default router/gateway 105*d4ae33f0SDevin Teske f_eval_catch $funcname f_sysrc_set \ 106*d4ae33f0SDevin Teske 'f_sysrc_set defaultrouter "%s"' "$defaultrouter" 107ab2043b8SDevin Teske fi 108ab2043b8SDevin Teske 109ab2043b8SDevin Teske # 110ab2043b8SDevin Teske # Only ask to apply setting if the current defaultrouter is different 111ab2043b8SDevin Teske # than the stored configuration (in rc.conf(5)). 112ab2043b8SDevin Teske # 113*d4ae33f0SDevin Teske local dr 114*d4ae33f0SDevin Teske f_route_get_default dr 115*d4ae33f0SDevin Teske if [ "$dr" != "$defaultrouter" ]; then 116ab2043b8SDevin Teske f_dialog_clear 117*d4ae33f0SDevin Teske f_yesno "$msg_activate_default_router" "$dr" "$defaultrouter" 118f677a9e2SDevin Teske if [ $? -eq $DIALOG_OK ]; then 119ab2043b8SDevin Teske # Apply the default router/gateway 120*d4ae33f0SDevin Teske f_eval_catch -d $funcname route 'route delete default' 121*d4ae33f0SDevin Teske f_eval_catch $funcname route \ 122*d4ae33f0SDevin Teske 'route add default "%s"' "$defaultrouter" || 123f677a9e2SDevin Teske return $DIALOG_CANCEL 124ab2043b8SDevin Teske fi 125ab2043b8SDevin Teske fi 126ab2043b8SDevin Teske} 127ab2043b8SDevin Teske 12856961fd7SDevin Teske############################################################ MAIN 12956961fd7SDevin Teske 13056961fd7SDevin Teskef_dprintf "%s: Successfully loaded." networking/routing.subr 13156961fd7SDevin Teske 132ab2043b8SDevin Teskefi # ! $_NETWORKING_ROUTING_SUBR 133