77bec78dc9a3e3850bbd0f149faa3cf8b4f59046
[live-boot-grml.git] / debian / patches / 27_support_static_ip.patch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 27_support_staticip.dpatch by  <mru@grml.org>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: No description.
6
7 @DPATCH@
8
9 Index: live-boot-grml/components/9990-networking.sh
10 ===================================================================
11 --- live-boot-grml.orig/components/9990-networking.sh   2014-03-08 13:35:17.832580835 +0100
12 +++ live-boot-grml/components/9990-networking.sh        2014-03-08 13:35:33.106789237 +0100
13 @@ -44,7 +44,7 @@
14  
15                                 if [ "$bootif_mac" = "$current_mac" ]
16                                 then
17 -                                       DEVICE=${device##*/}
18 +                                       ETHDEVICE="${device##*/},$ETHDEVICE" # use ethdevice
19                                         break
20                                 fi
21                         fi
22 @@ -52,6 +52,24 @@
23         fi
24  }
25  
26 +get_ipconfig_para()
27 +{
28 +       if [ $# != 1 ] ; then
29 +               echo "Missin parameter for $0"
30 +               return
31 +       fi
32 +       devname=$1
33 +       for ip in ${STATICIP} ; do
34 +               case $ip in
35 +                       *:$devname:*)
36 +                       echo $ip
37 +                       return
38 +                       ;;
39 +               esac
40 +       done
41 +       echo $devname
42 +}
43 +
44  do_netsetup ()
45  {
46         modprobe -q af_packet # For DHCP
47 @@ -62,8 +80,20 @@
48         [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
49         echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
50  
51 -       if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
52 -       then
53 +       # Our modus operandi for getting a working network setup is this:
54 +       # * If ip=* is set, pass that to ipconfig and be done
55 +       # * Else, try dhcp on all devices in this order:
56 +       #   ethdevice= bootif= <all interfaces>
57 +
58 +       ALLDEVICES="$(cd /sys/class/net/ && ls -1 2>/dev/null | grep -v '^lo$' )"
59 +
60 +       # Turn on all interfaces before doing anything, to avoid timing problems
61 +       # during link negotiation.
62 +       echo "Net: Turning on all device links..."
63 +       for device in ${ALLDEVICES}; do
64 +               ipconfig -c none -d $device -t 1 2>/dev/null >/dev/null
65 +       done
66 +
67                 # See if we can select the device from BOOTIF
68                 Device_from_bootif
69  
70 @@ -73,14 +103,7 @@
71                 if [ -z "$ETHDEVICE" ]
72                 then
73                         echo "If you want to boot from a specific device use bootoption ethdevice=..."
74 -                       for device in /sys/class/net/*
75 -                       do
76 -                               dev=${device##*/}
77 -                               if [ "$dev" != "lo" ]
78 -                               then
79 -                                       ETHDEVICE="$ETHDEVICE $dev"
80 -                               fi
81 -                       done
82 +                       ETHDEVICE="$ALLDEVICES"
83                 fi
84  
85                 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
86 @@ -89,42 +112,29 @@
87                         devlist="$devlist $device"
88                 done
89  
90 -               # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
91 -               # an endless loop; if execution fails give it two further tries, that's
92 -               # why we use '$devlist $devlist $devlist' for the other for loop
93 -               for dev in $devlist $devlist $devlist
94 -               do
95 -                       echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
96 -                       ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
97 -                       jobid=$!
98 -                       sleep "$ETHDEV_TIMEOUT" ; sleep 1
99 -                       if [ -r /proc/"$jobid"/status ]
100 -                       then
101 -                               echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
102 -                               kill -9 $jobid
103 +               for dev in $devlist ; do
104 +                       param="$(get_ipconfig_para $dev)"
105 +                       if [ -n "$NODHCP" ] && [ "$param" = "$dev" ] ; then
106 +                               echo "Ignoring network device $dev due to nodhcp." | tee -a /boot.log
107 +                               continue
108                         fi
109 +                       echo "Executing ipconfig -t $ETHDEV_TIMEOUT $param"
110 +                       ipconfig -t "$ETHDEV_TIMEOUT" "$param" | tee -a /netboot.config
111  
112                         # if configuration of device worked we should have an assigned
113                         # IP address, if so let's use the device as $DEVICE for later usage.
114                         # simple and primitive approach which seems to work fine
115 -                       if ifconfig $dev | grep -q 'inet.*addr:'
116 -                       then
117 -                               export DEVICE="$dev"
118 -                               break
119 +
120 +                       IPV4ADDR="0.0.0.0"
121 +                       if [ -e "/run/net-${device}.conf" ]; then
122 +                               . /run/net-${device}.conf
123                         fi
124 -               done
125 -       else
126 -               for interface in ${DEVICE}; do
127 -                       ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
128 -
129 -                       [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
130 -
131 -                       if [ "$IPV4ADDR" != "0.0.0.0" ]
132 -                       then
133 -                               break
134 +                       if [ "${IPV4ADDR}" != "0.0.0.0" ]; then
135 +                               export DEVICE="$dev $DEVICE"
136 +                               # break  # exit loop as we just use the irst
137                         fi
138                 done
139 -       fi
140 +       unset devlist
141  
142         for interface in ${DEVICE}
143         do
144 Index: live-boot-grml/components/9990-cmdline-old
145 ===================================================================
146 --- live-boot-grml.orig/components/9990-cmdline-old     2014-03-08 13:35:17.832580835 +0100
147 +++ live-boot-grml/components/9990-cmdline-old  2014-03-08 13:35:17.828581304 +0100
148 @@ -51,9 +51,8 @@
149                                 ;;
150  
151                         ethdevice=*)
152 -                               DEVICE="${_PARAMETER#ethdevice=}"
153 -                               ETHDEVICE="${DEVICE}"
154 -                               export DEVICE ETHDEVICE
155 +                               ETHDEVICE="${_PARAMETER#ethdevice=}"
156 +                               export ETHDEVICE
157                                 ;;
158  
159                         ethdevice-timeout=*)
160 @@ -110,13 +109,9 @@
161                                 ;;
162  
163                         ip=*)
164 -                               STATICIP="${_PARAMETER#ip=}"
165 -
166 -                               if [ -z "${STATICIP}" ]
167 -                               then
168 -                                       STATICIP="frommedia"
169 -                               fi
170 -
171 +                               # copy complete ip=args into staticip, and
172 +                               # keep multiple uses.
173 +                               STATICIP="${STATICIP} ${_PARAMETER}"
174                                 export STATICIP
175                                 ;;
176