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
23 #include <netinet/in.h>
24 #include <netinet/if_ether.h>
26 #include <sys/socket.h>
27 #include <sys/types.h>
28 #include "aa-structs.h"
29 #include "lldp-const.h"
43 case LLDPD_AF_IPV4
: return AF_INET
;
44 case LLDPD_AF_IPV6
: return AF_INET6
;
45 case LLDPD_AF_LAST
: return AF_MAX
;
46 default: return AF_UNSPEC
;
50 #define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
52 struct ovs_list m_entries
;
56 struct in6_addr inet6
;
57 u_int8_t octets
[LLDPD_MGMT_MAXADDRSIZE
];
63 struct lldpd_chassis
{
65 u_int16_t c_refcount
; /* Reference count by ports */
66 u_int16_t c_index
; /* Monotonic index */
67 u_int8_t c_protocol
; /* Protocol used to get this chassis */
68 u_int8_t c_id_subtype
;
74 u_int16_t c_cap_available
;
75 u_int16_t c_cap_enabled
;
79 struct lldpd_mgmt c_mgmt
;
81 /* WARNING: any change to this structure should also be reflected into
82 `lldpd_copy_chassis()` which is not using marshaling. */
85 struct ovs_list p_entries
;
86 struct lldpd_chassis
*p_chassis
; /* Attached chassis */
87 time_t p_lastchange
; /* Time of last change of values */
88 time_t p_lastupdate
; /* Time of last update received */
89 struct lldpd_frame
*p_lastframe
; /* Frame received during last update */
90 u_int8_t p_protocol
; /* Protocol used to get this port */
91 u_int8_t p_hidden_in
:1; /* Considered hidden for reception */
92 u_int8_t p_hidden_out
:2; /* Considered hidden for emission */
93 /* Important: all fields that should be ignored to check if a port has
94 * been changed should be before p_id_subtype. Check
95 * `lldpd_reset_timer()`.
97 u_int8_t p_id_subtype
;
102 struct lldpd_aa_element_tlv p_element
;
103 struct lldpd_aa_isid_vlan_maps_tlv p_isid_vlan_maps
;
106 /* Used to modify some port related settings */
107 struct lldpd_port_set
{
111 /* Smart mode / Hide mode */
112 #define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */
113 #define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only 1 proto */
114 #define SMART_INCOMING_ONE_NEIGH (1<<2) /* On recep., keep only 1 neighbor */
115 #define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */
116 #define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */
117 #define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only
119 #define SMART_INCOMING (SMART_INCOMING_FILTER | \
120 SMART_INCOMING_ONE_PROTO | \
121 SMART_INCOMING_ONE_NEIGH)
122 #define SMART_OUTGOING (SMART_OUTGOING_FILTER | \
123 SMART_OUTGOING_ONE_PROTO | \
124 SMART_OUTGOING_ONE_NEIGH)
126 struct lldpd_config
{
127 int c_paused
; /* lldpd is paused */
128 int c_tx_interval
; /* Transmit interval */
129 int c_smart
; /* Bitmask for smart configuration (see SMART_*) */
130 int c_receiveonly
; /* Receive only mode */
131 int c_max_neighbors
; /* Maximum number of neighbors (per protocol) */
133 char *c_mgmt_pattern
; /* Pattern to match a management address */
134 char *c_cid_pattern
; /* Pattern to match interfaces to use for chassis
136 char *c_iface_pattern
; /* Pattern to match interfaces to use */
138 char *c_platform
; /* Override platform description (for CDP) */
139 char *c_description
; /* Override chassis description */
140 char *c_hostname
; /* Override system name */
141 int c_advertise_version
; /* Should the precise version be advertised? */
142 int c_set_ifdescr
; /* Set interface description */
143 int c_promisc
; /* Interfaces should be in promiscuous mode */
144 int c_tx_hold
; /* Transmit hold */
145 int c_bond_slave_src_mac_type
; /* Src mac type in lldp frames over bond
147 int c_lldp_portid_type
; /* The PortID type */
152 unsigned char frame
[1];
155 struct lldpd_hardware
;
158 int(*send
)(struct lldpd
*,
159 struct lldpd_hardware
*,
160 char *, size_t); /* Function to send a frame */
161 int(*recv
)(struct lldpd
*,
162 struct lldpd_hardware
*,
163 int, char *, size_t); /* Function to receive a frame */
164 int(*cleanup
)(struct lldpd
*, struct lldpd_hardware
*); /* Cleanup */
167 /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
168 * means if an interface becomes enslaved, it will be considered as a new
169 * interface. The same applies for renaming and we include the index in case of
170 * renaming to an existing interface.
172 struct lldpd_hardware
{
173 struct ovs_list h_entries
;
175 struct lldpd
*h_cfg
; /* Pointer to main configuration */
176 void *h_recv
; /* FD for reception */
177 int h_sendfd
; /* FD for sending, only used by h_ops */
178 int h_mangle
; /* 1 if we have to mangle the MAC address */
179 struct lldpd_ops
*h_ops
; /* Hardware-dependent functions */
180 void *h_data
; /* Hardware-dependent data */
181 void *h_timer
; /* Timer for this port */
184 int h_flags
; /* Packets will be sent only
185 * if IFF_RUNNING. Will be
186 * removed if this is left
188 int h_ifindex
; /* Interface index, used by SNMP */
189 char h_ifname
[IFNAMSIZ
]; /* Should be unique */
190 u_int8_t h_lladdr
[ETH_ADDR_LEN
];
194 u_int64_t h_rx_discarded_cnt
;
195 u_int64_t h_rx_unrecognized_cnt
;
196 u_int64_t h_ageout_cnt
;
197 u_int64_t h_insert_cnt
;
198 u_int64_t h_delete_cnt
;
199 u_int64_t h_drop_cnt
;
201 u_int16_t h_lport_cksum
; /* Checksum on local port to see if there
204 struct lldpd_port h_lport
; /* Port attached to this hardware port */
205 struct lldpd_port h_rports
; /* Remote ports */
208 struct lldpd_interface
;
209 struct lldpd_interface_list
;
211 struct lldpd_neighbor_change
{
213 #define NEIGHBOR_CHANGE_DELETED -1
214 #define NEIGHBOR_CHANGE_ADDED 1
215 #define NEIGHBOR_CHANGE_UPDATED 0
217 struct lldpd_port
*neighbor
;
220 /* Cleanup functions */
221 void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis
*);
222 void lldpd_chassis_cleanup(struct lldpd_chassis
*, int);
223 void lldpd_remote_cleanup(struct lldpd_hardware
*,
224 void (*expire
)(struct lldpd_hardware
*, struct lldpd_port
*), int);
225 void lldpd_port_cleanup(struct lldpd_port
*, int);
226 void lldpd_config_cleanup(struct lldpd_config
*);