xref: /openbsd/usr.sbin/ldpd/lde.h (revision 38e65088)
1 /*	$OpenBSD: lde.h,v 1.50 2017/03/04 00:21:48 renato Exp $ */
2 
3 /*
4  * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5  * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
6  * Copyright (c) 2004, 2005 Esben Norby <norby@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 _LDE_H_
22 #define _LDE_H_
23 
24 #include <sys/types.h>
25 #include <sys/queue.h>
26 #include <sys/tree.h>
27 
28 enum fec_type {
29 	FEC_TYPE_IPV4,
30 	FEC_TYPE_IPV6,
31 	FEC_TYPE_PWID
32 };
33 
34 struct fec {
35 	RB_ENTRY(fec)		entry;
36 	enum fec_type		type;
37 	union {
38 		struct {
39 			struct in_addr	prefix;
40 			uint8_t		prefixlen;
41 		} ipv4;
42 		struct {
43 			struct in6_addr	prefix;
44 			uint8_t		prefixlen;
45 		} ipv6;
46 		struct {
47 			uint16_t	type;
48 			uint32_t	pwid;
49 			struct in_addr	lsr_id;
50 		} pwid;
51 	} u;
52 };
53 RB_HEAD(fec_tree, fec);
54 RB_PROTOTYPE(fec_tree, fec, entry, fec_compare)
55 
56 /* request entries */
57 struct lde_req {
58 	struct fec		 fec;
59 	uint32_t		 msg_id;
60 };
61 
62 /* mapping entries */
63 struct lde_map {
64 	struct fec		 fec;
65 	LIST_ENTRY(lde_map)	 entry;
66 	struct lde_nbr		*nexthop;
67 	struct map		 map;
68 };
69 
70 /* withdraw entries */
71 struct lde_wdraw {
72 	struct fec		 fec;
73 	uint32_t		 label;
74 };
75 
76 /* Addresses belonging to neighbor */
77 struct lde_addr {
78 	TAILQ_ENTRY(lde_addr)	 entry;
79 	int			 af;
80 	union ldpd_addr		 addr;
81 };
82 
83 /* just the info LDE needs */
84 struct lde_nbr {
85 	RB_ENTRY(lde_nbr)	 entry;
86 	uint32_t		 peerid;
87 	struct in_addr		 id;
88 	int			 v4_enabled;	/* announce/process v4 msgs */
89 	int			 v6_enabled;	/* announce/process v6 msgs */
90 	int			 flags;		/* capabilities */
91 	struct fec_tree		 recv_req;
92 	struct fec_tree		 sent_req;
93 	struct fec_tree		 recv_map;
94 	struct fec_tree		 sent_map;
95 	struct fec_tree		 sent_wdraw;
96 	TAILQ_HEAD(, lde_addr)	 addr_list;
97 };
98 RB_HEAD(nbr_tree, lde_nbr);
99 RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare)
100 
101 struct fec_nh {
102 	LIST_ENTRY(fec_nh)	 entry;
103 	int			 af;
104 	union ldpd_addr		 nexthop;
105 	uint32_t		 remote_label;
106 	uint8_t			 priority;
107 };
108 
109 struct fec_node {
110 	struct fec		 fec;
111 
112 	LIST_HEAD(, fec_nh)	 nexthops;	/* fib nexthops */
113 	LIST_HEAD(, lde_map)	 downstream;	/* recv mappings */
114 	LIST_HEAD(, lde_map)	 upstream;	/* sent mappings */
115 
116 	uint32_t		 local_label;
117 	void			*data;		/* fec specific data */
118 };
119 
120 #define LDE_GC_INTERVAL 300
121 
122 extern struct ldpd_conf	*ldeconf;
123 extern struct fec_tree	 ft;
124 extern struct nbr_tree	 lde_nbrs;
125 extern struct event	 gc_timer;
126 
127 /* lde.c */
128 void		 lde(int, int);
129 int		 lde_imsg_compose_ldpe(int, uint32_t, pid_t, void *, uint16_t);
130 uint32_t	 lde_assign_label(void);
131 void		 lde_send_change_klabel(struct fec_node *, struct fec_nh *);
132 void		 lde_send_delete_klabel(struct fec_node *, struct fec_nh *);
133 void		 lde_fec2map(struct fec *, struct map *);
134 void		 lde_map2fec(struct map *, struct in_addr, struct fec *);
135 void		 lde_send_labelmapping(struct lde_nbr *, struct fec_node *,
136 		    int);
137 void		 lde_send_labelwithdraw(struct lde_nbr *, struct fec_node *,
138 		    struct map *, struct status_tlv *);
139 void		 lde_send_labelwithdraw_wcard(struct lde_nbr *, uint32_t);
140 void		 lde_send_labelwithdraw_twcard_prefix(struct lde_nbr *,
141 		    uint16_t, uint32_t);
142 void		 lde_send_labelwithdraw_twcard_pwid(struct lde_nbr *, uint16_t,
143 		    uint32_t);
144 void		 lde_send_labelwithdraw_pwid_wcard(struct lde_nbr *, uint16_t,
145 		    uint32_t);
146 void		 lde_send_labelrelease(struct lde_nbr *, struct fec_node *,
147 		    struct map *, uint32_t);
148 void		 lde_send_notification(struct lde_nbr *, uint32_t, uint32_t,
149 		    uint16_t);
150 void		 lde_send_notification_eol_prefix(struct lde_nbr *, int);
151 void		 lde_send_notification_eol_pwid(struct lde_nbr *, uint16_t);
152 struct lde_nbr	*lde_nbr_find_by_lsrid(struct in_addr);
153 struct lde_nbr	*lde_nbr_find_by_addr(int, union ldpd_addr *);
154 struct lde_map	*lde_map_add(struct lde_nbr *, struct fec_node *, int);
155 void		 lde_map_del(struct lde_nbr *, struct lde_map *, int);
156 struct lde_req	*lde_req_add(struct lde_nbr *, struct fec *, int);
157 void		 lde_req_del(struct lde_nbr *, struct lde_req *, int);
158 struct lde_wdraw *lde_wdraw_add(struct lde_nbr *, struct fec_node *);
159 void		 lde_wdraw_del(struct lde_nbr *, struct lde_wdraw *);
160 void		 lde_change_egress_label(int, int);
161 struct lde_addr	*lde_address_find(struct lde_nbr *, int,
162 		    union ldpd_addr *);
163 
164 /* lde_lib.c */
165 void		 fec_init(struct fec_tree *);
166 struct fec	*fec_find(struct fec_tree *, struct fec *);
167 int		 fec_insert(struct fec_tree *, struct fec *);
168 int		 fec_remove(struct fec_tree *, struct fec *);
169 void		 fec_clear(struct fec_tree *, void (*)(void *));
170 void		 rt_dump(pid_t);
171 void		 fec_snap(struct lde_nbr *);
172 void		 fec_tree_clear(void);
173 struct fec_nh	*fec_nh_find(struct fec_node *, int, union ldpd_addr *,
174 		    uint8_t);
175 uint32_t	 egress_label(enum fec_type);
176 void		 lde_kernel_insert(struct fec *, int, union ldpd_addr *,
177 		    uint8_t, int, void *);
178 void		 lde_kernel_remove(struct fec *, int, union ldpd_addr *,
179 		    uint8_t);
180 void		 lde_check_mapping(struct map *, struct lde_nbr *);
181 void		 lde_check_request(struct map *, struct lde_nbr *);
182 void		 lde_check_request_wcard(struct map *, struct lde_nbr *);
183 void		 lde_check_release(struct map *, struct lde_nbr *);
184 void		 lde_check_release_wcard(struct map *, struct lde_nbr *);
185 void		 lde_check_withdraw(struct map *, struct lde_nbr *);
186 void		 lde_check_withdraw_wcard(struct map *, struct lde_nbr *);
187 int		 lde_wildcard_apply(struct map *, struct fec *,
188 		    struct lde_map *);
189 void		 lde_gc_timer(int, short, void *);
190 void		 lde_gc_start_timer(void);
191 void		 lde_gc_stop_timer(void);
192 
193 /* l2vpn.c */
194 struct l2vpn	*l2vpn_new(const char *);
195 struct l2vpn	*l2vpn_find(struct ldpd_conf *, const char *);
196 void		 l2vpn_del(struct l2vpn *);
197 void		 l2vpn_init(struct l2vpn *);
198 void		 l2vpn_exit(struct l2vpn *);
199 struct l2vpn_if	*l2vpn_if_new(struct l2vpn *, struct kif *);
200 struct l2vpn_if	*l2vpn_if_find(struct l2vpn *, unsigned int);
201 void		 l2vpn_if_update(struct l2vpn_if *);
202 struct l2vpn_pw	*l2vpn_pw_new(struct l2vpn *, struct kif *);
203 struct l2vpn_pw *l2vpn_pw_find(struct l2vpn *, unsigned int);
204 void		 l2vpn_pw_init(struct l2vpn_pw *);
205 void		 l2vpn_pw_exit(struct l2vpn_pw *);
206 void		 l2vpn_pw_reset(struct l2vpn_pw *);
207 int		 l2vpn_pw_ok(struct l2vpn_pw *, struct fec_nh *);
208 int		 l2vpn_pw_negotiate(struct lde_nbr *, struct fec_node *,
209 		    struct map *);
210 void		 l2vpn_send_pw_status(struct lde_nbr *, uint32_t, struct fec *);
211 void		 l2vpn_send_pw_status_wcard(struct lde_nbr *, uint32_t,
212 		    uint16_t, uint32_t);
213 void		 l2vpn_recv_pw_status(struct lde_nbr *, struct notify_msg *);
214 void		 l2vpn_recv_pw_status_wcard(struct lde_nbr *,
215 		    struct notify_msg *);
216 void		 l2vpn_sync_pws(int, union ldpd_addr *);
217 void		 l2vpn_pw_ctl(pid_t);
218 void		 l2vpn_binding_ctl(pid_t);
219 
220 #endif	/* _LDE_H_ */
221