summaryrefslogtreecommitdiff
path: root/usr.sbin/eigrpd/eigrpd.h
blob: a2d1db7dae8376eeca54bb273a3c2aaa0cd11ac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
/*	$OpenBSD: eigrpd.h,v 1.6 2015/12/13 18:55:53 renato Exp $ */

/*
 * Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
 * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _EIGRPD_H_
#define _EIGRPD_H_

#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/tree.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
#include <event.h>

#include <imsg.h>
#include "eigrp.h"

#define CONF_FILE		"/etc/eigrpd.conf"
#define	EIGRPD_SOCKET		"/var/run/eigrpd.sock"
#define EIGRPD_USER		"_eigrpd"

#define NBR_IDSELF		1
#define NBR_CNTSTART		(NBR_IDSELF + 1)

#define	READ_BUF_SIZE		65535
#define	PKG_DEF_SIZE		512	/* compromise */
#define	RT_BUF_SIZE		16384
#define	MAX_RTSOCK_BUF		128 * 1024

#define	F_EIGRPD_INSERTED	0x0001
#define	F_KERNEL		0x0002
#define	F_CONNECTED		0x0004
#define	F_STATIC		0x0008
#define	F_DYNAMIC		0x0010
#define F_DOWN                  0x0020
#define	F_REJECT		0x0040
#define	F_BLACKHOLE		0x0080
#define	F_REDISTRIBUTED		0x0100
#define	F_CTL_EXTERNAL		0x0200	/* only used by eigrpctl */
#define	F_CTL_ACTIVE		0x0400
#define	F_CTL_ALLLINKS		0x0800

struct imsgev {
	struct imsgbuf		 ibuf;
	void			(*handler)(int, short, void *);
	struct event		 ev;
	void			*data;
	short			 events;
};

enum imsg_type {
	IMSG_CTL_RELOAD,
	IMSG_CTL_SHOW_INTERFACE,
	IMSG_CTL_SHOW_NBR,
	IMSG_CTL_SHOW_TOPOLOGY,
	IMSG_CTL_SHOW_STATS,
	IMSG_CTL_FIB_COUPLE,
	IMSG_CTL_FIB_DECOUPLE,
	IMSG_CTL_IFACE,
	IMSG_CTL_KROUTE,
	IMSG_CTL_IFINFO,
	IMSG_CTL_END,
	IMSG_CTL_LOG_VERBOSE,
	IMSG_KROUTE_CHANGE,
	IMSG_KROUTE_DELETE,
	IMSG_NONE,
	IMSG_IFINFO,
	IMSG_IFDOWN,
	IMSG_NEWADDR,
	IMSG_DELADDR,
	IMSG_NETWORK_ADD,
	IMSG_NETWORK_DEL,
	IMSG_NEIGHBOR_UP,
	IMSG_NEIGHBOR_DOWN,
	IMSG_RECV_UPDATE_INIT,
	IMSG_RECV_UPDATE,
	IMSG_RECV_QUERY,
	IMSG_RECV_REPLY,
	IMSG_RECV_SIAQUERY,
	IMSG_RECV_SIAREPLY,
	IMSG_SEND_UPDATE,
	IMSG_SEND_QUERY,
	IMSG_SEND_REPLY,
	IMSG_SEND_MUPDATE,
	IMSG_SEND_MQUERY,
	IMSG_SEND_UPDATE_END,
	IMSG_SEND_REPLY_END,
	IMSG_SEND_SIAQUERY_END,
	IMSG_SEND_SIAREPLY_END,
	IMSG_SEND_MUPDATE_END,
	IMSG_SEND_MQUERY_END,
	IMSG_RECONF_CONF,
	IMSG_RECONF_IFACE,
	IMSG_RECONF_INSTANCE,
	IMSG_RECONF_EIGRP_IFACE,
	IMSG_RECONF_END
};

union eigrpd_addr {
	struct in_addr	v4;
	struct in6_addr	v6;
};

