]>
git.proxmox.com Git - mirror_frr.git/blob - lib/zebra.h
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__
33 #ifndef HAVE_SOCKLEN_T
34 typedef int socklen_t
;
35 #endif /* HAVE_SOCKLEN_T */
49 #endif /* HAVE_STROPTS_H */
50 #include <sys/fcntl.h>
51 #ifdef HAVE_SYS_SELECT_H
52 #include <sys/select.h>
53 #endif /* HAVE_SYS_SELECT_H */
56 #include <sys/types.h>
57 #include <sys/param.h>
58 #ifdef HAVE_SYS_SYSCTL_H
59 #include <sys/sysctl.h>
60 #endif /* HAVE_SYS_SYSCTL_H */
61 #include <sys/ioctl.h>
62 #ifdef HAVE_SYS_CONF_H
64 #endif /* HAVE_SYS_CONF_H */
65 #ifdef HAVE_SYS_KSYM_H
67 #endif /* HAVE_SYS_KSYM_H */
71 #include <sys/utsname.h>
73 #include <sys/resource.h>
74 #endif /* HAVE_RUSAGE */
76 /* machine dependent includes */
82 /* machine dependent includes */
83 #ifdef HAVE_LINUX_VERSION_H
84 #include <linux/version.h>
85 #endif /* HAVE_LINUX_VERSION_H */
87 #ifdef HAVE_ASM_TYPES_H
88 #include <asm/types.h>
89 #endif /* HAVE_ASM_TYPES_H */
91 /* misc include group */
96 #include <sys/capability.h>
97 #include <sys/prctl.h>
98 #endif /* HAVE_LCAPS */
100 /* network include group */
102 #include <sys/socket.h>
104 #ifdef HAVE_SYS_SOCKIO_H
105 #include <sys/sockio.h>
106 #endif /* HAVE_SYS_SOCKIO_H */
108 #ifdef HAVE_NETINET_IN_H
109 #include <netinet/in.h>
110 #endif /* HAVE_NETINET_IN_H */
111 #include <netinet/in_systm.h>
112 #include <netinet/ip.h>
113 #include <netinet/tcp.h>
115 #ifdef HAVE_NET_NETOPT_H
116 #include <net/netopt.h>
117 #endif /* HAVE_NET_NETOPT_H */
121 #ifdef HAVE_NET_IF_DL_H
122 #include <net/if_dl.h>
123 #endif /* HAVE_NET_IF_DL_H */
125 #ifdef HAVE_NET_IF_VAR_H
126 #include <net/if_var.h>
127 #endif /* HAVE_NET_IF_VAR_H */
129 #include <net/route.h>
132 #include <linux/netlink.h>
133 #include <linux/rtnetlink.h>
135 #define RT_TABLE_MAIN 0
136 #endif /* HAVE_NETLINK */
140 #endif /* HAVE_NETDB_H */
142 #include <arpa/inet.h>
143 #include <arpa/telnet.h>
145 #ifdef HAVE_INET_ND_H
147 #endif /* HAVE_INET_ND_H */
149 #ifdef HAVE_NETINET_IN_VAR_H
150 #include <netinet/in_var.h>
151 #endif /* HAVE_NETINET_IN_VAR_H */
153 #ifdef HAVE_NETINET6_IN6_VAR_H
154 #include <netinet6/in6_var.h>
155 #endif /* HAVE_NETINET6_IN6_VAR_H */
157 #ifdef HAVE_NETINET_IN6_VAR_H
158 #include <netinet/in6_var.h>
159 #endif /* HAVE_NETINET_IN6_VAR_H */
161 #ifdef HAVE_NETINET6_IN_H
162 #include <netinet6/in.h>
163 #endif /* HAVE_NETINET6_IN_H */
166 #ifdef HAVE_NETINET6_IP6_H
167 #include <netinet6/ip6.h>
168 #endif /* HAVE_NETINET6_IP6_H */
170 #ifdef HAVE_NETINET_ICMP6_H
171 #include <netinet/icmp6.h>
172 #endif /* HAVE_NETINET_ICMP6_H */
174 #ifdef HAVE_NETINET6_ND6_H
175 #include <netinet6/nd6.h>
176 #endif /* HAVE_NETINET6_ND6_H */
178 #ifdef HAVE_LIBUTIL_H
180 #endif /* HAVE_LIBUTIL_H */
182 #ifdef HAVE_GLIBC_BACKTRACE
183 #include <execinfo.h>
184 #endif /* HAVE_GLIBC_BACKTRACE */
188 #ifdef HAVE_NETINET6_IN6_H
189 #include <netinet6/in6.h>
190 #endif /* HAVE_NETINET6_IN6_H */
193 #include <netinet6/in6.h>
196 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
198 /* BSD/OS 4.0 has lost belows defines, it should appear at
199 /usr/include/sys/socket.h. */
200 #define CMSG_ALIGN(n) (((n) + 3) & ~3)
201 #define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
202 #define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
204 #endif /* BSDI_NRL */
206 /* The definition of struct in_pktinfo is missing in old version of
207 GLIBC 2.1 (Redhat 6.1). */
208 #if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
212 struct in_addr ipi_spec_dst
;
213 struct in_addr ipi_addr
;
217 /* For old definition. */
218 #ifndef IN6_ARE_ADDR_EQUAL
219 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
220 #endif /* IN6_ARE_ADDR_EQUAL */
222 /* Zebra message types. */
223 #define ZEBRA_INTERFACE_ADD 1
224 #define ZEBRA_INTERFACE_DELETE 2
225 #define ZEBRA_INTERFACE_ADDRESS_ADD 3
226 #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
227 #define ZEBRA_INTERFACE_UP 5
228 #define ZEBRA_INTERFACE_DOWN 6
229 #define ZEBRA_IPV4_ROUTE_ADD 7
230 #define ZEBRA_IPV4_ROUTE_DELETE 8
231 #define ZEBRA_IPV6_ROUTE_ADD 9
232 #define ZEBRA_IPV6_ROUTE_DELETE 10
233 #define ZEBRA_REDISTRIBUTE_ADD 11
234 #define ZEBRA_REDISTRIBUTE_DELETE 12
235 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
236 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
237 #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
238 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
239 #define ZEBRA_IPV4_IMPORT_LOOKUP 17
240 #define ZEBRA_IPV6_IMPORT_LOOKUP 18
241 #define ZEBRA_MESSAGE_MAX 19
243 /* Zebra route's types. */
244 #define ZEBRA_ROUTE_SYSTEM 0
245 #define ZEBRA_ROUTE_KERNEL 1
246 #define ZEBRA_ROUTE_CONNECT 2
247 #define ZEBRA_ROUTE_STATIC 3
248 #define ZEBRA_ROUTE_RIP 4
249 #define ZEBRA_ROUTE_RIPNG 5
250 #define ZEBRA_ROUTE_OSPF 6
251 #define ZEBRA_ROUTE_OSPF6 7
252 #define ZEBRA_ROUTE_BGP 8
253 #define ZEBRA_ROUTE_MAX 9
255 /* Zebra's family types. */
256 #define ZEBRA_FAMILY_IPV4 1
257 #define ZEBRA_FAMILY_IPV6 2
258 #define ZEBRA_FAMILY_MAX 3
260 /* Error codes of zebra. */
261 #define ZEBRA_ERR_RTEXIST -1
262 #define ZEBRA_ERR_RTUNREACH -2
263 #define ZEBRA_ERR_EPERM -3
264 #define ZEBRA_ERR_RTNOEXIST -4
266 /* Zebra message flags */
267 #define ZEBRA_FLAG_INTERNAL 0x01
268 #define ZEBRA_FLAG_SELFROUTE 0x02
269 #define ZEBRA_FLAG_BLACKHOLE 0x04
270 #define ZEBRA_FLAG_IBGP 0x08
271 #define ZEBRA_FLAG_SELECTED 0x10
272 #define ZEBRA_FLAG_CHANGED 0x20
273 #define ZEBRA_FLAG_STATIC 0x40
274 #define ZEBRA_FLAG_REJECT 0x80
276 /* Zebra nexthop flags. */
277 #define ZEBRA_NEXTHOP_IFINDEX 1
278 #define ZEBRA_NEXTHOP_IFNAME 2
279 #define ZEBRA_NEXTHOP_IPV4 3
280 #define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
281 #define ZEBRA_NEXTHOP_IPV4_IFNAME 5
282 #define ZEBRA_NEXTHOP_IPV6 6
283 #define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
284 #define ZEBRA_NEXTHOP_IPV6_IFNAME 8
285 #define ZEBRA_NEXTHOP_BLACKHOLE 9
287 #ifndef INADDR_LOOPBACK
288 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
291 /* Address family numbers from RFC1700. */
296 /* Subsequent Address Family Identifier. */
297 #define SAFI_UNICAST 1
298 #define SAFI_MULTICAST 2
299 #define SAFI_UNICAST_MULTICAST 3
300 #define SAFI_MPLS_VPN 4
303 /* Filter direction. */
308 /* Default Administrative Distance of each protocol. */
309 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
310 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
311 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
312 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
313 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
314 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
315 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
316 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
317 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
319 /* Flag manipulation macros. */
320 #define CHECK_FLAG(V,F) ((V) & (F))
321 #define SET_FLAG(V,F) (V) = (V) | (F)
322 #define UNSET_FLAG(V,F) (V) = (V) & ~(F)
324 /* AFI and SAFI type. */
325 typedef u_int16_t afi_t
;
326 typedef u_char safi_t
;
329 typedef u_int16_t zebra_size_t
;
330 typedef u_int8_t zebra_command_t
;
332 /* FIFO -- first in first out structure and macros. */
339 #define FIFO_INIT(F) \
341 struct fifo *Xfifo = (struct fifo *)(F); \
342 Xfifo->next = Xfifo->prev = Xfifo; \
345 #define FIFO_ADD(F,N) \
347 struct fifo *Xfifo = (struct fifo *)(F); \
348 struct fifo *Xnode = (struct fifo *)(N); \
349 Xnode->next = Xfifo; \
350 Xnode->prev = Xfifo->prev; \
351 Xfifo->prev = Xfifo->prev->next = Xnode; \
354 #define FIFO_DEL(N) \
356 struct fifo *Xnode = (struct fifo *)(N); \
357 Xnode->prev->next = Xnode->next; \
358 Xnode->next->prev = Xnode->prev; \
361 #define FIFO_HEAD(F) \
362 ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
365 #define FIFO_EMPTY(F) \
366 (((struct fifo *)(F))->next == (struct fifo *)(F))
368 #define FIFO_TOP(F) \
369 (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
371 #endif /* _ZEBRA_H */