blob: 12ed8b7c573f3f898c1f5083a1f78991f57735dc [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
paula1ac18c2005-06-28 17:17:12 +0000204extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
205extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
206extern struct nexthop *nexthop_blackhole_add (struct rib *);
207extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
paul718e3742002-12-13 20:15:29 +0000208#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000209extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000210#endif /* HAVE_IPV6 */
211
paula1ac18c2005-06-28 17:17:12 +0000212extern struct vrf *vrf_lookup (u_int32_t);
213extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
214extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
paul718e3742002-12-13 20:15:29 +0000215
paula1ac18c2005-06-28 17:17:12 +0000216extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
217 struct in_addr *gate, unsigned int ifindex,
218 u_int32_t vrf_id, u_int32_t, u_char);
paul718e3742002-12-13 20:15:29 +0000219
paula1ac18c2005-06-28 17:17:12 +0000220extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
paul718e3742002-12-13 20:15:29 +0000221
paula1ac18c2005-06-28 17:17:12 +0000222extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
223 struct in_addr *gate, unsigned int ifindex,
224 u_int32_t);
paul718e3742002-12-13 20:15:29 +0000225
paula1ac18c2005-06-28 17:17:12 +0000226extern struct rib *rib_match_ipv4 (struct in_addr);
paul718e3742002-12-13 20:15:29 +0000227
paula1ac18c2005-06-28 17:17:12 +0000228extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
paul718e3742002-12-13 20:15:29 +0000229
paula1ac18c2005-06-28 17:17:12 +0000230extern void rib_update (void);
231extern void rib_weed_tables (void);
232extern void rib_sweep_route (void);
233extern void rib_close (void);
234extern void rib_init (void);
paul718e3742002-12-13 20:15:29 +0000235
paula1ac18c2005-06-28 17:17:12 +0000236extern int
hasso39db97e2004-10-12 20:50:58 +0000237static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
hasso81dfcaa2003-05-25 19:21:25 +0000238 u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000239
paula1ac18c2005-06-28 17:17:12 +0000240extern int
hasso39db97e2004-10-12 20:50:58 +0000241static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
paul718e3742002-12-13 20:15:29 +0000242 u_char distance, u_int32_t vrf_id);
243
244#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +0000245extern int
paul718e3742002-12-13 20:15:29 +0000246rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
hassobe61c4e2005-08-27 06:05:47 +0000247 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
248 u_int32_t metric, u_char distance);
paul718e3742002-12-13 20:15:29 +0000249
paula1ac18c2005-06-28 17:17:12 +0000250extern int
paul718e3742002-12-13 20:15:29 +0000251rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
252 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
253
paula1ac18c2005-06-28 17:17:12 +0000254extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000255
paula1ac18c2005-06-28 17:17:12 +0000256extern struct rib *rib_match_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000257
258extern struct route_table *rib_table_ipv6;
259
paula1ac18c2005-06-28 17:17:12 +0000260extern int
paul718e3742002-12-13 20:15:29 +0000261static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000262 const char *ifname, u_char flags, u_char distance,
263 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000264
paula1ac18c2005-06-28 17:17:12 +0000265extern int
paul718e3742002-12-13 20:15:29 +0000266static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000267 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000268
269#endif /* HAVE_IPV6 */
270
271#endif /*_ZEBRA_RIB_H */