File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
nixos/modules/services/networking Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 273273
274274 ${ cfg . extraStopCommands }
275275
276+ N_OUTPUT_RULES="$(iptables --list OUTPUT --line-number | tail -1 | cut -d' ' -f1)"
277+ ${ lib . optionalString config . networking . enableIPv6 ''
278+ N_OUTPUT_RULES_IPv6="$(ip6tables --list OUTPUT --line-number | tail -1 | cut -d' ' -f1)"
279+ '' }
280+
276281 if ${ startScript } ; then
277282 ip46tables -D INPUT -j nixos-drop 2>/dev/null || true
283+
284+ # Do not clear OUTPUT rules to avoid dropping connections,
285+ # instead drop the old rules after reload. Rules are dropped
286+ # in reverse order in order to preserve fallthrough behaviour
287+ # while rules are being dropped.
288+
289+ if [[ "$N_OUTPUT_RULES" != "num" ]]; then # Catch case when chain is empty
290+ for i in $(seq $N_OUTPUT_RULES -1 1); do
291+ iptables -D OUTPUT $i
292+ done
293+ fi
294+ ${ lib . optionalString config . networking . enableIPv6 ''
295+ if [[ "$N_OUTPUT_RULES_IPv6" != "num" ]]; then # Catch case when chain is empty
296+ for i in $(seq $N_OUTPUT_RULES_IPv6 -1 1); do
297+ ip6tables -D OUTPUT $i
298+ done
299+ fi
300+ '' }
278301 else
279302 echo "Failed to reload firewall... Stopping"
280303 ${ stopScript }
347370 ] ;
348371 conflicts = [ "shutdown.target" ] ;
349372
350- path = [ cfg . package ] ++ cfg . extraPackages ;
373+ path = [ pkgs . coreutils cfg . package ] ++ cfg . extraPackages ;
351374
352375 # FIXME: this module may also try to load kernel modules, but
353376 # containers don't have CAP_SYS_MODULE. So the host system had
You can’t perform that action at this time.
0 commit comments