#include <systemd/sd-daemon.h>
#include <systemd/sd-device.h>
#include <systemd/sd-event.h>
+#include <systemd/sd-netlink.h>
#include "bus.h"
#include "config.h"
// Event Loop
sd_event* loop;
+ // Netlink Connection
+ sd_netlink* rtnl;
+
// DBus Connection
sd_bus* bus;
return 0;
}
+static int _rtnl_dummy(sd_netlink* rtnl, sd_netlink_message* message, void* data) {
+ DEBUG("_rtnl_dummy called\n");
+
+ return 0;
+}
+
+static int nw_daemon_connect_rtnl(struct nw_daemon* daemon, int fd) {
+ int r;
+
+ // Connect to Netlink
+ r = sd_netlink_open(&daemon->rtnl);
+ if (r < 0) {
+ ERROR("Could not connect to the kernel's netlink interface: %m\n");
+ return 1;
+ }
+
+ // Increase the receive buffer
+ r = sd_netlink_increase_rxbuf(daemon->rtnl, RCVBUF_SIZE);
+ if (r < 0) {
+ ERROR("Could not increase receive buffer for the netlink socket: %m\n");
+ return 1;
+ }
+
+ // Connect it to the event loop
+ r = sd_netlink_attach_event(daemon->rtnl, daemon->loop, 0);
+ if (r < 0) {
+ ERROR("Could not connect the netlink socket to the event loop: %m\n");
+ return 1;
+ }
+
+ // Register callback for new interfaces
+ r = sd_netlink_add_match(daemon->rtnl, NULL, RTM_NEWLINK, _rtnl_dummy, NULL,
+ daemon, "networkd-RTM_NEWLINK");
+ if (r < 0) {
+ ERROR("Could not register RTM_NEWLINK: %m\n");
+ return 1;
+ }
+
+ return 0;
+}
+
static int nw_daemon_setup(struct nw_daemon* daemon) {
int r;
if (r)
return r;
+ // Connect to the kernel's netlink interface
+ r = nw_daemon_connect_rtnl(daemon, 0);
+ if (r)
+ return r;
+
// Connect to the system bus
r = nw_bus_connect(daemon->bus, daemon->loop, daemon);
if (r)