summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
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;