Skip to content

Commit

Permalink
Separate address from netmask or prefix length before validation
Browse files Browse the repository at this point in the history
The previous commits will help you start a pot that has been
configured with alias networking and addresses with netmasks or prefix
lengths, but stopping a pot may fail when it tries to remove addresses
from network interfaces.  If the netmask or prefix length is present,
ifconfig(8) won't like it very much when you try to `-alias`
a.k.a. `delete`.  So we parse the recorded addresses yet again in
order to ensure proper cleanup of network addresses.

Fixes bsdpot#268
  • Loading branch information
tnalpgge committed Jun 2, 2023
1 parent a9e0a6d commit e7b80eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion share/pot/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ _get_alias_ipv6()
# $2 network stack
_validate_alias_ipaddr()
{
local _i _nic _ip _ipv4_empty _ipv6_empty _stack
local _i _nic _ip _ipv4_empty _ipv6_empty _stack _netmask
_stack="$2"
_ipv4_empty="YES"
_ipv6_empty="YES"
Expand All @@ -294,6 +294,12 @@ _validate_alias_ipaddr()
else
_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 ipcheck -H "$_ip" 2> /dev/null ; then
_error "$_ip is not a valid IP address"
return 1 # false
Expand Down
4 changes: 4 additions & 0 deletions share/pot/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ _js_stop()
_nic="$POT_EXTIF"
_ipaddr="$_i"
fi
if echo "$_ipaddr" | grep -qF '/' ; then
_netmask="$(echo "$_ipaddr" | cut -f 2 -d '/' )"
_ipaddr="$(echo "$_ipaddr" | cut -f 1 -d '/' )"
fi
if potnet ip4check -H "$_ipaddr" ; then
if ifconfig "${_nic}" | grep -q "inet $_ipaddr " ; then
ifconfig "${_nic}" inet "$_ipaddr" -alias
Expand Down

0 comments on commit e7b80eb

Please sign in to comment.