#include "config.h"
#include "daemon.h"
#include "devmon.h"
+#include "link.h"
#include "links.h"
#include "logging.h"
#include "zone.h"
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;
}
// Register callback for new interfaces
- r = sd_netlink_add_match(daemon->rtnl, NULL, RTM_NEWLINK, _rtnl_dummy, NULL,
+ r = sd_netlink_add_match(daemon->rtnl, NULL, RTM_NEWLINK, nw_link_process, NULL,
daemon, "networkd-RTM_NEWLINK");
if (r < 0) {
ERROR("Could not register RTM_NEWLINK: %m\n");
return 0;
}
+/*
+ Netlink
+*/
+sd_netlink* nw_daemon_get_rtnl(struct nw_daemon* daemon) {
+ return daemon->rtnl;
+}
+
/*
Zones
*/
#ifndef NETWORKD_DAEMON_H
#define NETWORKD_DAEMON_H
+#include <systemd/sd-netlink.h>
+
#include "zone.h"
struct nw_daemon;
int nw_daemon_reload(struct nw_daemon* daemon);
+/*
+ Netlink
+*/
+sd_netlink* nw_daemon_get_rtnl(struct nw_daemon* daemon);
+
/*
Zones
*/
#include "daemon.h"
#include "link.h"
+#include "logging.h"
struct nw_link {
struct nw_daemon* daemon;
nw_link_free(link);
return NULL;
}
+
+int nw_link_process(sd_netlink* rtnl, sd_netlink_message* message, void* data) {
+ DEBUG("nw_link_process called\n");
+
+ return 0;
+}
struct nw_link* nw_link_ref(struct nw_link* link);
struct nw_link* nw_link_unref(struct nw_link* link);
+int nw_link_process(sd_netlink* rtnl, sd_netlink_message* message, void* data);
+
#endif /* NETWORKD_LINK_H */
}
int nw_links_enumerate(struct nw_links* links) {
- // TODO
+ sd_netlink_message* req = NULL;
+ sd_netlink_message* res = NULL;
+ int r;
- return 0;
+ sd_netlink* rtnl = nw_daemon_get_rtnl(links->daemon);
+ if (!rtnl)
+ return 1;
+
+ r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, 0);
+ if (r < 0)
+ return 1;
+
+ r = sd_netlink_message_set_request_dump(req, 1);
+ if (r < 0)
+ return 1;
+
+ r = sd_netlink_call(rtnl, req, 0, &res);
+ if (r < 0)
+ return 1;
+
+ sd_netlink_message* m = res;
+
+ // Iterate through all replies
+ do {
+ r = nw_link_process(rtnl, m, links->daemon);
+ if (r)
+ goto ERROR;
+ } while ((m = sd_netlink_message_next(m)));
+
+ERROR:
+ if (m)
+ sd_netlink_message_unref(m);
+ if (req)
+ sd_netlink_message_unref(req);
+ if (res)
+ sd_netlink_message_unref(res);
+
+ return r;
}