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