1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
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.
18 #ifndef _LLDPD_STRUCTS_H
19 #define _LLDPD_STRUCTS_H
25 #include <sys/types.h>
26 #include <sys/socket.h>
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.
32 # include <linux/if.h>
37 #include <netinet/in.h>
38 #include <netinet/if_ether.h>
39 #include <sys/queue.h>
41 #include "compat/compat.h"
43 #include "lldp-const.h"
47 TAILQ_ENTRY(lldpd_ppvid
) p_entries
;
48 u_int8_t p_cap_status
;
51 MARSHAL_BEGIN(lldpd_ppvid
)
52 MARSHAL_TQE(lldpd_ppvid
, p_entries
)
53 MARSHAL_END(lldpd_ppvid
);
56 TAILQ_ENTRY(lldpd_vlan
) v_entries
;
60 MARSHAL_BEGIN(lldpd_vlan
)
61 MARSHAL_TQE(lldpd_vlan
, v_entries
)
62 MARSHAL_STR(lldpd_vlan
, v_name
)
63 MARSHAL_END(lldpd_vlan
);
66 TAILQ_ENTRY(lldpd_pi
) p_entries
;
70 MARSHAL_BEGIN(lldpd_pi
)
71 MARSHAL_TQE(lldpd_pi
, p_entries
)
72 MARSHAL_FSTR(lldpd_pi
, p_pi
, p_pi_len
)
73 MARSHAL_END(lldpd_pi
);
77 struct lldpd_med_policy
{
78 u_int8_t index
; /* Not used. */
86 MARSHAL(lldpd_med_policy
);
88 struct lldpd_med_loc
{
89 u_int8_t index
; /* Not used. */
94 MARSHAL_BEGIN(lldpd_med_loc
)
95 MARSHAL_FSTR(lldpd_med_loc
, data
, data_len
)
96 MARSHAL_END(lldpd_med_loc
);
98 struct lldpd_med_power
{
99 u_int8_t devicetype
; /* PD or PSE */
104 MARSHAL(lldpd_med_power
);
108 struct lldpd_dot3_macphy
{
109 u_int8_t autoneg_support
;
110 u_int8_t autoneg_enabled
;
111 u_int16_t autoneg_advertised
;
115 struct lldpd_dot3_power
{
119 u_int8_t paircontrol
;
122 u_int8_t powertype
; /* If set to LLDP_DOT3_POWER_8023AT_OFF,
123 following fields have no meaning */
129 MARSHAL(lldpd_dot3_power
);
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
;
150 #define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
152 TAILQ_ENTRY(lldpd_mgmt
) m_entries
;
156 struct in6_addr inet6
;
157 u_int8_t octets
[LLDPD_MGMT_MAXADDRSIZE
]; /* network byte order! */
162 MARSHAL_BEGIN(lldpd_mgmt
)
163 MARSHAL_TQE(lldpd_mgmt
, m_entries
)
164 MARSHAL_END(lldpd_mgmt
);
166 struct lldpd_chassis
{
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 */
171 u_int8_t c_id_subtype
;
177 u_int16_t c_cap_available
;
178 u_int16_t c_cap_enabled
;
182 TAILQ_HEAD(, lldpd_mgmt
) c_mgmt
;
184 #ifdef ENABLE_LLDPMED
185 u_int16_t c_med_cap_available
;
197 /* WARNING: any change to this structure should also be reflected into
198 `lldpd_copy_chassis()` which is not using marshaling. */
199 MARSHAL_BEGIN(lldpd_chassis
)
200 MARSHAL_IGNORE(lldpd_chassis
, c_entries
.tqe_next
)
201 MARSHAL_IGNORE(lldpd_chassis
, c_entries
.tqe_prev
)
202 MARSHAL_FSTR(lldpd_chassis
, c_id
, c_id_len
)
203 MARSHAL_STR(lldpd_chassis
, c_name
)
204 MARSHAL_STR(lldpd_chassis
, c_descr
)
205 MARSHAL_SUBTQ(lldpd_chassis
, lldpd_mgmt
, c_mgmt
)
206 #ifdef ENABLE_LLDPMED
207 MARSHAL_STR(lldpd_chassis
, c_med_hw
)
208 MARSHAL_STR(lldpd_chassis
, c_med_fw
)
209 MARSHAL_STR(lldpd_chassis
, c_med_sw
)
210 MARSHAL_STR(lldpd_chassis
, c_med_sn
)
211 MARSHAL_STR(lldpd_chassis
, c_med_manuf
)
212 MARSHAL_STR(lldpd_chassis
, c_med_model
)
213 MARSHAL_STR(lldpd_chassis
, c_med_asset
)
215 MARSHAL_END(lldpd_chassis
);
217 /* Custom TLV struct as defined on page 35 of IEEE 802.1AB-2005 */
218 struct lldpd_custom
{
219 TAILQ_ENTRY(lldpd_custom
) next
; /* Pointer to next custom TLV */
221 /* Organizationally Unique Identifier */
222 u_int8_t oui
[LLDP_TLV_ORG_OUI_LEN
];
223 /* Organizationally Defined Subtype */
225 /* Organizationally Defined Information String; for now/simplicity static array */
226 u_int8_t oui_info
[LLDP_TLV_ORG_OUI_INFO_MAXLEN
];
227 /* Organizationally Defined Information String length */
230 MARSHAL_BEGIN(lldpd_custom
)
231 MARSHAL_TQE(lldpd_custom
, next
)
232 MARSHAL_END(lldpd_custom
);
235 TAILQ_ENTRY(lldpd_port
) p_entries
;
236 struct lldpd_chassis
*p_chassis
; /* Attached chassis */
237 time_t p_lastchange
; /* Time of last change of values */
238 time_t p_lastupdate
; /* Time of last update received */
239 struct lldpd_frame
*p_lastframe
; /* Frame received during last update */
240 u_int8_t p_protocol
; /* Protocol used to get this port */
241 u_int8_t p_hidden_in
:1; /* Considered as hidden for reception */
242 u_int8_t p_hidden_out
:2; /* Considered as hidden for emission */
243 /* Important: all fields that should be ignored to check if a port has
244 * been changed should be before this mark. */
245 #define LLDPD_PORT_START_MARKER (offsetof(struct lldpd_port, p_id_subtype))
246 u_int8_t p_id_subtype
;
254 u_int32_t p_aggregid
;
255 struct lldpd_dot3_macphy p_macphy
;
256 struct lldpd_dot3_power p_power
;
259 #ifdef ENABLE_LLDPMED
260 u_int16_t p_med_cap_enabled
;
261 struct lldpd_med_policy p_med_policy
[LLDP_MED_APPTYPE_LAST
];
262 struct lldpd_med_loc p_med_location
[LLDP_MED_LOCFORMAT_LAST
];
263 struct lldpd_med_power p_med_power
;
268 TAILQ_HEAD(, lldpd_vlan
) p_vlans
;
269 TAILQ_HEAD(, lldpd_ppvid
) p_ppvids
;
270 TAILQ_HEAD(, lldpd_pi
) p_pids
;
272 TAILQ_HEAD(, lldpd_custom
) p_custom_list
;
274 MARSHAL_BEGIN(lldpd_port
)
275 MARSHAL_TQE(lldpd_port
, p_entries
)
276 MARSHAL_POINTER(lldpd_port
, lldpd_chassis
, p_chassis
)
277 MARSHAL_IGNORE(lldpd_port
, p_lastframe
)
278 MARSHAL_FSTR(lldpd_port
, p_id
, p_id_len
)
279 MARSHAL_STR(lldpd_port
, p_descr
)
280 #ifdef ENABLE_LLDPMED
281 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[0])
282 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[1])
283 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[2])
286 MARSHAL_SUBTQ(lldpd_port
, lldpd_vlan
, p_vlans
)
287 MARSHAL_SUBTQ(lldpd_port
, lldpd_ppvid
, p_ppvids
)
288 MARSHAL_SUBTQ(lldpd_port
, lldpd_pi
, p_pids
)
290 MARSHAL_SUBTQ(lldpd_port
, lldpd_custom
, p_custom_list
)
291 MARSHAL_END(lldpd_port
);
293 /* Used to modify some port related settings */
294 struct lldpd_port_set
{
298 #ifdef ENABLE_LLDPMED
299 struct lldpd_med_policy
*med_policy
;
300 struct lldpd_med_loc
*med_location
;
301 struct lldpd_med_power
*med_power
;
304 struct lldpd_dot3_power
*dot3_power
;
306 struct lldpd_custom
*custom
;
307 int custom_list_clear
;
309 MARSHAL_BEGIN(lldpd_port_set
)
310 MARSHAL_STR(lldpd_port_set
, ifname
)
311 MARSHAL_STR(lldpd_port_set
, local_id
)
312 MARSHAL_STR(lldpd_port_set
, local_descr
)
313 #ifdef ENABLE_LLDPMED
314 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_policy
, med_policy
)
315 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_loc
, med_location
)
316 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_power
, med_power
)
319 MARSHAL_POINTER(lldpd_port_set
, lldpd_dot3_power
, dot3_power
)
321 MARSHAL_POINTER(lldpd_port_set
, lldpd_custom
, custom
)
322 MARSHAL_END(lldpd_port_set
);
324 /* Smart mode / Hide mode */
325 #define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */
326 #define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only one proto */
327 #define SMART_INCOMING_ONE_NEIGH (1<<2) /* On reception, keep only one neighbor */
328 #define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */
329 #define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */
330 #define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only one neighbor */
331 #define SMART_INCOMING (SMART_INCOMING_FILTER | \
332 SMART_INCOMING_ONE_PROTO | \
333 SMART_INCOMING_ONE_NEIGH)
334 #define SMART_OUTGOING (SMART_OUTGOING_FILTER | \
335 SMART_OUTGOING_ONE_PROTO | \
336 SMART_OUTGOING_ONE_NEIGH)
338 struct lldpd_config
{
339 int c_paused
; /* lldpd is paused */
340 int c_tx_interval
; /* Transmit interval */
341 int c_smart
; /* Bitmask for smart configuration (see SMART_*) */
342 int c_receiveonly
; /* Receive only mode */
343 int c_max_neighbors
; /* Maximum number of neighbors (per protocol) */
345 char *c_mgmt_pattern
; /* Pattern to match a management address */
346 char *c_cid_pattern
; /* Pattern to match interfaces to use for chassis ID */
347 char *c_iface_pattern
; /* Pattern to match interfaces to use */
349 char *c_platform
; /* Override platform description (for CDP) */
350 char *c_description
; /* Override chassis description */
351 char *c_hostname
; /* Override system name */
352 int c_advertise_version
; /* Should the precise version be advertised? */
353 int c_set_ifdescr
; /* Set interface description */
354 int c_promisc
; /* Interfaces should be in promiscuous mode */
355 int c_cap_advertise
; /* Chassis capabilities advertisement */
356 int c_mgmt_advertise
; /* Management addresses advertisement */
358 #ifdef ENABLE_LLDPMED
359 int c_noinventory
; /* Don't send inventory with LLDP-MED */
360 int c_enable_fast_start
; /* enable fast start */
361 int c_tx_fast_init
; /* Num of lldpd lldppdu's for fast start */
362 int c_tx_fast_interval
; /* Time intr between sends during fast start */
364 int c_tx_hold
; /* Transmit hold */
365 int c_bond_slave_src_mac_type
; /* Src mac type in lldp frames over bond
367 int c_lldp_portid_type
; /* The PortID type */
369 MARSHAL_BEGIN(lldpd_config
)
370 MARSHAL_STR(lldpd_config
, c_mgmt_pattern
)
371 MARSHAL_STR(lldpd_config
, c_cid_pattern
)
372 MARSHAL_STR(lldpd_config
, c_iface_pattern
)
373 MARSHAL_STR(lldpd_config
, c_hostname
)
374 MARSHAL_STR(lldpd_config
, c_platform
)
375 MARSHAL_STR(lldpd_config
, c_description
)
376 MARSHAL_END(lldpd_config
);
380 unsigned char frame
[1];
383 struct lldpd_hardware
;
386 int(*send
)(struct lldpd
*,
387 struct lldpd_hardware
*,
388 char *, size_t); /* Function to send a frame */
389 int(*recv
)(struct lldpd
*,
390 struct lldpd_hardware
*,
391 int, char *, size_t); /* Function to receive a frame */
392 int(*cleanup
)(struct lldpd
*, struct lldpd_hardware
*); /* Cleanup function. */
395 /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
396 * means if an interface becomes enslaved, it will be considered as a new
397 * interface. The same applies for renaming and we include the index in case of
398 * renaming to an existing interface. */
399 struct lldpd_hardware
{
400 TAILQ_ENTRY(lldpd_hardware
) h_entries
;
402 struct lldpd
*h_cfg
; /* Pointer to main configuration */
403 void *h_recv
; /* FD for reception */
404 int h_sendfd
; /* FD for sending, only used by h_ops */
405 int h_mangle
; /* 1 if we have to mangle the MAC address */
406 struct lldpd_ops
*h_ops
; /* Hardware-dependent functions */
407 void *h_data
; /* Hardware-dependent data */
408 void *h_timer
; /* Timer for this port */
411 int h_flags
; /* Packets will be sent only
412 if IFF_RUNNING. Will be
413 removed if this is left
415 int h_ifindex
; /* Interface index, used by SNMP */
416 char h_ifname
[IFNAMSIZ
]; /* Should be unique */
417 u_int8_t h_lladdr
[ETHER_ADDR_LEN
];
421 u_int64_t h_rx_discarded_cnt
;
422 u_int64_t h_rx_unrecognized_cnt
;
423 u_int64_t h_ageout_cnt
;
424 u_int64_t h_insert_cnt
;
425 u_int64_t h_delete_cnt
;
426 u_int64_t h_drop_cnt
;
428 /* Previous values of different stuff. */
429 /* Backup of the previous local port. Used to check if there was a
430 * change to send an immediate update. All those are not marshalled to
432 void *h_lport_previous
;
433 ssize_t h_lport_previous_len
;
434 /* Backup of the previous chassis ID. Used to check if there was a
435 * change and send an LLDP shutdown. */
436 u_int8_t h_lchassis_previous_id_subtype
;
437 char *h_lchassis_previous_id
;
438 int h_lchassis_previous_id_len
;
439 /* Backup of the previous port ID. Used to check if there was a change
440 * and send an LLDP shutdown. */
441 u_int8_t h_lport_previous_id_subtype
;
442 char *h_lport_previous_id
;
443 int h_lport_previous_id_len
;
445 struct lldpd_port h_lport
; /* Port attached to this hardware port */
446 TAILQ_HEAD(, lldpd_port
) h_rports
; /* Remote ports */
448 #ifdef ENABLE_LLDPMED
449 int h_tx_fast
; /* current tx fast start count */
452 MARSHAL_BEGIN(lldpd_hardware
)
453 MARSHAL_IGNORE(lldpd_hardware
, h_entries
.tqe_next
)
454 MARSHAL_IGNORE(lldpd_hardware
, h_entries
.tqe_prev
)
455 MARSHAL_IGNORE(lldpd_hardware
, h_ops
)
456 MARSHAL_IGNORE(lldpd_hardware
, h_data
)
457 MARSHAL_IGNORE(lldpd_hardware
, h_cfg
)
458 MARSHAL_IGNORE(lldpd_hardware
, h_lport_previous
)
459 MARSHAL_IGNORE(lldpd_hardware
, h_lport_previous_len
)
460 MARSHAL_IGNORE(lldpd_hardware
, h_lchassis_previous_id_subtype
)
461 MARSHAL_IGNORE(lldpd_hardware
, h_lchassis_previous_id
)
462 MARSHAL_IGNORE(lldpd_hardware
, h_lchassis_previous_id_len
)
463 MARSHAL_IGNORE(lldpd_hardware
, h_lport_previous_id_subtype
)
464 MARSHAL_IGNORE(lldpd_hardware
, h_lport_previous_id
)
465 MARSHAL_IGNORE(lldpd_hardware
, h_lport_previous_id_len
)
466 MARSHAL_SUBSTRUCT(lldpd_hardware
, lldpd_port
, h_lport
)
467 MARSHAL_SUBTQ(lldpd_hardware
, lldpd_port
, h_rports
)
468 MARSHAL_END(lldpd_hardware
);
470 struct lldpd_interface
{
471 TAILQ_ENTRY(lldpd_interface
) next
;
474 MARSHAL_BEGIN(lldpd_interface
)
475 MARSHAL_TQE(lldpd_interface
, next
)
476 MARSHAL_STR(lldpd_interface
, name
)
477 MARSHAL_END(lldpd_interface
);
478 TAILQ_HEAD(lldpd_interface_list
, lldpd_interface
);
479 MARSHAL_TQ(lldpd_interface_list
, lldpd_interface
);
481 struct lldpd_neighbor_change
{
483 #define NEIGHBOR_CHANGE_DELETED -1
484 #define NEIGHBOR_CHANGE_ADDED 1
485 #define NEIGHBOR_CHANGE_UPDATED 0
487 struct lldpd_port
*neighbor
;
489 MARSHAL_BEGIN(lldpd_neighbor_change
)
490 MARSHAL_STR(lldpd_neighbor_change
, ifname
)
491 MARSHAL_POINTER(lldpd_neighbor_change
, lldpd_port
, neighbor
)
492 MARSHAL_END(lldpd_neighbor_change
);
494 /* Cleanup functions */
495 void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis
*);
496 void lldpd_chassis_cleanup(struct lldpd_chassis
*, int);
497 void lldpd_remote_cleanup(struct lldpd_hardware
*,
498 void(*expire
)(struct lldpd_hardware
*, struct lldpd_port
*),
500 void lldpd_port_cleanup(struct lldpd_port
*, int);
501 void lldpd_config_cleanup(struct lldpd_config
*);
503 void lldpd_ppvid_cleanup(struct lldpd_port
*);
504 void lldpd_vlan_cleanup(struct lldpd_port
*);
505 void lldpd_pi_cleanup(struct lldpd_port
*);
507 void lldpd_custom_list_cleanup(struct lldpd_port
*);