summary refs log tree commit diff
path: root/img/app/etc/mdev/iface
diff options
context:
space:
mode:
Diffstat (limited to 'img/app/etc/mdev/iface')
-rwxr-xr-ximg/app/etc/mdev/iface36
1 files changed, 36 insertions, 0 deletions
diff --git a/img/app/etc/mdev/iface b/img/app/etc/mdev/iface
new file mode 100755
index 0000000..d8ceda5
--- /dev/null
+++ b/img/app/etc/mdev/iface
@@ -0,0 +1,36 @@
+#!/bin/execlineb -P
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2020-2021 Alyssa Ross <hi@alyssa.is>
+
+importas -i INTERFACE INTERFACE
+
+if { test $INTERFACE != lo }
+
+# Our IP is encoded in the NIC-specific portion of the interface's MAC
+# address.
+backtick -E LOCAL_IP {
+  awk -F: "{printf \"100.64.%d.%d\\n\", \"0x\" $5, \"0x\" $6}"
+  /sys/class/net/${INTERFACE}/address
+}
+
+if { ip address add ${LOCAL_IP}/32 dev $INTERFACE }
+if { ip link set $INTERFACE up }
+if { ip route add 169.254.0.1 dev $INTERFACE }
+if { ip route add default via 169.254.0.1 dev $INTERFACE }
+
+# Try to wait for the network to be up.
+# If we time out, well, there's not much we can do, so just carry on.
+# In future, it would be better if the network VM notified us about
+# network changes.
+foreground { printf "Waiting for network… " }
+foreground {
+  ifte { echo "Connected." } { echo "Timed out." }
+  pipeline { seq 10 }
+  forstdin _
+  if -n {
+    redirfd -w 2 /dev/null
+    wget -qT 6 -O /dev/null http://ipv4.connman.net/online/status.html
+  }
+}
+
+s6-rc -u change app