]>
Commit | Line | Data |
---|---|---|
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. */ | |
72 | struct event; | |
73 | struct 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 | ||
88 | struct 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 | ||
101 | struct 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 | ||
131 | typedef void(*lldpd_ifhandlers)(struct lldpd *, struct ifaddrs *); | |
132 | ||
133 | /* lldpd.c */ | |
134 | struct lldpd_hardware *lldpd_get_hardware(struct lldpd *, | |
135 | char *, int, struct lldpd_ops *); | |
136 | struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *); | |
137 | void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *); | |
138 | struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, u_int32_t iface); | |
139 | void lldpd_recv(struct lldpd *, struct lldpd_hardware *, int); | |
140 | void lldpd_loop(struct lldpd *); | |
141 | int lldpd_main(int, char **); | |
142 | ||
143 | /* event.c */ | |
144 | void levent_loop(struct lldpd *); | |
145 | void levent_hardware_init(struct lldpd_hardware *); | |
146 | void levent_hardware_add_fd(struct lldpd_hardware *, int); | |
147 | void levent_hardware_release(struct lldpd_hardware *); | |
4e90a9e0 | 148 | void levent_ctl_notify(char *, int, struct lldpd_port *); |
47287a61 | 149 | void levent_send_now(struct lldpd *); |
4b292b55 VB |
150 | |
151 | /* lldp.c */ | |
152 | int lldp_send(PROTO_SEND_SIG); | |
153 | int lldp_decode(PROTO_DECODE_SIG); | |
154 | ||
155 | /* cdp.c */ | |
156 | #ifdef ENABLE_CDP | |
157 | int cdpv1_send(PROTO_SEND_SIG); | |
158 | int cdpv2_send(PROTO_SEND_SIG); | |
159 | int cdpv1_guess(PROTO_GUESS_SIG); | |
160 | int cdpv2_guess(PROTO_GUESS_SIG); | |
161 | #endif | |
162 | #if defined (ENABLE_CDP) || defined (ENABLE_FDP) | |
163 | int cdp_decode(PROTO_DECODE_SIG); | |
164 | #endif | |
165 | #ifdef ENABLE_FDP | |
166 | int fdp_send(PROTO_SEND_SIG); | |
167 | #endif | |
168 | ||
169 | #ifdef ENABLE_SONMP | |
170 | /* sonmp.c */ | |
171 | int sonmp_send(PROTO_SEND_SIG); | |
172 | int sonmp_decode(PROTO_DECODE_SIG); | |
173 | #endif | |
174 | ||
175 | #ifdef ENABLE_EDP | |
176 | /* edp.c */ | |
177 | int edp_send(PROTO_SEND_SIG); | |
178 | int edp_decode(PROTO_DECODE_SIG); | |
179 | #endif | |
180 | ||
181 | /* interfaces.c */ | |
182 | void lldpd_ifh_whitelist(struct lldpd *, struct ifaddrs *); | |
183 | void lldpd_ifh_bond(struct lldpd *, struct ifaddrs *); | |
184 | void lldpd_ifh_eth(struct lldpd *, struct ifaddrs *); | |
185 | #ifdef ENABLE_DOT1 | |
186 | void lldpd_ifh_vlan(struct lldpd *, struct ifaddrs *); | |
187 | #endif | |
188 | void lldpd_ifh_mgmt(struct lldpd *, struct ifaddrs *); | |
189 | void lldpd_ifh_chassis(struct lldpd *, struct ifaddrs *); | |
190 | ||
191 | /* dmi.c */ | |
192 | #ifdef ENABLE_LLDPMED | |
193 | #if __i386__ || __amd64__ | |
194 | char *dmi_hw(void); | |
195 | char *dmi_fw(void); | |
196 | char *dmi_sn(void); | |
197 | char *dmi_manuf(void); | |
198 | char *dmi_model(void); | |
199 | char *dmi_asset(void); | |
200 | #endif | |
201 | #endif | |
202 | ||
203 | /* agent.c */ | |
204 | void agent_shutdown(void); | |
205 | void agent_init(struct lldpd *, char *); | |
206 | ||
207 | /* agent_priv.c */ | |
208 | void agent_priv_register_domain(void); | |
209 | ||
210 | /* client.c */ | |
e0478a46 VB |
211 | int |
212 | client_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 */ | |
219 | void priv_init(char*, int, uid_t, gid_t); | |
220 | void priv_ctl_cleanup(void); | |
221 | char *priv_gethostbyname(void); | |
222 | int priv_open(char*); | |
223 | int priv_ethtool(char*, struct ethtool_cmd*); | |
224 | int priv_iface_init(const char *); | |
225 | int priv_iface_multicast(const char *, u_int8_t *, int); | |
226 | int priv_snmp_socket(struct sockaddr_un *); | |
227 | ||
228 | /* privsep_fdpass.c */ | |
229 | int receive_fd(int); | |
230 | void send_fd(int, int); | |
231 | ||
232 | #endif /* _LLDPD_H */ |