blob: 04fbbecf9e0c68aa86b234f55ab05230f145960e [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{
Paul Jakma6d691122006-07-27 21:49:00 +000033 /* Status Flags for the *route_node*, but kept in the head RIB.. */
34 u_char rn_status;
35#define RIB_ROUTE_QUEUED (1 << 0)
36
paul718e3742002-12-13 20:15:29 +000037 /* Link list. */
38 struct rib *next;
39 struct rib *prev;
Paul Jakmae6d7d052006-03-30 13:32:09 +000040
41 /* Nexthop structure */
42 struct nexthop *nexthop;
43
44 /* Refrence count. */
45 unsigned long refcnt;
46
47 /* Uptime. */
48 time_t uptime;
paul718e3742002-12-13 20:15:29 +000049
50 /* Type fo this route. */
51 int type;
52
53 /* Which routing table */
54 int table;
55
Paul Jakmae6d7d052006-03-30 13:32:09 +000056 /* Metric */
57 u_int32_t metric;
58
paul718e3742002-12-13 20:15:29 +000059 /* Distance. */
60 u_char distance;
61
Paul Jakma6d691122006-07-27 21:49:00 +000062 /* Flags of this route.
63 * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
64 * to clients via Zserv
65 */
paul718e3742002-12-13 20:15:29 +000066 u_char flags;
67
Paul Jakma6d691122006-07-27 21:49:00 +000068 /* RIB internal status */
69 u_char status;
70#define RIB_ENTRY_REMOVED (1 << 0)
71
paul718e3742002-12-13 20:15:29 +000072 /* Nexthop information. */
73 u_char nexthop_num;
74 u_char nexthop_active_num;
75 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000076};
77
78/* Static route information. */
79struct static_ipv4
80{
81 /* For linked list. */
82 struct static_ipv4 *prev;
83 struct static_ipv4 *next;
84
85 /* Administrative distance. */
86 u_char distance;
87
88 /* Flag for this static route's type. */
89 u_char type;
90#define STATIC_IPV4_GATEWAY 1
91#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +000092#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +000093
94 /* Nexthop value. */
95 union
96 {
97 struct in_addr ipv4;
98 char *ifname;
99 } gate;
hasso81dfcaa2003-05-25 19:21:25 +0000100
101 /* bit flags */
102 u_char flags;
103/*
104 see ZEBRA_FLAG_REJECT
105 ZEBRA_FLAG_BLACKHOLE
106 */
paul718e3742002-12-13 20:15:29 +0000107};
108
109#ifdef HAVE_IPV6
110/* Static route information. */
111struct static_ipv6
112{
113 /* For linked list. */
114 struct static_ipv6 *prev;
115 struct static_ipv6 *next;
116
117 /* Administrative distance. */
118 u_char distance;
119
120 /* Flag for this static route's type. */
121 u_char type;
122#define STATIC_IPV6_GATEWAY 1
123#define STATIC_IPV6_GATEWAY_IFNAME 2
124#define STATIC_IPV6_IFNAME 3
125
126 /* Nexthop value. */
127 struct in6_addr ipv6;
128 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000129
130 /* bit flags */
131 u_char flags;
132/*
133 see ZEBRA_FLAG_REJECT
134 ZEBRA_FLAG_BLACKHOLE
135 */
paul718e3742002-12-13 20:15:29 +0000136};
137#endif /* HAVE_IPV6 */
138
paul7021c422003-07-15 12:52:22 +0000139enum nexthop_types_t
140{
141 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
142 NEXTHOP_TYPE_IFNAME, /* Interface route. */
143 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
144 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
145 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
146 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
147 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
148 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
149 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
150};
151
paul718e3742002-12-13 20:15:29 +0000152/* Nexthop structure. */
153struct nexthop
154{
155 struct nexthop *next;
156 struct nexthop *prev;
157
Paul Jakmae6d7d052006-03-30 13:32:09 +0000158 /* Interface index. */
159 char *ifname;
160 unsigned int ifindex;
161
paul7021c422003-07-15 12:52:22 +0000162 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000163
164 u_char flags;
165#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
166#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
167#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
168
paul718e3742002-12-13 20:15:29 +0000169 /* Nexthop address or interface name. */
170 union
171 {
172 struct in_addr ipv4;
173#ifdef HAVE_IPV6
174 struct in6_addr ipv6;
175#endif /* HAVE_IPV6*/
176 } gate;
177
178 /* Recursive lookup nexthop. */
179 u_char rtype;
180 unsigned int rifindex;
181 union
182 {
183 struct in_addr ipv4;
184#ifdef HAVE_IPV6
185 struct in6_addr ipv6;
186#endif /* HAVE_IPV6 */
187 } rgate;
paul718e3742002-12-13 20:15:29 +0000188};
189
190/* Routing table instance. */
191struct vrf
192{
193 /* Identifier. This is same as routing table vector index. */
194 u_int32_t id;
195
196 /* Routing table name. */
197 char *name;
198
199 /* Description. */
200 char *desc;
201
202 /* FIB identifier. */
203 u_char fib_id;
204
205 /* Routing table. */
206 struct route_table *table[AFI_MAX][SAFI_MAX];
207
208 /* Static route configuration. */
209 struct route_table *stable[AFI_MAX][SAFI_MAX];
210};
211
paula1ac18c2005-06-28 17:17:12 +0000212extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
213extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
214extern struct nexthop *nexthop_blackhole_add (struct rib *);
215extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
paul718e3742002-12-13 20:15:29 +0000216#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000217extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000218#endif /* HAVE_IPV6 */
219
paula1ac18c2005-06-28 17:17:12 +0000220extern struct vrf *vrf_lookup (u_int32_t);
221extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
222extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
paul718e3742002-12-13 20:15:29 +0000223
hassod24af182005-09-24 14:00:26 +0000224/* NOTE:
225 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
226 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000227extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
228 struct in_addr *gate, unsigned int ifindex,
229 u_int32_t vrf_id, u_int32_t, u_char);
paul718e3742002-12-13 20:15:29 +0000230
paula1ac18c2005-06-28 17:17:12 +0000231extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
paul718e3742002-12-13 20:15:29 +0000232
paula1ac18c2005-06-28 17:17:12 +0000233extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
234 struct in_addr *gate, unsigned int ifindex,
235 u_int32_t);
paul718e3742002-12-13 20:15:29 +0000236
paula1ac18c2005-06-28 17:17:12 +0000237extern struct rib *rib_match_ipv4 (struct in_addr);
paul718e3742002-12-13 20:15:29 +0000238
paula1ac18c2005-06-28 17:17:12 +0000239extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
paul718e3742002-12-13 20:15:29 +0000240
paula1ac18c2005-06-28 17:17:12 +0000241extern void rib_update (void);
242extern void rib_weed_tables (void);
243extern void rib_sweep_route (void);
244extern void rib_close (void);
245extern void rib_init (void);
paul718e3742002-12-13 20:15:29 +0000246
paula1ac18c2005-06-28 17:17:12 +0000247extern int
hasso39db97e2004-10-12 20:50:58 +0000248static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
hasso81dfcaa2003-05-25 19:21:25 +0000249 u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000250
paula1ac18c2005-06-28 17:17:12 +0000251extern int
hasso39db97e2004-10-12 20:50:58 +0000252static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
paul718e3742002-12-13 20:15:29 +0000253 u_char distance, u_int32_t vrf_id);
254
255#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000256extern int
paul718e3742002-12-13 20:15:29 +0000257rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
hassobe61c4e2005-08-27 06:05:47 +0000258 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
259 u_int32_t metric, u_char distance);
paul718e3742002-12-13 20:15:29 +0000260
paula1ac18c2005-06-28 17:17:12 +0000261extern int
paul718e3742002-12-13 20:15:29 +0000262rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
263 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
264
paula1ac18c2005-06-28 17:17:12 +0000265extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000266
paula1ac18c2005-06-28 17:17:12 +0000267extern struct rib *rib_match_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000268
269extern struct route_table *rib_table_ipv6;
270
paula1ac18c2005-06-28 17:17:12 +0000271extern int
paul718e3742002-12-13 20:15:29 +0000272static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000273 const char *ifname, u_char flags, u_char distance,
274 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000275
paula1ac18c2005-06-28 17:17:12 +0000276extern int
paul718e3742002-12-13 20:15:29 +0000277static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000278 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000279
280#endif /* HAVE_IPV6 */
281
282#endif /*_ZEBRA_RIB_H */