From 45a6b85535c88e9f90ccae2272317adb68334189 Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 3 Nov 2020 19:03:12 +0100 Subject: [PATCH 1/6] adds dhcpv6 support via extra tag --- Dockerfile.v6 | 16 +++++++++ build_v6 | 2 ++ util/entrypoint_v6.sh | 76 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 Dockerfile.v6 create mode 100755 build_v6 create mode 100755 util/entrypoint_v6.sh diff --git a/Dockerfile.v6 b/Dockerfile.v6 new file mode 100644 index 0000000..85b815d --- /dev/null +++ b/Dockerfile.v6 @@ -0,0 +1,16 @@ +FROM ubuntu:18.04 + +MAINTAINER Robin Smidsrød + +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get -q -y update \ + && apt-get -q -y -o "DPkg::Options::=--force-confold" -o "DPkg::Options::=--force-confdef" install apt-utils \ + && rm /etc/dpkg/dpkg.cfg.d/excludes \ + && apt-get -q -y -o "DPkg::Options::=--force-confold" -o "DPkg::Options::=--force-confdef" install dumb-init isc-dhcp-server man \ + && apt-get -q -y autoremove \ + && apt-get -q -y clean \ + && rm -rf /var/lib/apt/lists/* + +COPY util/entrypoint_v6.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/build_v6 b/build_v6 new file mode 100755 index 0000000..3cc396e --- /dev/null +++ b/build_v6 @@ -0,0 +1,2 @@ +#!/bin/bash +docker build -t networkboot/dhcpd:v6 -f Dockerfile.v6 "$@" $(dirname $0) diff --git a/util/entrypoint_v6.sh b/util/entrypoint_v6.sh new file mode 100755 index 0000000..10c4b12 --- /dev/null +++ b/util/entrypoint_v6.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +set -e + + +# Support docker run --init parameter which obsoletes the use of dumb-init, +# but support dumb-init for those that still use it without --init +if [ -x "/dev/init" ]; then + run="exec" +else + run="exec /usr/bin/dumb-init --" +fi + +# Single argument to command line is interface name +if [ $# -eq 1 -a -n "$1" ]; then + # skip wait-for-interface behavior if found in path + if ! which "$1" >/dev/null; then + # loop until interface is found, or we give up + NEXT_WAIT_TIME=1 + until [ -e "/sys/class/net/$1" ] || [ $NEXT_WAIT_TIME -eq 4 ]; do + sleep $(( NEXT_WAIT_TIME++ )) + echo "Waiting for interface '$1' to become available... ${NEXT_WAIT_TIME}" + done + if [ -e "/sys/class/net/$1" ]; then + IFACE="$1" + fi + fi +fi + +# No arguments mean all interfaces +if [ -z "$1" ]; then + IFACE=" " +fi + +if [ -n "$IFACE" ]; then + # Run dhcpd for specified interface or all interfaces + + data_dir="/data" + if [ ! -d "$data_dir" ]; then + echo "Please ensure '$data_dir' folder is available." + echo 'If you just want to keep your configuration in "data/", add -v "$(pwd)/data:/data" to the docker run command line.' + exit 1 + fi + + dhcpd_conf="$data_dir/dhcpd.conf" + if [ ! -r "$dhcpd_conf" ]; then + echo "Please ensure '$dhcpd_conf' exists and is readable." + echo "Run the container with arguments 'man dhcpd.conf' if you need help with creating the configuration." + exit 1 + fi + + uid=$(stat -c%u "$data_dir") + gid=$(stat -c%g "$data_dir") + if [ $gid -ne 0 ]; then + groupmod -g $gid dhcpd + fi + if [ $uid -ne 0 ]; then + usermod -u $uid dhcpd + fi + + [ -e "$data_dir/dhcpd.leases" ] || touch "$data_dir/dhcpd.leases" + chown dhcpd:dhcpd "$data_dir/dhcpd.leases" + if [ -e "$data_dir/dhcpd.leases~" ]; then + chown dhcpd:dhcpd "$data_dir/dhcpd.leases~" + fi + + container_id=$(grep docker /proc/self/cgroup | sort -n | head -n 1 | cut -d: -f3 | cut -d/ -f3) + if perl -e '($id,$name)=@ARGV;$short=substr $id,0,length $name;exit 1 if $name ne $short;exit 0' $container_id $HOSTNAME; then + echo "You must add the 'docker run' option '--net=host' if you want to provide DHCP service to the host network." + fi + + $run /usr/sbin/dhcpd -6 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE +else + # Run another binary + $run "$@" +fi From 8b04ac79075570c581530bac679e50be44fb2969 Mon Sep 17 00:00:00 2001 From: ticevi Date: Thu, 5 Nov 2020 10:24:52 +0100 Subject: [PATCH 2/6] Revert "adds dhcpv6 support via extra tag" This reverts commit 45a6b85535c88e9f90ccae2272317adb68334189. --- Dockerfile.v6 | 16 --------- build_v6 | 2 -- util/entrypoint_v6.sh | 76 ------------------------------------------- 3 files changed, 94 deletions(-) delete mode 100644 Dockerfile.v6 delete mode 100755 build_v6 delete mode 100755 util/entrypoint_v6.sh diff --git a/Dockerfile.v6 b/Dockerfile.v6 deleted file mode 100644 index 85b815d..0000000 --- a/Dockerfile.v6 +++ /dev/null @@ -1,16 +0,0 @@ -FROM ubuntu:18.04 - -MAINTAINER Robin Smidsrød - -ARG DEBIAN_FRONTEND=noninteractive - -RUN apt-get -q -y update \ - && apt-get -q -y -o "DPkg::Options::=--force-confold" -o "DPkg::Options::=--force-confdef" install apt-utils \ - && rm /etc/dpkg/dpkg.cfg.d/excludes \ - && apt-get -q -y -o "DPkg::Options::=--force-confold" -o "DPkg::Options::=--force-confdef" install dumb-init isc-dhcp-server man \ - && apt-get -q -y autoremove \ - && apt-get -q -y clean \ - && rm -rf /var/lib/apt/lists/* - -COPY util/entrypoint_v6.sh /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] diff --git a/build_v6 b/build_v6 deleted file mode 100755 index 3cc396e..0000000 --- a/build_v6 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -docker build -t networkboot/dhcpd:v6 -f Dockerfile.v6 "$@" $(dirname $0) diff --git a/util/entrypoint_v6.sh b/util/entrypoint_v6.sh deleted file mode 100755 index 10c4b12..0000000 --- a/util/entrypoint_v6.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -set -e - - -# Support docker run --init parameter which obsoletes the use of dumb-init, -# but support dumb-init for those that still use it without --init -if [ -x "/dev/init" ]; then - run="exec" -else - run="exec /usr/bin/dumb-init --" -fi - -# Single argument to command line is interface name -if [ $# -eq 1 -a -n "$1" ]; then - # skip wait-for-interface behavior if found in path - if ! which "$1" >/dev/null; then - # loop until interface is found, or we give up - NEXT_WAIT_TIME=1 - until [ -e "/sys/class/net/$1" ] || [ $NEXT_WAIT_TIME -eq 4 ]; do - sleep $(( NEXT_WAIT_TIME++ )) - echo "Waiting for interface '$1' to become available... ${NEXT_WAIT_TIME}" - done - if [ -e "/sys/class/net/$1" ]; then - IFACE="$1" - fi - fi -fi - -# No arguments mean all interfaces -if [ -z "$1" ]; then - IFACE=" " -fi - -if [ -n "$IFACE" ]; then - # Run dhcpd for specified interface or all interfaces - - data_dir="/data" - if [ ! -d "$data_dir" ]; then - echo "Please ensure '$data_dir' folder is available." - echo 'If you just want to keep your configuration in "data/", add -v "$(pwd)/data:/data" to the docker run command line.' - exit 1 - fi - - dhcpd_conf="$data_dir/dhcpd.conf" - if [ ! -r "$dhcpd_conf" ]; then - echo "Please ensure '$dhcpd_conf' exists and is readable." - echo "Run the container with arguments 'man dhcpd.conf' if you need help with creating the configuration." - exit 1 - fi - - uid=$(stat -c%u "$data_dir") - gid=$(stat -c%g "$data_dir") - if [ $gid -ne 0 ]; then - groupmod -g $gid dhcpd - fi - if [ $uid -ne 0 ]; then - usermod -u $uid dhcpd - fi - - [ -e "$data_dir/dhcpd.leases" ] || touch "$data_dir/dhcpd.leases" - chown dhcpd:dhcpd "$data_dir/dhcpd.leases" - if [ -e "$data_dir/dhcpd.leases~" ]; then - chown dhcpd:dhcpd "$data_dir/dhcpd.leases~" - fi - - container_id=$(grep docker /proc/self/cgroup | sort -n | head -n 1 | cut -d: -f3 | cut -d/ -f3) - if perl -e '($id,$name)=@ARGV;$short=substr $id,0,length $name;exit 1 if $name ne $short;exit 0' $container_id $HOSTNAME; then - echo "You must add the 'docker run' option '--net=host' if you want to provide DHCP service to the host network." - fi - - $run /usr/sbin/dhcpd -6 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE -else - # Run another binary - $run "$@" -fi From 46eead3e70a283d5a893b6fbd78210ee4b44f00b Mon Sep 17 00:00:00 2001 From: ticevi Date: Thu, 5 Nov 2020 10:56:31 +0100 Subject: [PATCH 3/6] adds support for dhcpv6 vi env --- util/entrypoint.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/entrypoint.sh b/util/entrypoint.sh index 1a8f59b..96efa72 100755 --- a/util/entrypoint.sh +++ b/util/entrypoint.sh @@ -69,7 +69,12 @@ if [ -n "$IFACE" ]; then echo "You must add the 'docker run' option '--net=host' if you want to provide DHCP service to the host network." fi - $run /usr/sbin/dhcpd -4 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE + # check if v6 should be used + if [ -n "$DHCPv6"]; then + $run /usr/sbin/dhcpd -6 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE + else + $run /usr/sbin/dhcpd -4 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE + fi else # Run another binary $run "$@" From 5e7352372614e2d28a7df4377756c84bb3f49cb6 Mon Sep 17 00:00:00 2001 From: ticevi Date: Thu, 5 Nov 2020 11:04:35 +0100 Subject: [PATCH 4/6] adds documentation for DHCPv6 --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 2590fe8..c9db57d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,14 @@ on. A simple `run` script is also included which makes it quick to iterate on a configuration until you're satisfied. +DHCPv6 +------ + +To use a DHCPv6-Server you have to pass `DHCPv6` as enviroment variable + +`docker run -it --rm --init -e DHCPv6 --net host -v "$(pwd)/data":/data networkboot/dhcpd eth0` + + Notes ===== From 70f436ec5e01518866cf74acd3783e5b1d03885f Mon Sep 17 00:00:00 2001 From: ticevi Date: Thu, 5 Nov 2020 11:32:09 +0100 Subject: [PATCH 5/6] using 'DHCPD_PROTOCOL' as variable --- Dockerfile | 2 ++ Dockerfile.ldap | 2 ++ README.md | 2 +- util/entrypoint.sh | 7 +------ 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4836674..1d97dfe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,5 +12,7 @@ RUN apt-get -q -y update \ && apt-get -q -y clean \ && rm -rf /var/lib/apt/lists/* +ENV DHCPD_PROTOCOL=4 + COPY util/entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/Dockerfile.ldap b/Dockerfile.ldap index deaabd6..52048af 100644 --- a/Dockerfile.ldap +++ b/Dockerfile.ldap @@ -12,5 +12,7 @@ RUN apt-get -q -y update \ && apt-get -q -y clean \ && rm -rf /var/lib/apt/lists/* +ENV DHCPD_PROTOCOL=4 + COPY util/entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index c9db57d..0271ce8 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ DHCPv6 To use a DHCPv6-Server you have to pass `DHCPv6` as enviroment variable -`docker run -it --rm --init -e DHCPv6 --net host -v "$(pwd)/data":/data networkboot/dhcpd eth0` +`docker run -it --rm --init -e DHCPD_PROTOCOL=6 --net host -v "$(pwd)/data":/data networkboot/dhcpd eth0` Notes diff --git a/util/entrypoint.sh b/util/entrypoint.sh index 96efa72..63883fd 100755 --- a/util/entrypoint.sh +++ b/util/entrypoint.sh @@ -69,12 +69,7 @@ if [ -n "$IFACE" ]; then echo "You must add the 'docker run' option '--net=host' if you want to provide DHCP service to the host network." fi - # check if v6 should be used - if [ -n "$DHCPv6"]; then - $run /usr/sbin/dhcpd -6 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE - else - $run /usr/sbin/dhcpd -4 -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE - fi + $run /usr/sbin/dhcpd -$DHCPD_PROTOCOL -f -d --no-pid -cf "$data_dir/dhcpd.conf" -lf "$data_dir/dhcpd.leases" $IFACE else # Run another binary $run "$@" From e979b4257688da7239fe022e8b09c40f10478e35 Mon Sep 17 00:00:00 2001 From: ticevi Date: Thu, 5 Nov 2020 11:44:56 +0100 Subject: [PATCH 6/6] fix variable name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0271ce8..d5078bd 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ configuration until you're satisfied. DHCPv6 ------ -To use a DHCPv6-Server you have to pass `DHCPv6` as enviroment variable +To use a DHCPv6-Server you have to pass `DHCPD_PROTOCOL=6` as enviroment variable `docker run -it --rm --init -e DHCPD_PROTOCOL=6 --net host -v "$(pwd)/data":/data networkboot/dhcpd eth0`