blob: 3827b6e78e2ae62453ad84d6bbb08569293d19bc [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;
Paul Jakmae6d7d052006-03-30 13:32:09 +000036
37 /* Nexthop structure */
38 struct nexthop *nexthop;
39
40 /* Refrence count. */
41 unsigned long refcnt;
42
43 /* Uptime. */
44 time_t uptime;
paul718e3742002-12-13 20:15:29 +000045
paul4d38fdb2005-04-28 17:35:14 +000046 /* ref count */
47 unsigned int lock;
Paul Jakmae6d7d052006-03-30 13:32:09 +000048
paul718e3742002-12-13 20:15:29 +000049 /* Type fo this route. */
50 int type;
51
52 /* Which routing table */
53 int table;
54
Paul Jakmae6d7d052006-03-30 13:32:09 +000055 /* Metric */
56 u_int32_t metric;
57
paul718e3742002-12-13 20:15:29 +000058 /* Distance. */
59 u_char distance;
60
61 /* Flags of this route. This flag's definition is in lib/zebra.h
62 ZEBRA_FLAG_* */
63 u_char flags;
64
paul718e3742002-12-13 20:15:29 +000065 /* Nexthop information. */
66 u_char nexthop_num;
67 u_char nexthop_active_num;
68 u_char nexthop_fib_num;
paul718e3742002-12-13 20:15:29 +000069};
70
71/* Static route information. */
72struct static_ipv4
73{
74 /* For linked list. */
75 struct static_ipv4 *prev;
76 struct static_ipv4 *next;
77
78 /* Administrative distance. */
79 u_char distance;
80
81 /* Flag for this static route's type. */
82 u_char type;
83#define STATIC_IPV4_GATEWAY 1
84#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +000085#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +000086
87 /* Nexthop value. */
88 union
89 {
90 struct in_addr ipv4;
91 char *ifname;
92 } gate;
hasso81dfcaa2003-05-25 19:21:25 +000093
94 /* bit flags */
95 u_char flags;
96/*
97 see ZEBRA_FLAG_REJECT
98 ZEBRA_FLAG_BLACKHOLE
99 */
paul718e3742002-12-13 20:15:29 +0000100};
101
102#ifdef HAVE_IPV6
103/* Static route information. */
104struct static_ipv6
105{
106 /* For linked list. */
107 struct static_ipv6 *prev;
108 struct static_ipv6 *next;
109
110 /* Administrative distance. */
111 u_char distance;
112
113 /* Flag for this static route's type. */
114 u_char type;
115#define STATIC_IPV6_GATEWAY 1
116#define STATIC_IPV6_GATEWAY_IFNAME 2
117#define STATIC_IPV6_IFNAME 3
118
119 /* Nexthop value. */
120 struct in6_addr ipv6;
121 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000122
123 /* bit flags */
124 u_char flags;
125/*
126 see ZEBRA_FLAG_REJECT
127 ZEBRA_FLAG_BLACKHOLE
128 */
paul718e3742002-12-13 20:15:29 +0000129};
130#endif /* HAVE_IPV6 */
131
paul7021c422003-07-15 12:52:22 +0000132enum nexthop_types_t
133{
134 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
135 NEXTHOP_TYPE_IFNAME, /* Interface route. */
136 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
137 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
138 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
139 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
140 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
141 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
142 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
143};
144
paul718e3742002-12-13 20:15:29 +0000145/* Nexthop structure. */
146struct nexthop
147{
148 struct nexthop *next;
149 struct nexthop *prev;
150
Paul Jakmae6d7d052006-03-30 13:32:09 +0000151 /* Interface index. */
152 char *ifname;
153 unsigned int ifindex;
154
paul7021c422003-07-15 12:52:22 +0000155 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000156
157 u_char flags;
158#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
159#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
160#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
161
paul718e3742002-12-13 20:15:29 +0000162 /* Nexthop address or interface name. */
163 union
164 {
165 struct in_addr ipv4;
166#ifdef HAVE_IPV6
167 struct in6_addr ipv6;
168#endif /* HAVE_IPV6*/
169 } gate;
170
171 /* Recursive lookup nexthop. */
172 u_char rtype;
173 unsigned int rifindex;
174 union
175 {
176 struct in_addr ipv4;
177#ifdef HAVE_IPV6
178 struct in6_addr ipv6;
179#endif /* HAVE_IPV6 */
180 } rgate;
paul718e3742002-12-13 20:15:29 +0000181};
182
183/* Routing table instance. */
184struct vrf
185{
186 /* Identifier. This is same as routing table vector index. */
187 u_int32_t id;
188
189 /* Routing table name. */
190 char *name;
191
192 /* Description. */
193 char *desc;
194
195 /* FIB identifier. */
196 u_char fib_id;
197
198 /* Routing table. */
199 struct route_table *table[AFI_MAX][SAFI_MAX];
200
201 /* Static route configuration. */
202 struct route_table *stable[AFI_MAX][SAFI_MAX];
203};
204
paula1ac18c2005-06-28 17:17:12 +0000205extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
206extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
207extern struct nexthop *nexthop_blackhole_add (struct rib *);
208extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
paul718e3742002-12-13 20:15:29 +0000209#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000210extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000211#endif /* HAVE_IPV6 */
212
paula1ac18c2005-06-28 17:17:12 +0000213extern struct vrf *vrf_lookup (u_int32_t);
214extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
215extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
paul718e3742002-12-13 20:15:29 +0000216
hassod24af182005-09-24 14:00:26 +0000217/* NOTE:
218 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
219 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000220extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
221 struct in_addr *gate, unsigned int ifindex,
222 u_int32_t vrf_id, u_int32_t, u_char);
paul718e3742002-12-13 20:15:29 +0000223
paula1ac18c2005-06-28 17:17:12 +0000224extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
paul718e3742002-12-13 20:15:29 +0000225
paula1ac18c2005-06-28 17:17:12 +0000226extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
227 struct in_addr *gate, unsigned int ifindex,
228 u_int32_t);
paul718e3742002-12-13 20:15:29 +0000229
paula1ac18c2005-06-28 17:17:12 +0000230extern struct rib *rib_match_ipv4 (struct in_addr);
paul718e3742002-12-13 20:15:29 +0000231
paula1ac18c2005-06-28 17:17:12 +0000232extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
paul718e3742002-12-13 20:15:29 +0000233
paula1ac18c2005-06-28 17:17:12 +0000234extern void rib_update (void);
235extern void rib_weed_tables (void);
236extern void rib_sweep_route (void);
237extern void rib_close (void);
238extern void rib_init (void);
paul718e3742002-12-13 20:15:29 +0000239
paula1ac18c2005-06-28 17:17:12 +0000240extern int
hasso39db97e2004-10-12 20:50:58 +0000241static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
hasso81dfcaa2003-05-25 19:21:25 +0000242 u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000243
paula1ac18c2005-06-28 17:17:12 +0000244extern int
hasso39db97e2004-10-12 20:50:58 +0000245static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
paul718e3742002-12-13 20:15:29 +0000246 u_char distance, u_int32_t vrf_id);
247
248#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000249extern int
paul718e3742002-12-13 20:15:29 +0000250rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
hassobe61c4e2005-08-27 06:05:47 +0000251 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
252 u_int32_t metric, u_char distance);
paul718e3742002-12-13 20:15:29 +0000253
paula1ac18c2005-06-28 17:17:12 +0000254extern int
paul718e3742002-12-13 20:15:29 +0000255rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
256 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
257
paula1ac18c2005-06-28 17:17:12 +0000258extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000259
paula1ac18c2005-06-28 17:17:12 +0000260extern struct rib *rib_match_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000261
262extern struct route_table *rib_table_ipv6;
263
paula1ac18c2005-06-28 17:17:12 +0000264extern int
paul718e3742002-12-13 20:15:29 +0000265static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000266 const char *ifname, u_char flags, u_char distance,
267 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000268
paula1ac18c2005-06-28 17:17:12 +0000269extern int
paul718e3742002-12-13 20:15:29 +0000270static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000271 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000272
273#endif /* HAVE_IPV6 */
274
275#endif /*_ZEBRA_RIB_H */