added files
[bcm963xx.git] / userapps / opensource / zebra / lib / zebra.h
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
33 #include <unistd.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #include <errno.h>
38 #include <fcntl.h>
39 #include <signal.h>
40 #include <string.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
70 /* machine dependent includes */
71 #ifdef SUNOS_5
72 #include <limits.h>
73 #include <strings.h>
74 #endif /* SUNOS_5 */
75
76 /* machine dependent includes */
77 #ifdef HAVE_LINUX_VERSION_H
78 #include <linux/version.h>
79 #endif /* HAVE_LINUX_VERSION_H */
80
81 #ifdef HAVE_ASM_TYPES_H
82 #include <asm/types.h>
83 #endif /* HAVE_ASM_TYPES_H */
84
85 /* misc include group */
86 #include <stdarg.h>
87 #include <assert.h>
88
89 /* network include group */
90
91 #include <sys/socket.h>
92
93 #ifdef HAVE_SYS_SOCKIO_H
94 #include <sys/sockio.h>
95 #endif /* HAVE_SYS_SOCKIO_H */
96
97 #ifdef HAVE_NETINET_IN_H
98 #include <netinet/in.h>
99 #endif /* HAVE_NETINET_IN_H */
100 #include <netinet/in_systm.h>
101 #include <netinet/ip.h>
102 #include <netinet/tcp.h>
103
104 #ifdef HAVE_NET_NETOPT_H
105 #include <net/netopt.h>
106 #endif /* HAVE_NET_NETOPT_H */
107
108 #include <net/if.h>
109
110 #ifdef HAVE_NET_IF_DL_H
111 #include <net/if_dl.h>
112 #endif /* HAVE_NET_IF_DL_H */
113
114 #ifdef HAVE_NET_IF_VAR_H
115 #include <net/if_var.h>
116 #endif /* HAVE_NET_IF_VAR_H */
117
118 #include <net/route.h>
119
120 #ifdef HAVE_NETLINK
121 #include <linux/netlink.h>
122 #include <linux/rtnetlink.h>
123 #else
124 #define RT_TABLE_MAIN           0
125 #endif /* HAVE_NETLINK */
126
127 #ifdef HAVE_NETDB_H
128 #include <netdb.h>
129 #endif /* HAVE_NETDB_H */
130
131 #include <arpa/inet.h>
132 #include <arpa/telnet.h>
133
134 #ifdef HAVE_INET_ND_H
135 #include <inet/nd.h>
136 #endif /* HAVE_INET_ND_H */
137
138 #ifdef HAVE_NETINET_IN_VAR_H
139 #include <netinet/in_var.h>
140 #endif /* HAVE_NETINET_IN_VAR_H */
141
142 #ifdef HAVE_NETINET_IN6_VAR_H
143 #include <netinet/in6_var.h>
144 #endif /* HAVE_NETINET_IN6_VAR_H */
145
146 #ifdef HAVE_NETINET6_IN_H
147 #include <netinet6/in.h>
148 #endif /* HAVE_NETINET6_IN_H */
149
150
151 #ifdef HAVE_NETINET6_IP6_H
152 #include <netinet6/ip6.h>
153 #endif /* HAVE_NETINET6_IP6_H */
154
155 #ifdef HAVE_NETINET_ICMP6_H
156 #include <netinet/icmp6.h>
157 #endif /* HAVE_NETINET_ICMP6_H */
158
159 #ifdef HAVE_NETINET6_ND6_H
160 #include <netinet6/nd6.h>
161 #endif /* HAVE_NETINET6_ND6_H */
162
163 #ifdef HAVE_LIBUTIL_H
164 #include <libutil.h>
165 #endif /* HAVE_LIBUTIL_H */
166
167 #ifdef BSDI_NRL
168
169 #ifdef HAVE_NETINET6_IN6_H
170 #include <netinet6/in6.h>
171 #endif /* HAVE_NETINET6_IN6_H */
172
173 #ifdef NRL
174 #include <netinet6/in6.h>
175 #endif /* NRL */
176
177 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
178
179 /* BSD/OS 4.0 has lost belows defines, it should appear at
180    /usr/include/sys/socket.h.  */
181 #define CMSG_ALIGN(n)           (((n) + 3) & ~3)
182 #define CMSG_SPACE(l)   (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
183 #define CMSG_LEN(l)     (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
184
185 #endif /* BSDI_NRL */
186
187 /*  The definition of struct in_pktinfo is missing in old version of
188     GLIBC 2.1 (Redhat 6.1).  */
189 #if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
190 struct in_pktinfo
191 {
192   int ipi_ifindex;
193   struct in_addr ipi_spec_dst;
194   struct in_addr ipi_addr;
195 };
196 #endif
197
198 /* For old definition. */
199 #ifndef IN6_ARE_ADDR_EQUAL
200 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
201 #endif /* IN6_ARE_ADDR_EQUAL */
202
203 /* Zebra message types. */
204 #define ZEBRA_INTERFACE_ADD                1
205 #define ZEBRA_INTERFACE_DELETE             2
206 #define ZEBRA_INTERFACE_ADDRESS_ADD        3
207 #define ZEBRA_INTERFACE_ADDRESS_DELETE     4
208 #define ZEBRA_INTERFACE_UP                 5
209 #define ZEBRA_INTERFACE_DOWN               6
210 #define ZEBRA_IPV4_ROUTE_ADD               7
211 #define ZEBRA_IPV4_ROUTE_DELETE            8
212 #define ZEBRA_IPV6_ROUTE_ADD               9
213 #define ZEBRA_IPV6_ROUTE_DELETE           10
214 #define ZEBRA_REDISTRIBUTE_ADD            11
215 #define ZEBRA_REDISTRIBUTE_DELETE         12
216 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD    13
217 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
218 #define ZEBRA_IPV4_NEXTHOP_LOOKUP         15
219 #define ZEBRA_IPV6_NEXTHOP_LOOKUP         16
220 #define ZEBRA_IPV4_IMPORT_LOOKUP          17
221 #define ZEBRA_IPV6_IMPORT_LOOKUP          18
222 #define ZEBRA_MESSAGE_MAX                 19
223
224 /* Zebra route's types. */
225 #define ZEBRA_ROUTE_SYSTEM               0
226 #define ZEBRA_ROUTE_KERNEL               1
227 #define ZEBRA_ROUTE_CONNECT              2
228 #define ZEBRA_ROUTE_STATIC               3
229 #define ZEBRA_ROUTE_RIP                  4
230 #define ZEBRA_ROUTE_RIPNG                5
231 #define ZEBRA_ROUTE_OSPF                 6
232 #define ZEBRA_ROUTE_OSPF6                7
233 #define ZEBRA_ROUTE_BGP                  8
234 #define ZEBRA_ROUTE_MAX                  9
235
236 /* Zebra's family types. */
237 #define ZEBRA_FAMILY_IPV4                1
238 #define ZEBRA_FAMILY_IPV6                2
239 #define ZEBRA_FAMILY_MAX                 3
240
241 /* Error codes of zebra. */
242 #define ZEBRA_ERR_RTEXIST               -1
243 #define ZEBRA_ERR_RTUNREACH             -2
244 #define ZEBRA_ERR_EPERM                 -3
245 #define ZEBRA_ERR_RTNOEXIST             -4
246
247 /* Zebra message flags */
248 #define ZEBRA_FLAG_INTERNAL           0x01
249 #define ZEBRA_FLAG_SELFROUTE          0x02
250 #define ZEBRA_FLAG_BLACKHOLE          0x04
251 #define ZEBRA_FLAG_IBGP               0x08
252 #define ZEBRA_FLAG_SELECTED           0x10
253 #define ZEBRA_FLAG_CHANGED            0x20
254 #define ZEBRA_FLAG_STATIC             0x40
255
256 /* Zebra nexthop flags. */
257 #define ZEBRA_NEXTHOP_IFINDEX            1
258 #define ZEBRA_NEXTHOP_IFNAME             2
259 #define ZEBRA_NEXTHOP_IPV4               3
260 #define ZEBRA_NEXTHOP_IPV4_IFINDEX       4
261 #define ZEBRA_NEXTHOP_IPV4_IFNAME        5
262 #define ZEBRA_NEXTHOP_IPV6               6
263 #define ZEBRA_NEXTHOP_IPV6_IFINDEX       7
264 #define ZEBRA_NEXTHOP_IPV6_IFNAME        8
265
266 #ifndef INADDR_LOOPBACK
267 #define INADDR_LOOPBACK 0x7f000001      /* Internet address 127.0.0.1.  */
268 #endif
269
270 /* Address family numbers from RFC1700. */
271 #define AFI_IP                    1
272 #define AFI_IP6                   2
273 #define AFI_MAX                   3
274
275 /* Subsequent Address Family Identifier. */
276 #define SAFI_UNICAST              1
277 #define SAFI_MULTICAST            2
278 #define SAFI_UNICAST_MULTICAST    3
279 #define SAFI_MPLS_VPN             4
280 #define SAFI_MAX                  5
281
282 /* Filter direction.  */
283 #define FILTER_IN                 0
284 #define FILTER_OUT                1
285 #define FILTER_MAX                2
286
287 /* Default Administrative Distance of each protocol. */
288 #define ZEBRA_KERNEL_DISTANCE_DEFAULT      0
289 #define ZEBRA_CONNECT_DISTANCE_DEFAULT     0
290 #define ZEBRA_STATIC_DISTANCE_DEFAULT      1
291 #define ZEBRA_RIP_DISTANCE_DEFAULT       120
292 #define ZEBRA_RIPNG_DISTANCE_DEFAULT     120
293 #define ZEBRA_OSPF_DISTANCE_DEFAULT      110
294 #define ZEBRA_OSPF6_DISTANCE_DEFAULT     110
295 #define ZEBRA_IBGP_DISTANCE_DEFAULT      200
296 #define ZEBRA_EBGP_DISTANCE_DEFAULT       20
297
298 /* Flag manipulation macros. */
299 #define CHECK_FLAG(V,F)      ((V) & (F))
300 #define SET_FLAG(V,F)        (V) = (V) | (F)
301 #define UNSET_FLAG(V,F)      (V) = (V) & ~(F)
302
303 /* AFI and SAFI type. */
304 typedef u_int16_t afi_t;
305 typedef u_char safi_t;
306
307 /* Zebra types. */
308 typedef u_int16_t zebra_size_t;
309 typedef u_int8_t zebra_command_t;
310
311 #endif /* _ZEBRA_H */