xref: /openbsd-src/usr.sbin/ripd/ripd.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: ripd.h,v 1.21 2009/11/02 20:28:49 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
5  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _RIPD_H_
21 #define _RIPD_H_
22 
23 #include <sys/queue.h>
24 #include <sys/socket.h>
25 #include <sys/tree.h>
26 #include <md5.h>
27 #include <net/if.h>
28 #include <netinet/in.h>
29 #include <event.h>
30 
31 #include <imsg.h>
32 
33 #define	CONF_FILE		"/etc/ripd.conf"
34 #define	RIPD_SOCKET		"/var/run/ripd.sock"
35 #define	RIPD_USER		"_ripd"
36 
37 #define	NBR_HASHSIZE		128
38 #define	NBR_IDSELF		1
39 #define	NBR_CNTSTART		(NBR_IDSELF + 1)
40 
41 #define	ROUTE_TIMEOUT		180
42 #define ROUTE_GARBAGE		120
43 
44 #define	NBR_TIMEOUT		180
45 
46 #define RT_BUF_SIZE		16384
47 #define MAX_RTSOCK_BUF		128 * 1024
48 
49 #define	RIPD_FLAG_NO_FIB_UPDATE	0x0001
50 
51 #define	F_RIPD_INSERTED		0x0001
52 #define	F_KERNEL		0x0002
53 #define	F_CONNECTED		0x0008
54 #define	F_DOWN			0x0010
55 #define	F_STATIC		0x0020
56 #define	F_DYNAMIC		0x0040
57 #define	F_REDISTRIBUTED		0x0100
58 #define	F_REJECT		0x0200
59 #define	F_BLACKHOLE		0x0400
60 
61 #define REDISTRIBUTE_ON		0x01
62 
63 #define	OPT_SPLIT_HORIZON	0x01
64 #define	OPT_SPLIT_POISONED	0x02
65 #define	OPT_TRIGGERED_UPDATES	0x04
66 
67 enum imsg_type {
68 	IMSG_NONE,
69 	IMSG_CTL_END,
70 	IMSG_CTL_RELOAD,
71 	IMSG_CTL_IFINFO,
72 	IMSG_IFINFO,
73 	IMSG_CTL_FIB_COUPLE,
74 	IMSG_CTL_FIB_DECOUPLE,
75 	IMSG_CTL_KROUTE,
76 	IMSG_CTL_KROUTE_ADDR,
77 	IMSG_CTL_SHOW_INTERFACE,
78 	IMSG_CTL_SHOW_IFACE,
79 	IMSG_CTL_SHOW_NBR,
80 	IMSG_CTL_SHOW_RIB,
81 	IMSG_CTL_LOG_VERBOSE,
82 	IMSG_KROUTE_CHANGE,
83 	IMSG_KROUTE_DELETE,
84 	IMSG_NETWORK_ADD,
85 	IMSG_NETWORK_DEL,
86 	IMSG_ROUTE_FEED,
87 	IMSG_RESPONSE_ADD,
88 	IMSG_SEND_RESPONSE,
89 	IMSG_FULL_RESPONSE,
90 	IMSG_ROUTE_REQUEST,
91 	IMSG_ROUTE_REQUEST_END,
92 	IMSG_FULL_REQUEST,
93 	IMSG_REQUEST_ADD,
94 	IMSG_SEND_REQUEST,
95 	IMSG_SEND_TRIGGERED_UPDATE,
96 	IMSG_DEMOTE
97 };
98 
99 struct imsgev {
100 	struct imsgbuf		 ibuf;
101 	void			(*handler)(int, short, void *);
102 	struct event		 ev;
103 	void			*data;
104 	short			 events;
105 };
106 
107 /* interface states */
108 #define IF_STA_DOWN		0x01
109 #define IF_STA_ACTIVE		(~IF_STA_DOWN)
110 #define IF_STA_ANY		0x7f
111 
112 /* interface events */
113 enum iface_event {
114 	IF_EVT_NOTHING,
115 	IF_EVT_UP,
116 	IF_EVT_DOWN
117 };
118 
119 /* interface actions */
120 enum iface_action {
121 	IF_ACT_NOTHING,
122 	IF_ACT_STRT,
123 	IF_ACT_RST
124 };
125 
126 /* interface types */
127 enum iface_type {
128 	IF_TYPE_POINTOPOINT,
129 	IF_TYPE_BROADCAST,
130 	IF_TYPE_NBMA,
131 	IF_TYPE_POINTOMULTIPOINT
132 };
133 
134 /* neighbor states */
135 #define NBR_STA_DOWN		0x01
136 #define	NBR_STA_REQ_RCVD	0x02
137 #define NBR_STA_ACTIVE		(~NBR_STA_DOWN)
138 #define NBR_STA_ANY		0xff
139 
140 struct auth_md {
141 	TAILQ_ENTRY(auth_md)	 entry;
142 	u_int32_t		 seq_modulator;
143 	u_int8_t		 key[MD5_DIGEST_LENGTH];
144 	u_int8_t		 keyid;
145 };
146 
147 #define MAX_SIMPLE_AUTH_LEN	16
148 
149 /* auth types */
150 enum auth_type {
151 	AUTH_NONE = 1,
152 	AUTH_SIMPLE,
153 	AUTH_CRYPT
154 };
155 
156 TAILQ_HEAD(auth_md_head, auth_md);
157 TAILQ_HEAD(packet_head, packet_entry);
158 
159 struct iface {
160 	LIST_ENTRY(iface)	 entry;
161 	LIST_HEAD(, nbr)	 nbr_list;
162 	LIST_HEAD(, nbr_failed)	 failed_nbr_list;
163 	char			 name[IF_NAMESIZE];
164 	char			 demote_group[IFNAMSIZ];
165 	u_int8_t		 auth_key[MAX_SIMPLE_AUTH_LEN];
166 	struct in_addr		 addr;
167 	struct in_addr		 dst;
168 	struct in_addr		 mask;
169 	struct packet_head	 rq_list;
170 	struct packet_head	 rp_list;
171 	struct auth_md_head	 auth_md_list;
172 
173 	u_int64_t		 baudrate;
174 	time_t			 uptime;
175 	u_int			 mtu;
176 	int			 fd; /* XXX */
177 	int			 state;
178 	u_short			 ifindex;
179 	u_int16_t		 cost;
180 	u_int16_t		 flags;
181 	enum iface_type		 type;
182 	enum auth_type		 auth_type;
183 	u_int8_t		 linktype;
184 	u_int8_t		 media_type;
185 	u_int8_t		 passive;
186 	u_int8_t		 linkstate;
187 	u_int8_t		 auth_keyid;
188 };
189 
190 struct rip_route {
191 	struct in_addr		 address;
192 	struct in_addr		 mask;
193 	struct in_addr		 nexthop;
194 	int			 refcount;
195 	u_short			 ifindex;
196 	u_int8_t		 metric;
197 };
198 
199 struct packet_entry {
200 	TAILQ_ENTRY(packet_entry)	 entry;
201 	struct rip_route		*rr;
202 };
203 
204 enum {
205 	PROC_MAIN,
206 	PROC_RIP_ENGINE,
207 	PROC_RDE_ENGINE
208 } ripd_process;
209 
210 #define	REDIST_CONNECTED	0x01
211 #define	REDIST_STATIC		0x02
212 #define	REDIST_LABEL		0x04
213 #define	REDIST_ADDR		0x08
214 #define	REDIST_DEFAULT		0x10
215 #define	REDIST_NO		0x20
216 
217 struct redistribute {
218 	SIMPLEQ_ENTRY(redistribute)	entry;
219 	struct in_addr			addr;
220 	struct in_addr			mask;
221 	u_int32_t			metric;
222 	u_int16_t			label;
223 	u_int16_t			type;
224 };
225 
226 struct ripd_conf {
227 	struct event		 ev;
228 	struct event		 report_timer;
229 	LIST_HEAD(, iface)	 iface_list;
230 	SIMPLEQ_HEAD(, redistribute) redist_list;
231 
232 	u_int32_t		 opts;
233 #define RIPD_OPT_VERBOSE	0x00000001
234 #define	RIPD_OPT_VERBOSE2	0x00000002
235 #define	RIPD_OPT_NOACTION	0x00000004
236 #define	RIPD_OPT_FORCE_DEMOTE	0x00000008
237 	int			 flags;
238 	int			 options;
239 	int			 rip_socket;
240 	int			 redistribute;
241 	u_int			 rdomain;
242 };
243 
244 /* kroute */
245 struct kroute {
246 	struct in_addr	prefix;
247 	struct in_addr	netmask;
248 	struct in_addr	nexthop;
249 	u_int16_t	flags;
250 	u_int16_t	rtlabel;
251 	u_short		ifindex;
252 	u_int8_t	metric;
253 	u_int8_t	priority;
254 };
255 
256 struct kif {
257 	char		 ifname[IF_NAMESIZE];
258 	u_int64_t	 baudrate;
259 	int		 flags;
260 	int		 mtu;
261 	u_short		 ifindex;
262 	u_int8_t	 media_type;
263 	u_int8_t	 link_state;
264 	u_int8_t	 nh_reachable;	/* for nexthop verification */
265 };
266 
267 /* control data structures */
268 struct ctl_iface {
269 	char			 name[IF_NAMESIZE];
270 	struct in_addr		 addr;
271 	struct in_addr		 mask;
272 
273 	time_t			 uptime;
274 	time_t			 report_timer;
275 
276 	u_int64_t		 baudrate;
277 	unsigned int		 ifindex;
278 	int			 state;
279 	int			 mtu;
280 
281 	u_int16_t		 flags;
282 	u_int16_t		 metric;
283 	enum iface_type		 type;
284 	u_int8_t		 linkstate;
285 	u_int8_t		 mediatype;
286 	u_int8_t		 passive;
287 };
288 
289 struct ctl_rt {
290 	struct in_addr		 prefix;
291 	struct in_addr		 netmask;
292 	struct in_addr		 nexthop;
293 	time_t			 uptime;
294 	time_t			 expire;
295 	u_int32_t		 metric;
296 	u_int16_t		 flags;
297 };
298 
299 struct ctl_nbr {
300 	char			 name[IF_NAMESIZE];
301 	struct in_addr		 id;
302 	struct in_addr		 addr;
303 	time_t			 dead_timer;
304 	time_t			 uptime;
305 	int			 nbr_state;
306 	int			 iface_state;
307 };
308 
309 struct demote_msg {
310 	char			 demote_group[IF_NAMESIZE];
311 	int			 level;
312 };
313 
314 int		 kif_init(void);
315 int		 kr_init(int, u_int);
316 int		 kr_change(struct kroute *);
317 int		 kr_delete(struct kroute *);
318 void		 kr_shutdown(void);
319 void		 kr_fib_couple(void);
320 void		 kr_fib_decouple(void);
321 void		 kr_dispatch_msg(int, short, void *);
322 void		 kr_show_route(struct imsg *);
323 void		 kr_ifinfo(char *, pid_t);
324 struct kif	*kif_findname(char *);
325 
326 in_addr_t	 prefixlen2mask(u_int8_t);
327 u_int8_t	 mask2prefixlen(in_addr_t);
328 
329 /* ripd.c */
330 void		 main_imsg_compose_ripe(int, pid_t, void *, u_int16_t);
331 void		 main_imsg_compose_rde(int, pid_t, void *, u_int16_t);
332 int		 rip_redistribute(struct kroute *);
333 void		 imsg_event_add(struct imsgev *);
334 int		 imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t,
335 		    pid_t, int, void *, u_int16_t);
336 
337 /* parse.y */
338 struct ripd_conf	*parse_config(char *, int);
339 int			 cmdline_symset(char *);
340 
341 /* carp.c */
342 int		 carp_demote_init(char *, int);
343 void		 carp_demote_shutdown(void);
344 int		 carp_demote_get(char *);
345 int		 carp_demote_set(char *, int);
346 
347 /* printconf.c */
348 void		 print_config(struct ripd_conf *);
349 
350 /* log.c */
351 const char	*if_state_name(int);
352 const char	*if_auth_name(enum auth_type);
353 const char	*nbr_state_name(int);
354 
355 /* interface.c */
356 struct iface	*if_find_index(u_short);
357 
358 /* name2id.c */
359 u_int16_t	 rtlabel_name2id(const char *);
360 const char	*rtlabel_id2name(u_int16_t);
361 void		 rtlabel_unref(u_int16_t);
362 
363 #endif /* _RIPD_H_ */
364