zebra.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /* Zebra common header.
  2. Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
  3. Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
  4. This file is part of GNU Zebra.
  5. GNU Zebra is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option) any
  8. later version.
  9. GNU Zebra is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Zebra; see the file COPYING. If not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. 02111-1307, USA. */
  17. #ifndef _ZEBRA_H
  18. #define _ZEBRA_H
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif /* HAVE_CONFIG_H */
  22. #ifdef SUNOS_5
  23. #define _XPG4_2
  24. #define __EXTENSIONS__
  25. typedef unsigned int u_int32_t;
  26. typedef unsigned short u_int16_t;
  27. typedef unsigned char u_int8_t;
  28. #endif /* SUNOS_5 */
  29. #ifndef HAVE_SOCKLEN_T
  30. typedef int socklen_t;
  31. #endif /* HAVE_SOCKLEN_T */
  32. #include <unistd.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <stddef.h>
  36. #include <ctype.h>
  37. #include <errno.h>
  38. #include <fcntl.h>
  39. #include <signal.h>
  40. #include <string.h>
  41. #include <pwd.h>
  42. #include <grp.h>
  43. #ifdef HAVE_STROPTS_H
  44. #include <stropts.h>
  45. #endif /* HAVE_STROPTS_H */
  46. #ifdef HAVE_SYS_SELECT_H
  47. #include <sys/select.h>
  48. #endif /* HAVE_SYS_SELECT_H */
  49. #include <sys/stat.h>
  50. #include <sys/types.h>
  51. #include <sys/param.h>
  52. #ifdef HAVE_SYS_SYSCTL_H
  53. #ifdef GNU_LINUX
  54. #include <linux/types.h>
  55. #endif
  56. #include <sys/sysctl.h>
  57. #endif /* HAVE_SYS_SYSCTL_H */
  58. #include <sys/ioctl.h>
  59. #ifdef HAVE_SYS_CONF_H
  60. #include <sys/conf.h>
  61. #endif /* HAVE_SYS_CONF_H */
  62. #ifdef HAVE_SYS_KSYM_H
  63. #include <sys/ksym.h>
  64. #endif /* HAVE_SYS_KSYM_H */
  65. #include <syslog.h>
  66. #ifdef TIME_WITH_SYS_TIME
  67. # include <sys/time.h>
  68. # include <time.h>
  69. #else
  70. # ifdef HAVE_SYS_TIME_H
  71. # include <sys/time.h>
  72. # else
  73. # include <time.h>
  74. # endif
  75. #endif /* TIME_WITH_SYS_TIME */
  76. #include <sys/uio.h>
  77. #include <sys/utsname.h>
  78. #ifdef HAVE_RUSAGE
  79. #include <sys/resource.h>
  80. #endif /* HAVE_RUSAGE */
  81. #ifdef HAVE_LIMITS_H
  82. #include <limits.h>
  83. #endif /* HAVE_LIMITS_H */
  84. #ifdef HAVE_INTTYPES_H
  85. #include <inttypes.h>
  86. #endif /* HAVE_INTTYPES_H */
  87. /* machine dependent includes */
  88. #ifdef SUNOS_5
  89. #include <strings.h>
  90. #endif /* SUNOS_5 */
  91. /* machine dependent includes */
  92. #ifdef HAVE_LINUX_VERSION_H
  93. #include <linux/version.h>
  94. #endif /* HAVE_LINUX_VERSION_H */
  95. #ifdef HAVE_ASM_TYPES_H
  96. #include <asm/types.h>
  97. #endif /* HAVE_ASM_TYPES_H */
  98. /* misc include group */
  99. #include <stdarg.h>
  100. #if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
  101. /* Not C99; do we need to define va_copy? */
  102. #ifndef va_copy
  103. #ifdef __va_copy
  104. #define va_copy(DST,SRC) __va_copy(DST,SRC)
  105. #else
  106. /* Now we are desperate; this should work on many typical platforms.
  107. But this is slightly dangerous, because the standard does not require
  108. va_copy to be a macro. */
  109. #define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list))
  110. #warning "Not C99 and no va_copy macro available, falling back to memcpy"
  111. #endif /* __va_copy */
  112. #endif /* !va_copy */
  113. #endif /* !C99 */
  114. #ifdef HAVE_LCAPS
  115. #include <sys/capability.h>
  116. #include <sys/prctl.h>
  117. #endif /* HAVE_LCAPS */
  118. #ifdef HAVE_SOLARIS_CAPABILITIES
  119. #include <priv.h>
  120. #endif /* HAVE_SOLARIS_CAPABILITIES */
  121. /* network include group */
  122. #include <sys/socket.h>
  123. #ifdef HAVE_SYS_SOCKIO_H
  124. #include <sys/sockio.h>
  125. #endif /* HAVE_SYS_SOCKIO_H */
  126. #ifdef __APPLE__
  127. #define __APPLE_USE_RFC_3542
  128. #endif
  129. #ifdef HAVE_NETINET_IN_H
  130. #include <netinet/in.h>
  131. #endif /* HAVE_NETINET_IN_H */
  132. #include <netinet/in_systm.h>
  133. #include <netinet/ip.h>
  134. #include <netinet/tcp.h>
  135. #ifdef HAVE_NET_NETOPT_H
  136. #include <net/netopt.h>
  137. #endif /* HAVE_NET_NETOPT_H */
  138. #include <net/if.h>
  139. #ifdef HAVE_NET_IF_DL_H
  140. #include <net/if_dl.h>
  141. #endif /* HAVE_NET_IF_DL_H */
  142. #ifdef HAVE_NET_IF_VAR_H
  143. #include <net/if_var.h>
  144. #endif /* HAVE_NET_IF_VAR_H */
  145. #ifdef HAVE_NET_ROUTE_H
  146. #include <net/route.h>
  147. #endif /* HAVE_NET_ROUTE_H */
  148. #ifdef HAVE_NETLINK
  149. #include <linux/netlink.h>
  150. #include <linux/rtnetlink.h>
  151. #include <linux/filter.h>
  152. #else
  153. #define RT_TABLE_MAIN 0
  154. #endif /* HAVE_NETLINK */
  155. #ifdef HAVE_NETDB_H
  156. #include <netdb.h>
  157. #endif /* HAVE_NETDB_H */
  158. #include <arpa/inet.h>
  159. #ifdef HAVE_INET_ND_H
  160. #include <inet/nd.h>
  161. #endif /* HAVE_INET_ND_H */
  162. #ifdef HAVE_NETINET_IN_VAR_H
  163. #include <netinet/in_var.h>
  164. #endif /* HAVE_NETINET_IN_VAR_H */
  165. #ifdef HAVE_NETINET6_IN6_VAR_H
  166. #include <netinet6/in6_var.h>
  167. #endif /* HAVE_NETINET6_IN6_VAR_H */
  168. #ifdef HAVE_NETINET_IN6_VAR_H
  169. #include <netinet/in6_var.h>
  170. #endif /* HAVE_NETINET_IN6_VAR_H */
  171. #ifdef HAVE_NETINET6_IN_H
  172. #include <netinet6/in.h>
  173. #endif /* HAVE_NETINET6_IN_H */
  174. #ifdef HAVE_NETINET6_IP6_H
  175. #include <netinet6/ip6.h>
  176. #endif /* HAVE_NETINET6_IP6_H */
  177. #ifdef HAVE_NETINET_ICMP6_H
  178. #include <netinet/icmp6.h>
  179. #endif /* HAVE_NETINET_ICMP6_H */
  180. #ifdef HAVE_NETINET6_ND6_H
  181. #include <netinet6/nd6.h>
  182. #endif /* HAVE_NETINET6_ND6_H */
  183. /* Some systems do not define UINT32_MAX, etc.. from inttypes.h
  184. * e.g. this makes life easier for FBSD 4.11 users.
  185. */
  186. #ifndef INT8_MAX
  187. #define INT8_MAX (127)
  188. #endif
  189. #ifndef INT16_MAX
  190. #define INT16_MAX (32767)
  191. #endif
  192. #ifndef INT32_MAX
  193. #define INT32_MAX (2147483647)
  194. #endif
  195. #ifndef UINT8_MAX
  196. #define UINT8_MAX (255U)
  197. #endif
  198. #ifndef UINT16_MAX
  199. #define UINT16_MAX (65535U)
  200. #endif
  201. #ifndef UINT32_MAX
  202. #define UINT32_MAX (4294967295U)
  203. #endif
  204. #ifdef HAVE_GLIBC_BACKTRACE
  205. #include <execinfo.h>
  206. #endif /* HAVE_GLIBC_BACKTRACE */
  207. #ifdef BSDI_NRL
  208. #ifdef HAVE_NETINET6_IN6_H
  209. #include <netinet6/in6.h>
  210. #endif /* HAVE_NETINET6_IN6_H */
  211. #ifdef NRL
  212. #include <netinet6/in6.h>
  213. #endif /* NRL */
  214. #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
  215. #endif /* BSDI_NRL */
  216. /* Local includes: */
  217. #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
  218. #define __attribute__(x)
  219. #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
  220. #include "zassert.h"
  221. #include "str.h"
  222. #ifdef HAVE_BROKEN_CMSG_FIRSTHDR
  223. /* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
  224. please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
  225. /* Check that msg_controllen is large enough. */
  226. #define ZCMSG_FIRSTHDR(mhdr) \
  227. (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \
  228. CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL)
  229. #warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
  230. #else /* HAVE_BROKEN_CMSG_FIRSTHDR */
  231. #define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
  232. #endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
  233. /*
  234. * RFC 3542 defines several macros for using struct cmsghdr.
  235. * Here, we define those that are not present
  236. */
  237. /*
  238. * Internal defines, for use only in this file.
  239. * These are likely wrong on other than ILP32 machines, so warn.
  240. */
  241. #ifndef _CMSG_DATA_ALIGN
  242. #define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
  243. #endif /* _CMSG_DATA_ALIGN */
  244. #ifndef _CMSG_HDR_ALIGN
  245. #define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
  246. #endif /* _CMSG_HDR_ALIGN */
  247. /*
  248. * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
  249. * version.
  250. */
  251. #ifndef CMSG_SPACE
  252. #define CMSG_SPACE(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \
  253. _CMSG_HDR_ALIGN(l))
  254. #warning "assuming 4-byte alignment for CMSG_SPACE"
  255. #endif /* CMSG_SPACE */
  256. #ifndef CMSG_LEN
  257. #define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
  258. #warning "assuming 4-byte alignment for CMSG_LEN"
  259. #endif /* CMSG_LEN */
  260. /* The definition of struct in_pktinfo is missing in old version of
  261. GLIBC 2.1 (Redhat 6.1). */
  262. #if defined (GNU_LINUX) && ! defined (HAVE_STRUCT_IN_PKTINFO)
  263. struct in_pktinfo
  264. {
  265. int ipi_ifindex;
  266. struct in_addr ipi_spec_dst;
  267. struct in_addr ipi_addr;
  268. };
  269. #endif
  270. /*
  271. * OSPF Fragmentation / fragmented writes
  272. *
  273. * ospfd can support writing fragmented packets, for cases where
  274. * kernel will not fragment IP_HDRINCL and/or multicast destined
  275. * packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However,
  276. * SunOS, probably BSD too, clobber the user supplied IP ID and IP
  277. * flags fields, hence user-space fragmentation will not work.
  278. * Only Linux is known to leave IP header unmolested.
  279. * Further, fragmentation really should be done the kernel, which already
  280. * supports it, and which avoids nasty IP ID state problems.
  281. *
  282. * Fragmentation of OSPF packets can be required on networks with router
  283. * with many many interfaces active in one area, or on networks with links
  284. * with low MTUs.
  285. */
  286. #ifdef GNU_LINUX
  287. #define WANT_OSPF_WRITE_FRAGMENT
  288. #endif
  289. /*
  290. * IP_HDRINCL / struct ip byte order
  291. *
  292. * Linux: network byte order
  293. * *BSD: network, except for length and offset. (cf Stevens)
  294. * SunOS: nominally as per BSD. but bug: network order on LE.
  295. * OpenBSD: network byte order, apart from older versions which are as per
  296. * *BSD
  297. */
  298. #if defined(__NetBSD__) \
  299. || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
  300. || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
  301. || (defined(__APPLE__)) \
  302. || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
  303. #define HAVE_IP_HDRINCL_BSD_ORDER
  304. #endif
  305. /* Define BYTE_ORDER, if not defined. Useful for compiler conditional
  306. * code, rather than preprocessor conditional.
  307. * Not all the world has this BSD define.
  308. */
  309. #ifndef BYTE_ORDER
  310. #define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */
  311. #define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */
  312. #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
  313. #if defined(WORDS_BIGENDIAN)
  314. #define BYTE_ORDER BIG_ENDIAN
  315. #else /* !WORDS_BIGENDIAN */
  316. #define BYTE_ORDER LITTLE_ENDIAN
  317. #endif /* WORDS_BIGENDIAN */
  318. #endif /* ndef BYTE_ORDER */
  319. /* MAX / MIN are not commonly defined, but useful */
  320. #ifndef MAX
  321. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  322. #endif
  323. #ifndef MIN
  324. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  325. #endif
  326. #define ZEBRA_NUM_OF(x) (sizeof (x) / sizeof (x[0]))
  327. /* For old definition. */
  328. #ifndef IN6_ARE_ADDR_EQUAL
  329. #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
  330. #endif /* IN6_ARE_ADDR_EQUAL */
  331. /* default zebra TCP port for zclient */
  332. #define ZEBRA_PORT 2600
  333. /* Zebra message types. */
  334. #define ZEBRA_INTERFACE_ADD 1
  335. #define ZEBRA_INTERFACE_DELETE 2
  336. #define ZEBRA_INTERFACE_ADDRESS_ADD 3
  337. #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
  338. #define ZEBRA_INTERFACE_UP 5
  339. #define ZEBRA_INTERFACE_DOWN 6
  340. #define ZEBRA_IPV4_ROUTE_ADD 7
  341. #define ZEBRA_IPV4_ROUTE_DELETE 8
  342. #define ZEBRA_IPV6_ROUTE_ADD 9
  343. #define ZEBRA_IPV6_ROUTE_DELETE 10
  344. #define ZEBRA_REDISTRIBUTE_ADD 11
  345. #define ZEBRA_REDISTRIBUTE_DELETE 12
  346. #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
  347. #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
  348. #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
  349. #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
  350. #define ZEBRA_IPV4_IMPORT_LOOKUP 17
  351. #define ZEBRA_IPV6_IMPORT_LOOKUP 18
  352. #define ZEBRA_INTERFACE_RENAME 19
  353. #define ZEBRA_ROUTER_ID_ADD 20
  354. #define ZEBRA_ROUTER_ID_DELETE 21
  355. #define ZEBRA_ROUTER_ID_UPDATE 22
  356. #define ZEBRA_HELLO 23
  357. #define ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB 24
  358. #define ZEBRA_MESSAGE_MAX 25
  359. /* Marker value used in new Zserv, in the byte location corresponding
  360. * the command value in the old zserv header. To allow old and new
  361. * Zserv headers to be distinguished from each other.
  362. */
  363. #define ZEBRA_HEADER_MARKER 255
  364. /* Zebra route's types. */
  365. #define ZEBRA_ROUTE_SYSTEM 0
  366. #define ZEBRA_ROUTE_KERNEL 1
  367. #define ZEBRA_ROUTE_CONNECT 2
  368. #define ZEBRA_ROUTE_STATIC 3
  369. #define ZEBRA_ROUTE_RIP 4
  370. #define ZEBRA_ROUTE_RIPNG 5
  371. #define ZEBRA_ROUTE_OSPF 6
  372. #define ZEBRA_ROUTE_OSPF6 7
  373. #define ZEBRA_ROUTE_ISIS 8
  374. #define ZEBRA_ROUTE_BGP 9
  375. #define ZEBRA_ROUTE_HSLS 10
  376. #define ZEBRA_ROUTE_PIM 11
  377. #define ZEBRA_ROUTE_MAX 12
  378. /* Note: whenever a new route-type or zserv-command is added the
  379. * corresponding {command,route}_types[] table in lib/log.c MUST be
  380. * updated! */
  381. /* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
  382. extern const char *zebra_route_string(unsigned int route_type);
  383. /* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
  384. extern char zebra_route_char(unsigned int route_type);
  385. /* Map a zserv command type to the same string,
  386. * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
  387. /* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
  388. extern int proto_name2num(const char *s);
  389. /* Map redistribute X argument to protocol number.
  390. * unlike proto_name2num, this accepts shorthands and takes
  391. * an AFI value to restrict input */
  392. extern int proto_redistnum(int afi, const char *s);
  393. extern const char *zserv_command_string (unsigned int command);
  394. /* Zebra's family types. */
  395. #define ZEBRA_FAMILY_IPV4 1
  396. #define ZEBRA_FAMILY_IPV6 2
  397. #define ZEBRA_FAMILY_MAX 3
  398. /* Error codes of zebra. */
  399. #define ZEBRA_ERR_NOERROR 0
  400. #define ZEBRA_ERR_RTEXIST -1
  401. #define ZEBRA_ERR_RTUNREACH -2
  402. #define ZEBRA_ERR_EPERM -3
  403. #define ZEBRA_ERR_RTNOEXIST -4
  404. #define ZEBRA_ERR_KERNEL -5
  405. /* Zebra message flags */
  406. #define ZEBRA_FLAG_INTERNAL 0x01
  407. #define ZEBRA_FLAG_SELFROUTE 0x02
  408. #define ZEBRA_FLAG_BLACKHOLE 0x04
  409. #define ZEBRA_FLAG_IBGP 0x08
  410. #define ZEBRA_FLAG_SELECTED 0x10
  411. #define ZEBRA_FLAG_CHANGED 0x20
  412. #define ZEBRA_FLAG_STATIC 0x40
  413. #define ZEBRA_FLAG_REJECT 0x80
  414. /* Zebra nexthop flags. */
  415. #define ZEBRA_NEXTHOP_IFINDEX 1
  416. #define ZEBRA_NEXTHOP_IFNAME 2
  417. #define ZEBRA_NEXTHOP_IPV4 3
  418. #define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
  419. #define ZEBRA_NEXTHOP_IPV4_IFNAME 5
  420. #define ZEBRA_NEXTHOP_IPV6 6
  421. #define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
  422. #define ZEBRA_NEXTHOP_IPV6_IFNAME 8
  423. #define ZEBRA_NEXTHOP_BLACKHOLE 9
  424. #ifndef INADDR_LOOPBACK
  425. #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
  426. #endif
  427. /* Address family numbers from RFC1700. */
  428. #define AFI_IP 1
  429. #define AFI_IP6 2
  430. #define AFI_MAX 3
  431. /* Subsequent Address Family Identifier. */
  432. #define SAFI_UNICAST 1
  433. #define SAFI_MULTICAST 2
  434. #define SAFI_RESERVED_3 3
  435. #define SAFI_MPLS_VPN 4
  436. #define SAFI_MAX 5
  437. /* Filter direction. */
  438. #define FILTER_IN 0
  439. #define FILTER_OUT 1
  440. #define FILTER_MAX 2
  441. /* Default Administrative Distance of each protocol. */
  442. #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
  443. #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
  444. #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
  445. #define ZEBRA_RIP_DISTANCE_DEFAULT 120
  446. #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
  447. #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
  448. #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
  449. #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
  450. #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
  451. #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
  452. /* Flag manipulation macros. */
  453. #define CHECK_FLAG(V,F) ((V) & (F))
  454. #define SET_FLAG(V,F) (V) |= (F)
  455. #define UNSET_FLAG(V,F) (V) &= ~(F)
  456. /* AFI and SAFI type. */
  457. typedef u_int16_t afi_t;
  458. typedef u_int8_t safi_t;
  459. /* Zebra types. Used in Zserv message header. */
  460. typedef u_int16_t zebra_size_t;
  461. typedef u_int16_t zebra_command_t;
  462. /* FIFO -- first in first out structure and macros. */
  463. struct fifo
  464. {
  465. struct fifo *next;
  466. struct fifo *prev;
  467. };
  468. #define FIFO_INIT(F) \
  469. do { \
  470. struct fifo *Xfifo = (struct fifo *)(F); \
  471. Xfifo->next = Xfifo->prev = Xfifo; \
  472. } while (0)
  473. #define FIFO_ADD(F,N) \
  474. do { \
  475. struct fifo *Xfifo = (struct fifo *)(F); \
  476. struct fifo *Xnode = (struct fifo *)(N); \
  477. Xnode->next = Xfifo; \
  478. Xnode->prev = Xfifo->prev; \
  479. Xfifo->prev = Xfifo->prev->next = Xnode; \
  480. } while (0)
  481. #define FIFO_DEL(N) \
  482. do { \
  483. struct fifo *Xnode = (struct fifo *)(N); \
  484. Xnode->prev->next = Xnode->next; \
  485. Xnode->next->prev = Xnode->prev; \
  486. } while (0)
  487. #define FIFO_HEAD(F) \
  488. ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
  489. ? NULL : (F)->next)
  490. #define FIFO_EMPTY(F) \
  491. (((struct fifo *)(F))->next == (struct fifo *)(F))
  492. #define FIFO_TOP(F) \
  493. (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
  494. #endif /* _ZEBRA_H */