]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/lldpd-structs.h
coverity: change a bit the annotations
[thirdparty/lldpd.git] / src / lldpd-structs.h
CommitLineData
4b292b55 1/* -*- mode: c; c-file-style: "openbsd" -*- */
43c02e7b
VB
2/*
3 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
4 *
51434125 5 * Permission to use, copy, modify, and/or distribute this software for any
43c02e7b
VB
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
4b292b55
VB
18#ifndef _LLDPD_STRUCTS_H
19#define _LLDPD_STRUCTS_H
43c02e7b
VB
20
21#if HAVE_CONFIG_H
d38eae28 22# include <config.h>
43c02e7b
VB
23#endif
24
4b292b55
VB
25#include <sys/types.h>
26#include <sys/socket.h>
e12c2365
VB
27
28/* This is not very convenient, but we need net/if.h for IFNAMSIZ and others but
29 * we may also need linux/if.h in some modules. And they conflict each others.
30 */
31#ifdef HOST_OS_LINUX
32# include <linux/if.h>
43c02e7b 33#else
e12c2365 34# include <net/if.h>
43c02e7b 35#endif
e12c2365 36
43c02e7b 37#include <netinet/in.h>
21a48c64 38#include <netinet/if_ether.h>
4b292b55 39#include <sys/queue.h>
43c02e7b 40
4b292b55 41#include "compat/compat.h"
db323555 42#include "marshal.h"
4b292b55 43#include "lldp-const.h"
43c02e7b 44
a1347cd8 45#ifdef ENABLE_DOT1
9757bfbc
SK
46struct lldpd_ppvid {
47 TAILQ_ENTRY(lldpd_ppvid) p_entries;
48 u_int8_t p_cap_status;
49 u_int16_t p_ppvid;
50};
f6d20631
VB
51MARSHAL_BEGIN(lldpd_ppvid)
52MARSHAL_TQE(lldpd_ppvid, p_entries)
985a4cb5 53MARSHAL_END(lldpd_ppvid);
9757bfbc 54
43c02e7b
VB
55struct lldpd_vlan {
56 TAILQ_ENTRY(lldpd_vlan) v_entries;
57 char *v_name;
58 u_int16_t v_vid;
59};
f6d20631
VB
60MARSHAL_BEGIN(lldpd_vlan)
61MARSHAL_TQE(lldpd_vlan, v_entries)
62MARSHAL_STR(lldpd_vlan, v_name)
985a4cb5 63MARSHAL_END(lldpd_vlan);
9757bfbc
SK
64
65struct lldpd_pi {
66 TAILQ_ENTRY(lldpd_pi) p_entries;
67 char *p_pi;
48acfcaf 68 int p_pi_len;
9757bfbc 69};
f6d20631
VB
70MARSHAL_BEGIN(lldpd_pi)
71MARSHAL_TQE(lldpd_pi, p_entries)
72MARSHAL_FSTR(lldpd_pi, p_pi, p_pi_len)
985a4cb5 73MARSHAL_END(lldpd_pi);
a1347cd8 74#endif
43c02e7b 75
e3a44efb 76#ifdef ENABLE_LLDPMED
e3a44efb 77struct lldpd_med_policy {
4b292b55 78 u_int8_t index; /* Not used. */
e3a44efb
VB
79 u_int8_t type;
80 u_int8_t unknown;
81 u_int8_t tagged;
82 u_int16_t vid;
83 u_int8_t priority;
84 u_int8_t dscp;
e3a44efb 85};
f6d20631 86MARSHAL(lldpd_med_policy);
e3a44efb 87
e3a44efb 88struct lldpd_med_loc {
4b292b55 89 u_int8_t index; /* Not used. */
e3a44efb
VB
90 u_int8_t format;
91 char *data;
92 int data_len;
e3a44efb 93};
f6d20631
VB
94MARSHAL_BEGIN(lldpd_med_loc)
95MARSHAL_FSTR(lldpd_med_loc, data, data_len)
985a4cb5 96MARSHAL_END(lldpd_med_loc);
6d08df0e 97
6d08df0e
VB
98struct lldpd_med_power {
99 u_int8_t devicetype; /* PD or PSE */
100 u_int8_t source;
101 u_int8_t priority;
102 u_int16_t val;
103};
f6d20631 104MARSHAL(lldpd_med_power);
e3a44efb
VB
105#endif
106
3fd015c0 107#ifdef ENABLE_DOT3
3fd015c0
VB
108struct lldpd_dot3_macphy {
109 u_int8_t autoneg_support;
110 u_int8_t autoneg_enabled;
111 u_int16_t autoneg_advertised;
112 u_int16_t mau_type;
113};
befbdf89 114
befbdf89
VB
115struct lldpd_dot3_power {
116 u_int8_t devicetype;
117 u_int8_t supported;
118 u_int8_t enabled;
119 u_int8_t paircontrol;
120 u_int8_t pairs;
121 u_int8_t class;
608cb51c
VB
122 u_int8_t powertype; /* If set to LLDP_DOT3_POWER_8023AT_OFF,
123 following fields have no meaning */
124 u_int8_t source;
125 u_int8_t priority;
126 u_int16_t requested;
127 u_int16_t allocated;
befbdf89 128};
f6d20631 129MARSHAL(lldpd_dot3_power);
3fd015c0
VB
130#endif
131
f15d3950
VB
132enum {
133 LLDPD_AF_UNSPEC = 0,
134 LLDPD_AF_IPV4,
135 LLDPD_AF_IPV6,
136 LLDPD_AF_LAST
137};
138
139inline static int
140lldpd_af(int af)
141{
142 switch (af) {
4b292b55
VB
143 case LLDPD_AF_IPV4: return AF_INET;
144 case LLDPD_AF_IPV6: return AF_INET6;
145 case LLDPD_AF_LAST: return AF_MAX;
146 default: return AF_UNSPEC;
f15d3950
VB
147 }
148}
149
e6b36c87
JV
150#define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
151struct lldpd_mgmt {
152 TAILQ_ENTRY(lldpd_mgmt) m_entries;
153 int m_family;
154 union {
155 struct in_addr inet;
156 struct in6_addr inet6;
157 u_int8_t octets[LLDPD_MGMT_MAXADDRSIZE];
158 } m_addr;
159 size_t m_addrsize;
160 u_int32_t m_iface;
161};
162MARSHAL_BEGIN(lldpd_mgmt)
163MARSHAL_TQE(lldpd_mgmt, m_entries)
985a4cb5 164MARSHAL_END(lldpd_mgmt);
e6b36c87 165
43c02e7b 166struct lldpd_chassis {
75068724
VB
167 TAILQ_ENTRY(lldpd_chassis) c_entries;
168 u_int16_t c_refcount; /* Reference count by ports */
169 u_int16_t c_index; /* Monotonic index */
170 u_int8_t c_protocol; /* Protocol used to get this chassis */
43c02e7b
VB
171 u_int8_t c_id_subtype;
172 char *c_id;
173 int c_id_len;
174 char *c_name;
175 char *c_descr;
176
177 u_int16_t c_cap_available;
178 u_int16_t c_cap_enabled;
179
180 u_int16_t c_ttl;
181
e6b36c87 182 TAILQ_HEAD(, lldpd_mgmt) c_mgmt;
89840df0
VB
183
184#ifdef ENABLE_LLDPMED
40ecae87 185 u_int16_t c_med_cap_available;
89840df0
VB
186 u_int8_t c_med_type;
187 char *c_med_hw;
188 char *c_med_fw;
189 char *c_med_sw;
190 char *c_med_sn;
191 char *c_med_manuf;
192 char *c_med_model;
193 char *c_med_asset;
89840df0 194#endif
1531f7f3
VB
195
196};
d938c51f
VB
197/* WARNING: any change to this structure should also be reflected into
198 `lldpd_copy_chassis()` which is not using marshaling. */
f6d20631 199MARSHAL_BEGIN(lldpd_chassis)
74e0080e
VB
200MARSHAL_IGNORE(lldpd_chassis, c_entries.tqe_next)
201MARSHAL_IGNORE(lldpd_chassis, c_entries.tqe_prev)
f6d20631
VB
202MARSHAL_FSTR(lldpd_chassis, c_id, c_id_len)
203MARSHAL_STR(lldpd_chassis, c_name)
204MARSHAL_STR(lldpd_chassis, c_descr)
e6b36c87 205MARSHAL_SUBTQ(lldpd_chassis, lldpd_mgmt, c_mgmt)
f6d20631
VB
206#ifdef ENABLE_LLDPMED
207MARSHAL_STR(lldpd_chassis, c_med_hw)
208MARSHAL_STR(lldpd_chassis, c_med_fw)
209MARSHAL_STR(lldpd_chassis, c_med_sw)
210MARSHAL_STR(lldpd_chassis, c_med_sn)
211MARSHAL_STR(lldpd_chassis, c_med_manuf)
212MARSHAL_STR(lldpd_chassis, c_med_model)
213MARSHAL_STR(lldpd_chassis, c_med_asset)
214#endif
985a4cb5 215MARSHAL_END(lldpd_chassis);
f6d20631 216
43c02e7b
VB
217
218struct lldpd_port {
75068724
VB
219 TAILQ_ENTRY(lldpd_port) p_entries;
220 struct lldpd_chassis *p_chassis; /* Attached chassis */
221 time_t p_lastchange; /* Time of last change of values */
222 time_t p_lastupdate; /* Time of last update received */
223 struct lldpd_frame *p_lastframe; /* Frame received during last update */
224 u_int8_t p_protocol; /* Protocol used to get this port */
579bedd5
VB
225 u_int8_t p_hidden_in:1; /* Considered as hidden for reception */
226 u_int8_t p_hidden_out:2; /* Considered as hidden for emission */
227 /* Important: all fields that should be ignored to check if a port has
228 * been changed should be before p_id_subtype. Check
229 * `lldpd_reset_timer()`. */
43c02e7b
VB
230 u_int8_t p_id_subtype;
231 char *p_id;
232 int p_id_len;
233 char *p_descr;
548109b2 234 u_int16_t p_mfs;
43c02e7b 235
a1347cd8 236#ifdef ENABLE_DOT3
43c02e7b
VB
237 /* Dot3 stuff */
238 u_int32_t p_aggregid;
3fd015c0 239 struct lldpd_dot3_macphy p_macphy;
befbdf89 240 struct lldpd_dot3_power p_power;
a1347cd8 241#endif
1531f7f3 242
740593ff 243#ifdef ENABLE_LLDPMED
740593ff 244 u_int16_t p_med_cap_enabled;
4b292b55
VB
245 struct lldpd_med_policy p_med_policy[LLDP_MED_APPTYPE_LAST];
246 struct lldpd_med_loc p_med_location[LLDP_MED_LOCFORMAT_LAST];
6d08df0e 247 struct lldpd_med_power p_med_power;
740593ff
VB
248#endif
249
a1347cd8 250#ifdef ENABLE_DOT1
75b3469d 251 u_int16_t p_pvid;
1531f7f3 252 TAILQ_HEAD(, lldpd_vlan) p_vlans;
9757bfbc
SK
253 TAILQ_HEAD(, lldpd_ppvid) p_ppvids;
254 TAILQ_HEAD(, lldpd_pi) p_pids;
a1347cd8 255#endif
1531f7f3 256};
f6d20631
VB
257MARSHAL_BEGIN(lldpd_port)
258MARSHAL_TQE(lldpd_port, p_entries)
259MARSHAL_POINTER(lldpd_port, lldpd_chassis, p_chassis)
260MARSHAL_IGNORE(lldpd_port, p_lastframe)
261MARSHAL_FSTR(lldpd_port, p_id, p_id_len)
262MARSHAL_STR(lldpd_port, p_descr)
263#ifdef ENABLE_LLDPMED
264MARSHAL_SUBSTRUCT(lldpd_port, lldpd_med_loc, p_med_location[0])
265MARSHAL_SUBSTRUCT(lldpd_port, lldpd_med_loc, p_med_location[1])
266MARSHAL_SUBSTRUCT(lldpd_port, lldpd_med_loc, p_med_location[2])
267#endif
268#ifdef ENABLE_DOT1
269MARSHAL_SUBTQ(lldpd_port, lldpd_vlan, p_vlans)
270MARSHAL_SUBTQ(lldpd_port, lldpd_ppvid, p_ppvids)
271MARSHAL_SUBTQ(lldpd_port, lldpd_pi, p_pids)
272#endif
985a4cb5 273MARSHAL_END(lldpd_port);
1531f7f3 274
f6d20631
VB
275/* Used to modify some port related settings */
276struct lldpd_port_set {
277 char *ifname;
278#ifdef ENABLE_LLDPMED
279 struct lldpd_med_policy *med_policy;
280 struct lldpd_med_loc *med_location;
281 struct lldpd_med_power *med_power;
282#endif
283#ifdef ENABLE_DOT3
284 struct lldpd_dot3_power *dot3_power;
285#endif
286};
287MARSHAL_BEGIN(lldpd_port_set)
288MARSHAL_STR(lldpd_port_set, ifname)
289#ifdef ENABLE_LLDPMED
290MARSHAL_POINTER(lldpd_port_set, lldpd_med_policy, med_policy)
291MARSHAL_POINTER(lldpd_port_set, lldpd_med_loc, med_location)
292MARSHAL_POINTER(lldpd_port_set, lldpd_med_power, med_power)
293#endif
294#ifdef ENABLE_DOT3
295MARSHAL_POINTER(lldpd_port_set, lldpd_dot3_power, dot3_power)
296#endif
985a4cb5 297MARSHAL_END(lldpd_port_set);
43c02e7b 298
8ec333bd
VB
299/* Smart mode / Hide mode */
300#define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */
301#define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only one proto */
302#define SMART_INCOMING_ONE_NEIGH (1<<2) /* On reception, keep only one neighbor */
303#define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */
304#define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */
305#define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only one neighbor */
306#define SMART_INCOMING (SMART_INCOMING_FILTER | \
307 SMART_INCOMING_ONE_PROTO | \
308 SMART_INCOMING_ONE_NEIGH)
309#define SMART_OUTGOING (SMART_OUTGOING_FILTER | \
310 SMART_OUTGOING_ONE_PROTO | \
311 SMART_OUTGOING_ONE_NEIGH)
312
313struct lldpd_config {
e4ff3ed5 314 int c_paused; /* lldpd is paused */
8843f168 315 int c_tx_interval; /* Transmit interval */
8ec333bd
VB
316 int c_smart; /* Bitmask for smart configuration (see SMART_*) */
317 int c_receiveonly; /* Receive only mode */
42589660 318 int c_max_neighbors; /* Maximum number of neighbors (per protocol) */
8ec333bd
VB
319
320 char *c_mgmt_pattern; /* Pattern to match a management address */
321 char *c_cid_pattern; /* Pattern to match interfaces to use for chassis ID */
322 char *c_iface_pattern; /* Pattern to match interfaces to use */
323
324 char *c_platform; /* Override platform description (for CDP) */
325 char *c_description; /* Override chassis description */
326 int c_advertise_version; /* Should the precise version be advertised? */
bb37268d 327 int c_set_ifdescr; /* Set interface description */
8ec333bd
VB
328
329#ifdef ENABLE_LLDPMED
330 int c_noinventory; /* Don't send inventory with LLDP-MED */
b9de0ca6 331 int c_enable_fast_start; /* enable fast start */
332 int c_tx_fast_init; /* Num of lldpd lldppdu's for fast start */
333 int c_tx_fast_interval; /* Time intr between sends during fast start */
be511d00 334#endif
c10302a3 335 int c_tx_hold; /* Transmit hold */
dfbd7185
RP
336 int c_bond_slave_src_mac_type; /* Src mac type in lldp frames over bond
337 slaves */
8ec333bd
VB
338};
339MARSHAL_BEGIN(lldpd_config)
340MARSHAL_STR(lldpd_config, c_mgmt_pattern)
341MARSHAL_STR(lldpd_config, c_cid_pattern)
342MARSHAL_STR(lldpd_config, c_iface_pattern)
343MARSHAL_STR(lldpd_config, c_platform)
344MARSHAL_STR(lldpd_config, c_description)
985a4cb5 345MARSHAL_END(lldpd_config);
8ec333bd 346
43c02e7b
VB
347struct lldpd_frame {
348 int size;
b5c7ce8d 349 unsigned char frame[1];
43c02e7b
VB
350};
351
6e75df87
VB
352struct lldpd_hardware;
353struct lldpd;
354struct lldpd_ops {
355 int(*send)(struct lldpd *,
356 struct lldpd_hardware*,
357 char *, size_t); /* Function to send a frame */
358 int(*recv)(struct lldpd *,
359 struct lldpd_hardware*,
360 int, char *, size_t); /* Function to receive a frame */
361 int(*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup function. */
362};
363
44002d66
VB
364/* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
365 * means if an interface becomes enslaved, it will be considered as a new
366 * interface. The same applies for renaming and we include the index in case of
367 * renaming to an existing interface. */
43c02e7b
VB
368struct lldpd_hardware {
369 TAILQ_ENTRY(lldpd_hardware) h_entries;
370
d6e889b6
VB
371 struct lldpd *h_cfg; /* Pointer to main configuration */
372 void *h_recv; /* FD for reception */
6e75df87 373 int h_sendfd; /* FD for sending, only used by h_ops */
5347914e 374 int h_mangle; /* 1 if we have to mangle the MAC address */
6e75df87
VB
375 struct lldpd_ops *h_ops; /* Hardware-dependent functions */
376 void *h_data; /* Hardware-dependent data */
579bedd5 377 void *h_timer; /* Timer for this port */
43c02e7b 378
43c02e7b 379 int h_mtu;
6e75df87
VB
380 int h_flags; /* Packets will be sent only
381 if IFF_RUNNING. Will be
382 removed if this is left
383 to 0. */
384 int h_ifindex; /* Interface index, used by SNMP */
385 char h_ifname[IFNAMSIZ]; /* Should be unique */
43c02e7b
VB
386 u_int8_t h_lladdr[ETHER_ADDR_LEN];
387
388 u_int64_t h_tx_cnt;
389 u_int64_t h_rx_cnt;
390 u_int64_t h_rx_discarded_cnt;
37387046 391 u_int64_t h_rx_unrecognized_cnt;
14052b61
VB
392 u_int64_t h_ageout_cnt;
393 u_int64_t h_insert_cnt;
394 u_int64_t h_delete_cnt;
42589660 395 u_int64_t h_drop_cnt;
43c02e7b 396
579bedd5 397 u_int16_t h_lport_cksum; /* Checksum on local port to see if there is a change */
75068724
VB
398 struct lldpd_port h_lport; /* Port attached to this hardware port */
399 TAILQ_HEAD(, lldpd_port) h_rports; /* Remote ports */
b9de0ca6 400
be511d00 401#ifdef ENABLE_LLDPMED
b9de0ca6 402 int h_tx_fast; /* current tx fast start count */
be511d00 403#endif
43c02e7b 404};
f6d20631
VB
405MARSHAL_BEGIN(lldpd_hardware)
406MARSHAL_IGNORE(lldpd_hardware, h_entries.tqe_next)
407MARSHAL_IGNORE(lldpd_hardware, h_entries.tqe_prev)
408MARSHAL_IGNORE(lldpd_hardware, h_ops)
409MARSHAL_IGNORE(lldpd_hardware, h_data)
d6e889b6 410MARSHAL_IGNORE(lldpd_hardware, h_cfg)
f6d20631
VB
411MARSHAL_SUBSTRUCT(lldpd_hardware, lldpd_port, h_lport)
412MARSHAL_SUBTQ(lldpd_hardware, lldpd_port, h_rports)
985a4cb5 413MARSHAL_END(lldpd_hardware);
43c02e7b
VB
414
415struct lldpd_interface {
416 TAILQ_ENTRY(lldpd_interface) next;
417 char *name;
418};
f6d20631
VB
419MARSHAL_BEGIN(lldpd_interface)
420MARSHAL_TQE(lldpd_interface, next)
421MARSHAL_STR(lldpd_interface, name)
985a4cb5 422MARSHAL_END(lldpd_interface);
f6d20631
VB
423TAILQ_HEAD(lldpd_interface_list, lldpd_interface);
424MARSHAL_TQ(lldpd_interface_list, lldpd_interface);
43c02e7b 425
4e90a9e0
VB
426struct lldpd_neighbor_change {
427 char *ifname;
428#define NEIGHBOR_CHANGE_DELETED -1
429#define NEIGHBOR_CHANGE_ADDED 1
430#define NEIGHBOR_CHANGE_UPDATED 0
431 int state;
432 struct lldpd_port *neighbor;
433};
434MARSHAL_BEGIN(lldpd_neighbor_change)
435MARSHAL_STR(lldpd_neighbor_change, ifname)
436MARSHAL_POINTER(lldpd_neighbor_change, lldpd_port, neighbor)
985a4cb5 437MARSHAL_END(lldpd_neighbor_change);
4e90a9e0 438
4b292b55
VB
439/* Cleanup functions */
440void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *);
441void lldpd_chassis_cleanup(struct lldpd_chassis *, int);
4e90a9e0 442void lldpd_remote_cleanup(struct lldpd_hardware *,
ef3707da
VB
443 void(*expire)(struct lldpd_hardware *, struct lldpd_port *),
444 int);
4b292b55 445void lldpd_port_cleanup(struct lldpd_port *, int);
8ec333bd 446void lldpd_config_cleanup(struct lldpd_config *);
a1347cd8 447#ifdef ENABLE_DOT1
9757bfbc 448void lldpd_ppvid_cleanup(struct lldpd_port *);
43c02e7b 449void lldpd_vlan_cleanup(struct lldpd_port *);
9757bfbc 450void lldpd_pi_cleanup(struct lldpd_port *);
a1347cd8 451#endif
6e75df87 452
0265b1e5 453#endif