1 /* Zebra common header.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #endif /* HAVE_CONFIG_H */
30 typedef unsigned int u_int32_t
;
31 typedef unsigned short u_int16_t
;
32 typedef unsigned char u_int8_t
;
48 #endif /* HAVE_STROPTS_H */
49 #include <sys/select.h>
51 #include <sys/types.h>
52 #include <sys/param.h>
53 #ifdef HAVE_SYS_SYSCTL_H
55 #include <linux/types.h>
57 #include <sys/sysctl.h>
58 #endif /* HAVE_SYS_SYSCTL_H */
59 #include <sys/ioctl.h>
60 #ifdef HAVE_SYS_CONF_H
62 #endif /* HAVE_SYS_CONF_H */
63 #ifdef HAVE_SYS_KSYM_H
65 #endif /* HAVE_SYS_KSYM_H */
70 #include <sys/utsname.h>
71 #include <sys/resource.h>
76 /* machine dependent includes */
81 /* machine dependent includes */
82 #ifdef HAVE_LINUX_VERSION_H
83 #include <linux/version.h>
84 #endif /* HAVE_LINUX_VERSION_H */
86 #ifdef HAVE_ASM_TYPES_H
87 #include <asm/types.h>
88 #endif /* HAVE_ASM_TYPES_H */
90 /* misc include group */
92 #if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
93 /* Not C99; do we need to define va_copy? */
96 #define va_copy(DST,SRC) __va_copy(DST,SRC)
98 /* Now we are desperate; this should work on many typical platforms.
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 */
109 #include <sys/capability.h>
110 #include <sys/prctl.h>
111 #endif /* HAVE_LCAPS */
113 #ifdef HAVE_SOLARIS_CAPABILITIES
115 #endif /* HAVE_SOLARIS_CAPABILITIES */
117 /* network include group */
119 #include <sys/socket.h>
121 #ifdef HAVE_SYS_SOCKIO_H
122 #include <sys/sockio.h>
123 #endif /* HAVE_SYS_SOCKIO_H */
126 #define __APPLE_USE_RFC_3542
129 #include <netinet/in.h>
130 #include <netinet/in_systm.h>
131 #include <netinet/ip.h>
132 #include <netinet/tcp.h>
134 #ifdef HAVE_NET_NETOPT_H
135 #include <net/netopt.h>
136 #endif /* HAVE_NET_NETOPT_H */
140 #ifdef HAVE_NET_IF_DL_H
141 #include <net/if_dl.h>
142 #endif /* HAVE_NET_IF_DL_H */
144 #ifdef HAVE_NET_IF_VAR_H
145 #include <net/if_var.h>
146 #endif /* HAVE_NET_IF_VAR_H */
148 #include <net/route.h>
151 #include <linux/netlink.h>
152 #include <linux/rtnetlink.h>
153 #include <linux/filter.h>
155 #define RT_TABLE_MAIN 0
156 #endif /* HAVE_NETLINK */
159 #include <arpa/inet.h>
161 #ifdef HAVE_INET_ND_H
163 #endif /* HAVE_INET_ND_H */
165 #ifdef HAVE_NETINET_IN_VAR_H
166 #include <netinet/in_var.h>
167 #endif /* HAVE_NETINET_IN_VAR_H */
169 #ifdef HAVE_NETINET6_IN6_VAR_H
170 #include <netinet6/in6_var.h>
171 #endif /* HAVE_NETINET6_IN6_VAR_H */
173 #ifdef HAVE_NETINET_IN6_VAR_H
174 #include <netinet/in6_var.h>
175 #endif /* HAVE_NETINET_IN6_VAR_H */
177 #ifdef HAVE_NETINET6_IN_H
178 #include <netinet6/in.h>
179 #endif /* HAVE_NETINET6_IN_H */
182 #ifdef HAVE_NETINET6_IP6_H
183 #include <netinet6/ip6.h>
184 #endif /* HAVE_NETINET6_IP6_H */
186 #include <netinet/icmp6.h>
188 #ifdef HAVE_NETINET6_ND6_H
189 #include <netinet6/nd6.h>
190 #endif /* HAVE_NETINET6_ND6_H */
192 /* Some systems do not define UINT32_MAX, etc.. from inttypes.h
193 * e.g. this makes life easier for FBSD 4.11 users.
196 #define INT8_MAX (127)
199 #define INT16_MAX (32767)
202 #define INT32_MAX (2147483647)
205 #define UINT8_MAX (255U)
208 #define UINT16_MAX (65535U)
211 #define UINT32_MAX (4294967295U)
214 #ifdef HAVE_GLIBC_BACKTRACE
215 #include <execinfo.h>
216 #endif /* HAVE_GLIBC_BACKTRACE */
218 /* Local includes: */
219 #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
220 #define __attribute__(x)
221 #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
226 size_t strlcat (char *__restrict dest
, const char *__restrict src
, size_t size
);
229 size_t strlcpy (char *__restrict dest
, const char *__restrict src
, size_t size
);
232 #ifdef HAVE_BROKEN_CMSG_FIRSTHDR
233 /* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
234 please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
236 /* Check that msg_controllen is large enough. */
237 #define ZCMSG_FIRSTHDR(mhdr) \
238 (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \
239 CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL)
241 #warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
243 #else /* HAVE_BROKEN_CMSG_FIRSTHDR */
244 #define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
245 #endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
250 * RFC 3542 defines several macros for using struct cmsghdr.
251 * Here, we define those that are not present
255 * Internal defines, for use only in this file.
256 * These are likely wrong on other than ILP32 machines, so warn.
258 #ifndef _CMSG_DATA_ALIGN
259 #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
260 #endif /* _CMSG_DATA_ALIGN */
262 #ifndef _CMSG_HDR_ALIGN
263 #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
264 #endif /* _CMSG_HDR_ALIGN */
267 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
271 #define CMSG_SPACE(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \
273 #warning "assuming 4-byte alignment for CMSG_SPACE"
274 #endif /* CMSG_SPACE */
278 #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
279 #warning "assuming 4-byte alignment for CMSG_LEN"
280 #endif /* CMSG_LEN */
283 /* The definition of struct in_pktinfo is missing in old version of
284 GLIBC 2.1 (Redhat 6.1). */
285 #if defined (GNU_LINUX) && ! defined (HAVE_STRUCT_IN_PKTINFO)
289 struct in_addr ipi_spec_dst
;
290 struct in_addr ipi_addr
;
295 * IP_HDRINCL / struct ip byte order
297 * Linux: network byte order
298 * *BSD: network, except for length and offset. (cf Stevens)
299 * SunOS: nominally as per BSD. but bug: network order on LE.
300 * OpenBSD: network byte order, apart from older versions which are as per
303 #if defined(__NetBSD__) \
304 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
305 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
306 || (defined(__APPLE__)) \
307 || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
308 #define HAVE_IP_HDRINCL_BSD_ORDER
311 /* Define BYTE_ORDER, if not defined. Useful for compiler conditional
312 * code, rather than preprocessor conditional.
313 * Not all the world has this BSD define.
316 #define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */
317 #define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */
318 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
320 #if defined(WORDS_BIGENDIAN)
321 #define BYTE_ORDER BIG_ENDIAN
322 #else /* !WORDS_BIGENDIAN */
323 #define BYTE_ORDER LITTLE_ENDIAN
324 #endif /* WORDS_BIGENDIAN */
326 #endif /* ndef BYTE_ORDER */
328 /* MAX / MIN are not commonly defined, but useful */
329 /* note: glibc sys/param.h has #define MIN(a,b) (((a)<(b))?(a):(b)) */
334 ({ typeof (a) _a = (a); \
335 typeof (b) _b = (b); \
336 _a > _b ? _a : _b; })
341 ({ typeof (a) _a = (a); \
342 typeof (b) _b = (b); \
343 _a < _b ? _a : _b; })
345 #define ZEBRA_NUM_OF(x) (sizeof (x) / sizeof (x[0]))
347 /* For old definition. */
348 #ifndef IN6_ARE_ADDR_EQUAL
349 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
350 #endif /* IN6_ARE_ADDR_EQUAL */
352 /* default zebra TCP port for zclient */
353 #define ZEBRA_PORT 2600
355 /* Zebra message types. */
358 ZEBRA_INTERFACE_DELETE
,
359 ZEBRA_INTERFACE_ADDRESS_ADD
,
360 ZEBRA_INTERFACE_ADDRESS_DELETE
,
362 ZEBRA_INTERFACE_DOWN
,
363 ZEBRA_IPV4_ROUTE_ADD
,
364 ZEBRA_IPV4_ROUTE_DELETE
,
365 ZEBRA_IPV6_ROUTE_ADD
,
366 ZEBRA_IPV6_ROUTE_DELETE
,
367 ZEBRA_REDISTRIBUTE_ADD
,
368 ZEBRA_REDISTRIBUTE_DELETE
,
369 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
370 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
372 ZEBRA_ROUTER_ID_DELETE
,
373 ZEBRA_ROUTER_ID_UPDATE
,
375 ZEBRA_NEXTHOP_REGISTER
,
376 ZEBRA_NEXTHOP_UNREGISTER
,
377 ZEBRA_NEXTHOP_UPDATE
,
378 ZEBRA_INTERFACE_NBR_ADDRESS_ADD
,
379 ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
,
380 ZEBRA_INTERFACE_BFD_DEST_UPDATE
,
381 ZEBRA_IMPORT_ROUTE_REGISTER
,
382 ZEBRA_IMPORT_ROUTE_UNREGISTER
,
383 ZEBRA_IMPORT_CHECK_UPDATE
,
384 ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
,
385 ZEBRA_BFD_DEST_REGISTER
,
386 ZEBRA_BFD_DEST_DEREGISTER
,
387 ZEBRA_BFD_DEST_UPDATE
,
388 ZEBRA_BFD_DEST_REPLAY
,
389 ZEBRA_REDISTRIBUTE_IPV4_ADD
,
390 ZEBRA_REDISTRIBUTE_IPV4_DEL
,
391 ZEBRA_REDISTRIBUTE_IPV6_ADD
,
392 ZEBRA_REDISTRIBUTE_IPV6_DEL
,
393 ZEBRA_VRF_UNREGISTER
,
396 ZEBRA_INTERFACE_VRF_UPDATE
,
397 ZEBRA_BFD_CLIENT_REGISTER
,
398 ZEBRA_INTERFACE_ENABLE_RADV
,
399 ZEBRA_INTERFACE_DISABLE_RADV
,
400 ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB
,
401 ZEBRA_INTERFACE_LINK_PARAMS
,
402 ZEBRA_MPLS_LABELS_ADD
,
403 ZEBRA_MPLS_LABELS_DELETE
,
404 ZEBRA_IPV4_NEXTHOP_ADD
,
405 ZEBRA_IPV4_NEXTHOP_DELETE
,
406 ZEBRA_IPV6_NEXTHOP_ADD
,
407 ZEBRA_IPV6_NEXTHOP_DELETE
,
408 } zebra_message_types_t
;
410 /* Marker value used in new Zserv, in the byte location corresponding
411 * the command value in the old zserv header. To allow old and new
412 * Zserv headers to be distinguished from each other.
414 #define ZEBRA_HEADER_MARKER 254
416 /* Zebra route's types are defined in route_types.h */
417 #include "route_types.h"
419 /* Note: whenever a new route-type or zserv-command is added the
420 * corresponding {command,route}_types[] table in lib/log.c MUST be
423 /* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
424 extern const char *zebra_route_string(unsigned int route_type
);
425 /* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
426 extern char zebra_route_char(unsigned int route_type
);
427 /* Map a zserv command type to the same string,
428 * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
429 /* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
430 extern int proto_name2num(const char *s
);
431 /* Map redistribute X argument to protocol number.
432 * unlike proto_name2num, this accepts shorthands and takes
433 * an AFI value to restrict input */
434 extern int proto_redistnum(int afi
, const char *s
);
436 extern const char *zserv_command_string (unsigned int command
);
438 /* Error codes of zebra. */
439 #define ZEBRA_ERR_NOERROR 0
440 #define ZEBRA_ERR_RTEXIST -1
441 #define ZEBRA_ERR_RTUNREACH -2
442 #define ZEBRA_ERR_EPERM -3
443 #define ZEBRA_ERR_RTNOEXIST -4
444 #define ZEBRA_ERR_KERNEL -5
446 /* Zebra message flags */
447 #define ZEBRA_FLAG_INTERNAL 0x01
448 #define ZEBRA_FLAG_SELFROUTE 0x02
449 #define ZEBRA_FLAG_BLACKHOLE 0x04
450 #define ZEBRA_FLAG_IBGP 0x08
451 #define ZEBRA_FLAG_SELECTED 0x10
452 #define ZEBRA_FLAG_STATIC 0x40
453 #define ZEBRA_FLAG_REJECT 0x80
454 #define ZEBRA_FLAG_SCOPE_LINK 0x100
455 #define ZEBRA_FLAG_FIB_OVERRIDE 0x200
457 #ifndef INADDR_LOOPBACK
458 #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
461 /* Address family numbers from RFC1700. */
465 AFI_ETHER
= 3, /* RFC 1700 has "6" for 802.* */
469 /* Subsequent Address Family Identifier. */
470 #define SAFI_UNICAST 1
471 #define SAFI_MULTICAST 2
472 #define SAFI_RESERVED_3 3
473 #define SAFI_MPLS_VPN 4
474 #define SAFI_ENCAP 7 /* per IANA */
477 /* Default Administrative Distance of each protocol. */
478 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
479 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
480 #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
481 #define ZEBRA_RIP_DISTANCE_DEFAULT 120
482 #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
483 #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
484 #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
485 #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
486 #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
487 #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
488 #define ZEBRA_TABLE_DISTANCE_DEFAULT 15
490 /* Flag manipulation macros. */
491 #define CHECK_FLAG(V,F) ((V) & (F))
492 #define SET_FLAG(V,F) (V) |= (F)
493 #define UNSET_FLAG(V,F) (V) &= ~(F)
494 #define RESET_FLAG(V) (V) = 0
496 typedef u_int8_t safi_t
;
498 /* Zebra types. Used in Zserv message header. */
499 typedef u_int16_t zebra_size_t
;
500 typedef u_int16_t zebra_command_t
;
503 typedef u_int16_t vrf_id_t
;
505 typedef uint32_t route_tag_t
;
506 #define ROUTE_TAG_MAX UINT32_MAX
507 #define ROUTE_TAG_PRI PRIu32
509 #endif /* _ZEBRA_H */