From: Michael Tremer Date: Sat, 11 Feb 2023 17:44:42 +0000 (+0000) Subject: networkd: Use typedef to keep type names shorter X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2361667ee3e575e7c1b3044936a7b466283d7996;p=network.git networkd: Use typedef to keep type names shorter Signed-off-by: Michael Tremer --- diff --git a/src/networkd/bus.c b/src/networkd/bus.c index 258aacda..1daa0352 100644 --- a/src/networkd/bus.c +++ b/src/networkd/bus.c @@ -29,14 +29,14 @@ #include "logging.h" static int nw_bus_on_connect(sd_bus_message* m, void* data, sd_bus_error* error) { - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; DEBUG("Connected to D-Bus\n"); return 0; } -int nw_bus_connect(sd_bus* bus, sd_event* loop, struct nw_daemon* daemon) { +int nw_bus_connect(sd_bus* bus, sd_event* loop, nw_daemon* daemon) { int r; // Create a bus object diff --git a/src/networkd/bus.h b/src/networkd/bus.h index 42ab2d31..05b4c637 100644 --- a/src/networkd/bus.h +++ b/src/networkd/bus.h @@ -30,27 +30,27 @@ #include "daemon.h" -int nw_bus_connect(sd_bus* bus, sd_event* loop, struct nw_daemon* daemon); +int nw_bus_connect(sd_bus* bus, sd_event* loop, nw_daemon* daemon); struct nw_bus_vtable_pair { const sd_bus_vtable* vtable; sd_bus_object_find_t object_find; }; -struct nw_bus_implementation { +typedef struct nw_bus_implementation { const char* path; const char* interface; const sd_bus_vtable** vtables; const struct nw_bus_vtable_pair* fallback_vtables; sd_bus_node_enumerator_t node_enumerator; const struct nw_bus_implementation** children; -}; +} nw_bus_implementation; #define BUS_FALLBACK_VTABLES(...) ((const struct nw_bus_vtable_pair[]) { __VA_ARGS__, {} }) -#define BUS_IMPLEMENTATIONS(...) ((const struct nw_bus_implementation* []) { __VA_ARGS__, NULL }) +#define BUS_IMPLEMENTATIONS(...) ((const nw_bus_implementation* []) { __VA_ARGS__, NULL }) #define BUS_VTABLES(...) ((const sd_bus_vtable* []){ __VA_ARGS__, NULL }) int nw_bus_register_implementation(sd_bus* bus, - const struct nw_bus_implementation* impl, void* data); + const nw_bus_implementation* impl, void* data); #endif /* NETWORKD_BUS_H */ diff --git a/src/networkd/config.c b/src/networkd/config.c index 17d6d890..b3d52845 100644 --- a/src/networkd/config.c +++ b/src/networkd/config.c @@ -50,7 +50,7 @@ static void nw_config_entry_free(struct nw_config_entry* entry) { } static struct nw_config_entry* nw_config_entry_create( - struct nw_config* config, const char* key) { + nw_config* config, const char* key) { int r; // Check input value @@ -79,17 +79,17 @@ ERROR: return NULL; } -static void nw_config_free(struct nw_config* config) { +static void nw_config_free(nw_config* config) { // Flush all entries nw_config_flush(config); free(config); } -int nw_config_create(struct nw_config** config, const char* path) { +int nw_config_create(nw_config** config, const char* path) { int r; - struct nw_config* c = calloc(1, sizeof(*c)); + nw_config* c = calloc(1, sizeof(*c)); if (!c) return 1; @@ -121,13 +121,13 @@ ERROR: return r; } -struct nw_config* nw_config_ref(struct nw_config* config) { +nw_config* nw_config_ref(nw_config* config) { config->nrefs++; return config; } -struct nw_config* nw_config_unref(struct nw_config* config) { +nw_config* nw_config_unref(nw_config* config) { if (--config->nrefs > 0) return config; @@ -135,14 +135,14 @@ struct nw_config* nw_config_unref(struct nw_config* config) { return NULL; } -const char* nw_config_path(struct nw_config* config) { +const char* nw_config_path(nw_config* config) { if (*config->path) return config->path; return NULL; } -int nw_config_flush(struct nw_config* config) { +int nw_config_flush(nw_config* config) { struct nw_config_entry* entry = NULL; while (!STAILQ_EMPTY(&config->entries)) { @@ -156,7 +156,7 @@ int nw_config_flush(struct nw_config* config) { return 0; } -static int nw_config_readf(struct nw_config* config, FILE* f) { +static int nw_config_readf(nw_config* config, FILE* f) { char* line = NULL; size_t length = 0; int r; @@ -202,7 +202,7 @@ static int nw_config_readf(struct nw_config* config, FILE* f) { return r; } -int nw_config_read(struct nw_config* config) { +int nw_config_read(nw_config* config) { FILE* f = NULL; int r; @@ -234,7 +234,7 @@ ERROR: return r; } -static int nw_config_writef(struct nw_config* config, FILE* f) { +static int nw_config_writef(nw_config* config, FILE* f) { struct nw_config_entry* entry = NULL; int r; @@ -254,7 +254,7 @@ static int nw_config_writef(struct nw_config* config, FILE* f) { return 0; } -int nw_config_write(struct nw_config* config) { +int nw_config_write(nw_config* config) { int r; // We cannot write if path is not set @@ -280,7 +280,7 @@ ERROR: return r; } -static struct nw_config_entry* nw_config_find(struct nw_config* config, const char* key) { +static struct nw_config_entry* nw_config_find(nw_config* config, const char* key) { struct nw_config_entry* entry = NULL; STAILQ_FOREACH(entry, &config->entries, nodes) { @@ -296,7 +296,7 @@ static struct nw_config_entry* nw_config_find(struct nw_config* config, const ch return NULL; } -int nw_config_del(struct nw_config* config, const char* key) { +int nw_config_del(nw_config* config, const char* key) { struct nw_config_entry* entry = NULL; // Find an entry matching the key @@ -315,7 +315,7 @@ int nw_config_del(struct nw_config* config, const char* key) { return 0; } -const char* nw_config_get(struct nw_config* config, const char* key) { +const char* nw_config_get(nw_config* config, const char* key) { struct nw_config_entry* entry = nw_config_find(config, key); // Return the value if found and set @@ -326,7 +326,7 @@ const char* nw_config_get(struct nw_config* config, const char* key) { return NULL; } -int nw_config_set(struct nw_config* config, const char* key, const char* value) { +int nw_config_set(nw_config* config, const char* key, const char* value) { struct nw_config_entry* entry = NULL; // Delete the entry if val is NULL @@ -347,7 +347,7 @@ int nw_config_set(struct nw_config* config, const char* key, const char* value) return nw_string_set(entry->value, value); } -int nw_config_get_int(struct nw_config* config, const char* key, const int __default) { +int nw_config_get_int(nw_config* config, const char* key, const int __default) { const char* value = nw_config_get(config, key); // Return zero if not set @@ -357,7 +357,7 @@ int nw_config_get_int(struct nw_config* config, const char* key, const int __def return strtoul(value, NULL, 10); } -int nw_config_set_int(struct nw_config* config, const char* key, const int value) { +int nw_config_set_int(nw_config* config, const char* key, const int value) { char __value[1024]; int r; diff --git a/src/networkd/config.h b/src/networkd/config.h index b8d85550..041a10e8 100644 --- a/src/networkd/config.h +++ b/src/networkd/config.h @@ -26,26 +26,26 @@ #define NETWORK_CONFIG_KEY_MAX_LENGTH 128 #define NETWORK_CONFIG_VALUE_MAX_LENGTH 2048 -struct nw_config; +typedef struct nw_config nw_config; -int nw_config_create(struct nw_config** config, const char* path); +int nw_config_create(nw_config** config, const char* path); -struct nw_config* nw_config_ref(struct nw_config* config); -struct nw_config* nw_config_unref(struct nw_config* config); +nw_config* nw_config_ref(nw_config* config); +nw_config* nw_config_unref(nw_config* config); -const char* nw_config_path(struct nw_config* config); +const char* nw_config_path(nw_config* config); -int nw_config_flush(struct nw_config* config); +int nw_config_flush(nw_config* config); -int nw_config_read(struct nw_config* config); -int nw_config_write(struct nw_config* config); +int nw_config_read(nw_config* config); +int nw_config_write(nw_config* config); -int nw_config_del(struct nw_config* config, const char* key); +int nw_config_del(nw_config* config, const char* key); -const char* nw_config_get(struct nw_config* config, const char* key); -int nw_config_set(struct nw_config* config, const char* key, const char* value); +const char* nw_config_get(nw_config* config, const char* key); +int nw_config_set(nw_config* config, const char* key, const char* value); -int nw_config_get_int(struct nw_config* config, const char* key, const int __default); -int nw_config_set_int(struct nw_config* config, const char* key, const int value); +int nw_config_get_int(nw_config* config, const char* key, const int __default); +int nw_config_set_int(nw_config* config, const char* key, const int value); #endif /* NETWORKD_CONFIG_H */ diff --git a/src/networkd/daemon-bus.c b/src/networkd/daemon-bus.c index ca0754f5..93a04110 100644 --- a/src/networkd/daemon-bus.c +++ b/src/networkd/daemon-bus.c @@ -26,7 +26,7 @@ #include "zone-bus.h" static int nw_daemon_bus_reload(sd_bus_message* m, void* data, sd_bus_error* error) { - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; // Reload the daemon nw_daemon_reload(daemon); @@ -42,7 +42,7 @@ static const sd_bus_vtable daemon_vtable[] = { SD_BUS_VTABLE_END, }; -const struct nw_bus_implementation daemon_bus_impl = { +const nw_bus_implementation daemon_bus_impl = { .path = "/org/ipfire/network1", .interface = "org.ipfire.network1", .vtables = BUS_VTABLES(daemon_vtable), diff --git a/src/networkd/daemon-bus.h b/src/networkd/daemon-bus.h index 787e92a1..c3149633 100644 --- a/src/networkd/daemon-bus.h +++ b/src/networkd/daemon-bus.h @@ -23,6 +23,6 @@ #include "bus.h" -extern const struct nw_bus_implementation daemon_bus_impl; +extern const nw_bus_implementation daemon_bus_impl; #endif /* NETWORKD_DAEMON_BUS_H */ diff --git a/src/networkd/daemon.c b/src/networkd/daemon.c index c4acff55..9b9bf738 100644 --- a/src/networkd/daemon.c +++ b/src/networkd/daemon.c @@ -44,7 +44,7 @@ struct nw_daemon { int nrefs; - struct nw_config* config; + nw_config* config; // Event Loop sd_event* loop; @@ -59,13 +59,13 @@ struct nw_daemon { sd_device_monitor* devmon; // Links - struct nw_links* links; + nw_links* links; // Zones - struct nw_zones* zones; + nw_zones* zones; // Ports - struct nw_ports* ports; + nw_ports* ports; }; @@ -78,7 +78,7 @@ static int __nw_daemon_terminate(sd_event_source* source, const struct signalfd_ static int __nw_daemon_reload(sd_event_source* source, const struct signalfd_siginfo* si, void* data) { - struct nw_daemon* daemon = (struct nw_daemon*)daemon; + nw_daemon* daemon = (nw_daemon*)daemon; DEBUG("Received signal to reload...\n"); @@ -88,7 +88,7 @@ static int __nw_daemon_reload(sd_event_source* source, const struct signalfd_sig return 0; } -static int nw_daemon_setup_loop(struct nw_daemon* daemon) { +static int nw_daemon_setup_loop(nw_daemon* daemon) { int r; // Fetch a reference to the default event loop @@ -132,7 +132,7 @@ static int nw_daemon_setup_loop(struct nw_daemon* daemon) { return 0; } -static int nw_daemon_load_config(struct nw_daemon* daemon) { +static int nw_daemon_load_config(nw_daemon* daemon) { int r; // Read configuration file @@ -148,7 +148,7 @@ static int nw_daemon_load_config(struct nw_daemon* daemon) { return r; } -static int nw_start_device_monitor(struct nw_daemon* daemon) { +static int nw_start_device_monitor(nw_daemon* daemon) { int r; const char* subsystems[] = { @@ -199,7 +199,7 @@ static int nw_start_device_monitor(struct nw_daemon* daemon) { return 0; } -static int nw_daemon_connect_rtnl(struct nw_daemon* daemon, int fd) { +static int nw_daemon_connect_rtnl(nw_daemon* daemon, int fd) { int r; // Connect to Netlink @@ -242,7 +242,7 @@ static int nw_daemon_connect_rtnl(struct nw_daemon* daemon, int fd) { return 0; } -static int nw_daemon_enumerate_links(struct nw_daemon* daemon) { +static int nw_daemon_enumerate_links(nw_daemon* daemon) { int r; // Create a new links container @@ -253,7 +253,7 @@ static int nw_daemon_enumerate_links(struct nw_daemon* daemon) { return nw_links_enumerate(daemon->links); } -static int nw_daemon_enumerate_ports(struct nw_daemon* daemon) { +static int nw_daemon_enumerate_ports(nw_daemon* daemon) { int r; // Create a new ports container @@ -264,7 +264,7 @@ static int nw_daemon_enumerate_ports(struct nw_daemon* daemon) { return nw_ports_enumerate(daemon->ports); } -static int nw_daemon_enumerate(struct nw_daemon* daemon) { +static int nw_daemon_enumerate(nw_daemon* daemon) { int r; // Links @@ -280,7 +280,7 @@ static int nw_daemon_enumerate(struct nw_daemon* daemon) { return 0; } -static int nw_daemon_setup(struct nw_daemon* daemon) { +static int nw_daemon_setup(nw_daemon* daemon) { int r; // Read the configuration @@ -316,10 +316,10 @@ static int nw_daemon_setup(struct nw_daemon* daemon) { return 0; } -int nw_daemon_create(struct nw_daemon** daemon) { +int nw_daemon_create(nw_daemon** daemon) { int r; - struct nw_daemon* d = calloc(1, sizeof(*d)); + nw_daemon* d = calloc(1, sizeof(*d)); if (!d) return 1; @@ -342,7 +342,7 @@ ERROR: return r; } -static void nw_daemon_cleanup(struct nw_daemon* daemon) { +static void nw_daemon_cleanup(nw_daemon* daemon) { if (daemon->ports) nw_ports_unref(daemon->ports); if (daemon->zones) @@ -353,7 +353,7 @@ static void nw_daemon_cleanup(struct nw_daemon* daemon) { nw_config_unref(daemon->config); } -static void nw_daemon_free(struct nw_daemon* daemon) { +static void nw_daemon_free(nw_daemon* daemon) { // Cleanup common objects nw_daemon_cleanup(daemon); @@ -365,13 +365,13 @@ static void nw_daemon_free(struct nw_daemon* daemon) { free(daemon); } -struct nw_daemon* nw_daemon_ref(struct nw_daemon* daemon) { +nw_daemon* nw_daemon_ref(nw_daemon* daemon) { daemon->nrefs++; return daemon; } -struct nw_daemon* nw_daemon_unref(struct nw_daemon* daemon) { +nw_daemon* nw_daemon_unref(nw_daemon* daemon) { if (--daemon->nrefs > 0) return daemon; @@ -382,7 +382,7 @@ struct nw_daemon* nw_daemon_unref(struct nw_daemon* daemon) { /* This function contains the main loop of the daemon... */ -int nw_daemon_run(struct nw_daemon* daemon) { +int nw_daemon_run(nw_daemon* daemon) { int r; // We are now ready to process any requests @@ -412,7 +412,7 @@ ERROR: return 1; } -int nw_daemon_reload(struct nw_daemon* daemon) { +int nw_daemon_reload(nw_daemon* daemon) { DEBUG("Reloading daemon...\n"); // XXX TODO @@ -423,32 +423,32 @@ int nw_daemon_reload(struct nw_daemon* daemon) { /* Netlink */ -sd_netlink* nw_daemon_get_rtnl(struct nw_daemon* daemon) { +sd_netlink* nw_daemon_get_rtnl(nw_daemon* daemon) { return daemon->rtnl; } /* Links */ -struct nw_links* nw_daemon_links(struct nw_daemon* daemon) { +nw_links* nw_daemon_links(nw_daemon* daemon) { return nw_links_ref(daemon->links); } -void nw_daemon_drop_link(struct nw_daemon* daemon, struct nw_link* link) { +void nw_daemon_drop_link(nw_daemon* daemon, nw_link* link) { if (!daemon->links) return; nw_links_drop_link(daemon->links, link); } -struct nw_link* nw_daemon_get_link_by_ifindex(struct nw_daemon* daemon, int ifindex) { +nw_link* nw_daemon_get_link_by_ifindex(nw_daemon* daemon, int ifindex) { if (!daemon->links) return NULL; return nw_links_get_by_ifindex(daemon->links, ifindex); } -struct nw_link* nw_daemon_get_link_by_name(struct nw_daemon* daemon, const char* name) { +nw_link* nw_daemon_get_link_by_name(nw_daemon* daemon, const char* name) { if (!daemon->links) return NULL; @@ -458,11 +458,11 @@ struct nw_link* nw_daemon_get_link_by_name(struct nw_daemon* daemon, const char* /* Ports */ -struct nw_ports* nw_daemon_ports(struct nw_daemon* daemon) { +nw_ports* nw_daemon_ports(nw_daemon* daemon) { return nw_ports_ref(daemon->ports); } -struct nw_port* nw_daemon_get_port_by_name(struct nw_daemon* daemon, const char* name) { +nw_port* nw_daemon_get_port_by_name(nw_daemon* daemon, const char* name) { if (!daemon->ports) return NULL; @@ -473,11 +473,11 @@ struct nw_port* nw_daemon_get_port_by_name(struct nw_daemon* daemon, const char* Zones */ -struct nw_zones* nw_daemon_zones(struct nw_daemon* daemon) { +nw_zones* nw_daemon_zones(nw_daemon* daemon) { return nw_zones_ref(daemon->zones); } -struct nw_zone* nw_daemon_get_zone_by_name(struct nw_daemon* daemon, const char* name) { +nw_zone* nw_daemon_get_zone_by_name(nw_daemon* daemon, const char* name) { if (!daemon->zones) return NULL; diff --git a/src/networkd/daemon.h b/src/networkd/daemon.h index a40dd60d..16945991 100644 --- a/src/networkd/daemon.h +++ b/src/networkd/daemon.h @@ -23,43 +23,47 @@ #include -struct nw_daemon; +typedef struct nw_daemon nw_daemon; #include "link.h" +#include "links.h" +#include "port.h" +#include "ports.h" #include "zone.h" +#include "zones.h" -int nw_daemon_create(struct nw_daemon** daemon); +int nw_daemon_create(nw_daemon** daemon); -struct nw_daemon* nw_daemon_ref(struct nw_daemon* daemon); -struct nw_daemon* nw_daemon_unref(struct nw_daemon* daemon); +nw_daemon* nw_daemon_ref(nw_daemon* daemon); +nw_daemon* nw_daemon_unref(nw_daemon* daemon); -int nw_daemon_run(struct nw_daemon* daemon); +int nw_daemon_run(nw_daemon* daemon); -int nw_daemon_reload(struct nw_daemon* daemon); +int nw_daemon_reload(nw_daemon* daemon); /* Netlink */ -sd_netlink* nw_daemon_get_rtnl(struct nw_daemon* daemon); +sd_netlink* nw_daemon_get_rtnl(nw_daemon* daemon); /* Links */ -struct nw_links* nw_daemon_links(struct nw_daemon* daemon); -void nw_daemon_drop_link(struct nw_daemon* daemon, struct nw_link* link); -struct nw_link* nw_daemon_get_link_by_ifindex(struct nw_daemon* daemon, int ifindex); -struct nw_link* nw_daemon_get_link_by_name(struct nw_daemon* daemon, const char* name); +nw_links* nw_daemon_links(nw_daemon* daemon); +void nw_daemon_drop_link(nw_daemon* daemon, nw_link* link); +nw_link* nw_daemon_get_link_by_ifindex(nw_daemon* daemon, int ifindex); +nw_link* nw_daemon_get_link_by_name(nw_daemon* daemon, const char* name); /* Ports */ -struct nw_ports* nw_daemon_ports(struct nw_daemon* daemon); -struct nw_port* nw_daemon_get_port_by_name(struct nw_daemon* daemon, const char* name); +nw_ports* nw_daemon_ports(nw_daemon* daemon); +nw_port* nw_daemon_get_port_by_name(nw_daemon* daemon, const char* name); /* Zones */ -struct nw_zones* nw_daemon_zones(struct nw_daemon* daemon); -struct nw_zone* nw_daemon_get_zone_by_name(struct nw_daemon* daemon, const char* name); +nw_zones* nw_daemon_zones(nw_daemon* daemon); +nw_zone* nw_daemon_get_zone_by_name(nw_daemon* daemon, const char* name); #endif /* NETWORKD_DAEMON_H */ diff --git a/src/networkd/link.c b/src/networkd/link.c index 62be8937..2f95dc30 100644 --- a/src/networkd/link.c +++ b/src/networkd/link.c @@ -32,7 +32,7 @@ #include "string.h" struct nw_link { - struct nw_daemon* daemon; + nw_daemon* daemon; int nrefs; // Interface Index @@ -47,9 +47,9 @@ struct nw_link { uint32_t max_mtu; }; -int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex) { +int nw_link_create(nw_link** link, nw_daemon* daemon, int ifindex) { // Allocate a new object - struct nw_link* l = calloc(1, sizeof(*l)); + nw_link* l = calloc(1, sizeof(*l)); if (!l) return 1; @@ -69,20 +69,20 @@ int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex) return 0; } -static void nw_link_free(struct nw_link* link) { +static void nw_link_free(nw_link* link) { DEBUG("Freeing link (ifindex = %d)\n", link->ifindex); if (link->daemon) nw_daemon_unref(link->daemon); } -struct nw_link* nw_link_ref(struct nw_link* link) { +nw_link* nw_link_ref(nw_link* link) { link->nrefs++; return link; } -struct nw_link* nw_link_unref(struct nw_link* link) { +nw_link* nw_link_unref(nw_link* link) { if (--link->nrefs > 0) return link; @@ -90,11 +90,11 @@ struct nw_link* nw_link_unref(struct nw_link* link) { return NULL; } -int nw_link_ifindex(struct nw_link* link) { +int nw_link_ifindex(nw_link* link) { return link->ifindex; } -static int nw_link_update_ifname(struct nw_link* link, sd_netlink_message* message) { +static int nw_link_update_ifname(nw_link* link, sd_netlink_message* message) { const char* ifname = NULL; int r; @@ -120,7 +120,7 @@ static int nw_link_update_ifname(struct nw_link* link, sd_netlink_message* messa return 0; } -static int nw_link_update_mtu(struct nw_link* link, sd_netlink_message* message) { +static int nw_link_update_mtu(nw_link* link, sd_netlink_message* message) { uint32_t mtu = 0; uint32_t min_mtu = 0; uint32_t max_mtu = 0; @@ -172,7 +172,7 @@ static int nw_link_update_mtu(struct nw_link* link, sd_netlink_message* message) This function is called whenever anything changes, so that we can update our internal link object. */ -static int nw_link_update(struct nw_link* link, sd_netlink_message* message) { +static int nw_link_update(nw_link* link, sd_netlink_message* message) { int r; // Update the interface name @@ -189,14 +189,14 @@ static int nw_link_update(struct nw_link* link, sd_netlink_message* message) { } int nw_link_process(sd_netlink* rtnl, sd_netlink_message* message, void* data) { - struct nw_links* links = NULL; - struct nw_link* link = NULL; + nw_links* links = NULL; + nw_link* link = NULL; const char* ifname = NULL; int ifindex; uint16_t type; int r; - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; // Fetch links links = nw_daemon_links(daemon); diff --git a/src/networkd/link.h b/src/networkd/link.h index 72ddfa99..acb5e7b3 100644 --- a/src/networkd/link.h +++ b/src/networkd/link.h @@ -21,17 +21,17 @@ #ifndef NETWORKD_LINK_H #define NETWORKD_LINK_H -struct nw_link; +typedef struct nw_link nw_link; #include "daemon.h" -int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex); +int nw_link_create(nw_link** link, nw_daemon* daemon, int ifindex); -struct nw_link* nw_link_ref(struct nw_link* link); -struct nw_link* nw_link_unref(struct nw_link* link); +nw_link* nw_link_ref(nw_link* link); +nw_link* nw_link_unref(nw_link* link); -int nw_link_ifindex(struct nw_link* link); -const char* nw_link_name(struct nw_link* link); +int nw_link_ifindex(nw_link* link); +const char* nw_link_name(nw_link* link); int nw_link_process(sd_netlink* rtnl, sd_netlink_message* message, void* data); diff --git a/src/networkd/links.c b/src/networkd/links.c index 7aa83a31..9f41034c 100644 --- a/src/networkd/links.c +++ b/src/networkd/links.c @@ -29,14 +29,14 @@ #include "links.h" struct nw_links_entry { - struct nw_link* link; + nw_link* link; // Link to the other entries STAILQ_ENTRY(nw_links_entry) nodes; }; struct nw_links { - struct nw_daemon* daemon; + nw_daemon* daemon; int nrefs; // Link Entries @@ -46,8 +46,8 @@ struct nw_links { unsigned int num; }; -int nw_links_create(struct nw_links** links, struct nw_daemon* daemon) { - struct nw_links* l = calloc(1, sizeof(*l)); +int nw_links_create(nw_links** links, nw_daemon* daemon) { + nw_links* l = calloc(1, sizeof(*l)); if (!l) return 1; @@ -66,7 +66,7 @@ int nw_links_create(struct nw_links** links, struct nw_daemon* daemon) { return 0; } -static void nw_links_free(struct nw_links* links) { +static void nw_links_free(nw_links* links) { struct nw_links_entry* entry = NULL; while (!STAILQ_EMPTY(&links->entries)) { @@ -86,13 +86,13 @@ static void nw_links_free(struct nw_links* links) { nw_daemon_unref(links->daemon); } -struct nw_links* nw_links_ref(struct nw_links* links) { +nw_links* nw_links_ref(nw_links* links) { links->nrefs++; return links; } -struct nw_links* nw_links_unref(struct nw_links* links) { +nw_links* nw_links_unref(nw_links* links) { if (--links->nrefs > 0) return links; @@ -100,7 +100,7 @@ struct nw_links* nw_links_unref(struct nw_links* links) { return NULL; } -static struct nw_links_entry* nw_links_find_link(struct nw_links* links, const int ifindex) { +static struct nw_links_entry* nw_links_find_link(nw_links* links, const int ifindex) { struct nw_links_entry* entry = NULL; STAILQ_FOREACH(entry, &links->entries, nodes) { @@ -112,7 +112,7 @@ static struct nw_links_entry* nw_links_find_link(struct nw_links* links, const i return NULL; } -int nw_links_add_link(struct nw_links* links, struct nw_link* link) { +int nw_links_add_link(nw_links* links, struct nw_link* link) { // Allocate a new entry struct nw_links_entry* entry = calloc(1, sizeof(*entry)); if (!entry) @@ -130,7 +130,7 @@ int nw_links_add_link(struct nw_links* links, struct nw_link* link) { return 0; } -void nw_links_drop_link(struct nw_links* links, struct nw_link* link) { +void nw_links_drop_link(nw_links* links, struct nw_link* link) { struct nw_links_entry* entry = NULL; entry = nw_links_find_link(links, nw_link_ifindex(link)); @@ -143,7 +143,7 @@ void nw_links_drop_link(struct nw_links* links, struct nw_link* link) { links->num--; } -int nw_links_enumerate(struct nw_links* links) { +int nw_links_enumerate(nw_links* links) { sd_netlink_message* req = NULL; sd_netlink_message* res = NULL; int r; @@ -184,7 +184,7 @@ ERROR: return r; } -struct nw_link* nw_links_get_by_ifindex(struct nw_links* links, int ifindex) { +nw_link* nw_links_get_by_ifindex(nw_links* links, int ifindex) { struct nw_links_entry* entry = NULL; entry = nw_links_find_link(links, ifindex); @@ -194,7 +194,7 @@ struct nw_link* nw_links_get_by_ifindex(struct nw_links* links, int ifindex) { return nw_link_ref(entry->link); } -struct nw_link* nw_links_get_by_name(struct nw_links* links, const char* name) { +nw_link* nw_links_get_by_name(nw_links* links, const char* name) { struct nw_links_entry* entry = NULL; STAILQ_FOREACH(entry, &links->entries, nodes) { diff --git a/src/networkd/links.h b/src/networkd/links.h index 2b5c7876..21e6cfb3 100644 --- a/src/networkd/links.h +++ b/src/networkd/links.h @@ -24,19 +24,19 @@ #include "daemon.h" #include "link.h" -struct nw_links; +typedef struct nw_links nw_links; -int nw_links_create(struct nw_links** links, struct nw_daemon* daemon); +int nw_links_create(nw_links** links, nw_daemon* daemon); -struct nw_links* nw_links_ref(struct nw_links* links); -struct nw_links* nw_links_unref(struct nw_links* links); +nw_links* nw_links_ref(nw_links* links); +nw_links* nw_links_unref(nw_links* links); -int nw_links_add_link(struct nw_links* links, struct nw_link* link); -void nw_links_drop_link(struct nw_links* links, struct nw_link* link); +int nw_links_add_link(nw_links* links, nw_link* link); +void nw_links_drop_link(nw_links* links, nw_link* link); -int nw_links_enumerate(struct nw_links* links); +int nw_links_enumerate(nw_links* links); -struct nw_link* nw_links_get_by_ifindex(struct nw_links* links, int ifindex); -struct nw_link* nw_links_get_by_name(struct nw_links* links, const char* name); +nw_link* nw_links_get_by_ifindex(nw_links* links, int ifindex); +nw_link* nw_links_get_by_name(nw_links* links, const char* name); #endif /* NETWORKD_LINKS_H */ diff --git a/src/networkd/main.c b/src/networkd/main.c index 9a0fd74d..d3afc2aa 100644 --- a/src/networkd/main.c +++ b/src/networkd/main.c @@ -212,7 +212,7 @@ static int drop_privileges(const char* user) { } int main(int argc, char** argv) { - struct nw_daemon* daemon = NULL; + nw_daemon* daemon = NULL; int r; // Drop privileges diff --git a/src/networkd/port-bus.c b/src/networkd/port-bus.c index 1a486554..996be920 100644 --- a/src/networkd/port-bus.c +++ b/src/networkd/port-bus.c @@ -36,10 +36,10 @@ static int nw_port_node_enumerator(sd_bus* bus, const char* path, void* data, DEBUG("Enumerating ports...\n"); // Fetch a reference to the daemon - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; // Fetch ports - struct nw_ports* ports = nw_daemon_ports(daemon); + nw_ports* ports = nw_daemon_ports(daemon); // Make bus paths for all ports r = nw_ports_bus_paths(ports, nodes); @@ -58,7 +58,7 @@ static int nw_port_object_find(sd_bus* bus, const char* path, const char* interf int r; // Fetch a reference to the daemon - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; // Decode the path of the requested object r = sd_bus_path_decode(path, "/org/ipfire/network1/port", &name); @@ -66,7 +66,7 @@ static int nw_port_object_find(sd_bus* bus, const char* path, const char* interf return 0; // Find the port - struct nw_port* port = nw_daemon_get_port_by_name(daemon, name); + nw_port* port = nw_daemon_get_port_by_name(daemon, name); if (!port) return 0; @@ -80,7 +80,7 @@ static int nw_port_object_find(sd_bus* bus, const char* path, const char* interf static int nw_port_bus_get_address(sd_bus* bus, const char* path, const char* interface, const char* property, sd_bus_message* reply, void* data, sd_bus_error* error) { - struct nw_port* port = (struct nw_port*)data; + nw_port* port = (nw_port*)data; int r; // Fetch the address @@ -115,7 +115,7 @@ static const sd_bus_vtable port_vtable[] = { SD_BUS_VTABLE_END }; -const struct nw_bus_implementation port_bus_impl = { +const nw_bus_implementation port_bus_impl = { "/org/ipfire/network1/port", "org.ipfire.network1.Port", .fallback_vtables = BUS_FALLBACK_VTABLES({port_vtable, nw_port_object_find}), diff --git a/src/networkd/port-bus.h b/src/networkd/port-bus.h index 95e49a89..373c2812 100644 --- a/src/networkd/port-bus.h +++ b/src/networkd/port-bus.h @@ -23,6 +23,6 @@ #include "bus.h" -extern const struct nw_bus_implementation port_bus_impl; +extern const nw_bus_implementation port_bus_impl; #endif /* NETWORKD_PORT_BUS_H */ diff --git a/src/networkd/port.c b/src/networkd/port.c index 33e75d70..41b8b242 100644 --- a/src/networkd/port.c +++ b/src/networkd/port.c @@ -33,14 +33,14 @@ #include "port.h" struct nw_port { - struct nw_daemon* daemon; + nw_daemon* daemon; int nrefs; char name[IF_NAMESIZE]; nw_port_type_t type; // Configuration - struct nw_config *config; + nw_config *config; // Common attributes nw_address_t address; @@ -65,7 +65,7 @@ static nw_port_type_t nw_port_type_from_string(const char* s) { return NW_PORT_UNKNOWN; } -static void nw_port_free(struct nw_port* port) { +static void nw_port_free(nw_port* port) { if (port->config) nw_config_unref(port->config); if (port->daemon) @@ -74,7 +74,7 @@ static void nw_port_free(struct nw_port* port) { free(port); } -static int nw_port_setup_address(struct nw_port* port) { +static int nw_port_setup_address(nw_port* port) { int r; // Read ADDRESS from configuration @@ -111,7 +111,7 @@ ERROR: return 0; } -static int nw_port_setup_common(struct nw_port* port) { +static int nw_port_setup_common(nw_port* port) { int r; // Address @@ -122,7 +122,7 @@ static int nw_port_setup_common(struct nw_port* port) { return 0; } -static nw_port_type_t nw_port_setup_type(struct nw_port* port) { +static nw_port_type_t nw_port_setup_type(nw_port* port) { const char* type = nw_config_get(port->config, "TYPE"); if (!type) return NW_PORT_UNKNOWN; @@ -130,7 +130,7 @@ static nw_port_type_t nw_port_setup_type(struct nw_port* port) { return nw_port_type_from_string(type); } -static int nw_port_setup(struct nw_port* port) { +static int nw_port_setup(nw_port* port) { char path[PATH_MAX]; int r; @@ -167,11 +167,11 @@ static int nw_port_setup(struct nw_port* port) { return 0; } -int nw_port_create(struct nw_port** port, struct nw_daemon* daemon, const char* name) { +int nw_port_create(nw_port** port, nw_daemon* daemon, const char* name) { int r; // Allocate a new object - struct nw_port* p = calloc(1, sizeof(*p)); + nw_port* p = calloc(1, sizeof(*p)); if (!p) return 1; @@ -199,13 +199,13 @@ ERROR: return r; } -struct nw_port* nw_port_ref(struct nw_port* port) { +nw_port* nw_port_ref(nw_port* port) { port->nrefs++; return port; } -struct nw_port* nw_port_unref(struct nw_port* port) { +nw_port* nw_port_unref(nw_port* port) { if (--port->nrefs > 0) return port; @@ -213,11 +213,11 @@ struct nw_port* nw_port_unref(struct nw_port* port) { return NULL; } -const char* nw_port_name(struct nw_port* port) { +const char* nw_port_name(nw_port* port) { return port->name; } -char* nw_port_bus_path(struct nw_port* port) { +char* nw_port_bus_path(nw_port* port) { char* p = NULL; int r; @@ -229,10 +229,10 @@ char* nw_port_bus_path(struct nw_port* port) { return p; } -static struct nw_link* nw_port_get_link(struct nw_port* port) { +static nw_link* nw_port_get_link(nw_port* port) { return nw_daemon_get_link_by_name(port->daemon, port->name); } -const nw_address_t* nw_port_get_address(struct nw_port* port) { +const nw_address_t* nw_port_get_address(nw_port* port) { return &port->address; } diff --git a/src/networkd/port.h b/src/networkd/port.h index 92d60b29..9881846d 100644 --- a/src/networkd/port.h +++ b/src/networkd/port.h @@ -28,20 +28,20 @@ typedef enum nw_port_type { NW_PORT_DUMMY, } nw_port_type_t; -struct nw_port; +typedef struct nw_port nw_port; #include "address.h" #include "daemon.h" -int nw_port_create(struct nw_port** port, struct nw_daemon* daemon, const char* name); +int nw_port_create(nw_port** port, nw_daemon* daemon, const char* name); -struct nw_port* nw_port_ref(struct nw_port* port); -struct nw_port* nw_port_unref(struct nw_port* port); +nw_port* nw_port_ref(nw_port* port); +nw_port* nw_port_unref(nw_port* port); -const char* nw_port_name(struct nw_port* port); +const char* nw_port_name(nw_port* port); -char* nw_port_bus_path(struct nw_port* port); +char* nw_port_bus_path(nw_port* port); -const nw_address_t* nw_port_get_address(struct nw_port* port); +const nw_address_t* nw_port_get_address(nw_port* port); #endif /* NETWORKD_PORT_H */ diff --git a/src/networkd/ports.c b/src/networkd/ports.c index 9cec1115..35ed0481 100644 --- a/src/networkd/ports.c +++ b/src/networkd/ports.c @@ -30,14 +30,14 @@ #include "util.h" struct nw_ports_entry { - struct nw_port* port; + nw_port* port; // Link to the other entries STAILQ_ENTRY(nw_ports_entry) nodes; }; struct nw_ports { - struct nw_daemon* daemon; + nw_daemon* daemon; int nrefs; // Port Entries @@ -47,8 +47,8 @@ struct nw_ports { unsigned int num; }; -int nw_ports_create(struct nw_ports** ports, struct nw_daemon* daemon) { - struct nw_ports* p = calloc(1, sizeof(*p)); +int nw_ports_create(nw_ports** ports, nw_daemon* daemon) { + nw_ports* p = calloc(1, sizeof(*p)); if (!p) return 1; @@ -67,7 +67,7 @@ int nw_ports_create(struct nw_ports** ports, struct nw_daemon* daemon) { return 0; } -static void nw_ports_free(struct nw_ports* ports) { +static void nw_ports_free(nw_ports* ports) { struct nw_ports_entry* entry = NULL; while (!STAILQ_EMPTY(&ports->entries)) { @@ -84,13 +84,13 @@ static void nw_ports_free(struct nw_ports* ports) { } } -struct nw_ports* nw_ports_ref(struct nw_ports* ports) { +nw_ports* nw_ports_ref(nw_ports* ports) { ports->nrefs++; return ports; } -struct nw_ports* nw_ports_unref(struct nw_ports* ports) { +nw_ports* nw_ports_unref(nw_ports* ports) { if (--ports->nrefs > 0) return ports; @@ -98,7 +98,7 @@ struct nw_ports* nw_ports_unref(struct nw_ports* ports) { return NULL; } -static int nw_ports_add_port(struct nw_ports* ports, struct nw_port* port) { +static int nw_ports_add_port(nw_ports* ports, nw_port* port) { // Allocate a new entry struct nw_ports_entry* entry = calloc(1, sizeof(*entry)); if (!entry) @@ -117,10 +117,10 @@ static int nw_ports_add_port(struct nw_ports* ports, struct nw_port* port) { } static int __nw_ports_enumerate(const char* path, const struct stat* s, void* data) { - struct nw_port* port = NULL; + nw_port* port = NULL; int r; - struct nw_ports* ports = (struct nw_ports*)data; + nw_ports* ports = (nw_ports*)data; // Skip anything that isn't a regular file if (!S_ISREG(s->st_mode)) @@ -154,11 +154,11 @@ ERROR: return r; } -int nw_ports_enumerate(struct nw_ports* ports) { +int nw_ports_enumerate(nw_ports* ports) { return nw_ftw(PORT_CONFIG_DIR, PORT_CONFIG_DIR "/*", __nw_ports_enumerate, ports); } -struct nw_port* nw_ports_get_by_name(struct nw_ports* ports, const char* name) { +nw_port* nw_ports_get_by_name(nw_ports* ports, const char* name) { struct nw_ports_entry* entry = NULL; STAILQ_FOREACH(entry, &ports->entries, nodes) { @@ -173,7 +173,7 @@ struct nw_port* nw_ports_get_by_name(struct nw_ports* ports, const char* name) { return NULL; } -int nw_ports_bus_paths(struct nw_ports* ports, char*** paths) { +int nw_ports_bus_paths(nw_ports* ports, char*** paths) { struct nw_ports_entry* entry = NULL; char* path = NULL; diff --git a/src/networkd/ports.h b/src/networkd/ports.h index e807e25b..f58c3a4b 100644 --- a/src/networkd/ports.h +++ b/src/networkd/ports.h @@ -21,19 +21,19 @@ #ifndef NETWORKD_PORTS_H #define NETWORKD_PORTS_H -struct nw_ports; +typedef struct nw_ports nw_ports; #include "daemon.h" -int nw_ports_create(struct nw_ports** ports, struct nw_daemon* daemon); +int nw_ports_create(nw_ports** ports, nw_daemon* daemon); -struct nw_ports* nw_ports_ref(struct nw_ports* ports); -struct nw_ports* nw_ports_unref(struct nw_ports* ports); +nw_ports* nw_ports_ref(nw_ports* ports); +nw_ports* nw_ports_unref(nw_ports* ports); -int nw_ports_enumerate(struct nw_ports* ports); +int nw_ports_enumerate(nw_ports* ports); -struct nw_port* nw_ports_get_by_name(struct nw_ports* ports, const char* name); +struct nw_port* nw_ports_get_by_name(nw_ports* ports, const char* name); -int nw_ports_bus_paths(struct nw_ports* ports, char*** paths); +int nw_ports_bus_paths(nw_ports* ports, char*** paths); #endif /* NETWORKD_PORTS_H */ diff --git a/src/networkd/zone-bus.c b/src/networkd/zone-bus.c index e9c2ecc2..a06deb5b 100644 --- a/src/networkd/zone-bus.c +++ b/src/networkd/zone-bus.c @@ -34,10 +34,10 @@ static int nw_zone_node_enumerator(sd_bus* bus, const char* path, void* data, DEBUG("Enumerating zones...\n"); // Fetch a reference to the daemon - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; // Fetch zones - struct nw_zones* zones = nw_daemon_zones(daemon); + nw_zones* zones = nw_daemon_zones(daemon); // Make bus paths for all zones r = nw_zones_bus_paths(zones, nodes); @@ -56,7 +56,7 @@ static int nw_zone_object_find(sd_bus* bus, const char* path, const char* interf int r; // Fetch a reference to the daemon - struct nw_daemon* daemon = (struct nw_daemon*)data; + nw_daemon* daemon = (nw_daemon*)data; // Decode the path of the requested object r = sd_bus_path_decode(path, "/org/ipfire/network1/zone", &name); @@ -64,7 +64,7 @@ static int nw_zone_object_find(sd_bus* bus, const char* path, const char* interf return 0; // Find the zone - struct nw_zone* zone = nw_daemon_get_zone_by_name(daemon, name); + nw_zone* zone = nw_daemon_get_zone_by_name(daemon, name); if (!zone) return 0; @@ -81,7 +81,7 @@ static int nw_zone_object_find(sd_bus* bus, const char* path, const char* interf */ static int nw_zone_bus_get_mtu(sd_bus* bus, const char *path, const char *interface, const char* property, sd_bus_message* reply, void* data, sd_bus_error *error) { - struct nw_zone* zone = (struct nw_zone*)data; + nw_zone* zone = (nw_zone*)data; return sd_bus_message_append(reply, "u", nw_zone_mtu(zone)); } @@ -91,7 +91,7 @@ static int nw_zone_bus_set_mtu(sd_bus* bus, const char* path, const char* interf unsigned int mtu = 0; int r; - struct nw_zone* zone = (struct nw_zone*)data; + nw_zone* zone = (nw_zone*)data; // Parse the value r = sd_bus_message_read(value, "u", &mtu); @@ -114,7 +114,7 @@ static const sd_bus_vtable zone_vtable[] = { SD_BUS_VTABLE_END }; -const struct nw_bus_implementation zone_bus_impl = { +const nw_bus_implementation zone_bus_impl = { "/org/ipfire/network1/zone", "org.ipfire.network1.Zone", .fallback_vtables = BUS_FALLBACK_VTABLES({zone_vtable, nw_zone_object_find}), diff --git a/src/networkd/zone-bus.h b/src/networkd/zone-bus.h index 0d5583ed..db257f73 100644 --- a/src/networkd/zone-bus.h +++ b/src/networkd/zone-bus.h @@ -23,6 +23,6 @@ #include "bus.h" -extern const struct nw_bus_implementation zone_bus_impl; +extern const nw_bus_implementation zone_bus_impl; #endif /* NETWORKD_ZONE_BUS_H */ diff --git a/src/networkd/zone.c b/src/networkd/zone.c index c64706fc..b6fa65d2 100644 --- a/src/networkd/zone.c +++ b/src/networkd/zone.c @@ -34,13 +34,13 @@ struct nw_zone { char name[NETWORK_ZONE_NAME_MAX_LENGTH]; // Configuration - struct nw_config *config; + nw_config *config; }; #define nw_zone_path(zone, path, format, ...) \ __nw_zone_path(zone, path, sizeof(path), format, __VA_ARGS__) -static int __nw_zone_path(struct nw_zone* zone, char* p, const size_t length, +static int __nw_zone_path(nw_zone* zone, char* p, const size_t length, const char* format, ...) { char prefix[NAME_MAX]; char suffix[NAME_MAX]; @@ -63,14 +63,14 @@ static int __nw_zone_path(struct nw_zone* zone, char* p, const size_t length, return __nw_path_join(p, length, prefix, suffix); } -static void nw_zone_free(struct nw_zone* zone) { +static void nw_zone_free(nw_zone* zone) { if (zone->config) nw_config_unref(zone->config); free(zone); } -static int nw_zone_setup(struct nw_zone* zone) { +static int nw_zone_setup(nw_zone* zone) { char path[PATH_MAX]; int r; @@ -87,11 +87,11 @@ static int nw_zone_setup(struct nw_zone* zone) { return 0; } -int nw_zone_create(struct nw_zone** zone, const char* name) { +int nw_zone_create(nw_zone** zone, const char* name) { int r; // Allocate a new object - struct nw_zone* z = calloc(1, sizeof(*z)); + nw_zone* z = calloc(1, sizeof(*z)); if (!z) return 1; @@ -116,13 +116,13 @@ ERROR: return r; } -struct nw_zone* nw_zone_ref(struct nw_zone* zone) { +nw_zone* nw_zone_ref(nw_zone* zone) { zone->nrefs++; return zone; } -struct nw_zone* nw_zone_unref(struct nw_zone* zone) { +nw_zone* nw_zone_unref(nw_zone* zone) { if (--zone->nrefs > 0) return zone; @@ -130,11 +130,11 @@ struct nw_zone* nw_zone_unref(struct nw_zone* zone) { return NULL; } -const char* nw_zone_name(struct nw_zone* zone) { +const char* nw_zone_name(nw_zone* zone) { return zone->name; } -char* nw_zone_bus_path(struct nw_zone* zone) { +char* nw_zone_bus_path(nw_zone* zone) { char* p = NULL; int r; @@ -149,11 +149,11 @@ char* nw_zone_bus_path(struct nw_zone* zone) { /* MTU */ -unsigned int nw_zone_mtu(struct nw_zone* zone) { +unsigned int nw_zone_mtu(nw_zone* zone) { return nw_config_get_int(zone->config, "MTU", NETWORK_ZONE_DEFAULT_MTU); } -int nw_zone_set_mtu(struct nw_zone* zone, unsigned int mtu) { +int nw_zone_set_mtu(nw_zone* zone, unsigned int mtu) { DEBUG("Change MTU of %s to %u\n", zone->name, mtu); return nw_config_set_int(zone->config, "MTU", mtu); diff --git a/src/networkd/zone.h b/src/networkd/zone.h index 4a004125..1c8e6b65 100644 --- a/src/networkd/zone.h +++ b/src/networkd/zone.h @@ -24,21 +24,21 @@ #define NETWORK_ZONE_NAME_MAX_LENGTH 16 #define NETWORK_ZONE_DEFAULT_MTU 1500 -struct nw_zone; +typedef struct nw_zone nw_zone; -int nw_zone_create(struct nw_zone** zone, const char* name); +int nw_zone_create(nw_zone** zone, const char* name); -struct nw_zone* nw_zone_ref(struct nw_zone* zone); -struct nw_zone* nw_zone_unref(struct nw_zone* zone); +nw_zone* nw_zone_ref(nw_zone* zone); +nw_zone* nw_zone_unref(nw_zone* zone); -const char* nw_zone_name(struct nw_zone* zone); +const char* nw_zone_name(nw_zone* zone); -char* nw_zone_bus_path(struct nw_zone* zone); +char* nw_zone_bus_path(nw_zone* zone); /* MTU */ -unsigned int nw_zone_mtu(struct nw_zone* zone); -int nw_zone_set_mtu(struct nw_zone* zone, unsigned int mtu); +unsigned int nw_zone_mtu(nw_zone* zone); +int nw_zone_set_mtu(nw_zone* zone, unsigned int mtu); #endif /* NETWORKD_ZONE_H */ diff --git a/src/networkd/zones.c b/src/networkd/zones.c index 4f739f52..779bbe10 100644 --- a/src/networkd/zones.c +++ b/src/networkd/zones.c @@ -28,7 +28,7 @@ #include "zones.h" struct nw_zones_entry { - struct nw_zone* zone; + nw_zone* zone; // Link to the other entries STAILQ_ENTRY(nw_zones_entry) nodes; @@ -44,8 +44,8 @@ struct nw_zones { unsigned int num; }; -static int nw_zones_create(struct nw_zones** zones) { - struct nw_zones* z = calloc(1, sizeof(*z)); +static int nw_zones_create(nw_zones** zones) { + nw_zones* z = calloc(1, sizeof(*z)); if (!z) return 1; @@ -61,7 +61,7 @@ static int nw_zones_create(struct nw_zones** zones) { return 0; } -static void nw_zones_free(struct nw_zones* zones) { +static void nw_zones_free(nw_zones* zones) { struct nw_zones_entry* entry = NULL; while (!STAILQ_EMPTY(&zones->entries)) { @@ -78,13 +78,13 @@ static void nw_zones_free(struct nw_zones* zones) { } } -struct nw_zones* nw_zones_ref(struct nw_zones* zones) { +nw_zones* nw_zones_ref(nw_zones* zones) { zones->nrefs++; return zones; } -struct nw_zones* nw_zones_unref(struct nw_zones* zones) { +nw_zones* nw_zones_unref(nw_zones* zones) { if (--zones->nrefs > 0) return zones; @@ -92,7 +92,7 @@ struct nw_zones* nw_zones_unref(struct nw_zones* zones) { return NULL; } -static int nw_zones_add_zone(struct nw_zones* zones, struct nw_zone* zone) { +static int nw_zones_add_zone(nw_zones* zones, nw_zone* zone) { // Allocate a new entry struct nw_zones_entry* entry = calloc(1, sizeof(*entry)); if (!entry) @@ -124,12 +124,12 @@ static int nw_zones_load_filter(const struct dirent* path) { return 1; } -static int __nw_zones_load(struct nw_zones* zones) { +static int __nw_zones_load(nw_zones* zones) { struct dirent** paths = NULL; int n; int r = 0; - struct nw_zone* zone = NULL; + nw_zone* zone = NULL; // Scan the zones directory n = scandir(CONFIG_DIR "/zones", &paths, nw_zones_load_filter, alphasort); @@ -173,7 +173,7 @@ ERROR: return r; } -int nw_zones_load(struct nw_zones** zones) { +int nw_zones_load(nw_zones** zones) { int r; // Create a new zones object @@ -193,7 +193,7 @@ ERROR: return r; } -size_t nw_zones_num(struct nw_zones* zones) { +size_t nw_zones_num(nw_zones* zones) { struct nw_zones_entry* entry = NULL; size_t length = 0; @@ -204,7 +204,7 @@ size_t nw_zones_num(struct nw_zones* zones) { return length; } -struct nw_zone* nw_zones_get_by_name(struct nw_zones* zones, const char* name) { +nw_zone* nw_zones_get_by_name(nw_zones* zones, const char* name) { struct nw_zones_entry* entry = NULL; STAILQ_FOREACH(entry, &zones->entries, nodes) { @@ -219,7 +219,7 @@ struct nw_zone* nw_zones_get_by_name(struct nw_zones* zones, const char* name) { return NULL; } -int nw_zones_bus_paths(struct nw_zones* zones, char*** paths) { +int nw_zones_bus_paths(nw_zones* zones, char*** paths) { struct nw_zones_entry* entry = NULL; char* path = NULL; diff --git a/src/networkd/zones.h b/src/networkd/zones.h index 6e2686d0..e41c74fd 100644 --- a/src/networkd/zones.h +++ b/src/networkd/zones.h @@ -21,17 +21,17 @@ #ifndef NETWORKD_ZONES_H #define NETWORKD_ZONES_H -struct nw_zones; +typedef struct nw_zones nw_zones; -struct nw_zones* nw_zones_ref(struct nw_zones* zones); -struct nw_zones* nw_zones_unref(struct nw_zones* zones); +nw_zones* nw_zones_ref(nw_zones* zones); +nw_zones* nw_zones_unref(nw_zones* zones); -int nw_zones_load(struct nw_zones** zones); +int nw_zones_load(nw_zones** zones); -size_t nw_zones_num(struct nw_zones* zones); +size_t nw_zones_num(nw_zones* zones); -struct nw_zone* nw_zones_get_by_name(struct nw_zones* zones, const char* name); +nw_zone* nw_zones_get_by_name(nw_zones* zones, const char* name); -int nw_zones_bus_paths(struct nw_zones* zones, char*** paths); +int nw_zones_bus_paths(nw_zones* zones, char*** paths); #endif /* NETWORKD_ZONES_H */