/* interface types */
enum iface_type {
	IF_TYPE_POINTOPOINT,
	IF_TYPE_BROADCAST,
};

struct if_addr {
	TAILQ_ENTRY(if_addr)	 entry;
	int			 af;
	union eigrpd_addr	 addr;
	uint8_t			 prefixlen;
	union eigrpd_addr	 dstbrd;
};
TAILQ_HEAD(if_addr_head, if_addr);

struct iface {
	TAILQ_ENTRY(iface)	 entry;
	TAILQ_HEAD(, eigrp_iface) ei_list;
	unsigned int		 ifindex;
	char			 name[IF_NAMESIZE];
	struct if_addr_head      addr_list;
	struct in6_addr		 linklocal;
	int			 mtu;
	enum iface_type		 type;
	uint8_t			 if_type;
	uint64_t		 baudrate;
	uint16_t		 flags;
	uint8_t			 linkstate;
	uint8_t			 group_count_v4;
	uint8_t			 group_count_v6;
};

enum route_type {
	EIGRP_ROUTE_INTERNAL,
	EIGRP_ROUTE_EXTERNAL
};

/* routing information advertised by update/query/reply messages */
struct rinfo {
	int			 af;
	enum route_type		 type;
	union eigrpd_addr	 prefix;
	uint8_t			 prefixlen;
	union eigrpd_addr	 nexthop;
	struct classic_metric	 metric;
	struct classic_emetric	 emetric;
};

struct rinfo_entry {
	TAILQ_ENTRY(rinfo_entry) entry;
	struct rinfo		 rinfo;
};
TAILQ_HEAD(rinfo_head, rinfo_entry);

/* interface states */
#define	IF_STA_DOWN		0x01
#define	IF_STA_ACTIVE		0x02

struct summary_addr {
	TAILQ_ENTRY(summary_addr) entry;
	union eigrpd_addr	 prefix;
	uint8_t			 prefixlen;
};

struct eigrp_iface {
	RB_ENTRY(eigrp_iface)	 id_tree;
	TAILQ_ENTRY(eigrp_iface) e_entry;
	TAILQ_ENTRY(eigrp_iface) i_entry;
	struct eigrp		*eigrp;
	struct iface		*iface;
	int			 state;
	uint32_t		 ifaceid;
	struct event		 hello_timer;
	uint32_t		 delay;
	uint32_t		 bandwidth;
	uint16_t		 hello_holdtime;
	uint16_t		 hello_interval;
	uint8_t			 splithorizon;
	uint8_t			 passive;
	time_t			 uptime;
	TAILQ_HEAD(, nbr)	 nbr_list;
	struct nbr		*self;
	struct rinfo_head	 update_list;	/* multicast updates */
	struct rinfo_head	 query_list;	/* multicast queries */
	TAILQ_HEAD(, summary_addr) summary_list;
};

#define INADDRSZ	4
#define IN6ADDRSZ	16

struct seq_addr_entry {
	TAILQ_ENTRY(seq_addr_entry) entry;
	int			 af;
	union eigrpd_addr	 addr;
};
TAILQ_HEAD(seq_addr_head, seq_addr_entry);

struct nbr;
RB_HEAD(nbr_addr_head, nbr);
RB_HEAD(nbr_pid_head, nbr);
struct rt_node;
RB_HEAD(rt_tree, rt_node);

#define	REDIST_STATIC		0x01
#define	REDIST_RIP		0x02
#define	REDIST_OSPF		0x04
#define	REDIST_CONNECTED	0x08
#define	REDIST_DEFAULT		0x10
#define	REDIST_ADDR		0x20
#define	REDIST_NO		0x40

struct redist_metric {
	uint32_t		 bandwidth;
	uint32_t		 delay;
	uint8_t			 reliability;
	uint8_t			 load;
	uint16_t		 mtu;
};

