]> git.proxmox.com Git - mirror_frr.git/blob - lib/zebra.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[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 /* misc include group */
79 #include <stdarg.h>
80
81 #ifdef HAVE_LCAPS
82 #include <sys/capability.h>
83 #include <sys/prctl.h>
84 #endif /* HAVE_LCAPS */
85
86 /* network include group */
87
88 #include <sys/socket.h>
89
90 #ifdef HAVE_SYS_SOCKIO_H
91 #include <sys/sockio.h>
92 #endif /* HAVE_SYS_SOCKIO_H */
93
94 #ifdef __APPLE__
95 #define __APPLE_USE_RFC_3542
96 #endif
97
98 #ifndef HAVE_LIBCRYPT
99 #ifdef HAVE_LIBCRYPTO
100 #include <openssl/des.h>
101 # define crypt DES_crypt
102 #endif
103 #endif
104
105 #ifdef CRYPTO_OPENSSL
106 #include <openssl/evp.h>
107 #include <openssl/hmac.h>
108 #endif
109
110 #include "openbsd-tree.h"
111
112 #include <netinet/in.h>
113 #include <netinet/in_systm.h>
114 #include <netinet/ip.h>
115 #include <netinet/tcp.h>
116
117 #ifdef HAVE_NET_NETOPT_H
118 #include <net/netopt.h>
119 #endif /* HAVE_NET_NETOPT_H */
120
121 #include <net/if.h>
122
123 #ifdef HAVE_NET_IF_DL_H
124 #include <net/if_dl.h>
125 #endif /* HAVE_NET_IF_DL_H */
126
127 #ifdef HAVE_NET_IF_VAR_H
128 #include <net/if_var.h>
129 #endif /* HAVE_NET_IF_VAR_H */
130
131 #include <net/route.h>
132
133 #ifdef HAVE_NETLINK
134 #include <linux/netlink.h>
135 #include <linux/rtnetlink.h>
136 #include <linux/filter.h>
137 #else
138 #define RT_TABLE_MAIN 0
139 #endif /* HAVE_NETLINK */
140
141 #include <netdb.h>
142 #include <arpa/inet.h>
143
144 #ifdef HAVE_INET_ND_H
145 #include <inet/nd.h>
146 #endif /* HAVE_INET_ND_H */
147
148 #ifdef HAVE_NETINET_IN_VAR_H
149 #include <netinet/in_var.h>
150 #endif /* HAVE_NETINET_IN_VAR_H */
151
152 #ifdef HAVE_NETINET6_IN6_VAR_H
153 #include <netinet6/in6_var.h>
154 #endif /* HAVE_NETINET6_IN6_VAR_H */
155
156 #ifdef HAVE_NETINET_IN6_VAR_H
157 #include <netinet/in6_var.h>
158 #endif /* HAVE_NETINET_IN6_VAR_H */
159
160 #ifdef HAVE_NETINET6_IN_H
161 #include <netinet6/in.h>
162 #endif /* HAVE_NETINET6_IN_H */
163
164
165 #ifdef HAVE_NETINET6_IP6_H
166 #include <netinet6/ip6.h>
167 #endif /* HAVE_NETINET6_IP6_H */
168
169 #include <netinet/icmp6.h>
170
171 #ifdef HAVE_NETINET6_ND6_H
172 #include <netinet6/nd6.h>
173 #endif /* HAVE_NETINET6_ND6_H */
174
175 /* Some systems do not define UINT32_MAX, etc.. from inttypes.h
176 * e.g. this makes life easier for FBSD 4.11 users.
177 */
178 #ifndef INT16_MAX
179 #define INT16_MAX (32767)
180 #endif
181 #ifndef INT32_MAX
182 #define INT32_MAX (2147483647)
183 #endif
184 #ifndef UINT16_MAX
185 #define UINT16_MAX (65535U)
186 #endif
187 #ifndef UINT32_MAX
188 #define UINT32_MAX (4294967295U)
189 #endif
190
191 #ifdef HAVE_GLIBC_BACKTRACE
192 #include <execinfo.h>
193 #endif /* HAVE_GLIBC_BACKTRACE */
194
195 /* Local includes: */
196 #if !defined(__GNUC__)
197 #define __attribute__(x)
198 #endif /* !__GNUC__ */
199
200 #include <assert.h>
201
202 /*
203 * Add explicit static cast only when using a C++ compiler.
204 */
205 #ifdef __cplusplus
206 #define static_cast(l, r) static_cast<decltype(l)>((r))
207 #else
208 #define static_cast(l, r) (r)
209 #endif
210
211 #ifdef __cplusplus
212 extern "C" {
213 #endif
214
215 #ifndef HAVE_STRLCAT
216 size_t strlcat(char *__restrict dest,
217 const char *__restrict src, size_t destsize);
218 #endif
219 #ifndef HAVE_STRLCPY
220 size_t strlcpy(char *__restrict dest,
221 const char *__restrict src, size_t destsize);
222 #endif
223
224 #ifndef HAVE_EXPLICIT_BZERO
225 void explicit_bzero(void *buf, size_t len);
226 #endif
227
228 #if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG)
229 /* avoid conflicts in case we have partial support */
230 #define mmsghdr frr_mmsghdr
231 #define sendmmsg frr_sendmmsg
232
233 struct mmsghdr {
234 struct msghdr msg_hdr;
235 unsigned int msg_len;
236 };
237
238 /* just go 1 at a time here, the loop this is used in will handle the rest */
239 static inline int sendmmsg(int fd, struct mmsghdr *mmh, unsigned int len,
240 int flags)
241 {
242 int rv = sendmsg(fd, &mmh->msg_hdr, 0);
243
244 return rv > 0 ? 1 : rv;
245 }
246 #endif
247
248 /*
249 * RFC 3542 defines several macros for using struct cmsghdr.
250 * Here, we define those that are not present
251 */
252
253 /*
254 * Internal defines, for use only in this file.
255 * These are likely wrong on other than ILP32 machines, so warn.
256 */
257 #ifndef _CMSG_DATA_ALIGN
258 #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
259 #endif /* _CMSG_DATA_ALIGN */
260
261 #ifndef _CMSG_HDR_ALIGN
262 #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
263 #endif /* _CMSG_HDR_ALIGN */
264
265 /*
266 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
267 * version.
268 */
269 #ifndef CMSG_SPACE
270 #define CMSG_SPACE(l) \
271 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
272 #warning "assuming 4-byte alignment for CMSG_SPACE"
273 #endif /* CMSG_SPACE */
274
275
276 #ifndef CMSG_LEN
277 #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
278 #warning "assuming 4-byte alignment for CMSG_LEN"
279 #endif /* CMSG_LEN */
280
281
282 /* The definition of struct in_pktinfo is missing in old version of
283 GLIBC 2.1 (Redhat 6.1). */
284 #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
285 struct in_pktinfo {
286 int ipi_ifindex;
287 struct in_addr ipi_spec_dst;
288 struct in_addr ipi_addr;
289 };
290 #endif
291
292 /*
293 * IP_HDRINCL / struct ip byte order
294 *
295 * Linux: network byte order
296 * *BSD: network, except for length and offset. (cf Stevens)
297 * SunOS: nominally as per BSD. but bug: network order on LE.
298 * OpenBSD: network byte order, apart from older versions which are as per
299 * *BSD
300 */
301 #if defined(__NetBSD__) \
302 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
303 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
304 || (defined(__APPLE__))
305 #define HAVE_IP_HDRINCL_BSD_ORDER
306 #endif
307
308 /* autoconf macros for this are deprecated, just find endian.h */
309 #ifndef BYTE_ORDER
310 #error please locate an endian.h file appropriate to your platform
311 #endif
312
313 /* For old definition. */
314 #ifndef IN6_ARE_ADDR_EQUAL
315 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
316 #endif /* IN6_ARE_ADDR_EQUAL */
317
318 /* default zebra TCP port for zclient */
319 #define ZEBRA_PORT 2600
320
321 /*
322 * The compiler.h header is used for anyone using the CPP_NOTICE
323 * since this is universally needed, let's add it to zebra.h
324 */
325 #include "compiler.h"
326
327 /* Zebra route's types are defined in route_types.h */
328 #include "lib/route_types.h"
329
330 #define strmatch(a,b) (!strcmp((a), (b)))
331
332 #if BYTE_ORDER == LITTLE_ENDIAN
333 #define htonll(x) (((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32))
334 #define ntohll(x) (((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32))
335 #else
336 #define htonll(x) (x)
337 #define ntohll(x) (x)
338 #endif
339
340 #ifndef INADDR_LOOPBACK
341 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
342 #endif
343
344 /* Address family numbers from RFC1700. */
345 typedef enum {
346 AFI_UNSPEC = 0,
347 AFI_IP = 1,
348 AFI_IP6 = 2,
349 AFI_L2VPN = 3,
350 AFI_MAX = 4
351 } afi_t;
352
353 #define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX)
354
355 /* Subsequent Address Family Identifier. */
356 typedef enum {
357 SAFI_UNSPEC = 0,
358 SAFI_UNICAST = 1,
359 SAFI_MULTICAST = 2,
360 SAFI_MPLS_VPN = 3,
361 SAFI_ENCAP = 4,
362 SAFI_EVPN = 5,
363 SAFI_LABELED_UNICAST = 6,
364 SAFI_FLOWSPEC = 7,
365 SAFI_MAX = 8
366 } safi_t;
367
368 #define FOREACH_AFI_SAFI(afi, safi) \
369 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
370 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
371
372 #define FOREACH_AFI_SAFI_NSF(afi, safi) \
373 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
374 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
375
376 /* Default Administrative Distance of each protocol. */
377 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
378 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
379 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
380 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
381 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
382 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
383 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
384 #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
385 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
386 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
387 #define ZEBRA_TABLE_DISTANCE_DEFAULT 15
388 #define ZEBRA_EIGRP_DISTANCE_DEFAULT 90
389 #define ZEBRA_NHRP_DISTANCE_DEFAULT 10
390 #define ZEBRA_LDP_DISTANCE_DEFAULT 150
391 #define ZEBRA_BABEL_DISTANCE_DEFAULT 100
392 #define ZEBRA_SHARP_DISTANCE_DEFAULT 150
393 #define ZEBRA_PBR_DISTANCE_DEFAULT 200
394 #define ZEBRA_OPENFABRIC_DISTANCE_DEFAULT 115
395 #define ZEBRA_MAX_DISTANCE_DEFAULT 255
396
397 /* Flag manipulation macros. */
398 #define CHECK_FLAG(V,F) ((V) & (F))
399 #define SET_FLAG(V,F) (V) |= (F)
400 #define UNSET_FLAG(V,F) (V) &= ~(F)
401 #define RESET_FLAG(V) (V) = 0
402 #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
403
404 /* Atomic flag manipulation macros. */
405 #define CHECK_FLAG_ATOMIC(PV, F) \
406 ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
407 #define SET_FLAG_ATOMIC(PV, F) \
408 ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
409 #define UNSET_FLAG_ATOMIC(PV, F) \
410 ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
411 #define RESET_FLAG_ATOMIC(PV) \
412 ((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
413
414 /* VRF ID type. */
415 typedef uint32_t vrf_id_t;
416
417 typedef uint32_t route_tag_t;
418 #define ROUTE_TAG_MAX UINT32_MAX
419 #define ROUTE_TAG_PRI PRIu32
420
421 #ifdef __cplusplus
422 }
423 #endif
424
425 #endif /* _ZEBRA_H */