[25/29] dhcpcd.exe: Add a safety net to make sure we always have a route

Message ID 20221201172318.3166615-25-michael.tremer@ipfire.org
State Accepted
Commit 86ba5ce3161d2fce3a7190e761ba72dee63889ae
Headers
Series [01/29] libgudev: New package |

Commit Message

Michael Tremer Dec. 1, 2022, 5:23 p.m. UTC
  Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/initscripts/networking/dhcpcd.exe | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Patch

diff --git a/src/initscripts/networking/dhcpcd.exe b/src/initscripts/networking/dhcpcd.exe
index 4ab9fbc43..220f95c83 100644
--- a/src/initscripts/networking/dhcpcd.exe
+++ b/src/initscripts/networking/dhcpcd.exe
@@ -60,6 +60,18 @@  dhcpcd_up()
 		mv /tmp/hosts /etc/hosts
 	fi
 
+	# Try to set the default route if there is none
+	# This can happen when we are using the 3RD party configuration
+	# This should not be necessary, since dhcpcd says it will configure
+	# a default route, but that does not seem to happen:
+	# https://github.com/NetworkConfiguration/dhcpcd/issues/129
+	if ! ip route 2>/dev/null | grep ^default && [ -s "/var/ipfire/red/remote-ipaddress" ]; then
+		gateway=$(</var/ipfire/red/remote-ipaddress)
+
+		# XXX This is ignoring any MTU configuration
+		ip route add default via "${gateway}"
+	fi
+
 	if [ $update ]; then
 		# Consider RED being active
 		touch /var/ipfire/red/active