From f85499108f79011fa3ed6f18cc22a9dc50f6f9c2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 12 Jun 2021 12:26:37 +0900 Subject: [PATCH] network: start/stop LLDP client on carrier gained/lost Then, link_acquire_dynamic_conf() matches link_stop_engines(). Previously, LLDP client is started on interface is up, and stopped on both down and carrier loss. --- src/network/networkd-link.c | 10 ++++++---- src/network/networkd-lldp-rx.c | 29 ----------------------------- src/network/networkd-lldp-rx.h | 1 - 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 2cf84b0f139..c232a8d6c57 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -690,6 +690,12 @@ static int link_acquire_dynamic_conf(Link *link) { if (r < 0) return log_link_warning_errno(link, r, "Failed to start LLDP transmission: %m"); + if (link->lldp) { + r = sd_lldp_start(link->lldp); + if (r < 0) + return log_link_warning_errno(link, r, "Failed to start LLDP client: %m"); + } + return 0; } @@ -1986,10 +1992,6 @@ static int link_update_flags(Link *link, sd_netlink_message *message) { return r; } - r = link_update_lldp(link); - if (r < 0) - return r; - if (!had_carrier && link_has_carrier(link)) { log_link_info(link, "Gained carrier"); diff --git a/src/network/networkd-lldp-rx.c b/src/network/networkd-lldp-rx.c index c30cc36b51c..57c8446adef 100644 --- a/src/network/networkd-lldp-rx.c +++ b/src/network/networkd-lldp-rx.c @@ -103,38 +103,9 @@ int link_lldp_rx_configure(Link *link) { if (r < 0) return r; - r = link_update_lldp(link); - if (r < 0) - return r; - return 0; } -int link_update_lldp(Link *link) { - int r; - - assert(link); - - if (!link->lldp) - return 0; - - if (link->flags & IFF_UP) { - r = sd_lldp_start(link->lldp); - if (r < 0) - return log_link_warning_errno(link, r, "Failed to start LLDP: %m"); - if (r > 0) - log_link_debug(link, "Started LLDP."); - } else { - r = sd_lldp_stop(link->lldp); - if (r < 0) - return log_link_warning_errno(link, r, "Failed to stop LLDP: %m"); - if (r > 0) - log_link_debug(link, "Stopped LLDP."); - } - - return r; -} - int link_lldp_save(Link *link) { _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; diff --git a/src/network/networkd-lldp-rx.h b/src/network/networkd-lldp-rx.h index 49306eafd0a..22f6602bd0f 100644 --- a/src/network/networkd-lldp-rx.h +++ b/src/network/networkd-lldp-rx.h @@ -14,7 +14,6 @@ typedef enum LLDPMode { } LLDPMode; int link_lldp_rx_configure(Link *link); -int link_update_lldp(Link *link); int link_lldp_save(Link *link); const char* lldp_mode_to_string(LLDPMode m) _const_;