]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/lldpd.h
Ignore unknown ORG TLV. Thanks to Michael Hanig for noticing it.
[thirdparty/lldpd.git] / src / lldpd.h
CommitLineData
43c02e7b
VB
1/*
2 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _LLDPD_H
18#define _LLDPD_H
19
20#if HAVE_CONFIG_H
21 #include <config.h>
22#endif
23
24#define _GNU_SOURCE 1
25#include <stdlib.h>
26#include <string.h>
27#include <sys/queue.h>
28#ifndef INCLUDE_LINUX_IF_H
29#include <net/if.h>
30#else
31#include <arpa/inet.h>
32#include <linux/if.h>
33#endif
34#include <net/ethernet.h>
35#include <netinet/in.h>
36
37#include "compat.h"
38#include "lldp.h"
39#include "cdp.h"
40#include "sonmp.h"
41#include "edp.h"
42
43#define LLDPD_TTL 120
44#define LLDPD_TX_DELAY 30
45#define LLDPD_TX_MSGDELAY 1
46#define LLDPD_CTL_SOCKET "/var/run/lldpd.socket"
47#define LLDPD_PID_FILE "/var/run/lldpd.pid"
48
49#define UNIX_PATH_MAX 108
50
51#define USING_AGENTX_SUBAGENT_MODULE 1
52
53struct lldpd_vlan {
54 TAILQ_ENTRY(lldpd_vlan) v_entries;
55 char *v_name;
56 u_int16_t v_vid;
57};
58#define STRUCT_LLDPD_VLAN "Lsw"
59
60struct lldpd_chassis {
61 u_int8_t c_id_subtype;
62 char *c_id;
63 int c_id_len;
64 char *c_name;
65 char *c_descr;
66
67 u_int16_t c_cap_available;
68 u_int16_t c_cap_enabled;
69
70 u_int16_t c_ttl;
71
72 struct in_addr c_mgmt;
73 u_int32_t c_mgmt_if;
74};
75#define STRUCT_LLDPD_CHASSIS "bCsswwwll"
76
77struct lldpd_port {
78 u_int8_t p_id_subtype;
79 char *p_id;
80 int p_id_len;
81 char *p_descr;
82
83 /* Dot3 stuff */
84 u_int32_t p_aggregid;
85 u_int8_t p_autoneg_support;
86 u_int8_t p_autoneg_enabled;
87 u_int16_t p_autoneg_advertised;
88 u_int16_t p_mau_type;
89
90 TAILQ_HEAD(, lldpd_vlan) p_vlans;
91};
92#define STRUCT_LLDPD_PORT "bCslbbwwPP"
93
94struct lldpd_frame {
95 int size;
96 unsigned char frame[];
97};
98
99struct lldpd_hardware {
100 TAILQ_ENTRY(lldpd_hardware) h_entries;
101
102#define INTERFACE_OPENED(x) ((x)->h_raw != -1)
103
104 int h_raw;
105 int h_raw_real; /* For bonding */
106 int h_master; /* For bonding */
107
108#define LLDPD_MODE_ANY 0
109#define LLDPD_MODE_LLDP 1
110#define LLDPD_MODE_CDPV1 2
111#define LLDPD_MODE_CDPV2 3
112#define LLDPD_MODE_SONMP 4
113#define LLDPD_MODE_EDP 5
114 int h_mode;
115
116 int h_flags;
117 int h_mtu;
118 char h_ifname[IFNAMSIZ];
119 u_int8_t h_lladdr[ETHER_ADDR_LEN];
120
121 u_int64_t h_tx_cnt;
122 u_int64_t h_rx_cnt;
123 u_int64_t h_rx_discarded_cnt;
124 u_int64_t h_rx_ageout_cnt;
125
126 u_int8_t *h_proto_macs;
127 time_t h_start_probe;
128
129 struct lldpd_port h_lport;
130 time_t h_llastchange;
131 struct lldpd_frame *h_llastframe;
132
133 time_t h_rlastchange;
134 time_t h_rlastupdate;
135 int h_rid;
136 struct lldpd_frame *h_rlastframe;
137 struct lldpd_port *h_rport;
138 struct lldpd_chassis *h_rchassis;
139};
140
50a89ca7
VB
141/* lldpd_vif can be casted to lldpd_hardware on some cases */
142struct lldpd_vif {
143 TAILQ_ENTRY(lldpd_vif) vif_entries;
144 int vif_raw;
145 int vif_raw_real; /* Not used */
146 int vif_master; /* Not used */
147 int vif_mode; /* Not used */
148 int vif_flags;
149 int vif_mtu;
150 char vif_ifname[IFNAMSIZ];
151
152 /* No more compatibility with struct lldpd_hardware from here */
153 struct lldpd_hardware *vif_real;
154};
155
43c02e7b
VB
156struct lldpd_interface {
157 TAILQ_ENTRY(lldpd_interface) next;
158 char *name;
159};
160#define STRUCT_LLDPD_INTERFACE "Ls"
161
162struct lldpd_client {
163 TAILQ_ENTRY(lldpd_client) next;
164 int fd;
165};
166
167#define PROTO_SEND_SIG struct lldpd *, struct lldpd_chassis *, struct lldpd_hardware *
168#define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, struct lldpd_port **
169#define PROTO_GUESS_SIG char *, int
170
171struct lldpd;
172struct protocol {
173 int mode; /* > 0 mode identifier (unique per protocol) */
174 int enabled; /* Is this protocol enabled? */
175 char *name; /* Name of protocol */
176 char arg; /* Argument to enable this protocol */
177 int(*send)(PROTO_SEND_SIG); /* How to send a frame */
178 int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
179 int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */
180 u_int8_t mac[ETH_ALEN]; /* Destination MAC address used by this protocol */
181 struct sock_filter *filter; /* BPF filter */
182 size_t filterlen; /* Size of BPF filter */
183};
184
185struct lldpd {
186 int g_sock;
187 int g_delay;
188
189 struct protocol *g_protocols;
190 int g_multi; /* Set to 1 if multiple protocols */
191 int g_probe_time;
766f32b3 192 int g_listen_vlans;
43c02e7b
VB
193
194 time_t g_lastsent;
195 int g_lastrid;
196#ifdef USE_SNMP
197 int g_snmp;
198#endif /* USE_SNMP */
199
200 /* Unix socket handling */
201 int g_ctl;
202 TAILQ_HEAD(, lldpd_client) g_clients;
203
204 char *g_mgmt_pattern;
205
206 struct lldpd_chassis g_lchassis;
207
208 TAILQ_HEAD(, lldpd_hardware) g_hardware;
50a89ca7 209 TAILQ_HEAD(, lldpd_vif) g_vif;
43c02e7b
VB
210};
211
212enum hmsg_type {
213 HMSG_NONE,
214 HMSG_GET_INTERFACES,
215 HMSG_GET_CHASSIS,
216 HMSG_GET_PORT,
217 HMSG_GET_VLANS,
218 HMSG_SHUTDOWN
219};
220
221struct hmsg_hdr {
222 enum hmsg_type type;
223 int16_t len;
224 pid_t pid;
225} __attribute__ ((__packed__));
226
227struct hmsg {
228 struct hmsg_hdr hdr;
229 void *data;
230} __attribute__ ((__packed__));
231
232#define HMSG_HEADER_SIZE sizeof(struct hmsg_hdr)
233#define MAX_HMSGSIZE 8192
234
235/* lldpd.c */
236void lldpd_cleanup(struct lldpd *);
237void lldpd_vlan_cleanup(struct lldpd_port *);
238void lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int);
239void lldpd_port_cleanup(struct lldpd_port *);
240void lldpd_chassis_cleanup(struct lldpd_chassis *);
241
242/* lldp.c */
243int lldp_send(PROTO_SEND_SIG);
244int lldp_decode(PROTO_DECODE_SIG);
245
246/* cdp.c */
247int cdpv1_send(PROTO_SEND_SIG);
248int cdpv2_send(PROTO_SEND_SIG);
249int cdp_decode(PROTO_DECODE_SIG);
250int cdpv1_guess(PROTO_GUESS_SIG);
251int cdpv2_guess(PROTO_GUESS_SIG);
252
253/* sonmp.c */
254int sonmp_send(PROTO_SEND_SIG);
255int sonmp_decode(PROTO_DECODE_SIG);
256
257/* edp.c */
258int edp_send(PROTO_SEND_SIG);
259int edp_decode(PROTO_DECODE_SIG);
260
261/* ctl.c */
262int ctl_create(struct lldpd *, char *);
263int ctl_connect(char *);
264void ctl_cleanup(int, char *);
265int ctl_accept(struct lldpd *, int);
266int ctl_close(struct lldpd *, int);
267void ctl_msg_init(struct hmsg *, enum hmsg_type);
268int ctl_msg_send(int, struct hmsg *);
269int ctl_msg_recv(int, struct hmsg *);
270int ctl_msg_pack_list(char *, void *, unsigned int, struct hmsg *, void **);
271int ctl_msg_unpack_list(char *, void *, unsigned int, struct hmsg *, void **);
272int ctl_msg_pack_structure(char *, void *, unsigned int, struct hmsg *, void **);
273int ctl_msg_unpack_structure(char *, void *, unsigned int, struct hmsg *, void **);
274
275/* features.c */
276int iface_is_bridge(struct lldpd *, const char *);
277int iface_is_bridged(struct lldpd *, const char *);
278int iface_is_wireless(struct lldpd *, const char *);
279int iface_is_vlan(struct lldpd *, const char *);
280int iface_is_bond(struct lldpd *, const char *);
281int iface_is_bond_slave(struct lldpd *,
282 const char *, const char *);
283int iface_is_enslaved(struct lldpd *, const char *);
284
285/* log.c */
286void log_init(int);
287void log_warn(const char *, ...);
288#define LLOG_WARN(x,...) log_warn("%s: " x, __FUNCTION__, ##__VA_ARGS__)
289void log_warnx(const char *, ...);
290#define LLOG_WARNX(x,...) log_warnx("%s: " x, __FUNCTION__, ##__VA_ARGS__)
291void log_info(const char *, ...);
292#define LLOG_INFO(x,...) log_info("%s: " x, __FUNCTION__, ##__VA_ARGS__)
293void log_debug(const char *, ...);
294#define LLOG_DEBUG(x,...) log_debug("%s: " x, __FUNCTION__, ##__VA_ARGS__)
295void fatal(const char *);
296void fatalx(const char *);
297
298/* agent.c */
299void agent_shutdown();
300void agent_init(struct lldpd *, int);
301
302/* strlcpy.c */
303size_t strlcpy(char *, const char *, size_t);
304
305/* iov.c */
306void iov_dump(struct lldpd_frame **, struct iovec *, int);
307u_int16_t iov_checksum(struct iovec *, int, int);
308
a552a72e
VB
309/* client.c */
310struct client_handle {
311 enum hmsg_type type;
312 void (*handle)(struct lldpd*, struct hmsg*, struct hmsg*);
313};
314
315void client_handle_client(struct lldpd *, struct lldpd_client *,
316 char *, int);
317void client_handle_none(struct lldpd *, struct hmsg *,
318 struct hmsg *);
319void client_handle_get_interfaces(struct lldpd *, struct hmsg *,
320 struct hmsg *);
321void client_handle_get_port_related(struct lldpd *, struct hmsg *,
322 struct hmsg *);
323void client_handle_shutdown(struct lldpd *, struct hmsg *,
324 struct hmsg *);
325
43c02e7b 326#endif /* _LLDPD_H */