]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/daemon/lldpd.h
lldpd: add proper insert/delete/ageout counters
[thirdparty/lldpd.git] / src / daemon / lldpd.h
CommitLineData
4b292b55
VB
1/* -*- mode: c; c-file-style: "openbsd" -*- */
2/*
3 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _LLDPD_H
19#define _LLDPD_H
20
21#if HAVE_CONFIG_H
22# include <config.h>
23#endif
24
25#ifdef HAVE_VALGRIND_VALGRIND_H
26# include <valgrind/valgrind.h>
27#else
28# define RUNNING_ON_VALGRIND 0
29#endif
30
31#define _GNU_SOURCE 1
32#include <stdlib.h>
33#include <stddef.h>
34#include <string.h>
35#include <sys/queue.h>
36#ifdef HAVE_SYS_TYPES_H
37# include <sys/types.h>
38#endif
39#ifndef INCLUDE_LINUX_IF_H
40# include <net/if.h>
41#else
42# include <arpa/inet.h>
43# include <linux/if.h>
44#endif
45#if HAVE_GETIFADDRS
46# include <ifaddrs.h>
47#endif
48#include <net/ethernet.h>
49#include <netinet/in.h>
50#include <linux/ethtool.h>
51#include <sys/un.h>
52
53#include "lldp-tlv.h"
54#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
55# include "cdp.h"
56#endif
57#ifdef ENABLE_SONMP
58# include "sonmp.h"
59#endif
60#ifdef ENABLE_EDP
61# include "edp.h"
62#endif
63
64#include "../compat/compat.h"
65#include "../marshal.h"
66#include "../log.h"
67#include "../ctl.h"
68#include "../lldpd-structs.h"
69
70/* We don't want to import event2/event.h. We only need those as
71 opaque structs. */
72struct event;
73struct event_base;
74
75#define SYSFS_CLASS_NET "/sys/class/net/"
76#define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
77#define LLDPD_TTL 120
8843f168 78#define LLDPD_TX_INTERVAL 30
4b292b55
VB
79#define LLDPD_TX_MSGDELAY 1
80#define LLDPD_PID_FILE "/var/run/lldpd.pid"
81
82#define USING_AGENTX_SUBAGENT_MODULE 1
83
84#define PROTO_SEND_SIG struct lldpd *, struct lldpd_hardware *
85#define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, struct lldpd_port **
86#define PROTO_GUESS_SIG char *, int
87
88struct protocol {
89 int mode; /* > 0 mode identifier (unique per protocol) */
90 int enabled; /* Is this protocol enabled? */
91 char *name; /* Name of protocol */
92 char arg; /* Argument to enable this protocol */
93 int(*send)(PROTO_SEND_SIG); /* How to send a frame */
94 int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
95 int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */
96 u_int8_t mac[ETH_ALEN]; /* Destination MAC address used by this protocol */
97};
98
4b292b55
VB
99#define SMART_HIDDEN(port) (port->p_hidden_in)
100
101struct lldpd {
102 int g_sock;
4b292b55
VB
103 struct event_base *g_base;
104#ifdef USE_SNMP
105#endif
106
8ec333bd
VB
107 struct lldpd_config g_config;
108
4b292b55
VB
109 struct protocol *g_protocols;
110 time_t g_lastsent;
111 int g_lastrid;
4b292b55
VB
112 struct event *g_main_loop;
113#ifdef USE_SNMP
114 int g_snmp;
115 struct event *g_snmp_timeout;
116 void *g_snmp_fds;
117 char *g_snmp_agentx;
118#endif /* USE_SNMP */
119
120 /* Unix socket handling */
121 int g_ctl;
122 struct event *g_ctl_event;
123
4b292b55 124 char *g_lsb_release;
4b292b55
VB
125
126#define LOCAL_CHASSIS(cfg) ((struct lldpd_chassis *)(TAILQ_FIRST(&cfg->g_chassis)))
127 TAILQ_HEAD(, lldpd_chassis) g_chassis;
128 TAILQ_HEAD(, lldpd_hardware) g_hardware;
129};
130
131typedef void(*lldpd_ifhandlers)(struct lldpd *, struct ifaddrs *);
132
133/* lldpd.c */
134struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
135 char *, int, struct lldpd_ops *);
136struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *);
137void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
138struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, u_int32_t iface);
139void lldpd_recv(struct lldpd *, struct lldpd_hardware *, int);
140void lldpd_loop(struct lldpd *);
141int lldpd_main(int, char **);
142
143/* event.c */
144void levent_loop(struct lldpd *);
145void levent_hardware_init(struct lldpd_hardware *);
146void levent_hardware_add_fd(struct lldpd_hardware *, int);
147void levent_hardware_release(struct lldpd_hardware *);
4e90a9e0 148void levent_ctl_notify(char *, int, struct lldpd_port *);
47287a61 149void levent_send_now(struct lldpd *);
4b292b55
VB
150
151/* lldp.c */
152int lldp_send(PROTO_SEND_SIG);
153int lldp_decode(PROTO_DECODE_SIG);
154
155/* cdp.c */
156#ifdef ENABLE_CDP
157int cdpv1_send(PROTO_SEND_SIG);
158int cdpv2_send(PROTO_SEND_SIG);
159int cdpv1_guess(PROTO_GUESS_SIG);
160int cdpv2_guess(PROTO_GUESS_SIG);
161#endif
162#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
163int cdp_decode(PROTO_DECODE_SIG);
164#endif
165#ifdef ENABLE_FDP
166int fdp_send(PROTO_SEND_SIG);
167#endif
168
169#ifdef ENABLE_SONMP
170/* sonmp.c */
171int sonmp_send(PROTO_SEND_SIG);
172int sonmp_decode(PROTO_DECODE_SIG);
173#endif
174
175#ifdef ENABLE_EDP
176/* edp.c */
177int edp_send(PROTO_SEND_SIG);
178int edp_decode(PROTO_DECODE_SIG);
179#endif
180
181/* interfaces.c */
182void lldpd_ifh_whitelist(struct lldpd *, struct ifaddrs *);
183void lldpd_ifh_bond(struct lldpd *, struct ifaddrs *);
184void lldpd_ifh_eth(struct lldpd *, struct ifaddrs *);
185#ifdef ENABLE_DOT1
186void lldpd_ifh_vlan(struct lldpd *, struct ifaddrs *);
187#endif
188void lldpd_ifh_mgmt(struct lldpd *, struct ifaddrs *);
189void lldpd_ifh_chassis(struct lldpd *, struct ifaddrs *);
190
191/* dmi.c */
192#ifdef ENABLE_LLDPMED
193#if __i386__ || __amd64__
194char *dmi_hw(void);
195char *dmi_fw(void);
196char *dmi_sn(void);
197char *dmi_manuf(void);
198char *dmi_model(void);
199char *dmi_asset(void);
200#endif
201#endif
202
203/* agent.c */
204void agent_shutdown(void);
205void agent_init(struct lldpd *, char *);
206
207/* agent_priv.c */
208void agent_priv_register_domain(void);
209
210/* client.c */
e0478a46
VB
211int
212client_handle_client(struct lldpd *cfg,
213 ssize_t(*send)(void *, int, void *, size_t),
214 void *,
4e90a9e0
VB
215 enum hmsg_type type, void *buffer, size_t n,
216 int*);
4b292b55
VB
217
218/* priv.c */
219void priv_init(char*, int, uid_t, gid_t);
220void priv_ctl_cleanup(void);
221char *priv_gethostbyname(void);
222int priv_open(char*);
223int priv_ethtool(char*, struct ethtool_cmd*);
224int priv_iface_init(const char *);
225int priv_iface_multicast(const char *, u_int8_t *, int);
226int priv_snmp_socket(struct sockaddr_un *);
227
228/* privsep_fdpass.c */
229int receive_fd(int);
230void send_fd(int, int);
231
232#endif /* _LLDPD_H */