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

Enhancement: optional ext_if6 macro in pf.conf to enable rdr for non-VNET dual-stack jails #627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion usr/local/bin/bastille
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bastille_conf_check
. /usr/local/etc/bastille/bastille.conf
# Set default values for config properties added during the current major version:
: "${bastille_network_pf_ext_if:=ext_if}"
: "${bastille_network_pf_ext_if:=ext_if6}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this variable is meant to be ${bastille_network_pf_ext_if6:=ext_if6}?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct... I fixed it locally but forgot to push.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waseigo can you push the change so we can review it again?

: "${bastille_network_pf_table:=jails}"

## bastille_prefix should be 0750
Expand All @@ -62,7 +63,7 @@ bastille_perms_check() {
bastille_perms_check

## version
BASTILLE_VERSION="0.10.20231013"
BASTILLE_VERSION=b7d741b5cd3b0c758f0983fd9546e88fba0354d7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be included in the patch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will keep it in mind for next time!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waseigo please then remove the change from your PR


usage() {
cat << EOF
Expand Down
1 change: 1 addition & 0 deletions usr/local/etc/bastille/bastille.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ bastille_export_options="" ## default
## Networking
bastille_network_loopback="bastille0" ## default: "bastille0"
bastille_network_pf_ext_if="ext_if" ## default: "ext_if"
bastille_network_pf_ext_if6="ext_if6" ## default: "ext_if6"
bastille_network_pf_table="jails" ## default: "jails"
bastille_network_shared="" ## default: ""
bastille_network_gateway="" ## default: ""
Expand Down
16 changes: 13 additions & 3 deletions usr/local/share/bastille/rdr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ JAIL_NAME=""
JAIL_IP=""
JAIL_IP6=""
EXT_IF=""
EXT_IF6=""
shift

check_jail_validity() {
Expand All @@ -76,7 +77,7 @@ check_jail_validity() {
fi
# Check if jail ip6 address (ip6.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
if [ "$(bastille config $TARGET get ip6)" != 'disable' ] && [ "$(bastille config $TARGET get ip6)" != 'not set' ]; then
if [ "$(bastille config $TARGET get ip6)" != 'disable' ] && [ "$(bastille config $TARGET get ip6.addr)" != 'not set' ]; then
JAIL_IP6=$(/usr/sbin/jls -j "${TARGET}" ip6.addr 2>/dev/null)
fi
fi
Expand All @@ -94,6 +95,15 @@ check_jail_validity() {
error_exit "bastille_network_pf_ext_if (${bastille_network_pf_ext_if}) not defined in pf.conf"
fi
fi
# Check if ext_if6 is defined in pf.conf (non-VNET only)
if [ -n "${bastille_pf_conf}" ]; then
EXT_IF6=$(grep "^[[:space:]]*${bastille_network_pf_ext_if6}[[:space:]]*=" ${bastille_pf_conf})
if [ -z "${EXT_IF6}" ]; then
error_exit "bastille_network_pf_ext_if6 (${bastille_network_pf_ext_if6}) not defined in pf.conf"
fi
fi


}

# function: write rule to rdr.conf
Expand All @@ -120,7 +130,7 @@ load_rdr_rule() {
| pfctl -a "rdr/${JAIL_NAME}" -f-
if [ -n "$JAIL_IP6" ]; then
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP6" "$3" ) \
printf '%s\nrdr pass on $%s inet6 proto %s to port %s -> %s port %s\n' "$EXT_IF6" "${bastille_network_pf_ext_if6}" "$1" "$2" "$JAIL_IP6" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
fi
}
Expand All @@ -135,7 +145,7 @@ log=$@
| pfctl -a "rdr/${JAIL_NAME}" -f-
if [ -n "$JAIL_IP6" ]; then
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP6" "$jail_port" ) \
printf '%s\nrdr pass %s on $%s inet6 proto %s to port %s -> %s port %s\n' "$EXT_IF6" "$log" "${bastille_network_pf_ext_if6}" "$proto" "$host_port" "$JAIL_IP6" "$jail_port" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
fi

Expand Down