Skip to content

Commit

Permalink
hotplug: load default/networking for hotplug itfs
Browse files Browse the repository at this point in the history
* [email protected] 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.
  • Loading branch information
sohorx committed Jun 20, 2023
1 parent 269bef8 commit 3fc2153
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
18 changes: 13 additions & 5 deletions debian/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 32 additions & 6 deletions debian/ifupdown2-hotplug
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,39 @@ 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

if [ -d /run/systemd/system ]; then
exec systemctl --no-block start $(systemd-escape --template [email protected] $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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 3fc2153

Please sign in to comment.