1 |
commit: 97c0c1761b977b0ddc1100111b608a2dba32e32a |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jul 29 16:26:25 2019 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jul 29 20:02:21 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=97c0c176 |
7 |
|
8 |
initrd.scripts: start_network(): Handle already running interface |
9 |
|
10 |
When kernel was built with CONFIG_IP_PNP_DHCP=y option for example and |
11 |
ip=dhcp was specified on kernel command-line, interface maybe already |
12 |
up and running (configured). In this case it doesn't make any sense to |
13 |
fire up udhcpc which would only get the same network configuration. |
14 |
|
15 |
However, when interface is already up but manual IP configuration was |
16 |
specified, we must restart interface to get back into a known state and |
17 |
apply our own configuration like told by the user because we support |
18 |
more complex configurations. |
19 |
|
20 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
21 |
|
22 |
defaults/initrd.scripts | 33 ++++++++++++++++++++++++++++++++- |
23 |
1 file changed, 32 insertions(+), 1 deletion(-) |
24 |
|
25 |
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts |
26 |
index ce38bd8..e01f461 100644 |
27 |
--- a/defaults/initrd.scripts |
28 |
+++ b/defaults/initrd.scripts |
29 |
@@ -1727,10 +1727,23 @@ start_network() { |
30 |
|
31 |
warn_msg "Will not try to start network ..." |
32 |
return 1 |
33 |
+ elif [ "${interface_identifier}" = 'mac' ] |
34 |
+ then |
35 |
+ good_msg "Interface detected as ${GK_NET_IFACE}" |
36 |
fi |
37 |
|
38 |
if [ -z "${IP}" -o "${IP}" = 'dhcp' ] |
39 |
then |
40 |
+ if is_interface_up |
41 |
+ then |
42 |
+ # CONFIG_IP_PNP_DHCP and ip=dhcp probably caused kernel to bring up |
43 |
+ # network for us. Really no need re-run dhcp... |
44 |
+ warn_msg "Interface ${GK_NET_IFACE} is already up." |
45 |
+ warn_msg "Skipping network setup; Will use existing network configuration ..." |
46 |
+ touch "${GK_NET_LOCKFILE}" |
47 |
+ return 0 |
48 |
+ fi |
49 |
+ |
50 |
good_msg "Bringing up interface ${GK_NET_IFACE} using dhcp ..." ${QUIET} |
51 |
busybox udhcpc -i "${GK_NET_IFACE}" -n -t ${GK_NET_DHCP_RETRIES} -T ${GK_NET_TIMEOUT_DHCP} -R -p "${GK_NET_DHCP_PIDFILE}" |
52 |
if [ $? -ne 0 ] |
53 |
@@ -1739,6 +1752,15 @@ start_network() { |
54 |
return 1 |
55 |
fi |
56 |
else |
57 |
+ if is_interface_up |
58 |
+ then |
59 |
+ # At this point we don't know if kernel has brought up network the |
60 |
+ # way we wanted. It's safer to restart interface and do it on our own... |
61 |
+ warn_msg "Interface ${GK_NET_IFACE} is already up and therefore in an unknown state!" |
62 |
+ warn_msg "Will now restart interface ${GK_NET_IFACE} to get into a known state ..." |
63 |
+ kill_network |
64 |
+ fi |
65 |
+ |
66 |
good_msg "Bringing up interface ${GK_NET_IFACE} ..." ${QUIET} |
67 |
ip link set "${GK_NET_IFACE}" up |
68 |
|
69 |
@@ -1835,7 +1857,16 @@ kill_network() { |
70 |
return |
71 |
fi |
72 |
|
73 |
- rm "${GK_NET_LOCKFILE}" |
74 |
+ [ -f "${GK_NET_LOCKFILE}" ] && rm "${GK_NET_LOCKFILE}" |
75 |
+} |
76 |
+ |
77 |
+is_interface_up() { |
78 |
+ if ip link show dev "${GK_NET_IFACE}" 2>/dev/null | grep -q ',UP,' |
79 |
+ then |
80 |
+ return 0 |
81 |
+ else |
82 |
+ return 1 |
83 |
+ fi |
84 |
} |
85 |
|
86 |
ipv6_tentative() { |