| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <net/ethernet.h> |
| 5 |
|
| 6 |
#include "sd-lldp-rx.h" |
| 7 |
|
| 8 |
#include "sd-forward.h" |
| 9 |
#include "memory-util.h" |
| 10 |
#include "time-util.h" |
| 11 |
|
| 12 |
typedef struct LLDPNeighborID { |
| 13 |
/* The spec calls this an "MSAP identifier" */ |
| 14 |
void *chassis_id; |
| 15 |
size_t chassis_id_size; |
| 16 |
|
| 17 |
void *port_id; |
| 18 |
size_t port_id_size; |
| 19 |
} LLDPNeighborID; |
| 20 |
|
| 21 |
struct sd_lldp_neighbor { |
| 22 |
/* Neighbor objects stay around as long as they are linked into an "sd_lldp_rx" object or n_ref > 0. */ |
| 23 |
sd_lldp_rx *lldp_rx; |
| 24 |
unsigned n_ref; |
| 25 |
|
| 26 |
triple_timestamp timestamp; |
| 27 |
|
| 28 |
usec_t until; |
| 29 |
unsigned prioq_idx; |
| 30 |
|
| 31 |
struct ether_addr source_address; |
| 32 |
struct ether_addr destination_address; |
| 33 |
|
| 34 |
LLDPNeighborID id; |
| 35 |
|
| 36 |
/* The raw packet size. The data is appended to the object, accessible via LLDP_NEIGHBOR_RAW() */ |
| 37 |
size_t raw_size; |
| 38 |
|
| 39 |
/* The current read index for the iterative TLV interface */ |
| 40 |
size_t rindex; |
| 41 |
|
| 42 |
/* And a couple of fields parsed out. */ |
| 43 |
bool has_ttl:1; |
| 44 |
bool has_capabilities:1; |
| 45 |
bool has_port_vlan_id:1; |
| 46 |
|
| 47 |
uint16_t ttl; |
| 48 |
|
| 49 |
uint16_t system_capabilities; |
| 50 |
uint16_t enabled_capabilities; |
| 51 |
|
| 52 |
char *port_description; |
| 53 |
char *system_name; |
| 54 |
char *system_description; |
| 55 |
char *mud_url; |
| 56 |
|
| 57 |
uint16_t port_vlan_id; |
| 58 |
|
| 59 |
char *chassis_id_as_string; |
| 60 |
char *port_id_as_string; |
| 61 |
}; |
| 62 |
|
| 63 |
static inline void *LLDP_NEIGHBOR_RAW(const sd_lldp_neighbor *n) { |
| 64 |
return (uint8_t*) n + ALIGN(sizeof(sd_lldp_neighbor)); |
| 65 |
} |
| 66 |
|
| 67 |
static inline uint8_t LLDP_NEIGHBOR_TLV_TYPE(const sd_lldp_neighbor *n) { |
| 68 |
return ((uint8_t*) LLDP_NEIGHBOR_RAW(n))[n->rindex] >> 1; |
| 69 |
} |
| 70 |
|
| 71 |
static inline size_t LLDP_NEIGHBOR_TLV_LENGTH(const sd_lldp_neighbor *n) { |
| 72 |
uint8_t *p; |
| 73 |
|
| 74 |
p = (uint8_t*) LLDP_NEIGHBOR_RAW(n) + n->rindex; |
| 75 |
return p[1] + (((size_t) (p[0] & 1)) << 8); |
| 76 |
} |
| 77 |
|
| 78 |
static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) { |
| 79 |
return ((uint8_t*) LLDP_NEIGHBOR_RAW(n)) + n->rindex + 2; |
| 80 |
} |
| 81 |
|
| 82 |
extern const struct hash_ops lldp_neighbor_hash_ops; |
| 83 |
int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y); |
| 84 |
int lldp_neighbor_prioq_compare_func(const sd_lldp_neighbor *x, const sd_lldp_neighbor *y); |
| 85 |
|
| 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); |
| 91 |
int lldp_neighbor_build_json(sd_lldp_neighbor *n, sd_json_variant **ret); |