struct redistribute {
	SIMPLEQ_ENTRY(redistribute) entry;
	uint8_t			 type;
	int			 af;
	union eigrpd_addr	 addr;
	uint8_t			 prefixlen;
	struct redist_metric	*metric;
	struct {
		uint32_t	 as;
		uint32_t	 metric;
		uint32_t	 tag;
	} emetric;
};
SIMPLEQ_HEAD(redist_list, redistribute);

struct eigrp_stats {
	uint32_t		 hellos_sent;
	uint32_t		 hellos_recv;
	uint32_t		 updates_sent;
	uint32_t		 updates_recv;
	uint32_t		 queries_sent;
	uint32_t		 queries_recv;
	uint32_t		 replies_sent;
	uint32_t		 replies_recv;
	uint32_t		 acks_sent;
	uint32_t		 acks_recv;
	uint32_t		 squeries_sent;
	uint32_t		 squeries_recv;
	uint32_t		 sreplies_sent;
	uint32_t		 sreplies_recv;
};

/* eigrp instance */
struct eigrp {
	TAILQ_ENTRY(eigrp)	 entry;
	int			 af;
	uint16_t		 as;
	uint8_t			 kvalues[6];
	uint16_t		 active_timeout;
	uint8_t			 maximum_hops;
	uint8_t			 maximum_paths;
	uint8_t			 variance;
	struct redist_metric	*dflt_metric;
	struct redist_list	 redist_list;
	TAILQ_HEAD(, eigrp_iface) ei_list;
	struct nbr_addr_head	 nbrs;
	struct rde_nbr		*rnbr_redist;
	struct rde_nbr		*rnbr_summary;
	struct rt_tree		 topology;
	uint32_t		 seq_num;
	struct eigrp_stats	 stats;
};

/* eigrp_conf */
enum {
	PROC_MAIN,
	PROC_EIGRP_ENGINE,
	PROC_RDE_ENGINE
} eigrpd_process;

struct eigrpd_conf {
	struct in_addr		 rtr_id;

	uint32_t		 opts;
#define EIGRPD_OPT_VERBOSE	0x00000001
#define EIGRPD_OPT_VERBOSE2	0x00000002
#define EIGRPD_OPT_NOACTION	0x00000004

	int			 flags;
#define	EIGRPD_FLAG_NO_FIB_UPDATE 0x0001

	time_t			 uptime;
	int			 eigrp_socket_v4;
	int			 eigrp_socket_v6;
	unsigned int		 rdomain;
	uint8_t			 fib_priority_internal;
	uint8_t			 fib_priority_external;
	uint8_t			 fib_priority_summary;
	TAILQ_HEAD(, iface)	 iface_list;
	TAILQ_HEAD(, eigrp)	 instances;
	char			*csock;
};

/* kroute */
struct kroute {
	int			 af;
	union eigrpd_addr	 prefix;
	uint8_t			 prefixlen;
	union eigrpd_addr	 nexthop;
	unsigned short		 ifindex;
	uint8_t			 priority;
	uint16_t		 flags;
};

struct kaddr {
	unsigned short		 ifindex;
	int			 af;
	union eigrpd_addr	 addr;
	uint8_t			 prefixlen;
	union eigrpd_addr	 dstbrd;
};

struct kif {
	char			 ifname[IF_NAMESIZE];
	unsigned short		 ifindex;
	int			 flags;
	uint8_t			 link_state;
	int			 mtu;
	uint8_t			 if_type;
	uint64_t		 baudrate;
	uint8_t			 nh_reachable;	/* for nexthop verification */
};

/* control data structures */
struct ctl_iface {
	int			 af;
	uint16_t		 as;
	char			 name[IF_NAMESIZE];
	unsigned int		 ifindex;
	union eigrpd_addr	 addr;
	uint8_t			 prefixlen;
	uint16_t		 flags;
	uint8_t			 linkstate;
	int			 mtu;
	enum iface_type		 type;
	uint8_t			 if_type;
	uint64_t		 baudrate;
	uint32_t		 delay;
	uint32_t		 bandwidth;
	uint16_t		 hello_holdtime;
	uint16_t		 hello_interval;
	uint8_t			 splithorizon;
	uint8_t			 passive;
	time_t			 uptime;
	int			 nbr_cnt;
};

