]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/lldpd.h
Fix a typo when receiving LLDP-MED inventory asset id.
[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>
4afe659e 36#include <linux/ethtool.h>
43c02e7b
VB
37
38#include "compat.h"
39#include "lldp.h"
4bad1937 40#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
43c02e7b 41#include "cdp.h"
4bad1937
VB
42#endif
43#ifdef ENABLE_SONMP
43c02e7b 44#include "sonmp.h"
4bad1937
VB
45#endif
46#ifdef ENABLE_EDP
43c02e7b 47#include "edp.h"
4bad1937 48#endif
43c02e7b 49
89840df0
VB
50#define SYSFS_CLASS_NET "/sys/class/net/"
51#define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
43c02e7b
VB
52#define LLDPD_TTL 120
53#define LLDPD_TX_DELAY 30
54#define LLDPD_TX_MSGDELAY 1
55#define LLDPD_CTL_SOCKET "/var/run/lldpd.socket"
56#define LLDPD_PID_FILE "/var/run/lldpd.pid"
57
58#define UNIX_PATH_MAX 108
59
60#define USING_AGENTX_SUBAGENT_MODULE 1
61
62struct lldpd_vlan {
63 TAILQ_ENTRY(lldpd_vlan) v_entries;
64 char *v_name;
65 u_int16_t v_vid;
66};
67#define STRUCT_LLDPD_VLAN "Lsw"
68
69struct lldpd_chassis {
70 u_int8_t c_id_subtype;
71 char *c_id;
72 int c_id_len;
73 char *c_name;
74 char *c_descr;
75
76 u_int16_t c_cap_available;
77 u_int16_t c_cap_enabled;
78
79 u_int16_t c_ttl;
80
81 struct in_addr c_mgmt;
82 u_int32_t c_mgmt_if;
89840df0
VB
83
84#ifdef ENABLE_LLDPMED
85 u_int16_t c_med_cap;
86 u_int8_t c_med_type;
87 char *c_med_hw;
88 char *c_med_fw;
89 char *c_med_sw;
90 char *c_med_sn;
91 char *c_med_manuf;
92 char *c_med_model;
93 char *c_med_asset;
94#endif
95
43c02e7b 96};
6772b237 97#ifndef ENABLE_LLDPMED
43c02e7b 98#define STRUCT_LLDPD_CHASSIS "bCsswwwll"
89840df0
VB
99#else
100#define STRUCT_LLDPD_CHASSIS "bCsswwwllwbsssssss"
101#endif
43c02e7b
VB
102
103struct lldpd_port {
104 u_int8_t p_id_subtype;
105 char *p_id;
106 int p_id_len;
107 char *p_descr;
108
109 /* Dot3 stuff */
110 u_int32_t p_aggregid;
111 u_int8_t p_autoneg_support;
112 u_int8_t p_autoneg_enabled;
113 u_int16_t p_autoneg_advertised;
114 u_int16_t p_mau_type;
115
116 TAILQ_HEAD(, lldpd_vlan) p_vlans;
117};
118#define STRUCT_LLDPD_PORT "bCslbbwwPP"
119
120struct lldpd_frame {
121 int size;
122 unsigned char frame[];
123};
124
125struct lldpd_hardware {
126 TAILQ_ENTRY(lldpd_hardware) h_entries;
127
128#define INTERFACE_OPENED(x) ((x)->h_raw != -1)
129
130 int h_raw;
131 int h_raw_real; /* For bonding */
132 int h_master; /* For bonding */
133
134#define LLDPD_MODE_ANY 0
135#define LLDPD_MODE_LLDP 1
136#define LLDPD_MODE_CDPV1 2
137#define LLDPD_MODE_CDPV2 3
138#define LLDPD_MODE_SONMP 4
139#define LLDPD_MODE_EDP 5
031118c4 140#define LLDPD_MODE_FDP 6
43c02e7b
VB
141 int h_mode;
142
143 int h_flags;
144 int h_mtu;
145 char h_ifname[IFNAMSIZ];
146 u_int8_t h_lladdr[ETHER_ADDR_LEN];
147
148 u_int64_t h_tx_cnt;
149 u_int64_t h_rx_cnt;
150 u_int64_t h_rx_discarded_cnt;
151 u_int64_t h_rx_ageout_cnt;
37387046 152 u_int64_t h_rx_unrecognized_cnt;
43c02e7b
VB
153
154 u_int8_t *h_proto_macs;
155 time_t h_start_probe;
156
157 struct lldpd_port h_lport;
158 time_t h_llastchange;
159 struct lldpd_frame *h_llastframe;
160
161 time_t h_rlastchange;
162 time_t h_rlastupdate;
163 int h_rid;
164 struct lldpd_frame *h_rlastframe;
165 struct lldpd_port *h_rport;
166 struct lldpd_chassis *h_rchassis;
167};
168
50a89ca7
VB
169/* lldpd_vif can be casted to lldpd_hardware on some cases */
170struct lldpd_vif {
171 TAILQ_ENTRY(lldpd_vif) vif_entries;
172 int vif_raw;
173 int vif_raw_real; /* Not used */
174 int vif_master; /* Not used */
175 int vif_mode; /* Not used */
176 int vif_flags;
177 int vif_mtu;
178 char vif_ifname[IFNAMSIZ];
179
180 /* No more compatibility with struct lldpd_hardware from here */
181 struct lldpd_hardware *vif_real;
182};
183
43c02e7b
VB
184struct lldpd_interface {
185 TAILQ_ENTRY(lldpd_interface) next;
186 char *name;
187};
188#define STRUCT_LLDPD_INTERFACE "Ls"
189
190struct lldpd_client {
191 TAILQ_ENTRY(lldpd_client) next;
192 int fd;
193};
194
195#define PROTO_SEND_SIG struct lldpd *, struct lldpd_chassis *, struct lldpd_hardware *
196#define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, struct lldpd_port **
197#define PROTO_GUESS_SIG char *, int
198
199struct lldpd;
200struct protocol {
201 int mode; /* > 0 mode identifier (unique per protocol) */
202 int enabled; /* Is this protocol enabled? */
203 char *name; /* Name of protocol */
204 char arg; /* Argument to enable this protocol */
205 int(*send)(PROTO_SEND_SIG); /* How to send a frame */
206 int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
207 int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */
208 u_int8_t mac[ETH_ALEN]; /* Destination MAC address used by this protocol */
209 struct sock_filter *filter; /* BPF filter */
210 size_t filterlen; /* Size of BPF filter */
211};
212
213struct lldpd {
214 int g_sock;
215 int g_delay;
216
217 struct protocol *g_protocols;
218 int g_multi; /* Set to 1 if multiple protocols */
219 int g_probe_time;
766f32b3 220 int g_listen_vlans;
43c02e7b
VB
221
222 time_t g_lastsent;
223 int g_lastrid;
224#ifdef USE_SNMP
225 int g_snmp;
226#endif /* USE_SNMP */
227
228 /* Unix socket handling */
229 int g_ctl;
230 TAILQ_HEAD(, lldpd_client) g_clients;
231
232 char *g_mgmt_pattern;
233
234 struct lldpd_chassis g_lchassis;
235
236 TAILQ_HEAD(, lldpd_hardware) g_hardware;
50a89ca7 237 TAILQ_HEAD(, lldpd_vif) g_vif;
43c02e7b
VB
238};
239
240enum hmsg_type {
241 HMSG_NONE,
242 HMSG_GET_INTERFACES,
243 HMSG_GET_CHASSIS,
244 HMSG_GET_PORT,
245 HMSG_GET_VLANS,
246 HMSG_SHUTDOWN
247};
248
249struct hmsg_hdr {
250 enum hmsg_type type;
251 int16_t len;
252 pid_t pid;
253} __attribute__ ((__packed__));
254
255struct hmsg {
256 struct hmsg_hdr hdr;
257 void *data;
258} __attribute__ ((__packed__));
259
260#define HMSG_HEADER_SIZE sizeof(struct hmsg_hdr)
261#define MAX_HMSGSIZE 8192
262
263/* lldpd.c */
264void lldpd_cleanup(struct lldpd *);
265void lldpd_vlan_cleanup(struct lldpd_port *);
266void lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int);
267void lldpd_port_cleanup(struct lldpd_port *);
268void lldpd_chassis_cleanup(struct lldpd_chassis *);
269
270/* lldp.c */
271int lldp_send(PROTO_SEND_SIG);
272int lldp_decode(PROTO_DECODE_SIG);
273
274/* cdp.c */
4bad1937 275#ifdef ENABLE_CDP
43c02e7b
VB
276int cdpv1_send(PROTO_SEND_SIG);
277int cdpv2_send(PROTO_SEND_SIG);
43c02e7b
VB
278int cdpv1_guess(PROTO_GUESS_SIG);
279int cdpv2_guess(PROTO_GUESS_SIG);
4bad1937
VB
280#endif
281#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
282int cdp_decode(PROTO_DECODE_SIG);
283#endif
284#ifdef ENABLE_FDP
285int fdp_send(PROTO_SEND_SIG);
286#endif
43c02e7b 287
4bad1937 288#ifdef ENABLE_SONMP
43c02e7b
VB
289/* sonmp.c */
290int sonmp_send(PROTO_SEND_SIG);
291int sonmp_decode(PROTO_DECODE_SIG);
4bad1937 292#endif
43c02e7b 293
4bad1937 294#ifdef ENABLE_EDP
43c02e7b
VB
295/* edp.c */
296int edp_send(PROTO_SEND_SIG);
297int edp_decode(PROTO_DECODE_SIG);
4bad1937 298#endif
43c02e7b
VB
299
300/* ctl.c */
b5562b23 301int ctl_create(char *);
43c02e7b 302int ctl_connect(char *);
b5562b23 303void ctl_cleanup(char *);
43c02e7b
VB
304int ctl_accept(struct lldpd *, int);
305int ctl_close(struct lldpd *, int);
306void ctl_msg_init(struct hmsg *, enum hmsg_type);
307int ctl_msg_send(int, struct hmsg *);
308int ctl_msg_recv(int, struct hmsg *);
309int ctl_msg_pack_list(char *, void *, unsigned int, struct hmsg *, void **);
310int ctl_msg_unpack_list(char *, void *, unsigned int, struct hmsg *, void **);
311int ctl_msg_pack_structure(char *, void *, unsigned int, struct hmsg *, void **);
312int ctl_msg_unpack_structure(char *, void *, unsigned int, struct hmsg *, void **);
313
314/* features.c */
315int iface_is_bridge(struct lldpd *, const char *);
316int iface_is_bridged(struct lldpd *, const char *);
317int iface_is_wireless(struct lldpd *, const char *);
318int iface_is_vlan(struct lldpd *, const char *);
319int iface_is_bond(struct lldpd *, const char *);
320int iface_is_bond_slave(struct lldpd *,
321 const char *, const char *);
322int iface_is_enslaved(struct lldpd *, const char *);
89840df0
VB
323#ifdef ENABLE_LLDPMED
324char *dmi_hw();
325char *dmi_fw();
326char *dmi_sn();
327char *dmi_manuf();
328char *dmi_model();
329char *dmi_asset();
330#endif
43c02e7b
VB
331
332/* log.c */
333void log_init(int);
334void log_warn(const char *, ...);
335#define LLOG_WARN(x,...) log_warn("%s: " x, __FUNCTION__, ##__VA_ARGS__)
336void log_warnx(const char *, ...);
337#define LLOG_WARNX(x,...) log_warnx("%s: " x, __FUNCTION__, ##__VA_ARGS__)
338void log_info(const char *, ...);
339#define LLOG_INFO(x,...) log_info("%s: " x, __FUNCTION__, ##__VA_ARGS__)
340void log_debug(const char *, ...);
341#define LLOG_DEBUG(x,...) log_debug("%s: " x, __FUNCTION__, ##__VA_ARGS__)
342void fatal(const char *);
343void fatalx(const char *);
344
345/* agent.c */
346void agent_shutdown();
347void agent_init(struct lldpd *, int);
348
d72a05d4
VB
349/* agent_priv.c */
350void agent_priv_register_domain();
351
43c02e7b
VB
352/* strlcpy.c */
353size_t strlcpy(char *, const char *, size_t);
354
355/* iov.c */
356void iov_dump(struct lldpd_frame **, struct iovec *, int);
357u_int16_t iov_checksum(struct iovec *, int, int);
358
a552a72e
VB
359/* client.c */
360struct client_handle {
361 enum hmsg_type type;
362 void (*handle)(struct lldpd*, struct hmsg*, struct hmsg*);
363};
364
365void client_handle_client(struct lldpd *, struct lldpd_client *,
366 char *, int);
367void client_handle_none(struct lldpd *, struct hmsg *,
368 struct hmsg *);
369void client_handle_get_interfaces(struct lldpd *, struct hmsg *,
370 struct hmsg *);
371void client_handle_get_port_related(struct lldpd *, struct hmsg *,
372 struct hmsg *);
373void client_handle_shutdown(struct lldpd *, struct hmsg *,
374 struct hmsg *);
375
b5562b23 376/* priv.c */
a2993d83 377void priv_init(char*);
a7502371
VB
378int priv_ctl_create();
379void priv_ctl_cleanup();
380char *priv_gethostbyname();
381int priv_open(char*);
382int priv_ethtool(char*, struct ethtool_cmd*);
383int priv_iface_init(struct lldpd_hardware *, int);
384int priv_iface_multicast(char *, u_int8_t *, int);
d72a05d4 385int priv_snmp_socket(struct sockaddr_un *);
4afe659e
VB
386
387/* privsep_fdpass.c */
388int receive_fd(int);
389void send_fd(int, int);
b5562b23 390
43c02e7b 391#endif /* _LLDPD_H */