From 4be699a8dbb85cac1c80f5a1414bc8e4c1bd5035 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 14:44:12 +0900 Subject: [PATCH 01/12] sd-lldp-rx: ignore all errors in processing datagram --- src/libsystemd-network/sd-lldp-rx.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 8d9b132722..8431412613 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -178,16 +178,12 @@ static int lldp_rx_handle_datagram(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *n) { assert(n); r = lldp_neighbor_parse(n); - if (r == -EBADMSG) /* Ignore bad messages */ - return 0; if (r < 0) return r; r = lldp_rx_add_neighbor(lldp_rx, n); - if (r < 0) { - log_lldp_rx_errno(lldp_rx, r, "Failed to add datagram. Ignoring."); - return 0; - } + if (r < 0) + return log_lldp_rx_errno(lldp_rx, r, "Failed to add datagram. Ignoring."); log_lldp_rx(lldp_rx, "Successfully processed LLDP datagram."); return 0; @@ -209,8 +205,10 @@ static int lldp_rx_receive_datagram(sd_event_source *s, int fd, uint32_t revents } n = lldp_neighbor_new(space); - if (!n) - return -ENOMEM; + if (!n) { + log_oom_debug(); + return 0; + } length = recv(fd, LLDP_NEIGHBOR_RAW(n), n->raw_size, MSG_DONTWAIT); if (length < 0) { @@ -232,7 +230,8 @@ static int lldp_rx_receive_datagram(sd_event_source *s, int fd, uint32_t revents else triple_timestamp_get(&n->timestamp); - return lldp_rx_handle_datagram(lldp_rx, n); + (void) lldp_rx_handle_datagram(lldp_rx, n); + return 0; } static void lldp_rx_reset(sd_lldp_rx *lldp_rx) { From b5dce07a5ebe070b70f85ed683fbcaf82a862b5a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 14:51:24 +0900 Subject: [PATCH 02/12] sd-lldp-rx: introduce sd_lldp_rx_is_running() --- src/libsystemd-network/sd-lldp-rx.c | 21 ++++++++++++--------- src/systemd/sd-lldp-rx.h | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 8431412613..21b538a930 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -242,6 +242,13 @@ static void lldp_rx_reset(sd_lldp_rx *lldp_rx) { lldp_rx->fd = safe_close(lldp_rx->fd); } +int sd_lldp_rx_is_running(sd_lldp_rx *lldp_rx) { + if (!lldp_rx) + return false; + + return lldp_rx->fd >= 0; +} + _public_ int sd_lldp_rx_start(sd_lldp_rx *lldp_rx) { int r; @@ -249,7 +256,7 @@ _public_ int sd_lldp_rx_start(sd_lldp_rx *lldp_rx) { assert_return(lldp_rx->event, -EINVAL); assert_return(lldp_rx->ifindex > 0, -EINVAL); - if (lldp_rx->fd >= 0) + if (sd_lldp_rx_is_running(lldp_rx)) return 0; assert(!lldp_rx->io_event_source); @@ -277,10 +284,7 @@ fail: } _public_ int sd_lldp_rx_stop(sd_lldp_rx *lldp_rx) { - if (!lldp_rx) - return 0; - - if (lldp_rx->fd < 0) + if (!sd_lldp_rx_is_running(lldp_rx)) return 0; log_lldp_rx(lldp_rx, "Stopping LLDP client"); @@ -295,7 +299,7 @@ _public_ int sd_lldp_rx_attach_event(sd_lldp_rx *lldp_rx, sd_event *event, int64 int r; assert_return(lldp_rx, -EINVAL); - assert_return(lldp_rx->fd < 0, -EBUSY); + assert_return(!sd_lldp_rx_is_running(lldp_rx), -EBUSY); assert_return(!lldp_rx->event, -EBUSY); if (event) @@ -312,9 +316,8 @@ _public_ int sd_lldp_rx_attach_event(sd_lldp_rx *lldp_rx, sd_event *event, int64 } _public_ int sd_lldp_rx_detach_event(sd_lldp_rx *lldp_rx) { - assert_return(lldp_rx, -EINVAL); - assert_return(lldp_rx->fd < 0, -EBUSY); + assert_return(!sd_lldp_rx_is_running(lldp_rx), -EBUSY); lldp_rx->event = sd_event_unref(lldp_rx->event); return 0; @@ -338,7 +341,7 @@ _public_ int sd_lldp_rx_set_callback(sd_lldp_rx *lldp_rx, sd_lldp_rx_callback_t _public_ int sd_lldp_rx_set_ifindex(sd_lldp_rx *lldp_rx, int ifindex) { assert_return(lldp_rx, -EINVAL); assert_return(ifindex > 0, -EINVAL); - assert_return(lldp_rx->fd < 0, -EBUSY); + assert_return(!sd_lldp_rx_is_running(lldp_rx), -EBUSY); lldp_rx->ifindex = ifindex; return 0; diff --git a/src/systemd/sd-lldp-rx.h b/src/systemd/sd-lldp-rx.h index 060c677f3d..4653626eee 100644 --- a/src/systemd/sd-lldp-rx.h +++ b/src/systemd/sd-lldp-rx.h @@ -50,6 +50,7 @@ sd_lldp_rx *sd_lldp_rx_unref(sd_lldp_rx *lldp_rx); int sd_lldp_rx_start(sd_lldp_rx *lldp_rx); int sd_lldp_rx_stop(sd_lldp_rx *lldp_rx); +int sd_lldp_rx_is_running(sd_lldp_rx *lldp_rx); int sd_lldp_rx_attach_event(sd_lldp_rx *lldp_rx, sd_event *event, int64_t priority); int sd_lldp_rx_detach_event(sd_lldp_rx *lldp_rx); From e9ea43136cab8f95075869657cf8736e33699252 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:01:06 +0900 Subject: [PATCH 03/12] sd-lldp-rx: add comments about the three multicast addresses --- src/libsystemd-network/lldp-network.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libsystemd-network/lldp-network.c b/src/libsystemd-network/lldp-network.c index 43141b2d79..d11af3ebbb 100644 --- a/src/libsystemd-network/lldp-network.c +++ b/src/libsystemd-network/lldp-network.c @@ -56,15 +56,18 @@ int lldp_network_bind_raw_socket(int ifindex) { if (r < 0) return -errno; + /* customer bridge */ r = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (r < 0) return -errno; + /* non TPMR bridge */ mreq.mr_address[ETH_ALEN - 1] = 0x03; r = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (r < 0) return -errno; + /* nearest bridge */ mreq.mr_address[ETH_ALEN - 1] = 0x0E; r = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (r < 0) From aa3f8d4ca133dbd43598967e68257b5e93789f92 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 14:55:06 +0900 Subject: [PATCH 04/12] sd-lldp-rx: ensure no event will be triggered after sd_lldp_rx_detach_event() is called --- src/libsystemd-network/sd-lldp-rx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 21b538a930..54e8dd8779 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -319,6 +319,8 @@ _public_ int sd_lldp_rx_detach_event(sd_lldp_rx *lldp_rx) { assert_return(lldp_rx, -EINVAL); assert_return(!sd_lldp_rx_is_running(lldp_rx), -EBUSY); + lldp_rx->io_event_source = sd_event_source_disable_unref(lldp_rx->io_event_source); + lldp_rx->timer_event_source = sd_event_source_disable_unref(lldp_rx->timer_event_source); lldp_rx->event = sd_event_unref(lldp_rx->event); return 0; } @@ -369,7 +371,6 @@ static sd_lldp_rx *lldp_rx_free(sd_lldp_rx *lldp_rx) { lldp_rx_reset(lldp_rx); - sd_event_source_unref(lldp_rx->timer_event_source); sd_lldp_rx_detach_event(lldp_rx); lldp_rx_flush_neighbors(lldp_rx); From 5bff20ea62706b05f599e915da0a5934bd520d0c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:14:50 +0900 Subject: [PATCH 05/12] prioq: introduce prioq_ensure_put() --- src/basic/prioq.c | 10 ++++++++++ src/basic/prioq.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/basic/prioq.c b/src/basic/prioq.c index 559e5d124d..c15dcb26af 100644 --- a/src/basic/prioq.c +++ b/src/basic/prioq.c @@ -173,6 +173,16 @@ int prioq_put(Prioq *q, void *data, unsigned *idx) { return 0; } +int prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx) { + int r; + + r = prioq_ensure_allocated(q, compare_func); + if (r < 0) + return r; + + return prioq_put(*q, data, idx); +} + static void remove_item(Prioq *q, struct prioq_item *i) { struct prioq_item *l; diff --git a/src/basic/prioq.h b/src/basic/prioq.h index 7c76647611..508db88026 100644 --- a/src/basic/prioq.h +++ b/src/basic/prioq.h @@ -16,6 +16,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Prioq*, prioq_free); int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func); int prioq_put(Prioq *q, void *data, unsigned *idx); +int prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx); int prioq_remove(Prioq *q, void *data, unsigned *idx); int prioq_reshuffle(Prioq *q, void *data, unsigned *idx); From b0a67b202dd9cbfb40a670ff64e60c3019cb5f4c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:19:39 +0900 Subject: [PATCH 06/12] sd-lldp-rx: delay allocating hashmap and prioq to store neighbors --- src/libsystemd-network/sd-lldp-rx.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 54e8dd8779..78a297b68f 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -147,11 +147,11 @@ static int lldp_rx_add_neighbor(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *n) { /* Then, make room for at least one new neighbor */ lldp_rx_make_space(lldp_rx, 1); - r = hashmap_put(lldp_rx->neighbor_by_id, &n->id, n); + r = hashmap_ensure_put(&lldp_rx->neighbor_by_id, &lldp_neighbor_hash_ops, &n->id, n); if (r < 0) goto finish; - r = prioq_put(lldp_rx->neighbor_by_expiry, n, &n->prioq_idx); + r = prioq_ensure_put(&lldp_rx->neighbor_by_expiry, lldp_neighbor_prioq_compare_func, n, &n->prioq_idx); if (r < 0) { assert_se(hashmap_remove(lldp_rx->neighbor_by_id, &n->id) == n); goto finish; @@ -385,7 +385,6 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_lldp_rx, sd_lldp_rx, lldp_rx_free); _public_ int sd_lldp_rx_new(sd_lldp_rx **ret) { _cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL; - int r; assert_return(ret, -EINVAL); @@ -400,16 +399,7 @@ _public_ int sd_lldp_rx_new(sd_lldp_rx **ret) { .capability_mask = UINT16_MAX, }; - lldp_rx->neighbor_by_id = hashmap_new(&lldp_neighbor_hash_ops); - if (!lldp_rx->neighbor_by_id) - return -ENOMEM; - - r = prioq_ensure_allocated(&lldp_rx->neighbor_by_expiry, lldp_neighbor_prioq_compare_func); - if (r < 0) - return r; - *ret = TAKE_PTR(lldp_rx); - return 0; } From 90496cc68c21be8f891da3f742b6da32a0fafc22 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:29:07 +0900 Subject: [PATCH 07/12] sd-lldp-rx: add missing assertions --- src/libsystemd-network/lldp-neighbor.c | 9 +++++++++ src/libsystemd-network/sd-lldp-rx.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 342e490603..3ee8969e59 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -11,6 +11,9 @@ #include "unaligned.h" static void lldp_neighbor_id_hash_func(const LLDPNeighborID *id, struct siphash *state) { + assert(id); + assert(state); + siphash24_compress(id->chassis_id, id->chassis_id_size, state); siphash24_compress(&id->chassis_id_size, sizeof(id->chassis_id_size), state); siphash24_compress(id->port_id, id->port_id_size, state); @@ -18,6 +21,9 @@ static void lldp_neighbor_id_hash_func(const LLDPNeighborID *id, struct siphash } int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y) { + assert(x); + assert(y); + return memcmp_nn(x->chassis_id, x->chassis_id_size, y->chassis_id, y->chassis_id_size) ?: memcmp_nn(x->port_id, x->port_id_size, y->port_id, y->port_id_size); } @@ -28,6 +34,9 @@ DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(lldp_neighbor_hash_ops, LLDPNeighborID, ll int lldp_neighbor_prioq_compare_func(const void *a, const void *b) { const sd_lldp_neighbor *x = a, *y = b; + assert(x); + assert(y); + return CMP(x->until, y->until); } diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 78a297b68f..fd3097b26b 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -403,10 +403,6 @@ _public_ int sd_lldp_rx_new(sd_lldp_rx **ret) { return 0; } -static int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) { - return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); -} - static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) { sd_lldp_rx *lldp_rx = userdata; int r; @@ -448,6 +444,15 @@ static int lldp_rx_start_timer(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *neighbor) lldp_rx->event_priority, "lldp-rx-timer", true); } +static inline int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) { + assert(a); + assert(b); + assert(*a); + assert(*b); + + return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); +} + _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { sd_lldp_neighbor **l = NULL, *n; int k = 0, r; From 71c4f7e8958d9ee82e030a21738dde3d89cc0b10 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:29:27 +0900 Subject: [PATCH 08/12] sd-lldp-rx: wrap long line --- src/libsystemd-network/lldp-neighbor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 3ee8969e59..4ae78d25df 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -28,8 +28,13 @@ int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID ?: memcmp_nn(x->port_id, x->port_id_size, y->port_id, y->port_id_size); } -DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(lldp_neighbor_hash_ops, LLDPNeighborID, lldp_neighbor_id_hash_func, lldp_neighbor_id_compare_func, - sd_lldp_neighbor, lldp_neighbor_unlink); +DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + lldp_neighbor_hash_ops, + LLDPNeighborID, + lldp_neighbor_id_hash_func, + lldp_neighbor_id_compare_func, + sd_lldp_neighbor, + lldp_neighbor_unlink); int lldp_neighbor_prioq_compare_func(const void *a, const void *b) { const sd_lldp_neighbor *x = a, *y = b; From 0cd7e072b466b8ad4e4d315ffbec89682b0d23a1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:30:52 +0900 Subject: [PATCH 09/12] sd-lldp-rx: use _cleanup_ attribute at one more place --- src/libsystemd-network/sd-lldp-rx.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index fd3097b26b..bf544a5e3a 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -454,7 +454,8 @@ static inline int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_nei } _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { - sd_lldp_neighbor **l = NULL, *n; + _cleanup_free_ sd_lldp_neighbor **l = NULL; + sd_lldp_neighbor *n; int k = 0, r; assert_return(lldp_rx, -EINVAL); @@ -470,10 +471,8 @@ _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***r return -ENOMEM; r = lldp_rx_start_timer(lldp_rx, NULL); - if (r < 0) { - free(l); + if (r < 0) return r; - } HASHMAP_FOREACH(n, lldp_rx->neighbor_by_id) l[k++] = sd_lldp_neighbor_ref(n); @@ -482,7 +481,7 @@ _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***r /* Return things in a stable order */ typesafe_qsort(l, k, neighbor_compare_func); - *ret = l; + *ret = TAKE_PTR(l); return k; } From 3e4a2025195b85beec4824b7285516b57ad34eab Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:38:50 +0900 Subject: [PATCH 10/12] sd-lldp-rx: do not enable timer event source in sd_lldp_rx_get_neighbors() It must be just a simple getter. --- src/libsystemd-network/sd-lldp-rx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index bf544a5e3a..af4bd62762 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -456,7 +456,7 @@ static inline int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_nei _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { _cleanup_free_ sd_lldp_neighbor **l = NULL; sd_lldp_neighbor *n; - int k = 0, r; + int k = 0; assert_return(lldp_rx, -EINVAL); assert_return(ret, -EINVAL); @@ -470,10 +470,6 @@ _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***r if (!l) return -ENOMEM; - r = lldp_rx_start_timer(lldp_rx, NULL); - if (r < 0) - return r; - HASHMAP_FOREACH(n, lldp_rx->neighbor_by_id) l[k++] = sd_lldp_neighbor_ref(n); From 92466b8da2d868cabf6237fe0f6a8e8151a4cebf Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:41:19 +0900 Subject: [PATCH 11/12] sd-lldp-rx: sd_event should be attached when lldp_rx_start_timer() is called --- src/libsystemd-network/sd-lldp-rx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index af4bd62762..05dec99d51 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -426,6 +426,7 @@ static int lldp_rx_start_timer(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *neighbor) sd_lldp_neighbor *n; assert(lldp_rx); + assert(lldp_rx->event); if (neighbor) lldp_neighbor_start_ttl(neighbor); @@ -434,9 +435,6 @@ static int lldp_rx_start_timer(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *neighbor) if (!n) return event_source_disable(lldp_rx->timer_event_source); - if (!lldp_rx->event) - return 0; - return event_reset_time(lldp_rx->event, &lldp_rx->timer_event_source, clock_boottime_or_monotonic(), n->until, 0, From 35777f517883a9324e94a6c201f4eb36b14ff1c8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 28 Sep 2021 15:51:59 +0900 Subject: [PATCH 12/12] sd-lldp-rx: make lldp_rx_free() and lldp_neighbor_free() accept NULL --- src/libsystemd-network/lldp-neighbor.c | 7 ++++--- src/libsystemd-network/sd-lldp-rx.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 4ae78d25df..48c2142b1e 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -55,8 +55,9 @@ _public_ sd_lldp_neighbor *sd_lldp_neighbor_ref(sd_lldp_neighbor *n) { return n; } -static void lldp_neighbor_free(sd_lldp_neighbor *n) { - assert(n); +static sd_lldp_neighbor *lldp_neighbor_free(sd_lldp_neighbor *n) { + if (!n) + return NULL; free(n->id.port_id); free(n->id.chassis_id); @@ -66,7 +67,7 @@ static void lldp_neighbor_free(sd_lldp_neighbor *n) { free(n->mud_url); free(n->chassis_id_as_string); free(n->port_id_as_string); - free(n); + return mfree(n); } _public_ sd_lldp_neighbor *sd_lldp_neighbor_unref(sd_lldp_neighbor *n) { diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 05dec99d51..98bde8b306 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -367,7 +367,8 @@ const char *sd_lldp_rx_get_ifname(sd_lldp_rx *lldp_rx) { } static sd_lldp_rx *lldp_rx_free(sd_lldp_rx *lldp_rx) { - assert(lldp_rx); + if (!lldp_rx) + return NULL; lldp_rx_reset(lldp_rx);