From 3fc21533d00d791b9f38b0af170c626c17caefc1 Mon Sep 17 00:00:00 2001 From: Adrien Banlin Date: Mon, 19 Jun 2023 11:46:09 +0200 Subject: [PATCH] hotplug: load default/networking for hotplug itfs * ifup@.service is be able to show debug and verbose logs if set in the default file. (-d -v) * ifupdown2-hotplug load default before processing (excluding EXCLUDE_INTERFACES and adding -v -d --syslog on an init.d system. --- debian/ifup@.service | 18 +++++++++++++----- debian/ifupdown2-hotplug | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/debian/ifup@.service b/debian/ifup@.service index 6f8e3c7b..8f065193 100644 --- a/debian/ifup@.service +++ b/debian/ifup@.service @@ -11,19 +11,27 @@ IgnoreOnIsolate=yes [Service] # avoid stopping on shutdown via stopping system-ifup.slice Slice=system.slice +Environment=HOTPLUG_ARGS= Environment=LOCKFILE=/run/network/.lock +EnvironmentFile=-/etc/default/networking ExecStart=/bin/sh -ec "( \ + /bin/test \"$VERBOSE\" = \"yes\" && EXTRA_ARGS=-v; \ + /bin/test \"$DEBUG\" = \"yes\" && EXTRA_ARGS=\"$EXTRA_ARGS -d\"; \ flock 9; \ if $(/sbin/ifquery -L 9 -l --allow=hotplug 2>/dev/null | grep -w -q \"^%I$\"); then \ - exec /sbin/ifup %I -L 9 --systemd; \ - else \ - echo 'Interface %I not hotplug'; \ - exit 1; \ + exec /sbin/ifup $EXTRA_ARGS $HOTPLUG_ARGS %I -L 9 --systemd; \ fi; \ + exit 1; \ ) 9>$LOCKFILE" ExecStop=/bin/sh -ec "( \ + /bin/test \"$VERBOSE\" = \"yes\" && EXTRA_ARGS=-v; \ + /bin/test \"$DEBUG\" = \"yes\" && EXTRA_ARGS=\"$EXTRA_ARGS -d\"; \ flock 9; \ - exec /sbin/ifdown %I -L 9 --systemd; \ + exec /sbin/ifdown $EXTRA_ARGS %I -L 9 --systemd; \ ) 9>$LOCKFILE" RemainAfterExit=true TimeoutStartSec=2min + +# remove log duplications +StandardOutput=null +StandardError=null diff --git a/debian/ifupdown2-hotplug b/debian/ifupdown2-hotplug index 3496b256..2b6b869b 100755 --- a/debian/ifupdown2-hotplug +++ b/debian/ifupdown2-hotplug @@ -49,10 +49,22 @@ wait_for_interface() { done } +process_exclusions() { + set -- $EXCLUDE_INTERFACES + exclusions="" + for d; do + exclusions="-X $d $exclusions" + done + echo $exclusions +} + net_ifup() { + . /etc/default/networking 2>/dev/null || true + + exclusions=$(process_exclusions) - # exit if the interface is not configured as allow-hotplug (querying does not require a lock) - if ! $(/sbin/ifquery --allow=hotplug -l 2>/dev/null | grep -w -q "^$INTERFACE$"); then + # exit if the interface is not configured as allow-hotplug or excluded (querying does not require a lock) + if ! $(/sbin/ifquery --allow=hotplug -l $exclusions 2>/dev/null | grep -w -q "^$INTERFACE$"); then exit 0 fi @@ -60,11 +72,16 @@ net_ifup() { exec systemctl --no-block start $(systemd-escape --template ifup@.service $INTERFACE) fi + EXTRA_ARGS= + [ "$VERBOSE" = yes ] && EXTRA_ARGS=-v + [ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d" + [ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog" + # Take the lock and wait for lo before exec ifup. ( flock 9 wait_for_interface lo - exec ifup $INTERFACE -L 9 + exec ifup $EXTRA_ARGS $HOTPLUG_ARGS -L 9 $INTERFACE ) 9>$LOCKFILE } @@ -76,15 +93,24 @@ net_ifdown() { exit 0 fi - # exit if the interface is not configured as allow-hotplug (querying does not require a lock) - if ! $(/sbin/ifquery --allow=hotplug -l 2>/dev/null | grep -w -q "^$INTERFACE$"); then + . /etc/default/networking 2>/dev/null || true + + exclusions=$(process_exclusions) + + # exit if the interface is not configured as allow-hotplug or excluded (querying does not require a lock) + if ! $(/sbin/ifquery --allow=hotplug -l $exclusions 2>/dev/null | grep -w -q "^$INTERFACE$"); then exit 0 fi + EXTRA_ARGS= + [ "$VERBOSE" = yes ] && EXTRA_ARGS=-v + [ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d" + [ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog" + # Take the lock and exec ifdown. ( flock 9 - exec ifdown $INTERFACE -L 9 + exec ifdown $EXTRA_ARGS $INTERFACE -L 9 ) 9>$LOCKFILE }