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