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