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