]> git.ipfire.org Git - people/ms/network.git/commitdiff
networkd: Try to reconfigure all ports and zones on startup
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Apr 2023 13:06:25 +0000 (13:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Apr 2023 13:06:25 +0000 (13:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/daemon.c
src/networkd/port.c
src/networkd/port.h
src/networkd/ports.c
src/networkd/ports.h
src/networkd/zone.c
src/networkd/zone.h
src/networkd/zones.c
src/networkd/zones.h

index 925b2070c2f3a74cdaf5e004ca0f1c19709f3e9a..c6dad91ee7156fa58d2d09aa92cec9090b22645c 100644 (file)
@@ -291,6 +291,37 @@ static int nw_daemon_enumerate(nw_daemon* daemon) {
        return 0;
 }
 
+static int __nw_daemon_reconfigure(sd_event_source* s, void* data) {
+       nw_daemon* daemon = (nw_daemon*)data;
+       int r;
+
+       DEBUG("Reconfiguring...\n");
+
+       // Reconfigure all zones
+       r = nw_zones_reconfigure(daemon->zones);
+       if (r)
+               return r;
+
+       // Reconfigure all ports
+       r = nw_ports_reconfigure(daemon->ports);
+       if (r)
+               return r;
+
+       return 0;
+}
+
+static int nw_daemon_reconfigure(nw_daemon* daemon) {
+       int r;
+
+       r = sd_event_add_defer(daemon->loop, NULL, __nw_daemon_reconfigure, daemon);
+       if (r) {
+               ERROR("Could not schedule re-configuration task: %m\n");
+               return r;
+       }
+
+       return 0;
+}
+
 static int nw_daemon_setup(nw_daemon* daemon) {
        int r;
 
@@ -324,6 +355,11 @@ static int nw_daemon_setup(nw_daemon* daemon) {
        if (r)
                return r;
 
+       // (Re-)configure everything
+       r = nw_daemon_reconfigure(daemon);
+       if (r)
+               return r;
+
        return 0;
 }
 
index 3c4f0b3eef9c7009b1f9e2c972cdf2a5d31ea33d..ec40830fe11405b8585e4de652a6e5024704971a 100644 (file)
@@ -263,6 +263,10 @@ const nw_address_t* nw_port_get_address(nw_port* port) {
        return &port->address;
 }
 
+int nw_port_reconfigure(nw_port* port) {
+       return 0; // XXX TODO
+}
+
 int nw_port_has_carrier(nw_port* port) {
        if (!port->link)
                return 0;
index 33241ed929a45086649d86d58cc8227f01fb4d44..17c8c3cd20508d48a2a992c1de536b8722122900 100644 (file)
@@ -46,6 +46,8 @@ char* nw_port_bus_path(nw_port* port);
 
 const nw_address_t* nw_port_get_address(nw_port* port);
 
+int nw_port_reconfigure(nw_port* port);
+
 int nw_port_has_carrier(nw_port* port);
 
 #endif /* NETWORKD_PORT_H */
index a87ca033c4958eb8f17220f279065a2dbe410441..87135d8cb628f19ea378c680f4dbff2c7c3c3021 100644 (file)
@@ -222,3 +222,24 @@ ERROR:
 
        return 1;
 }
+
+int nw_ports_walk(nw_ports* ports, nw_ports_walk_callback callback, void* data) {
+       struct nw_ports_entry* entry = NULL;
+       int r;
+
+       STAILQ_FOREACH(entry, &ports->entries, nodes) {
+               r = callback(ports->daemon, entry->port, data);
+               if (r)
+                       return r;
+       }
+
+       return 0;
+}
+
+static int __nw_ports_reconfigure(nw_daemon* daemon, nw_port* port, void* data) {
+       return nw_port_reconfigure(port);
+}
+
+int nw_ports_reconfigure(nw_ports* ports) {
+       return nw_ports_walk(ports, __nw_ports_reconfigure, NULL);
+}
index 40c9ae184c783031831c52259a4922ee854c49e4..68ae532ffb40cbb9278e37e396101ff68a00eb76 100644 (file)
@@ -23,6 +23,8 @@
 
 typedef struct nw_ports nw_ports;
 
+typedef int (*nw_ports_walk_callback)(nw_daemon* daemon, nw_port* port, void* data);
+
 #include "daemon.h"
 
 int nw_ports_create(nw_ports** ports, nw_daemon* daemon);
@@ -38,4 +40,8 @@ struct nw_port* nw_ports_get_by_name(nw_ports* ports, const char* name);
 
 int nw_ports_bus_paths(nw_ports* ports, char*** paths);
 
+int nw_ports_walk(nw_ports* ports, nw_ports_walk_callback callback, void* data);
+
+int nw_ports_reconfigure(nw_ports* ports);
+
 #endif /* NETWORKD_PORTS_H */
index 4fda1e5f28157349ae994aff26cc9c0378775f4d..9daa0d3d19b49e51ee6a7f551a2cd95ceba7a3f7 100644 (file)
@@ -184,6 +184,10 @@ static nw_link* nw_zone_get_link(nw_zone* zone) {
        return nw_link_ref(zone->link);
 }
 
+int nw_zone_reconfigure(nw_zone* zone) {
+       return 0; // XXX TODO
+}
+
 // Carrier
 
 int nw_zone_has_carrier(nw_zone* zone) {
index f5a2355ef9d517ec9c0cb72ceff0788d3ecb1624..591e467d6f03fcc12707a089b77adf31fbfdbff9 100644 (file)
@@ -41,6 +41,8 @@ const char* nw_zone_name(nw_zone* zone);
 
 char* nw_zone_bus_path(nw_zone* zone);
 
+int nw_zone_reconfigure(nw_zone* zone);
+
 int nw_zone_has_carrier(nw_zone* zone);
 
 /*
index 521da51d6b8c0c96544b620b38d93b09a82499ca..84a6673e8ef19cb18c17907cddf33d1b8f03547b 100644 (file)
@@ -252,3 +252,11 @@ int nw_zones_walk(nw_zones* zones, nw_zones_walk_callback callback, void* data)
 
        return 0;
 }
+
+static int __nw_zones_reconfigure(nw_daemon* daemon, nw_zone* zone, void* data) {
+       return nw_zone_reconfigure(zone);
+}
+
+int nw_zones_reconfigure(nw_zones* zones) {
+       return nw_zones_walk(zones, __nw_zones_reconfigure, NULL);
+}
index 019955e7d3d7d626a1290b2426afc15c270f3e39..ad39fd27f789782e4ef46868e839cfbc963e176c 100644 (file)
@@ -44,4 +44,6 @@ int nw_zones_bus_paths(nw_zones* zones, char*** paths);
 
 int nw_zones_walk(nw_zones* zones, nw_zones_walk_callback callback, void* data);
 
+int nw_zones_reconfigure(nw_zones* zones);
+
 #endif /* NETWORKD_ZONES_H */