paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Zebra common header. |
| 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 |
| 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 |
| 19 | 02111-1307, USA. */ |
| 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 |
| 30 | #define __EXTENSIONS__ |
| 31 | #endif /* SUNOS_5 */ |
| 32 | |
paul | f043852 | 2003-05-19 21:06:32 +0000 | [diff] [blame] | 33 | #ifndef HAVE_SOCKLEN_T |
| 34 | typedef int socklen_t; |
| 35 | #endif /* HAVE_SOCKLEN_T */ |
| 36 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | #include <unistd.h> |
| 38 | #include <stdio.h> |
| 39 | #include <stdlib.h> |
| 40 | #include <ctype.h> |
| 41 | #include <errno.h> |
| 42 | #include <fcntl.h> |
| 43 | #include <signal.h> |
| 44 | #include <string.h> |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 45 | #include <pwd.h> |
| 46 | #include <grp.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 47 | #ifdef HAVE_STROPTS_H |
| 48 | #include <stropts.h> |
| 49 | #endif /* HAVE_STROPTS_H */ |
| 50 | #include <sys/fcntl.h> |
| 51 | #ifdef HAVE_SYS_SELECT_H |
| 52 | #include <sys/select.h> |
| 53 | #endif /* HAVE_SYS_SELECT_H */ |
| 54 | #include <sys/stat.h> |
| 55 | #include <sys/time.h> |
| 56 | #include <sys/types.h> |
| 57 | #include <sys/param.h> |
| 58 | #ifdef HAVE_SYS_SYSCTL_H |
| 59 | #include <sys/sysctl.h> |
| 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> |
| 69 | #include <time.h> |
| 70 | #include <sys/uio.h> |
| 71 | #include <sys/utsname.h> |
| 72 | #ifdef HAVE_RUSAGE |
| 73 | #include <sys/resource.h> |
| 74 | #endif /* HAVE_RUSAGE */ |
| 75 | |
| 76 | /* machine dependent includes */ |
| 77 | #ifdef SUNOS_5 |
| 78 | #include <limits.h> |
| 79 | #include <strings.h> |
| 80 | #endif /* SUNOS_5 */ |
| 81 | |
| 82 | /* machine dependent includes */ |
| 83 | #ifdef HAVE_LINUX_VERSION_H |
| 84 | #include <linux/version.h> |
| 85 | #endif /* HAVE_LINUX_VERSION_H */ |
| 86 | |
paul | ba965c6 | 2003-05-20 02:37:39 +0000 | [diff] [blame] | 87 | #ifdef HAVE_ASM_TYPES_H |
| 88 | #include <asm/types.h> |
| 89 | #endif /* HAVE_ASM_TYPES_H */ |
| 90 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 91 | /* misc include group */ |
| 92 | #include <stdarg.h> |
| 93 | #include <assert.h> |
| 94 | |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 95 | #ifdef HAVE_LCAPS |
| 96 | #include <sys/capability.h> |
| 97 | #include <sys/prctl.h> |
| 98 | #endif /* HAVE_LCAPS */ |
| 99 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 100 | /* network include group */ |
| 101 | |
| 102 | #include <sys/socket.h> |
| 103 | |
| 104 | #ifdef HAVE_SYS_SOCKIO_H |
| 105 | #include <sys/sockio.h> |
| 106 | #endif /* HAVE_SYS_SOCKIO_H */ |
| 107 | |
| 108 | #ifdef HAVE_NETINET_IN_H |
| 109 | #include <netinet/in.h> |
| 110 | #endif /* HAVE_NETINET_IN_H */ |
| 111 | #include <netinet/in_systm.h> |
| 112 | #include <netinet/ip.h> |
| 113 | #include <netinet/tcp.h> |
| 114 | |
| 115 | #ifdef HAVE_NET_NETOPT_H |
| 116 | #include <net/netopt.h> |
| 117 | #endif /* HAVE_NET_NETOPT_H */ |
| 118 | |
| 119 | #include <net/if.h> |
| 120 | |
| 121 | #ifdef HAVE_NET_IF_DL_H |
| 122 | #include <net/if_dl.h> |
| 123 | #endif /* HAVE_NET_IF_DL_H */ |
| 124 | |
| 125 | #ifdef HAVE_NET_IF_VAR_H |
| 126 | #include <net/if_var.h> |
| 127 | #endif /* HAVE_NET_IF_VAR_H */ |
| 128 | |
| 129 | #include <net/route.h> |
| 130 | |
| 131 | #ifdef HAVE_NETLINK |
| 132 | #include <linux/netlink.h> |
| 133 | #include <linux/rtnetlink.h> |
| 134 | #else |
| 135 | #define RT_TABLE_MAIN 0 |
| 136 | #endif /* HAVE_NETLINK */ |
| 137 | |
| 138 | #ifdef HAVE_NETDB_H |
| 139 | #include <netdb.h> |
| 140 | #endif /* HAVE_NETDB_H */ |
| 141 | |
| 142 | #include <arpa/inet.h> |
| 143 | #include <arpa/telnet.h> |
| 144 | |
| 145 | #ifdef HAVE_INET_ND_H |
| 146 | #include <inet/nd.h> |
| 147 | #endif /* HAVE_INET_ND_H */ |
| 148 | |
| 149 | #ifdef HAVE_NETINET_IN_VAR_H |
| 150 | #include <netinet/in_var.h> |
| 151 | #endif /* HAVE_NETINET_IN_VAR_H */ |
| 152 | |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 153 | #ifdef HAVE_NETINET6_IN6_VAR_H |
| 154 | #include <netinet6/in6_var.h> |
| 155 | #endif /* HAVE_NETINET6_IN6_VAR_H */ |
| 156 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | #ifdef HAVE_NETINET_IN6_VAR_H |
| 158 | #include <netinet/in6_var.h> |
| 159 | #endif /* HAVE_NETINET_IN6_VAR_H */ |
| 160 | |
| 161 | #ifdef HAVE_NETINET6_IN_H |
| 162 | #include <netinet6/in.h> |
| 163 | #endif /* HAVE_NETINET6_IN_H */ |
| 164 | |
| 165 | |
| 166 | #ifdef HAVE_NETINET6_IP6_H |
| 167 | #include <netinet6/ip6.h> |
| 168 | #endif /* HAVE_NETINET6_IP6_H */ |
| 169 | |
| 170 | #ifdef HAVE_NETINET_ICMP6_H |
| 171 | #include <netinet/icmp6.h> |
| 172 | #endif /* HAVE_NETINET_ICMP6_H */ |
| 173 | |
| 174 | #ifdef HAVE_NETINET6_ND6_H |
| 175 | #include <netinet6/nd6.h> |
| 176 | #endif /* HAVE_NETINET6_ND6_H */ |
| 177 | |
| 178 | #ifdef HAVE_LIBUTIL_H |
| 179 | #include <libutil.h> |
| 180 | #endif /* HAVE_LIBUTIL_H */ |
| 181 | |
paul | fb2d150 | 2003-06-04 09:40:54 +0000 | [diff] [blame] | 182 | #ifdef HAVE_GLIBC_BACKTRACE |
| 183 | #include <execinfo.h> |
| 184 | #endif /* HAVE_GLIBC_BACKTRACE */ |
| 185 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 186 | #ifdef BSDI_NRL |
| 187 | |
| 188 | #ifdef HAVE_NETINET6_IN6_H |
| 189 | #include <netinet6/in6.h> |
| 190 | #endif /* HAVE_NETINET6_IN6_H */ |
| 191 | |
| 192 | #ifdef NRL |
| 193 | #include <netinet6/in6.h> |
| 194 | #endif /* NRL */ |
| 195 | |
| 196 | #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL |
| 197 | |
| 198 | /* BSD/OS 4.0 has lost belows defines, it should appear at |
| 199 | /usr/include/sys/socket.h. */ |
| 200 | #define CMSG_ALIGN(n) (((n) + 3) & ~3) |
| 201 | #define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l)) |
| 202 | #define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l)) |
| 203 | |
| 204 | #endif /* BSDI_NRL */ |
| 205 | |
| 206 | /* The definition of struct in_pktinfo is missing in old version of |
| 207 | GLIBC 2.1 (Redhat 6.1). */ |
| 208 | #if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO) |
| 209 | struct in_pktinfo |
| 210 | { |
| 211 | int ipi_ifindex; |
| 212 | struct in_addr ipi_spec_dst; |
| 213 | struct in_addr ipi_addr; |
| 214 | }; |
| 215 | #endif |
| 216 | |
| 217 | /* For old definition. */ |
| 218 | #ifndef IN6_ARE_ADDR_EQUAL |
| 219 | #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL |
| 220 | #endif /* IN6_ARE_ADDR_EQUAL */ |
| 221 | |
| 222 | /* Zebra message types. */ |
| 223 | #define ZEBRA_INTERFACE_ADD 1 |
| 224 | #define ZEBRA_INTERFACE_DELETE 2 |
| 225 | #define ZEBRA_INTERFACE_ADDRESS_ADD 3 |
| 226 | #define ZEBRA_INTERFACE_ADDRESS_DELETE 4 |
| 227 | #define ZEBRA_INTERFACE_UP 5 |
| 228 | #define ZEBRA_INTERFACE_DOWN 6 |
| 229 | #define ZEBRA_IPV4_ROUTE_ADD 7 |
| 230 | #define ZEBRA_IPV4_ROUTE_DELETE 8 |
| 231 | #define ZEBRA_IPV6_ROUTE_ADD 9 |
| 232 | #define ZEBRA_IPV6_ROUTE_DELETE 10 |
| 233 | #define ZEBRA_REDISTRIBUTE_ADD 11 |
| 234 | #define ZEBRA_REDISTRIBUTE_DELETE 12 |
| 235 | #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13 |
| 236 | #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14 |
| 237 | #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15 |
| 238 | #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16 |
| 239 | #define ZEBRA_IPV4_IMPORT_LOOKUP 17 |
| 240 | #define ZEBRA_IPV6_IMPORT_LOOKUP 18 |
| 241 | #define ZEBRA_MESSAGE_MAX 19 |
| 242 | |
| 243 | /* Zebra route's types. */ |
| 244 | #define ZEBRA_ROUTE_SYSTEM 0 |
| 245 | #define ZEBRA_ROUTE_KERNEL 1 |
| 246 | #define ZEBRA_ROUTE_CONNECT 2 |
| 247 | #define ZEBRA_ROUTE_STATIC 3 |
| 248 | #define ZEBRA_ROUTE_RIP 4 |
| 249 | #define ZEBRA_ROUTE_RIPNG 5 |
| 250 | #define ZEBRA_ROUTE_OSPF 6 |
| 251 | #define ZEBRA_ROUTE_OSPF6 7 |
| 252 | #define ZEBRA_ROUTE_BGP 8 |
| 253 | #define ZEBRA_ROUTE_MAX 9 |
| 254 | |
| 255 | /* Zebra's family types. */ |
| 256 | #define ZEBRA_FAMILY_IPV4 1 |
| 257 | #define ZEBRA_FAMILY_IPV6 2 |
| 258 | #define ZEBRA_FAMILY_MAX 3 |
| 259 | |
| 260 | /* Error codes of zebra. */ |
| 261 | #define ZEBRA_ERR_RTEXIST -1 |
| 262 | #define ZEBRA_ERR_RTUNREACH -2 |
| 263 | #define ZEBRA_ERR_EPERM -3 |
| 264 | #define ZEBRA_ERR_RTNOEXIST -4 |
| 265 | |
| 266 | /* Zebra message flags */ |
| 267 | #define ZEBRA_FLAG_INTERNAL 0x01 |
| 268 | #define ZEBRA_FLAG_SELFROUTE 0x02 |
| 269 | #define ZEBRA_FLAG_BLACKHOLE 0x04 |
| 270 | #define ZEBRA_FLAG_IBGP 0x08 |
| 271 | #define ZEBRA_FLAG_SELECTED 0x10 |
| 272 | #define ZEBRA_FLAG_CHANGED 0x20 |
| 273 | #define ZEBRA_FLAG_STATIC 0x40 |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 274 | #define ZEBRA_FLAG_REJECT 0x80 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 275 | |
| 276 | /* Zebra nexthop flags. */ |
| 277 | #define ZEBRA_NEXTHOP_IFINDEX 1 |
| 278 | #define ZEBRA_NEXTHOP_IFNAME 2 |
| 279 | #define ZEBRA_NEXTHOP_IPV4 3 |
| 280 | #define ZEBRA_NEXTHOP_IPV4_IFINDEX 4 |
| 281 | #define ZEBRA_NEXTHOP_IPV4_IFNAME 5 |
| 282 | #define ZEBRA_NEXTHOP_IPV6 6 |
| 283 | #define ZEBRA_NEXTHOP_IPV6_IFINDEX 7 |
| 284 | #define ZEBRA_NEXTHOP_IPV6_IFNAME 8 |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 285 | #define ZEBRA_NEXTHOP_BLACKHOLE 9 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 286 | |
| 287 | #ifndef INADDR_LOOPBACK |
| 288 | #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */ |
| 289 | #endif |
| 290 | |
| 291 | /* Address family numbers from RFC1700. */ |
| 292 | #define AFI_IP 1 |
| 293 | #define AFI_IP6 2 |
| 294 | #define AFI_MAX 3 |
| 295 | |
| 296 | /* Subsequent Address Family Identifier. */ |
| 297 | #define SAFI_UNICAST 1 |
| 298 | #define SAFI_MULTICAST 2 |
| 299 | #define SAFI_UNICAST_MULTICAST 3 |
| 300 | #define SAFI_MPLS_VPN 4 |
| 301 | #define SAFI_MAX 5 |
| 302 | |
| 303 | /* Filter direction. */ |
| 304 | #define FILTER_IN 0 |
| 305 | #define FILTER_OUT 1 |
| 306 | #define FILTER_MAX 2 |
| 307 | |
| 308 | /* Default Administrative Distance of each protocol. */ |
| 309 | #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 |
| 310 | #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 |
| 311 | #define ZEBRA_STATIC_DISTANCE_DEFAULT 1 |
| 312 | #define ZEBRA_RIP_DISTANCE_DEFAULT 120 |
| 313 | #define ZEBRA_RIPNG_DISTANCE_DEFAULT 120 |
| 314 | #define ZEBRA_OSPF_DISTANCE_DEFAULT 110 |
| 315 | #define ZEBRA_OSPF6_DISTANCE_DEFAULT 110 |
| 316 | #define ZEBRA_IBGP_DISTANCE_DEFAULT 200 |
| 317 | #define ZEBRA_EBGP_DISTANCE_DEFAULT 20 |
| 318 | |
| 319 | /* Flag manipulation macros. */ |
| 320 | #define CHECK_FLAG(V,F) ((V) & (F)) |
| 321 | #define SET_FLAG(V,F) (V) = (V) | (F) |
| 322 | #define UNSET_FLAG(V,F) (V) = (V) & ~(F) |
| 323 | |
| 324 | /* AFI and SAFI type. */ |
| 325 | typedef u_int16_t afi_t; |
| 326 | typedef u_char safi_t; |
| 327 | |
| 328 | /* Zebra types. */ |
| 329 | typedef u_int16_t zebra_size_t; |
| 330 | typedef u_int8_t zebra_command_t; |
| 331 | |
paul | f043852 | 2003-05-19 21:06:32 +0000 | [diff] [blame] | 332 | /* FIFO -- first in first out structure and macros. */ |
| 333 | struct fifo |
| 334 | { |
| 335 | struct fifo *next; |
| 336 | struct fifo *prev; |
| 337 | }; |
| 338 | |
| 339 | #define FIFO_INIT(F) \ |
| 340 | do { \ |
| 341 | struct fifo *Xfifo = (struct fifo *)(F); \ |
| 342 | Xfifo->next = Xfifo->prev = Xfifo; \ |
| 343 | } while (0) |
| 344 | |
| 345 | #define FIFO_ADD(F,N) \ |
| 346 | do { \ |
| 347 | struct fifo *Xfifo = (struct fifo *)(F); \ |
| 348 | struct fifo *Xnode = (struct fifo *)(N); \ |
| 349 | Xnode->next = Xfifo; \ |
| 350 | Xnode->prev = Xfifo->prev; \ |
| 351 | Xfifo->prev = Xfifo->prev->next = Xnode; \ |
| 352 | } while (0) |
| 353 | |
| 354 | #define FIFO_DEL(N) \ |
| 355 | do { \ |
| 356 | struct fifo *Xnode = (struct fifo *)(N); \ |
| 357 | Xnode->prev->next = Xnode->next; \ |
| 358 | Xnode->next->prev = Xnode->prev; \ |
| 359 | } while (0) |
| 360 | |
| 361 | #define FIFO_HEAD(F) \ |
| 362 | ((((struct fifo *)(F))->next == (struct fifo *)(F)) \ |
| 363 | ? NULL : (F)->next) |
| 364 | |
| 365 | #define FIFO_EMPTY(F) \ |
| 366 | (((struct fifo *)(F))->next == (struct fifo *)(F)) |
| 367 | |
| 368 | #define FIFO_TOP(F) \ |
| 369 | (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next) |
| 370 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 371 | #endif /* _ZEBRA_H */ |