summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorSusant Sahani <susant@redhat.com>2014-12-11 09:59:55 +0530
committerSusant Sahani <susant@redhat.com>2014-12-19 08:15:05 +0530
commit49699bac94d24b444274f91f85c82e6fad04d029 (patch)
tree617cd733775e4b23bcabc37de590f4f6ff8ef916 /src/network/networkd-link.c
parentce43e484465050c619ea9a1991d49b3d6215028b (diff)
LLDP: Add support for networkctl
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 725e22b93f..93b53ee3c0 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -219,6 +219,12 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
if (r < 0)
return -ENOMEM;
+ r = asprintf(&link->lldp_file, "/run/systemd/netif/lldp/%d",
+ link->ifindex);
+ if (r < 0)
+ return -ENOMEM;
+
+
r = hashmap_ensure_allocated(&manager->links, NULL);
if (r < 0)
return r;
@@ -259,6 +265,9 @@ static void link_free(Link *link) {
unlink(link->lease_file);
free(link->lease_file);
+ unlink(link->lldp_file);
+ free(link->lldp_file);
+
sd_ipv4ll_unref(link->ipv4ll);
sd_dhcp6_client_unref(link->dhcp6_client);
sd_icmp6_nd_unref(link->icmp6_router_discovery);
@@ -895,6 +904,23 @@ static int link_set_bridge(Link *link) {
return r;
}
+static void lldp_handler(sd_lldp *lldp, int event, void *userdata) {
+ Link *link = userdata;
+ int r;
+
+ assert(link);
+ assert(link->network);
+ assert(link->manager);
+
+ if (event != UPDATE_INFO)
+ return;
+
+ r = sd_lldp_save(link->lldp, link->lldp_file);
+ if (r < 0)
+ log_link_warning(link, "could not save LLDP");
+
+}
+
static int link_acquire_conf(Link *link) {
int r;
@@ -1237,6 +1263,11 @@ static int link_configure(Link *link) {
r = sd_lldp_attach_event(link->lldp, NULL, 0);
if (r < 0)
return r;
+
+ r = sd_lldp_set_callback(link->lldp,
+ lldp_handler, link);
+ if (r < 0)
+ return r;
}
if (link_has_carrier(link)) {
@@ -1855,6 +1886,19 @@ int link_save(Link *link) {
} else
unlink(link->lease_file);
+ if (link->lldp) {
+ assert(link->network);
+
+ r = sd_lldp_save(link->lldp, link->lldp_file);
+ if (r < 0)
+ goto fail;
+
+ fprintf(f,
+ "LLDP_FILE=%s\n",
+ link->lldp_file);
+ } else
+ unlink(link->lldp_file);
+
r = fflush_and_check(f);
if (r < 0)
goto fail;