]>
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #endif /* HAVE_CONFIG_H */
43 #endif /* HAVE_STROPTS_H */
44 #include <sys/select.h>
46 #include <sys/types.h>
47 #include <sys/param.h>
48 #ifdef HAVE_SYS_SYSCTL_H
50 #include <linux/types.h>
52 #include <sys/sysctl.h>
54 #endif /* HAVE_SYS_SYSCTL_H */
55 #include <sys/ioctl.h>
56 #ifdef HAVE_SYS_CONF_H
58 #endif /* HAVE_SYS_CONF_H */
59 #ifdef HAVE_SYS_KSYM_H
61 #endif /* HAVE_SYS_KSYM_H */
66 #include <sys/utsname.h>
67 #include <sys/resource.h>
71 #ifdef HAVE_SYS_ENDIAN_H
72 #include <sys/endian.h>
78 /* machine dependent includes */
79 #ifdef HAVE_LINUX_VERSION_H
80 #include <linux/version.h>
81 #endif /* HAVE_LINUX_VERSION_H */
83 #ifdef HAVE_ASM_TYPES_H
84 #include <asm/types.h>
85 #endif /* HAVE_ASM_TYPES_H */
87 /* misc include group */
91 #include <sys/capability.h>
92 #include <sys/prctl.h>
93 #endif /* HAVE_LCAPS */
95 /* network include group */
97 #include <sys/socket.h>
99 #ifdef HAVE_SYS_SOCKIO_H
100 #include <sys/sockio.h>
101 #endif /* HAVE_SYS_SOCKIO_H */
104 #define __APPLE_USE_RFC_3542
107 #ifndef HAVE_LIBCRYPT
108 #ifdef HAVE_LIBCRYPTO
109 #include <openssl/des.h>
110 # define crypt DES_crypt
114 #ifdef CRYPTO_OPENSSL
115 #include <openssl/evp.h>
116 #include <openssl/hmac.h>
119 #include "openbsd-tree.h"
121 #include <netinet/in.h>
122 #include <netinet/in_systm.h>
123 #include <netinet/ip.h>
124 #include <netinet/tcp.h>
126 #ifdef HAVE_NET_NETOPT_H
127 #include <net/netopt.h>
128 #endif /* HAVE_NET_NETOPT_H */
132 #ifdef HAVE_NET_IF_DL_H
133 #include <net/if_dl.h>
134 #endif /* HAVE_NET_IF_DL_H */
136 #ifdef HAVE_NET_IF_VAR_H
137 #include <net/if_var.h>
138 #endif /* HAVE_NET_IF_VAR_H */
140 #include <net/route.h>
143 #include <linux/netlink.h>
144 #include <linux/rtnetlink.h>
145 #include <linux/filter.h>
147 #define RT_TABLE_MAIN 0
148 #endif /* HAVE_NETLINK */
151 #include <arpa/inet.h>
153 #ifdef HAVE_INET_ND_H
155 #endif /* HAVE_INET_ND_H */
157 #ifdef HAVE_NETINET_IN_VAR_H
158 #include <netinet/in_var.h>
159 #endif /* HAVE_NETINET_IN_VAR_H */
161 #ifdef HAVE_NETINET6_IN6_VAR_H
162 #include <netinet6/in6_var.h>
163 #endif /* HAVE_NETINET6_IN6_VAR_H */
165 #ifdef HAVE_NETINET_IN6_VAR_H
166 #include <netinet/in6_var.h>
167 #endif /* HAVE_NETINET_IN6_VAR_H */
169 #ifdef HAVE_NETINET6_IN_H
170 #include <netinet6/in.h>
171 #endif /* HAVE_NETINET6_IN_H */
174 #ifdef HAVE_NETINET6_IP6_H
175 #include <netinet6/ip6.h>
176 #endif /* HAVE_NETINET6_IP6_H */
178 #include <netinet/icmp6.h>
180 #ifdef HAVE_NETINET6_ND6_H
181 #include <netinet6/nd6.h>
182 #endif /* HAVE_NETINET6_ND6_H */
184 /* Some systems do not define UINT32_MAX, etc.. from inttypes.h
185 * e.g. this makes life easier for FBSD 4.11 users.
188 #define INT16_MAX (32767)
191 #define INT32_MAX (2147483647)
194 #define UINT16_MAX (65535U)
197 #define UINT32_MAX (4294967295U)
200 #ifdef HAVE_GLIBC_BACKTRACE
201 #include <execinfo.h>
202 #endif /* HAVE_GLIBC_BACKTRACE */
204 /* Local includes: */
205 #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
206 #define __attribute__(x)
207 #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
212 * Add explicit static cast only when using a C++ compiler.
215 #define static_cast(l, r) static_cast<decltype(l)>((r))
217 #define static_cast(l, r) (r)
225 size_t strlcat(char *__restrict dest
,
226 const char *__restrict src
, size_t destsize
);
229 size_t strlcpy(char *__restrict dest
,
230 const char *__restrict src
, size_t destsize
);
234 * RFC 3542 defines several macros for using struct cmsghdr.
235 * Here, we define those that are not present
239 * Internal defines, for use only in this file.
240 * These are likely wrong on other than ILP32 machines, so warn.
242 #ifndef _CMSG_DATA_ALIGN
243 #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
244 #endif /* _CMSG_DATA_ALIGN */
246 #ifndef _CMSG_HDR_ALIGN
247 #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
248 #endif /* _CMSG_HDR_ALIGN */
251 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
255 #define CMSG_SPACE(l) \
256 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
257 #warning "assuming 4-byte alignment for CMSG_SPACE"
258 #endif /* CMSG_SPACE */
262 #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
263 #warning "assuming 4-byte alignment for CMSG_LEN"
264 #endif /* CMSG_LEN */
267 /* The definition of struct in_pktinfo is missing in old version of
268 GLIBC 2.1 (Redhat 6.1). */
269 #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
272 struct in_addr ipi_spec_dst
;
273 struct in_addr ipi_addr
;
278 * IP_HDRINCL / struct ip byte order
280 * Linux: network byte order
281 * *BSD: network, except for length and offset. (cf Stevens)
282 * SunOS: nominally as per BSD. but bug: network order on LE.
283 * OpenBSD: network byte order, apart from older versions which are as per
286 #if defined(__NetBSD__) \
287 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
288 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
289 || (defined(__APPLE__))
290 #define HAVE_IP_HDRINCL_BSD_ORDER
293 /* autoconf macros for this are deprecated, just find endian.h */
295 #error please locate an endian.h file appropriate to your platform
298 /* For old definition. */
299 #ifndef IN6_ARE_ADDR_EQUAL
300 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
301 #endif /* IN6_ARE_ADDR_EQUAL */
303 /* default zebra TCP port for zclient */
304 #define ZEBRA_PORT 2600
307 * The compiler.h header is used for anyone using the CPP_NOTICE
308 * since this is universally needed, let's add it to zebra.h
310 #include "compiler.h"
312 /* Zebra route's types are defined in route_types.h */
313 #include "lib/route_types.h"
315 #define strmatch(a,b) (!strcmp((a), (b)))
317 #ifndef INADDR_LOOPBACK
318 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
321 /* Address family numbers from RFC1700. */
330 #define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
332 /* Subsequent Address Family Identifier. */
340 SAFI_LABELED_UNICAST
= 6,
345 #define FOREACH_AFI_SAFI(afi, safi) \
346 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
347 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
349 /* Default Administrative Distance of each protocol. */
350 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
351 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
352 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
353 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
354 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
355 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
356 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
357 #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
358 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
359 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
360 #define ZEBRA_TABLE_DISTANCE_DEFAULT 15
362 /* Flag manipulation macros. */
363 #define CHECK_FLAG(V,F) ((V) & (F))
364 #define SET_FLAG(V,F) (V) |= (F)
365 #define UNSET_FLAG(V,F) (V) &= ~(F)
366 #define RESET_FLAG(V) (V) = 0
367 #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
369 /* Atomic flag manipulation macros. */
370 #define CHECK_FLAG_ATOMIC(PV, F) \
371 ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
372 #define SET_FLAG_ATOMIC(PV, F) \
373 ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
374 #define UNSET_FLAG_ATOMIC(PV, F) \
375 ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
376 #define RESET_FLAG_ATOMIC(PV) \
377 ((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
380 typedef uint32_t vrf_id_t
;
382 typedef uint32_t route_tag_t
;
383 #define ROUTE_TAG_MAX UINT32_MAX
384 #define ROUTE_TAG_PRI PRIu32
386 /* Name of hook calls */
387 #define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results"
393 #endif /* _ZEBRA_H */