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>
27 #ifndef INCLUDE_LINUX_IF_H
30 # include <arpa/inet.h>
31 # include <linux/if.h>
33 #include <net/ethernet.h>
34 #include <netinet/in.h>
35 #include <sys/queue.h>
37 #include "compat/compat.h"
39 #include "lldp-const.h"
43 TAILQ_ENTRY(lldpd_ppvid
) p_entries
;
44 u_int8_t p_cap_status
;
47 MARSHAL_BEGIN(lldpd_ppvid
)
48 MARSHAL_TQE(lldpd_ppvid
, p_entries
)
52 TAILQ_ENTRY(lldpd_vlan
) v_entries
;
56 MARSHAL_BEGIN(lldpd_vlan
)
57 MARSHAL_TQE(lldpd_vlan
, v_entries
)
58 MARSHAL_STR(lldpd_vlan
, v_name
)
62 TAILQ_ENTRY(lldpd_pi
) p_entries
;
66 MARSHAL_BEGIN(lldpd_pi
)
67 MARSHAL_TQE(lldpd_pi
, p_entries
)
68 MARSHAL_FSTR(lldpd_pi
, p_pi
, p_pi_len
)
73 struct lldpd_med_policy
{
74 u_int8_t index
; /* Not used. */
82 MARSHAL(lldpd_med_policy
);
84 struct lldpd_med_loc
{
85 u_int8_t index
; /* Not used. */
90 MARSHAL_BEGIN(lldpd_med_loc
)
91 MARSHAL_FSTR(lldpd_med_loc
, data
, data_len
)
94 struct lldpd_med_power
{
95 u_int8_t devicetype
; /* PD or PSE */
100 MARSHAL(lldpd_med_power
);
104 struct lldpd_dot3_macphy
{
105 u_int8_t autoneg_support
;
106 u_int8_t autoneg_enabled
;
107 u_int16_t autoneg_advertised
;
111 struct lldpd_dot3_power
{
115 u_int8_t paircontrol
;
118 u_int8_t powertype
; /* If set to LLDP_DOT3_POWER_8023AT_OFF,
119 following fields have no meaning */
125 MARSHAL(lldpd_dot3_power
);
139 case LLDPD_AF_IPV4
: return AF_INET
;
140 case LLDPD_AF_IPV6
: return AF_INET6
;
141 case LLDPD_AF_LAST
: return AF_MAX
;
142 default: return AF_UNSPEC
;
146 #define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
148 TAILQ_ENTRY(lldpd_mgmt
) m_entries
;
152 struct in6_addr inet6
;
153 u_int8_t octets
[LLDPD_MGMT_MAXADDRSIZE
];
158 MARSHAL_BEGIN(lldpd_mgmt
)
159 MARSHAL_TQE(lldpd_mgmt
, m_entries
)
162 struct lldpd_chassis
{
163 TAILQ_ENTRY(lldpd_chassis
) c_entries
;
164 u_int16_t c_refcount
; /* Reference count by ports */
165 u_int16_t c_index
; /* Monotonic index */
166 u_int8_t c_protocol
; /* Protocol used to get this chassis */
167 u_int8_t c_id_subtype
;
173 u_int16_t c_cap_available
;
174 u_int16_t c_cap_enabled
;
178 TAILQ_HEAD(, lldpd_mgmt
) c_mgmt
;
180 #ifdef ENABLE_LLDPMED
181 u_int16_t c_med_cap_available
;
193 /* WARNING: any change to this structure should also be reflected into
194 `lldpd_copy_chassis()` which is not using marshaling. */
195 MARSHAL_BEGIN(lldpd_chassis
)
196 MARSHAL_IGNORE(lldpd_chassis
, c_entries
.tqe_next
)
197 MARSHAL_IGNORE(lldpd_chassis
, c_entries
.tqe_prev
)
198 MARSHAL_FSTR(lldpd_chassis
, c_id
, c_id_len
)
199 MARSHAL_STR(lldpd_chassis
, c_name
)
200 MARSHAL_STR(lldpd_chassis
, c_descr
)
201 MARSHAL_SUBTQ(lldpd_chassis
, lldpd_mgmt
, c_mgmt
)
202 #ifdef ENABLE_LLDPMED
203 MARSHAL_STR(lldpd_chassis
, c_med_hw
)
204 MARSHAL_STR(lldpd_chassis
, c_med_fw
)
205 MARSHAL_STR(lldpd_chassis
, c_med_sw
)
206 MARSHAL_STR(lldpd_chassis
, c_med_sn
)
207 MARSHAL_STR(lldpd_chassis
, c_med_manuf
)
208 MARSHAL_STR(lldpd_chassis
, c_med_model
)
209 MARSHAL_STR(lldpd_chassis
, c_med_asset
)
215 TAILQ_ENTRY(lldpd_port
) p_entries
;
216 struct lldpd_chassis
*p_chassis
; /* Attached chassis */
217 time_t p_lastchange
; /* Time of last change of values */
218 time_t p_lastupdate
; /* Time of last update received */
219 struct lldpd_frame
*p_lastframe
; /* Frame received during last update */
220 u_int8_t p_protocol
; /* Protocol used to get this port */
221 u_int8_t p_id_subtype
;
226 u_int8_t p_hidden_in
:1; /* Considered as hidden for reception */
227 u_int8_t p_hidden_out
:2; /* Considered as hidden for emission */
231 u_int32_t p_aggregid
;
232 struct lldpd_dot3_macphy p_macphy
;
233 struct lldpd_dot3_power p_power
;
236 #ifdef ENABLE_LLDPMED
237 u_int16_t p_med_cap_enabled
;
238 struct lldpd_med_policy p_med_policy
[LLDP_MED_APPTYPE_LAST
];
239 struct lldpd_med_loc p_med_location
[LLDP_MED_LOCFORMAT_LAST
];
240 struct lldpd_med_power p_med_power
;
245 TAILQ_HEAD(, lldpd_vlan
) p_vlans
;
246 TAILQ_HEAD(, lldpd_ppvid
) p_ppvids
;
247 TAILQ_HEAD(, lldpd_pi
) p_pids
;
250 MARSHAL_BEGIN(lldpd_port
)
251 MARSHAL_TQE(lldpd_port
, p_entries
)
252 MARSHAL_POINTER(lldpd_port
, lldpd_chassis
, p_chassis
)
253 MARSHAL_IGNORE(lldpd_port
, p_lastframe
)
254 MARSHAL_FSTR(lldpd_port
, p_id
, p_id_len
)
255 MARSHAL_STR(lldpd_port
, p_descr
)
256 #ifdef ENABLE_LLDPMED
257 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[0])
258 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[1])
259 MARSHAL_SUBSTRUCT(lldpd_port
, lldpd_med_loc
, p_med_location
[2])
262 MARSHAL_SUBTQ(lldpd_port
, lldpd_vlan
, p_vlans
)
263 MARSHAL_SUBTQ(lldpd_port
, lldpd_ppvid
, p_ppvids
)
264 MARSHAL_SUBTQ(lldpd_port
, lldpd_pi
, p_pids
)
268 /* Used to modify some port related settings */
269 struct lldpd_port_set
{
271 #ifdef ENABLE_LLDPMED
272 struct lldpd_med_policy
*med_policy
;
273 struct lldpd_med_loc
*med_location
;
274 struct lldpd_med_power
*med_power
;
277 struct lldpd_dot3_power
*dot3_power
;
280 MARSHAL_BEGIN(lldpd_port_set
)
281 MARSHAL_STR(lldpd_port_set
, ifname
)
282 #ifdef ENABLE_LLDPMED
283 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_policy
, med_policy
)
284 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_loc
, med_location
)
285 MARSHAL_POINTER(lldpd_port_set
, lldpd_med_power
, med_power
)
288 MARSHAL_POINTER(lldpd_port_set
, lldpd_dot3_power
, dot3_power
)
294 unsigned char frame
[1];
297 struct lldpd_hardware
;
300 int(*send
)(struct lldpd
*,
301 struct lldpd_hardware
*,
302 char *, size_t); /* Function to send a frame */
303 int(*recv
)(struct lldpd
*,
304 struct lldpd_hardware
*,
305 int, char *, size_t); /* Function to receive a frame */
306 int(*cleanup
)(struct lldpd
*, struct lldpd_hardware
*); /* Cleanup function. */
309 /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
310 * means if an interface becomes enslaved, it will be considered as a new
311 * interface. The same applies for renaming and we include the index in case of
312 * renaming to an existing interface. */
313 struct lldpd_hardware
{
314 TAILQ_ENTRY(lldpd_hardware
) h_entries
;
316 struct lldpd
*h_cfg
; /* Pointer to main configuration */
317 void *h_recv
; /* FD for reception */
318 int h_sendfd
; /* FD for sending, only used by h_ops */
319 struct lldpd_ops
*h_ops
; /* Hardware-dependent functions */
320 void *h_data
; /* Hardware-dependent data */
323 int h_flags
; /* Packets will be sent only
324 if IFF_RUNNING. Will be
325 removed if this is left
327 int h_ifindex
; /* Interface index, used by SNMP */
328 char h_ifname
[IFNAMSIZ
]; /* Should be unique */
329 u_int8_t h_lladdr
[ETHER_ADDR_LEN
];
333 u_int64_t h_rx_discarded_cnt
;
334 u_int64_t h_rx_ageout_cnt
;
335 u_int64_t h_rx_unrecognized_cnt
;
337 struct lldpd_port h_lport
; /* Port attached to this hardware port */
338 TAILQ_HEAD(, lldpd_port
) h_rports
; /* Remote ports */
340 MARSHAL_BEGIN(lldpd_hardware
)
341 MARSHAL_IGNORE(lldpd_hardware
, h_entries
.tqe_next
)
342 MARSHAL_IGNORE(lldpd_hardware
, h_entries
.tqe_prev
)
343 MARSHAL_IGNORE(lldpd_hardware
, h_ops
)
344 MARSHAL_IGNORE(lldpd_hardware
, h_data
)
345 MARSHAL_IGNORE(lldpd_hardware
, h_cfg
)
346 MARSHAL_SUBSTRUCT(lldpd_hardware
, lldpd_port
, h_lport
)
347 MARSHAL_SUBTQ(lldpd_hardware
, lldpd_port
, h_rports
)
350 struct lldpd_interface
{
351 TAILQ_ENTRY(lldpd_interface
) next
;
354 MARSHAL_BEGIN(lldpd_interface
)
355 MARSHAL_TQE(lldpd_interface
, next
)
356 MARSHAL_STR(lldpd_interface
, name
)
358 TAILQ_HEAD(lldpd_interface_list
, lldpd_interface
);
359 MARSHAL_TQ(lldpd_interface_list
, lldpd_interface
);
361 struct lldpd_neighbor_change
{
363 #define NEIGHBOR_CHANGE_DELETED -1
364 #define NEIGHBOR_CHANGE_ADDED 1
365 #define NEIGHBOR_CHANGE_UPDATED 0
367 struct lldpd_port
*neighbor
;
369 MARSHAL_BEGIN(lldpd_neighbor_change
)
370 MARSHAL_STR(lldpd_neighbor_change
, ifname
)
371 MARSHAL_POINTER(lldpd_neighbor_change
, lldpd_port
, neighbor
)
374 /* Cleanup functions */
375 void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis
*);
376 void lldpd_chassis_cleanup(struct lldpd_chassis
*, int);
377 void lldpd_remote_cleanup(struct lldpd_hardware
*,
378 void(*expire
)(struct lldpd_hardware
*, struct lldpd_port
*));
379 void lldpd_port_cleanup(struct lldpd_port
*, int);
381 void lldpd_ppvid_cleanup(struct lldpd_port
*);
382 void lldpd_vlan_cleanup(struct lldpd_port
*);
383 void lldpd_pi_cleanup(struct lldpd_port
*);