blob: 62566cf86c4a3c5d5bdff531825bf0dc61a1bea1 [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>
45#ifdef HAVE_STROPTS_H
46#include <stropts.h>
47#endif /* HAVE_STROPTS_H */
48#include <sys/fcntl.h>
49#ifdef HAVE_SYS_SELECT_H
50#include <sys/select.h>
51#endif /* HAVE_SYS_SELECT_H */
52#include <sys/stat.h>
53#include <sys/time.h>
54#include <sys/types.h>
55#include <sys/param.h>
56#ifdef HAVE_SYS_SYSCTL_H
57#include <sys/sysctl.h>
58#endif /* HAVE_SYS_SYSCTL_H */
59#include <sys/ioctl.h>
60#ifdef HAVE_SYS_CONF_H
61#include <sys/conf.h>
62#endif /* HAVE_SYS_CONF_H */
63#ifdef HAVE_SYS_KSYM_H
64#include <sys/ksym.h>
65#endif /* HAVE_SYS_KSYM_H */
66#include <syslog.h>
67#include <time.h>
68#include <sys/uio.h>
69#include <sys/utsname.h>
70#ifdef HAVE_RUSAGE
71#include <sys/resource.h>
72#endif /* HAVE_RUSAGE */
73
74/* machine dependent includes */
75#ifdef SUNOS_5
76#include <limits.h>
77#include <strings.h>
78#endif /* SUNOS_5 */
79
80/* machine dependent includes */
81#ifdef HAVE_LINUX_VERSION_H
82#include <linux/version.h>
83#endif /* HAVE_LINUX_VERSION_H */
84
paulba965c62003-05-20 02:37:39 +000085#ifdef HAVE_ASM_TYPES_H
86#include <asm/types.h>
87#endif /* HAVE_ASM_TYPES_H */
88
paul718e3742002-12-13 20:15:29 +000089/* misc include group */
90#include <stdarg.h>
91#include <assert.h>
92
93/* network include group */
94
95#include <sys/socket.h>
96
97#ifdef HAVE_SYS_SOCKIO_H
98#include <sys/sockio.h>
99#endif /* HAVE_SYS_SOCKIO_H */
100
101#ifdef HAVE_NETINET_IN_H
102#include <netinet/in.h>
103#endif /* HAVE_NETINET_IN_H */
104#include <netinet/in_systm.h>
105#include <netinet/ip.h>
106#include <netinet/tcp.h>
107
108#ifdef HAVE_NET_NETOPT_H
109#include <net/netopt.h>
110#endif /* HAVE_NET_NETOPT_H */
111
112#include <net/if.h>
113
114#ifdef HAVE_NET_IF_DL_H
115#include <net/if_dl.h>
116#endif /* HAVE_NET_IF_DL_H */
117
118#ifdef HAVE_NET_IF_VAR_H
119#include <net/if_var.h>
120#endif /* HAVE_NET_IF_VAR_H */
121
122#include <net/route.h>
123
124#ifdef HAVE_NETLINK
125#include <linux/netlink.h>
126#include <linux/rtnetlink.h>
127#else
128#define RT_TABLE_MAIN 0
129#endif /* HAVE_NETLINK */
130
131#ifdef HAVE_NETDB_H
132#include <netdb.h>
133#endif /* HAVE_NETDB_H */
134
135#include <arpa/inet.h>
136#include <arpa/telnet.h>
137
138#ifdef HAVE_INET_ND_H
139#include <inet/nd.h>
140#endif /* HAVE_INET_ND_H */
141
142#ifdef HAVE_NETINET_IN_VAR_H
143#include <netinet/in_var.h>
144#endif /* HAVE_NETINET_IN_VAR_H */
145
hasso726f9b22003-05-25 21:04:54 +0000146#ifdef HAVE_NETINET6_IN6_VAR_H
147#include <netinet6/in6_var.h>
148#endif /* HAVE_NETINET6_IN6_VAR_H */
149
paul718e3742002-12-13 20:15:29 +0000150#ifdef HAVE_NETINET_IN6_VAR_H
151#include <netinet/in6_var.h>
152#endif /* HAVE_NETINET_IN6_VAR_H */
153
154#ifdef HAVE_NETINET6_IN_H
155#include <netinet6/in.h>
156#endif /* HAVE_NETINET6_IN_H */
157
158
159#ifdef HAVE_NETINET6_IP6_H
160#include <netinet6/ip6.h>
161#endif /* HAVE_NETINET6_IP6_H */
162
163#ifdef HAVE_NETINET_ICMP6_H
164#include <netinet/icmp6.h>
165#endif /* HAVE_NETINET_ICMP6_H */
166
167#ifdef HAVE_NETINET6_ND6_H
168#include <netinet6/nd6.h>
169#endif /* HAVE_NETINET6_ND6_H */
170
171#ifdef HAVE_LIBUTIL_H
172#include <libutil.h>
173#endif /* HAVE_LIBUTIL_H */
174
paulfb2d1502003-06-04 09:40:54 +0000175#ifdef HAVE_GLIBC_BACKTRACE
176#include <execinfo.h>
177#endif /* HAVE_GLIBC_BACKTRACE */
178
paul718e3742002-12-13 20:15:29 +0000179#ifdef BSDI_NRL
180
181#ifdef HAVE_NETINET6_IN6_H
182#include <netinet6/in6.h>
183#endif /* HAVE_NETINET6_IN6_H */
184
185#ifdef NRL
186#include <netinet6/in6.h>
187#endif /* NRL */
188
189#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
190
191/* BSD/OS 4.0 has lost belows defines, it should appear at
192 /usr/include/sys/socket.h. */
193#define CMSG_ALIGN(n) (((n) + 3) & ~3)
194#define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
195#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
196
197#endif /* BSDI_NRL */
198
199/* The definition of struct in_pktinfo is missing in old version of
200 GLIBC 2.1 (Redhat 6.1). */
201#if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
202struct in_pktinfo
203{
204 int ipi_ifindex;
205 struct in_addr ipi_spec_dst;
206 struct in_addr ipi_addr;
207};
208#endif
209
210/* For old definition. */
211#ifndef IN6_ARE_ADDR_EQUAL
212#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
213#endif /* IN6_ARE_ADDR_EQUAL */
214
215/* Zebra message types. */
216#define ZEBRA_INTERFACE_ADD 1
217#define ZEBRA_INTERFACE_DELETE 2
218#define ZEBRA_INTERFACE_ADDRESS_ADD 3
219#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
220#define ZEBRA_INTERFACE_UP 5
221#define ZEBRA_INTERFACE_DOWN 6
222#define ZEBRA_IPV4_ROUTE_ADD 7
223#define ZEBRA_IPV4_ROUTE_DELETE 8
224#define ZEBRA_IPV6_ROUTE_ADD 9
225#define ZEBRA_IPV6_ROUTE_DELETE 10
226#define ZEBRA_REDISTRIBUTE_ADD 11
227#define ZEBRA_REDISTRIBUTE_DELETE 12
228#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
229#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
230#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
231#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
232#define ZEBRA_IPV4_IMPORT_LOOKUP 17
233#define ZEBRA_IPV6_IMPORT_LOOKUP 18
234#define ZEBRA_MESSAGE_MAX 19
235
236/* Zebra route's types. */
237#define ZEBRA_ROUTE_SYSTEM 0
238#define ZEBRA_ROUTE_KERNEL 1
239#define ZEBRA_ROUTE_CONNECT 2
240#define ZEBRA_ROUTE_STATIC 3
241#define ZEBRA_ROUTE_RIP 4
242#define ZEBRA_ROUTE_RIPNG 5
243#define ZEBRA_ROUTE_OSPF 6
244#define ZEBRA_ROUTE_OSPF6 7
245#define ZEBRA_ROUTE_BGP 8
246#define ZEBRA_ROUTE_MAX 9
247
248/* Zebra's family types. */
249#define ZEBRA_FAMILY_IPV4 1
250#define ZEBRA_FAMILY_IPV6 2
251#define ZEBRA_FAMILY_MAX 3
252
253/* Error codes of zebra. */
254#define ZEBRA_ERR_RTEXIST -1
255#define ZEBRA_ERR_RTUNREACH -2
256#define ZEBRA_ERR_EPERM -3
257#define ZEBRA_ERR_RTNOEXIST -4
258
259/* Zebra message flags */
260#define ZEBRA_FLAG_INTERNAL 0x01
261#define ZEBRA_FLAG_SELFROUTE 0x02
262#define ZEBRA_FLAG_BLACKHOLE 0x04
263#define ZEBRA_FLAG_IBGP 0x08
264#define ZEBRA_FLAG_SELECTED 0x10
265#define ZEBRA_FLAG_CHANGED 0x20
266#define ZEBRA_FLAG_STATIC 0x40
hasso81dfcaa2003-05-25 19:21:25 +0000267#define ZEBRA_FLAG_REJECT 0x80
paul718e3742002-12-13 20:15:29 +0000268
269/* Zebra nexthop flags. */
270#define ZEBRA_NEXTHOP_IFINDEX 1
271#define ZEBRA_NEXTHOP_IFNAME 2
272#define ZEBRA_NEXTHOP_IPV4 3
273#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
274#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
275#define ZEBRA_NEXTHOP_IPV6 6
276#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
277#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
paul595db7f2003-05-25 21:35:06 +0000278#define ZEBRA_NEXTHOP_BLACKHOLE 9
paul718e3742002-12-13 20:15:29 +0000279
280#ifndef INADDR_LOOPBACK
281#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
282#endif
283
284/* Address family numbers from RFC1700. */
285#define AFI_IP 1
286#define AFI_IP6 2
287#define AFI_MAX 3
288
289/* Subsequent Address Family Identifier. */
290#define SAFI_UNICAST 1
291#define SAFI_MULTICAST 2
292#define SAFI_UNICAST_MULTICAST 3
293#define SAFI_MPLS_VPN 4
294#define SAFI_MAX 5
295
296/* Filter direction. */
297#define FILTER_IN 0
298#define FILTER_OUT 1
299#define FILTER_MAX 2
300
301/* Default Administrative Distance of each protocol. */
302#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
303#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
304#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
305#define ZEBRA_RIP_DISTANCE_DEFAULT 120
306#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
307#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
308#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
309#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
310#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
311
312/* Flag manipulation macros. */
313#define CHECK_FLAG(V,F) ((V) & (F))
314#define SET_FLAG(V,F) (V) = (V) | (F)
315#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
316
317/* AFI and SAFI type. */
318typedef u_int16_t afi_t;
319typedef u_char safi_t;
320
321/* Zebra types. */
322typedef u_int16_t zebra_size_t;
323typedef u_int8_t zebra_command_t;
324
paulf0438522003-05-19 21:06:32 +0000325/* FIFO -- first in first out structure and macros. */
326struct fifo
327{
328 struct fifo *next;
329 struct fifo *prev;
330};
331
332#define FIFO_INIT(F) \
333 do { \
334 struct fifo *Xfifo = (struct fifo *)(F); \
335 Xfifo->next = Xfifo->prev = Xfifo; \
336 } while (0)
337
338#define FIFO_ADD(F,N) \
339 do { \
340 struct fifo *Xfifo = (struct fifo *)(F); \
341 struct fifo *Xnode = (struct fifo *)(N); \
342 Xnode->next = Xfifo; \
343 Xnode->prev = Xfifo->prev; \
344 Xfifo->prev = Xfifo->prev->next = Xnode; \
345 } while (0)
346
347#define FIFO_DEL(N) \
348 do { \
349 struct fifo *Xnode = (struct fifo *)(N); \
350 Xnode->prev->next = Xnode->next; \
351 Xnode->next->prev = Xnode->prev; \
352 } while (0)
353
354#define FIFO_HEAD(F) \
355 ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
356 ? NULL : (F)->next)
357
358#define FIFO_EMPTY(F) \
359 (((struct fifo *)(F))->next == (struct fifo *)(F))
360
361#define FIFO_TOP(F) \
362 (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
363
paul718e3742002-12-13 20:15:29 +0000364#endif /* _ZEBRA_H */