m/n/c/network: set status with static config
This makes the static network service also set the network state if no
autoconfiguration is in use.
This is currently quite hacky, it essentially checks if any interface
uses IPv4 autoconfig/DHCP and if not it choses the first IPv4 address
and sets that as the external address.
Change-Id: I53cebfaa373512eec3d26c59640c0328297acf32
Reviewed-on: https://review.monogon.dev/c/monogon/+/1644
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/node/core/network/static.go b/metropolis/node/core/network/static.go
index b04cba3..4d04ff3 100644
--- a/metropolis/node/core/network/static.go
+++ b/metropolis/node/core/network/static.go
@@ -41,6 +41,8 @@
return err
}
+ var hasIPv4Autoconfig bool
+
nameLinkMap := make(map[string]netlink.Link)
// interface name -> parent interface name
@@ -92,6 +94,7 @@
if err := s.runDHCPv4(ctx, newLink); err != nil {
return fmt.Errorf("error enabling DHCPv4 on %q: %w", newLink.Attrs().Name, err)
}
+ hasIPv4Autoconfig = true
}
if i.Ipv6Autoconfig != nil {
err := sysctlOptions{
@@ -128,6 +131,29 @@
s.ConfigureDNS(dns.NewUpstreamDirective(nsIPList))
}
+ if !hasIPv4Autoconfig {
+ var selectedAddr net.IP
+ ifLoop:
+ for _, i := range s.StaticConfig.Interface {
+ if i.Ipv4Autoconfig != nil {
+ continue
+ }
+ for _, a := range i.Address {
+ ipNet, err := addressOrPrefix(a)
+ if err != nil {
+ }
+ if ipNet.IP.To4() != nil {
+ selectedAddr = ipNet.IP.To4()
+ break ifLoop
+ }
+ }
+ }
+ s.status.Set(&Status{
+ ExternalAddress: selectedAddr,
+ DNSServers: nsIPList,
+ })
+ }
+
supervisor.Signal(ctx, supervisor.SignalHealthy)
supervisor.Signal(ctx, supervisor.SignalDone)
return nil