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