Skip to content

Commit 5ee2bb0

Browse files
author
Sebastian L
committed
Fix and enhance networking
- Use configure_networking() in networking.sh - Wait for valid network connection - Deconfigure network in init-bottom/networking.sh
1 parent 2c9c899 commit 5ee2bb0

File tree

4 files changed

+72
-21
lines changed

4 files changed

+72
-21
lines changed

build-deb.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
chmod u=rwx src/etc/initramfs-tools/hooks/*.sh
44
chmod u=rwx src/etc/initramfs-tools/scripts/init-premount/*.sh
5+
chmod u=rwx src/etc/initramfs-tools/scripts/init-bottom/*.sh
56
chmod u=rwx src/lib/cryptsetup/scripts/wget_or_ask
67

78
chmod og=rx src/etc/initramfs-tools/hooks/*.sh
89
chmod og=rx src/etc/initramfs-tools/scripts/init-premount/*.sh
10+
chmod og=rx src/etc/initramfs-tools/scripts/init-bottom/*.sh
911
chmod og=rx src/lib/cryptsetup/scripts/wget_or_ask
1012

11-
dpkg-deb -b src dist
13+
dpkg-deb -b src dist
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
PREREQ=""
4+
5+
prereqs() {
6+
echo "$PREREQ"
7+
}
8+
9+
case "$1" in
10+
prereqs)
11+
prereqs
12+
exit 0
13+
;;
14+
esac
15+
16+
. /scripts/functions
17+
18+
# Bring all interfaces down or set variable IFACE to none
19+
IFDOWN=*
20+
21+
if [ "$BOOT" != nfs ] && [ "$IFDOWN" != none ]; then
22+
for IFACE in /sys/class/net/$IFDOWN; do
23+
[ -e "$IFACE" ] || continue
24+
IFACE="${IFACE#/sys/class/net/}"
25+
log_begin_msg "Bringing down $IFACE"
26+
ip link set dev "$IFACE" down
27+
ip address flush dev "$IFACE"
28+
ip route flush dev "$IFACE"
29+
log_end_msg
30+
done
31+
fi
Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
#!/bin/sh
2-
set -e
32

4-
PREREQ=""
3+
PREREQ="udev"
54

6-
prereqs()
7-
{
5+
prereqs() {
86
echo "$PREREQ"
97
}
108

11-
case $1 in
9+
case "$1" in
1210
prereqs)
1311
prereqs
1412
exit 0
15-
;;
13+
;;
1614
esac
1715

1816
. /scripts/functions
1917

20-
# The more sensible approach might be use the configure_networking function
21-
# but I struggled to make this work well independently of configuring NFS
22-
wait_for_udev 10
23-
ipconfig -t 30 -c dhcp -d eth0
24-
25-
26-
# Cloudflare
27-
echo 'nameserver 1.1.1.1' > /etc/resolv.conf
28-
echo 'nameserver 1.0.0.1' >> /etc/resolv.conf
29-
30-
# Quad 9
31-
echo 'nameserver 9.9.9.9' >> /etc/resolv.conf
32-
echo 'nameserver 9.9.9.10' >> /etc/resolv.conf
18+
# Network is manually configured.
19+
[ "$IP" != off ] && [ "$IP" != none ] || exit 0
20+
21+
# Always run configure_networking() before fetching the key; on NFS
22+
# mounts this has been already done
23+
[ "$BOOT" != nfs ] && configure_networking
24+
25+
# Waiting 30 seconds to get a valid network connection before
26+
# configuring resolv.conf
27+
connection_wait=30
28+
seconds=0
29+
while [ $seconds -le 30 ]; do
30+
if [ "$(/sbin/ip addr | grep -c inet )" -ne 0 ]; then
31+
break
32+
fi
33+
if [ $seconds -ge $connection_wait ]; then
34+
log_failure_msg "No working networking connection found in $connection_wait seconds"
35+
fi
36+
sleep 1
37+
seconds=$(( seconds + 1))
38+
done
39+
40+
# Configure a basic resolv.conf just to get domain name resolving
41+
# working.
42+
if ! [ -s /etc/resolv.conf ]; then
43+
# Cloudflare
44+
[ -z "$IPV4DNS0" ] && IPV4DNS0="1.1.1.1"
45+
# Quad9
46+
[ -z "$IPV4DNS1" ] && IPV4DNS1="9.9.9.9"
47+
echo "nameserver $IPV4DNS0" > /etc/resolv.conf
48+
echo "nameserver $IPV4DNS1" > /etc/resolv.conf
49+
fi

tests/shellcheck.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ SC_EXCLUDE="SC2181,SC2162,SC1091,SC2129"
33

44
shellcheck -s sh --exclude="$SC_EXCLUDE" src/lib/cryptsetup/scripts/wget_or_ask \
55
src/etc/initramfs-tools/hooks/*.sh \
6-
src/etc/initramfs-tools/scripts/init-premount/networking.sh
6+
src/etc/initramfs-tools/scripts/init-premount/networking.sh
7+
src/etc/initramfs-tools/scripts/init-bottom/networking.sh

0 commit comments

Comments
 (0)