xref: /openbsd/usr.sbin/ldpd/ldpe.h (revision 91f110e0)
1 /*	$OpenBSD: ldpe.h,v 1.31 2013/10/17 17:52:21 renato Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _LDPE_H_
20 #define _LDPE_H_
21 
22 #define min(x,y) ((x) <= (y) ? (x) : (y))
23 #define max(x,y) ((x) > (y) ? (x) : (y))
24 
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <netinet/in_systm.h>
29 #include <netinet/ip.h>
30 
31 TAILQ_HEAD(ctl_conns, ctl_conn)	ctl_conns;
32 
33 struct hello_source {
34 	enum hello_type		 type;
35 	struct {
36 		struct iface	*iface;
37 		struct in_addr	 src_addr;
38 	}			 link;
39 	struct tnbr		*target;
40 };
41 
42 struct adj {
43 	LIST_ENTRY(adj)		 nbr_entry;
44 	LIST_ENTRY(adj)		 iface_entry;
45 	struct nbr		*nbr;
46 	struct hello_source	 source;
47 	struct event		 inactivity_timer;
48 	u_int16_t		 holdtime;
49 	struct in_addr		 addr;
50 };
51 
52 struct nbr;
53 struct tcp_conn {
54 	struct nbr		*nbr;
55 	int			 fd;
56 	struct ibuf_read	*rbuf;
57 	struct evbuf		 wbuf;
58 	struct event		 rev;
59 };
60 
61 struct nbr {
62 	RB_ENTRY(nbr)		 id_tree, pid_tree;
63 	struct tcp_conn		*tcp;
64 	LIST_HEAD(, adj)	 adj_list;	/* adjacencies */
65 	struct event		 ev_connect;
66 	struct event		 keepalive_timer;
67 	struct event		 keepalive_timeout;
68 	struct event		 initdelay_timer;
69 
70 	struct mapping_head	 mapping_list;
71 	struct mapping_head	 withdraw_list;
72 	struct mapping_head	 request_list;
73 	struct mapping_head	 release_list;
74 	struct mapping_head	 abortreq_list;
75 
76 	struct in_addr		 addr;
77 	struct in_addr		 id;
78 
79 	time_t			 uptime;
80 	u_int32_t		 peerid;	/* unique ID in DB */
81 
82 	int			 fd;
83 	int			 state;
84 	int			 idtimer_cnt;
85 	u_int16_t		 keepalive;
86 };
87 
88 struct mapping_entry {
89 	TAILQ_ENTRY(mapping_entry)	entry;
90 	struct map			map;
91 };
92 
93 /* accept.c */
94 void	accept_init(void);
95 int	accept_add(int, void (*)(int, short, void *), void *);
96 void	accept_del(int);
97 void	accept_pause(void);
98 void	accept_unpause(void);
99 
100 /* hello.c */
101 int	 send_hello(enum hello_type, struct iface *, struct tnbr *);
102 void	 recv_hello(struct iface *,  struct in_addr, char *, u_int16_t);
103 
104 /* init.c */
105 void	 send_init(struct nbr *);
106 int	 recv_init(struct nbr *, char *, u_int16_t);
107 
108 /* keepalive.c */
109 void	 send_keepalive(struct nbr *);
110 int	 recv_keepalive(struct nbr *, char *, u_int16_t);
111 
112 /* notification.c */
113 void	 send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t);
114 void	 send_notification(u_int32_t, struct tcp_conn *, u_int32_t,
115 	    u_int32_t);
116 int	 recv_notification(struct nbr *, char *, u_int16_t);
117 
118 /* address.c */
119 void	 send_address(struct nbr *, struct if_addr *);
120 int	 recv_address(struct nbr *, char *, u_int16_t);
121 void	 send_address_withdraw(struct nbr *, struct if_addr *);
122 
123 /* labelmapping.c */
124 #define PREFIX_SIZE(x)	(((x) + 7) / 8)
125 void	 send_labelmessage(struct nbr *, u_int16_t, struct mapping_head *);
126 int	 recv_labelmessage(struct nbr *, char *, u_int16_t, u_int16_t);
127 
128 /* ldpe.c */
129 pid_t		 ldpe(struct ldpd_conf *, int[2], int[2], int[2]);
130 void		 ldpe_dispatch_main(int, short, void *);
131 void		 ldpe_dispatch_lde(int, short, void *);
132 int		 ldpe_imsg_compose_parent(int, pid_t, void *, u_int16_t);
133 int		 ldpe_imsg_compose_lde(int, u_int32_t, pid_t, void *,
134 		     u_int16_t);
135 u_int32_t	 ldpe_router_id(void);
136 void		 ldpe_fib_update(int);
137 void		 ldpe_iface_ctl(struct ctl_conn *, unsigned int);
138 
139 /* interface.c */
140 int		 if_fsm(struct iface *, enum iface_event);
141 
142 struct iface	*if_new(struct kif *);
143 void		 if_del(struct iface *);
144 void		 if_init(struct ldpd_conf *, struct iface *);
145 struct iface	*if_lookup(u_short);
146 
147 struct ctl_iface	*if_to_ctl(struct iface *);
148 
149 int	 if_join_group(struct iface *, struct in_addr *);
150 int	 if_leave_group(struct iface *, struct in_addr *);
151 int	 if_set_mcast(struct iface *);
152 int	 if_set_recvif(int, int);
153 void	 if_set_recvbuf(int);
154 int	 if_set_mcast_loop(int);
155 int	 if_set_mcast_ttl(int, u_int8_t);
156 int	 if_set_tos(int, int);
157 int	 if_set_reuse(int, int);
158 
159 /* adjacency.c */
160 struct adj	*adj_new(struct nbr *, struct hello_source *, u_int16_t,
161     struct in_addr);
162 void		 adj_del(struct adj *);
163 struct adj	*adj_find(struct nbr *, struct hello_source *);
164 void		 adj_start_itimer(struct adj *);
165 void		 adj_stop_itimer(struct adj *);
166 struct tnbr	*tnbr_new(struct ldpd_conf *, struct in_addr, int);
167 void		 tnbr_del(struct tnbr *);
168 void		 tnbr_init(struct ldpd_conf *, struct tnbr *);
169 struct tnbr	*tnbr_find(struct in_addr);
170 
171 struct ctl_adj	*adj_to_ctl(struct adj *);
172 void		 ldpe_adj_ctl(struct ctl_conn *);
173 
174 /* neighbor.c */
175 struct nbr	*nbr_new(struct in_addr, struct in_addr);
176 void		 nbr_del(struct nbr *);
177 
178 struct nbr	*nbr_find_ldpid(u_int32_t);
179 struct nbr	*nbr_find_peerid(u_int32_t);
180 
181 int	 nbr_fsm(struct nbr *, enum nbr_event);
182 int	 nbr_session_active_role(struct nbr *);
183 
184 void	 nbr_ktimer(int, short, void *);
185 void	 nbr_start_ktimer(struct nbr *);
186 void	 nbr_stop_ktimer(struct nbr *);
187 void	 nbr_ktimeout(int, short, void *);
188 void	 nbr_start_ktimeout(struct nbr *);
189 void	 nbr_stop_ktimeout(struct nbr *);
190 void	 nbr_idtimer(int, short, void *);
191 void	 nbr_start_idtimer(struct nbr *);
192 void	 nbr_stop_idtimer(struct nbr *);
193 int	 nbr_pending_idtimer(struct nbr *);
194 int	 nbr_pending_connect(struct nbr *);
195 
196 int	 nbr_establish_connection(struct nbr *);
197 
198 void			 nbr_mapping_add(struct nbr *, struct mapping_head *,
199 			    struct map *);
200 struct mapping_entry	*nbr_mapping_find(struct nbr *, struct mapping_head *,
201 			    struct map *);
202 void			 nbr_mapping_del(struct nbr *, struct mapping_head *,
203 			    struct map *);
204 void			 mapping_list_clr(struct mapping_head *);
205 
206 struct ctl_nbr	*nbr_to_ctl(struct nbr *);
207 void		 ldpe_nbr_ctl(struct ctl_conn *);
208 
209 /* packet.c */
210 int	 gen_ldp_hdr(struct ibuf *, u_int16_t);
211 int	 gen_msg_tlv(struct ibuf *, u_int32_t, u_int16_t);
212 int	 send_packet(int, struct iface *, void *, size_t, struct sockaddr_in *);
213 void	 disc_recv_packet(int, short, void *);
214 void	 session_accept(int, short, void *);
215 
216 struct tcp_conn *tcp_new(int, struct nbr *);
217 void		 tcp_close(struct tcp_conn *);
218 
219 void	 session_read(int, short, void *);
220 void	 session_write(int, short, void *);
221 void	 session_close(struct nbr *);
222 void	 session_shutdown(struct nbr *, u_int32_t, u_int32_t, u_int32_t);
223 
224 char	*pkt_ptr;	/* packet buffer */
225 
226 #endif	/* _LDPE_H_ */
227