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