struct ctl_nbr {
	int			 af;
	uint16_t		 as;
	char			 ifname[IF_NAMESIZE];
	union eigrpd_addr	 addr;
	uint16_t		 hello_holdtime;
	time_t			 uptime;
};

struct ctl_rt {
	int			 af;
	uint16_t		 as;
	union eigrpd_addr	 prefix;
	uint8_t			 prefixlen;
	enum route_type		 type;
	union eigrpd_addr	 nexthop;
	char			 ifname[IF_NAMESIZE];
	uint32_t		 distance;
	uint32_t		 rdistance;
	uint32_t		 fdistance;
	int			 state;
	uint8_t			 flags;
	struct {
		uint32_t	 delay;
		uint32_t	 bandwidth;
		uint32_t	 mtu;
		uint8_t		 hop_count;
		uint8_t		 reliability;
		uint8_t		 load;
	} metric;
	struct classic_emetric	 emetric;
};
#define	F_CTL_RT_FIRST		0x01
#define	F_CTL_RT_SUCCESSOR	0x02
#define	F_CTL_RT_FSUCCESSOR	0x04

struct ctl_show_topology_req {
	int			 af;
	union eigrpd_addr	 prefix;
	uint8_t			 prefixlen;
	uint16_t		 flags;
};

struct ctl_stats {
	int			 af;
	uint16_t		 as;
	struct eigrp_stats	 stats;
};

/* parse.y */
struct eigrpd_conf	*parse_config(char *, int);
int			 cmdline_symset(char *);

/* in_cksum.c */
uint16_t	 in_cksum(void *, size_t);

/* kroute.c */
int		 kif_init(void);
void		 kif_redistribute(void);
int		 kr_init(int, unsigned int);
int		 kr_change(struct kroute *);
int		 kr_delete(struct kroute *);
void		 kif_clear(void);
void		 kr_shutdown(void);
void		 kr_fib_couple(void);
void		 kr_fib_decouple(void);
void		 kr_fib_reload(void);
void		 kr_dispatch_msg(int, short, void *);
void		 kr_show_route(struct imsg *);
void		 kr_ifinfo(char *, pid_t);
struct kif	*kif_findname(char *);
void		 kr_reload(void);

/* util.c */
uint8_t		 mask2prefixlen(in_addr_t);
uint8_t		 mask2prefixlen6(struct sockaddr_in6 *);
in_addr_t	 prefixlen2mask(uint8_t);
struct in6_addr	*prefixlen2mask6(uint8_t);
void		 eigrp_applymask(int, union eigrpd_addr *,
    const union eigrpd_addr *, int);
int		 eigrp_addrcmp(int, union eigrpd_addr *, union eigrpd_addr *);
int		 eigrp_addrisset(int, union eigrpd_addr *);
int		 eigrp_prefixcmp(int, const union eigrpd_addr *,
    const union eigrpd_addr *, uint8_t);
void		 embedscope(struct sockaddr_in6 *);
void		 recoverscope(struct sockaddr_in6 *);
void		 addscope(struct sockaddr_in6 *, uint32_t);
void		 clearscope(struct in6_addr *);

/* eigrpd.c */
void		 main_imsg_compose_eigrpe(int, pid_t, void *, uint16_t);
void		 main_imsg_compose_rde(int, pid_t, void *, uint16_t);
void		 merge_config(struct eigrpd_conf *, struct eigrpd_conf *);
void		 config_clear(struct eigrpd_conf *);
void		 imsg_event_add(struct imsgev *);
int		 imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
    pid_t, int, void *, uint16_t);
uint32_t	 eigrp_router_id(struct eigrpd_conf *);
struct eigrp	*eigrp_find(struct eigrpd_conf *, int, uint16_t);

/* printconf.c */
void	print_config(struct eigrpd_conf *);

#endif	/* _EIGRPD_H_ */