diff options
| author | Simon Rettberg | 2014-01-15 17:01:20 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2014-01-15 17:01:20 +0100 |
| commit | 0e54b9468d137100ba148ada15479b7b1625dd4f (patch) | |
| tree | d93e8c3088ea4e9bcafc8d387403f4c731e3fb0f /remote/modules | |
| parent | <system startup> rework dhcp request: try to get an address (and dns/hostname... (diff) | |
| download | tm-scripts-0e54b9468d137100ba148ada15479b7b1625dd4f.tar.gz tm-scripts-0e54b9468d137100ba148ada15479b7b1625dd4f.tar.xz tm-scripts-0e54b9468d137100ba148ada15479b7b1625dd4f.zip | |
Move udhcpc stuff to its own module. Was spread across systemd and rootfs-stage32
Diffstat (limited to 'remote/modules')
| -rw-r--r-- | remote/modules/dhcpc-busybox/README | 7 | ||||
| l--------- | remote/modules/dhcpc-busybox/data/etc/systemd/system/sysinit.target.wants/udhcpc@br0.service (renamed from remote/modules/systemd/data/etc/systemd/system/sysinit.target.wants/udhcpc@br0.service) | 0 | ||||
| -rw-r--r-- | remote/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service (renamed from remote/modules/systemd/data/etc/systemd/system/udhcpc@.service) | 0 | ||||
| -rwxr-xr-x | remote/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++ | 11 | ||||
| -rwxr-xr-x | remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx | 190 | ||||
| -rw-r--r-- | remote/modules/dhcpc-busybox/dhcpc-busybox.build | 13 | ||||
| -rw-r--r-- | remote/modules/dhcpc-busybox/dhcpc-busybox.conf | 1 |
7 files changed, 222 insertions, 0 deletions
diff --git a/remote/modules/dhcpc-busybox/README b/remote/modules/dhcpc-busybox/README new file mode 100644 index 00000000..5dd78e73 --- /dev/null +++ b/remote/modules/dhcpc-busybox/README @@ -0,0 +1,7 @@ +This module requires that busybox udhcpc is present in stage 3.2 + +The default setup builds busybox with udhcpc, puts it in stage 3.1 +which copies it to stage 3.2 before the switchroot happens. That's +why there is no direct dependency in this module's .conf: busybox +is not part of the stage 3.2 target. + diff --git a/remote/modules/systemd/data/etc/systemd/system/sysinit.target.wants/udhcpc@br0.service b/remote/modules/dhcpc-busybox/data/etc/systemd/system/sysinit.target.wants/udhcpc@br0.service index dff66b14..dff66b14 120000 --- a/remote/modules/systemd/data/etc/systemd/system/sysinit.target.wants/udhcpc@br0.service +++ b/remote/modules/dhcpc-busybox/data/etc/systemd/system/sysinit.target.wants/udhcpc@br0.service diff --git a/remote/modules/systemd/data/etc/systemd/system/udhcpc@.service b/remote/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service index 6547de5b..6547de5b 100644 --- a/remote/modules/systemd/data/etc/systemd/system/udhcpc@.service +++ b/remote/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service diff --git a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++ new file mode 100755 index 00000000..f3de82df --- /dev/null +++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++ @@ -0,0 +1,11 @@ +#!/bin/bash + +NET_IF="$1" +NET_IP="$(ip addr show dev "${NET_IF}" | grep "inet " | awk -F " " '{print $2}' | awk -F "/" '{print $1}')" + +UDHCPC_OPTS="" +[ ! -z "$NET_IP" ] && UDHCPC_OPTS=" -r $NET_IP" +echo "udhcp++: running on $NET_IF with additional params $UDHCPC_OPTS" >> "/tmp/udhcpclog" +mkdir -p /run/udhcpc || echo "Could not create '/run/udhcpc'." +/opt/openslx/sbin/udhcpc $UDHCPC_OPTS -O domain -O nissrv -O nisdomain -O wpad -t 8 -s /opt/openslx/scripts/udhcpc-openslx -i "$NET_IF" -p "/run/udhcpc/udhcpc.$NET_IF.pid" || \ + slxlog "udhcpc" "Could not run 'udhcpc${UDHCPC_OPTS}' on ${NET_IF}." diff --git a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx new file mode 100755 index 00000000..b6ea93c4 --- /dev/null +++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -0,0 +1,190 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2011 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# +# Mini-Linux Toolkit +# +# ----------------------------------------------------------------------------- + +. /opt/openslx/config + +RESOLV_CONF="/etc/resolv.conf" +THISFILE="/run/udhcpc/${interface}.resolv" + +echo "$interface [$1] $ip" >> "/tmp/udhcpclog" + +rebuild_resolv_conf () { + # Maybe make this smarter some time, if anyone is using client's that are on multiple networks at once etc... + # This is a little braindead but should work most of the time + sort -u /run/udhcpc/*.resolv > "$RESOLV_CONF" +} + +escape_search() { + echo "$@" | sed -e 's/[]\/()$*.^|[]/\\&/g' +} + +escape_replace() { + echo "$@" | sed -e 's/[\/&]/\\&/g' +} + +case "$1" in + bound|renew) + ip addr add "$ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//)" dev "$interface" + if [ -n "$router" ]; then + ip route add default via "$router" + fi + + # Update resolver configuration file + CONF="" + if [ -n "$domain" ]; then + printf -v CONF "domain $domain\nsearch $domain\n" + elif [ -n "$SLX_NET_DOMAIN" ]; then + printf -v CONF "domain $SLX_NET_DOMAIN\nsearch $SLX_NET_DOMAIN\n" + fi + for i in $dns; do + echo "$0: Adding DNS $i" + printf -v CONF "${CONF}nameserver $i\n" + done + + if [ -x /sbin/resolvconf ] && [ -L /etc/resolv.conf ] && [ -d /etc/resolvconf/update.d ]; then + # Automatic handling :-) + resolvconf --create-runtime-directories + resolvconf --enable-updates + echo -n "$CONF" | resolvconf -a "${interface}.udhcpc" + else + # Manual handling required :-( + mkdir -p "/run/udhcpc" + echo -n "$CONF" | sed 's# 132\.200\.# 132.230.#g' > "$THISFILE" # HACK for Pharmazie-Pool, as DHCP gives wrong DNS information. Remove when DHCP guys fixed it... + rebuild_resolv_conf + fi + + # Things that should only happen for the main interface that was used for booting + if [ "$interface" == "br0" ]; then + # Update IP + sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config + + # Only if network is not ready yet + if [ ! -e "/run/udhcpc/network-ready" ]; then + # Update hostname + dns_host=$(rdns "$ip") + if [ -z "$dns_host" ]; then + # fallback to what the dhcp told us + dns_host="$hostname" + fi + # Avoid empty hostnames + [ -z "$dns_host" ] && dns_host="slx-client" + echo "$dns_host" > "/proc/sys/kernel/hostname" + echo "$dns_host" > "/etc/hostname" + if grep '^SLX_HOSTNAME=' /opt/openslx/config 2>/dev/null; then + sed -i "s/^\(SLX_HOSTNAME=\).*$/\1'$dns_host'/" /opt/openslx/config + else + echo "# Config written by openslx-dhcp-script (1)" >> /opt/openslx/config + echo "SLX_HOSTNAME='$dns_host'" >> /opt/openslx/config + fi + + # if domain is given from dhcp, save it to openslx config for later use in VMs + if [ -n "$domain" ]; then + # check if SLX_NET_DOMAIN is in the config at all + if grep '^SLX_NET_DOMAIN=' /opt/openslx/config 2>/dev/null; then + sed -i "s/^\(SLX_NET_DOMAIN=\).*$/\1'$domain'/" /opt/openslx/config + else + # not set, add it + echo "SLX_NET_DOMAIN='$domain'" >> /opt/openslx/config + fi + fi + # Update /etc/issue for proper spacing + /opt/openslx/scripts/openslx-create_issue + fi + fi + + # Hostname in /etc/hosts + touch /etc/hosts + if [ -n "$dns_host" ]; then + short="${dns_host%%.*}" + [ "x$short" = "x$dns_host" ] && short="" + sed -i -r "s/\s$(escape_search "$dns_host")(\s|$)/ /g" /etc/hosts + [ -n "$short" ] && sed -i -r "s/\s$(escape_search "$short")(\s|$)/ /g" /etc/hosts + if grep -q -E "^$ip\s" /etc/hosts; then + sed -i "s/^$(escape_search "$ip")\s/$(escape_replace "$ip $dns_host $short ")/g" /etc/hosts + else + echo "$ip $dns_host $short" >> /etc/hosts + fi + fi + if [ -n "$hostname" -a "x$hostname" != "x$dns_host" ]; then + short="${hostname%%.*}" + [ "x$short" = "x$hostname" ] && short="" + sed -i -r "s/\s$(escape_search "$hostname")(\s|$)/ /g" /etc/hosts + [ -n "$short" ] && sed -i -r "s/\s$(escape_search "$short")(\s|$)/ /g" /etc/hosts + if grep -q -E "^$ip\s" /etc/hosts; then + sed -i "s/^$(escape_search "$ip")\s/$(escape_replace "$ip $hostname $short ")/g" /etc/hosts + else + echo "$ip $hostname $short" >> /etc/hosts + fi + fi + sed -i -r '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s*$/d' /etc/hosts + + # We consider the network setup to be complete if an interface is being configured that + # has a default route and some dns servers set. + if [ -n "$router" ] && [ -n "$dns" ] && [ ! -e "/run/udhcpc/network-ready" ]; then + touch "/run/udhcpc/network-ready" + # Write to openslx-config + echo "# Config written by openslx-dhcp-script (2)" >> /opt/openslx/config + echo "SLX_DNS='$dns'" >> /opt/openslx/config + + # Mark network target as reached + systemctl start network.target + # Port redirection for printing + iptables -A INPUT -i br0 -p tcp --dport 515 -j DROP + iptables -A INPUT -i br0 -p tcp --dport 5515 -j DROP + iptables -t nat -A PREROUTING -p tcp --dport 515 -j REDIRECT --to-port 5515 + fi + + ;; + + deconfig) + if [ $(grep -c "nfs=" /proc/cmdline) == 0 ]; then + echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" + clientip=${ip%%:*} + ip addr del "$clientip/$(ipcalc -s -p $clientip $subnet|sed s/.*=//)" dev "$interface" + else + echo "NFS is active, not removing old ip adress. warning: lease may expire after a while." + fi + + if [ -x /sbin/resolvconf ] && [ -L /etc/resolv.conf ] && [ -d /etc/resolvconf/update.d ]; then + # Automatic handling :-) + resolvconf -d "${interface}.udhcpc" + else + # Manual handling required :-( + rm -f "$THISFILE" + rebuild_resolv_conf + fi + + ;; + + leasefail) + echo "$0: Lease failed: $message" + + ;; + + nak) + echo "$0: Received a NAK: $message" + + ;; + + *) + echo "$0: Unknown udhcpc command: $1"; + exit 1; + + ;; +esac + diff --git a/remote/modules/dhcpc-busybox/dhcpc-busybox.build b/remote/modules/dhcpc-busybox/dhcpc-busybox.build new file mode 100644 index 00000000..d8804784 --- /dev/null +++ b/remote/modules/dhcpc-busybox/dhcpc-busybox.build @@ -0,0 +1,13 @@ + +fetch_source() { + : +} + +build() { + : +} + +post_copy() { + : +} + diff --git a/remote/modules/dhcpc-busybox/dhcpc-busybox.conf b/remote/modules/dhcpc-busybox/dhcpc-busybox.conf new file mode 100644 index 00000000..c01ade29 --- /dev/null +++ b/remote/modules/dhcpc-busybox/dhcpc-busybox.conf @@ -0,0 +1 @@ +# Nothing |
