From: Michael Tremer Date: Sun, 4 Jun 2023 16:42:11 +0000 (+0000) Subject: ports: Rename the ops struct as we will need to store more things than function pointers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=89f8f6af09b8ebf897ca6f91a3abb3b3f40fcaad;p=network.git ports: Rename the ops struct as we will need to store more things than function pointers Signed-off-by: Michael Tremer --- diff --git a/src/networkd/port-dummy.c b/src/networkd/port-dummy.c index 09367d83..d6842d0c 100644 --- a/src/networkd/port-dummy.c +++ b/src/networkd/port-dummy.c @@ -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", }; diff --git a/src/networkd/port-dummy.h b/src/networkd/port-dummy.h index 0a29c84f..b07cf399 100644 --- a/src/networkd/port-dummy.h +++ b/src/networkd/port-dummy.h @@ -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 */ diff --git a/src/networkd/port-vlan.c b/src/networkd/port-vlan.c index edf91d91..f1cd9fbb 100644 --- a/src/networkd/port-vlan.c +++ b/src/networkd/port-vlan.c @@ -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, + }, }; /* diff --git a/src/networkd/port-vlan.h b/src/networkd/port-vlan.h index 2bacb24d..c666dfb6 100644 --- a/src/networkd/port-vlan.h +++ b/src/networkd/port-vlan.h @@ -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); diff --git a/src/networkd/port.c b/src/networkd/port.c index a7cbab63..061e13c7 100644 --- a/src/networkd/port.c +++ b/src/networkd/port.c @@ -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; } diff --git a/src/networkd/port.h b/src/networkd/port.h index d44ecb68..b73c5fe9 100644 --- a/src/networkd/port.h +++ b/src/networkd/port.h @@ -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 {