]> git.ipfire.org Git - network.git/commitdiff
ports: Rename the ops struct as we will need to store more things than function pointers
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Jun 2023 16:42:11 +0000 (16:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Jun 2023 16:42:11 +0000 (16:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/port-dummy.c
src/networkd/port-dummy.h
src/networkd/port-vlan.c
src/networkd/port-vlan.h
src/networkd/port.c
src/networkd/port.h

index 09367d830bfae6558c96f1b61d9599bc10cc53ea..d6842d0cea722e53d9b460f7f17029a0dc69844e 100644 (file)
@@ -20,6 +20,6 @@
 
 #include "port-dummy.h"
 
-nw_port_ops_t nw_port_ops_dummy = {
+nw_port_info_t nw_port_info_dummy = {
        .kind = "dummy",
 };
index 0a29c84fb9f068c577b24a3780e88ee45d20dcf1..b07cf3998596f3091033b6294b0568dbfd71b6f9 100644 (file)
@@ -23,6 +23,6 @@
 
 #include "port.h"
 
-extern nw_port_ops_t nw_port_ops_dummy;
+extern nw_port_info_t nw_port_info_dummy;
 
 #endif /* NETWORKD_PORT_DUMMY_H */
index edf91d91d1ad5a3f26ef12bc922b519d57af2eb6..f1cd9fbb107941ea4a677e338f0c5e933a11ab21 100644 (file)
@@ -77,17 +77,20 @@ static int nw_port_vlan_create_link(nw_port* port, sd_netlink_message* m) {
        return 0;
 }
 
-nw_port_ops_t nw_port_ops_vlan = {
+nw_port_info_t nw_port_info_vlan = {
        .kind = "vlan",
 
-       // Configuration
-       .config_read = nw_port_vlan_config_read,
-       .config_write = nw_port_vlan_config_write,
+       // Operations
+       .ops = {
+               // Configuration
+               .config_read = nw_port_vlan_config_read,
+               .config_write = nw_port_vlan_config_write,
 
-       .get_parent_port = nw_port_get_vlan_parent,
+               .get_parent_port = nw_port_get_vlan_parent,
 
-       // Link
-       .create_link = nw_port_vlan_create_link,
+               // Link
+               .create_link = nw_port_vlan_create_link,
+       },
 };
 
 /*
index 2bacb24d30dcab9bd902ed025619efa3557a1cd7..c666dfb6b5124d2b7e9b1631ce52ca1bfc735aa6 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "port.h"
 
-extern nw_port_ops_t nw_port_ops_vlan;
+extern nw_port_info_t nw_port_info_vlan;
 
 // ID
 int nw_port_get_vlan_id(nw_port* port);
index a7cbab63c0c6775cbdadb81e76a14c8817d5caaa..061e13c73ccf789b511f79421b2abdcdd35336de 100644 (file)
@@ -168,8 +168,8 @@ static int nw_port_setup(nw_port* port) {
                goto ERROR;
 
        // Call any custom initialization
-       if (port->ops.config_read) {
-               r = port->ops.config_read(port);
+       if (NW_PORT_OPS(port)->config_read) {
+               r = NW_PORT_OPS(port)->config_read(port);
                if (r)
                        goto ERROR;
        }
@@ -201,11 +201,11 @@ int nw_port_create(nw_port** port, nw_daemon* daemon, nw_port_type_t type, const
        // Set operations
        switch (p->type) {
                case NW_PORT_DUMMY:
-                       p->ops = nw_port_ops_dummy;
+                       p->info = &nw_port_info_dummy;
                        break;
 
                case NW_PORT_VLAN:
-                       p->ops = nw_port_ops_vlan;
+                       p->info = &nw_port_info_vlan;
                        break;
        }
 
@@ -339,8 +339,8 @@ int nw_port_save(nw_port* port) {
        int r;
 
        // Call the custom handler
-       if (port->ops.config_write) {
-               r = port->ops.config_write(port);
+       if (NW_PORT_OPS(port)->config_write) {
+               r = NW_PORT_OPS(port)->config_write(port);
                if (r)
                        goto ERROR;
        }
@@ -429,11 +429,11 @@ static nw_link* nw_port_get_parent_link(nw_port* port) {
        nw_link* link = NULL;
 
        // Do nothing if not implemented
-       if (!port->ops.get_parent_port)
+       if (!NW_PORT_OPS(port)->get_parent_port)
                goto ERROR;
 
        // Fetch the parent
-       parent = port->ops.get_parent_port(port);
+       parent = NW_PORT_OPS(port)->get_parent_port(port);
        if (!parent)
                goto ERROR;
 
@@ -502,14 +502,14 @@ static int nw_port_create_link(nw_port* port) {
                goto ERROR;
 
        // Run the custom setup
-       if (port->ops.create_link) {
-               r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, port->ops.kind);
+       if (NW_PORT_OPS(port)->create_link) {
+               r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, NW_PORT_INFO(port)->kind);
                if (r < 0) {
                        ERROR("Could not open IFLA_INFO_DATA container: %s\n", strerror(-r));
                        goto ERROR;
                }
 
-               r = port->ops.create_link(port, m);
+               r = NW_PORT_OPS(port)->create_link(port, m);
                if (r) {
                        ERROR("Could not create port %s: %m\n", port->name);
                        goto ERROR;
@@ -522,7 +522,7 @@ static int nw_port_create_link(nw_port* port) {
 
        // Just set IFLA_INFO_KIND if there is no custom function
        } else {
-               r = sd_netlink_message_append_string(m, IFLA_INFO_KIND, port->ops.kind);
+               r = sd_netlink_message_append_string(m, IFLA_INFO_KIND, NW_PORT_INFO(port)->kind);
                if (r < 0)
                        goto ERROR;
        }
index d44ecb689360767491ec50753e041435cacc4e24..b73c5fe97c5d1419a01352c949d31d920ee15c30 100644 (file)
@@ -46,21 +46,26 @@ typedef struct nw_port nw_port;
 #include "config.h"
 #include "daemon.h"
 
-typedef struct nw_port_ops {
+typedef struct nw_port_info {
        // IFLA_INFO_KIND/IFLA_INFO_DATA
        const char* kind;
 
-       // Configuration
-       int (*config_read)(nw_port* port);
-       int (*config_write)(nw_port* port);
+       struct nw_port_ops {
+               // Configuration
+               int (*config_read)(nw_port* port);
+               int (*config_write)(nw_port* port);
 
-       // Get Parent Port
-       nw_port* (*get_parent_port)(nw_port* port);
+               // Get Parent Port
+               nw_port* (*get_parent_port)(nw_port* port);
 
-       // Link
-       int (*create_link)(nw_port* port, sd_netlink_message* message);
-       int (*destroy_link)(nw_port* port);
-} nw_port_ops_t;
+               // Link
+               int (*create_link)(nw_port* port, sd_netlink_message* message);
+               int (*destroy_link)(nw_port* port);
+       } ops;
+} nw_port_info_t;
+
+#define NW_PORT_INFO(port) (port->info)
+#define NW_PORT_OPS(port) (&NW_PORT_INFO(port)->ops)
 
 struct nw_port {
        nw_daemon* daemon;
@@ -79,7 +84,7 @@ struct nw_port {
        nw_address_t address;
 
        // Type Operations
-       nw_port_ops_t ops;
+       nw_port_info_t* info;
 
        // VLAN settings
        struct nw_port_vlan {