]> git.ipfire.org Git - thirdparty/lldpd.git/blame - src/daemon/lldpd.h
netlink: fix bogus alignment warnings
[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
5d6aba3e 20#define _GNU_SOURCE 1
4b292b55
VB
21
22#if HAVE_CONFIG_H
23# include <config.h>
24#endif
25
26#ifdef HAVE_VALGRIND_VALGRIND_H
27# include <valgrind/valgrind.h>
28#else
29# define RUNNING_ON_VALGRIND 0
30#endif
31
4b292b55
VB
32#include <stdlib.h>
33#include <stddef.h>
34#include <string.h>
35#include <sys/queue.h>
e12c2365 36#include <sys/types.h>
4b292b55
VB
37#include <net/ethernet.h>
38#include <netinet/in.h>
4b292b55
VB
39#include <sys/un.h>
40
41#include "lldp-tlv.h"
42#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
43# include "cdp.h"
44#endif
45#ifdef ENABLE_SONMP
46# include "sonmp.h"
47#endif
48#ifdef ENABLE_EDP
49# include "edp.h"
50#endif
51
52#include "../compat/compat.h"
53#include "../marshal.h"
54#include "../log.h"
55#include "../ctl.h"
56#include "../lldpd-structs.h"
57
58/* We don't want to import event2/event.h. We only need those as
59 opaque structs. */
60struct event;
61struct event_base;
62
63#define SYSFS_CLASS_NET "/sys/class/net/"
64#define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
65#define LLDPD_TTL 120
8843f168 66#define LLDPD_TX_INTERVAL 30
4b292b55
VB
67#define LLDPD_TX_MSGDELAY 1
68#define LLDPD_PID_FILE "/var/run/lldpd.pid"
69
70#define USING_AGENTX_SUBAGENT_MODULE 1
71
72#define PROTO_SEND_SIG struct lldpd *, struct lldpd_hardware *
73#define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, struct lldpd_port **
74#define PROTO_GUESS_SIG char *, int
75
76struct protocol {
77 int mode; /* > 0 mode identifier (unique per protocol) */
78 int enabled; /* Is this protocol enabled? */
79 char *name; /* Name of protocol */
80 char arg; /* Argument to enable this protocol */
81 int(*send)(PROTO_SEND_SIG); /* How to send a frame */
82 int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
83 int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */
84 u_int8_t mac[ETH_ALEN]; /* Destination MAC address used by this protocol */
85};
86
4b292b55
VB
87#define SMART_HIDDEN(port) (port->p_hidden_in)
88
89struct lldpd {
90 int g_sock;
4b292b55
VB
91 struct event_base *g_base;
92#ifdef USE_SNMP
93#endif
94
8ec333bd
VB
95 struct lldpd_config g_config;
96
4b292b55
VB
97 struct protocol *g_protocols;
98 time_t g_lastsent;
99 int g_lastrid;
4b292b55
VB
100 struct event *g_main_loop;
101#ifdef USE_SNMP
102 int g_snmp;
103 struct event *g_snmp_timeout;
104 void *g_snmp_fds;
105 char *g_snmp_agentx;
106#endif /* USE_SNMP */
107
108 /* Unix socket handling */
109 int g_ctl;
110 struct event *g_ctl_event;
111
4b292b55 112 char *g_lsb_release;
4b292b55
VB
113
114#define LOCAL_CHASSIS(cfg) ((struct lldpd_chassis *)(TAILQ_FIRST(&cfg->g_chassis)))
115 TAILQ_HEAD(, lldpd_chassis) g_chassis;
116 TAILQ_HEAD(, lldpd_hardware) g_hardware;
117};
118
4b292b55
VB
119/* lldpd.c */
120struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
121 char *, int, struct lldpd_ops *);
e12c2365 122struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int);
4b292b55
VB
123void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
124struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, u_int32_t iface);
125void lldpd_recv(struct lldpd *, struct lldpd_hardware *, int);
126void lldpd_loop(struct lldpd *);
127int lldpd_main(int, char **);
128
129/* event.c */
130void levent_loop(struct lldpd *);
131void levent_hardware_init(struct lldpd_hardware *);
132void levent_hardware_add_fd(struct lldpd_hardware *, int);
133void levent_hardware_release(struct lldpd_hardware *);
4e90a9e0 134void levent_ctl_notify(char *, int, struct lldpd_port *);
47287a61 135void levent_send_now(struct lldpd *);
4b292b55
VB
136
137/* lldp.c */
138int lldp_send(PROTO_SEND_SIG);
139int lldp_decode(PROTO_DECODE_SIG);
140
141/* cdp.c */
142#ifdef ENABLE_CDP
143int cdpv1_send(PROTO_SEND_SIG);
144int cdpv2_send(PROTO_SEND_SIG);
145int cdpv1_guess(PROTO_GUESS_SIG);
146int cdpv2_guess(PROTO_GUESS_SIG);
147#endif
148#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
149int cdp_decode(PROTO_DECODE_SIG);
150#endif
151#ifdef ENABLE_FDP
152int fdp_send(PROTO_SEND_SIG);
153#endif
154
155#ifdef ENABLE_SONMP
156/* sonmp.c */
157int sonmp_send(PROTO_SEND_SIG);
158int sonmp_decode(PROTO_DECODE_SIG);
159#endif
160
161#ifdef ENABLE_EDP
162/* edp.c */
163int edp_send(PROTO_SEND_SIG);
164int edp_decode(PROTO_DECODE_SIG);
165#endif
166
4b292b55
VB
167/* dmi.c */
168#ifdef ENABLE_LLDPMED
4b292b55
VB
169char *dmi_hw(void);
170char *dmi_fw(void);
171char *dmi_sn(void);
172char *dmi_manuf(void);
173char *dmi_model(void);
174char *dmi_asset(void);
175#endif
4b292b55 176
25de85a4 177#ifdef USE_SNMP
4b292b55
VB
178/* agent.c */
179void agent_shutdown(void);
180void agent_init(struct lldpd *, char *);
25de85a4
VB
181void agent_notify(struct lldpd_hardware *, int, struct lldpd_port *);
182#endif
4b292b55
VB
183
184/* agent_priv.c */
185void agent_priv_register_domain(void);
186
187/* client.c */
e0478a46
VB
188int
189client_handle_client(struct lldpd *cfg,
190 ssize_t(*send)(void *, int, void *, size_t),
191 void *,
4e90a9e0
VB
192 enum hmsg_type type, void *buffer, size_t n,
193 int*);
4b292b55
VB
194
195/* priv.c */
196void priv_init(char*, int, uid_t, gid_t);
197void priv_ctl_cleanup(void);
198char *priv_gethostbyname(void);
199int priv_open(char*);
e12c2365
VB
200#ifdef HOST_OS_LINUX
201int priv_ethtool(char*, void*, size_t);
202#endif
203int priv_iface_init(int);
4b292b55
VB
204int priv_iface_multicast(const char *, u_int8_t *, int);
205int priv_snmp_socket(struct sockaddr_un *);
206
207/* privsep_fdpass.c */
208int receive_fd(int);
209void send_fd(int, int);
210
e12c2365
VB
211/* interfaces-*.c */
212void interfaces_update(struct lldpd *);
213
214#ifdef HOST_OS_LINUX
215/* netlink stuff */
216struct netlink_interface {
217 TAILQ_ENTRY(netlink_interface) next;
218 int index; /* Index */
219 char *name; /* Name */
220 char *alias; /* Alias */
221 int flags; /* Flags */
222 int mtu; /* MTU */
223 char *address; /* MAC address */
224 int type; /* Type (ARPHDR_*) */
225 int link; /* Support interface */
226 int master; /* Master interface */
227 int txqueue; /* TX queue len */
228};
229struct netlink_address {
230 TAILQ_ENTRY(netlink_address) next;
231 int index; /* Index */
232 int flags; /* Flags */
233 struct sockaddr_storage address; /* Address */
234};
235TAILQ_HEAD(netlink_interface_list, netlink_interface);
236TAILQ_HEAD(netlink_address_list, netlink_address);
237struct netlink_interface_list *netlink_get_interfaces(void);
238struct netlink_address_list *netlink_get_addresses(void);
239void netlink_free_interfaces(struct netlink_interface_list *);
240void netlink_free_addresses(struct netlink_address_list *);
241#endif
242
4b292b55 243#endif /* _LLDPD_H */