mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-27 11:55:06 +00:00
Add a new configuration variable, ipv4_addrs_<ifn>, which adds one or
more IPv4 address from a ranged list in CIRD notation: ipv4_addrs_ed0="192.168.0.1/24 192.168.1.1-5/28" In the process move alias processing into new ipv4_up/down functions to more toward a less IPv4 centric world. Submitted by: Philipp Wuensche <cryx dash freebsd at h3q dot com>
This commit is contained in:
parent
4b01ab171d
commit
cda39c0193
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=152441
@ -154,6 +154,7 @@ ifconfig_lo0="inet 127.0.0.1" # default loopback device configuration.
|
||||
#ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample alias entry.
|
||||
#ifconfig_ed0_ipx="ipx 0x00010010" # Sample IPX address family entry.
|
||||
#ifconfig_fxp0_name="net0" # Change interface name from fxp0 to net0.
|
||||
#ipv4_addrs_fxp0="192.168.0.1/24 192.168.1.1-5/28" # example IPv4 address entry.
|
||||
#
|
||||
# If you have any sppp(4) interfaces above, you might also want to set
|
||||
# the following parameters. Refer to spppcontrol(8) for their meaning.
|
||||
|
@ -198,6 +198,64 @@ wpaif()
|
||||
return 1
|
||||
}
|
||||
|
||||
# ipv4_up if
|
||||
# add IPv4 addresses to the interface $if
|
||||
ipv4_up()
|
||||
{
|
||||
_if=$1
|
||||
ifalias_up ${_if}
|
||||
ipv4_addrs_common ${_if} alias
|
||||
}
|
||||
|
||||
# ipv4_down if
|
||||
# remove IPv4 addresses from the interface $if
|
||||
ipv4_down()
|
||||
{
|
||||
_if=$1
|
||||
ifalias_down ${_if}
|
||||
ipv4_addrs_common ${_if} -alias
|
||||
}
|
||||
|
||||
# ipv4_addrs_common if action
|
||||
# Evaluate the ifconfig_if_ipv4 arguments for interface $if
|
||||
# and use $action to add or remove IPv4 addresses from $if.
|
||||
ipv4_addrs_common()
|
||||
{
|
||||
_ret=1
|
||||
_if=$1
|
||||
_action=$2
|
||||
|
||||
# get ipv4-addresses
|
||||
eval cidr_addr=\${ipv4_addrs_${_if}}
|
||||
|
||||
for _cidr in ${cidr_addr}; do
|
||||
_ipaddr=${_cidr%%/*}
|
||||
_netmask="/"${_cidr##*/}
|
||||
_range=${_ipaddr##*.}
|
||||
_ipnet=${_ipaddr%.*}
|
||||
_iplow=${_range%-*}
|
||||
_iphigh=${_range#*-}
|
||||
|
||||
# clear netmask when removing aliases
|
||||
if [ "${_action}" = "-alias" ]; then
|
||||
_netmask=""
|
||||
fi
|
||||
|
||||
_ipcount=${_iplow}
|
||||
while [ "${_ipcount}" -le "${_iphigh}" ]; do
|
||||
eval "ifconfig ${_if} ${_action} ${_ipnet}.${_ipcount}${_netmask}"
|
||||
_ipcount=$((${_ipcount}+1))
|
||||
_ret=0
|
||||
|
||||
# only the first ipaddr in a subnet need the real netmask
|
||||
if [ "${_action}" != "-alias" ]; then
|
||||
_netmask="/32"
|
||||
fi
|
||||
done
|
||||
done
|
||||
return $_ret
|
||||
}
|
||||
|
||||
# ifalias_up if
|
||||
# Configure aliases for network interface $if.
|
||||
# It returns 0 if at least one alias was configured or
|
||||
|
@ -150,7 +150,7 @@ ifn_start()
|
||||
|
||||
ifscript_up ${ifn} && cfg=0
|
||||
ifconfig_up ${ifn} && cfg=0
|
||||
ifalias_up ${ifn} && cfg=0
|
||||
ipv4_up ${ifn} && cfg=0
|
||||
ipx_up ${ifn} && cfg=0
|
||||
|
||||
return $cfg
|
||||
@ -165,7 +165,7 @@ ifn_stop()
|
||||
[ -z "$ifn" ] && return 1
|
||||
|
||||
ipx_down ${ifn} && cfg=0
|
||||
ifalias_down ${ifn} && cfg=0
|
||||
ipv4_down ${ifn} && cfg=0
|
||||
ifconfig_down ${ifn} && cfg=0
|
||||
ifscript_down ${ifn} && cfg=0
|
||||
|
||||
|
@ -946,9 +946,26 @@ Such keywords are removed before passing the value to
|
||||
.Xr ifconfig 8
|
||||
while the order of the other arguments is preserved.
|
||||
.Pp
|
||||
It is also possible to add IP alias entries here in cases where
|
||||
multiple IP addresses registered against a single interface
|
||||
are desired.
|
||||
One can configure more than one IPv4 address with the
|
||||
.Va ipv4_addrs_ Ns Aq Ar interface
|
||||
variable.
|
||||
One or more IP addresses must be provided in Classless Inter-Domain
|
||||
Routing (CIDR) address notation, whose last byte can be a range like
|
||||
192.168.0.5-23/24.
|
||||
In this case the address 192.168.0.5 will be configured with the
|
||||
netmask /24 and the addresses 192.168.0.6 to 192.168.0.23 with
|
||||
the non-conflicting netmask /32 as explained in the ifconfig(8)
|
||||
alias section.
|
||||
With the interface in question being
|
||||
.Li ed0,
|
||||
an example could look like:
|
||||
.Bd -literal
|
||||
ipv4_addrs_ed0="192.168.0.1/24 192.168.1.1-5/28"
|
||||
.Ed
|
||||
.Pp
|
||||
It is also possible to add IP alias entries using
|
||||
.Xr ifconfig 8
|
||||
syntax.
|
||||
Assuming that the interface in question was
|
||||
.Li ed0 ,
|
||||
it might look
|
||||
@ -979,6 +996,9 @@ be added since the search would
|
||||
stop with the missing
|
||||
.Dq Li alias3
|
||||
entry.
|
||||
Due to this difficult to manage behavior, the
|
||||
.Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n
|
||||
form is deprecated.
|
||||
.Pp
|
||||
If the
|
||||
.Pa /etc/start_if. Ns Aq Ar interface
|
||||
|
Loading…
Reference in New Issue
Block a user