mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
network/lldp: do not save LLDP neighbors under /run/systemd
Now LLDP neighbors are exposed through varlink. Hence, it is not necessary to save to a file.
This commit is contained in:
parent
14a5c07afa
commit
5a0f6adbb2
@ -272,7 +272,6 @@ static Link *link_free(Link *link) {
|
||||
free(link->driver);
|
||||
|
||||
unlink_and_free(link->lease_file);
|
||||
unlink_and_free(link->lldp_file);
|
||||
unlink_and_free(link->state_file);
|
||||
|
||||
sd_device_unref(link->dev);
|
||||
@ -2653,7 +2652,7 @@ static Link *link_drop_or_unref(Link *link) {
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_drop_or_unref);
|
||||
|
||||
static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||
_cleanup_free_ char *ifname = NULL, *kind = NULL, *state_file = NULL, *lease_file = NULL, *lldp_file = NULL;
|
||||
_cleanup_free_ char *ifname = NULL, *kind = NULL, *state_file = NULL, *lease_file = NULL;
|
||||
_cleanup_(link_drop_or_unrefp) Link *link = NULL;
|
||||
unsigned short iftype;
|
||||
int r, ifindex;
|
||||
@ -2694,9 +2693,6 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||
|
||||
if (asprintf(&lease_file, "/run/systemd/netif/leases/%d", ifindex) < 0)
|
||||
return log_oom_debug();
|
||||
|
||||
if (asprintf(&lldp_file, "/run/systemd/netif/lldp/%d", ifindex) < 0)
|
||||
return log_oom_debug();
|
||||
}
|
||||
|
||||
link = new(Link, 1);
|
||||
@ -2719,7 +2715,6 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||
|
||||
.state_file = TAKE_PTR(state_file),
|
||||
.lease_file = TAKE_PTR(lease_file),
|
||||
.lldp_file = TAKE_PTR(lldp_file),
|
||||
|
||||
.n_dns = UINT_MAX,
|
||||
.dns_default_route = -1,
|
||||
|
@ -181,7 +181,6 @@ typedef struct Link {
|
||||
|
||||
/* This is about LLDP reception */
|
||||
sd_lldp_rx *lldp_rx;
|
||||
char *lldp_file;
|
||||
|
||||
/* This is about LLDP transmission */
|
||||
sd_lldp_tx *lldp_tx;
|
||||
|
@ -52,8 +52,6 @@ static void lldp_rx_handler(sd_lldp_rx *lldp_rx, sd_lldp_rx_event_t event, sd_ll
|
||||
Link *link = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
(void) link_lldp_save(link);
|
||||
|
||||
if (link->lldp_tx && event == SD_LLDP_RX_EVENT_ADDED) {
|
||||
/* If we received information about a new neighbor, restart the LLDP "fast" logic */
|
||||
|
||||
@ -104,70 +102,3 @@ int link_lldp_rx_configure(Link *link) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int link_lldp_save(Link *link) {
|
||||
_cleanup_(unlink_and_freep) char *temp_path = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
sd_lldp_neighbor **l = NULL;
|
||||
int n = 0, r, i;
|
||||
|
||||
assert(link);
|
||||
|
||||
if (isempty(link->lldp_file))
|
||||
return 0; /* Do not update state file when running in test mode. */
|
||||
|
||||
if (!link->lldp_rx) {
|
||||
(void) unlink(link->lldp_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = sd_lldp_rx_get_neighbors(link->lldp_rx, &l);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0) {
|
||||
(void) unlink(link->lldp_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = r;
|
||||
|
||||
r = fopen_temporary(link->lldp_file, &f, &temp_path);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
(void) fchmod(fileno(f), 0644);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
const void *p;
|
||||
le64_t u;
|
||||
size_t sz;
|
||||
|
||||
r = sd_lldp_neighbor_get_raw(l[i], &p, &sz);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
u = htole64(sz);
|
||||
fwrite(&u, 1, sizeof(u), f);
|
||||
fwrite(p, 1, sz, f);
|
||||
}
|
||||
|
||||
r = fflush_and_check(f);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
r = conservative_rename(temp_path, link->lldp_file);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
finish:
|
||||
if (r < 0)
|
||||
log_link_error_errno(link, r, "Failed to save LLDP data to %s: %m", link->lldp_file);
|
||||
|
||||
if (l) {
|
||||
for (i = 0; i < n; i++)
|
||||
sd_lldp_neighbor_unref(l[i]);
|
||||
free(l);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ typedef enum LLDPMode {
|
||||
} LLDPMode;
|
||||
|
||||
int link_lldp_rx_configure(Link *link);
|
||||
int link_lldp_save(Link *link);
|
||||
|
||||
const char* lldp_mode_to_string(LLDPMode m) _const_;
|
||||
LLDPMode lldp_mode_from_string(const char *s) _pure_;
|
||||
|
@ -583,8 +583,6 @@ static int link_save(Link *link) {
|
||||
if (link->state == LINK_STATE_LINGER)
|
||||
return 0;
|
||||
|
||||
link_lldp_save(link);
|
||||
|
||||
admin_state = link_state_to_string(link->state);
|
||||
assert(admin_state);
|
||||
|
||||
|
@ -72,8 +72,7 @@ static int run(int argc, char *argv[]) {
|
||||
* to support old kernels not supporting AmbientCapabilities=. */
|
||||
FOREACH_STRING(p,
|
||||
"/run/systemd/netif/links/",
|
||||
"/run/systemd/netif/leases/",
|
||||
"/run/systemd/netif/lldp/") {
|
||||
"/run/systemd/netif/leases/") {
|
||||
r = mkdir_safe_label(p, 0755, UID_INVALID, GID_INVALID, MKDIR_WARN_MODE);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Could not create directory '%s': %m", p);
|
||||
|
@ -10,4 +10,3 @@
|
||||
d /run/systemd/netif 0755 systemd-network systemd-network -
|
||||
d /run/systemd/netif/links 0755 systemd-network systemd-network -
|
||||
d /run/systemd/netif/leases 0755 systemd-network systemd-network -
|
||||
d /run/systemd/netif/lldp 0755 systemd-network systemd-network -
|
||||
|
Loading…
x
Reference in New Issue
Block a user