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