]>
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 |
31 | #define _XPG4_2 | |
d7c0a89a QY |
32 | typedef unsigned int uint32_t; |
33 | typedef unsigned short uint16_t; | |
34 | typedef unsigned char uint8_t; | |
718e3744 | 35 | #endif /* SUNOS_5 */ |
36 | ||
37 | #include <unistd.h> | |
38 | #include <stdio.h> | |
39 | #include <stdlib.h> | |
c423d413 | 40 | #include <stddef.h> |
718e3744 | 41 | #include <ctype.h> |
42 | #include <errno.h> | |
43 | #include <fcntl.h> | |
44 | #include <signal.h> | |
45 | #include <string.h> | |
edd7c245 | 46 | #include <pwd.h> |
47 | #include <grp.h> | |
718e3744 | 48 | #ifdef HAVE_STROPTS_H |
49 | #include <stropts.h> | |
50 | #endif /* HAVE_STROPTS_H */ | |
718e3744 | 51 | #include <sys/select.h> |
718e3744 | 52 | #include <sys/stat.h> |
718e3744 | 53 | #include <sys/types.h> |
54 | #include <sys/param.h> | |
55 | #ifdef HAVE_SYS_SYSCTL_H | |
0dc0b708 AS |
56 | #ifdef GNU_LINUX |
57 | #include <linux/types.h> | |
58 | #endif | |
718e3744 | 59 | #include <sys/sysctl.h> |
60 | #endif /* HAVE_SYS_SYSCTL_H */ | |
61 | #include <sys/ioctl.h> | |
62 | #ifdef HAVE_SYS_CONF_H | |
63 | #include <sys/conf.h> | |
64 | #endif /* HAVE_SYS_CONF_H */ | |
65 | #ifdef HAVE_SYS_KSYM_H | |
66 | #include <sys/ksym.h> | |
67 | #endif /* HAVE_SYS_KSYM_H */ | |
68 | #include <syslog.h> | |
24f5e2fc DL |
69 | #include <sys/time.h> |
70 | #include <time.h> | |
718e3744 | 71 | #include <sys/uio.h> |
72 | #include <sys/utsname.h> | |
718e3744 | 73 | #include <sys/resource.h> |
a58c25b6 | 74 | #include <limits.h> |
35cfc90c | 75 | #include <inttypes.h> |
63a13864 | 76 | #include <stdbool.h> |
718e3744 | 77 | |
78 | /* machine dependent includes */ | |
79 | #ifdef SUNOS_5 | |
718e3744 | 80 | #include <strings.h> |
81 | #endif /* SUNOS_5 */ | |
82 | ||
83 | /* machine dependent includes */ | |
84 | #ifdef HAVE_LINUX_VERSION_H | |
85 | #include <linux/version.h> | |
86 | #endif /* HAVE_LINUX_VERSION_H */ | |
87 | ||
ba965c6c | 88 | #ifdef HAVE_ASM_TYPES_H |
89 | #include <asm/types.h> | |
90 | #endif /* HAVE_ASM_TYPES_H */ | |
91 | ||
718e3744 | 92 | /* misc include group */ |
93 | #include <stdarg.h> | |
4cf0d0df | 94 | #if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) |
95 | /* Not C99; do we need to define va_copy? */ | |
e22f5516 | 96 | #ifndef va_copy |
97 | #ifdef __va_copy | |
4cf0d0df | 98 | #define va_copy(DST,SRC) __va_copy(DST,SRC) |
e22f5516 | 99 | #else |
d62a17ae | 100 | /* Now we are desperate; this should work on many typical platforms. |
e22f5516 | 101 | But this is slightly dangerous, because the standard does not require |
102 | va_copy to be a macro. */ | |
103 | #define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list)) | |
104 | #warning "Not C99 and no va_copy macro available, falling back to memcpy" | |
105 | #endif /* __va_copy */ | |
106 | #endif /* !va_copy */ | |
4cf0d0df | 107 | #endif /* !C99 */ |
db8eaac6 | 108 | |
718e3744 | 109 | |
ba3a0bc5 | 110 | #ifdef HAVE_LCAPS |
111 | #include <sys/capability.h> | |
112 | #include <sys/prctl.h> | |
113 | #endif /* HAVE_LCAPS */ | |
114 | ||
ceacedba | 115 | #ifdef HAVE_SOLARIS_CAPABILITIES |
116 | #include <priv.h> | |
117 | #endif /* HAVE_SOLARIS_CAPABILITIES */ | |
118 | ||
718e3744 | 119 | /* network include group */ |
120 | ||
121 | #include <sys/socket.h> | |
122 | ||
123 | #ifdef HAVE_SYS_SOCKIO_H | |
124 | #include <sys/sockio.h> | |
125 | #endif /* HAVE_SYS_SOCKIO_H */ | |
126 | ||
ea057677 HT |
127 | #ifdef __APPLE__ |
128 | #define __APPLE_USE_RFC_3542 | |
129 | #endif | |
130 | ||
f9e75524 | 131 | #ifndef HAVE_LIBCRYPT |
996c9314 LB |
132 | #ifdef HAVE_LIBCRYPTO |
133 | #include <openssl/des.h> | |
f9e75524 | 134 | # define crypt DES_crypt |
996c9314 | 135 | #endif |
f9e75524 JAG |
136 | #endif |
137 | ||
8d8763f4 | 138 | #include "openbsd-tree.h" |
6021c8d3 | 139 | |
718e3744 | 140 | #include <netinet/in.h> |
718e3744 | 141 | #include <netinet/in_systm.h> |
142 | #include <netinet/ip.h> | |
143 | #include <netinet/tcp.h> | |
144 | ||
145 | #ifdef HAVE_NET_NETOPT_H | |
146 | #include <net/netopt.h> | |
147 | #endif /* HAVE_NET_NETOPT_H */ | |
148 | ||
149 | #include <net/if.h> | |
150 | ||
151 | #ifdef HAVE_NET_IF_DL_H | |
152 | #include <net/if_dl.h> | |
153 | #endif /* HAVE_NET_IF_DL_H */ | |
154 | ||
155 | #ifdef HAVE_NET_IF_VAR_H | |
156 | #include <net/if_var.h> | |
157 | #endif /* HAVE_NET_IF_VAR_H */ | |
158 | ||
159 | #include <net/route.h> | |
160 | ||
161 | #ifdef HAVE_NETLINK | |
162 | #include <linux/netlink.h> | |
163 | #include <linux/rtnetlink.h> | |
768a27ea | 164 | #include <linux/filter.h> |
718e3744 | 165 | #else |
166 | #define RT_TABLE_MAIN 0 | |
167 | #endif /* HAVE_NETLINK */ | |
168 | ||
718e3744 | 169 | #include <netdb.h> |
718e3744 | 170 | #include <arpa/inet.h> |
718e3744 | 171 | |
172 | #ifdef HAVE_INET_ND_H | |
173 | #include <inet/nd.h> | |
174 | #endif /* HAVE_INET_ND_H */ | |
175 | ||
176 | #ifdef HAVE_NETINET_IN_VAR_H | |
177 | #include <netinet/in_var.h> | |
178 | #endif /* HAVE_NETINET_IN_VAR_H */ | |
179 | ||
726f9b2b | 180 | #ifdef HAVE_NETINET6_IN6_VAR_H |
181 | #include <netinet6/in6_var.h> | |
182 | #endif /* HAVE_NETINET6_IN6_VAR_H */ | |
183 | ||
718e3744 | 184 | #ifdef HAVE_NETINET_IN6_VAR_H |
185 | #include <netinet/in6_var.h> | |
186 | #endif /* HAVE_NETINET_IN6_VAR_H */ | |
187 | ||
188 | #ifdef HAVE_NETINET6_IN_H | |
189 | #include <netinet6/in.h> | |
190 | #endif /* HAVE_NETINET6_IN_H */ | |
191 | ||
192 | ||
193 | #ifdef HAVE_NETINET6_IP6_H | |
194 | #include <netinet6/ip6.h> | |
195 | #endif /* HAVE_NETINET6_IP6_H */ | |
196 | ||
718e3744 | 197 | #include <netinet/icmp6.h> |
718e3744 | 198 | |
199 | #ifdef HAVE_NETINET6_ND6_H | |
200 | #include <netinet6/nd6.h> | |
201 | #endif /* HAVE_NETINET6_ND6_H */ | |
202 | ||
35cfc90c PJ |
203 | /* Some systems do not define UINT32_MAX, etc.. from inttypes.h |
204 | * e.g. this makes life easier for FBSD 4.11 users. | |
205 | */ | |
206 | #ifndef INT8_MAX | |
207 | #define INT8_MAX (127) | |
208 | #endif | |
209 | #ifndef INT16_MAX | |
210 | #define INT16_MAX (32767) | |
211 | #endif | |
212 | #ifndef INT32_MAX | |
213 | #define INT32_MAX (2147483647) | |
214 | #endif | |
215 | #ifndef UINT8_MAX | |
216 | #define UINT8_MAX (255U) | |
217 | #endif | |
218 | #ifndef UINT16_MAX | |
219 | #define UINT16_MAX (65535U) | |
220 | #endif | |
3b424979 | 221 | #ifndef UINT32_MAX |
35cfc90c PJ |
222 | #define UINT32_MAX (4294967295U) |
223 | #endif | |
3b424979 | 224 | |
fb2d1502 | 225 | #ifdef HAVE_GLIBC_BACKTRACE |
226 | #include <execinfo.h> | |
227 | #endif /* HAVE_GLIBC_BACKTRACE */ | |
228 | ||
db8eaac6 | 229 | /* Local includes: */ |
d62a17ae | 230 | #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL)) |
db8eaac6 | 231 | #define __attribute__(x) |
d62a17ae | 232 | #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */ |
db8eaac6 | 233 | |
234 | #include "zassert.h" | |
235 | ||
c5d9d3bb | 236 | #ifndef HAVE_STRLCAT |
c9a164df DS |
237 | size_t strlcat(char *__restrict dest, |
238 | const char *__restrict src, size_t destsize); | |
c5d9d3bb DL |
239 | #endif |
240 | #ifndef HAVE_STRLCPY | |
c9a164df DS |
241 | size_t strlcpy(char *__restrict dest, |
242 | const char *__restrict src, size_t destsize); | |
c5d9d3bb | 243 | #endif |
db8eaac6 | 244 | |
fe232cf8 QY |
245 | /* GCC have printf type attribute check. */ |
246 | #ifdef __GNUC__ | |
247 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) | |
248 | #else | |
249 | #define PRINTF_ATTRIBUTE(a,b) | |
250 | #endif /* __GNUC__ */ | |
b99760ab | 251 | |
d62a17ae | 252 | /* |
69e1325f | 253 | * RFC 3542 defines several macros for using struct cmsghdr. |
254 | * Here, we define those that are not present | |
255 | */ | |
256 | ||
257 | /* | |
258 | * Internal defines, for use only in this file. | |
259 | * These are likely wrong on other than ILP32 machines, so warn. | |
02ff83c5 | 260 | */ |
261 | #ifndef _CMSG_DATA_ALIGN | |
262 | #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3) | |
263 | #endif /* _CMSG_DATA_ALIGN */ | |
264 | ||
265 | #ifndef _CMSG_HDR_ALIGN | |
266 | #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3) | |
267 | #endif /* _CMSG_HDR_ALIGN */ | |
268 | ||
69e1325f | 269 | /* |
270 | * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that | |
271 | * version. | |
272 | */ | |
02ff83c5 | 273 | #ifndef CMSG_SPACE |
d62a17ae | 274 | #define CMSG_SPACE(l) \ |
275 | (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l)) | |
69e1325f | 276 | #warning "assuming 4-byte alignment for CMSG_SPACE" |
d62a17ae | 277 | #endif /* CMSG_SPACE */ |
02ff83c5 | 278 | |
279 | ||
280 | #ifndef CMSG_LEN | |
281 | #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l)) | |
69e1325f | 282 | #warning "assuming 4-byte alignment for CMSG_LEN" |
02ff83c5 | 283 | #endif /* CMSG_LEN */ |
284 | ||
69e1325f | 285 | |
718e3744 | 286 | /* The definition of struct in_pktinfo is missing in old version of |
287 | GLIBC 2.1 (Redhat 6.1). */ | |
d62a17ae | 288 | #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO) |
289 | struct in_pktinfo { | |
290 | int ipi_ifindex; | |
291 | struct in_addr ipi_spec_dst; | |
292 | struct in_addr ipi_addr; | |
718e3744 | 293 | }; |
294 | #endif | |
295 | ||
d62a17ae | 296 | /* |
9172ee0e | 297 | * IP_HDRINCL / struct ip byte order |
298 | * | |
299 | * Linux: network byte order | |
300 | * *BSD: network, except for length and offset. (cf Stevens) | |
301 | * SunOS: nominally as per BSD. but bug: network order on LE. | |
d62a17ae | 302 | * OpenBSD: network byte order, apart from older versions which are as per |
9172ee0e | 303 | * *BSD |
304 | */ | |
d62a17ae | 305 | #if defined(__NetBSD__) \ |
306 | || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \ | |
307 | || (defined(__OpenBSD__) && (OpenBSD < 200311)) \ | |
308 | || (defined(__APPLE__)) \ | |
309 | || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN)) | |
9172ee0e | 310 | #define HAVE_IP_HDRINCL_BSD_ORDER |
311 | #endif | |
312 | ||
34204aac | 313 | /* Define BYTE_ORDER, if not defined. Useful for compiler conditional |
314 | * code, rather than preprocessor conditional. | |
315 | * Not all the world has this BSD define. | |
316 | */ | |
317 | #ifndef BYTE_ORDER | |
318 | #define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */ | |
319 | #define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */ | |
320 | #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */ | |
321 | ||
322 | #if defined(WORDS_BIGENDIAN) | |
323 | #define BYTE_ORDER BIG_ENDIAN | |
d62a17ae | 324 | #else /* !WORDS_BIGENDIAN */ |
34204aac | 325 | #define BYTE_ORDER LITTLE_ENDIAN |
326 | #endif /* WORDS_BIGENDIAN */ | |
327 | ||
328 | #endif /* ndef BYTE_ORDER */ | |
329 | ||
efba6ce9 | 330 | /* MAX / MIN are not commonly defined, but useful */ |
6b143a68 DL |
331 | /* note: glibc sys/param.h has #define MIN(a,b) (((a)<(b))?(a):(b)) */ |
332 | #ifdef MAX | |
333 | #undef MAX | |
334 | #endif | |
d62a17ae | 335 | #define MAX(a, b) \ |
336 | ({ \ | |
337 | typeof(a) _a = (a); \ | |
338 | typeof(b) _b = (b); \ | |
339 | _a > _b ? _a : _b; \ | |
340 | }) | |
6b143a68 DL |
341 | #ifdef MIN |
342 | #undef MIN | |
8a0bebfc | 343 | #endif |
d62a17ae | 344 | #define MIN(a, b) \ |
345 | ({ \ | |
346 | typeof(a) _a = (a); \ | |
347 | typeof(b) _b = (b); \ | |
348 | _a < _b ? _a : _b; \ | |
349 | }) | |
efba6ce9 | 350 | |
d43d2df5 CF |
351 | #ifndef offsetof |
352 | #ifdef __compiler_offsetof | |
353 | #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) | |
354 | #else | |
355 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | |
356 | #endif | |
357 | #endif | |
358 | ||
359 | #ifndef container_of | |
360 | #define container_of(ptr, type, member) \ | |
361 | ({ \ | |
362 | const typeof(((type *)0)->member) *__mptr = (ptr); \ | |
363 | (type *)((char *)__mptr - offsetof(type, member)); \ | |
364 | }) | |
365 | #endif | |
366 | ||
0915bb0c AS |
367 | #define ZEBRA_NUM_OF(x) (sizeof (x) / sizeof (x[0])) |
368 | ||
718e3744 | 369 | /* For old definition. */ |
370 | #ifndef IN6_ARE_ADDR_EQUAL | |
371 | #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL | |
372 | #endif /* IN6_ARE_ADDR_EQUAL */ | |
373 | ||
8cc4198f | 374 | /* default zebra TCP port for zclient */ |
375 | #define ZEBRA_PORT 2600 | |
376 | ||
c1b9800a | 377 | /* Marker value used in new Zserv, in the byte location corresponding |
378 | * the command value in the old zserv header. To allow old and new | |
379 | * Zserv headers to be distinguished from each other. | |
380 | */ | |
80e71dcd | 381 | #define ZEBRA_HEADER_MARKER 254 |
c1b9800a | 382 | |
e0ca5fde DL |
383 | /* Zebra route's types are defined in route_types.h */ |
384 | #include "route_types.h" | |
718e3744 | 385 | |
d6d672aa PJ |
386 | /* Note: whenever a new route-type or zserv-command is added the |
387 | * corresponding {command,route}_types[] table in lib/log.c MUST be | |
388 | * updated! */ | |
f52d13cb | 389 | |
390 | /* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */ | |
b6026073 | 391 | extern const char *zebra_route_string(unsigned int route_type); |
f52d13cb | 392 | /* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */ |
b6026073 | 393 | extern char zebra_route_char(unsigned int route_type); |
d62a17ae | 394 | /* Map a zserv command type to the same string, |
d6d672aa | 395 | * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */ |
7514fb77 PJ |
396 | /* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/ |
397 | extern int proto_name2num(const char *s); | |
e0ca5fde DL |
398 | /* Map redistribute X argument to protocol number. |
399 | * unlike proto_name2num, this accepts shorthands and takes | |
400 | * an AFI value to restrict input */ | |
401 | extern int proto_redistnum(int afi, const char *s); | |
7514fb77 | 402 | |
d62a17ae | 403 | extern const char *zserv_command_string(unsigned int command); |
f52d13cb | 404 | |
bf31fc81 DL |
405 | #define strmatch(a,b) (!strcmp((a), (b))) |
406 | ||
718e3744 | 407 | /* Zebra message flags */ |
4e8b02f4 | 408 | #define ZEBRA_FLAG_ALLOW_RECURSION 0x01 |
718e3744 | 409 | #define ZEBRA_FLAG_SELFROUTE 0x02 |
718e3744 | 410 | #define ZEBRA_FLAG_IBGP 0x08 |
411 | #define ZEBRA_FLAG_SELECTED 0x10 | |
718e3744 | 412 | #define ZEBRA_FLAG_STATIC 0x40 |
525c1839 | 413 | #define ZEBRA_FLAG_SCOPE_LINK 0x100 |
446bb95e | 414 | #define ZEBRA_FLAG_FIB_OVERRIDE 0x200 |
90264d64 | 415 | #define ZEBRA_FLAG_EVPN_ROUTE 0x400 |
40ecd8e4 | 416 | #define ZEBRA_FLAG_RR_USE_DISTANCE 0x800 |
a8309422 DL |
417 | /* ZEBRA_FLAG_BLACKHOLE was 0x04 */ |
418 | /* ZEBRA_FLAG_REJECT was 0x80 */ | |
718e3744 | 419 | |
28d58fd7 VV |
420 | /* Zebra FEC flags. */ |
421 | #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x1 | |
422 | ||
718e3744 | 423 | #ifndef INADDR_LOOPBACK |
424 | #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */ | |
425 | #endif | |
426 | ||
427 | /* Address family numbers from RFC1700. */ | |
d62a17ae | 428 | typedef enum { AFI_IP = 1, AFI_IP6 = 2, AFI_L2VPN = 3, AFI_MAX = 4 } afi_t; |
718e3744 | 429 | |
430 | /* Subsequent Address Family Identifier. */ | |
5c525538 RW |
431 | typedef enum { |
432 | SAFI_UNICAST = 1, | |
433 | SAFI_MULTICAST = 2, | |
434 | SAFI_MPLS_VPN = 3, | |
435 | SAFI_ENCAP = 4, | |
436 | SAFI_EVPN = 5, | |
437 | SAFI_LABELED_UNICAST = 6, | |
b98f7728 PG |
438 | SAFI_FLOWSPEC = 7, |
439 | SAFI_MAX = 8 | |
5c525538 | 440 | } safi_t; |
718e3744 | 441 | |
90d82769 DS |
442 | /* |
443 | * The above AFI and SAFI definitions are for internal use. The protocol | |
444 | * definitions (IANA values) as for example used in BGP protocol packets | |
445 | * are defined below and these will get mapped to/from the internal values | |
446 | * in the appropriate places. | |
447 | * The rationale is that the protocol (IANA) values may be sparse and are | |
448 | * not optimal for use in data-structure sizing. | |
449 | * Note: Only useful (i.e., supported) values are defined below. | |
450 | */ | |
451 | typedef enum { | |
d62a17ae | 452 | IANA_AFI_RESERVED = 0, |
453 | IANA_AFI_IPV4 = 1, | |
454 | IANA_AFI_IPV6 = 2, | |
455 | IANA_AFI_L2VPN = 25, | |
456 | IANA_AFI_IPMR = 128, | |
457 | IANA_AFI_IP6MR = 129 | |
90d82769 DS |
458 | } iana_afi_t; |
459 | ||
5c525538 RW |
460 | typedef enum { |
461 | IANA_SAFI_RESERVED = 0, | |
462 | IANA_SAFI_UNICAST = 1, | |
463 | IANA_SAFI_MULTICAST = 2, | |
464 | IANA_SAFI_LABELED_UNICAST = 4, | |
465 | IANA_SAFI_ENCAP = 7, | |
466 | IANA_SAFI_EVPN = 70, | |
7c40bf39 | 467 | IANA_SAFI_MPLS_VPN = 128, |
468 | IANA_SAFI_FLOWSPEC = 133 | |
5c525538 | 469 | } iana_safi_t; |
718e3744 | 470 | |
718e3744 | 471 | /* Default Administrative Distance of each protocol. */ |
472 | #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 | |
473 | #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 | |
474 | #define ZEBRA_STATIC_DISTANCE_DEFAULT 1 | |
475 | #define ZEBRA_RIP_DISTANCE_DEFAULT 120 | |
476 | #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120 | |
477 | #define ZEBRA_OSPF_DISTANCE_DEFAULT 110 | |
478 | #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110 | |
9e867fe6 | 479 | #define ZEBRA_ISIS_DISTANCE_DEFAULT 115 |
718e3744 | 480 | #define ZEBRA_IBGP_DISTANCE_DEFAULT 200 |
481 | #define ZEBRA_EBGP_DISTANCE_DEFAULT 20 | |
7ab5795a | 482 | #define ZEBRA_TABLE_DISTANCE_DEFAULT 15 |
718e3744 | 483 | |
484 | /* Flag manipulation macros. */ | |
485 | #define CHECK_FLAG(V,F) ((V) & (F)) | |
548e6f7d | 486 | #define SET_FLAG(V,F) (V) |= (F) |
487 | #define UNSET_FLAG(V,F) (V) &= ~(F) | |
fb018d25 | 488 | #define RESET_FLAG(V) (V) = 0 |
9fb964de | 489 | #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F))) |
718e3744 | 490 | |
f765d422 QY |
491 | /* Atomic flag manipulation macros. */ |
492 | #define CHECK_FLAG_ATOMIC(PV, F) \ | |
493 | ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F)) | |
494 | #define SET_FLAG_ATOMIC(PV, F) \ | |
495 | ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst))) | |
496 | #define UNSET_FLAG_ATOMIC(PV, F) \ | |
497 | ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst))) | |
498 | #define RESET_FLAG_ATOMIC(PV) \ | |
499 | ((atomic_store_explicit(PV, 0, memory_order_seq_cst))) | |
500 | ||
c1b9800a | 501 | /* Zebra types. Used in Zserv message header. */ |
d7c0a89a QY |
502 | typedef uint16_t zebra_size_t; |
503 | typedef uint16_t zebra_command_t; | |
718e3744 | 504 | |
b72ede27 | 505 | /* VRF ID type. */ |
a9ff90c4 | 506 | typedef uint32_t vrf_id_t; |
b72ede27 | 507 | |
dc9ffce8 CF |
508 | typedef uint32_t route_tag_t; |
509 | #define ROUTE_TAG_MAX UINT32_MAX | |
510 | #define ROUTE_TAG_PRI PRIu32 | |
511 | ||
d62a17ae | 512 | static inline afi_t afi_iana2int(iana_afi_t afi) |
9cabb64b | 513 | { |
085347cf RW |
514 | switch (afi) { |
515 | case IANA_AFI_IPV4: | |
d62a17ae | 516 | return AFI_IP; |
085347cf | 517 | case IANA_AFI_IPV6: |
d62a17ae | 518 | return AFI_IP6; |
085347cf | 519 | case IANA_AFI_L2VPN: |
d62a17ae | 520 | return AFI_L2VPN; |
085347cf RW |
521 | default: |
522 | return AFI_MAX; | |
523 | } | |
9cabb64b | 524 | } |
525 | ||
d62a17ae | 526 | static inline iana_afi_t afi_int2iana(afi_t afi) |
9cabb64b | 527 | { |
085347cf RW |
528 | switch (afi) { |
529 | case AFI_IP: | |
d62a17ae | 530 | return IANA_AFI_IPV4; |
085347cf | 531 | case AFI_IP6: |
d62a17ae | 532 | return IANA_AFI_IPV6; |
085347cf | 533 | case AFI_L2VPN: |
d62a17ae | 534 | return IANA_AFI_L2VPN; |
085347cf RW |
535 | default: |
536 | return IANA_AFI_RESERVED; | |
537 | } | |
9cabb64b | 538 | } |
539 | ||
5c525538 | 540 | static inline safi_t safi_iana2int(iana_safi_t safi) |
9cabb64b | 541 | { |
085347cf RW |
542 | switch (safi) { |
543 | case IANA_SAFI_UNICAST: | |
d62a17ae | 544 | return SAFI_UNICAST; |
085347cf | 545 | case IANA_SAFI_MULTICAST: |
d62a17ae | 546 | return SAFI_MULTICAST; |
085347cf | 547 | case IANA_SAFI_MPLS_VPN: |
d62a17ae | 548 | return SAFI_MPLS_VPN; |
085347cf | 549 | case IANA_SAFI_ENCAP: |
d62a17ae | 550 | return SAFI_ENCAP; |
085347cf | 551 | case IANA_SAFI_EVPN: |
d62a17ae | 552 | return SAFI_EVPN; |
085347cf | 553 | case IANA_SAFI_LABELED_UNICAST: |
d62a17ae | 554 | return SAFI_LABELED_UNICAST; |
7c40bf39 | 555 | case IANA_SAFI_FLOWSPEC: |
556 | return SAFI_FLOWSPEC; | |
085347cf RW |
557 | default: |
558 | return SAFI_MAX; | |
559 | } | |
9cabb64b | 560 | } |
561 | ||
5c525538 | 562 | static inline iana_safi_t safi_int2iana(safi_t safi) |
9cabb64b | 563 | { |
085347cf RW |
564 | switch (safi) { |
565 | case SAFI_UNICAST: | |
d62a17ae | 566 | return IANA_SAFI_UNICAST; |
085347cf | 567 | case SAFI_MULTICAST: |
d62a17ae | 568 | return IANA_SAFI_MULTICAST; |
085347cf | 569 | case SAFI_MPLS_VPN: |
d62a17ae | 570 | return IANA_SAFI_MPLS_VPN; |
085347cf | 571 | case SAFI_ENCAP: |
d62a17ae | 572 | return IANA_SAFI_ENCAP; |
085347cf | 573 | case SAFI_EVPN: |
d62a17ae | 574 | return IANA_SAFI_EVPN; |
085347cf | 575 | case SAFI_LABELED_UNICAST: |
d62a17ae | 576 | return IANA_SAFI_LABELED_UNICAST; |
7c40bf39 | 577 | case SAFI_FLOWSPEC: |
578 | return IANA_SAFI_FLOWSPEC; | |
085347cf RW |
579 | default: |
580 | return IANA_SAFI_RESERVED; | |
581 | } | |
9cabb64b | 582 | } |
583 | ||
718e3744 | 584 | #endif /* _ZEBRA_H */ |