xref: /openbsd/usr.sbin/ldpd/ldpd.h (revision 2cba3533)
1 /*	$OpenBSD: ldpd.h,v 1.68 2016/05/23 18:40:15 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 LDPD_OPT_VERBOSE	0x00000001
41 #define LDPD_OPT_VERBOSE2	0x00000002
42 #define LDPD_OPT_NOACTION	0x00000004
43 
44 #define TCP_MD5_KEY_LEN		80
45 #define L2VPN_NAME_LEN		32
46 
47 #define	RT_BUF_SIZE		16384
48 #define	MAX_RTSOCK_BUF		128 * 1024
49 #define	LDP_BACKLOG		128
50 
51 #define	F_LDPD_INSERTED		0x0001
52 #define	F_CONNECTED		0x0002
53 #define	F_STATIC		0x0004
54 #define	F_DYNAMIC		0x0008
55 #define	F_REJECT		0x0010
56 #define	F_BLACKHOLE		0x0020
57 #define	F_REDISTRIBUTED		0x0040
58 
59 struct evbuf {
60 	struct msgbuf		wbuf;
61 	struct event		ev;
62 };
63 
64 struct imsgev {
65 	struct imsgbuf		 ibuf;
66 	void			(*handler)(int, short, void *);
67 	struct event		 ev;
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_SHOW_L2VPN_PW,
79 	IMSG_CTL_SHOW_L2VPN_BINDING,
80 	IMSG_CTL_FIB_COUPLE,
81 	IMSG_CTL_FIB_DECOUPLE,
82 	IMSG_CTL_KROUTE,
83 	IMSG_CTL_KROUTE_ADDR,
84 	IMSG_CTL_IFINFO,
85 	IMSG_CTL_END,
86 	IMSG_CTL_LOG_VERBOSE,
87 	IMSG_KLABEL_CHANGE,
88 	IMSG_KLABEL_DELETE,
89 	IMSG_KPWLABEL_CHANGE,
90 	IMSG_KPWLABEL_DELETE,
91 	IMSG_IFSTATUS,
92 	IMSG_NEWADDR,
93 	IMSG_DELADDR,
94 	IMSG_LABEL_MAPPING,
95 	IMSG_LABEL_MAPPING_FULL,
96 	IMSG_LABEL_REQUEST,
97 	IMSG_LABEL_RELEASE,
98 	IMSG_LABEL_WITHDRAW,
99 	IMSG_LABEL_ABORT,
100 	IMSG_REQUEST_ADD,
101 	IMSG_REQUEST_ADD_END,
102 	IMSG_MAPPING_ADD,
103 	IMSG_MAPPING_ADD_END,
104 	IMSG_RELEASE_ADD,
105 	IMSG_RELEASE_ADD_END,
106 	IMSG_WITHDRAW_ADD,
107 	IMSG_WITHDRAW_ADD_END,
108 	IMSG_ADDRESS_ADD,
109 	IMSG_ADDRESS_DEL,
110 	IMSG_NOTIFICATION,
111 	IMSG_NOTIFICATION_SEND,
112 	IMSG_NEIGHBOR_UP,
113 	IMSG_NEIGHBOR_DOWN,
114 	IMSG_NETWORK_ADD,
115 	IMSG_NETWORK_DEL,
116 	IMSG_SOCKET_NET,
117 	IMSG_CLOSE_SOCKETS,
118 	IMSG_REQUEST_SOCKETS,
119 	IMSG_SETUP_SOCKETS,
120 	IMSG_RECONF_CONF,
121 	IMSG_RECONF_IFACE,
122 	IMSG_RECONF_TNBR,
123 	IMSG_RECONF_NBRP,
124 	IMSG_RECONF_L2VPN,
125 	IMSG_RECONF_L2VPN_IF,
126 	IMSG_RECONF_L2VPN_PW,
127 	IMSG_RECONF_END
128 };
129 
130 /* interface states */
131 #define	IF_STA_DOWN		0x01
132 #define	IF_STA_ACTIVE		0x02
133 
134 /* targeted neighbor states */
135 #define	TNBR_STA_DOWN		0x01
136 #define	TNBR_STA_ACTIVE		0x02
137 
138 /* interface types */
139 enum iface_type {
140 	IF_TYPE_POINTOPOINT,
141 	IF_TYPE_BROADCAST
142 };
143 
144 /* neighbor states */
145 #define	NBR_STA_PRESENT		0x0001
146 #define	NBR_STA_INITIAL		0x0002
147 #define	NBR_STA_OPENREC		0x0004
148 #define	NBR_STA_OPENSENT	0x0008
149 #define	NBR_STA_OPER		0x0010
150 #define	NBR_STA_SESSION		(NBR_STA_INITIAL | NBR_STA_OPENREC | \
151 				NBR_STA_OPENSENT | NBR_STA_OPER)
152 
153 /* neighbor events */
154 enum nbr_event {
155 	NBR_EVT_NOTHING,
156 	NBR_EVT_MATCH_ADJ,
157 	NBR_EVT_CONNECT_UP,
158 	NBR_EVT_CLOSE_SESSION,
159 	NBR_EVT_INIT_RCVD,
160 	NBR_EVT_KEEPALIVE_RCVD,
161 	NBR_EVT_PDU_RCVD,
162 	NBR_EVT_PDU_SENT,
163 	NBR_EVT_INIT_SENT
164 };
165 
166 /* neighbor actions */
167 enum nbr_action {
168 	NBR_ACT_NOTHING,
169 	NBR_ACT_RST_KTIMEOUT,
170 	NBR_ACT_SESSION_EST,
171 	NBR_ACT_RST_KTIMER,
172 	NBR_ACT_CONNECT_SETUP,
173 	NBR_ACT_PASSIVE_INIT,
174 	NBR_ACT_KEEPALIVE_SEND,
175 	NBR_ACT_CLOSE_SESSION
176 };
177 
178 TAILQ_HEAD(mapping_head, mapping_entry);
179 
180 struct map {
181 	uint8_t		type;
182 	uint32_t	messageid;
183 	union map_fec {
184 		struct {
185 			struct in_addr	prefix;
186 			uint8_t		prefixlen;
187 		} ipv4;
188 		struct {
189 			uint16_t	type;
190 			uint32_t	pwid;
191 			uint32_t	group_id;
192 			uint16_t	ifmtu;
193 		} pwid;
194 	} fec;
195 	uint32_t	label;
196 	uint32_t	requestid;
197 	uint32_t	pw_status;
198 	uint8_t		flags;
199 };
200 #define F_MAP_REQ_ID	0x01	/* optional request message id present */
201 #define F_MAP_PW_CWORD	0x02	/* pseudowire control word */
202 #define F_MAP_PW_ID	0x04	/* pseudowire connection id */
203 #define F_MAP_PW_IFMTU	0x08	/* pseudowire interface parameter */
204 #define F_MAP_PW_STATUS	0x10	/* pseudowire status */
205 
206 struct notify_msg {
207 	uint32_t	status;
208 	uint32_t	messageid;	/* network byte order */
209 	uint16_t	type;		/* network byte order */
210 	uint32_t	pw_status;
211 	struct map	fec;
212 	uint8_t		flags;
213 };
214 #define F_NOTIF_PW_STATUS	0x01	/* pseudowire status tlv present */
215 #define F_NOTIF_FEC		0x02	/* fec tlv present */
216 
217 struct if_addr {
218 	LIST_ENTRY(if_addr)	 entry;
219 	struct in_addr		 addr;
220 	struct in_addr		 mask;
221 	struct in_addr		 dstbrd;
222 };
223 LIST_HEAD(if_addr_head, if_addr);
224 
225 struct iface {
226 	LIST_ENTRY(iface)	 entry;
227 	struct event		 hello_timer;
228 
229 	char			 name[IF_NAMESIZE];
230 	struct if_addr_head	 addr_list;
231 	LIST_HEAD(, adj)	 adj_list;
232 
233 	time_t			 uptime;
234 	unsigned int		 ifindex;
235 	int			 state;
236 	uint16_t		 hello_holdtime;
237 	uint16_t		 hello_interval;
238 	uint16_t		 flags;
239 	enum iface_type		 type;
240 	uint8_t			 if_type;
241 	uint8_t			 linkstate;
242 };
243 
244 /* source of targeted hellos */
245 struct tnbr {
246 	LIST_ENTRY(tnbr)	 entry;
247 	struct event		 hello_timer;
248 	struct adj		*adj;
249 	struct in_addr		 addr;
250 
251 	int			 state;
252 	uint16_t		 hello_holdtime;
253 	uint16_t		 hello_interval;
254 	uint16_t		 pw_count;
255 	uint8_t			 flags;
256 };
257 #define F_TNBR_CONFIGURED	 0x01
258 #define F_TNBR_DYNAMIC		 0x02
259 
260 enum auth_method {
261 	AUTH_NONE,
262 	AUTH_MD5SIG
263 };
264 
265 /* neighbor specific parameters */
266 struct nbr_params {
267 	LIST_ENTRY(nbr_params)	 entry;
268 	struct in_addr		 lsr_id;
269 	uint16_t		 keepalive;
270 	struct {
271 		enum auth_method	 method;
272 		char			 md5key[TCP_MD5_KEY_LEN];
273 		uint8_t			 md5key_len;
274 	} auth;
275 	uint8_t			 flags;
276 };
277 #define F_NBRP_KEEPALIVE	 0x01
278 
279 struct l2vpn_if {
280 	LIST_ENTRY(l2vpn_if)	 entry;
281 	struct l2vpn		*l2vpn;
282 	char			 ifname[IF_NAMESIZE];
283 	unsigned int		 ifindex;
284 	uint16_t		 flags;
285 	uint8_t			 link_state;
286 };
287 
288 struct l2vpn_pw {
289 	LIST_ENTRY(l2vpn_pw)	 entry;
290 	struct l2vpn		*l2vpn;
291 	struct in_addr		 lsr_id;
292 	uint32_t		 pwid;
293 	char			 ifname[IF_NAMESIZE];
294 	unsigned int		 ifindex;
295 	uint32_t		 remote_group;
296 	uint16_t		 remote_mtu;
297 	uint32_t		 remote_status;
298 	uint8_t			 flags;
299 };
300 #define F_PW_STATUSTLV_CONF	0x01	/* status tlv configured */
301 #define F_PW_STATUSTLV		0x02	/* status tlv negotiated */
302 #define F_PW_CWORD_CONF		0x04	/* control word configured */
303 #define F_PW_CWORD		0x08	/* control word negotiated */
304 #define F_PW_STATUS_UP		0x10	/* pseudowire is operational */
305 
306 struct l2vpn {
307 	LIST_ENTRY(l2vpn)	 entry;
308 	char			 name[L2VPN_NAME_LEN];
309 	int			 type;
310 	int			 pw_type;
311 	int			 mtu;
312 	char			 br_ifname[IF_NAMESIZE];
313 	unsigned int		 br_ifindex;
314 	LIST_HEAD(, l2vpn_if)	 if_list;
315 	LIST_HEAD(, l2vpn_pw)	 pw_list;
316 };
317 #define L2VPN_TYPE_VPWS		1
318 #define L2VPN_TYPE_VPLS		2
319 
320 /* ldp_conf */
321 enum {
322 	PROC_MAIN,
323 	PROC_LDP_ENGINE,
324 	PROC_LDE_ENGINE
325 } ldpd_process;
326 
327 enum socket_type {
328 	LDP_SOCKET_DISC,
329 	LDP_SOCKET_EDISC,
330 	LDP_SOCKET_SESSION
331 };
332 
333 enum hello_type {
334 	HELLO_LINK,
335 	HELLO_TARGETED
336 };
337 
338 struct ldpd_conf {
339 	struct in_addr		 rtr_id;
340 	struct in_addr		 trans_addr;
341 	LIST_HEAD(, iface)	 iface_list;
342 	LIST_HEAD(, tnbr)	 tnbr_list;
343 	LIST_HEAD(, nbr_params)	 nbrp_list;
344 	LIST_HEAD(, l2vpn)	 l2vpn_list;
345 	uint16_t		 keepalive;
346 	uint16_t		 thello_holdtime;
347 	uint16_t		 thello_interval;
348 	int			 flags;
349 };
350 #define	F_LDPD_NO_FIB_UPDATE	0x0001
351 #define	F_LDPD_TH_ACCEPT	0x0002
352 #define	F_LDPD_EXPNULL		0x0004
353 
354 struct ldpd_global {
355 	int			 cmd_opts;
356 	time_t			 uptime;
357 	int			 pfkeysock;
358 	int			 ldp_disc_socket;
359 	int			 ldp_edisc_socket;
360 	int			 ldp_session_socket;
361 	struct if_addr_head	 addr_list;
362 	TAILQ_HEAD(, pending_conn) pending_conns;
363 };
364 
365 extern struct ldpd_global global;
366 
367 /* kroute */
368 struct kroute {
369 	struct in_addr		 prefix;
370 	struct in_addr		 nexthop;
371 	uint32_t		 local_label;
372 	uint32_t		 remote_label;
373 	uint16_t		 flags;
374 	unsigned short		 ifindex;
375 	uint8_t			 prefixlen;
376 	uint8_t			 priority;
377 };
378 
379 struct kpw {
380 	unsigned short		 ifindex;
381 	int			 pw_type;
382 	struct in_addr		 nexthop;
383 	uint32_t		 local_label;
384 	uint32_t		 remote_label;
385 	uint8_t			 flags;
386 };
387 
388 struct kaddr {
389 	unsigned short		 ifindex;
390 	struct in_addr		 addr;
391 	struct in_addr		 mask;
392 	struct in_addr		 dstbrd;
393 };
394 
395 struct kif {
396 	char			 ifname[IF_NAMESIZE];
397 	uint64_t		 baudrate;
398 	int			 flags;
399 	int			 mtu;
400 	unsigned short		 ifindex;
401 	uint8_t			 if_type;
402 	uint8_t			 link_state;
403 };
404 
405 /* control data structures */
406 struct ctl_iface {
407 	char			 name[IF_NAMESIZE];
408 	time_t			 uptime;
409 	unsigned int		 ifindex;
410 	int			 state;
411 	uint16_t		 adj_cnt;
412 	uint16_t		 flags;
413 	uint16_t		 hello_holdtime;
414 	uint16_t		 hello_interval;
415 	enum iface_type		 type;
416 	uint8_t			 linkstate;
417 	uint8_t			 if_type;
418 };
419 
420 struct ctl_adj {
421 	struct in_addr		 id;
422 	enum hello_type		 type;
423 	char			 ifname[IF_NAMESIZE];
424 	struct in_addr		 src_addr;
425 	uint16_t		 holdtime;
426 };
427 
428 struct ctl_nbr {
429 	struct in_addr		 id;
430 	struct in_addr		 addr;
431 	time_t			 uptime;
432 	int			 nbr_state;
433 };
434 
435 struct ctl_rt {
436 	struct in_addr		 prefix;
437 	uint8_t			 prefixlen;
438 	struct in_addr		 nexthop;
439 	uint32_t		 local_label;
440 	uint32_t		 remote_label;
441 	uint8_t			 flags;
442 	uint8_t			 in_use;
443 };
444 
445 struct ctl_pw {
446 	uint16_t		 type;
447 	char			 ifname[IF_NAMESIZE];
448 	uint32_t		 pwid;
449 	struct in_addr		 lsr_id;
450 	uint32_t		 local_label;
451 	uint32_t		 local_gid;
452 	uint16_t		 local_ifmtu;
453 	uint32_t		 remote_label;
454 	uint32_t		 remote_gid;
455 	uint16_t		 remote_ifmtu;
456 	uint32_t		 status;
457 };
458 
459 /* parse.y */
460 struct ldpd_conf	*parse_config(char *);
461 int			 cmdline_symset(char *);
462 
463 /* kroute.c */
464 int		 kif_init(void);
465 void		 kif_redistribute(const char *);
466 int		 kr_init(int);
467 int		 kr_change(struct kroute *);
468 int		 kr_delete(struct kroute *);
469 void		 kif_clear(void);
470 void		 kr_shutdown(void);
471 void		 kr_fib_couple(void);
472 void		 kr_fib_decouple(void);
473 void		 kr_change_egress_label(int);
474 void		 kr_dispatch_msg(int, short, void *);
475 void		 kr_show_route(struct imsg *);
476 void		 kr_ifinfo(char *, pid_t);
477 struct kif	*kif_findname(char *);
478 uint8_t		 mask2prefixlen(in_addr_t);
479 in_addr_t	 prefixlen2mask(uint8_t);
480 void		 kmpw_set(struct kpw *);
481 void		 kmpw_unset(struct kpw *);
482 void		 kmpw_install(const char *, struct kpw *);
483 void		 kmpw_uninstall(const char *, struct kpw *);
484 
485 /* log.h */
486 const char	*nbr_state_name(int);
487 const char	*if_state_name(int);
488 const char	*if_type_name(enum iface_type);
489 const char	*notification_name(uint32_t);
490 
491 /* util.c */
492 int		 bad_ip_addr(struct in_addr);
493 
494 /* ldpd.c */
495 void	main_imsg_compose_ldpe(int, pid_t, void *, uint16_t);
496 void	main_imsg_compose_lde(int, pid_t, void *, uint16_t);
497 void	merge_config(struct ldpd_conf *, struct ldpd_conf *);
498 void	config_clear(struct ldpd_conf *);
499 int	imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
500 	    int, void *, uint16_t);
501 void	imsg_event_add(struct imsgev *);
502 void	evbuf_enqueue(struct evbuf *, struct ibuf *);
503 void	evbuf_event_add(struct evbuf *);
504 void	evbuf_init(struct evbuf *, int, void (*)(int, short, void *), void *);
505 void	evbuf_clear(struct evbuf *);
506 
507 /* socket.c */
508 int		 ldp_create_socket(enum socket_type);
509 void		 sock_set_recvbuf(int);
510 int		 sock_set_reuse(int, int);
511 int		 sock_set_ipv4_mcast_ttl(int, uint8_t);
512 int		 sock_set_ipv4_tos(int, int);
513 int		 sock_set_ipv4_recvif(int, int);
514 int		 sock_set_ipv4_mcast(struct iface *);
515 int		 sock_set_ipv4_mcast_loop(int);
516 
517 /* printconf.c */
518 void	print_config(struct ldpd_conf *);
519 
520 #endif	/* _LDPD_H_ */
521