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