]> git.proxmox.com Git - mirror_frr.git/blob - lib/zebra.h
Merge pull request #11387 from SaiGomathiN/pimshow
[mirror_frr.git] / lib / zebra.h
1 /* Zebra common header.
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 */
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
28 #include "compiler.h"
29
30 #include <unistd.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stddef.h>
34 #include <ctype.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <signal.h>
38 #include <string.h>
39 #include <pwd.h>
40 #include <grp.h>
41 #ifdef HAVE_STROPTS_H
42 #include <stropts.h>
43 #endif /* HAVE_STROPTS_H */
44 #include <sys/select.h>
45 #include <sys/stat.h>
46 #include <sys/types.h>
47 #include <sys/param.h>
48 #ifdef HAVE_SYS_SYSCTL_H
49 #ifdef GNU_LINUX
50 #include <linux/types.h>
51 #else
52 #include <sys/sysctl.h>
53 #endif
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>
63 #include <sys/time.h>
64 #include <time.h>
65 #include <sys/uio.h>
66 #include <sys/utsname.h>
67 #include <sys/resource.h>
68 #include <limits.h>
69 #include <inttypes.h>
70 #include <stdbool.h>
71 #ifdef HAVE_SYS_ENDIAN_H
72 #include <sys/endian.h>
73 #endif
74 #ifdef HAVE_ENDIAN_H
75 #include <endian.h>
76 #endif
77
78 /* machine dependent includes */
79 #ifdef HAVE_LINUX_VERSION_H
80 #include <linux/version.h>
81 #endif /* HAVE_LINUX_VERSION_H */
82
83 #ifdef HAVE_ASM_TYPES_H
84 #include <asm/types.h>
85 #endif /* HAVE_ASM_TYPES_H */
86
87 /* misc include group */
88 #include <stdarg.h>
89
90 #ifdef HAVE_LCAPS
91 #include <sys/capability.h>
92 #include <sys/prctl.h>
93 #endif /* HAVE_LCAPS */
94
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
103 #ifdef __APPLE__
104 #define __APPLE_USE_RFC_3542
105 #endif
106
107 #ifndef HAVE_LIBCRYPT
108 #ifdef HAVE_LIBCRYPTO
109 #include <openssl/des.h>
110 # define crypt DES_crypt
111 #endif
112 #endif
113
114 #ifdef CRYPTO_OPENSSL
115 #include <openssl/evp.h>
116 #include <openssl/hmac.h>
117 #endif
118
119 #include "openbsd-tree.h"
120
121 #include <netinet/in.h>
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>
145 #include <linux/filter.h>
146 #else
147 #define RT_TABLE_MAIN 0
148 #endif /* HAVE_NETLINK */
149
150 #include <netdb.h>
151 #include <arpa/inet.h>
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
161 #ifdef HAVE_NETINET6_IN6_VAR_H
162 #include <netinet6/in6_var.h>
163 #endif /* HAVE_NETINET6_IN6_VAR_H */
164
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
178 #include <netinet/icmp6.h>
179
180 #ifdef HAVE_NETINET6_ND6_H
181 #include <netinet6/nd6.h>
182 #endif /* HAVE_NETINET6_ND6_H */
183
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 */
187 #ifndef INT16_MAX
188 #define INT16_MAX (32767)
189 #endif
190 #ifndef INT32_MAX
191 #define INT32_MAX (2147483647)
192 #endif
193 #ifndef UINT16_MAX
194 #define UINT16_MAX (65535U)
195 #endif
196 #ifndef UINT32_MAX
197 #define UINT32_MAX (4294967295U)
198 #endif
199
200 #ifdef HAVE_GLIBC_BACKTRACE
201 #include <execinfo.h>
202 #endif /* HAVE_GLIBC_BACKTRACE */
203
204 /* Local includes: */
205 #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
206 #define __attribute__(x)
207 #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
208
209 #include <assert.h>
210
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
220 #ifdef __cplusplus
221 extern "C" {
222 #endif
223
224 #ifndef HAVE_STRLCAT
225 size_t strlcat(char *__restrict dest,
226 const char *__restrict src, size_t destsize);
227 #endif
228 #ifndef HAVE_STRLCPY
229 size_t strlcpy(char *__restrict dest,
230 const char *__restrict src, size_t destsize);
231 #endif
232
233 #ifndef HAVE_EXPLICIT_BZERO
234 void explicit_bzero(void *buf, size_t len);
235 #endif
236
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
242 struct 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 */
248 static 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
257 /*
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.
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
274 /*
275 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
276 * version.
277 */
278 #ifndef CMSG_SPACE
279 #define CMSG_SPACE(l) \
280 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
281 #warning "assuming 4-byte alignment for CMSG_SPACE"
282 #endif /* CMSG_SPACE */
283
284
285 #ifndef CMSG_LEN
286 #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
287 #warning "assuming 4-byte alignment for CMSG_LEN"
288 #endif /* CMSG_LEN */
289
290
291 /* The definition of struct in_pktinfo is missing in old version of
292 GLIBC 2.1 (Redhat 6.1). */
293 #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
294 struct in_pktinfo {
295 int ipi_ifindex;
296 struct in_addr ipi_spec_dst;
297 struct in_addr ipi_addr;
298 };
299 #endif
300
301 /*
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.
307 * OpenBSD: network byte order, apart from older versions which are as per
308 * *BSD
309 */
310 #if defined(__NetBSD__) \
311 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
312 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
313 || (defined(__APPLE__))
314 #define HAVE_IP_HDRINCL_BSD_ORDER
315 #endif
316
317 /* autoconf macros for this are deprecated, just find endian.h */
318 #ifndef BYTE_ORDER
319 #error please locate an endian.h file appropriate to your platform
320 #endif
321
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
327 /* default zebra TCP port for zclient */
328 #define ZEBRA_PORT 2600
329
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
336 /* Zebra route's types are defined in route_types.h */
337 #include "lib/route_types.h"
338
339 #define strmatch(a,b) (!strcmp((a), (b)))
340
341 #ifndef INADDR_LOOPBACK
342 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
343 #endif
344
345 /* Address family numbers from RFC1700. */
346 typedef enum {
347 AFI_UNSPEC = 0,
348 AFI_IP = 1,
349 AFI_IP6 = 2,
350 AFI_L2VPN = 3,
351 AFI_MAX = 4
352 } afi_t;
353
354 #define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
355
356 /* Subsequent Address Family Identifier. */
357 typedef enum {
358 SAFI_UNSPEC = 0,
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,
365 SAFI_FLOWSPEC = 7,
366 SAFI_MAX = 8
367 } safi_t;
368
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
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
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
385 #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
386 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
387 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
388 #define ZEBRA_TABLE_DISTANCE_DEFAULT 15
389
390 /* Flag manipulation macros. */
391 #define CHECK_FLAG(V,F) ((V) & (F))
392 #define SET_FLAG(V,F) (V) |= (F)
393 #define UNSET_FLAG(V,F) (V) &= ~(F)
394 #define RESET_FLAG(V) (V) = 0
395 #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
396
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
407 /* VRF ID type. */
408 typedef uint32_t vrf_id_t;
409
410 typedef uint32_t route_tag_t;
411 #define ROUTE_TAG_MAX UINT32_MAX
412 #define ROUTE_TAG_PRI PRIu32
413
414 /* Name of hook calls */
415 #define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results"
416
417 #ifdef __cplusplus
418 }
419 #endif
420
421 #endif /* _ZEBRA_H */