blob: 15608dbcd87ff1a9caf5626284ab90606451b89c [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Zebra common header.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#ifndef _ZEBRA_H
22#define _ZEBRA_H
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif /* HAVE_CONFIG_H */
27
28#ifdef SUNOS_5
29#define _XPG4_2
30#define __EXTENSIONS__
31#endif /* SUNOS_5 */
32
paulf0438522003-05-19 21:06:32 +000033#ifndef HAVE_SOCKLEN_T
34typedef int socklen_t;
35#endif /* HAVE_SOCKLEN_T */
36
paul718e3742002-12-13 20:15:29 +000037#include <unistd.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <ctype.h>
41#include <errno.h>
42#include <fcntl.h>
43#include <signal.h>
44#include <string.h>
pauledd7c242003-06-04 13:59:38 +000045#include <pwd.h>
46#include <grp.h>
paul718e3742002-12-13 20:15:29 +000047#ifdef HAVE_STROPTS_H
48#include <stropts.h>
49#endif /* HAVE_STROPTS_H */
50#include <sys/fcntl.h>
51#ifdef HAVE_SYS_SELECT_H
52#include <sys/select.h>
53#endif /* HAVE_SYS_SELECT_H */
54#include <sys/stat.h>
55#include <sys/time.h>
56#include <sys/types.h>
57#include <sys/param.h>
58#ifdef HAVE_SYS_SYSCTL_H
59#include <sys/sysctl.h>
60#endif /* HAVE_SYS_SYSCTL_H */
61#include <sys/ioctl.h>
62#ifdef HAVE_SYS_CONF_H
63#include <sys/conf.h>
64#endif /* HAVE_SYS_CONF_H */
65#ifdef HAVE_SYS_KSYM_H
66#include <sys/ksym.h>
67#endif /* HAVE_SYS_KSYM_H */
68#include <syslog.h>
69#include <time.h>
70#include <sys/uio.h>
71#include <sys/utsname.h>
72#ifdef HAVE_RUSAGE
73#include <sys/resource.h>
74#endif /* HAVE_RUSAGE */
pauledd7c242003-06-04 13:59:38 +000075#ifdef HAVE_LCAPS
76#include <sys/capability.h>
77#include <sys/prctl.h>
78#endif /* HAVE_LCAPS */
paul718e3742002-12-13 20:15:29 +000079
80/* machine dependent includes */
81#ifdef SUNOS_5
82#include <limits.h>
83#include <strings.h>
84#endif /* SUNOS_5 */
85
86/* machine dependent includes */
87#ifdef HAVE_LINUX_VERSION_H
88#include <linux/version.h>
89#endif /* HAVE_LINUX_VERSION_H */
90
paulba965c62003-05-20 02:37:39 +000091#ifdef HAVE_ASM_TYPES_H
92#include <asm/types.h>
93#endif /* HAVE_ASM_TYPES_H */
94
paul718e3742002-12-13 20:15:29 +000095/* misc include group */
96#include <stdarg.h>
97#include <assert.h>
98
99/* network include group */
100
101#include <sys/socket.h>
102
103#ifdef HAVE_SYS_SOCKIO_H
104#include <sys/sockio.h>
105#endif /* HAVE_SYS_SOCKIO_H */
106
107#ifdef HAVE_NETINET_IN_H
108#include <netinet/in.h>
109#endif /* HAVE_NETINET_IN_H */
110#include <netinet/in_systm.h>
111#include <netinet/ip.h>
112#include <netinet/tcp.h>
113
114#ifdef HAVE_NET_NETOPT_H
115#include <net/netopt.h>
116#endif /* HAVE_NET_NETOPT_H */
117
118#include <net/if.h>
119
120#ifdef HAVE_NET_IF_DL_H
121#include <net/if_dl.h>
122#endif /* HAVE_NET_IF_DL_H */
123
124#ifdef HAVE_NET_IF_VAR_H
125#include <net/if_var.h>
126#endif /* HAVE_NET_IF_VAR_H */
127
128#include <net/route.h>
129
130#ifdef HAVE_NETLINK
131#include <linux/netlink.h>
132#include <linux/rtnetlink.h>
133#else
134#define RT_TABLE_MAIN 0
135#endif /* HAVE_NETLINK */
136
137#ifdef HAVE_NETDB_H
138#include <netdb.h>
139#endif /* HAVE_NETDB_H */
140
141#include <arpa/inet.h>
142#include <arpa/telnet.h>
143
144#ifdef HAVE_INET_ND_H
145#include <inet/nd.h>
146#endif /* HAVE_INET_ND_H */
147
148#ifdef HAVE_NETINET_IN_VAR_H
149#include <netinet/in_var.h>
150#endif /* HAVE_NETINET_IN_VAR_H */
151
hasso726f9b22003-05-25 21:04:54 +0000152#ifdef HAVE_NETINET6_IN6_VAR_H
153#include <netinet6/in6_var.h>
154#endif /* HAVE_NETINET6_IN6_VAR_H */
155
paul718e3742002-12-13 20:15:29 +0000156#ifdef HAVE_NETINET_IN6_VAR_H
157#include <netinet/in6_var.h>
158#endif /* HAVE_NETINET_IN6_VAR_H */
159
160#ifdef HAVE_NETINET6_IN_H
161#include <netinet6/in.h>
162#endif /* HAVE_NETINET6_IN_H */
163
164
165#ifdef HAVE_NETINET6_IP6_H
166#include <netinet6/ip6.h>
167#endif /* HAVE_NETINET6_IP6_H */
168
169#ifdef HAVE_NETINET_ICMP6_H
170#include <netinet/icmp6.h>
171#endif /* HAVE_NETINET_ICMP6_H */
172
173#ifdef HAVE_NETINET6_ND6_H
174#include <netinet6/nd6.h>
175#endif /* HAVE_NETINET6_ND6_H */
176
177#ifdef HAVE_LIBUTIL_H
178#include <libutil.h>
179#endif /* HAVE_LIBUTIL_H */
180
paulfb2d1502003-06-04 09:40:54 +0000181#ifdef HAVE_GLIBC_BACKTRACE
182#include <execinfo.h>
183#endif /* HAVE_GLIBC_BACKTRACE */
184
paul718e3742002-12-13 20:15:29 +0000185#ifdef BSDI_NRL
186
187#ifdef HAVE_NETINET6_IN6_H
188#include <netinet6/in6.h>
189#endif /* HAVE_NETINET6_IN6_H */
190
191#ifdef NRL
192#include <netinet6/in6.h>
193#endif /* NRL */
194
195#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
196
197/* BSD/OS 4.0 has lost belows defines, it should appear at
198 /usr/include/sys/socket.h. */
199#define CMSG_ALIGN(n) (((n) + 3) & ~3)
200#define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
201#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
202
203#endif /* BSDI_NRL */
204
205/* The definition of struct in_pktinfo is missing in old version of
206 GLIBC 2.1 (Redhat 6.1). */
207#if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
208struct in_pktinfo
209{
210 int ipi_ifindex;
211 struct in_addr ipi_spec_dst;
212 struct in_addr ipi_addr;
213};
214#endif
215
216/* For old definition. */
217#ifndef IN6_ARE_ADDR_EQUAL
218#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
219#endif /* IN6_ARE_ADDR_EQUAL */
220
221/* Zebra message types. */
222#define ZEBRA_INTERFACE_ADD 1
223#define ZEBRA_INTERFACE_DELETE 2
224#define ZEBRA_INTERFACE_ADDRESS_ADD 3
225#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
226#define ZEBRA_INTERFACE_UP 5
227#define ZEBRA_INTERFACE_DOWN 6
228#define ZEBRA_IPV4_ROUTE_ADD 7
229#define ZEBRA_IPV4_ROUTE_DELETE 8
230#define ZEBRA_IPV6_ROUTE_ADD 9
231#define ZEBRA_IPV6_ROUTE_DELETE 10
232#define ZEBRA_REDISTRIBUTE_ADD 11
233#define ZEBRA_REDISTRIBUTE_DELETE 12
234#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
235#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
236#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
237#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
238#define ZEBRA_IPV4_IMPORT_LOOKUP 17
239#define ZEBRA_IPV6_IMPORT_LOOKUP 18
240#define ZEBRA_MESSAGE_MAX 19
241
242/* Zebra route's types. */
243#define ZEBRA_ROUTE_SYSTEM 0
244#define ZEBRA_ROUTE_KERNEL 1
245#define ZEBRA_ROUTE_CONNECT 2
246#define ZEBRA_ROUTE_STATIC 3
247#define ZEBRA_ROUTE_RIP 4
248#define ZEBRA_ROUTE_RIPNG 5
249#define ZEBRA_ROUTE_OSPF 6
250#define ZEBRA_ROUTE_OSPF6 7
251#define ZEBRA_ROUTE_BGP 8
252#define ZEBRA_ROUTE_MAX 9
253
254/* Zebra's family types. */
255#define ZEBRA_FAMILY_IPV4 1
256#define ZEBRA_FAMILY_IPV6 2
257#define ZEBRA_FAMILY_MAX 3
258
259/* Error codes of zebra. */
260#define ZEBRA_ERR_RTEXIST -1
261#define ZEBRA_ERR_RTUNREACH -2
262#define ZEBRA_ERR_EPERM -3
263#define ZEBRA_ERR_RTNOEXIST -4
264
265/* Zebra message flags */
266#define ZEBRA_FLAG_INTERNAL 0x01
267#define ZEBRA_FLAG_SELFROUTE 0x02
268#define ZEBRA_FLAG_BLACKHOLE 0x04
269#define ZEBRA_FLAG_IBGP 0x08
270#define ZEBRA_FLAG_SELECTED 0x10
271#define ZEBRA_FLAG_CHANGED 0x20
272#define ZEBRA_FLAG_STATIC 0x40
hasso81dfcaa2003-05-25 19:21:25 +0000273#define ZEBRA_FLAG_REJECT 0x80
paul718e3742002-12-13 20:15:29 +0000274
275/* Zebra nexthop flags. */
276#define ZEBRA_NEXTHOP_IFINDEX 1
277#define ZEBRA_NEXTHOP_IFNAME 2
278#define ZEBRA_NEXTHOP_IPV4 3
279#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
280#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
281#define ZEBRA_NEXTHOP_IPV6 6
282#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
283#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
paul595db7f2003-05-25 21:35:06 +0000284#define ZEBRA_NEXTHOP_BLACKHOLE 9
paul718e3742002-12-13 20:15:29 +0000285
286#ifndef INADDR_LOOPBACK
287#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
288#endif
289
290/* Address family numbers from RFC1700. */
291#define AFI_IP 1
292#define AFI_IP6 2
293#define AFI_MAX 3
294
295/* Subsequent Address Family Identifier. */
296#define SAFI_UNICAST 1
297#define SAFI_MULTICAST 2
298#define SAFI_UNICAST_MULTICAST 3
299#define SAFI_MPLS_VPN 4
300#define SAFI_MAX 5
301
302/* Filter direction. */
303#define FILTER_IN 0
304#define FILTER_OUT 1
305#define FILTER_MAX 2
306
307/* Default Administrative Distance of each protocol. */
308#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
309#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
310#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
311#define ZEBRA_RIP_DISTANCE_DEFAULT 120
312#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
313#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
314#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
315#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
316#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
317
318/* Flag manipulation macros. */
319#define CHECK_FLAG(V,F) ((V) & (F))
320#define SET_FLAG(V,F) (V) = (V) | (F)
321#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
322
323/* AFI and SAFI type. */
324typedef u_int16_t afi_t;
325typedef u_char safi_t;
326
327/* Zebra types. */
328typedef u_int16_t zebra_size_t;
329typedef u_int8_t zebra_command_t;
330
paulf0438522003-05-19 21:06:32 +0000331/* FIFO -- first in first out structure and macros. */
332struct fifo
333{
334 struct fifo *next;
335 struct fifo *prev;
336};
337
338#define FIFO_INIT(F) \
339 do { \
340 struct fifo *Xfifo = (struct fifo *)(F); \
341 Xfifo->next = Xfifo->prev = Xfifo; \
342 } while (0)
343
344#define FIFO_ADD(F,N) \
345 do { \
346 struct fifo *Xfifo = (struct fifo *)(F); \
347 struct fifo *Xnode = (struct fifo *)(N); \
348 Xnode->next = Xfifo; \
349 Xnode->prev = Xfifo->prev; \
350 Xfifo->prev = Xfifo->prev->next = Xnode; \
351 } while (0)
352
353#define FIFO_DEL(N) \
354 do { \
355 struct fifo *Xnode = (struct fifo *)(N); \
356 Xnode->prev->next = Xnode->next; \
357 Xnode->next->prev = Xnode->prev; \
358 } while (0)
359
360#define FIFO_HEAD(F) \
361 ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
362 ? NULL : (F)->next)
363
364#define FIFO_EMPTY(F) \
365 (((struct fifo *)(F))->next == (struct fifo *)(F))
366
367#define FIFO_TOP(F) \
368 (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
369
paul718e3742002-12-13 20:15:29 +0000370#endif /* _ZEBRA_H */