MiniDLNA update: 1.0.19.1 to 1.0.20
[tomato.git] / release / src / router / zebra / lib / zebra.h
bloba2ea545d2dcd00c709d1e9637f19e9c38af6f5f2
1 /* Zebra common header.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
21 #ifndef _ZEBRA_H
22 #define _ZEBRA_H
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif /* HAVE_CONFIG_H */
28 #ifdef SUNOS_5
29 #define _XPG4_2
30 #define __EXTENSIONS__
31 typedef unsigned int u_int32_t;
32 typedef unsigned short u_int16_t;
33 typedef unsigned short u_int8_t;
34 #endif /* SUNOS_5 */
36 #ifndef HAVE_SOCKLEN_T
37 typedef int socklen_t;
38 #endif /* HAVE_SOCKLEN_T */
40 #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 */
77 /* machine dependent includes */
78 #ifdef SUNOS_5
79 #include <limits.h>
80 #include <strings.h>
81 #endif /* SUNOS_5 */
83 /* machine dependent includes */
84 #ifdef HAVE_LINUX_VERSION_H
85 #include <linux/version.h>
86 #endif /* HAVE_LINUX_VERSION_H */
88 #ifdef HAVE_ASM_TYPES_H
89 #include <asm/types.h>
90 #endif /* HAVE_ASM_TYPES_H */
92 /* misc include group */
93 #include <stdarg.h>
94 #include <assert.h>
96 /* network include group */
98 #include <sys/socket.h>
100 #ifdef HAVE_SYS_SOCKIO_H
101 #include <sys/sockio.h>
102 #endif /* HAVE_SYS_SOCKIO_H */
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>
111 #ifdef HAVE_NET_NETOPT_H
112 #include <net/netopt.h>
113 #endif /* HAVE_NET_NETOPT_H */
115 #include <net/if.h>
117 #ifdef HAVE_NET_IF_DL_H
118 #include <net/if_dl.h>
119 #endif /* HAVE_NET_IF_DL_H */
121 #ifdef HAVE_NET_IF_VAR_H
122 #include <net/if_var.h>
123 #endif /* HAVE_NET_IF_VAR_H */
125 #include <net/route.h>
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 */
134 #ifdef HAVE_NETDB_H
135 #include <netdb.h>
136 #endif /* HAVE_NETDB_H */
138 #include <arpa/inet.h>
139 #include <arpa/telnet.h>
141 #ifdef HAVE_INET_ND_H
142 #include <inet/nd.h>
143 #endif /* HAVE_INET_ND_H */
145 #ifdef HAVE_NETINET_IN_VAR_H
146 #include <netinet/in_var.h>
147 #endif /* HAVE_NETINET_IN_VAR_H */
149 #ifdef HAVE_NETINET_IN6_VAR_H
150 #include <netinet/in6_var.h>
151 #endif /* HAVE_NETINET_IN6_VAR_H */
153 #ifdef HAVE_NETINET6_IN_H
154 #include <netinet6/in.h>
155 #endif /* HAVE_NETINET6_IN_H */
158 #ifdef HAVE_NETINET6_IP6_H
159 #include <netinet6/ip6.h>
160 #endif /* HAVE_NETINET6_IP6_H */
162 #ifdef HAVE_NETINET_ICMP6_H
163 #include <netinet/icmp6.h>
164 #endif /* HAVE_NETINET_ICMP6_H */
166 #ifdef HAVE_NETINET6_ND6_H
167 #include <netinet6/nd6.h>
168 #endif /* HAVE_NETINET6_ND6_H */
170 #ifdef HAVE_LIBUTIL_H
171 #include <libutil.h>
172 #endif /* HAVE_LIBUTIL_H */
174 #ifdef BSDI_NRL
176 #ifdef HAVE_NETINET6_IN6_H
177 #include <netinet6/in6.h>
178 #endif /* HAVE_NETINET6_IN6_H */
180 #ifdef NRL
181 #include <netinet6/in6.h>
182 #endif /* NRL */
184 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
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))
192 #endif /* BSDI_NRL */
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)
197 struct in_pktinfo
199 int ipi_ifindex;
200 struct in_addr ipi_spec_dst;
201 struct in_addr ipi_addr;
203 #endif
205 /* OpenBSD release month check. */
206 #ifdef __OpenBSD__
207 #if OpenBSD < 200311
208 #define OpenBSD_IP_LEN
209 #endif /* OpenBSD */
210 #endif /* __OpenBSD__ */
212 /* For old definition. */
213 #ifndef IN6_ARE_ADDR_EQUAL
214 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
215 #endif /* IN6_ARE_ADDR_EQUAL */
217 /* Zebra message types. */
218 #define ZEBRA_INTERFACE_ADD 1
219 #define ZEBRA_INTERFACE_DELETE 2
220 #define ZEBRA_INTERFACE_ADDRESS_ADD 3
221 #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
222 #define ZEBRA_INTERFACE_UP 5
223 #define ZEBRA_INTERFACE_DOWN 6
224 #define ZEBRA_IPV4_ROUTE_ADD 7
225 #define ZEBRA_IPV4_ROUTE_DELETE 8
226 #define ZEBRA_IPV6_ROUTE_ADD 9
227 #define ZEBRA_IPV6_ROUTE_DELETE 10
228 #define ZEBRA_REDISTRIBUTE_ADD 11
229 #define ZEBRA_REDISTRIBUTE_DELETE 12
230 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
231 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
232 #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
233 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
234 #define ZEBRA_IPV4_IMPORT_LOOKUP 17
235 #define ZEBRA_IPV6_IMPORT_LOOKUP 18
236 #define ZEBRA_MESSAGE_MAX 19
238 /* Zebra route's types. */
239 #define ZEBRA_ROUTE_SYSTEM 0
240 #define ZEBRA_ROUTE_KERNEL 1
241 #define ZEBRA_ROUTE_CONNECT 2
242 #define ZEBRA_ROUTE_STATIC 3
243 #define ZEBRA_ROUTE_RIP 4
244 #define ZEBRA_ROUTE_RIPNG 5
245 #define ZEBRA_ROUTE_OSPF 6
246 #define ZEBRA_ROUTE_OSPF6 7
247 #define ZEBRA_ROUTE_BGP 8
248 #define ZEBRA_ROUTE_MAX 9
250 /* Zebra's family types. */
251 #define ZEBRA_FAMILY_IPV4 1
252 #define ZEBRA_FAMILY_IPV6 2
253 #define ZEBRA_FAMILY_MAX 3
255 /* Error codes of zebra. */
256 #define ZEBRA_ERR_RTEXIST -1
257 #define ZEBRA_ERR_RTUNREACH -2
258 #define ZEBRA_ERR_EPERM -3
259 #define ZEBRA_ERR_RTNOEXIST -4
261 /* Zebra message flags */
262 #define ZEBRA_FLAG_INTERNAL 0x01
263 #define ZEBRA_FLAG_SELFROUTE 0x02
264 #define ZEBRA_FLAG_BLACKHOLE 0x04
265 #define ZEBRA_FLAG_IBGP 0x08
266 #define ZEBRA_FLAG_SELECTED 0x10
267 #define ZEBRA_FLAG_CHANGED 0x20
268 #define ZEBRA_FLAG_STATIC 0x40
270 /* Zebra nexthop flags. */
271 #define ZEBRA_NEXTHOP_IFINDEX 1
272 #define ZEBRA_NEXTHOP_IFNAME 2
273 #define ZEBRA_NEXTHOP_IPV4 3
274 #define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
275 #define ZEBRA_NEXTHOP_IPV4_IFNAME 5
276 #define ZEBRA_NEXTHOP_IPV6 6
277 #define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
278 #define ZEBRA_NEXTHOP_IPV6_IFNAME 8
279 #define ZEBRA_NEXTHOP_BLACKHOLE 9
281 #ifndef INADDR_LOOPBACK
282 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
283 #endif
285 /* Address family numbers from RFC1700. */
286 #define AFI_IP 1
287 #define AFI_IP6 2
288 #define AFI_MAX 3
290 /* Subsequent Address Family Identifier. */
291 #define SAFI_UNICAST 1
292 #define SAFI_MULTICAST 2
293 #define SAFI_UNICAST_MULTICAST 3
294 #define SAFI_MPLS_VPN 4
295 #define SAFI_MAX 5
297 /* Filter direction. */
298 #define FILTER_IN 0
299 #define FILTER_OUT 1
300 #define FILTER_MAX 2
302 /* Default Administrative Distance of each protocol. */
303 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
304 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
305 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
306 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
307 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
308 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
309 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
310 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
311 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
313 /* Flag manipulation macros. */
314 #define CHECK_FLAG(V,F) ((V) & (F))
315 #define SET_FLAG(V,F) (V) = (V) | (F)
316 #define UNSET_FLAG(V,F) (V) = (V) & ~(F)
318 /* AFI and SAFI type. */
319 typedef u_int16_t afi_t;
320 typedef u_char safi_t;
322 /* Zebra types. */
323 typedef u_int16_t zebra_size_t;
324 typedef u_int8_t zebra_command_t;
326 /* FIFO -- first in first out structure and macros. */
327 struct fifo
329 struct fifo *next;
330 struct fifo *prev;
333 #define FIFO_INIT(F) \
334 do { \
335 struct fifo *Xfifo = (struct fifo *)(F); \
336 Xfifo->next = Xfifo->prev = Xfifo; \
337 } while (0)
339 #define FIFO_ADD(F,N) \
340 do { \
341 struct fifo *Xfifo = (struct fifo *)(F); \
342 struct fifo *Xnode = (struct fifo *)(N); \
343 Xnode->next = Xfifo; \
344 Xnode->prev = Xfifo->prev; \
345 Xfifo->prev = Xfifo->prev->next = Xnode; \
346 } while (0)
348 #define FIFO_DEL(N) \
349 do { \
350 struct fifo *Xnode = (struct fifo *)(N); \
351 Xnode->prev->next = Xnode->next; \
352 Xnode->next->prev = Xnode->prev; \
353 } while (0)
355 #define FIFO_HEAD(F) \
356 ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
357 ? NULL : (F)->next)
359 #define FIFO_EMPTY(F) \
360 (((struct fifo *)(F))->next == (struct fifo *)(F))
362 #define FIFO_TOP(F) \
363 (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
365 #endif /* _ZEBRA_H */