Skip to content

Commit

Permalink
Allow netmask in IPv4 alias address
Browse files Browse the repository at this point in the history
`jail(8)` manual page states that the `ip4.addr` parameter supports
the format `interface|ip-address/netmask param ...`.  While we can't
really accommodate the `param ...` portion easily with shell scripts,
we can pretty easily deal with the presence or absence of the extra
notation for the netmask.

Part of bsdpot#268
  • Loading branch information
tnalpgge committed Nov 5, 2023
1 parent 46f13fe commit 193c41d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion share/pot/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ _get_pot_network_stack()
# $2 ipaddr
_get_alias_ipv4()
{
local _i _ip _nic _output
local _i _ip _nic _output _netmask
_output=
if [ "$( _get_pot_network_stack "$1" )" != "ipv6" ]; then
for _i in $2 ; do
Expand All @@ -218,12 +218,21 @@ _get_alias_ipv4()
_nic="$POT_EXTIF"
_ip="$_i"
fi
if echo "$_ip" | grep -qF '/' ; then
_netmask="$( echo "$_ip" | cut -f 2 -d '/' )"
_ip="$( echo "$_ip" | cut -f 1 -d '/' )"
else
_netmask=""
fi
if potnet ip4check -H "$_ip" 2> /dev/null ; then
if [ -z "$_output" ]; then
_output="$_nic|$_ip"
else
_output="$_output,$_nic|$_ip"
fi
if [ -n "$_netmask" ]; then
_output="$_output/$_netmask"
fi
fi
done
fi
Expand Down

0 comments on commit 193c41d

Please sign in to comment.