Skip to content

Commit ed35055

Browse files
committed
Use interface name instead of index during early boot.
1 parent 7db76cd commit ed35055

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

debian/bearwall2.bearwall2-early.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Wants=network-pre.target
66
[Service]
77
Type=oneshot
88
RemainAfterExit=no
9-
ExecStart=/usr/sbin/bearwall2
9+
ExecStart=/usr/sbin/bearwall2 --early
1010

1111
[Install]
1212
WantedBy=multi-user.target

src/bearwall2.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ while [ ! $# -eq 0 ]; do
3939
fi
4040
MODE="try"
4141
;;
42+
-e | --early | early)
43+
MODE="early"
44+
;;
4245
-r | --rollback | rollback)
4346
if [ "${2}" ]; then
4447
ROLLBACK_DELAY=${2}
@@ -66,6 +69,7 @@ while [ ! $# -eq 0 ]; do
6669
echo ""
6770
echo "Options:"
6871
echo " * -t|--try [time] Temporarily apply firewall rules, if not committed, automatically rollback"
72+
echo " * -e|--early Run in mode suitable for use early in the system boot process"
6973
echo " * -c|--commit Apply firewall rules from try command permanently"
7074
echo " * -r|--rollback Rollback firewall rules applied by try command immediately"
7175
echo " * -h|--help Display help"

support/firewall.functions

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ function nft(){
278278
return 0
279279
fi
280280

281+
if [ "${MODE}" == "early" ]; then
282+
# In early mode, not all interfaces may exist yet
283+
# so rewrite nft rules to look up interfaces by name, rather than by index
284+
rule=$(echo "${rule}" | sed -E "s/(^| )oif /oifname /")
285+
rule=$(echo "${rule}" | sed -E "s/(^| )iif /iifname /")
286+
fi
287+
281288
split_rule_by_terminal_statement "${rule}"
282289

283290
# Add counter to rule if counters are enabled

0 commit comments

Comments
 (0)