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
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
26 #endif /* HAVE_CONFIG_H */
30 #define __EXTENSIONS__
31 typedef unsigned int u_int32_t
;
32 typedef unsigned short u_int16_t
;
33 typedef unsigned short u_int8_t
;
36 #ifndef HAVE_SOCKLEN_T
37 typedef int socklen_t
;
38 #endif /* HAVE_SOCKLEN_T */
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 */
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
65 #endif /* HAVE_SYS_CONF_H */
66 #ifdef HAVE_SYS_KSYM_H
68 #endif /* HAVE_SYS_KSYM_H */
72 #include <sys/utsname.h>
74 #include <sys/resource.h>
75 #endif /* HAVE_RUSAGE */
77 /* machine dependent includes */
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 */
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 */
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>
128 #include <linux/netlink.h>
129 #include <linux/rtnetlink.h>
131 #define RT_TABLE_MAIN 0
132 #endif /* HAVE_NETLINK */
136 #endif /* HAVE_NETDB_H */
138 #include <arpa/inet.h>
139 #include <arpa/telnet.h>
141 #ifdef HAVE_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
172 #endif /* HAVE_LIBUTIL_H */
176 #ifdef HAVE_NETINET6_IN6_H
177 #include <netinet6/in6.h>
178 #endif /* HAVE_NETINET6_IN6_H */
181 #include <netinet6/in6.h>
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)
200 struct in_addr ipi_spec_dst
;
201 struct in_addr ipi_addr
;
205 /* OpenBSD release month check. */
208 #define OpenBSD_IP_LEN
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. */
285 /* Address family numbers from RFC1700. */
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
297 /* Filter direction. */
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
;
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. */
333 #define FIFO_INIT(F) \
335 struct fifo *Xfifo = (struct fifo *)(F); \
336 Xfifo->next = Xfifo->prev = Xfifo; \
339 #define FIFO_ADD(F,N) \
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; \
348 #define FIFO_DEL(N) \
350 struct fifo *Xnode = (struct fifo *)(N); \
351 Xnode->prev->next = Xnode->next; \
352 Xnode->next->prev = Xnode->prev; \
355 #define FIFO_HEAD(F) \
356 ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
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 */