]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/lldp-neighbor.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd-network / lldp-neighbor.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
34437b4f
LP
2#pragma once
3
4/***
5 This file is part of systemd.
6
7 Copyright 2016 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21***/
22
23#include <inttypes.h>
24#include <stdbool.h>
25#include <sys/types.h>
26
27#include "sd-lldp.h"
28
29#include "hash-funcs.h"
30#include "lldp-internal.h"
31#include "time-util.h"
32
33typedef struct LLDPNeighborID {
34 /* The spec calls this an "MSAP identifier" */
35 void *chassis_id;
36 size_t chassis_id_size;
37
38 void *port_id;
39 size_t port_id_size;
40} LLDPNeighborID;
41
42struct sd_lldp_neighbor {
43 /* Neighbor objects stay around as long as they are linked into an "sd_lldp" object or n_ref > 0. */
44 sd_lldp *lldp;
45 unsigned n_ref;
46
16fed825
LP
47 triple_timestamp timestamp;
48
34437b4f
LP
49 usec_t until;
50 unsigned prioq_idx;
51
52 struct ether_addr source_address;
53 struct ether_addr destination_address;
54
55 LLDPNeighborID id;
56
57 /* The raw packet size. The data is appended to the object, accessible via LLDP_NEIGHBOR_RAW() */
58 size_t raw_size;
59
60 /* The current read index for the iterative TLV interface */
61 size_t rindex;
62
63 /* And a couple of fields parsed out. */
64 bool has_ttl:1;
65 bool has_capabilities:1;
66 bool has_port_vlan_id:1;
67
68 uint16_t ttl;
69
70 uint16_t system_capabilities;
71 uint16_t enabled_capabilities;
72
73 char *port_description;
74 char *system_name;
75 char *system_description;
76
77 uint16_t port_vlan_id;
78
79 char *chassis_id_as_string;
80 char *port_id_as_string;
81};
82
83static inline void *LLDP_NEIGHBOR_RAW(const sd_lldp_neighbor *n) {
84 return (uint8_t*) n + ALIGN(sizeof(sd_lldp_neighbor));
85}
86
f137029b 87static inline uint8_t LLDP_NEIGHBOR_TLV_TYPE(const sd_lldp_neighbor *n) {
34437b4f
LP
88 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n))[n->rindex] >> 1;
89}
90
f137029b 91static inline size_t LLDP_NEIGHBOR_TLV_LENGTH(const sd_lldp_neighbor *n) {
34437b4f
LP
92 uint8_t *p;
93
94 p = (uint8_t*) LLDP_NEIGHBOR_RAW(n) + n->rindex;
95 return p[1] + (((size_t) (p[0] & 1)) << 8);
96}
97
f137029b 98static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) {
34437b4f
LP
99 return ((uint8_t*) LLDP_NEIGHBOR_RAW(n)) + n->rindex + 2;
100}
101
102extern const struct hash_ops lldp_neighbor_id_hash_ops;
103int lldp_neighbor_prioq_compare_func(const void *a, const void *b);
104
105sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n);
106sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size);
107int lldp_neighbor_parse(sd_lldp_neighbor *n);
108void lldp_neighbor_start_ttl(sd_lldp_neighbor *n);
109bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b);