blob: a1a9e1dbc4fc1aae185b3f3a440162b17b8ce374 [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
paulec1a4282005-11-24 15:15:17 +000026#include "prefix.h"
27
paul718e3742002-12-13 20:15:29 +000028#define DISTANCE_INFINITY 255
29
30/* Routing information base. */
31struct rib
32{
33 /* Link list. */
34 struct rib *next;
35 struct rib *prev;
36
paul4d38fdb2005-04-28 17:35:14 +000037 /* ref count */
38 unsigned int lock;
39
paul718e3742002-12-13 20:15:29 +000040 /* Type fo this route. */
41 int type;
42
43 /* Which routing table */
44 int table;
45
46 /* Distance. */
47 u_char distance;
48
49 /* Flags of this route. This flag's definition is in lib/zebra.h
50 ZEBRA_FLAG_* */
51 u_char flags;
52
53 /* Metric */
54 u_int32_t metric;
55
56 /* Uptime. */
57 time_t uptime;
58
59 /* Refrence count. */
60 unsigned long refcnt;
61
62 /* Nexthop information. */
63 u_char nexthop_num;
64 u_char nexthop_active_num;
65 u_char nexthop_fib_num;
66
67 struct nexthop *nexthop;
68};
69
70/* Static route information. */
71struct static_ipv4
72{
73 /* For linked list. */
74 struct static_ipv4 *prev;
75 struct static_ipv4 *next;
76
77 /* Administrative distance. */
78 u_char distance;
79
80 /* Flag for this static route's type. */
81 u_char type;
82#define STATIC_IPV4_GATEWAY 1
83#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +000084#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +000085
86 /* Nexthop value. */
87 union
88 {
89 struct in_addr ipv4;
90 char *ifname;
91 } gate;
hasso81dfcaa2003-05-25 19:21:25 +000092
93 /* bit flags */
94 u_char flags;
95/*
96 see ZEBRA_FLAG_REJECT
97 ZEBRA_FLAG_BLACKHOLE
98 */
paul718e3742002-12-13 20:15:29 +000099};
100
101#ifdef HAVE_IPV6
102/* Static route information. */
103struct static_ipv6
104{
105 /* For linked list. */
106 struct static_ipv6 *prev;
107 struct static_ipv6 *next;
108
109 /* Administrative distance. */
110 u_char distance;
111
112 /* Flag for this static route's type. */
113 u_char type;
114#define STATIC_IPV6_GATEWAY 1
115#define STATIC_IPV6_GATEWAY_IFNAME 2
116#define STATIC_IPV6_IFNAME 3
117
118 /* Nexthop value. */
119 struct in6_addr ipv6;
120 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000121
122 /* bit flags */
123 u_char flags;
124/*
125 see ZEBRA_FLAG_REJECT
126 ZEBRA_FLAG_BLACKHOLE
127 */
paul718e3742002-12-13 20:15:29 +0000128};
129#endif /* HAVE_IPV6 */
130
paul7021c422003-07-15 12:52:22 +0000131enum nexthop_types_t
132{
133 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
134 NEXTHOP_TYPE_IFNAME, /* Interface route. */
135 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
136 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
137 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
138 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
139 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
140 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
141 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
142};
143
paul718e3742002-12-13 20:15:29 +0000144/* Nexthop structure. */
145struct nexthop
146{
147 struct nexthop *next;
148 struct nexthop *prev;
149
paul7021c422003-07-15 12:52:22 +0000150 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000151
152 u_char flags;
153#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
154#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
155#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
156
157 /* Interface index. */
158 unsigned int ifindex;
159 char *ifname;
160
161 /* Nexthop address or interface name. */
162 union
163 {
164 struct in_addr ipv4;
165#ifdef HAVE_IPV6
166 struct in6_addr ipv6;
167#endif /* HAVE_IPV6*/
168 } gate;
169
170 /* Recursive lookup nexthop. */
171 u_char rtype;
172 unsigned int rifindex;
173 union
174 {
175 struct in_addr ipv4;
176#ifdef HAVE_IPV6
177 struct in6_addr ipv6;
178#endif /* HAVE_IPV6 */
179 } rgate;
180
181 struct nexthop *indirect;
182};
183
184/* Routing table instance. */
185struct vrf
186{
187 /* Identifier. This is same as routing table vector index. */
188 u_int32_t id;
189
190 /* Routing table name. */
191 char *name;
192
193 /* Description. */
194 char *desc;
195
196 /* FIB identifier. */
197 u_char fib_id;
198
199 /* Routing table. */
200 struct route_table *table[AFI_MAX][SAFI_MAX];
201
202 /* Static route configuration. */
203 struct route_table *stable[AFI_MAX][SAFI_MAX];
204};
205
paula1ac18c2005-06-28 17:17:12 +0000206extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
207extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
208extern struct nexthop *nexthop_blackhole_add (struct rib *);
209extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
paul718e3742002-12-13 20:15:29 +0000210#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000211extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000212#endif /* HAVE_IPV6 */
213
paula1ac18c2005-06-28 17:17:12 +0000214extern struct vrf *vrf_lookup (u_int32_t);
215extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
216extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
paul718e3742002-12-13 20:15:29 +0000217
hassod24af182005-09-24 14:00:26 +0000218/* NOTE:
219 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
220 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000221extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
222 struct in_addr *gate, unsigned int ifindex,
223 u_int32_t vrf_id, u_int32_t, u_char);
paul718e3742002-12-13 20:15:29 +0000224
paula1ac18c2005-06-28 17:17:12 +0000225extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
paul718e3742002-12-13 20:15:29 +0000226
paula1ac18c2005-06-28 17:17:12 +0000227extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
228 struct in_addr *gate, unsigned int ifindex,
229 u_int32_t);
paul718e3742002-12-13 20:15:29 +0000230
paula1ac18c2005-06-28 17:17:12 +0000231extern struct rib *rib_match_ipv4 (struct in_addr);
paul718e3742002-12-13 20:15:29 +0000232
paula1ac18c2005-06-28 17:17:12 +0000233extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
paul718e3742002-12-13 20:15:29 +0000234
paula1ac18c2005-06-28 17:17:12 +0000235extern void rib_update (void);
236extern void rib_weed_tables (void);
237extern void rib_sweep_route (void);
238extern void rib_close (void);
239extern void rib_init (void);
paul718e3742002-12-13 20:15:29 +0000240
paula1ac18c2005-06-28 17:17:12 +0000241extern int
hasso39db97e2004-10-12 20:50:58 +0000242static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
hasso81dfcaa2003-05-25 19:21:25 +0000243 u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000244
paula1ac18c2005-06-28 17:17:12 +0000245extern int
hasso39db97e2004-10-12 20:50:58 +0000246static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
paul718e3742002-12-13 20:15:29 +0000247 u_char distance, u_int32_t vrf_id);
248
249#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000250extern int
paul718e3742002-12-13 20:15:29 +0000251rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
hassobe61c4e2005-08-27 06:05:47 +0000252 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
253 u_int32_t metric, u_char distance);
paul718e3742002-12-13 20:15:29 +0000254
paula1ac18c2005-06-28 17:17:12 +0000255extern int
paul718e3742002-12-13 20:15:29 +0000256rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
257 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
258
paula1ac18c2005-06-28 17:17:12 +0000259extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000260
paula1ac18c2005-06-28 17:17:12 +0000261extern struct rib *rib_match_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000262
263extern struct route_table *rib_table_ipv6;
264
paula1ac18c2005-06-28 17:17:12 +0000265extern int
paul718e3742002-12-13 20:15:29 +0000266static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000267 const char *ifname, u_char flags, u_char distance,
268 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000269
paula1ac18c2005-06-28 17:17:12 +0000270extern int
paul718e3742002-12-13 20:15:29 +0000271static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000272 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000273
274#endif /* HAVE_IPV6 */
275
276#endif /*_ZEBRA_RIB_H */