]>
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
);
233 #ifndef HAVE_EXPLICIT_BZERO
234 void explicit_bzero(void *buf
, size_t len
);
237 #if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG)
238 /* avoid conflicts in case we have partial support */
239 #define mmsghdr frr_mmsghdr
240 #define sendmmsg frr_sendmmsg
243 struct msghdr msg_hdr
;
244 unsigned int msg_len
;
247 /* just go 1 at a time here, the loop this is used in will handle the rest */
248 static inline int sendmmsg(int fd
, struct mmsghdr
*mmh
, unsigned int len
,
251 int rv
= sendmsg(fd
, &mmh
->msg_hdr
, 0);
253 return rv
> 0 ? 1 : rv
;
258 * RFC 3542 defines several macros for using struct cmsghdr.
259 * Here, we define those that are not present
263 * Internal defines, for use only in this file.
264 * These are likely wrong on other than ILP32 machines, so warn.
266 #ifndef _CMSG_DATA_ALIGN
267 #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
268 #endif /* _CMSG_DATA_ALIGN */
270 #ifndef _CMSG_HDR_ALIGN
271 #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
272 #endif /* _CMSG_HDR_ALIGN */
275 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
279 #define CMSG_SPACE(l) \
280 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
281 #warning "assuming 4-byte alignment for CMSG_SPACE"
282 #endif /* CMSG_SPACE */
286 #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
287 #warning "assuming 4-byte alignment for CMSG_LEN"
288 #endif /* CMSG_LEN */
291 /* The definition of struct in_pktinfo is missing in old version of
292 GLIBC 2.1 (Redhat 6.1). */
293 #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
296 struct in_addr ipi_spec_dst
;
297 struct in_addr ipi_addr
;
302 * IP_HDRINCL / struct ip byte order
304 * Linux: network byte order
305 * *BSD: network, except for length and offset. (cf Stevens)
306 * SunOS: nominally as per BSD. but bug: network order on LE.
307 * OpenBSD: network byte order, apart from older versions which are as per
310 #if defined(__NetBSD__) \
311 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
312 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
313 || (defined(__APPLE__))
314 #define HAVE_IP_HDRINCL_BSD_ORDER
317 /* autoconf macros for this are deprecated, just find endian.h */
319 #error please locate an endian.h file appropriate to your platform
322 /* For old definition. */
323 #ifndef IN6_ARE_ADDR_EQUAL
324 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
325 #endif /* IN6_ARE_ADDR_EQUAL */
327 /* default zebra TCP port for zclient */
328 #define ZEBRA_PORT 2600
331 * The compiler.h header is used for anyone using the CPP_NOTICE
332 * since this is universally needed, let's add it to zebra.h
334 #include "compiler.h"
336 /* Zebra route's types are defined in route_types.h */
337 #include "lib/route_types.h"
339 #define strmatch(a,b) (!strcmp((a), (b)))
341 #ifndef INADDR_LOOPBACK
342 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
345 /* Address family numbers from RFC1700. */
354 #define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
356 /* Subsequent Address Family Identifier. */
364 SAFI_LABELED_UNICAST
= 6,
369 #define FOREACH_AFI_SAFI(afi, safi) \
370 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
371 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
373 #define FOREACH_AFI_SAFI_NSF(afi, safi) \
374 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
375 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
377 /* Default Administrative Distance of each protocol. */
378 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
379 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
380 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
381 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
382 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
383 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
384 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
385 #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
386 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
387 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
388 #define ZEBRA_TABLE_DISTANCE_DEFAULT 15
390 /* Flag manipulation macros. */
391 #define CHECK_FLAG(V,F) ((V) & (F))
392 #define SET_FLAG(V,F) (V) |= (F)
393 #define UNSET_FLAG(V,F) (V) &= ~(F)
394 #define RESET_FLAG(V) (V) = 0
395 #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
397 /* Atomic flag manipulation macros. */
398 #define CHECK_FLAG_ATOMIC(PV, F) \
399 ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
400 #define SET_FLAG_ATOMIC(PV, F) \
401 ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
402 #define UNSET_FLAG_ATOMIC(PV, F) \
403 ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
404 #define RESET_FLAG_ATOMIC(PV) \
405 ((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
408 typedef uint32_t vrf_id_t
;
410 typedef uint32_t route_tag_t
;
411 #define ROUTE_TAG_MAX UINT32_MAX
412 #define ROUTE_TAG_PRI PRIu32
414 /* Name of hook calls */
415 #define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results"
421 #endif /* _ZEBRA_H */