]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/lldpd.h
Initial import
[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
141struct lldpd_interface {
142 TAILQ_ENTRY(lldpd_interface) next;
143 char *name;
144};
145#define STRUCT_LLDPD_INTERFACE "Ls"
146
147struct lldpd_client {
148 TAILQ_ENTRY(lldpd_client) next;
149 int fd;
150};
151
152#define PROTO_SEND_SIG struct lldpd *, struct lldpd_chassis *, struct lldpd_hardware *
153#define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, struct lldpd_port **
154#define PROTO_GUESS_SIG char *, int
155
156struct lldpd;
157struct protocol {
158 int mode; /* > 0 mode identifier (unique per protocol) */
159 int enabled; /* Is this protocol enabled? */
160 char *name; /* Name of protocol */
161 char arg; /* Argument to enable this protocol */
162 int(*send)(PROTO_SEND_SIG); /* How to send a frame */
163 int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
164 int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */
165 u_int8_t mac[ETH_ALEN]; /* Destination MAC address used by this protocol */
166 struct sock_filter *filter; /* BPF filter */
167 size_t filterlen; /* Size of BPF filter */
168};
169
170struct lldpd {
171 int g_sock;
172 int g_delay;
173
174 struct protocol *g_protocols;
175 int g_multi; /* Set to 1 if multiple protocols */
176 int g_probe_time;
177
178 time_t g_lastsent;
179 int g_lastrid;
180#ifdef USE_SNMP
181 int g_snmp;
182#endif /* USE_SNMP */
183
184 /* Unix socket handling */
185 int g_ctl;
186 TAILQ_HEAD(, lldpd_client) g_clients;
187
188 char *g_mgmt_pattern;
189
190 struct lldpd_chassis g_lchassis;
191
192 TAILQ_HEAD(, lldpd_hardware) g_hardware;
193};
194
195enum hmsg_type {
196 HMSG_NONE,
197 HMSG_GET_INTERFACES,
198 HMSG_GET_CHASSIS,
199 HMSG_GET_PORT,
200 HMSG_GET_VLANS,
201 HMSG_SHUTDOWN
202};
203
204struct hmsg_hdr {
205 enum hmsg_type type;
206 int16_t len;
207 pid_t pid;
208} __attribute__ ((__packed__));
209
210struct hmsg {
211 struct hmsg_hdr hdr;
212 void *data;
213} __attribute__ ((__packed__));
214
215#define HMSG_HEADER_SIZE sizeof(struct hmsg_hdr)
216#define MAX_HMSGSIZE 8192
217
218/* lldpd.c */
219void lldpd_cleanup(struct lldpd *);
220void lldpd_vlan_cleanup(struct lldpd_port *);
221void lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int);
222void lldpd_port_cleanup(struct lldpd_port *);
223void lldpd_chassis_cleanup(struct lldpd_chassis *);
224
225/* lldp.c */
226int lldp_send(PROTO_SEND_SIG);
227int lldp_decode(PROTO_DECODE_SIG);
228
229/* cdp.c */
230int cdpv1_send(PROTO_SEND_SIG);
231int cdpv2_send(PROTO_SEND_SIG);
232int cdp_decode(PROTO_DECODE_SIG);
233int cdpv1_guess(PROTO_GUESS_SIG);
234int cdpv2_guess(PROTO_GUESS_SIG);
235
236/* sonmp.c */
237int sonmp_send(PROTO_SEND_SIG);
238int sonmp_decode(PROTO_DECODE_SIG);
239
240/* edp.c */
241int edp_send(PROTO_SEND_SIG);
242int edp_decode(PROTO_DECODE_SIG);
243
244/* ctl.c */
245int ctl_create(struct lldpd *, char *);
246int ctl_connect(char *);
247void ctl_cleanup(int, char *);
248int ctl_accept(struct lldpd *, int);
249int ctl_close(struct lldpd *, int);
250void ctl_msg_init(struct hmsg *, enum hmsg_type);
251int ctl_msg_send(int, struct hmsg *);
252int ctl_msg_recv(int, struct hmsg *);
253int ctl_msg_pack_list(char *, void *, unsigned int, struct hmsg *, void **);
254int ctl_msg_unpack_list(char *, void *, unsigned int, struct hmsg *, void **);
255int ctl_msg_pack_structure(char *, void *, unsigned int, struct hmsg *, void **);
256int ctl_msg_unpack_structure(char *, void *, unsigned int, struct hmsg *, void **);
257
258/* features.c */
259int iface_is_bridge(struct lldpd *, const char *);
260int iface_is_bridged(struct lldpd *, const char *);
261int iface_is_wireless(struct lldpd *, const char *);
262int iface_is_vlan(struct lldpd *, const char *);
263int iface_is_bond(struct lldpd *, const char *);
264int iface_is_bond_slave(struct lldpd *,
265 const char *, const char *);
266int iface_is_enslaved(struct lldpd *, const char *);
267
268/* log.c */
269void log_init(int);
270void log_warn(const char *, ...);
271#define LLOG_WARN(x,...) log_warn("%s: " x, __FUNCTION__, ##__VA_ARGS__)
272void log_warnx(const char *, ...);
273#define LLOG_WARNX(x,...) log_warnx("%s: " x, __FUNCTION__, ##__VA_ARGS__)
274void log_info(const char *, ...);
275#define LLOG_INFO(x,...) log_info("%s: " x, __FUNCTION__, ##__VA_ARGS__)
276void log_debug(const char *, ...);
277#define LLOG_DEBUG(x,...) log_debug("%s: " x, __FUNCTION__, ##__VA_ARGS__)
278void fatal(const char *);
279void fatalx(const char *);
280
281/* agent.c */
282void agent_shutdown();
283void agent_init(struct lldpd *, int);
284
285/* strlcpy.c */
286size_t strlcpy(char *, const char *, size_t);
287
288/* iov.c */
289void iov_dump(struct lldpd_frame **, struct iovec *, int);
290u_int16_t iov_checksum(struct iovec *, int, int);
291
292#endif /* _LLDPD_H */