]>
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 /* misc include group */
82 #include <sys/capability.h>
83 #include <sys/prctl.h>
84 #endif /* HAVE_LCAPS */
86 /* network include group */
88 #include <sys/socket.h>
90 #ifdef HAVE_SYS_SOCKIO_H
91 #include <sys/sockio.h>
92 #endif /* HAVE_SYS_SOCKIO_H */
95 #define __APPLE_USE_RFC_3542
100 #include <openssl/des.h>
101 # define crypt DES_crypt
105 #ifdef CRYPTO_OPENSSL
106 #include <openssl/evp.h>
107 #include <openssl/hmac.h>
110 #include "openbsd-tree.h"
112 #include <netinet/in.h>
113 #include <netinet/in_systm.h>
114 #include <netinet/ip.h>
115 #include <netinet/tcp.h>
117 #ifdef HAVE_NET_NETOPT_H
118 #include <net/netopt.h>
119 #endif /* HAVE_NET_NETOPT_H */
123 #ifdef HAVE_NET_IF_DL_H
124 #include <net/if_dl.h>
125 #endif /* HAVE_NET_IF_DL_H */
127 #ifdef HAVE_NET_IF_VAR_H
128 #include <net/if_var.h>
129 #endif /* HAVE_NET_IF_VAR_H */
131 #include <net/route.h>
134 #include <linux/netlink.h>
135 #include <linux/rtnetlink.h>
136 #include <linux/filter.h>
138 #define RT_TABLE_MAIN 0
139 #endif /* HAVE_NETLINK */
142 #include <arpa/inet.h>
144 #ifdef HAVE_INET_ND_H
146 #endif /* HAVE_INET_ND_H */
148 #ifdef HAVE_NETINET_IN_VAR_H
149 #include <netinet/in_var.h>
150 #endif /* HAVE_NETINET_IN_VAR_H */
152 #ifdef HAVE_NETINET6_IN6_VAR_H
153 #include <netinet6/in6_var.h>
154 #endif /* HAVE_NETINET6_IN6_VAR_H */
156 #ifdef HAVE_NETINET_IN6_VAR_H
157 #include <netinet/in6_var.h>
158 #endif /* HAVE_NETINET_IN6_VAR_H */
160 #ifdef HAVE_NETINET6_IN_H
161 #include <netinet6/in.h>
162 #endif /* HAVE_NETINET6_IN_H */
165 #ifdef HAVE_NETINET6_IP6_H
166 #include <netinet6/ip6.h>
167 #endif /* HAVE_NETINET6_IP6_H */
169 #include <netinet/icmp6.h>
171 #ifdef HAVE_NETINET6_ND6_H
172 #include <netinet6/nd6.h>
173 #endif /* HAVE_NETINET6_ND6_H */
175 /* Some systems do not define UINT32_MAX, etc.. from inttypes.h
176 * e.g. this makes life easier for FBSD 4.11 users.
179 #define INT16_MAX (32767)
182 #define INT32_MAX (2147483647)
185 #define UINT16_MAX (65535U)
188 #define UINT32_MAX (4294967295U)
191 #ifdef HAVE_GLIBC_BACKTRACE
192 #include <execinfo.h>
193 #endif /* HAVE_GLIBC_BACKTRACE */
195 /* Local includes: */
196 #if !defined(__GNUC__)
197 #define __attribute__(x)
198 #endif /* !__GNUC__ */
203 * Add explicit static cast only when using a C++ compiler.
206 #define static_cast(l, r) static_cast<decltype(l)>((r))
208 #define static_cast(l, r) (r)
216 size_t strlcat(char *__restrict dest
,
217 const char *__restrict src
, size_t destsize
);
220 size_t strlcpy(char *__restrict dest
,
221 const char *__restrict src
, size_t destsize
);
224 #ifndef HAVE_EXPLICIT_BZERO
225 void explicit_bzero(void *buf
, size_t len
);
228 #if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG)
229 /* avoid conflicts in case we have partial support */
230 #define mmsghdr frr_mmsghdr
231 #define sendmmsg frr_sendmmsg
234 struct msghdr msg_hdr
;
235 unsigned int msg_len
;
238 /* just go 1 at a time here, the loop this is used in will handle the rest */
239 static inline int sendmmsg(int fd
, struct mmsghdr
*mmh
, unsigned int len
,
242 int rv
= sendmsg(fd
, &mmh
->msg_hdr
, 0);
244 return rv
> 0 ? 1 : rv
;
249 * RFC 3542 defines several macros for using struct cmsghdr.
250 * Here, we define those that are not present
254 * Internal defines, for use only in this file.
255 * These are likely wrong on other than ILP32 machines, so warn.
257 #ifndef _CMSG_DATA_ALIGN
258 #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
259 #endif /* _CMSG_DATA_ALIGN */
261 #ifndef _CMSG_HDR_ALIGN
262 #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
263 #endif /* _CMSG_HDR_ALIGN */
266 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
270 #define CMSG_SPACE(l) \
271 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
272 #warning "assuming 4-byte alignment for CMSG_SPACE"
273 #endif /* CMSG_SPACE */
277 #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
278 #warning "assuming 4-byte alignment for CMSG_LEN"
279 #endif /* CMSG_LEN */
282 /* The definition of struct in_pktinfo is missing in old version of
283 GLIBC 2.1 (Redhat 6.1). */
284 #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
287 struct in_addr ipi_spec_dst
;
288 struct in_addr ipi_addr
;
293 * IP_HDRINCL / struct ip byte order
295 * Linux: network byte order
296 * *BSD: network, except for length and offset. (cf Stevens)
297 * SunOS: nominally as per BSD. but bug: network order on LE.
298 * OpenBSD: network byte order, apart from older versions which are as per
301 #if defined(__NetBSD__) \
302 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
303 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
304 || (defined(__APPLE__))
305 #define HAVE_IP_HDRINCL_BSD_ORDER
308 /* autoconf macros for this are deprecated, just find endian.h */
310 #error please locate an endian.h file appropriate to your platform
313 /* For old definition. */
314 #ifndef IN6_ARE_ADDR_EQUAL
315 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
316 #endif /* IN6_ARE_ADDR_EQUAL */
318 /* default zebra TCP port for zclient */
319 #define ZEBRA_PORT 2600
322 * The compiler.h header is used for anyone using the CPP_NOTICE
323 * since this is universally needed, let's add it to zebra.h
325 #include "compiler.h"
327 /* Zebra route's types are defined in route_types.h */
328 #include "lib/route_types.h"
330 #define strmatch(a,b) (!strcmp((a), (b)))
332 #ifndef INADDR_LOOPBACK
333 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
336 /* Address family numbers from RFC1700. */
345 #define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
347 /* Subsequent Address Family Identifier. */
355 SAFI_LABELED_UNICAST
= 6,
360 #define FOREACH_AFI_SAFI(afi, safi) \
361 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
362 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
364 #define FOREACH_AFI_SAFI_NSF(afi, safi) \
365 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
366 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
368 /* Default Administrative Distance of each protocol. */
369 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
370 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
371 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
372 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
373 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
374 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
375 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
376 #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
377 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
378 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
379 #define ZEBRA_TABLE_DISTANCE_DEFAULT 15
381 /* Flag manipulation macros. */
382 #define CHECK_FLAG(V,F) ((V) & (F))
383 #define SET_FLAG(V,F) (V) |= (F)
384 #define UNSET_FLAG(V,F) (V) &= ~(F)
385 #define RESET_FLAG(V) (V) = 0
386 #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
388 /* Atomic flag manipulation macros. */
389 #define CHECK_FLAG_ATOMIC(PV, F) \
390 ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
391 #define SET_FLAG_ATOMIC(PV, F) \
392 ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
393 #define UNSET_FLAG_ATOMIC(PV, F) \
394 ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
395 #define RESET_FLAG_ATOMIC(PV) \
396 ((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
399 typedef uint32_t vrf_id_t
;
401 typedef uint32_t route_tag_t
;
402 #define ROUTE_TAG_MAX UINT32_MAX
403 #define ROUTE_TAG_PRI PRIu32
405 /* Name of hook calls */
406 #define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results"
412 #endif /* _ZEBRA_H */