]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
ad1ad5c8 SS |
2 | |
3 | #include <arpa/inet.h> | |
284d1cd0 | 4 | #include <linux/sockios.h> |
ef118d00 | 5 | #include <sys/ioctl.h> |
ad1ad5c8 | 6 | |
ad1ad5c8 | 7 | #include "sd-lldp.h" |
07630cea | 8 | |
b5efdb8a | 9 | #include "alloc-util.h" |
4f0e4d29 | 10 | #include "ether-addr-util.h" |
6ec11d46 | 11 | #include "event-util.h" |
3ffd4af2 | 12 | #include "fd-util.h" |
ad1ad5c8 | 13 | #include "lldp-internal.h" |
34437b4f | 14 | #include "lldp-neighbor.h" |
032b27f5 | 15 | #include "lldp-network.h" |
0a970718 | 16 | #include "memory-util.h" |
34437b4f | 17 | #include "socket-util.h" |
760877e9 | 18 | #include "sort-util.h" |
4f0e4d29 | 19 | #include "string-table.h" |
49699bac | 20 | |
34437b4f | 21 | #define LLDP_DEFAULT_NEIGHBORS_MAX 128U |
032b27f5 | 22 | |
4f0e4d29 YW |
23 | static const char * const lldp_event_table[_SD_LLDP_EVENT_MAX] = { |
24 | [SD_LLDP_EVENT_ADDED] = "added", | |
25 | [SD_LLDP_EVENT_REMOVED] = "removed", | |
26 | [SD_LLDP_EVENT_UPDATED] = "updated", | |
27 | [SD_LLDP_EVENT_REFRESHED] = "refreshed", | |
28 | }; | |
29 | ||
30 | DEFINE_STRING_TABLE_LOOKUP(lldp_event, sd_lldp_event); | |
31 | ||
34437b4f | 32 | static void lldp_flush_neighbors(sd_lldp *lldp) { |
ad1ad5c8 | 33 | assert(lldp); |
ad1ad5c8 | 34 | |
8276855e | 35 | hashmap_clear(lldp->neighbor_by_id); |
ad1ad5c8 SS |
36 | } |
37 | ||
90dffb22 LP |
38 | static void lldp_callback(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n) { |
39 | assert(lldp); | |
4f0e4d29 | 40 | assert(event >= 0 && event < _SD_LLDP_EVENT_MAX); |
90dffb22 | 41 | |
4f0e4d29 YW |
42 | if (!lldp->callback) { |
43 | log_lldp("Received '%s' event.", lldp_event_to_string(event)); | |
90dffb22 | 44 | return; |
4f0e4d29 | 45 | } |
90dffb22 | 46 | |
4f0e4d29 | 47 | log_lldp("Invoking callback for '%s' event.", lldp_event_to_string(event)); |
90dffb22 LP |
48 | lldp->callback(lldp, event, n, lldp->userdata); |
49 | } | |
50 | ||
34437b4f | 51 | static int lldp_make_space(sd_lldp *lldp, size_t extra) { |
34437b4f LP |
52 | usec_t t = USEC_INFINITY; |
53 | bool changed = false; | |
ad1ad5c8 | 54 | |
34437b4f | 55 | assert(lldp); |
ad1ad5c8 | 56 | |
34437b4f LP |
57 | /* Remove all entries that are past their TTL, and more until at least the specified number of extra entries |
58 | * are free. */ | |
ad1ad5c8 | 59 | |
34437b4f | 60 | for (;;) { |
90dffb22 LP |
61 | _cleanup_(sd_lldp_neighbor_unrefp) sd_lldp_neighbor *n = NULL; |
62 | ||
34437b4f LP |
63 | n = prioq_peek(lldp->neighbor_by_expiry); |
64 | if (!n) | |
859c37b1 | 65 | break; |
859c37b1 | 66 | |
90dffb22 LP |
67 | sd_lldp_neighbor_ref(n); |
68 | ||
34437b4f LP |
69 | if (hashmap_size(lldp->neighbor_by_id) > LESS_BY(lldp->neighbors_max, extra)) |
70 | goto remove_one; | |
859c37b1 | 71 | |
34437b4f LP |
72 | if (t == USEC_INFINITY) |
73 | t = now(clock_boottime_or_monotonic()); | |
859c37b1 | 74 | |
34437b4f | 75 | if (n->until > t) |
859c37b1 | 76 | break; |
859c37b1 | 77 | |
34437b4f LP |
78 | remove_one: |
79 | lldp_neighbor_unlink(n); | |
90dffb22 | 80 | lldp_callback(lldp, SD_LLDP_EVENT_REMOVED, n); |
34437b4f LP |
81 | changed = true; |
82 | } | |
859c37b1 | 83 | |
34437b4f LP |
84 | return changed; |
85 | } | |
ad1ad5c8 | 86 | |
90dffb22 LP |
87 | static bool lldp_keep_neighbor(sd_lldp *lldp, sd_lldp_neighbor *n) { |
88 | assert(lldp); | |
89 | assert(n); | |
90 | ||
91 | /* Don't keep data with a zero TTL */ | |
92 | if (n->ttl <= 0) | |
93 | return false; | |
94 | ||
95 | /* Filter out data from the filter address */ | |
96 | if (!ether_addr_is_null(&lldp->filter_address) && | |
97 | ether_addr_equal(&lldp->filter_address, &n->source_address)) | |
98 | return false; | |
99 | ||
100 | /* Only add if the neighbor has a capability we are interested in. Note that we also store all neighbors with | |
101 | * no caps field set. */ | |
102 | if (n->has_capabilities && | |
103 | (n->enabled_capabilities & lldp->capability_mask) == 0) | |
104 | return false; | |
105 | ||
106 | /* Keep everything else */ | |
107 | return true; | |
108 | } | |
109 | ||
0513ea4e TH |
110 | static int lldp_start_timer(sd_lldp *lldp, sd_lldp_neighbor *neighbor); |
111 | ||
34437b4f | 112 | static int lldp_add_neighbor(sd_lldp *lldp, sd_lldp_neighbor *n) { |
90dffb22 LP |
113 | _cleanup_(sd_lldp_neighbor_unrefp) sd_lldp_neighbor *old = NULL; |
114 | bool keep; | |
34437b4f | 115 | int r; |
ad1ad5c8 | 116 | |
34437b4f LP |
117 | assert(lldp); |
118 | assert(n); | |
119 | assert(!n->lldp); | |
120 | ||
90dffb22 LP |
121 | keep = lldp_keep_neighbor(lldp, n); |
122 | ||
34437b4f LP |
123 | /* First retrieve the old entry for this MSAP */ |
124 | old = hashmap_get(lldp->neighbor_by_id, &n->id); | |
125 | if (old) { | |
90dffb22 LP |
126 | sd_lldp_neighbor_ref(old); |
127 | ||
128 | if (!keep) { | |
129 | lldp_neighbor_unlink(old); | |
130 | lldp_callback(lldp, SD_LLDP_EVENT_REMOVED, old); | |
131 | return 0; | |
132 | } | |
133 | ||
34437b4f | 134 | if (lldp_neighbor_equal(n, old)) { |
f21f31b2 | 135 | /* Is this equal, then restart the TTL counter, but don't do anything else. */ |
16fed825 | 136 | old->timestamp = n->timestamp; |
0513ea4e | 137 | lldp_start_timer(lldp, old); |
90dffb22 | 138 | lldp_callback(lldp, SD_LLDP_EVENT_REFRESHED, old); |
34437b4f | 139 | return 0; |
ad1ad5c8 | 140 | } |
34437b4f LP |
141 | |
142 | /* Data changed, remove the old entry, and add a new one */ | |
143 | lldp_neighbor_unlink(old); | |
ad1ad5c8 | 144 | |
90dffb22 LP |
145 | } else if (!keep) |
146 | return 0; | |
ad1ad5c8 | 147 | |
34437b4f LP |
148 | /* Then, make room for at least one new neighbor */ |
149 | lldp_make_space(lldp, 1); | |
ad1ad5c8 | 150 | |
34437b4f LP |
151 | r = hashmap_put(lldp->neighbor_by_id, &n->id, n); |
152 | if (r < 0) | |
90dffb22 | 153 | goto finish; |
ad1ad5c8 | 154 | |
34437b4f LP |
155 | r = prioq_put(lldp->neighbor_by_expiry, n, &n->prioq_idx); |
156 | if (r < 0) { | |
157 | assert_se(hashmap_remove(lldp->neighbor_by_id, &n->id) == n); | |
90dffb22 | 158 | goto finish; |
ad1ad5c8 SS |
159 | } |
160 | ||
34437b4f | 161 | n->lldp = lldp; |
ad1ad5c8 | 162 | |
0513ea4e | 163 | lldp_start_timer(lldp, n); |
90dffb22 LP |
164 | lldp_callback(lldp, old ? SD_LLDP_EVENT_UPDATED : SD_LLDP_EVENT_ADDED, n); |
165 | ||
166 | return 1; | |
167 | ||
168 | finish: | |
169 | if (old) | |
35ad2cd7 | 170 | lldp_callback(lldp, SD_LLDP_EVENT_REMOVED, old); |
90dffb22 LP |
171 | |
172 | return r; | |
ad1ad5c8 SS |
173 | } |
174 | ||
34437b4f LP |
175 | static int lldp_handle_datagram(sd_lldp *lldp, sd_lldp_neighbor *n) { |
176 | int r; | |
ad1ad5c8 | 177 | |
34437b4f LP |
178 | assert(lldp); |
179 | assert(n); | |
ad1ad5c8 | 180 | |
34437b4f LP |
181 | r = lldp_neighbor_parse(n); |
182 | if (r == -EBADMSG) /* Ignore bad messages */ | |
183 | return 0; | |
184 | if (r < 0) | |
185 | return r; | |
ad1ad5c8 | 186 | |
34437b4f LP |
187 | r = lldp_add_neighbor(lldp, n); |
188 | if (r < 0) { | |
189 | log_lldp_errno(r, "Failed to add datagram. Ignoring."); | |
190 | return 0; | |
ad1ad5c8 | 191 | } |
ad1ad5c8 | 192 | |
34437b4f | 193 | log_lldp("Successfully processed LLDP datagram."); |
34437b4f | 194 | return 0; |
ad1ad5c8 SS |
195 | } |
196 | ||
34437b4f LP |
197 | static int lldp_receive_datagram(sd_event_source *s, int fd, uint32_t revents, void *userdata) { |
198 | _cleanup_(sd_lldp_neighbor_unrefp) sd_lldp_neighbor *n = NULL; | |
199 | ssize_t space, length; | |
200 | sd_lldp *lldp = userdata; | |
16fed825 | 201 | struct timespec ts; |
49699bac | 202 | |
34437b4f | 203 | assert(fd >= 0); |
49699bac | 204 | assert(lldp); |
49699bac | 205 | |
34437b4f LP |
206 | space = next_datagram_size_fd(fd); |
207 | if (space < 0) | |
208 | return log_lldp_errno(space, "Failed to determine datagram size to read: %m"); | |
49699bac | 209 | |
34437b4f LP |
210 | n = lldp_neighbor_new(space); |
211 | if (!n) | |
212 | return -ENOMEM; | |
49699bac | 213 | |
34437b4f | 214 | length = recv(fd, LLDP_NEIGHBOR_RAW(n), n->raw_size, MSG_DONTWAIT); |
f3315c58 | 215 | if (length < 0) { |
4c701096 | 216 | if (IN_SET(errno, EAGAIN, EINTR)) |
f3315c58 LP |
217 | return 0; |
218 | ||
34437b4f | 219 | return log_lldp_errno(errno, "Failed to read LLDP datagram: %m"); |
f3315c58 | 220 | } |
dacd6cee | 221 | |
34437b4f LP |
222 | if ((size_t) length != n->raw_size) { |
223 | log_lldp("Packet size mismatch."); | |
224 | return -EINVAL; | |
225 | } | |
49699bac | 226 | |
16fed825 LP |
227 | /* Try to get the timestamp of this packet if it is known */ |
228 | if (ioctl(fd, SIOCGSTAMPNS, &ts) >= 0) | |
229 | triple_timestamp_from_realtime(&n->timestamp, timespec_load(&ts)); | |
230 | else | |
231 | triple_timestamp_get(&n->timestamp); | |
232 | ||
34437b4f | 233 | return lldp_handle_datagram(lldp, n); |
49699bac SS |
234 | } |
235 | ||
fc6a313b LP |
236 | static void lldp_reset(sd_lldp *lldp) { |
237 | assert(lldp); | |
238 | ||
6ec11d46 | 239 | (void) event_source_disable(lldp->timer_event_source); |
fc6a313b LP |
240 | lldp->io_event_source = sd_event_source_unref(lldp->io_event_source); |
241 | lldp->fd = safe_close(lldp->fd); | |
242 | } | |
243 | ||
34437b4f | 244 | _public_ int sd_lldp_start(sd_lldp *lldp) { |
ad1ad5c8 SS |
245 | int r; |
246 | ||
247 | assert_return(lldp, -EINVAL); | |
fc6a313b LP |
248 | assert_return(lldp->event, -EINVAL); |
249 | assert_return(lldp->ifindex > 0, -EINVAL); | |
ad1ad5c8 | 250 | |
032b27f5 LP |
251 | if (lldp->fd >= 0) |
252 | return 0; | |
ad1ad5c8 | 253 | |
34437b4f | 254 | assert(!lldp->io_event_source); |
49699bac | 255 | |
032b27f5 LP |
256 | lldp->fd = lldp_network_bind_raw_socket(lldp->ifindex); |
257 | if (lldp->fd < 0) | |
258 | return lldp->fd; | |
259 | ||
fc6a313b LP |
260 | r = sd_event_add_io(lldp->event, &lldp->io_event_source, lldp->fd, EPOLLIN, lldp_receive_datagram, lldp); |
261 | if (r < 0) | |
262 | goto fail; | |
032b27f5 | 263 | |
fc6a313b LP |
264 | r = sd_event_source_set_priority(lldp->io_event_source, lldp->event_priority); |
265 | if (r < 0) | |
266 | goto fail; | |
032b27f5 | 267 | |
fc6a313b | 268 | (void) sd_event_source_set_description(lldp->io_event_source, "lldp-io"); |
ad1ad5c8 | 269 | |
fc6a313b | 270 | log_lldp("Started LLDP client"); |
032b27f5 LP |
271 | return 1; |
272 | ||
273 | fail: | |
fc6a313b | 274 | lldp_reset(lldp); |
032b27f5 | 275 | return r; |
ad1ad5c8 SS |
276 | } |
277 | ||
34437b4f | 278 | _public_ int sd_lldp_stop(sd_lldp *lldp) { |
ad1ad5c8 | 279 | assert_return(lldp, -EINVAL); |
ad1ad5c8 | 280 | |
032b27f5 LP |
281 | if (lldp->fd < 0) |
282 | return 0; | |
ad1ad5c8 | 283 | |
fc6a313b | 284 | log_lldp("Stopping LLDP client"); |
ad1ad5c8 | 285 | |
fc6a313b | 286 | lldp_reset(lldp); |
34437b4f | 287 | lldp_flush_neighbors(lldp); |
ad1ad5c8 | 288 | |
032b27f5 | 289 | return 1; |
ad1ad5c8 SS |
290 | } |
291 | ||
34437b4f | 292 | _public_ int sd_lldp_attach_event(sd_lldp *lldp, sd_event *event, int64_t priority) { |
ad1ad5c8 SS |
293 | int r; |
294 | ||
295 | assert_return(lldp, -EINVAL); | |
032b27f5 LP |
296 | assert_return(lldp->fd < 0, -EBUSY); |
297 | assert_return(!lldp->event, -EBUSY); | |
ad1ad5c8 SS |
298 | |
299 | if (event) | |
032b27f5 | 300 | lldp->event = sd_event_ref(event); |
ad1ad5c8 | 301 | else { |
032b27f5 | 302 | r = sd_event_default(&lldp->event); |
ad1ad5c8 SS |
303 | if (r < 0) |
304 | return r; | |
305 | } | |
306 | ||
032b27f5 | 307 | lldp->event_priority = priority; |
ad1ad5c8 SS |
308 | |
309 | return 0; | |
310 | } | |
311 | ||
34437b4f | 312 | _public_ int sd_lldp_detach_event(sd_lldp *lldp) { |
ad1ad5c8 SS |
313 | |
314 | assert_return(lldp, -EINVAL); | |
032b27f5 | 315 | assert_return(lldp->fd < 0, -EBUSY); |
ad1ad5c8 | 316 | |
032b27f5 | 317 | lldp->event = sd_event_unref(lldp->event); |
ad1ad5c8 SS |
318 | return 0; |
319 | } | |
320 | ||
3db2ec56 LP |
321 | _public_ sd_event* sd_lldp_get_event(sd_lldp *lldp) { |
322 | assert_return(lldp, NULL); | |
323 | ||
324 | return lldp->event; | |
325 | } | |
326 | ||
34437b4f | 327 | _public_ int sd_lldp_set_callback(sd_lldp *lldp, sd_lldp_callback_t cb, void *userdata) { |
49699bac SS |
328 | assert_return(lldp, -EINVAL); |
329 | ||
ccf86354 | 330 | lldp->callback = cb; |
49699bac SS |
331 | lldp->userdata = userdata; |
332 | ||
333 | return 0; | |
334 | } | |
335 | ||
fc6a313b LP |
336 | _public_ int sd_lldp_set_ifindex(sd_lldp *lldp, int ifindex) { |
337 | assert_return(lldp, -EINVAL); | |
338 | assert_return(ifindex > 0, -EINVAL); | |
339 | assert_return(lldp->fd < 0, -EBUSY); | |
340 | ||
341 | lldp->ifindex = ifindex; | |
342 | return 0; | |
343 | } | |
344 | ||
8301aa0b YW |
345 | static sd_lldp* lldp_free(sd_lldp *lldp) { |
346 | assert(lldp); | |
fc6a313b | 347 | |
6ec11d46 YW |
348 | lldp->timer_event_source = sd_event_source_unref(lldp->timer_event_source); |
349 | ||
fc6a313b LP |
350 | lldp_reset(lldp); |
351 | sd_lldp_detach_event(lldp); | |
34437b4f | 352 | lldp_flush_neighbors(lldp); |
ad1ad5c8 | 353 | |
34437b4f LP |
354 | hashmap_free(lldp->neighbor_by_id); |
355 | prioq_free(lldp->neighbor_by_expiry); | |
6b430fdb | 356 | return mfree(lldp); |
ad1ad5c8 SS |
357 | } |
358 | ||
8301aa0b YW |
359 | DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_lldp, sd_lldp, lldp_free); |
360 | ||
fc6a313b | 361 | _public_ int sd_lldp_new(sd_lldp **ret) { |
4afd3348 | 362 | _cleanup_(sd_lldp_unrefp) sd_lldp *lldp = NULL; |
ad1ad5c8 SS |
363 | int r; |
364 | ||
365 | assert_return(ret, -EINVAL); | |
ad1ad5c8 | 366 | |
8158b90d | 367 | lldp = new(sd_lldp, 1); |
ad1ad5c8 SS |
368 | if (!lldp) |
369 | return -ENOMEM; | |
370 | ||
8158b90d YW |
371 | *lldp = (sd_lldp) { |
372 | .n_ref = 1, | |
373 | .fd = -1, | |
374 | .neighbors_max = LLDP_DEFAULT_NEIGHBORS_MAX, | |
375 | .capability_mask = (uint16_t) -1, | |
376 | }; | |
ad1ad5c8 | 377 | |
8276855e | 378 | lldp->neighbor_by_id = hashmap_new(&lldp_neighbor_hash_ops); |
34437b4f | 379 | if (!lldp->neighbor_by_id) |
ad1ad5c8 SS |
380 | return -ENOMEM; |
381 | ||
34437b4f | 382 | r = prioq_ensure_allocated(&lldp->neighbor_by_expiry, lldp_neighbor_prioq_compare_func); |
ad1ad5c8 SS |
383 | if (r < 0) |
384 | return r; | |
385 | ||
1cc6c93a | 386 | *ret = TAKE_PTR(lldp); |
ad1ad5c8 SS |
387 | |
388 | return 0; | |
389 | } | |
7434883c | 390 | |
93bab288 | 391 | static int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) { |
dc5f9c6f | 392 | return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); |
34437b4f LP |
393 | } |
394 | ||
34437b4f LP |
395 | static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) { |
396 | sd_lldp *lldp = userdata; | |
bb1d9534 | 397 | int r; |
34437b4f LP |
398 | |
399 | r = lldp_make_space(lldp, 0); | |
400 | if (r < 0) | |
401 | return log_lldp_errno(r, "Failed to make space: %m"); | |
402 | ||
bb1d9534 ZJS |
403 | r = lldp_start_timer(lldp, NULL); |
404 | if (r < 0) | |
405 | return log_lldp_errno(r, "Failed to restart timer: %m"); | |
34437b4f | 406 | |
34437b4f LP |
407 | return 0; |
408 | } | |
7434883c | 409 | |
0513ea4e | 410 | static int lldp_start_timer(sd_lldp *lldp, sd_lldp_neighbor *neighbor) { |
34437b4f | 411 | sd_lldp_neighbor *n; |
34437b4f LP |
412 | |
413 | assert(lldp); | |
414 | ||
0513ea4e TH |
415 | if (neighbor) |
416 | lldp_neighbor_start_ttl(neighbor); | |
417 | ||
34437b4f | 418 | n = prioq_peek(lldp->neighbor_by_expiry); |
6ec11d46 YW |
419 | if (!n) |
420 | return event_source_disable(lldp->timer_event_source); | |
7434883c | 421 | |
34437b4f LP |
422 | if (!lldp->event) |
423 | return 0; | |
424 | ||
6ec11d46 YW |
425 | return event_reset_time(lldp->event, &lldp->timer_event_source, |
426 | clock_boottime_or_monotonic(), | |
427 | n->until, 0, | |
428 | on_timer_event, lldp, | |
429 | lldp->event_priority, "lldp-timer", true); | |
34437b4f LP |
430 | } |
431 | ||
432 | _public_ int sd_lldp_get_neighbors(sd_lldp *lldp, sd_lldp_neighbor ***ret) { | |
433 | sd_lldp_neighbor **l = NULL, *n; | |
434 | Iterator i; | |
435 | int k = 0, r; | |
436 | ||
437 | assert_return(lldp, -EINVAL); | |
438 | assert_return(ret, -EINVAL); | |
439 | ||
34437b4f LP |
440 | if (hashmap_isempty(lldp->neighbor_by_id)) { /* Special shortcut */ |
441 | *ret = NULL; | |
7434883c BG |
442 | return 0; |
443 | } | |
444 | ||
34437b4f LP |
445 | l = new0(sd_lldp_neighbor*, hashmap_size(lldp->neighbor_by_id)); |
446 | if (!l) | |
7434883c BG |
447 | return -ENOMEM; |
448 | ||
0513ea4e | 449 | r = lldp_start_timer(lldp, NULL); |
34437b4f LP |
450 | if (r < 0) { |
451 | free(l); | |
452 | return r; | |
7434883c BG |
453 | } |
454 | ||
34437b4f LP |
455 | HASHMAP_FOREACH(n, lldp->neighbor_by_id, i) |
456 | l[k++] = sd_lldp_neighbor_ref(n); | |
457 | ||
458 | assert((size_t) k == hashmap_size(lldp->neighbor_by_id)); | |
459 | ||
460 | /* Return things in a stable order */ | |
93bab288 | 461 | typesafe_qsort(l, k, neighbor_compare_func); |
34437b4f LP |
462 | *ret = l; |
463 | ||
464 | return k; | |
465 | } | |
466 | ||
467 | _public_ int sd_lldp_set_neighbors_max(sd_lldp *lldp, uint64_t m) { | |
468 | assert_return(lldp, -EINVAL); | |
469 | assert_return(m <= 0, -EINVAL); | |
470 | ||
471 | lldp->neighbors_max = m; | |
472 | lldp_make_space(lldp, 0); | |
473 | ||
474 | return 0; | |
475 | } | |
476 | ||
477 | _public_ int sd_lldp_match_capabilities(sd_lldp *lldp, uint16_t mask) { | |
478 | assert_return(lldp, -EINVAL); | |
479 | assert_return(mask != 0, -EINVAL); | |
480 | ||
481 | lldp->capability_mask = mask; | |
482 | ||
483 | return 0; | |
7434883c | 484 | } |
b553a6b1 LP |
485 | |
486 | _public_ int sd_lldp_set_filter_address(sd_lldp *lldp, const struct ether_addr *addr) { | |
487 | assert_return(lldp, -EINVAL); | |
488 | ||
489 | /* In order to deal nicely with bridges that send back our own packets, allow one address to be filtered, so | |
490 | * that our own can be filtered out here. */ | |
491 | ||
a1fb61b0 LP |
492 | if (addr) |
493 | lldp->filter_address = *addr; | |
494 | else | |
b553a6b1 | 495 | zero(lldp->filter_address); |
b553a6b1 | 496 | |
b553a6b1 LP |
497 | return 0; |
498 | } |