Deleted Added
sdiff udiff text old ( 243475 ) new ( 243504 )
full compact
1if [ ! "$_NETWORKING_IPADDR_SUBR" ]; then _NETWORKING_IPADDR_SUBR=1
2#
3# Copyright (c) 2006-2012 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:

--- 10 unchanged lines hidden (view full) ---

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/ipaddr.subr 243475 2012-11-24 06:27:46Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_include $BSDCFG_SHARE/sysrc.subr
34f_include $BSDCFG_SHARE/dialog.subr
35f_include $BSDCFG_SHARE/strings.subr

--- 19 unchanged lines hidden (view full) ---

55 print $2
56 found = 1
57 exit
58 }
59 END { exit ! found }
60 '
61}
62
63# f_dialog_validate_ipaddr $ipaddr
64#
65# Returns zero if the given argument (an IP address) is of the proper format.
66#
67# The return status for invalid IP address is one of:
68# 1 One or more individual octets within the IP address (separated
69# by dots) contains one or more invalid characters.
70# 2 One or more individual octets within the IP address are null
71# and/or missing.
72# 3 One or more individual octets within the IP address exceeds the
73# maximum of 255 (or 2^8, being an octet comprised of 8 bits).
74# 4 The IP address has either too few or too many octets.
75#
76# If the IP address is determined to be invalid, the appropriate error will be
77# displayed using the f_dialog_msgbox function.
78#
79f_dialog_validate_ipaddr()
80{
81 local ip="$1"
82
83 ( # Operate within a sub-shell to protect the parent environment
84
85 # Track number of octets for error checking
86 noctets=0
87

--- 13 unchanged lines hidden (view full) ---

101 [ $octet -gt 255 ] && exit 3
102
103 noctets=$(( $noctets + 1 ))
104
105 done
106
107 [ $noctets -eq 4 ] || exit 4
108 )
109
110 #
111 # Produce an appropriate error message if necessary.
112 #
113 local retval=$?
114 case $retval in
115 1) f_dialog_msgbox "$( printf \
116 "$msg_ipv4_addr_octet_contains_invalid_chars" "$ip" )";;
117 2) f_dialog_msgbox "$( printf \
118 "$msg_ipv4_addr_octet_is_null" "$ip" )";;
119 3) f_dialog_msgbox "$( printf \
120 "$msg_ipv4_addr_octet_exceeds_max_value" "$ip" )";;
121 4) f_dialog_msgbox "$( printf \
122 "$msg_ipv4_addr_octet_missing_or_extra" "$ip" )";;
123 esac
124
125 return $retval
126}
127
128# f_dialog_validate_ipaddr6 $ipv6_addr
129#
130# Returns zero if the given argument (an IPv6 address) is of the proper format.
131#
132# The return status for invalid IP address is one of:
133# 1 One or more individual segments within the IP address
134# (separated by colons) contains one or more invalid characters.
135# 2 More than two segments within the IP address are null or the
136# the second null segment is not at the end of the address.
137# 3 One or more individual segments within the IP address exceeds
138# the word length of 32-bits (segments are always hexadecimal).
139# 4 The IP address has either too few or too many segments.
140# 5 The IPv4 address at the end of the IPv6 address is invalid.
141#
142# If the IP address is determined to be invalid, the appropriate error will be
143# displayed using the f_dialog_msgbox function.
144#
145f_dialog_validate_ipaddr6()
146{
147 local ip="$1"
148
149 ( # Operate within a sub-shell to protect the parent environment
150
151 oldIFS="$IFS"
152 IFS=":" # Split on `colon'
153 set -- $ip:
154
155 # Return error if too many or too few segments
156 # Using 9 as max in case of leading or trailing null spanner
157 [ $# -gt 9 -o $# -lt 3 ] && exit 4
158
159 h="[0-9A-Fa-f]"

--- 51 unchanged lines hidden (view full) ---

211 # Return error if not enough segments
212 if [ $nulls -eq 0 ]; then
213 [ $nsegments -eq 7 ] || exit 4
214 fi
215
216 contains_ipv4_segment=1
217
218 # Validate the IPv4 address
219 IFS="$oldIFS"
220 f_dialog_validate_ipaddr "$segment" || exit 5
221 IFS=":"
222 ;;
223 *)
224 # Segment characters are all valid but too many
225 exit 3
226 esac
227
228 done
229

--- 19 unchanged lines hidden (view full) ---

249 # Return error if null spanner with too many segments
250 1) [ $nsegments -le $maxsegments ] || exit 4 ;;
251 # Return error if leading/trailing `::' with too many segments
252 2) [ $nsegments -le $(( $maxsegments + 1 )) ] || exit 4 ;;
253 esac
254
255 exit $SUCCESS
256 )
257
258 #
259 # Produce an appropriate error message if necessary.
260 #
261 local retval=$?
262 case $retval in
263 1) f_dialog_msgbox "$( printf \
264 "$msg_ipv6_addr_segment_contains_invalid_chars" "$ip" )";;
265 2) f_dialog_msgbox "$( printf \
266 "$msg_ipv6_addr_too_many_null_segments" "$ip" )";;
267 3) f_dialog_msgbox "$( printf \
268 "$msg_ipv6_addr_segment_contains_too_many_chars" "$ip" )";;
269 4) f_dialog_msgbox "$( printf \
270 "$msg_ipv6_addr_too_few_or_extra_segments" "$ip" )";;
271 5) : IPv4 at the end of IPv6 address is invalid ;;
272 # Don't display an error because f_dialog_validate_ipaddr
273 # already displayed one for the particular issue encountered.
274 esac
275
276 return $retval
277}
278
279# f_dialog_input_ipaddr $interface $ipaddr
280#
281# Allows the user to edit a given IP address. If the user does not cancel or
282# press ESC, the $ipaddr environment variable will hold the newly-configured
283# value upon return.

--- 107 unchanged lines hidden ---