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