]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
aa27b158 MP |
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 | ||
33 | typedef 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 | ||
42 | struct 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 | ||
5a920b42 MP |
47 | triple_timestamp timestamp; |
48 | ||
aa27b158 MP |
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 | ||
83 | static inline void *LLDP_NEIGHBOR_RAW(const sd_lldp_neighbor *n) { | |
84 | return (uint8_t*) n + ALIGN(sizeof(sd_lldp_neighbor)); | |
85 | } | |
86 | ||
5a920b42 | 87 | static inline uint8_t LLDP_NEIGHBOR_TLV_TYPE(const sd_lldp_neighbor *n) { |
aa27b158 MP |
88 | return ((uint8_t*) LLDP_NEIGHBOR_RAW(n))[n->rindex] >> 1; |
89 | } | |
90 | ||
5a920b42 | 91 | static inline size_t LLDP_NEIGHBOR_TLV_LENGTH(const sd_lldp_neighbor *n) { |
aa27b158 MP |
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 | ||
5a920b42 | 98 | static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) { |
aa27b158 MP |
99 | return ((uint8_t*) LLDP_NEIGHBOR_RAW(n)) + n->rindex + 2; |
100 | } | |
101 | ||
102 | extern const struct hash_ops lldp_neighbor_id_hash_ops; | |
103 | int lldp_neighbor_prioq_compare_func(const void *a, const void *b); | |
104 | ||
105 | sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n); | |
106 | sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size); | |
107 | int lldp_neighbor_parse(sd_lldp_neighbor *n); | |
108 | void lldp_neighbor_start_ttl(sd_lldp_neighbor *n); | |
109 | bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b); |