blob: 1e6393e6ae13bb49e0bde1d15363981f50b7a733 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * Routing Information Base header
3 * Copyright (C) 1997 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_RIB_H
24#define _ZEBRA_RIB_H
25
26#define DISTANCE_INFINITY 255
27
28/* Routing information base. */
29struct rib
30{
31 /* Link list. */
32 struct rib *next;
33 struct rib *prev;
34
paul4d38fdb2005-04-28 17:35:14 +000035 /* ref count */
36 unsigned int lock;
37
paul718e3742002-12-13 20:15:29 +000038 /* Type fo this route. */
39 int type;
40
41 /* Which routing table */
42 int table;
43
44 /* Distance. */
45 u_char distance;
46
47 /* Flags of this route. This flag's definition is in lib/zebra.h
48 ZEBRA_FLAG_* */
49 u_char flags;
50
51 /* Metric */
52 u_int32_t metric;
53
54 /* Uptime. */
55 time_t uptime;
56
57 /* Refrence count. */
58 unsigned long refcnt;
59
60 /* Nexthop information. */
61 u_char nexthop_num;
62 u_char nexthop_active_num;
63 u_char nexthop_fib_num;
64
65 struct nexthop *nexthop;
66};
67
68/* Static route information. */
69struct static_ipv4
70{
71 /* For linked list. */
72 struct static_ipv4 *prev;
73 struct static_ipv4 *next;
74
75 /* Administrative distance. */
76 u_char distance;
77
78 /* Flag for this static route's type. */
79 u_char type;
80#define STATIC_IPV4_GATEWAY 1
81#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +000082#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +000083
84 /* Nexthop value. */
85 union
86 {
87 struct in_addr ipv4;
88 char *ifname;
89 } gate;
hasso81dfcaa2003-05-25 19:21:25 +000090
91 /* bit flags */
92 u_char flags;
93/*
94 see ZEBRA_FLAG_REJECT
95 ZEBRA_FLAG_BLACKHOLE
96 */
paul718e3742002-12-13 20:15:29 +000097};
98
99#ifdef HAVE_IPV6
100/* Static route information. */
101struct static_ipv6
102{
103 /* For linked list. */
104 struct static_ipv6 *prev;
105 struct static_ipv6 *next;
106
107 /* Administrative distance. */
108 u_char distance;
109
110 /* Flag for this static route's type. */
111 u_char type;
112#define STATIC_IPV6_GATEWAY 1
113#define STATIC_IPV6_GATEWAY_IFNAME 2
114#define STATIC_IPV6_IFNAME 3
115
116 /* Nexthop value. */
117 struct in6_addr ipv6;
118 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000119
120 /* bit flags */
121 u_char flags;
122/*
123 see ZEBRA_FLAG_REJECT
124 ZEBRA_FLAG_BLACKHOLE
125 */
paul718e3742002-12-13 20:15:29 +0000126};
127#endif /* HAVE_IPV6 */
128
paul7021c422003-07-15 12:52:22 +0000129enum nexthop_types_t
130{
131 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
132 NEXTHOP_TYPE_IFNAME, /* Interface route. */
133 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
134 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
135 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
136 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
137 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
138 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
139 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
140};
141
paul718e3742002-12-13 20:15:29 +0000142/* Nexthop structure. */
143struct nexthop
144{
145 struct nexthop *next;
146 struct nexthop *prev;
147
paul7021c422003-07-15 12:52:22 +0000148 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000149
150 u_char flags;
151#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
152#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
153#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
154
155 /* Interface index. */
156 unsigned int ifindex;
157 char *ifname;
158
159 /* Nexthop address or interface name. */
160 union
161 {
162 struct in_addr ipv4;
163#ifdef HAVE_IPV6
164 struct in6_addr ipv6;
165#endif /* HAVE_IPV6*/
166 } gate;
167
168 /* Recursive lookup nexthop. */
169 u_char rtype;
170 unsigned int rifindex;
171 union
172 {
173 struct in_addr ipv4;
174#ifdef HAVE_IPV6
175 struct in6_addr ipv6;
176#endif /* HAVE_IPV6 */
177 } rgate;
178
179 struct nexthop *indirect;
180};
181
182/* Routing table instance. */
183struct vrf
184{
185 /* Identifier. This is same as routing table vector index. */
186 u_int32_t id;
187
188 /* Routing table name. */
189 char *name;
190
191 /* Description. */
192 char *desc;
193
194 /* FIB identifier. */
195 u_char fib_id;
196
197 /* Routing table. */
198 struct route_table *table[AFI_MAX][SAFI_MAX];
199
200 /* Static route configuration. */
201 struct route_table *stable[AFI_MAX][SAFI_MAX];
202};
203
204struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
205struct nexthop *nexthop_ifname_add (struct rib *, char *);
paul595db7f2003-05-25 21:35:06 +0000206struct nexthop *nexthop_blackhole_add (struct rib *);
paul718e3742002-12-13 20:15:29 +0000207struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
208#ifdef HAVE_IPV6
209struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
210#endif /* HAVE_IPV6 */
211
212struct vrf *vrf_lookup (u_int32_t);
213struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
214struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
215
216int
217rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
218 struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
219 u_int32_t, u_char);
220
221int
222rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
223
224int
225rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
226 struct in_addr *gate, unsigned int ifindex, u_int32_t);
227
228struct rib *
229rib_match_ipv4 (struct in_addr);
230
231struct rib *
232rib_lookup_ipv4 (struct prefix_ipv4 *);
233
234void rib_update ();
235void rib_sweep_route ();
236void rib_close ();
237void rib_init ();
238
239int
hasso39db97e2004-10-12 20:50:58 +0000240static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
hasso81dfcaa2003-05-25 19:21:25 +0000241 u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000242
243int
hasso39db97e2004-10-12 20:50:58 +0000244static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
paul718e3742002-12-13 20:15:29 +0000245 u_char distance, u_int32_t vrf_id);
246
247#ifdef HAVE_IPV6
248int
249rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
250 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
251
252int
253rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
254 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
255
256struct rib *rib_lookup_ipv6 (struct in6_addr *);
257
258struct rib *rib_match_ipv6 (struct in6_addr *);
259
260extern struct route_table *rib_table_ipv6;
261
262int
263static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000264 const char *ifname, u_char flags, u_char distance,
265 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000266
267int
268static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000269 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000270
271#endif /* HAVE_IPV6 */
272
273#endif /*_ZEBRA_RIB_H */