]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/lldp-neighbor.h
Merge pull request #8676 from keszybz/drop-license-boilerplate
[thirdparty/systemd.git] / src / libsystemd-network / lldp-neighbor.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2016 Lennart Poettering
8 ***/
9
10 #include <inttypes.h>
11 #include <stdbool.h>
12 #include <sys/types.h>
13
14 #include "sd-lldp.h"
15
16 #include "hash-funcs.h"
17 #include "lldp-internal.h"
18 #include "time-util.h"
19
20 typedef struct LLDPNeighborID {
21 /* The spec calls this an "MSAP identifier" */
22 void *chassis_id;
23 size_t chassis_id_size;
24
25 void *port_id;
26 size_t port_id_size;
27 } LLDPNeighborID;
28
29 struct sd_lldp_neighbor {
30 /* Neighbor objects stay around as long as they are linked into an "sd_lldp" object or n_ref > 0. */
31 sd_lldp *lldp;
32 unsigned n_ref;
33
34 triple_timestamp timestamp;
35
36 usec_t until;
37 unsigned prioq_idx;
38
39 struct ether_addr source_address;
40 struct ether_addr destination_address;
41
42 LLDPNeighborID id;
43
44 /* The raw packet size. The data is appended to the object, accessible via LLDP_NEIGHBOR_RAW() */
45 size_t raw_size;
46
47 /* The current read index for the iterative TLV interface */
48 size_t rindex;
49
50 /* And a couple of fields parsed out. */
51 bool has_ttl:1;
52 bool has_capabilities:1;
53 bool has_port_vlan_id:1;
54
55 uint16_t ttl;
56
57 uint16_t system_capabilities;
58 uint16_t enabled_capabilities;
59
60 char *port_description;
61 char *system_name;
62 char *system_description;
63
64 uint16_t port_vlan_id;
65
66 char *chassis_id_as_string;
67 char *port_id_as_string;
68 };
69
70 static inline void *LLDP_NEIGHBOR_RAW(const sd_lldp_neighbor *n) {
71 return (uint8_t*) n + ALIGN(sizeof(sd_lldp_neighbor));
72 }
73
74 static inline uint8_t LLDP_NEIGHBOR_TLV_TYPE(const sd_lldp_neighbor *n) {
75 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n))[n->rindex] >> 1;
76 }
77
78 static inline size_t LLDP_NEIGHBOR_TLV_LENGTH(const sd_lldp_neighbor *n) {
79 uint8_t *p;
80
81 p = (uint8_t*) LLDP_NEIGHBOR_RAW(n) + n->rindex;
82 return p[1] + (((size_t) (p[0] & 1)) << 8);
83 }
84
85 static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) {
86 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n)) + n->rindex + 2;
87 }
88
89 extern const struct hash_ops lldp_neighbor_id_hash_ops;
90 int lldp_neighbor_prioq_compare_func(const void *a, const void *b);
91
92 sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n);
93 sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size);
94 int lldp_neighbor_parse(sd_lldp_neighbor *n);
95 void lldp_neighbor_start_ttl(sd_lldp_neighbor *n);
96 bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b);