blob: 175eb6e22fa13a4924724dd89548e1e1709cdeeb [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
146#ifdef HAVE_NETINET_IN6_VAR_H
147#include <netinet/in6_var.h>
148#endif /* HAVE_NETINET_IN6_VAR_H */
149
150#ifdef HAVE_NETINET6_IN_H
151#include <netinet6/in.h>
152#endif /* HAVE_NETINET6_IN_H */
153
154
155#ifdef HAVE_NETINET6_IP6_H
156#include <netinet6/ip6.h>
157#endif /* HAVE_NETINET6_IP6_H */
158
159#ifdef HAVE_NETINET_ICMP6_H
160#include <netinet/icmp6.h>
161#endif /* HAVE_NETINET_ICMP6_H */
162
163#ifdef HAVE_NETINET6_ND6_H
164#include <netinet6/nd6.h>
165#endif /* HAVE_NETINET6_ND6_H */
166
167#ifdef HAVE_LIBUTIL_H
168#include <libutil.h>
169#endif /* HAVE_LIBUTIL_H */
170
171#ifdef BSDI_NRL
172
173#ifdef HAVE_NETINET6_IN6_H
174#include <netinet6/in6.h>
175#endif /* HAVE_NETINET6_IN6_H */
176
177#ifdef NRL
178#include <netinet6/in6.h>
179#endif /* NRL */
180
181#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
182
183/* BSD/OS 4.0 has lost belows defines, it should appear at
184 /usr/include/sys/socket.h. */
185#define CMSG_ALIGN(n) (((n) + 3) & ~3)
186#define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
187#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
188
189#endif /* BSDI_NRL */
190
191/* The definition of struct in_pktinfo is missing in old version of
192 GLIBC 2.1 (Redhat 6.1). */
193#if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
194struct in_pktinfo
195{
196 int ipi_ifindex;
197 struct in_addr ipi_spec_dst;
198 struct in_addr ipi_addr;
199};
200#endif
201
202/* For old definition. */
203#ifndef IN6_ARE_ADDR_EQUAL
204#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
205#endif /* IN6_ARE_ADDR_EQUAL */
206
207/* Zebra message types. */
208#define ZEBRA_INTERFACE_ADD 1
209#define ZEBRA_INTERFACE_DELETE 2
210#define ZEBRA_INTERFACE_ADDRESS_ADD 3
211#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
212#define ZEBRA_INTERFACE_UP 5
213#define ZEBRA_INTERFACE_DOWN 6
214#define ZEBRA_IPV4_ROUTE_ADD 7
215#define ZEBRA_IPV4_ROUTE_DELETE 8
216#define ZEBRA_IPV6_ROUTE_ADD 9
217#define ZEBRA_IPV6_ROUTE_DELETE 10
218#define ZEBRA_REDISTRIBUTE_ADD 11
219#define ZEBRA_REDISTRIBUTE_DELETE 12
220#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
221#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
222#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
223#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
224#define ZEBRA_IPV4_IMPORT_LOOKUP 17
225#define ZEBRA_IPV6_IMPORT_LOOKUP 18
226#define ZEBRA_MESSAGE_MAX 19
227
228/* Zebra route's types. */
229#define ZEBRA_ROUTE_SYSTEM 0
230#define ZEBRA_ROUTE_KERNEL 1
231#define ZEBRA_ROUTE_CONNECT 2
232#define ZEBRA_ROUTE_STATIC 3
233#define ZEBRA_ROUTE_RIP 4
234#define ZEBRA_ROUTE_RIPNG 5
235#define ZEBRA_ROUTE_OSPF 6
236#define ZEBRA_ROUTE_OSPF6 7
237#define ZEBRA_ROUTE_BGP 8
238#define ZEBRA_ROUTE_MAX 9
239
240/* Zebra's family types. */
241#define ZEBRA_FAMILY_IPV4 1
242#define ZEBRA_FAMILY_IPV6 2
243#define ZEBRA_FAMILY_MAX 3
244
245/* Error codes of zebra. */
246#define ZEBRA_ERR_RTEXIST -1
247#define ZEBRA_ERR_RTUNREACH -2
248#define ZEBRA_ERR_EPERM -3
249#define ZEBRA_ERR_RTNOEXIST -4
250
251/* Zebra message flags */
252#define ZEBRA_FLAG_INTERNAL 0x01
253#define ZEBRA_FLAG_SELFROUTE 0x02
254#define ZEBRA_FLAG_BLACKHOLE 0x04
255#define ZEBRA_FLAG_IBGP 0x08
256#define ZEBRA_FLAG_SELECTED 0x10
257#define ZEBRA_FLAG_CHANGED 0x20
258#define ZEBRA_FLAG_STATIC 0x40
hasso81dfcaa2003-05-25 19:21:25 +0000259#define ZEBRA_FLAG_REJECT 0x80
paul718e3742002-12-13 20:15:29 +0000260
261/* Zebra nexthop flags. */
262#define ZEBRA_NEXTHOP_IFINDEX 1
263#define ZEBRA_NEXTHOP_IFNAME 2
264#define ZEBRA_NEXTHOP_IPV4 3
265#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
266#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
267#define ZEBRA_NEXTHOP_IPV6 6
268#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
269#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
paul718e3742002-12-13 20:15:29 +0000270
271#ifndef INADDR_LOOPBACK
272#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
273#endif
274
275/* Address family numbers from RFC1700. */
276#define AFI_IP 1
277#define AFI_IP6 2
278#define AFI_MAX 3
279
280/* Subsequent Address Family Identifier. */
281#define SAFI_UNICAST 1
282#define SAFI_MULTICAST 2
283#define SAFI_UNICAST_MULTICAST 3
284#define SAFI_MPLS_VPN 4
285#define SAFI_MAX 5
286
287/* Filter direction. */
288#define FILTER_IN 0
289#define FILTER_OUT 1
290#define FILTER_MAX 2
291
292/* Default Administrative Distance of each protocol. */
293#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
294#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
295#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
296#define ZEBRA_RIP_DISTANCE_DEFAULT 120
297#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
298#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
299#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
300#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
301#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
302
303/* Flag manipulation macros. */
304#define CHECK_FLAG(V,F) ((V) & (F))
305#define SET_FLAG(V,F) (V) = (V) | (F)
306#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
307
308/* AFI and SAFI type. */
309typedef u_int16_t afi_t;
310typedef u_char safi_t;
311
312/* Zebra types. */
313typedef u_int16_t zebra_size_t;
314typedef u_int8_t zebra_command_t;
315
paulf0438522003-05-19 21:06:32 +0000316/* FIFO -- first in first out structure and macros. */
317struct fifo
318{
319 struct fifo *next;
320 struct fifo *prev;
321};
322
323#define FIFO_INIT(F) \
324 do { \
325 struct fifo *Xfifo = (struct fifo *)(F); \
326 Xfifo->next = Xfifo->prev = Xfifo; \
327 } while (0)
328
329#define FIFO_ADD(F,N) \
330 do { \
331 struct fifo *Xfifo = (struct fifo *)(F); \
332 struct fifo *Xnode = (struct fifo *)(N); \
333 Xnode->next = Xfifo; \
334 Xnode->prev = Xfifo->prev; \
335 Xfifo->prev = Xfifo->prev->next = Xnode; \
336 } while (0)
337
338#define FIFO_DEL(N) \
339 do { \
340 struct fifo *Xnode = (struct fifo *)(N); \
341 Xnode->prev->next = Xnode->next; \
342 Xnode->next->prev = Xnode->prev; \
343 } while (0)
344
345#define FIFO_HEAD(F) \
346 ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
347 ? NULL : (F)->next)
348
349#define FIFO_EMPTY(F) \
350 (((struct fifo *)(F))->next == (struct fifo *)(F))
351
352#define FIFO_TOP(F) \
353 (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
354
paul718e3742002-12-13 20:15:29 +0000355#endif /* _ZEBRA_H */