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>
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;
69 uint8_t *c_id; /* Typically an Ethernet address. */
74 u_int16_t c_cap_available;
75 u_int16_t c_cap_enabled;
79 struct ovs_list c_mgmt; /* Contains "struct lldp_mgmt"s. */
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:1; /* 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 ovs_list p_isid_vlan_maps; /* Contains "struct lldpd_aa_isid_vlan_maps_tlv"s. */
106 /* Smart mode / Hide mode */
107 #define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */
108 #define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only 1 proto */
109 #define SMART_INCOMING_ONE_NEIGH (1<<2) /* On recep., keep only 1 neighbor */
110 #define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */
111 #define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */
112 #define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only
114 #define SMART_INCOMING (SMART_INCOMING_FILTER | \
115 SMART_INCOMING_ONE_PROTO | \
116 SMART_INCOMING_ONE_NEIGH)
117 #define SMART_OUTGOING (SMART_OUTGOING_FILTER | \
118 SMART_OUTGOING_ONE_PROTO | \
119 SMART_OUTGOING_ONE_NEIGH)
121 struct lldpd_config {
122 int c_paused; /* lldpd is paused */
123 int c_tx_interval; /* Transmit interval */
124 int c_smart; /* Bitmask for smart configuration (see SMART_*) */
125 int c_receiveonly; /* Receive only mode */
126 int c_max_neighbors; /* Maximum number of neighbors (per protocol) */
128 char *c_mgmt_pattern; /* Pattern to match a management address */
129 char *c_cid_pattern; /* Pattern to match interfaces to use for chassis
131 char *c_iface_pattern; /* Pattern to match interfaces to use */
133 char *c_platform; /* Override platform description (for CDP) */
134 char *c_description; /* Override chassis description */
135 char *c_hostname; /* Override system name */
136 int c_advertise_version; /* Should the precise version be advertised? */
137 int c_set_ifdescr; /* Set interface description */
138 int c_promisc; /* Interfaces should be in promiscuous mode */
139 int c_tx_hold; /* Transmit hold */
140 int c_bond_slave_src_mac_type; /* Src mac type in lldp frames over bond
142 int c_lldp_portid_type; /* The PortID type */
147 unsigned char frame[];
150 struct lldpd_hardware;
153 int (*send)(struct lldpd *,
154 struct lldpd_hardware *,
155 char *, size_t); /* Function to send a frame */
156 int (*recv)(struct lldpd *,
157 struct lldpd_hardware *,
158 int, char *, size_t); /* Function to receive a frame */
159 int (*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup */
162 /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
163 * means if an interface becomes enslaved, it will be considered as a new
164 * interface. The same applies for renaming and we include the index in case of
165 * renaming to an existing interface.
167 struct lldpd_hardware {
168 struct ovs_list h_entries;
170 struct lldpd *h_cfg; /* Pointer to main configuration */
171 void *h_recv; /* FD for reception */
172 int h_sendfd; /* FD for sending, only used by h_ops */
173 int h_mangle; /* 1 if we have to mangle the MAC address */
174 struct lldpd_ops *h_ops; /* Hardware-dependent functions */
175 void *h_data; /* Hardware-dependent data */
176 void *h_timer; /* Timer for this port */
179 int h_flags; /* Packets will be sent only
180 * if IFF_RUNNING. Will be
181 * removed if this is left
183 int h_ifindex; /* Interface index, used by SNMP */
184 char h_ifname[IFNAMSIZ]; /* Should be unique */
185 struct eth_addr h_lladdr;
189 u_int64_t h_rx_discarded_cnt;
190 u_int64_t h_rx_unrecognized_cnt;
191 u_int64_t h_ageout_cnt;
192 u_int64_t h_insert_cnt;
193 u_int64_t h_delete_cnt;
194 u_int64_t h_drop_cnt;
196 u_int16_t h_lport_cksum; /* Checksum on local port to see if there
199 struct lldpd_port h_lport; /* Port attached to this hardware port */
200 struct ovs_list h_rports; /* Contains "struct lldp_port"s. */
203 struct lldpd_interface;
204 struct lldpd_interface_list;
206 struct lldpd_neighbor_change {
208 #define NEIGHBOR_CHANGE_DELETED -1
209 #define NEIGHBOR_CHANGE_ADDED 1
210 #define NEIGHBOR_CHANGE_UPDATED 0
212 struct lldpd_port *neighbor;
215 /* Cleanup functions */
216 void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *);
217 void lldpd_chassis_cleanup(struct lldpd_chassis *, bool all);
218 void lldpd_remote_cleanup(struct lldpd_hardware *,
219 void (*expire)(struct lldpd_hardware *, struct lldpd_port *), bool all);
220 void lldpd_port_cleanup(struct lldpd_port *, bool all);
221 void lldpd_config_cleanup(struct lldpd_config *);