1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2015 Nicira, Inc.
4 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifndef _LLDPD_STRUCTS_H
20 #define _LLDPD_STRUCTS_H
24 #include <netinet/in.h>
25 #include <netinet/if_ether.h>
27 #include <sys/socket.h>
28 #include <sys/types.h>
29 #include "aa-structs.h"
30 #include "lldp-const.h"
44 case LLDPD_AF_IPV4: return AF_INET;
45 case LLDPD_AF_IPV6: return AF_INET6;
46 case LLDPD_AF_LAST: return AF_MAX;
47 default: return AF_UNSPEC;
51 #define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
53 struct ovs_list m_entries;
57 struct in6_addr inet6;
58 u_int8_t octets[LLDPD_MGMT_MAXADDRSIZE];
64 struct lldpd_chassis {
66 u_int16_t c_refcount; /* Reference count by ports */
67 u_int16_t c_index; /* Monotonic index */
68 u_int8_t c_protocol; /* Protocol used to get this chassis */
69 u_int8_t c_id_subtype;
70 uint8_t *c_id; /* Typically an Ethernet address. */
75 u_int16_t c_cap_available;
76 u_int16_t c_cap_enabled;
80 struct ovs_list c_mgmt; /* Contains "struct lldp_mgmt"s. */
82 /* WARNING: any change to this structure should also be reflected into
83 `lldpd_copy_chassis()` which is not using marshaling. */
86 struct ovs_list p_entries;
87 struct lldpd_chassis *p_chassis; /* Attached chassis */
88 time_t p_lastchange; /* Time of last change of values */
89 time_t p_lastupdate; /* Time of last update received */
90 struct lldpd_frame *p_lastframe; /* Frame received during last update */
91 u_int8_t p_protocol; /* Protocol used to get this port */
92 u_int8_t p_hidden_in:1; /* Considered hidden for reception */
93 u_int8_t p_hidden_out:2; /* Considered hidden for emission */
94 /* Important: all fields that should be ignored to check if a port has
95 * been changed should be before p_id_subtype. Check
96 * `lldpd_reset_timer()`.
98 u_int8_t p_id_subtype;
103 struct lldpd_aa_element_tlv p_element;
104 struct ovs_list p_isid_vlan_maps; /* Contains "struct lldpd_aa_isid_vlan_maps_tlv"s. */
107 /* Used to modify some port related settings */
108 struct lldpd_port_set {
112 /* Smart mode / Hide mode */
113 #define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */
114 #define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only 1 proto */
115 #define SMART_INCOMING_ONE_NEIGH (1<<2) /* On recep., keep only 1 neighbor */
116 #define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */
117 #define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */
118 #define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only
120 #define SMART_INCOMING (SMART_INCOMING_FILTER | \
121 SMART_INCOMING_ONE_PROTO | \
122 SMART_INCOMING_ONE_NEIGH)
123 #define SMART_OUTGOING (SMART_OUTGOING_FILTER | \
124 SMART_OUTGOING_ONE_PROTO | \
125 SMART_OUTGOING_ONE_NEIGH)
127 struct lldpd_config {
128 int c_paused; /* lldpd is paused */
129 int c_tx_interval; /* Transmit interval */
130 int c_smart; /* Bitmask for smart configuration (see SMART_*) */
131 int c_receiveonly; /* Receive only mode */
132 int c_max_neighbors; /* Maximum number of neighbors (per protocol) */
134 char *c_mgmt_pattern; /* Pattern to match a management address */
135 char *c_cid_pattern; /* Pattern to match interfaces to use for chassis
137 char *c_iface_pattern; /* Pattern to match interfaces to use */
139 char *c_platform; /* Override platform description (for CDP) */
140 char *c_description; /* Override chassis description */
141 char *c_hostname; /* Override system name */
142 int c_advertise_version; /* Should the precise version be advertised? */
143 int c_set_ifdescr; /* Set interface description */
144 int c_promisc; /* Interfaces should be in promiscuous mode */
145 int c_tx_hold; /* Transmit hold */
146 int c_bond_slave_src_mac_type; /* Src mac type in lldp frames over bond
148 int c_lldp_portid_type; /* The PortID type */
153 unsigned char frame[];
156 struct lldpd_hardware;
159 int(*send)(struct lldpd *,
160 struct lldpd_hardware*,
161 char *, size_t); /* Function to send a frame */
162 int(*recv)(struct lldpd *,
163 struct lldpd_hardware*,
164 int, char *, size_t); /* Function to receive a frame */
165 int(*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup */
168 /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
169 * means if an interface becomes enslaved, it will be considered as a new
170 * interface. The same applies for renaming and we include the index in case of
171 * renaming to an existing interface.
173 struct lldpd_hardware {
174 struct ovs_list h_entries;
176 struct lldpd *h_cfg; /* Pointer to main configuration */
177 void *h_recv; /* FD for reception */
178 int h_sendfd; /* FD for sending, only used by h_ops */
179 int h_mangle; /* 1 if we have to mangle the MAC address */
180 struct lldpd_ops *h_ops; /* Hardware-dependent functions */
181 void *h_data; /* Hardware-dependent data */
182 void *h_timer; /* Timer for this port */
185 int h_flags; /* Packets will be sent only
186 * if IFF_RUNNING. Will be
187 * removed if this is left
189 int h_ifindex; /* Interface index, used by SNMP */
190 char h_ifname[IFNAMSIZ]; /* Should be unique */
191 u_int8_t h_lladdr[ETH_ADDR_LEN];
195 u_int64_t h_rx_discarded_cnt;
196 u_int64_t h_rx_unrecognized_cnt;
197 u_int64_t h_ageout_cnt;
198 u_int64_t h_insert_cnt;
199 u_int64_t h_delete_cnt;
200 u_int64_t h_drop_cnt;
202 u_int16_t h_lport_cksum; /* Checksum on local port to see if there
205 struct lldpd_port h_lport; /* Port attached to this hardware port */
206 struct ovs_list h_rports; /* Contains "struct lldp_port"s. */
209 struct lldpd_interface;
210 struct lldpd_interface_list;
212 struct lldpd_neighbor_change {
214 #define NEIGHBOR_CHANGE_DELETED -1
215 #define NEIGHBOR_CHANGE_ADDED 1
216 #define NEIGHBOR_CHANGE_UPDATED 0
218 struct lldpd_port *neighbor;
221 /* Cleanup functions */
222 void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *);
223 void lldpd_chassis_cleanup(struct lldpd_chassis *, bool all);
224 void lldpd_remote_cleanup(struct lldpd_hardware *,
225 void (*expire)(struct lldpd_hardware *, struct lldpd_port *), bool all);
226 void lldpd_port_cleanup(struct lldpd_port *, bool all);
227 void lldpd_config_cleanup(struct lldpd_config *);