#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
#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 */
}
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
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;
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;
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)) {
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;
return r;
}
-int nw_config_read(struct nw_config* config) {
+int nw_config_read(nw_config* config) {
FILE* f = NULL;
int r;
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;
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
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) {
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
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
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
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
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;
#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 */
#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);
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),
#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 */
struct nw_daemon {
int nrefs;
- struct nw_config* config;
+ nw_config* config;
// Event Loop
sd_event* loop;
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;
};
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");
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
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
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[] = {
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
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
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
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
return 0;
}
-static int nw_daemon_setup(struct nw_daemon* daemon) {
+static int nw_daemon_setup(nw_daemon* daemon) {
int r;
// Read the configuration
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;
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)
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);
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;
/*
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
return 1;
}
-int nw_daemon_reload(struct nw_daemon* daemon) {
+int nw_daemon_reload(nw_daemon* daemon) {
DEBUG("Reloading daemon...\n");
// XXX TODO
/*
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;
/*
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;
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;
#include <systemd/sd-netlink.h>
-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 */
#include "string.h"
struct nw_link {
- struct nw_daemon* daemon;
+ nw_daemon* daemon;
int nrefs;
// Interface Index
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;
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;
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;
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;
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
}
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);
#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);
#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
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;
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)) {
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;
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) {
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)
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));
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;
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);
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) {
#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 */
}
int main(int argc, char** argv) {
- struct nw_daemon* daemon = NULL;
+ nw_daemon* daemon = NULL;
int r;
// Drop privileges
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);
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);
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;
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
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}),
#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 */
#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;
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)
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
return 0;
}
-static int nw_port_setup_common(struct nw_port* port) {
+static int nw_port_setup_common(nw_port* port) {
int r;
// Address
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;
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;
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;
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;
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;
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;
}
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 */
#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
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;
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)) {
}
}
-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;
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)
}
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))
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) {
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;
#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 */
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);
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);
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;
*/
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));
}
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);
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}),
#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 */
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];
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;
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;
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;
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;
/*
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);
#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 */
#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;
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;
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)) {
}
}
-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;
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)
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);
return r;
}
-int nw_zones_load(struct nw_zones** zones) {
+int nw_zones_load(nw_zones** zones) {
int r;
// Create a new zones object
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;
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) {
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;
#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 */