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,
+ },
};
/*
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;
}
// 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;
}
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;
}
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;
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;
// 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;
}
#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;
nw_address_t address;
// Type Operations
- nw_port_ops_t ops;
+ nw_port_info_t* info;
// VLAN settings
struct nw_port_vlan {