1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2016 Lennart Poettering
12 #include <sys/types.h>
16 #include "hash-funcs.h"
17 #include "lldp-internal.h"
18 #include "time-util.h"
20 typedef struct LLDPNeighborID
{
21 /* The spec calls this an "MSAP identifier" */
23 size_t chassis_id_size
;
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. */
34 triple_timestamp timestamp
;
39 struct ether_addr source_address
;
40 struct ether_addr destination_address
;
44 /* The raw packet size. The data is appended to the object, accessible via LLDP_NEIGHBOR_RAW() */
47 /* The current read index for the iterative TLV interface */
50 /* And a couple of fields parsed out. */
52 bool has_capabilities
:1;
53 bool has_port_vlan_id
:1;
57 uint16_t system_capabilities
;
58 uint16_t enabled_capabilities
;
60 char *port_description
;
62 char *system_description
;
64 uint16_t port_vlan_id
;
66 char *chassis_id_as_string
;
67 char *port_id_as_string
;
70 static inline void *LLDP_NEIGHBOR_RAW(const sd_lldp_neighbor
*n
) {
71 return (uint8_t*) n
+ ALIGN(sizeof(sd_lldp_neighbor
));
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;
78 static inline size_t LLDP_NEIGHBOR_TLV_LENGTH(const sd_lldp_neighbor
*n
) {
81 p
= (uint8_t*) LLDP_NEIGHBOR_RAW(n
) + n
->rindex
;
82 return p
[1] + (((size_t) (p
[0] & 1)) << 8);
85 static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor
*n
) {
86 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n
)) + n
->rindex
+ 2;
89 extern const struct hash_ops lldp_neighbor_id_hash_ops
;
90 int lldp_neighbor_prioq_compare_func(const void *a
, const void *b
);
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
);