]> git.proxmox.com Git - mirror_frr.git/blame - lib/zebra.h
*: make sure `config.h` or `zebra.h` is first
[mirror_frr.git] / lib / zebra.h
CommitLineData
718e3744 1/* Zebra common header.
896014f4
DL
2 * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 */
718e3744 20
21#ifndef _ZEBRA_H
22#define _ZEBRA_H
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif /* HAVE_CONFIG_H */
27
ef7eec74
QY
28#include "compiler.h"
29
718e3744 30#include <unistd.h>
31#include <stdio.h>
32#include <stdlib.h>
c423d413 33#include <stddef.h>
718e3744 34#include <ctype.h>
35#include <errno.h>
36#include <fcntl.h>
37#include <signal.h>
38#include <string.h>
edd7c245 39#include <pwd.h>
40#include <grp.h>
718e3744 41#ifdef HAVE_STROPTS_H
42#include <stropts.h>
43#endif /* HAVE_STROPTS_H */
718e3744 44#include <sys/select.h>
718e3744 45#include <sys/stat.h>
718e3744 46#include <sys/types.h>
47#include <sys/param.h>
48#ifdef HAVE_SYS_SYSCTL_H
beec2cfe
MW
49#ifdef GNU_LINUX
50#include <linux/types.h>
51#else
718e3744 52#include <sys/sysctl.h>
15e84e5a 53#endif
718e3744 54#endif /* HAVE_SYS_SYSCTL_H */
55#include <sys/ioctl.h>
56#ifdef HAVE_SYS_CONF_H
57#include <sys/conf.h>
58#endif /* HAVE_SYS_CONF_H */
59#ifdef HAVE_SYS_KSYM_H
60#include <sys/ksym.h>
61#endif /* HAVE_SYS_KSYM_H */
62#include <syslog.h>
24f5e2fc
DL
63#include <sys/time.h>
64#include <time.h>
718e3744 65#include <sys/uio.h>
66#include <sys/utsname.h>
718e3744 67#include <sys/resource.h>
a58c25b6 68#include <limits.h>
35cfc90c 69#include <inttypes.h>
63a13864 70#include <stdbool.h>
19083e4f
DL
71#ifdef HAVE_SYS_ENDIAN_H
72#include <sys/endian.h>
73#endif
74#ifdef HAVE_ENDIAN_H
75#include <endian.h>
76#endif
718e3744 77
718e3744 78/* machine dependent includes */
79#ifdef HAVE_LINUX_VERSION_H
80#include <linux/version.h>
81#endif /* HAVE_LINUX_VERSION_H */
82
ba965c6c 83#ifdef HAVE_ASM_TYPES_H
84#include <asm/types.h>
85#endif /* HAVE_ASM_TYPES_H */
86
718e3744 87/* misc include group */
88#include <stdarg.h>
718e3744 89
ba3a0bc5 90#ifdef HAVE_LCAPS
91#include <sys/capability.h>
92#include <sys/prctl.h>
93#endif /* HAVE_LCAPS */
94
718e3744 95/* network include group */
96
97#include <sys/socket.h>
98
99#ifdef HAVE_SYS_SOCKIO_H
100#include <sys/sockio.h>
101#endif /* HAVE_SYS_SOCKIO_H */
102
ea057677
HT
103#ifdef __APPLE__
104#define __APPLE_USE_RFC_3542
105#endif
106
f9e75524 107#ifndef HAVE_LIBCRYPT
996c9314
LB
108#ifdef HAVE_LIBCRYPTO
109#include <openssl/des.h>
f9e75524 110# define crypt DES_crypt
996c9314 111#endif
f9e75524
JAG
112#endif
113
0513a271
MR
114#ifdef CRYPTO_OPENSSL
115#include <openssl/evp.h>
6252100f 116#include <openssl/hmac.h>
0513a271
MR
117#endif
118
8d8763f4 119#include "openbsd-tree.h"
6021c8d3 120
718e3744 121#include <netinet/in.h>
718e3744 122#include <netinet/in_systm.h>
123#include <netinet/ip.h>
124#include <netinet/tcp.h>
125
126#ifdef HAVE_NET_NETOPT_H
127#include <net/netopt.h>
128#endif /* HAVE_NET_NETOPT_H */
129
130#include <net/if.h>
131
132#ifdef HAVE_NET_IF_DL_H
133#include <net/if_dl.h>
134#endif /* HAVE_NET_IF_DL_H */
135
136#ifdef HAVE_NET_IF_VAR_H
137#include <net/if_var.h>
138#endif /* HAVE_NET_IF_VAR_H */
139
140#include <net/route.h>
141
142#ifdef HAVE_NETLINK
143#include <linux/netlink.h>
144#include <linux/rtnetlink.h>
768a27ea 145#include <linux/filter.h>
718e3744 146#else
147#define RT_TABLE_MAIN 0
148#endif /* HAVE_NETLINK */
149
718e3744 150#include <netdb.h>
718e3744 151#include <arpa/inet.h>
718e3744 152
153#ifdef HAVE_INET_ND_H
154#include <inet/nd.h>
155#endif /* HAVE_INET_ND_H */
156
157#ifdef HAVE_NETINET_IN_VAR_H
158#include <netinet/in_var.h>
159#endif /* HAVE_NETINET_IN_VAR_H */
160
726f9b2b 161#ifdef HAVE_NETINET6_IN6_VAR_H
162#include <netinet6/in6_var.h>
163#endif /* HAVE_NETINET6_IN6_VAR_H */
164
718e3744 165#ifdef HAVE_NETINET_IN6_VAR_H
166#include <netinet/in6_var.h>
167#endif /* HAVE_NETINET_IN6_VAR_H */
168
169#ifdef HAVE_NETINET6_IN_H
170#include <netinet6/in.h>
171#endif /* HAVE_NETINET6_IN_H */
172
173
174#ifdef HAVE_NETINET6_IP6_H
175#include <netinet6/ip6.h>
176#endif /* HAVE_NETINET6_IP6_H */
177
718e3744 178#include <netinet/icmp6.h>
718e3744 179
180#ifdef HAVE_NETINET6_ND6_H
181#include <netinet6/nd6.h>
182#endif /* HAVE_NETINET6_ND6_H */
183
35cfc90c
PJ
184/* Some systems do not define UINT32_MAX, etc.. from inttypes.h
185 * e.g. this makes life easier for FBSD 4.11 users.
186 */
35cfc90c
PJ
187#ifndef INT16_MAX
188#define INT16_MAX (32767)
189#endif
190#ifndef INT32_MAX
191#define INT32_MAX (2147483647)
192#endif
35cfc90c
PJ
193#ifndef UINT16_MAX
194#define UINT16_MAX (65535U)
195#endif
3b424979 196#ifndef UINT32_MAX
35cfc90c
PJ
197#define UINT32_MAX (4294967295U)
198#endif
3b424979 199
fb2d1502 200#ifdef HAVE_GLIBC_BACKTRACE
201#include <execinfo.h>
202#endif /* HAVE_GLIBC_BACKTRACE */
203
db8eaac6 204/* Local includes: */
d62a17ae 205#if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
db8eaac6 206#define __attribute__(x)
d62a17ae 207#endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
db8eaac6 208
209#include "zassert.h"
210
343cd13e
RW
211/*
212 * Add explicit static cast only when using a C++ compiler.
213 */
214#ifdef __cplusplus
215#define static_cast(l, r) static_cast<decltype(l)>((r))
216#else
217#define static_cast(l, r) (r)
218#endif
219
c5d9d3bb 220#ifndef HAVE_STRLCAT
c9a164df
DS
221size_t strlcat(char *__restrict dest,
222 const char *__restrict src, size_t destsize);
c5d9d3bb
DL
223#endif
224#ifndef HAVE_STRLCPY
c9a164df
DS
225size_t strlcpy(char *__restrict dest,
226 const char *__restrict src, size_t destsize);
c5d9d3bb 227#endif
db8eaac6 228
d62a17ae 229/*
69e1325f 230 * RFC 3542 defines several macros for using struct cmsghdr.
231 * Here, we define those that are not present
232 */
233
234/*
235 * Internal defines, for use only in this file.
236 * These are likely wrong on other than ILP32 machines, so warn.
02ff83c5 237 */
238#ifndef _CMSG_DATA_ALIGN
239#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
240#endif /* _CMSG_DATA_ALIGN */
241
242#ifndef _CMSG_HDR_ALIGN
243#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
244#endif /* _CMSG_HDR_ALIGN */
245
69e1325f 246/*
247 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
248 * version.
249 */
02ff83c5 250#ifndef CMSG_SPACE
d62a17ae 251#define CMSG_SPACE(l) \
252 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
69e1325f 253#warning "assuming 4-byte alignment for CMSG_SPACE"
d62a17ae 254#endif /* CMSG_SPACE */
02ff83c5 255
256
257#ifndef CMSG_LEN
258#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
69e1325f 259#warning "assuming 4-byte alignment for CMSG_LEN"
02ff83c5 260#endif /* CMSG_LEN */
261
69e1325f 262
718e3744 263/* The definition of struct in_pktinfo is missing in old version of
264 GLIBC 2.1 (Redhat 6.1). */
d62a17ae 265#if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
266struct in_pktinfo {
267 int ipi_ifindex;
268 struct in_addr ipi_spec_dst;
269 struct in_addr ipi_addr;
718e3744 270};
271#endif
272
d62a17ae 273/*
9172ee0e 274 * IP_HDRINCL / struct ip byte order
275 *
276 * Linux: network byte order
277 * *BSD: network, except for length and offset. (cf Stevens)
278 * SunOS: nominally as per BSD. but bug: network order on LE.
d62a17ae 279 * OpenBSD: network byte order, apart from older versions which are as per
9172ee0e 280 * *BSD
281 */
d62a17ae 282#if defined(__NetBSD__) \
283 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
284 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
cae8bc96 285 || (defined(__APPLE__))
9172ee0e 286#define HAVE_IP_HDRINCL_BSD_ORDER
287#endif
288
19083e4f 289/* autoconf macros for this are deprecated, just find endian.h */
34204aac 290#ifndef BYTE_ORDER
19083e4f
DL
291#error please locate an endian.h file appropriate to your platform
292#endif
34204aac 293
718e3744 294/* For old definition. */
295#ifndef IN6_ARE_ADDR_EQUAL
296#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
297#endif /* IN6_ARE_ADDR_EQUAL */
298
8cc4198f 299/* default zebra TCP port for zclient */
300#define ZEBRA_PORT 2600
301
728806e6
DS
302/*
303 * The compiler.h header is used for anyone using the CPP_NOTICE
304 * since this is universally needed, let's add it to zebra.h
305 */
306#include "compiler.h"
307
e0ca5fde 308/* Zebra route's types are defined in route_types.h */
09781197 309#include "lib/route_types.h"
718e3744 310
bf31fc81
DL
311#define strmatch(a,b) (!strcmp((a), (b)))
312
718e3744 313#ifndef INADDR_LOOPBACK
314#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
315#endif
316
317/* Address family numbers from RFC1700. */
b26f891d
SW
318typedef enum {
319 AFI_UNSPEC = 0,
320 AFI_IP = 1,
321 AFI_IP6 = 2,
322 AFI_L2VPN = 3,
323 AFI_MAX = 4
324} afi_t;
718e3744 325
d35e556c
QY
326#define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
327
718e3744 328/* Subsequent Address Family Identifier. */
5c525538 329typedef enum {
dc912615 330 SAFI_UNSPEC = 0,
5c525538
RW
331 SAFI_UNICAST = 1,
332 SAFI_MULTICAST = 2,
333 SAFI_MPLS_VPN = 3,
334 SAFI_ENCAP = 4,
335 SAFI_EVPN = 5,
336 SAFI_LABELED_UNICAST = 6,
b98f7728
PG
337 SAFI_FLOWSPEC = 7,
338 SAFI_MAX = 8
5c525538 339} safi_t;
718e3744 340
f18ba3cd
DS
341#define FOREACH_AFI_SAFI(afi, safi) \
342 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
343 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
344
718e3744 345/* Default Administrative Distance of each protocol. */
346#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
347#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
348#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
349#define ZEBRA_RIP_DISTANCE_DEFAULT 120
350#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
351#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
352#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
9e867fe6 353#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
718e3744 354#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
355#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
7ab5795a 356#define ZEBRA_TABLE_DISTANCE_DEFAULT 15
718e3744 357
358/* Flag manipulation macros. */
359#define CHECK_FLAG(V,F) ((V) & (F))
548e6f7d 360#define SET_FLAG(V,F) (V) |= (F)
361#define UNSET_FLAG(V,F) (V) &= ~(F)
fb018d25 362#define RESET_FLAG(V) (V) = 0
9fb964de 363#define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
718e3744 364
f765d422
QY
365/* Atomic flag manipulation macros. */
366#define CHECK_FLAG_ATOMIC(PV, F) \
367 ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
368#define SET_FLAG_ATOMIC(PV, F) \
369 ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
370#define UNSET_FLAG_ATOMIC(PV, F) \
371 ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
372#define RESET_FLAG_ATOMIC(PV) \
373 ((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
374
b72ede27 375/* VRF ID type. */
a9ff90c4 376typedef uint32_t vrf_id_t;
b72ede27 377
dc9ffce8
CF
378typedef uint32_t route_tag_t;
379#define ROUTE_TAG_MAX UINT32_MAX
380#define ROUTE_TAG_PRI PRIu32
381
718e3744 382#endif /* _ZEBRA_H */