1 if [ ! "$_NETWORKING_MEDIA_SUBR" ]; then _NETWORKING_MEDIA_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/media.subr
34 f_include $BSDCFG_SHARE/dialog.subr
35 f_include $BSDCFG_SHARE/networking/common.subr
36 f_include $BSDCFG_SHARE/strings.subr
37 f_include $BSDCFG_SHARE/sysrc.subr
39 BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
40 f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
42 ############################################################ FUNCTIONS
44 # f_ifconfig_options $interface
46 # Returns any/all extra ifconfig(8) parameters associated with $interface.
51 [ "$interface" ] || return $SUCCESS
54 # Loop over the options, removing what we don't want
57 set -- $( f_sysrc_get ifconfig_$interface )
60 # Return if the interface is configured for DHCP
62 glob="[Dd][Hh][Cc][Pp]"
64 $glob|[Ss][Yy][Nn][Cc]$glob|[Nn][Oo][Ss][Yy][Nn][Cc]$glob)
69 while [ $# -gt 0 ]; do
71 inet|netmask) shift 1 ;;
72 *) output="$output${output:+ }$1"
80 # f_ifconfig_media $interface
82 # Returns list of supported media for $interface.
87 ifconfig -m "$interface" 2> /dev/null | awk \
89 BEGIN { media_found = 0 }
91 if ( media_found == 1 ) { print; next }
93 ( $1 $2 == "supported" "media:" ) \
98 END { exit ! media_found }
102 # f_dialog_input_options $interface
104 # Input custom interface options. If the user does not press ESC or choose
105 # Cancel/No, $options will hold the user's input. Default input is taken from
106 # the same variable ($options).
108 f_dialog_input_options()
113 # Return with-error when there are NFS-mounts currently active. If the
114 # options are changed while NFS-exported directories are mounted,
115 # the system may hang (if any NFS mounts are using that interface).
117 if f_nfs_mounted && ! f_jailed; then
118 local setting="$( printf "$msg_current_options" \
119 "$interface" "$options" )"
120 f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
121 return $DIALOG_CANCEL
124 local msg="$( printf "$msg_please_enter_mediaopts" "$interface" )"
125 local hline="$hline_alnum_punc_tab_enter"
128 _options=$( $DIALOG \
129 --title "$DIALOG_TITLE" \
130 --backtitle "$DIALOG_BACKTITLE" \
132 --ok-label "$msg_ok" \
133 --cancel-label "$msg_cancel" \
134 --inputbox "$msg" 9 70 \
136 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
139 f_dialog_line_sanitize _options
141 [ $retval -eq $DIALOG_OK ] && options="$_options"
146 # f_dialog_menu_media_options $interface
148 # Display a menu of additional media options for the given network interface.
150 f_dialog_menu_media_options()
152 local interface="$1" _options="$2"
154 # Not all network interfaces support additional media options, but
155 # when available we should prompt the user to select from a list
156 # of available options (or none, as is the first/default option).
160 # Return with-error when there are NFS-mounts currently active. If the
161 # media options are changed while NFS-exported directories are mounted,
162 # the system may hang (if any NFS mounts are using that interface).
164 if f_nfs_mounted && ! f_jailed; then
165 local setting="$( printf "$msg_current_options" \
166 "$interface" "$_options" )"
167 f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
168 return $DIALOG_CANCEL
172 # Build list of additional media options
174 local opt_none="$msg_no_options"
175 local opt_cust="$msg_custom"
176 local supported_media="$(
177 f_ifconfig_media $interface | \
180 echo "'$( f_substr "$DIALOG_MENU_TAGS" $index 1 )'"
182 index=$(( $index + 1 ))
184 echo "'$( f_substr "$DIALOG_MENU_TAGS" $index 1 )'"
186 index=$(( $index + 1 ))
188 while read media_options; do
189 [ $index -lt ${#DIALOG_MENU_TAGS} ] || break
190 echo "'$( f_substr "$DIALOG_MENU_TAGS" $index 1 )'"
191 echo "'$media_options'"
192 index=$(( $index + 1 ))
198 if [ "$USE_XDIALOG" ]; then
199 msg=$( printf "$xmsg_supported_media_options" \
200 "$interface" "$interface" )
202 msg=$( printf "$msg_supported_media_options" \
203 "$interface" "$interface" )
206 local hline="$hline_arrows_tab_enter"
209 tag=$( eval $DIALOG \
210 --title \"\$DIALOG_TITLE\" \
211 --backtitle \"\$DIALOG_BACKTITLE\" \
212 --hline \"\$hline\" \
213 --ok-label \"\$msg_ok\" \
214 --cancel-label \"\$msg_cancel\" \
215 --menu \"\$msg\" 21 60 12 \
217 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
220 f_dialog_data_sanitize tag
222 if [ $retval -eq $DIALOG_OK ]; then
223 options=$( eval f_dialog_menutag2item \"\$tag\" \
231 f_dialog_input_options "$interface"
240 ############################################################ MAIN
242 f_dprintf "%s: Successfully loaded." networking/media.subr
244 fi # ! $_NETWORKING_MEDIA_SUBR