1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "hash-funcs.h"
11 #include "lldp-internal.h"
12 #include "time-util.h"
14 typedef struct LLDPNeighborID
{
15 /* The spec calls this an "MSAP identifier" */
17 size_t chassis_id_size
;
23 struct sd_lldp_neighbor
{
24 /* Neighbor objects stay around as long as they are linked into an "sd_lldp" object or n_ref > 0. */
28 triple_timestamp timestamp
;
33 struct ether_addr source_address
;
34 struct ether_addr destination_address
;
38 /* The raw packet size. The data is appended to the object, accessible via LLDP_NEIGHBOR_RAW() */
41 /* The current read index for the iterative TLV interface */
44 /* And a couple of fields parsed out. */
46 bool has_capabilities
:1;
47 bool has_port_vlan_id
:1;
51 uint16_t system_capabilities
;
52 uint16_t enabled_capabilities
;
54 char *port_description
;
56 char *system_description
;
58 uint16_t port_vlan_id
;
60 char *chassis_id_as_string
;
61 char *port_id_as_string
;
64 static inline void *LLDP_NEIGHBOR_RAW(const sd_lldp_neighbor
*n
) {
65 return (uint8_t*) n
+ ALIGN(sizeof(sd_lldp_neighbor
));
68 static inline uint8_t LLDP_NEIGHBOR_TLV_TYPE(const sd_lldp_neighbor
*n
) {
69 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n
))[n
->rindex
] >> 1;
72 static inline size_t LLDP_NEIGHBOR_TLV_LENGTH(const sd_lldp_neighbor
*n
) {
75 p
= (uint8_t*) LLDP_NEIGHBOR_RAW(n
) + n
->rindex
;
76 return p
[1] + (((size_t) (p
[0] & 1)) << 8);
79 static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor
*n
) {
80 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n
)) + n
->rindex
+ 2;
83 extern const struct hash_ops lldp_neighbor_id_hash_ops
;
84 int lldp_neighbor_prioq_compare_func(const void *a
, const void *b
);
86 sd_lldp_neighbor
*lldp_neighbor_unlink(sd_lldp_neighbor
*n
);
87 sd_lldp_neighbor
*lldp_neighbor_new(size_t raw_size
);
88 int lldp_neighbor_parse(sd_lldp_neighbor
*n
);
89 void lldp_neighbor_start_ttl(sd_lldp_neighbor
*n
);
90 bool lldp_neighbor_equal(const sd_lldp_neighbor
*a
, const sd_lldp_neighbor
*b
);