On Fri, Mar 06, 2015 at 09:02:39AM +0300, Michael Tokarev wrote: > 06.03.2015 02:57, Elliott Mitchell wrote: > > The documentation seems to suggest udhcpd can only handle binding to one > > interface and using one IP address range per udhcpd process. Due to > > this, it would be handy if Debian's init scripts had support for > > starting/stopping multiple udhcpd processes (this would mean require > > multiple .conf and .pid files). > > I suggest using some more advanced dhcp servers for this, for > example there's an excellent piece of software named dnsmasq > which is small and has other useful functionality. Udhcpd > scripts can be extended to support multiple interfaces, but > I think at this time, it is better to use, say, systemd > service files for that, which should be trivial to write > and drop to the right location (and no, I don't know off > my head how to do that ;).
I'm undecided on systemd right now, but the controversy has me rather concerned right now. dnsmasq may well be used in the future, but right now I still suspect udhcpd can readily take care of my current needs. > > When reading the man page I was wondering, could multiple configuration > > files be specified on udhcpd's command-line and would this have the > > effect of starting multiple udhcpd processes? (I rather doubt it, but > > the man page could be read that way) > > One invocation handles one interface, I think. But you can try :) I doubt it would work, just the man page could be interpreted to suggest this. I'm unsure whether it is good or bad news, but with some adjustments the /etc/init.d/udhcpd script can be rewritten as an ifupdown hook script. I'm attaching the script, place it in /etc/network/if-up.d/udhcpd, stick a symbolic link in /etc/network/if-down.d/ and the attached script will start/stop udhcpd when a given interface is brought up or down. This adds 3 settings to /etc/network/interfaces. "dhcpd-enable", "dhcpd-config" and "dhcpd-pidfile". Setting "dhcpd-enable" to "true", "yes", "1", or "udhcpd" will make udhcpd to be started when a given interface is brought up. If set, "dhcpd-config" will specify the configuration filename, DHCPD_CONFIG_DIR (set in /etc/default/udhcpd) will be added as a prefix if this is not an absolute path; otherwise it will look for /etc/udhcpd.<logical interface name>.conf then /etc/udhcpd.<physical interface name>.conf and finally fall back to /etc/udhcpd.conf. The "dhcpd-pidfile" can tell it where the .pid file is, though it will try to find it in the configuration file. Hopefully this works for others as a way to start udhcpd. -- (\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | ehem+sig...@m5p.com PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
#! /bin/sh # # Written by Miquel van Smoorenburg <miqu...@cistron.nl>. # Modified for Debian GNU/Linux by Ian Murdock <imurd...@gnu.ai.mit.edu> # and Axel Beckert <a...@deuxchevaux.org>. # Adjusted for use as an ifupdown hook script by Elliott Mitchell # <ehem+deb...@m5p.com>. # ### BEGIN INIT INFO # Provides: udhcpd # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start busybox udhcpd at boot time ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/udhcpd NAME=udhcpd DESC="very small Busybox based DHCP server" DHCPD_OPTS="-S" # Additional options given to the server test -x $DAEMON || exit 0 case "${IF_DHCPD_ENABLE}" in udhcpd) # *we* and not some other DHCP server are enabled ;; true|yes|1) # the DHCP server is enabled ;; *) exit 0 ;; esac # Include defaults if available [ -e /etc/default/udhcpd ] && . /etc/default/udhcpd set -e # Base location of configuration if relative path is given [ -z "${DHCPD_CONFIG_DIR}" ] && DHCPD_CONFIG_DIR=/etc # Has a configuration file been explicitly specified? Optionally add directory if [ -n "${IF_DHCPD_CONFIG}" ] then if [ "${IF_DHCPD_CONFIG}" = "${IF_DHCPD_CONFIG#/}" ] then IF_DHCPD_CONFIG=${DHCPD_CONFIG_DIR}/${IF_DHCPD_CONFIG} fi # Probe the location, first try ifupdown's logical name, then physical name elif [ -e "${DHCPD_CONFIG_DIR}/udhcpd.${LOGICAL}.conf" ] then IF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.${LOGICAL}.conf" elif [ -e "${DHCPD_CONFIG_DIR}/udhcpd.${IFACE}.conf" ] then IF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.${IFACE}.conf" else IF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.conf" fi # Has the .pid file been specified? Is it relative? if [ -n "${IF_DHCPD_PIDFILE}" ] then if [ "${IF_DHCPD_PIDFILE}" = "${IF_DHCPD_PIDFILE#/}" ] then IF_DHCPD_PIDFILE=/run/${IF_DHCPD_PIDFILE} fi # Look for the .pid file in the configuration file else if grep -q -E -e^\[\[:space:]]\*pidfile\[\[:space:]] ${IF_DHCPD_CONFIG} then IF_DHCPD_PIDFILE=`grep -E -e^\[\[:space:]]\*pidfile\[\[:space:]] ${IF_DHCPD_CONFIG} | sed -es/^\[\[:space:]]\*pidfile\[\[:space:]]+` else IF_DHCPD_PIDFILE=/run/udhcpd.pid fi fi # This works better for us [ "${VERBOSITY}" = 0 ] && VERBOSITY="" case "$MODE" in start) [ -n "${VERBOSITY}" ] && echo -n "Starting $DESC: " start-stop-daemon --start ${VERBOSITY:+--verbose} \ --pidfile ${IF_DHCPD_PIDFILE} --oknodo --exec $DAEMON \ -- ${IF_DHCPD_OPTS:-${DHCPD_OPTS}} ${IF_DHCPD_CONFIG} [ -n "${VERBOSITY}" ] && echo "$NAME." ;; stop) [ -n "${VERBOSITY}" ] && echo -n "Stopping $DESC: " start-stop-daemon --stop ${VERBOSITY:+--verbose} \ --pidfile ${IF_DHCPD_PIDFILE} --oknodo --exec $DAEMON [ -n "${VERBOSITY}" ] && echo "$NAME." ;; *) echo "Usage: $0 {start|stop}" >&2 exit 1 ;; esac exit 0