blob: 8d1284642e1d2b2681c2245c448aae223ba90db5 [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
hassod24af182005-09-24 14:00:26 +0000216/* NOTE:
217 * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
218 * also implicitly withdraw equal prefix of same type. */
paula1ac18c2005-06-28 17:17:12 +0000219extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
220 struct in_addr *gate, unsigned int ifindex,
221 u_int32_t vrf_id, u_int32_t, u_char);
paul718e3742002-12-13 20:15:29 +0000222
paula1ac18c2005-06-28 17:17:12 +0000223extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
paul718e3742002-12-13 20:15:29 +0000224
paula1ac18c2005-06-28 17:17:12 +0000225extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
226 struct in_addr *gate, unsigned int ifindex,
227 u_int32_t);
paul718e3742002-12-13 20:15:29 +0000228
paula1ac18c2005-06-28 17:17:12 +0000229extern struct rib *rib_match_ipv4 (struct in_addr);
paul718e3742002-12-13 20:15:29 +0000230
paula1ac18c2005-06-28 17:17:12 +0000231extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
paul718e3742002-12-13 20:15:29 +0000232
paula1ac18c2005-06-28 17:17:12 +0000233extern void rib_update (void);
234extern void rib_weed_tables (void);
235extern void rib_sweep_route (void);
236extern void rib_close (void);
237extern void rib_init (void);
paul718e3742002-12-13 20:15:29 +0000238
paula1ac18c2005-06-28 17:17:12 +0000239extern int
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
paula1ac18c2005-06-28 17:17:12 +0000243extern int
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
paula1ac18c2005-06-28 17:17:12 +0000248extern int
paul718e3742002-12-13 20:15:29 +0000249rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
hassobe61c4e2005-08-27 06:05:47 +0000250 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
251 u_int32_t metric, u_char distance);
paul718e3742002-12-13 20:15:29 +0000252
paula1ac18c2005-06-28 17:17:12 +0000253extern int
paul718e3742002-12-13 20:15:29 +0000254rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
255 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
256
paula1ac18c2005-06-28 17:17:12 +0000257extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000258
paula1ac18c2005-06-28 17:17:12 +0000259extern struct rib *rib_match_ipv6 (struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000260
261extern struct route_table *rib_table_ipv6;
262
paula1ac18c2005-06-28 17:17:12 +0000263extern int
paul718e3742002-12-13 20:15:29 +0000264static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000265 const char *ifname, u_char flags, u_char distance,
266 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000267
paula1ac18c2005-06-28 17:17:12 +0000268extern int
paul718e3742002-12-13 20:15:29 +0000269static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000270 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000271
272#endif /* HAVE_IPV6 */
273
274#endif /*_ZEBRA_RIB_H */