]> git.proxmox.com Git - mirror_frr.git/blame - lib/zebra.h
lib: Hide list macros in linklist.c
[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: */
89cb86ae 205#if !defined(__GNUC__)
db8eaac6 206#define __attribute__(x)
89cb86ae 207#endif /* !__GNUC__ */
db8eaac6 208
6a0eb688 209#include <assert.h>
db8eaac6 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
deca28a3
CH
220#ifdef __cplusplus
221extern "C" {
222#endif
223
c5d9d3bb 224#ifndef HAVE_STRLCAT
c9a164df
DS
225size_t strlcat(char *__restrict dest,
226 const char *__restrict src, size_t destsize);
c5d9d3bb
DL
227#endif
228#ifndef HAVE_STRLCPY
c9a164df
DS
229size_t strlcpy(char *__restrict dest,
230 const char *__restrict src, size_t destsize);
c5d9d3bb 231#endif
db8eaac6 232
04b4b595
LV
233#ifndef HAVE_EXPLICIT_BZERO
234void explicit_bzero(void *buf, size_t len);
235#endif
236
d948c317
DL
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
241
242struct mmsghdr {
243 struct msghdr msg_hdr;
244 unsigned int msg_len;
245};
246
247/* just go 1 at a time here, the loop this is used in will handle the rest */
248static inline int sendmmsg(int fd, struct mmsghdr *mmh, unsigned int len,
249 int flags)
250{
251 int rv = sendmsg(fd, &mmh->msg_hdr, 0);
252
253 return rv > 0 ? 1 : rv;
254}
255#endif
256
d62a17ae 257/*
69e1325f 258 * RFC 3542 defines several macros for using struct cmsghdr.
259 * Here, we define those that are not present
260 */
261
262/*
263 * Internal defines, for use only in this file.
264 * These are likely wrong on other than ILP32 machines, so warn.
02ff83c5 265 */
266#ifndef _CMSG_DATA_ALIGN
267#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
268#endif /* _CMSG_DATA_ALIGN */
269
270#ifndef _CMSG_HDR_ALIGN
271#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
272#endif /* _CMSG_HDR_ALIGN */
273
69e1325f 274/*
275 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
276 * version.
277 */
02ff83c5 278#ifndef CMSG_SPACE
d62a17ae 279#define CMSG_SPACE(l) \
280 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
69e1325f 281#warning "assuming 4-byte alignment for CMSG_SPACE"
d62a17ae 282#endif /* CMSG_SPACE */
02ff83c5 283
284
285#ifndef CMSG_LEN
286#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
69e1325f 287#warning "assuming 4-byte alignment for CMSG_LEN"
02ff83c5 288#endif /* CMSG_LEN */
289
69e1325f 290
718e3744 291/* The definition of struct in_pktinfo is missing in old version of
292 GLIBC 2.1 (Redhat 6.1). */
d62a17ae 293#if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
294struct in_pktinfo {
295 int ipi_ifindex;
296 struct in_addr ipi_spec_dst;
297 struct in_addr ipi_addr;
718e3744 298};
299#endif
300
d62a17ae 301/*
9172ee0e 302 * IP_HDRINCL / struct ip byte order
303 *
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.
d62a17ae 307 * OpenBSD: network byte order, apart from older versions which are as per
9172ee0e 308 * *BSD
309 */
d62a17ae 310#if defined(__NetBSD__) \
311 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
312 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
cae8bc96 313 || (defined(__APPLE__))
9172ee0e 314#define HAVE_IP_HDRINCL_BSD_ORDER
315#endif
316
19083e4f 317/* autoconf macros for this are deprecated, just find endian.h */
34204aac 318#ifndef BYTE_ORDER
19083e4f
DL
319#error please locate an endian.h file appropriate to your platform
320#endif
34204aac 321
718e3744 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 */
326
8cc4198f 327/* default zebra TCP port for zclient */
328#define ZEBRA_PORT 2600
329
728806e6
DS
330/*
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
333 */
334#include "compiler.h"
335
e0ca5fde 336/* Zebra route's types are defined in route_types.h */
09781197 337#include "lib/route_types.h"
718e3744 338
bf31fc81
DL
339#define strmatch(a,b) (!strcmp((a), (b)))
340
718e3744 341#ifndef INADDR_LOOPBACK
342#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
343#endif
344
345/* Address family numbers from RFC1700. */
b26f891d
SW
346typedef enum {
347 AFI_UNSPEC = 0,
348 AFI_IP = 1,
349 AFI_IP6 = 2,
350 AFI_L2VPN = 3,
351 AFI_MAX = 4
352} afi_t;
718e3744 353
d35e556c
QY
354#define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
355
718e3744 356/* Subsequent Address Family Identifier. */
5c525538 357typedef enum {
dc912615 358 SAFI_UNSPEC = 0,
5c525538
RW
359 SAFI_UNICAST = 1,
360 SAFI_MULTICAST = 2,
361 SAFI_MPLS_VPN = 3,
362 SAFI_ENCAP = 4,
363 SAFI_EVPN = 5,
364 SAFI_LABELED_UNICAST = 6,
b98f7728
PG
365 SAFI_FLOWSPEC = 7,
366 SAFI_MAX = 8
5c525538 367} safi_t;
718e3744 368
f18ba3cd
DS
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++)
372
df8d723c
DA
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++)
376
718e3744 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
9e867fe6 385#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
718e3744 386#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
387#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
7ab5795a 388#define ZEBRA_TABLE_DISTANCE_DEFAULT 15
718e3744 389
390/* Flag manipulation macros. */
391#define CHECK_FLAG(V,F) ((V) & (F))
548e6f7d 392#define SET_FLAG(V,F) (V) |= (F)
393#define UNSET_FLAG(V,F) (V) &= ~(F)
fb018d25 394#define RESET_FLAG(V) (V) = 0
9fb964de 395#define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
718e3744 396
f765d422
QY
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)))
406
b72ede27 407/* VRF ID type. */
a9ff90c4 408typedef uint32_t vrf_id_t;
b72ede27 409
dc9ffce8
CF
410typedef uint32_t route_tag_t;
411#define ROUTE_TAG_MAX UINT32_MAX
412#define ROUTE_TAG_PRI PRIu32
413
1247efcc
DL
414/* Name of hook calls */
415#define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results"
416
deca28a3
CH
417#ifdef __cplusplus
418}
419#endif
420
718e3744 421#endif /* _ZEBRA_H */