]>
Commit | Line | Data |
---|---|---|
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 |
31 | typedef unsigned int uint32_t; |
32 | typedef unsigned short uint16_t; | |
33 | typedef 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 | */ | |
205 | #ifndef INT8_MAX | |
206 | #define INT8_MAX (127) | |
207 | #endif | |
208 | #ifndef INT16_MAX | |
209 | #define INT16_MAX (32767) | |
210 | #endif | |
211 | #ifndef INT32_MAX | |
212 | #define INT32_MAX (2147483647) | |
213 | #endif | |
214 | #ifndef UINT8_MAX | |
215 | #define UINT8_MAX (255U) | |
216 | #endif | |
217 | #ifndef UINT16_MAX | |
218 | #define UINT16_MAX (65535U) | |
219 | #endif | |
3b424979 | 220 | #ifndef UINT32_MAX |
35cfc90c PJ |
221 | #define UINT32_MAX (4294967295U) |
222 | #endif | |
3b424979 | 223 | |
fb2d1502 | 224 | #ifdef HAVE_GLIBC_BACKTRACE |
225 | #include <execinfo.h> | |
226 | #endif /* HAVE_GLIBC_BACKTRACE */ | |
227 | ||
db8eaac6 | 228 | /* Local includes: */ |
d62a17ae | 229 | #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL)) |
db8eaac6 | 230 | #define __attribute__(x) |
d62a17ae | 231 | #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */ |
db8eaac6 | 232 | |
233 | #include "zassert.h" | |
234 | ||
343cd13e RW |
235 | /* |
236 | * Add explicit static cast only when using a C++ compiler. | |
237 | */ | |
238 | #ifdef __cplusplus | |
239 | #define static_cast(l, r) static_cast<decltype(l)>((r)) | |
240 | #else | |
241 | #define static_cast(l, r) (r) | |
242 | #endif | |
243 | ||
c5d9d3bb | 244 | #ifndef HAVE_STRLCAT |
c9a164df DS |
245 | size_t strlcat(char *__restrict dest, |
246 | const char *__restrict src, size_t destsize); | |
c5d9d3bb DL |
247 | #endif |
248 | #ifndef HAVE_STRLCPY | |
c9a164df DS |
249 | size_t strlcpy(char *__restrict dest, |
250 | const char *__restrict src, size_t destsize); | |
c5d9d3bb | 251 | #endif |
db8eaac6 | 252 | |
fe232cf8 QY |
253 | /* GCC have printf type attribute check. */ |
254 | #ifdef __GNUC__ | |
255 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
256 | #else | |
257 | #define PRINTF_ATTRIBUTE(a,b) | |
258 | #endif /* __GNUC__ */ | |
b99760ab | 259 | |
d62a17ae | 260 | /* |
69e1325f | 261 | * RFC 3542 defines several macros for using struct cmsghdr. |
262 | * Here, we define those that are not present | |
263 | */ | |
264 | ||
265 | /* | |
266 | * Internal defines, for use only in this file. | |
267 | * These are likely wrong on other than ILP32 machines, so warn. | |
02ff83c5 | 268 | */ |
269 | #ifndef _CMSG_DATA_ALIGN | |
270 | #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3) | |
271 | #endif /* _CMSG_DATA_ALIGN */ | |
272 | ||
273 | #ifndef _CMSG_HDR_ALIGN | |
274 | #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3) | |
275 | #endif /* _CMSG_HDR_ALIGN */ | |
276 | ||
69e1325f | 277 | /* |
278 | * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that | |
279 | * version. | |
280 | */ | |
02ff83c5 | 281 | #ifndef CMSG_SPACE |
d62a17ae | 282 | #define CMSG_SPACE(l) \ |
283 | (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l)) | |
69e1325f | 284 | #warning "assuming 4-byte alignment for CMSG_SPACE" |
d62a17ae | 285 | #endif /* CMSG_SPACE */ |
02ff83c5 | 286 | |
287 | ||
288 | #ifndef CMSG_LEN | |
289 | #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l)) | |
69e1325f | 290 | #warning "assuming 4-byte alignment for CMSG_LEN" |
02ff83c5 | 291 | #endif /* CMSG_LEN */ |
292 | ||
69e1325f | 293 | |
718e3744 | 294 | /* The definition of struct in_pktinfo is missing in old version of |
295 | GLIBC 2.1 (Redhat 6.1). */ | |
d62a17ae | 296 | #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO) |
297 | struct in_pktinfo { | |
298 | int ipi_ifindex; | |
299 | struct in_addr ipi_spec_dst; | |
300 | struct in_addr ipi_addr; | |
718e3744 | 301 | }; |
302 | #endif | |
303 | ||
d62a17ae | 304 | /* |
9172ee0e | 305 | * IP_HDRINCL / struct ip byte order |
306 | * | |
307 | * Linux: network byte order | |
308 | * *BSD: network, except for length and offset. (cf Stevens) | |
309 | * SunOS: nominally as per BSD. but bug: network order on LE. | |
d62a17ae | 310 | * OpenBSD: network byte order, apart from older versions which are as per |
9172ee0e | 311 | * *BSD |
312 | */ | |
d62a17ae | 313 | #if defined(__NetBSD__) \ |
314 | || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \ | |
315 | || (defined(__OpenBSD__) && (OpenBSD < 200311)) \ | |
316 | || (defined(__APPLE__)) \ | |
317 | || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN)) | |
9172ee0e | 318 | #define HAVE_IP_HDRINCL_BSD_ORDER |
319 | #endif | |
320 | ||
34204aac | 321 | /* Define BYTE_ORDER, if not defined. Useful for compiler conditional |
322 | * code, rather than preprocessor conditional. | |
323 | * Not all the world has this BSD define. | |
324 | */ | |
325 | #ifndef BYTE_ORDER | |
326 | #define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */ | |
327 | #define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */ | |
328 | #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */ | |
329 | ||
330 | #if defined(WORDS_BIGENDIAN) | |
331 | #define BYTE_ORDER BIG_ENDIAN | |
d62a17ae | 332 | #else /* !WORDS_BIGENDIAN */ |
34204aac | 333 | #define BYTE_ORDER LITTLE_ENDIAN |
334 | #endif /* WORDS_BIGENDIAN */ | |
335 | ||
336 | #endif /* ndef BYTE_ORDER */ | |
337 | ||
718e3744 | 338 | /* For old definition. */ |
339 | #ifndef IN6_ARE_ADDR_EQUAL | |
340 | #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL | |
341 | #endif /* IN6_ARE_ADDR_EQUAL */ | |
342 | ||
8cc4198f | 343 | /* default zebra TCP port for zclient */ |
344 | #define ZEBRA_PORT 2600 | |
345 | ||
c1b9800a | 346 | /* Marker value used in new Zserv, in the byte location corresponding |
347 | * the command value in the old zserv header. To allow old and new | |
348 | * Zserv headers to be distinguished from each other. | |
349 | */ | |
80e71dcd | 350 | #define ZEBRA_HEADER_MARKER 254 |
c1b9800a | 351 | |
728806e6 DS |
352 | /* |
353 | * The compiler.h header is used for anyone using the CPP_NOTICE | |
354 | * since this is universally needed, let's add it to zebra.h | |
355 | */ | |
356 | #include "compiler.h" | |
357 | ||
e0ca5fde DL |
358 | /* Zebra route's types are defined in route_types.h */ |
359 | #include "route_types.h" | |
718e3744 | 360 | |
d6d672aa PJ |
361 | /* Note: whenever a new route-type or zserv-command is added the |
362 | * corresponding {command,route}_types[] table in lib/log.c MUST be | |
363 | * updated! */ | |
f52d13cb | 364 | |
365 | /* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */ | |
b6026073 | 366 | extern const char *zebra_route_string(unsigned int route_type); |
f52d13cb | 367 | /* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */ |
b6026073 | 368 | extern char zebra_route_char(unsigned int route_type); |
d62a17ae | 369 | /* Map a zserv command type to the same string, |
d6d672aa | 370 | * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */ |
7514fb77 PJ |
371 | /* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/ |
372 | extern int proto_name2num(const char *s); | |
e0ca5fde DL |
373 | /* Map redistribute X argument to protocol number. |
374 | * unlike proto_name2num, this accepts shorthands and takes | |
375 | * an AFI value to restrict input */ | |
376 | extern int proto_redistnum(int afi, const char *s); | |
7514fb77 | 377 | |
d62a17ae | 378 | extern const char *zserv_command_string(unsigned int command); |
f52d13cb | 379 | |
bf31fc81 DL |
380 | #define strmatch(a,b) (!strcmp((a), (b))) |
381 | ||
718e3744 | 382 | /* Zebra message flags */ |
07c67e1e DS |
383 | |
384 | /* | |
385 | * Cause Zebra to consider this routes nexthops recursively | |
386 | */ | |
4e8b02f4 | 387 | #define ZEBRA_FLAG_ALLOW_RECURSION 0x01 |
07c67e1e DS |
388 | /* |
389 | * This is a route that is read in on startup that was left around | |
390 | * from a previous run of FRR | |
391 | */ | |
718e3744 | 392 | #define ZEBRA_FLAG_SELFROUTE 0x02 |
07c67e1e DS |
393 | /* |
394 | * This flag is used to tell Zebra that the BGP route being passed | |
395 | * down is a IBGP route | |
396 | */ | |
397 | #define ZEBRA_FLAG_IBGP 0x04 | |
398 | /* | |
399 | * This is a route that has been selected for FIB installation. | |
400 | * This flag is set in zebra and can be passed up to routing daemons | |
401 | */ | |
402 | #define ZEBRA_FLAG_SELECTED 0x08 | |
403 | /* | |
404 | * This is a route that we are telling Zebra that this route *must* | |
405 | * win and will be installed even over ZEBRA_FLAG_SELECTED | |
406 | */ | |
407 | #define ZEBRA_FLAG_FIB_OVERRIDE 0x10 | |
408 | /* | |
409 | * This flag tells Zebra that the route is a EVPN route and should | |
410 | * be treated specially | |
411 | */ | |
412 | #define ZEBRA_FLAG_EVPN_ROUTE 0x20 | |
413 | /* | |
414 | * This flag tells Zebra that it should treat the distance passed | |
415 | * down as an additional discriminator for route selection of the | |
416 | * route entry. This mainly is used for backup static routes. | |
417 | */ | |
418 | #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40 | |
718e3744 | 419 | |
718e3744 | 420 | #ifndef INADDR_LOOPBACK |
421 | #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */ | |
422 | #endif | |
423 | ||
424 | /* Address family numbers from RFC1700. */ | |
b26f891d SW |
425 | typedef enum { |
426 | AFI_UNSPEC = 0, | |
427 | AFI_IP = 1, | |
428 | AFI_IP6 = 2, | |
429 | AFI_L2VPN = 3, | |
430 | AFI_MAX = 4 | |
431 | } afi_t; | |
718e3744 | 432 | |
433 | /* Subsequent Address Family Identifier. */ | |
5c525538 RW |
434 | typedef enum { |
435 | SAFI_UNICAST = 1, | |
436 | SAFI_MULTICAST = 2, | |
437 | SAFI_MPLS_VPN = 3, | |
438 | SAFI_ENCAP = 4, | |
439 | SAFI_EVPN = 5, | |
440 | SAFI_LABELED_UNICAST = 6, | |
b98f7728 PG |
441 | SAFI_FLOWSPEC = 7, |
442 | SAFI_MAX = 8 | |
5c525538 | 443 | } safi_t; |
718e3744 | 444 | |
90d82769 DS |
445 | /* |
446 | * The above AFI and SAFI definitions are for internal use. The protocol | |
447 | * definitions (IANA values) as for example used in BGP protocol packets | |
448 | * are defined below and these will get mapped to/from the internal values | |
449 | * in the appropriate places. | |
450 | * The rationale is that the protocol (IANA) values may be sparse and are | |
451 | * not optimal for use in data-structure sizing. | |
452 | * Note: Only useful (i.e., supported) values are defined below. | |
453 | */ | |
454 | typedef enum { | |
d62a17ae | 455 | IANA_AFI_RESERVED = 0, |
456 | IANA_AFI_IPV4 = 1, | |
457 | IANA_AFI_IPV6 = 2, | |
458 | IANA_AFI_L2VPN = 25, | |
459 | IANA_AFI_IPMR = 128, | |
460 | IANA_AFI_IP6MR = 129 | |
90d82769 DS |
461 | } iana_afi_t; |
462 | ||
5c525538 RW |
463 | typedef enum { |
464 | IANA_SAFI_RESERVED = 0, | |
465 | IANA_SAFI_UNICAST = 1, | |
466 | IANA_SAFI_MULTICAST = 2, | |
467 | IANA_SAFI_LABELED_UNICAST = 4, | |
468 | IANA_SAFI_ENCAP = 7, | |
469 | IANA_SAFI_EVPN = 70, | |
7c40bf39 | 470 | IANA_SAFI_MPLS_VPN = 128, |
471 | IANA_SAFI_FLOWSPEC = 133 | |
5c525538 | 472 | } iana_safi_t; |
718e3744 | 473 | |
718e3744 | 474 | /* Default Administrative Distance of each protocol. */ |
475 | #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 | |
476 | #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 | |
477 | #define ZEBRA_STATIC_DISTANCE_DEFAULT 1 | |
478 | #define ZEBRA_RIP_DISTANCE_DEFAULT 120 | |
479 | #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120 | |
480 | #define ZEBRA_OSPF_DISTANCE_DEFAULT 110 | |
481 | #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110 | |
9e867fe6 | 482 | #define ZEBRA_ISIS_DISTANCE_DEFAULT 115 |
718e3744 | 483 | #define ZEBRA_IBGP_DISTANCE_DEFAULT 200 |
484 | #define ZEBRA_EBGP_DISTANCE_DEFAULT 20 | |
7ab5795a | 485 | #define ZEBRA_TABLE_DISTANCE_DEFAULT 15 |
718e3744 | 486 | |
487 | /* Flag manipulation macros. */ | |
488 | #define CHECK_FLAG(V,F) ((V) & (F)) | |
548e6f7d | 489 | #define SET_FLAG(V,F) (V) |= (F) |
490 | #define UNSET_FLAG(V,F) (V) &= ~(F) | |
fb018d25 | 491 | #define RESET_FLAG(V) (V) = 0 |
9fb964de | 492 | #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F))) |
718e3744 | 493 | |
f765d422 QY |
494 | /* Atomic flag manipulation macros. */ |
495 | #define CHECK_FLAG_ATOMIC(PV, F) \ | |
496 | ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F)) | |
497 | #define SET_FLAG_ATOMIC(PV, F) \ | |
498 | ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst))) | |
499 | #define UNSET_FLAG_ATOMIC(PV, F) \ | |
500 | ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst))) | |
501 | #define RESET_FLAG_ATOMIC(PV) \ | |
502 | ((atomic_store_explicit(PV, 0, memory_order_seq_cst))) | |
503 | ||
c1b9800a | 504 | /* Zebra types. Used in Zserv message header. */ |
d7c0a89a QY |
505 | typedef uint16_t zebra_size_t; |
506 | typedef uint16_t zebra_command_t; | |
718e3744 | 507 | |
b72ede27 | 508 | /* VRF ID type. */ |
a9ff90c4 | 509 | typedef uint32_t vrf_id_t; |
b72ede27 | 510 | |
dc9ffce8 CF |
511 | typedef uint32_t route_tag_t; |
512 | #define ROUTE_TAG_MAX UINT32_MAX | |
513 | #define ROUTE_TAG_PRI PRIu32 | |
514 | ||
d62a17ae | 515 | static inline afi_t afi_iana2int(iana_afi_t afi) |
9cabb64b | 516 | { |
085347cf RW |
517 | switch (afi) { |
518 | case IANA_AFI_IPV4: | |
d62a17ae | 519 | return AFI_IP; |
085347cf | 520 | case IANA_AFI_IPV6: |
d62a17ae | 521 | return AFI_IP6; |
085347cf | 522 | case IANA_AFI_L2VPN: |
d62a17ae | 523 | return AFI_L2VPN; |
085347cf RW |
524 | default: |
525 | return AFI_MAX; | |
526 | } | |
9cabb64b | 527 | } |
528 | ||
d62a17ae | 529 | static inline iana_afi_t afi_int2iana(afi_t afi) |
9cabb64b | 530 | { |
085347cf RW |
531 | switch (afi) { |
532 | case AFI_IP: | |
d62a17ae | 533 | return IANA_AFI_IPV4; |
085347cf | 534 | case AFI_IP6: |
d62a17ae | 535 | return IANA_AFI_IPV6; |
085347cf | 536 | case AFI_L2VPN: |
d62a17ae | 537 | return IANA_AFI_L2VPN; |
085347cf RW |
538 | default: |
539 | return IANA_AFI_RESERVED; | |
540 | } | |
9cabb64b | 541 | } |
542 | ||
5c525538 | 543 | static inline safi_t safi_iana2int(iana_safi_t safi) |
9cabb64b | 544 | { |
085347cf RW |
545 | switch (safi) { |
546 | case IANA_SAFI_UNICAST: | |
d62a17ae | 547 | return SAFI_UNICAST; |
085347cf | 548 | case IANA_SAFI_MULTICAST: |
d62a17ae | 549 | return SAFI_MULTICAST; |
085347cf | 550 | case IANA_SAFI_MPLS_VPN: |
d62a17ae | 551 | return SAFI_MPLS_VPN; |
085347cf | 552 | case IANA_SAFI_ENCAP: |
d62a17ae | 553 | return SAFI_ENCAP; |
085347cf | 554 | case IANA_SAFI_EVPN: |
d62a17ae | 555 | return SAFI_EVPN; |
085347cf | 556 | case IANA_SAFI_LABELED_UNICAST: |
d62a17ae | 557 | return SAFI_LABELED_UNICAST; |
7c40bf39 | 558 | case IANA_SAFI_FLOWSPEC: |
559 | return SAFI_FLOWSPEC; | |
085347cf RW |
560 | default: |
561 | return SAFI_MAX; | |
562 | } | |
9cabb64b | 563 | } |
564 | ||
5c525538 | 565 | static inline iana_safi_t safi_int2iana(safi_t safi) |
9cabb64b | 566 | { |
085347cf RW |
567 | switch (safi) { |
568 | case SAFI_UNICAST: | |
d62a17ae | 569 | return IANA_SAFI_UNICAST; |
085347cf | 570 | case SAFI_MULTICAST: |
d62a17ae | 571 | return IANA_SAFI_MULTICAST; |
085347cf | 572 | case SAFI_MPLS_VPN: |
d62a17ae | 573 | return IANA_SAFI_MPLS_VPN; |
085347cf | 574 | case SAFI_ENCAP: |
d62a17ae | 575 | return IANA_SAFI_ENCAP; |
085347cf | 576 | case SAFI_EVPN: |
d62a17ae | 577 | return IANA_SAFI_EVPN; |
085347cf | 578 | case SAFI_LABELED_UNICAST: |
d62a17ae | 579 | return IANA_SAFI_LABELED_UNICAST; |
7c40bf39 | 580 | case SAFI_FLOWSPEC: |
581 | return IANA_SAFI_FLOWSPEC; | |
085347cf RW |
582 | default: |
583 | return IANA_SAFI_RESERVED; | |
584 | } | |
9cabb64b | 585 | } |
586 | ||
718e3744 | 587 | #endif /* _ZEBRA_H */ |