xref: /openbsd/usr.sbin/ldpd/ldpd.h (revision cecf84d4)
1 /*	$OpenBSD: ldpd.h,v 1.45 2015/04/04 15:15:44 renato Exp $ */
2 
3 /*
4  * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
5  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
6  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #ifndef _LDPD_H_
22 #define _LDPD_H_
23 
24 #include <sys/queue.h>
25 #include <sys/socket.h>
26 #include <sys/time.h>
27 #include <sys/tree.h>
28 #include <md5.h>
29 #include <net/if.h>
30 #include <netinet/in.h>
31 #include <event.h>
32 
33 #include <imsg.h>
34 #include "ldp.h"
35 
36 #define CONF_FILE		"/etc/ldpd.conf"
37 #define	LDPD_SOCKET		"/var/run/ldpd.sock"
38 #define LDPD_USER		"_ldpd"
39 
40 #define NBR_IDSELF		1
41 #define NBR_CNTSTART		(NBR_IDSELF + 1)
42 
43 #define	RT_BUF_SIZE		16384
44 #define	MAX_RTSOCK_BUF		128 * 1024
45 #define	LDP_BACKLOG		128
46 
47 #define	LDPD_FLAG_NO_FIB_UPDATE	0x0001
48 #define	LDPD_FLAG_TH_ACCEPT	0x0002
49 
50 #define	F_LDPD_INSERTED		0x0001
51 #define	F_CONNECTED		0x0002
52 #define	F_STATIC		0x0004
53 #define	F_DYNAMIC		0x0008
54 #define	F_REJECT		0x0010
55 #define	F_BLACKHOLE		0x0020
56 #define	F_REDISTRIBUTED		0x0040
57 
58 struct evbuf {
59 	struct msgbuf		wbuf;
60 	struct event		ev;
61 };
62 
63 struct imsgev {
64 	struct imsgbuf		 ibuf;
65 	void			(*handler)(int, short, void *);
66 	struct event		 ev;
67 	void			*data;
68 	short			 events;
69 };
70 
71 enum imsg_type {
72 	IMSG_NONE,
73 	IMSG_CTL_RELOAD,
74 	IMSG_CTL_SHOW_INTERFACE,
75 	IMSG_CTL_SHOW_DISCOVERY,
76 	IMSG_CTL_SHOW_NBR,
77 	IMSG_CTL_SHOW_LIB,
78 	IMSG_CTL_FIB_COUPLE,
79 	IMSG_CTL_FIB_DECOUPLE,
80 	IMSG_CTL_KROUTE,
81 	IMSG_CTL_KROUTE_ADDR,
82 	IMSG_CTL_IFINFO,
83 	IMSG_CTL_END,
84 	IMSG_CTL_LOG_VERBOSE,
85 	IMSG_KLABEL_CHANGE,
86 	IMSG_KLABEL_DELETE,
87 	IMSG_IFSTATUS,
88 	IMSG_NEWADDR,
89 	IMSG_DELADDR,
90 	IMSG_LABEL_MAPPING,
91 	IMSG_LABEL_MAPPING_FULL,
92 	IMSG_LABEL_REQUEST,
93 	IMSG_LABEL_RELEASE,
94 	IMSG_LABEL_WITHDRAW,
95 	IMSG_LABEL_ABORT,
96 	IMSG_REQUEST_ADD,
97 	IMSG_REQUEST_ADD_END,
98 	IMSG_MAPPING_ADD,
99 	IMSG_MAPPING_ADD_END,
100 	IMSG_RELEASE_ADD,
101 	IMSG_RELEASE_ADD_END,
102 	IMSG_ADDRESS_ADD,
103 	IMSG_ADDRESS_DEL,
104 	IMSG_NOTIFICATION_SEND,
105 	IMSG_NEIGHBOR_UP,
106 	IMSG_NEIGHBOR_DOWN,
107 	IMSG_NETWORK_ADD,
108 	IMSG_NETWORK_DEL,
109 	IMSG_RECONF_CONF,
110 	IMSG_RECONF_IFACE,
111 	IMSG_RECONF_END
112 };
113 
114 /* interface states */
115 #define	IF_STA_NEW		0x00	/* dummy state for reload */
116 #define	IF_STA_DOWN		0x01
117 #define	IF_STA_ACTIVE		0x02
118 
119 /* interface types */
120 enum iface_type {
121 	IF_TYPE_POINTOPOINT,
122 	IF_TYPE_BROADCAST
123 };
124 
125 /* neighbor states */
126 #define	NBR_STA_PRESENT		0x0001
127 #define	NBR_STA_INITIAL		0x0002
128 #define	NBR_STA_OPENREC		0x0004
129 #define	NBR_STA_OPENSENT	0x0008
130 #define	NBR_STA_OPER		0x0010
131 #define	NBR_STA_SESSION		(NBR_STA_INITIAL | NBR_STA_OPENREC | \
132 				NBR_STA_OPENSENT | NBR_STA_OPER)
133 
134 /* neighbor events */
135 enum nbr_event {
136 	NBR_EVT_NOTHING,
137 	NBR_EVT_MATCH_ADJ,
138 	NBR_EVT_CONNECT_UP,
139 	NBR_EVT_CLOSE_SESSION,
140 	NBR_EVT_INIT_RCVD,
141 	NBR_EVT_KEEPALIVE_RCVD,
142 	NBR_EVT_PDU_RCVD,
143 	NBR_EVT_PDU_SENT,
144 	NBR_EVT_INIT_SENT,
145 };
146 
147 /* neighbor actions */
148 enum nbr_action {
149 	NBR_ACT_NOTHING,
150 	NBR_ACT_RST_KTIMEOUT,
151 	NBR_ACT_SESSION_EST,
152 	NBR_ACT_RST_KTIMER,
153 	NBR_ACT_CONNECT_SETUP,
154 	NBR_ACT_PASSIVE_INIT,
155 	NBR_ACT_KEEPALIVE_SEND,
156 	NBR_ACT_CLOSE_SESSION
157 };
158 
159 TAILQ_HEAD(mapping_head, mapping_entry);
160 
161 struct map {
162 	struct in_addr	prefix;
163 	u_int32_t	label;
164 	u_int32_t	messageid;
165 	u_int32_t	requestid;
166 	u_int8_t	prefixlen;
167 	u_int8_t	flags;
168 };
169 #define F_MAP_WILDCARD	0x01	/* wildcard FEC */
170 #define F_MAP_OPTLABEL	0x02	/* optional label present */
171 #define F_MAP_REQ_ID	0x04	/* optional request message id present */
172 
173 struct notify_msg {
174 	u_int32_t	messageid;
175 	u_int32_t	status;
176 	u_int32_t	type;
177 };
178 
179 struct if_addr {
180 	LIST_ENTRY(if_addr)	 global_entry;
181 	LIST_ENTRY(if_addr)	 iface_entry;
182 	struct in_addr		 addr;
183 	struct in_addr		 mask;
184 	struct in_addr		 dstbrd;
185 };
186 
187 struct iface {
188 	LIST_ENTRY(iface)	 entry;
189 	struct event		 hello_timer;
190 
191 	char			 name[IF_NAMESIZE];
192 	LIST_HEAD(, if_addr)	 addr_list;
193 	LIST_HEAD(, adj)	 adj_list;
194 
195 	time_t			 uptime;
196 	unsigned int		 ifindex;
197 	int			 discovery_fd;
198 	int			 state;
199 	u_int16_t		 hello_holdtime;
200 	u_int16_t		 hello_interval;
201 	u_int16_t		 flags;
202 	enum iface_type		 type;
203 	u_int8_t		 media_type;
204 	u_int8_t		 linkstate;
205 };
206 
207 /* source of targeted hellos */
208 struct tnbr {
209 	LIST_ENTRY(tnbr)	 entry;
210 	struct event		 hello_timer;
211 	int			 discovery_fd;
212 	struct adj		*adj;
213 	struct in_addr		 addr;
214 
215 	u_int16_t		 hello_holdtime;
216 	u_int16_t		 hello_interval;
217 	u_int8_t		 flags;
218 };
219 #define F_TNBR_CONFIGURED	 0x01
220 
221 /* ldp_conf */
222 enum {
223 	PROC_MAIN,
224 	PROC_LDP_ENGINE,
225 	PROC_LDE_ENGINE
226 } ldpd_process;
227 
228 enum hello_type {
229 	HELLO_LINK,
230 	HELLO_TARGETED
231 };
232 
233 #define	MODE_DIST_INDEPENDENT	0x01
234 #define	MODE_DIST_ORDERED	0x02
235 #define	MODE_RET_LIBERAL	0x04
236 #define	MODE_RET_CONSERVATIVE	0x08
237 #define	MODE_ADV_ONDEMAND	0x10
238 #define	MODE_ADV_UNSOLICITED	0x20
239 
240 struct ldpd_conf {
241 	struct event		disc_ev;
242 	struct event		edisc_ev;
243 	struct in_addr		rtr_id;
244 	LIST_HEAD(, iface)	iface_list;
245 	LIST_HEAD(, if_addr)	addr_list;
246 	LIST_HEAD(, tnbr)	tnbr_list;
247 
248 	u_int32_t		opts;
249 #define LDPD_OPT_VERBOSE	0x00000001
250 #define LDPD_OPT_VERBOSE2	0x00000002
251 #define LDPD_OPT_NOACTION	0x00000004
252 	time_t			uptime;
253 	int			ldp_discovery_socket;
254 	int			ldp_ediscovery_socket;
255 	int			ldp_session_socket;
256 	int			flags;
257 	u_int8_t		mode;
258 	u_int16_t		keepalive;
259 	u_int16_t		thello_holdtime;
260 	u_int16_t		thello_interval;
261 };
262 
263 /* kroute */
264 struct kroute {
265 	struct in_addr	prefix;
266 	struct in_addr	nexthop;
267 	u_int32_t	local_label;
268 	u_int32_t	remote_label;
269 	u_int16_t	flags;
270 	u_short		ifindex;
271 	u_int8_t	prefixlen;
272 	u_int8_t	priority;
273 };
274 
275 struct kaddr {
276 	u_short			 ifindex;
277 	struct in_addr		 addr;
278 	struct in_addr		 mask;
279 	struct in_addr		 dstbrd;
280 };
281 
282 struct kif {
283 	char			 ifname[IF_NAMESIZE];
284 	u_int64_t		 baudrate;
285 	int			 flags;
286 	int			 mtu;
287 	u_short			 ifindex;
288 	u_int8_t		 media_type;
289 	u_int8_t		 link_state;
290 };
291 
292 /* control data structures */
293 struct ctl_iface {
294 	char			 name[IF_NAMESIZE];
295 	time_t			 uptime;
296 	unsigned int		 ifindex;
297 	int			 state;
298 	u_int16_t		 adj_cnt;
299 	u_int16_t		 flags;
300 	u_int16_t		 hello_holdtime;
301 	u_int16_t		 hello_interval;
302 	enum iface_type		 type;
303 	u_int8_t		 linkstate;
304 	u_int8_t		 mediatype;
305 };
306 
307 struct ctl_adj {
308 	struct in_addr		 id;
309 	enum hello_type		 type;
310 	char			 ifname[IF_NAMESIZE];
311 	struct in_addr		 src_addr;
312 	u_int16_t		 holdtime;
313 };
314 
315 struct ctl_nbr {
316 	struct in_addr		 id;
317 	struct in_addr		 addr;
318 	time_t			 uptime;
319 	int			 nbr_state;
320 };
321 
322 struct ctl_rt {
323 	struct in_addr		 prefix;
324 	u_int8_t		 prefixlen;
325 	struct in_addr		 nexthop;
326 	u_int32_t		 local_label;
327 	u_int32_t		 remote_label;
328 	u_int8_t		 flags;
329 	u_int8_t		 in_use;
330 };
331 
332 /* parse.y */
333 struct ldpd_conf	*parse_config(char *, int);
334 int			 cmdline_symset(char *);
335 
336 /* kroute.c */
337 int		 kif_init(void);
338 void		 kif_redistribute(void);
339 int		 kr_init(int);
340 int		 kr_change(struct kroute *);
341 int		 kr_delete(struct kroute *);
342 void		 kr_shutdown(void);
343 void		 kr_fib_couple(void);
344 void		 kr_fib_decouple(void);
345 void		 kr_dispatch_msg(int, short, void *);
346 void		 kr_show_route(struct imsg *);
347 void		 kr_ifinfo(char *, pid_t);
348 struct kif	*kif_findname(char *);
349 void		 kr_reload(void);
350 
351 u_int8_t	mask2prefixlen(in_addr_t);
352 in_addr_t	prefixlen2mask(u_int8_t);
353 
354 /* log.h */
355 const char	*nbr_state_name(int);
356 const char	*if_state_name(int);
357 const char	*if_type_name(enum iface_type);
358 const char	*notification_name(u_int32_t);
359 
360 /* ldpd.c */
361 void	main_imsg_compose_ldpe(int, pid_t, void *, u_int16_t);
362 void	main_imsg_compose_lde(int, pid_t, void *, u_int16_t);
363 void	merge_config(struct ldpd_conf *, struct ldpd_conf *);
364 int	imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, pid_t,
365 	    int, void *, u_int16_t);
366 void	imsg_event_add(struct imsgev *);
367 void	evbuf_enqueue(struct evbuf *, struct ibuf *);
368 void	evbuf_event_add(struct evbuf *);
369 void	evbuf_init(struct evbuf *, int, void (*)(int, short, void *), void *);
370 void	evbuf_clear(struct evbuf *);
371 
372 /* printconf.c */
373 void	print_config(struct ldpd_conf *);
374 
375 #endif	/* _LDPD_H_ */
376