zebra.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /* Zebra common header.
  2. Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef _ZEBRA_H
  17. #define _ZEBRA_H
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif /* HAVE_CONFIG_H */
  21. #ifdef SUNOS_5
  22. #define _XPG4_2
  23. #define __EXTENSIONS__
  24. typedef unsigned int u_int32_t;
  25. typedef unsigned short u_int16_t;
  26. typedef unsigned char u_int8_t;
  27. #endif /* SUNOS_5 */
  28. #ifndef HAVE_SOCKLEN_T
  29. typedef int socklen_t;
  30. #endif /* HAVE_SOCKLEN_T */
  31. #include <unistd.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <ctype.h>
  35. #include <errno.h>
  36. #include <fcntl.h>
  37. #include <signal.h>
  38. #include <string.h>
  39. #include <pwd.h>
  40. #include <grp.h>
  41. #ifdef HAVE_STROPTS_H
  42. #include <stropts.h>
  43. #endif /* HAVE_STROPTS_H */
  44. #include <sys/fcntl.h>
  45. #ifdef HAVE_SYS_SELECT_H
  46. #include <sys/select.h>
  47. #endif /* HAVE_SYS_SELECT_H */
  48. #include <sys/stat.h>
  49. #include <sys/time.h>
  50. #include <sys/types.h>
  51. #include <sys/param.h>
  52. #ifdef HAVE_SYS_SYSCTL_H
  53. #include <sys/sysctl.h>
  54. #endif /* HAVE_SYS_SYSCTL_H */
  55. #include <sys/ioctl.h>
  56. #ifdef HAVE_SYS_CONF_H
  57. #include <sys/conf.h>
  58. #endif /* HAVE_SYS_CONF_H */
  59. #ifdef HAVE_SYS_KSYM_H
  60. #include <sys/ksym.h>
  61. #endif /* HAVE_SYS_KSYM_H */
  62. #include <syslog.h>
  63. #include <time.h>
  64. #include <sys/uio.h>
  65. #include <sys/utsname.h>
  66. #ifdef HAVE_RUSAGE
  67. #include <sys/resource.h>
  68. #endif /* HAVE_RUSAGE */
  69. #ifdef HAVE_LIMITS_H
  70. #include <limits.h>
  71. #endif /* HAVE_LIMITS_H */
  72. /* machine dependent includes */
  73. #ifdef SUNOS_5
  74. #include <strings.h>
  75. #endif /* SUNOS_5 */
  76. /* machine dependent includes */
  77. #ifdef HAVE_LINUX_VERSION_H
  78. #include <linux/version.h>
  79. #endif /* HAVE_LINUX_VERSION_H */
  80. #ifdef HAVE_ASM_TYPES_H
  81. #include <asm/types.h>
  82. #endif /* HAVE_ASM_TYPES_H */
  83. /* misc include group */
  84. #include <stdarg.h>
  85. #include <assert.h>
  86. #ifdef HAVE_LCAPS
  87. #include <sys/capability.h>
  88. #include <sys/prctl.h>
  89. #endif /* HAVE_LCAPS */
  90. /* network include group */
  91. #include <sys/socket.h>
  92. #ifdef HAVE_SYS_SOCKIO_H
  93. #include <sys/sockio.h>
  94. #endif /* HAVE_SYS_SOCKIO_H */
  95. #ifdef HAVE_NETINET_IN_H
  96. #include <netinet/in.h>
  97. #endif /* HAVE_NETINET_IN_H */
  98. #include <netinet/in_systm.h>
  99. #include <netinet/ip.h>
  100. #include <netinet/tcp.h>
  101. #ifdef HAVE_NET_NETOPT_H
  102. #include <net/netopt.h>
  103. #endif /* HAVE_NET_NETOPT_H */
  104. #include <net/if.h>
  105. #ifdef HAVE_NET_IF_DL_H
  106. #include <net/if_dl.h>
  107. #endif /* HAVE_NET_IF_DL_H */
  108. #ifdef HAVE_NET_IF_VAR_H
  109. #include <net/if_var.h>
  110. #endif /* HAVE_NET_IF_VAR_H */
  111. #ifdef HAVE_NET_ROUTE_H
  112. #include <net/route.h>
  113. #endif /* HAVE_NET_ROUTE_H */
  114. #ifdef HAVE_NETLINK
  115. #include <linux/netlink.h>
  116. #include <linux/rtnetlink.h>
  117. #else
  118. #define RT_TABLE_MAIN 0
  119. #endif /* HAVE_NETLINK */
  120. #ifdef HAVE_NETDB_H
  121. #include <netdb.h>
  122. #endif /* HAVE_NETDB_H */
  123. #include <arpa/inet.h>
  124. #include <arpa/telnet.h>
  125. #ifdef HAVE_INET_ND_H
  126. #include <inet/nd.h>
  127. #endif /* HAVE_INET_ND_H */
  128. #ifdef HAVE_NETINET_IN_VAR_H
  129. #include <netinet/in_var.h>
  130. #endif /* HAVE_NETINET_IN_VAR_H */
  131. #ifdef HAVE_NETINET6_IN6_VAR_H
  132. #include <netinet6/in6_var.h>
  133. #endif /* HAVE_NETINET6_IN6_VAR_H */
  134. #ifdef HAVE_NETINET_IN6_VAR_H
  135. #include <netinet/in6_var.h>
  136. #endif /* HAVE_NETINET_IN6_VAR_H */
  137. #ifdef HAVE_NETINET6_IN_H
  138. #include <netinet6/in.h>
  139. #endif /* HAVE_NETINET6_IN_H */
  140. #ifdef HAVE_NETINET6_IP6_H
  141. #include <netinet6/ip6.h>
  142. #endif /* HAVE_NETINET6_IP6_H */
  143. #ifdef HAVE_NETINET_ICMP6_H
  144. #include <netinet/icmp6.h>
  145. #endif /* HAVE_NETINET_ICMP6_H */
  146. #ifdef HAVE_NETINET6_ND6_H
  147. #include <netinet6/nd6.h>
  148. #endif /* HAVE_NETINET6_ND6_H */
  149. /* Some systems do not define UINT32_MAX */
  150. #ifndef UINT32_MAX
  151. #define UINT32_MAX 0xFFFFFFFFU
  152. #endif /* UINT32_MAX */
  153. #ifdef HAVE_LIBUTIL_H
  154. #include <libutil.h>
  155. #endif /* HAVE_LIBUTIL_H */
  156. #ifdef HAVE_GLIBC_BACKTRACE
  157. #include <execinfo.h>
  158. #endif /* HAVE_GLIBC_BACKTRACE */
  159. #ifdef BSDI_NRL
  160. #ifdef HAVE_NETINET6_IN6_H
  161. #include <netinet6/in6.h>
  162. #endif /* HAVE_NETINET6_IN6_H */
  163. #ifdef NRL
  164. #include <netinet6/in6.h>
  165. #endif /* NRL */
  166. #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
  167. /* BSD/OS 4.0 has lost belows defines, it should appear at
  168. /usr/include/sys/socket.h. */
  169. #define CMSG_ALIGN(n) (((n) + 3) & ~3)
  170. #define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
  171. #define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
  172. #endif /* BSDI_NRL */
  173. /* The definition of struct in_pktinfo is missing in old version of
  174. GLIBC 2.1 (Redhat 6.1). */
  175. #if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
  176. struct in_pktinfo
  177. {
  178. int ipi_ifindex;
  179. struct in_addr ipi_spec_dst;
  180. struct in_addr ipi_addr;
  181. };
  182. #endif
  183. /* For old definition. */
  184. #ifndef IN6_ARE_ADDR_EQUAL
  185. #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
  186. #endif /* IN6_ARE_ADDR_EQUAL */
  187. /* Zebra message types. */
  188. #define ZEBRA_INTERFACE_ADD 1
  189. #define ZEBRA_INTERFACE_DELETE 2
  190. #define ZEBRA_INTERFACE_ADDRESS_ADD 3
  191. #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
  192. #define ZEBRA_INTERFACE_UP 5
  193. #define ZEBRA_INTERFACE_DOWN 6
  194. #define ZEBRA_IPV4_ROUTE_ADD 7
  195. #define ZEBRA_IPV4_ROUTE_DELETE 8
  196. #define ZEBRA_IPV6_ROUTE_ADD 9
  197. #define ZEBRA_IPV6_ROUTE_DELETE 10
  198. #define ZEBRA_REDISTRIBUTE_ADD 11
  199. #define ZEBRA_REDISTRIBUTE_DELETE 12
  200. #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
  201. #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
  202. #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
  203. #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
  204. #define ZEBRA_IPV4_IMPORT_LOOKUP 17
  205. #define ZEBRA_IPV6_IMPORT_LOOKUP 18
  206. #define ZEBRA_MESSAGE_MAX 19
  207. /* Zebra route's types. */
  208. #define ZEBRA_ROUTE_SYSTEM 0
  209. #define ZEBRA_ROUTE_KERNEL 1
  210. #define ZEBRA_ROUTE_CONNECT 2
  211. #define ZEBRA_ROUTE_STATIC 3
  212. #define ZEBRA_ROUTE_RIP 4
  213. #define ZEBRA_ROUTE_RIPNG 5
  214. #define ZEBRA_ROUTE_OSPF 6
  215. #define ZEBRA_ROUTE_OSPF6 7
  216. #define ZEBRA_ROUTE_ISIS 8
  217. #define ZEBRA_ROUTE_BGP 9
  218. #define ZEBRA_ROUTE_MAX 10
  219. /* Zebra's family types. */
  220. #define ZEBRA_FAMILY_IPV4 1
  221. #define ZEBRA_FAMILY_IPV6 2
  222. #define ZEBRA_FAMILY_MAX 3
  223. /* Error codes of zebra. */
  224. #define ZEBRA_ERR_RTEXIST -1
  225. #define ZEBRA_ERR_RTUNREACH -2
  226. #define ZEBRA_ERR_EPERM -3
  227. #define ZEBRA_ERR_RTNOEXIST -4
  228. /* Zebra message flags */
  229. #define ZEBRA_FLAG_INTERNAL 0x01
  230. #define ZEBRA_FLAG_SELFROUTE 0x02
  231. #define ZEBRA_FLAG_BLACKHOLE 0x04
  232. #define ZEBRA_FLAG_IBGP 0x08
  233. #define ZEBRA_FLAG_SELECTED 0x10
  234. #define ZEBRA_FLAG_CHANGED 0x20
  235. #define ZEBRA_FLAG_STATIC 0x40
  236. #define ZEBRA_FLAG_REJECT 0x80
  237. /* Zebra nexthop flags. */
  238. #define ZEBRA_NEXTHOP_IFINDEX 1
  239. #define ZEBRA_NEXTHOP_IFNAME 2
  240. #define ZEBRA_NEXTHOP_IPV4 3
  241. #define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
  242. #define ZEBRA_NEXTHOP_IPV4_IFNAME 5
  243. #define ZEBRA_NEXTHOP_IPV6 6
  244. #define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
  245. #define ZEBRA_NEXTHOP_IPV6_IFNAME 8
  246. #define ZEBRA_NEXTHOP_BLACKHOLE 9
  247. #ifndef INADDR_LOOPBACK
  248. #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
  249. #endif
  250. /* Address family numbers from RFC1700. */
  251. #define AFI_IP 1
  252. #define AFI_IP6 2
  253. #define AFI_MAX 3
  254. /* Subsequent Address Family Identifier. */
  255. #define SAFI_UNICAST 1
  256. #define SAFI_MULTICAST 2
  257. #define SAFI_UNICAST_MULTICAST 3
  258. #define SAFI_MPLS_VPN 4
  259. #define SAFI_MAX 5
  260. /* Filter direction. */
  261. #define FILTER_IN 0
  262. #define FILTER_OUT 1
  263. #define FILTER_MAX 2
  264. /* Default Administrative Distance of each protocol. */
  265. #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
  266. #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
  267. #define ZEBRA_STATIC_DISTANCE_DEFAULT 1
  268. #define ZEBRA_RIP_DISTANCE_DEFAULT 120
  269. #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
  270. #define ZEBRA_OSPF_DISTANCE_DEFAULT 110
  271. #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
  272. #define ZEBRA_ISIS_DISTANCE_DEFAULT 115
  273. #define ZEBRA_IBGP_DISTANCE_DEFAULT 200
  274. #define ZEBRA_EBGP_DISTANCE_DEFAULT 20
  275. /* Flag manipulation macros. */
  276. #define CHECK_FLAG(V,F) ((V) & (F))
  277. #define SET_FLAG(V,F) (V) = (V) | (F)
  278. #define UNSET_FLAG(V,F) (V) = (V) & ~(F)
  279. /* AFI and SAFI type. */
  280. typedef u_int16_t afi_t;
  281. typedef u_char safi_t;
  282. /* Zebra types. */
  283. typedef u_int16_t zebra_size_t;
  284. typedef u_int8_t zebra_command_t;
  285. /* FIFO -- first in first out structure and macros. */
  286. struct fifo
  287. {
  288. struct fifo *next;
  289. struct fifo *prev;
  290. };
  291. #define FIFO_INIT(F) \
  292. do { \
  293. struct fifo *Xfifo = (struct fifo *)(F); \
  294. Xfifo->next = Xfifo->prev = Xfifo; \
  295. } while (0)
  296. #define FIFO_ADD(F,N) \
  297. do { \
  298. struct fifo *Xfifo = (struct fifo *)(F); \
  299. struct fifo *Xnode = (struct fifo *)(N); \
  300. Xnode->next = Xfifo; \
  301. Xnode->prev = Xfifo->prev; \
  302. Xfifo->prev = Xfifo->prev->next = Xnode; \
  303. } while (0)
  304. #define FIFO_DEL(N) \
  305. do { \
  306. struct fifo *Xnode = (struct fifo *)(N); \
  307. Xnode->prev->next = Xnode->next; \
  308. Xnode->next->prev = Xnode->prev; \
  309. } while (0)
  310. #define FIFO_HEAD(F) \
  311. ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
  312. ? NULL : (F)->next)
  313. #define FIFO_EMPTY(F) \
  314. (((struct fifo *)(F))->next == (struct fifo *)(F))
  315. #define FIFO_TOP(F) \
  316. (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
  317. #endif /* _ZEBRA_H */