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