Page MenuHomeVyOS Platform

About dhcp client hooks
Closed, ResolvedPublicFEATURE REQUEST

Description

Hello,

currently, dhcp client hooks can be executed placing them in the /config/scripts/dhcp-client/ directory as defined in:

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.

Details

Difficulty level
Unknown (require assessment)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Improvement (missing useful functionality)

Event Timeline

Create please a PR if it works for you.

Done: https://github.com/vyos/vyos-1x/pull/2472

That is my first PR; please, let me know if you need something else.

Viacheslav changed the task status from Open to In progress.Nov 11 2023, 10:26 AM
Viacheslav assigned this task to giuavo.
Viacheslav changed the task status from In progress to Needs testing.Nov 11 2023, 12:04 PM
Viacheslav moved this task from Need Triage to Finished on the VyOS 1.5 Circinus board.
Viacheslav moved this task from Need Triage to Finished on the VyOS 1.4 Sagitta board.