From 37754e77e3c863675dba9cc0ac6c2c48eaf4a9f6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 23 Jan 2014 16:17:25 +0100 Subject: Add Targets network-dns and network-gateway These trigger if a dns server / default route has been configured via DHCP. This would probably only be interesting for dual homed clients (which we currently do not have in production), since the boot interface (br0) might not be the one we access the outside world with. In cases where you only have one nic, it will be enough to wait for the network target if you need full network/internet/resolving. --- .../data/opt/openslx/scripts/udhcpc-openslx | 41 +++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'remote/modules') diff --git a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx index 00d22ba5..93287af8 100755 --- a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx +++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -78,7 +78,7 @@ case "$1" in printf -v CONF "${CONF}nameserver $i\n" done - if [ -x /sbin/resolvconf ] && [ -L /etc/resolv.conf ] && [ -d /etc/resolvconf/update.d ]; then + if [ -x "/sbin/resolvconf" ] && [ -L "/etc/resolv.conf" ] && [ -d "/etc/resolvconf/update.d" ]; then # Automatic handling :-) resolvconf --create-runtime-directories resolvconf --enable-updates @@ -91,13 +91,13 @@ case "$1" in # Things that should only happen for the main interface that was used for booting if [ "$interface" == "br0" ]; then + dns_host=$(rdns "$ip") # 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" @@ -106,6 +106,7 @@ case "$1" in # only if there is no /etc/hostname, we fall back (far back, that is) [ ! -s "/etc/hostname" ] && dns_host="slx-client" fi + # finally, if dns_host was set to anything, apply it if [ -n "$dns_host" ]; then echo "$dns_host" > "/proc/sys/kernel/hostname" echo "$dns_host" > "/etc/hostname" @@ -129,11 +130,14 @@ case "$1" in fi # Update /etc/issue for proper spacing /opt/openslx/scripts/openslx-create_issue - fi - fi + touch "/run/udhcpc/network-ready" + # Mark network target as reached + systemctl start network.target & + fi # end "network not ready yet" + fi # end "br0 only" # Hostname in /etc/hosts - touch /etc/hosts + touch "/etc/hosts" hostlist="" [ -n "$dns_host" ] && hostlist="$dns_host" [ -n "$hostname" -a "x$hostname" != "x$dns_host" ] && hostlist="$hostlist $hostname" @@ -150,25 +154,30 @@ case "$1" in fi done fi - # Get rid of orphaned lines + # Get rid of orphaned lines in /etc/hosts 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" + # "dns ready" target + if [ -n "$dns" ] && [ ! -e "/run/udhcpc/dns-ready" ]; then + touch "/run/udhcpc/dns-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 happens in printergui modules (iptables-helper rule) + systemctl start network-dns.target & + fi + # "default route exists" target + if [ -n "$router" ] && [ ! -e "/run/udhcpc/routing-ready" ]; then + touch "/run/udhcpc/routing-ready" + # Write to openslx-config + echo "# Config written by openslx-dhcp-script (3)" >> /opt/openslx/config + echo "SLX_DNS='$dns'" >> /opt/openslx/config + systemctl start network-gateway.target & + fi + + # Port redirection for printing happens in printergui module (iptables-helper rule) ####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 -s 192.168.0.0/16 -p tcp --dport 515 -j REDIRECT --to-port 5515 - fi - ;; deconfig) -- cgit v1.2.3-55-g7522