summaryrefslogtreecommitdiffstats
path: root/remote/rootfs
diff options
context:
space:
mode:
authorSimon Rettberg2013-06-28 15:22:14 +0200
committerSimon Rettberg2013-06-28 15:22:14 +0200
commit00f089e8c95ccff96b6839d6d2fd806217f6665d (patch)
tree43ea73f1ad1555db590ceaad164bd0ff09d6ee64 /remote/rootfs
parentsimplicity + elegance (diff)
downloadtm-scripts-00f089e8c95ccff96b6839d6d2fd806217f6665d.tar.gz
tm-scripts-00f089e8c95ccff96b6839d6d2fd806217f6665d.tar.xz
tm-scripts-00f089e8c95ccff96b6839d6d2fd806217f6665d.zip
Rework networking setup to be more robust
Diffstat (limited to 'remote/rootfs')
l---------remote/rootfs/rootfs-stage32/data/etc/systemd/system/network.target.wants/ntpdate.service1
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/bin/dhcp++5
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script192
3 files changed, 111 insertions, 87 deletions
diff --git a/remote/rootfs/rootfs-stage32/data/etc/systemd/system/network.target.wants/ntpdate.service b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/network.target.wants/ntpdate.service
new file mode 120000
index 00000000..f4b5e3f8
--- /dev/null
+++ b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/network.target.wants/ntpdate.service
@@ -0,0 +1 @@
+../ntpdate.service \ No newline at end of file
diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/dhcp++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/dhcp++
index 1bc103b0..45984032 100755
--- a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/dhcp++
+++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/dhcp++
@@ -1,12 +1,11 @@
#!/bin/bash
-export PATH="$PATH:/opt/openslx/bin:/opt/openslx/sbin:/opt/openslx/usr/bin:/opt/openslx/usr/sbin"
-
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"
-/opt/openslx/sbin/udhcpc $UDHCPC_OPTS -O domain -O nissrv -O nisdomain -O wpad -t 8 -s /opt/openslx/bin/udhcpc.openslx.script -i "$NET_IF" -p "/run/udhcpc.$NET_IF.pid"
+mkdir -p /run/udhcpc
+/opt/openslx/sbin/udhcpc $UDHCPC_OPTS -O domain -O nissrv -O nisdomain -O wpad -t 8 -s /opt/openslx/bin/udhcpc.openslx.script -i "$NET_IF" -p "/run/udhcpc/udhcpc.$NET_IF.pid"
diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script
index d79cffa0..08d59eba 100755
--- a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script
+++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script
@@ -1,6 +1,6 @@
#!/bin/bash
# -----------------------------------------------------------------------------
-#
+#
# Copyright (c) 2011 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
@@ -16,101 +16,125 @@
#
# -----------------------------------------------------------------------------
+. /opt/openslx/config
RESOLV_CONF="/etc/resolv.conf"
-IP_CONF="/tmp/udhcpc_ip_config"
-
-export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin
+THISFILE="/run/udhcpc/${interface}.resolv"
echo "$interface [$1] $ip" >> "/tmp/udhcpclog"
-case $1 in
- bound|renew)
-
- [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
- [ -n "$subnet" ] && NETMASK="netmask $subnet"
-
- ip addr add $ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//) dev $interface
- ip route add default via $router
-
- echo "ip=$ip" > $IP_CONF
- echo "subnet=$subnet" >> $IP_CONF
- echo "broadcast=$broadcast" >> $IP_CONF
- echo "gateway=$router" >> $IP_CONF
-
- # Update resolver configuration file
- R=""
- if [ -n "$domain" ]; then
- R="domain $domain
-"
- else
- R="domain lp.ruf.uni-freiburg.de
-search lp.ruf.uni-freiburg.de
-"
- fi
- count=1;
- for i in $dns; do
- echo "$0: Adding DNS $i"
- R="${R}nameserver $i
-"
- count=$((count+1));
- done
-
- if [ -x /sbin/resolvconf ]; then
- echo -n "$R" | resolvconf -a "${interface}.udhcpc"
- else
- echo -n "$R" > "$RESOLV_CONF"
- fi
-
- # Always mount virtlib directory
- systemctl start var-lib-virt.service
- # Write to openslx-config
- echo "# Config written by openslx-dhcp-script" >> /opt/openslx/config
- echo "SLX_DNS='$dns'" >> /opt/openslx/config
- echo "SLX_HOSTNAME='$hostname'" >> /opt/openslx/config
-
- #update ip
- sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config
-
- #update hostname
- dns_host=$(rdns "$ip")
- if [ -n "$dns_host" ]; then
- echo "$dns_host" > /proc/sys/kernel/hostname
- echo "$dns_host" > /etc/hostname
- elif [ -n "$hostname" ]; then
- echo "$hostname" > /proc/sys/kernel/hostname
- echo "$hostname" > /etc/hostname
- fi
-
- # TODO i.e. event trigger
- if [ "x$(grep -ci mount /proc/cmdline)" != "x0" ]; then
- systemctl start nfs-mount.service &
- fi
- # TODO do this only once. network.target seems not reliable though....
- systemctl start ntpdate &
-
+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"
+}
+
+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\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 ]; then
+ # Automatic handling :-)
+ echo -n "$CONF" | resolvconf -a "${interface}.udhcpc"
+ else
+ # Manual handling required :-(
+ mkdir -p "/run/udhcpc"
+ echo -n "$CONF" > "$THISFILE"
+ 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
+
+ #update hostname
+ dns_host=$(rdns "$ip")
+ if [ -z "$dns_host" ]; then
+ # fallback to what the dhcp told us
+ dns_host="$hostname"
+ fi
+ if [ -n "$dns_host" ]; then
+ 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
+ fi
+ fi
+
+ # 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
+
+ # TODO: This mounts stage4. Current method is for testing purposes only.
+ # when going productive, this has to happen after user login, if the
+ # user selects a native linux session.
+ if [ "x$(grep -ci mount /proc/cmdline)" != "x0" ]; then
+ systemctl start nfs-mount.service &
+ fi
+ # Mark network target as reached
+ systemctl start network.target
+ 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 ]; then
+ # Automatic handling :-)
+ resolvconf -d "${interface}.udhcpc"
+ else
+ # Manual handling required :-(
+ rm -f "$THISFILE"
+ rebuild_resolv_conf
+ 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
;;
+
+ leasefail)
+ echo "$0: Lease failed: $message"
- leasefail)
- echo "$0: Lease failed: $message"
;;
+
+ nak)
+ echo "$0: Received a NAK: $message"
- nak)
- echo "$0: Received a NAK: $message"
;;
+
+ *)
+ echo "$0: Unknown udhcpc command: $1";
+ exit 1;
- *)
- echo "$0: Unknown udhcpc command: $1";
- exit 1;
;;
esac
+