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/if_ether.h>
38 #include <netinet/in.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
)
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
)
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
)
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
)
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
];
162 MARSHAL_BEGIN(lldpd_mgmt
)
163 MARSHAL_TQE(lldpd_mgmt
, m_entries
)
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
)
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 */
225 u_int8_t p_id_subtype
;
230 u_int8_t p_hidden_in
:1; /* Considered as hidden for reception */
231 u_int8_t p_hidden_out
:2; /* Considered as hidden for emission */
235 u_int32_t p_aggregid
;
236 struct lldpd_dot3_macphy p_macphy
;
237 struct lldpd_dot3_power p_power
;
240 #ifdef ENABLE_LLDPMED
241 u_int16_t p_med_cap_enabled
;
242 struct lldpd_med_policy p_med_policy
[LLDP_MED_APPTYPE_LAST
];
243 struct lldpd_med_loc p_med_location
[LLDP_MED_LOCFORMAT_LAST
];
244 struct lldpd_med_power p_med_power
;
249 TAILQ_HEAD(, lldpd_vlan
) p_vlans
;
250 TAILQ_HEAD(, lldpd_ppvid
) p_ppvids
;
251 TAILQ_HEAD(, lldpd_pi
) p_pids
;
254 MARSHAL_BEGIN(lldpd_port
)
255 MARSHAL_TQE(lldpd_port
, p_entries
)
256 MARSHAL_POINTER(lldpd_port
, lldpd_chassis
, p_chassis
)
257 MARSHAL_IGNORE(lldpd_port
, p_lastframe
)
258 MARSHAL_FSTR(lldpd_port
, p_id
, p_id_len
)
259 MARSHAL_STR(lldpd_port
, p_descr
)
260 #ifdef ENABLE_LLDPMED
261 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[0])
262 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[1])
263 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[2])
266 MARSHAL_SUBTQ(lldpd_port
, lldpd_vlan
, p_vlans
)
267 MARSHAL_SUBTQ(lldpd_port
, lldpd_ppvid
, p_ppvids
)
268 MARSHAL_SUBTQ(lldpd_port
, lldpd_pi
, p_pids
)
272 /* Used to modify some port related settings */
273 struct lldpd_port_set
{
275 #ifdef ENABLE_LLDPMED
276 struct lldpd_med_policy
*med_policy
;
277 struct lldpd_med_loc
*med_location
;
278 struct lldpd_med_power
*med_power
;
281 struct lldpd_dot3_power
*dot3_power
;
284 MARSHAL_BEGIN(lldpd_port_set
)
285 MARSHAL_STR(lldpd_port_set
, ifname
)
286 #ifdef ENABLE_LLDPMED
287 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_policy
, med_policy
)
288 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_loc
, med_location
)
289 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_power
, med_power
)
292 MARSHAL_POINTER(lldpd_port_set
, lldpd_dot3_power
, dot3_power
)
296 /* Smart mode / Hide mode */
297 #define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */
298 #define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only one proto */
299 #define SMART_INCOMING_ONE_NEIGH (1<<2) /* On reception, keep only one neighbor */
300 #define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */
301 #define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */
302 #define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only one neighbor */
303 #define SMART_INCOMING (SMART_INCOMING_FILTER | \
304 SMART_INCOMING_ONE_PROTO | \
305 SMART_INCOMING_ONE_NEIGH)
306 #define SMART_OUTGOING (SMART_OUTGOING_FILTER | \
307 SMART_OUTGOING_ONE_PROTO | \
308 SMART_OUTGOING_ONE_NEIGH)
310 struct lldpd_config
{
311 int c_tx_interval
; /* Transmit interval */
312 int c_smart
; /* Bitmask for smart configuration (see SMART_*) */
313 int c_receiveonly
; /* Receive only mode */
315 char *c_mgmt_pattern
; /* Pattern to match a management address */
316 char *c_cid_pattern
; /* Pattern to match interfaces to use for chassis ID */
317 char *c_iface_pattern
; /* Pattern to match interfaces to use */
319 char *c_platform
; /* Override platform description (for CDP) */
320 char *c_description
; /* Override chassis description */
321 int c_advertise_version
; /* Should the precise version be advertised? */
323 #ifdef ENABLE_LLDPMED
324 int c_noinventory
; /* Don't send inventory with LLDP-MED */
327 MARSHAL_BEGIN(lldpd_config
)
328 MARSHAL_STR(lldpd_config
, c_mgmt_pattern
)
329 MARSHAL_STR(lldpd_config
, c_cid_pattern
)
330 MARSHAL_STR(lldpd_config
, c_iface_pattern
)
331 MARSHAL_STR(lldpd_config
, c_platform
)
332 MARSHAL_STR(lldpd_config
, c_description
)
337 unsigned char frame
[1];
340 struct lldpd_hardware
;
343 int(*send
)(struct lldpd
*,
344 struct lldpd_hardware
*,
345 char *, size_t); /* Function to send a frame */
346 int(*recv
)(struct lldpd
*,
347 struct lldpd_hardware
*,
348 int, char *, size_t); /* Function to receive a frame */
349 int(*cleanup
)(struct lldpd
*, struct lldpd_hardware
*); /* Cleanup function. */
352 /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
353 * means if an interface becomes enslaved, it will be considered as a new
354 * interface. The same applies for renaming and we include the index in case of
355 * renaming to an existing interface. */
356 struct lldpd_hardware
{
357 TAILQ_ENTRY(lldpd_hardware
) h_entries
;
359 struct lldpd
*h_cfg
; /* Pointer to main configuration */
360 void *h_recv
; /* FD for reception */
361 int h_sendfd
; /* FD for sending, only used by h_ops */
362 struct lldpd_ops
*h_ops
; /* Hardware-dependent functions */
363 void *h_data
; /* Hardware-dependent data */
366 int h_flags
; /* Packets will be sent only
367 if IFF_RUNNING. Will be
368 removed if this is left
370 int h_ifindex
; /* Interface index, used by SNMP */
371 char h_ifname
[IFNAMSIZ
]; /* Should be unique */
372 u_int8_t h_lladdr
[ETHER_ADDR_LEN
];
376 u_int64_t h_rx_discarded_cnt
;
377 u_int64_t h_rx_unrecognized_cnt
;
378 u_int64_t h_ageout_cnt
;
379 u_int64_t h_insert_cnt
;
380 u_int64_t h_delete_cnt
;
382 struct lldpd_port h_lport
; /* Port attached to this hardware port */
383 TAILQ_HEAD(, lldpd_port
) h_rports
; /* Remote ports */
385 MARSHAL_BEGIN(lldpd_hardware
)
386 MARSHAL_IGNORE(lldpd_hardware
, h_entries
.tqe_next
)
387 MARSHAL_IGNORE(lldpd_hardware
, h_entries
.tqe_prev
)
388 MARSHAL_IGNORE(lldpd_hardware
, h_ops
)
389 MARSHAL_IGNORE(lldpd_hardware
, h_data
)
390 MARSHAL_IGNORE(lldpd_hardware
, h_cfg
)
391 MARSHAL_SUBSTRUCT(lldpd_hardware
, lldpd_port
, h_lport
)
392 MARSHAL_SUBTQ(lldpd_hardware
, lldpd_port
, h_rports
)
395 struct lldpd_interface
{
396 TAILQ_ENTRY(lldpd_interface
) next
;
399 MARSHAL_BEGIN(lldpd_interface
)
400 MARSHAL_TQE(lldpd_interface
, next
)
401 MARSHAL_STR(lldpd_interface
, name
)
403 TAILQ_HEAD(lldpd_interface_list
, lldpd_interface
);
404 MARSHAL_TQ(lldpd_interface_list
, lldpd_interface
);
406 struct lldpd_neighbor_change
{
408 #define NEIGHBOR_CHANGE_DELETED -1
409 #define NEIGHBOR_CHANGE_ADDED 1
410 #define NEIGHBOR_CHANGE_UPDATED 0
412 struct lldpd_port
*neighbor
;
414 MARSHAL_BEGIN(lldpd_neighbor_change
)
415 MARSHAL_STR(lldpd_neighbor_change
, ifname
)
416 MARSHAL_POINTER(lldpd_neighbor_change
, lldpd_port
, neighbor
)
419 /* Cleanup functions */
420 void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis
*);
421 void lldpd_chassis_cleanup(struct lldpd_chassis
*, int);
422 void lldpd_remote_cleanup(struct lldpd_hardware
*,
423 void(*expire
)(struct lldpd_hardware
*, struct lldpd_port
*));
424 void lldpd_port_cleanup(struct lldpd_port
*, int);
425 void lldpd_config_cleanup(struct lldpd_config
*);
427 void lldpd_ppvid_cleanup(struct lldpd_port
*);
428 void lldpd_vlan_cleanup(struct lldpd_port
*);
429 void lldpd_pi_cleanup(struct lldpd_port
*);