]> git.proxmox.com Git - ovs.git/blob - lib/lldp/lldpd-structs.h
auto-attach: Initial support for Auto-Attach standard
[ovs.git] / lib / lldp / lldpd-structs.h
1 /* -*- mode: c; c-file-style: "openbsd" -*- */
2 /*
3 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
4 *
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.
8 *
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.
16 */
17
18 #ifndef _LLDPD_STRUCTS_H
19 #define _LLDPD_STRUCTS_H
20
21 #include <net/if.h>
22 #ifndef _WIN32
23 #include <netinet/in.h>
24 #include <netinet/if_ether.h>
25 #endif
26 #include <sys/socket.h>
27 #include <sys/types.h>
28 #include "aa-structs.h"
29 #include "lldp-const.h"
30 #include "packets.h"
31
32 enum {
33 LLDPD_AF_UNSPEC = 0,
34 LLDPD_AF_IPV4,
35 LLDPD_AF_IPV6,
36 LLDPD_AF_LAST
37 };
38
39 inline static int
40 lldpd_af(int af)
41 {
42 switch (af) {
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;
47 }
48 }
49
50 #define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */
51 struct lldpd_mgmt {
52 struct ovs_list m_entries;
53 int m_family;
54 union {
55 struct in_addr inet;
56 struct in6_addr inet6;
57 u_int8_t octets[LLDPD_MGMT_MAXADDRSIZE];
58 } m_addr;
59 size_t m_addrsize;
60 u_int32_t m_iface;
61 };
62
63 struct lldpd_chassis {
64 struct ovs_list list;
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 char *c_id;
70 int c_id_len;
71 char *c_name;
72 char *c_descr;
73
74 u_int16_t c_cap_available;
75 u_int16_t c_cap_enabled;
76
77 u_int16_t c_ttl;
78
79 struct lldpd_mgmt c_mgmt;
80 };
81 /* WARNING: any change to this structure should also be reflected into
82 `lldpd_copy_chassis()` which is not using marshaling. */
83
84 struct lldpd_port {
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()`.
96 */
97 u_int8_t p_id_subtype;
98 char *p_id;
99 int p_id_len;
100 char *p_descr;
101 u_int16_t p_mfs;
102 struct lldpd_aa_element_tlv p_element;
103 struct lldpd_aa_isid_vlan_maps_tlv p_isid_vlan_maps;
104 };
105
106 /* Used to modify some port related settings */
107 struct lldpd_port_set {
108 char *ifname;
109 };
110
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
118 one neighbor */
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)
125
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) */
132
133 char *c_mgmt_pattern; /* Pattern to match a management address */
134 char *c_cid_pattern; /* Pattern to match interfaces to use for chassis
135 * ID */
136 char *c_iface_pattern; /* Pattern to match interfaces to use */
137
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
146 * slaves */
147 int c_lldp_portid_type; /* The PortID type */
148 };
149
150 struct lldpd_frame {
151 int size;
152 unsigned char frame[1];
153 };
154
155 struct lldpd_hardware;
156 struct lldpd;
157 struct lldpd_ops {
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 */
165 };
166
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.
171 */
172 struct lldpd_hardware {
173 struct ovs_list h_entries;
174
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 */
182
183 int h_mtu;
184 int h_flags; /* Packets will be sent only
185 * if IFF_RUNNING. Will be
186 * removed if this is left
187 * to 0. */
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];
191
192 u_int64_t h_tx_cnt;
193 u_int64_t h_rx_cnt;
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;
200
201 u_int16_t h_lport_cksum; /* Checksum on local port to see if there
202 * is a change
203 */
204 struct lldpd_port h_lport; /* Port attached to this hardware port */
205 struct lldpd_port h_rports; /* Remote ports */
206 };
207
208 struct lldpd_interface;
209 struct lldpd_interface_list;
210
211 struct lldpd_neighbor_change {
212 char *ifname;
213 #define NEIGHBOR_CHANGE_DELETED -1
214 #define NEIGHBOR_CHANGE_ADDED 1
215 #define NEIGHBOR_CHANGE_UPDATED 0
216 int state;
217 struct lldpd_port *neighbor;
218 };
219
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 *);
227
228 #endif