diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-07-02 22:04:25 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-07-02 22:04:25 +0300 |
| commit | 5c235db068ae5b604a2a315f8bdbba0e7853a756 (patch) | |
| tree | 5c75e6d6806f30e61e0721eab1e3c64aced65004 /templates | |
| parent | 026131479b0281ea0cdfd6ac5edfaa79fced3f2a (diff) | |
Restore jail aliases on if up
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/etc_devd_lan0_jail_restore.conf.j2 | 6 | ||||
| -rw-r--r-- | templates/etc_rc.conf.j2 | 1 | ||||
| -rw-r--r-- | templates/usr_local_bin_restore_jail_aliases.sh.j2 | 27 |
3 files changed, 34 insertions, 0 deletions
diff --git a/templates/etc_devd_lan0_jail_restore.conf.j2 b/templates/etc_devd_lan0_jail_restore.conf.j2 new file mode 100644 index 0000000..c59b428 --- /dev/null +++ b/templates/etc_devd_lan0_jail_restore.conf.j2 @@ -0,0 +1,6 @@ +notify 10 { + match "system" "IFNET"; + match "subsystem" "lan0"; + match "type" "LINK_UP"; + action "/usr/local/bin/restore_jail_aliases.sh"; +}; diff --git a/templates/etc_rc.conf.j2 b/templates/etc_rc.conf.j2 index 99746f4..6dec6ea 100644 --- a/templates/etc_rc.conf.j2 +++ b/templates/etc_rc.conf.j2 @@ -26,3 +26,4 @@ nginx_enable="YES" clear_tmp_enable="YES" cleanvar_enable="YES" auditd_enable="YES" +devd_enable="YES" diff --git a/templates/usr_local_bin_restore_jail_aliases.sh.j2 b/templates/usr_local_bin_restore_jail_aliases.sh.j2 new file mode 100644 index 0000000..25d317f --- /dev/null +++ b/templates/usr_local_bin_restore_jail_aliases.sh.j2 @@ -0,0 +1,27 @@ +#!/bin/sh + +# The point of this script is to restore jail aliases +# if the lan0 interface flaps + +if_lan="lan0" +ipv4_out="$(ifconfig lan0 | grep "inet " | grep -v "0xffffffff")" +ipv4_lan="$(echo "${ipv4_out}" | awk '{ print $2 }')" +ipv4_mask="$(echo "${ipv4_out}" | awk '{ print $4 }')" + +if ! [ "$ipv4_mask" = "0xffff0000" ]; then + >&2 echo "Unexpected netmask on lan0: ${ipv4_mask}" + exit 1 +fi + +jls ip4.addr | while read ip; do + case "$ip" in + "192.168"*) ;; + *) continue ;; + esac + if ifconfig "$if_lan" | grep -q "$ip"; then + continue + fi + + echo "Re-adding $ip to $if_lan" + ifconfig "$if_lan" inet "$ip/32" alias +done |
