Hello,
currently, dhcp client hooks can be executed placing them in the /config/scripts/dhcp-client/ directory as defined in:
- https://github.com/vyos/vyos-1x/blob/current/src/etc/dhcp/dhclient-enter-hooks.d/99-run-user-hooks
- https://github.com/vyos/vyos-1x/blob/current/src/etc/dhcp/dhclient-exit-hooks.d/98-run-user-hooks
Both scripts use run-parts to execute the final user hooks:
#!/bin/bash DHCP_POST_HOOKS="/config/scripts/dhcp-client/post-hooks.d/" if [ -d "${DHCP_POST_HOOKS}" ] ; then run-parts "${DHCP_POST_HOOKS}" fi
The little side-effect is that hooks started via run-part are not allowed to modify any variable set by the dhcp client. For instance, it could be quite useful to have the posibility to modify the new_routers variable to avoid the installation of the default routes. Indeed, not all the dhcp servers honor the routes option coming with the dhcp request.
The /sbin/dhclient-script script defines two functions that can be used to achieve that goal:
# run given script
run_hook() {
local script="$1"
local exit_status=0
if [ -f $script ]; then
. $script
exit_status=$?
fi
if [ -n "$exit_status" ] && [ "$exit_status" -ne 0 ]; then
logger -p daemon.err "$script returned non-zero exit status $exit_status"
fi
return $exit_status
}
# run scripts in given directory
run_hookdir() {
local dir="$1"
local exit_status=0
if [ -d "$dir" ]; then
for script in $(run-parts --list $dir); do
run_hook $script
exit_status=$((exit_status|$?))
done
fi
return $exit_status
}Those are the functions used to execute the "first level" hooks. The vyos hooks could be then modified accordingly, for instance:
#!/bin/sh DHCP_POST_HOOKS="/config/scripts/dhcp-client/post-hooks.d/" if [ -d "${DHCP_POST_HOOKS}" ] ; then #run-parts "${DHCP_POST_HOOKS}" run_hookdir "${DHCP_POST_HOOKS}" fi
Basically run-parts is replaced by run_hookdir.
I think that could add a bit more flexibility in handling dhcp connections.