Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pfctl being invoked when NAT is not used + change ip var to ip4 #769

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions usr/local/share/bastille/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ for _jail in ${JAILS}; do
fi

## warn if matching configured (but not online) ip4.addr, ignore if there's no ip4.addr entry
ip=$(bastille config "${_jail}" get ip4.addr)
if [ -n "${ip}" ]; then
if ifconfig | grep -wF "${ip}" >/dev/null; then
error_notify "Error: IP address (${ip}) already in use."
_ip4=$(bastille config "${_jail}" get ip4.addr)
if [ "${_ip4}" != "not set" ]; then
if ifconfig | grep -wF "${_ip4}" >/dev/null; then
error_notify "Error: IP address (${_ip4}) already in use."
continue
fi
## add ip4.addr to firewall table
pfctl -q -t "${bastille_network_pf_table}" -T add "${ip}"
pfctl -q -t "${bastille_network_pf_table}" -T add "${_ip4}"
fi

## start the container
Expand Down
8 changes: 4 additions & 4 deletions usr/local/share/bastille/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ for _jail in ${JAILS}; do
## test if running
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
## Capture ip4.addr address while still running
_ip="$(/usr/sbin/jls -j ${_jail} ip4.addr)"
_ip4="$( bastille config ${_jail} get ip4.addr )"
tschettervictor marked this conversation as resolved.
Show resolved Hide resolved

# Check if pfctl is present
if which -s pfctl; then
if [ which -s pfctl ] && [ "${_ip4}" != "not set" ]; then
tschettervictor marked this conversation as resolved.
Show resolved Hide resolved
if [ "$(bastille rdr ${_jail} list)" ]; then
bastille rdr ${_jail} clear
fi
Expand All @@ -73,9 +73,9 @@ for _jail in ${JAILS}; do
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r "${_jail}"

## remove (captured above) ip4.addr from firewall table
if [ -n "${bastille_network_loopback}" -a ! -z "${_ip}" ]; then
if [ -n "${bastille_network_loopback}" ] && [ "${_ip4}" != "not set" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip}"
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip4}"
fi
fi
fi
Expand Down