]>
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 | |
beec2cfe MW |
55 | #ifdef GNU_LINUX |
56 | #include <linux/types.h> | |
57 | #else | |
718e3744 | 58 | #include <sys/sysctl.h> |
15e84e5a | 59 | #endif |
718e3744 | 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 | ||
0513a271 MR |
138 | #ifdef CRYPTO_OPENSSL |
139 | #include <openssl/evp.h> | |
6252100f | 140 | #include <openssl/hmac.h> |
0513a271 MR |
141 | #endif |
142 | ||
8d8763f4 | 143 | #include "openbsd-tree.h" |
6021c8d3 | 144 | |
718e3744 | 145 | #include <netinet/in.h> |
718e3744 | 146 | #include <netinet/in_systm.h> |
147 | #include <netinet/ip.h> | |
148 | #include <netinet/tcp.h> | |
149 | ||
150 | #ifdef HAVE_NET_NETOPT_H | |
151 | #include <net/netopt.h> | |
152 | #endif /* HAVE_NET_NETOPT_H */ | |
153 | ||
154 | #include <net/if.h> | |
155 | ||
156 | #ifdef HAVE_NET_IF_DL_H | |
157 | #include <net/if_dl.h> | |
158 | #endif /* HAVE_NET_IF_DL_H */ | |
159 | ||
160 | #ifdef HAVE_NET_IF_VAR_H | |
161 | #include <net/if_var.h> | |
162 | #endif /* HAVE_NET_IF_VAR_H */ | |
163 | ||
164 | #include <net/route.h> | |
165 | ||
166 | #ifdef HAVE_NETLINK | |
167 | #include <linux/netlink.h> | |
168 | #include <linux/rtnetlink.h> | |
768a27ea | 169 | #include <linux/filter.h> |
718e3744 | 170 | #else |
171 | #define RT_TABLE_MAIN 0 | |
172 | #endif /* HAVE_NETLINK */ | |
173 | ||
718e3744 | 174 | #include <netdb.h> |
718e3744 | 175 | #include <arpa/inet.h> |
718e3744 | 176 | |
177 | #ifdef HAVE_INET_ND_H | |
178 | #include <inet/nd.h> | |
179 | #endif /* HAVE_INET_ND_H */ | |
180 | ||
181 | #ifdef HAVE_NETINET_IN_VAR_H | |
182 | #include <netinet/in_var.h> | |
183 | #endif /* HAVE_NETINET_IN_VAR_H */ | |
184 | ||
726f9b2b | 185 | #ifdef HAVE_NETINET6_IN6_VAR_H |
186 | #include <netinet6/in6_var.h> | |
187 | #endif /* HAVE_NETINET6_IN6_VAR_H */ | |
188 | ||
718e3744 | 189 | #ifdef HAVE_NETINET_IN6_VAR_H |
190 | #include <netinet/in6_var.h> | |
191 | #endif /* HAVE_NETINET_IN6_VAR_H */ | |
192 | ||
193 | #ifdef HAVE_NETINET6_IN_H | |
194 | #include <netinet6/in.h> | |
195 | #endif /* HAVE_NETINET6_IN_H */ | |
196 | ||
197 | ||
198 | #ifdef HAVE_NETINET6_IP6_H | |
199 | #include <netinet6/ip6.h> | |
200 | #endif /* HAVE_NETINET6_IP6_H */ | |
201 | ||
718e3744 | 202 | #include <netinet/icmp6.h> |
718e3744 | 203 | |
204 | #ifdef HAVE_NETINET6_ND6_H | |
205 | #include <netinet6/nd6.h> | |
206 | #endif /* HAVE_NETINET6_ND6_H */ | |
207 | ||
35cfc90c PJ |
208 | /* Some systems do not define UINT32_MAX, etc.. from inttypes.h |
209 | * e.g. this makes life easier for FBSD 4.11 users. | |
210 | */ | |
35cfc90c PJ |
211 | #ifndef INT16_MAX |
212 | #define INT16_MAX (32767) | |
213 | #endif | |
214 | #ifndef INT32_MAX | |
215 | #define INT32_MAX (2147483647) | |
216 | #endif | |
35cfc90c PJ |
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 | |
d62a17ae | 253 | /* |
69e1325f | 254 | * RFC 3542 defines several macros for using struct cmsghdr. |
255 | * Here, we define those that are not present | |
256 | */ | |
257 | ||
258 | /* | |
259 | * Internal defines, for use only in this file. | |
260 | * These are likely wrong on other than ILP32 machines, so warn. | |
02ff83c5 | 261 | */ |
262 | #ifndef _CMSG_DATA_ALIGN | |
263 | #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3) | |
264 | #endif /* _CMSG_DATA_ALIGN */ | |
265 | ||
266 | #ifndef _CMSG_HDR_ALIGN | |
267 | #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3) | |
268 | #endif /* _CMSG_HDR_ALIGN */ | |
269 | ||
69e1325f | 270 | /* |
271 | * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that | |
272 | * version. | |
273 | */ | |
02ff83c5 | 274 | #ifndef CMSG_SPACE |
d62a17ae | 275 | #define CMSG_SPACE(l) \ |
276 | (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l)) | |
69e1325f | 277 | #warning "assuming 4-byte alignment for CMSG_SPACE" |
d62a17ae | 278 | #endif /* CMSG_SPACE */ |
02ff83c5 | 279 | |
280 | ||
281 | #ifndef CMSG_LEN | |
282 | #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l)) | |
69e1325f | 283 | #warning "assuming 4-byte alignment for CMSG_LEN" |
02ff83c5 | 284 | #endif /* CMSG_LEN */ |
285 | ||
69e1325f | 286 | |
718e3744 | 287 | /* The definition of struct in_pktinfo is missing in old version of |
288 | GLIBC 2.1 (Redhat 6.1). */ | |
d62a17ae | 289 | #if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO) |
290 | struct in_pktinfo { | |
291 | int ipi_ifindex; | |
292 | struct in_addr ipi_spec_dst; | |
293 | struct in_addr ipi_addr; | |
718e3744 | 294 | }; |
295 | #endif | |
296 | ||
d62a17ae | 297 | /* |
9172ee0e | 298 | * IP_HDRINCL / struct ip byte order |
299 | * | |
300 | * Linux: network byte order | |
301 | * *BSD: network, except for length and offset. (cf Stevens) | |
302 | * SunOS: nominally as per BSD. but bug: network order on LE. | |
d62a17ae | 303 | * OpenBSD: network byte order, apart from older versions which are as per |
9172ee0e | 304 | * *BSD |
305 | */ | |
d62a17ae | 306 | #if defined(__NetBSD__) \ |
307 | || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \ | |
308 | || (defined(__OpenBSD__) && (OpenBSD < 200311)) \ | |
309 | || (defined(__APPLE__)) \ | |
310 | || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN)) | |
9172ee0e | 311 | #define HAVE_IP_HDRINCL_BSD_ORDER |
312 | #endif | |
313 | ||
34204aac | 314 | /* Define BYTE_ORDER, if not defined. Useful for compiler conditional |
315 | * code, rather than preprocessor conditional. | |
316 | * Not all the world has this BSD define. | |
317 | */ | |
318 | #ifndef BYTE_ORDER | |
319 | #define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */ | |
320 | #define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */ | |
321 | #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */ | |
322 | ||
323 | #if defined(WORDS_BIGENDIAN) | |
324 | #define BYTE_ORDER BIG_ENDIAN | |
d62a17ae | 325 | #else /* !WORDS_BIGENDIAN */ |
34204aac | 326 | #define BYTE_ORDER LITTLE_ENDIAN |
327 | #endif /* WORDS_BIGENDIAN */ | |
328 | ||
329 | #endif /* ndef BYTE_ORDER */ | |
330 | ||
718e3744 | 331 | /* For old definition. */ |
332 | #ifndef IN6_ARE_ADDR_EQUAL | |
333 | #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL | |
334 | #endif /* IN6_ARE_ADDR_EQUAL */ | |
335 | ||
8cc4198f | 336 | /* default zebra TCP port for zclient */ |
337 | #define ZEBRA_PORT 2600 | |
338 | ||
728806e6 DS |
339 | /* |
340 | * The compiler.h header is used for anyone using the CPP_NOTICE | |
341 | * since this is universally needed, let's add it to zebra.h | |
342 | */ | |
343 | #include "compiler.h" | |
344 | ||
e0ca5fde DL |
345 | /* Zebra route's types are defined in route_types.h */ |
346 | #include "route_types.h" | |
718e3744 | 347 | |
bf31fc81 DL |
348 | #define strmatch(a,b) (!strcmp((a), (b))) |
349 | ||
718e3744 | 350 | #ifndef INADDR_LOOPBACK |
351 | #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */ | |
352 | #endif | |
353 | ||
354 | /* Address family numbers from RFC1700. */ | |
b26f891d SW |
355 | typedef enum { |
356 | AFI_UNSPEC = 0, | |
357 | AFI_IP = 1, | |
358 | AFI_IP6 = 2, | |
359 | AFI_L2VPN = 3, | |
360 | AFI_MAX = 4 | |
361 | } afi_t; | |
718e3744 | 362 | |
d35e556c QY |
363 | #define IS_VALID_AFI(a) ((a) > AFI_UNSPEC && (a) < AFI_MAX) |
364 | ||
718e3744 | 365 | /* Subsequent Address Family Identifier. */ |
5c525538 | 366 | typedef enum { |
dc912615 | 367 | SAFI_UNSPEC = 0, |
5c525538 RW |
368 | SAFI_UNICAST = 1, |
369 | SAFI_MULTICAST = 2, | |
370 | SAFI_MPLS_VPN = 3, | |
371 | SAFI_ENCAP = 4, | |
372 | SAFI_EVPN = 5, | |
373 | SAFI_LABELED_UNICAST = 6, | |
b98f7728 PG |
374 | SAFI_FLOWSPEC = 7, |
375 | SAFI_MAX = 8 | |
5c525538 | 376 | } safi_t; |
718e3744 | 377 | |
718e3744 | 378 | /* Default Administrative Distance of each protocol. */ |
379 | #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 | |
380 | #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 | |
381 | #define ZEBRA_STATIC_DISTANCE_DEFAULT 1 | |
382 | #define ZEBRA_RIP_DISTANCE_DEFAULT 120 | |
383 | #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120 | |
384 | #define ZEBRA_OSPF_DISTANCE_DEFAULT 110 | |
385 | #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110 | |
9e867fe6 | 386 | #define ZEBRA_ISIS_DISTANCE_DEFAULT 115 |
718e3744 | 387 | #define ZEBRA_IBGP_DISTANCE_DEFAULT 200 |
388 | #define ZEBRA_EBGP_DISTANCE_DEFAULT 20 | |
7ab5795a | 389 | #define ZEBRA_TABLE_DISTANCE_DEFAULT 15 |
718e3744 | 390 | |
391 | /* Flag manipulation macros. */ | |
392 | #define CHECK_FLAG(V,F) ((V) & (F)) | |
548e6f7d | 393 | #define SET_FLAG(V,F) (V) |= (F) |
394 | #define UNSET_FLAG(V,F) (V) &= ~(F) | |
fb018d25 | 395 | #define RESET_FLAG(V) (V) = 0 |
9fb964de | 396 | #define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F))) |
718e3744 | 397 | |
f765d422 QY |
398 | /* Atomic flag manipulation macros. */ |
399 | #define CHECK_FLAG_ATOMIC(PV, F) \ | |
400 | ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F)) | |
401 | #define SET_FLAG_ATOMIC(PV, F) \ | |
402 | ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst))) | |
403 | #define UNSET_FLAG_ATOMIC(PV, F) \ | |
404 | ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst))) | |
405 | #define RESET_FLAG_ATOMIC(PV) \ | |
406 | ((atomic_store_explicit(PV, 0, memory_order_seq_cst))) | |
407 | ||
b72ede27 | 408 | /* VRF ID type. */ |
a9ff90c4 | 409 | typedef uint32_t vrf_id_t; |
b72ede27 | 410 | |
dc9ffce8 CF |
411 | typedef uint32_t route_tag_t; |
412 | #define ROUTE_TAG_MAX UINT32_MAX | |
413 | #define ROUTE_TAG_PRI PRIu32 | |
414 | ||
718e3744 | 415 | #endif /* _ZEBRA_H */ |