Skip to content

Hooks

Hooks spawn additional services on interface (de)configuration to control userspace network services. Among other things, it can be used for:

  • DHCP clients
  • PPP dailup service
  • IPv6 RA daemon

Invocation

Hooks are referenced by a executable's filename inside of /etc/ifstate/hooks. They are called from inside the NetNS and/or VRF of the interface with the following environment variables set:

  • IFS_SCRIPT - absolute filename of the invoked script
  • IFS_RUNDIR - directory for temmporary files (i.e. pid files)
  • IFS_IFNAME - interface name
  • IFS_INDEX - interface index
  • IFS_NETNS - name of the interface's NetNS (or empty)
  • IFS_VRF - name of the interface's VRF (or empty)

  • IFS_ARG_… - additional environment variables specified in the configuration

A single argument is passed when executing the hook:

  • start - the interface is actived and the script needs to ensure that the service is active
  • check-start - dry run of start
  • stop - the interface is deactivated and the script needs to ensure that the service is inactive
  • check-stop - dry run of stop

Return Code

Ifstate expects the hook to return a appropriate return code. There are environment variables set for convenience reasons:

ENV variable RC Description
IFS_RC_OK 0 the hook service was already in the desired state
IFS_RC_ERROR 1 an error has been occured
IFS_RC_STARTED 2 the hook service has been started
IFS_RC_STOPPED 2 the hook service has been stopped
IFS_RC_CHANGED 3 the hook service has been restart or reloaded