blob: 5b0dcfe94b85dbec69f7f41fc215545f94e3bc26 [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
35 /* Type fo this route. */
36 int type;
37
38 /* Which routing table */
39 int table;
40
41 /* Distance. */
42 u_char distance;
43
44 /* Flags of this route. This flag's definition is in lib/zebra.h
45 ZEBRA_FLAG_* */
46 u_char flags;
47
48 /* Metric */
49 u_int32_t metric;
50
51 /* Uptime. */
52 time_t uptime;
53
54 /* Refrence count. */
55 unsigned long refcnt;
56
57 /* Nexthop information. */
58 u_char nexthop_num;
59 u_char nexthop_active_num;
60 u_char nexthop_fib_num;
61
62 struct nexthop *nexthop;
63};
64
65/* Static route information. */
66struct static_ipv4
67{
68 /* For linked list. */
69 struct static_ipv4 *prev;
70 struct static_ipv4 *next;
71
72 /* Administrative distance. */
73 u_char distance;
74
75 /* Flag for this static route's type. */
76 u_char type;
77#define STATIC_IPV4_GATEWAY 1
78#define STATIC_IPV4_IFNAME 2
paul595db7f2003-05-25 21:35:06 +000079#define STATIC_IPV4_BLACKHOLE 3
paul718e3742002-12-13 20:15:29 +000080
81 /* Nexthop value. */
82 union
83 {
84 struct in_addr ipv4;
85 char *ifname;
86 } gate;
hasso81dfcaa2003-05-25 19:21:25 +000087
88 /* bit flags */
89 u_char flags;
90/*
91 see ZEBRA_FLAG_REJECT
92 ZEBRA_FLAG_BLACKHOLE
93 */
paul718e3742002-12-13 20:15:29 +000094};
95
96#ifdef HAVE_IPV6
97/* Static route information. */
98struct static_ipv6
99{
100 /* For linked list. */
101 struct static_ipv6 *prev;
102 struct static_ipv6 *next;
103
104 /* Administrative distance. */
105 u_char distance;
106
107 /* Flag for this static route's type. */
108 u_char type;
109#define STATIC_IPV6_GATEWAY 1
110#define STATIC_IPV6_GATEWAY_IFNAME 2
111#define STATIC_IPV6_IFNAME 3
112
113 /* Nexthop value. */
114 struct in6_addr ipv6;
115 char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +0000116
117 /* bit flags */
118 u_char flags;
119/*
120 see ZEBRA_FLAG_REJECT
121 ZEBRA_FLAG_BLACKHOLE
122 */
paul718e3742002-12-13 20:15:29 +0000123};
124#endif /* HAVE_IPV6 */
125
126/* Nexthop structure. */
127struct nexthop
128{
129 struct nexthop *next;
130 struct nexthop *prev;
131
132 u_char type;
133#define NEXTHOP_TYPE_IFINDEX 1 /* Directly connected. */
134#define NEXTHOP_TYPE_IFNAME 2 /* Interface route. */
135#define NEXTHOP_TYPE_IPV4 3 /* IPv4 nexthop. */
136#define NEXTHOP_TYPE_IPV4_IFINDEX 4 /* IPv4 nexthop with ifindex. */
137#define NEXTHOP_TYPE_IPV4_IFNAME 5 /* IPv4 nexthop with ifname. */
138#define NEXTHOP_TYPE_IPV6 6 /* IPv6 nexthop. */
139#define NEXTHOP_TYPE_IPV6_IFINDEX 7 /* IPv6 nexthop with ifindex. */
140#define NEXTHOP_TYPE_IPV6_IFNAME 8 /* IPv6 nexthop with ifname. */
paul595db7f2003-05-25 21:35:06 +0000141#define NEXTHOP_TYPE_BLACKHOLE 9 /* Null0 nexthop. */
paul718e3742002-12-13 20:15:29 +0000142
143 u_char flags;
144#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
145#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
146#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
147
148 /* Interface index. */
149 unsigned int ifindex;
150 char *ifname;
151
152 /* Nexthop address or interface name. */
153 union
154 {
155 struct in_addr ipv4;
156#ifdef HAVE_IPV6
157 struct in6_addr ipv6;
158#endif /* HAVE_IPV6*/
159 } gate;
160
161 /* Recursive lookup nexthop. */
162 u_char rtype;
163 unsigned int rifindex;
164 union
165 {
166 struct in_addr ipv4;
167#ifdef HAVE_IPV6
168 struct in6_addr ipv6;
169#endif /* HAVE_IPV6 */
170 } rgate;
171
172 struct nexthop *indirect;
173};
174
175/* Routing table instance. */
176struct vrf
177{
178 /* Identifier. This is same as routing table vector index. */
179 u_int32_t id;
180
181 /* Routing table name. */
182 char *name;
183
184 /* Description. */
185 char *desc;
186
187 /* FIB identifier. */
188 u_char fib_id;
189
190 /* Routing table. */
191 struct route_table *table[AFI_MAX][SAFI_MAX];
192
193 /* Static route configuration. */
194 struct route_table *stable[AFI_MAX][SAFI_MAX];
195};
196
197struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
198struct nexthop *nexthop_ifname_add (struct rib *, char *);
paul595db7f2003-05-25 21:35:06 +0000199struct nexthop *nexthop_blackhole_add (struct rib *);
paul718e3742002-12-13 20:15:29 +0000200struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
201#ifdef HAVE_IPV6
202struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
203#endif /* HAVE_IPV6 */
204
205struct vrf *vrf_lookup (u_int32_t);
206struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
207struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
208
209int
210rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
211 struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
212 u_int32_t, u_char);
213
214int
215rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
216
217int
218rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
219 struct in_addr *gate, unsigned int ifindex, u_int32_t);
220
221struct rib *
222rib_match_ipv4 (struct in_addr);
223
224struct rib *
225rib_lookup_ipv4 (struct prefix_ipv4 *);
226
227void rib_update ();
228void rib_sweep_route ();
229void rib_close ();
230void rib_init ();
231
232int
233static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
hasso81dfcaa2003-05-25 19:21:25 +0000234 u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000235
236int
237static_delete_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
238 u_char distance, u_int32_t vrf_id);
239
240#ifdef HAVE_IPV6
241int
242rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
243 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
244
245int
246rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
247 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
248
249struct rib *rib_lookup_ipv6 (struct in6_addr *);
250
251struct rib *rib_match_ipv6 (struct in6_addr *);
252
253extern struct route_table *rib_table_ipv6;
254
255int
256static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso81dfcaa2003-05-25 19:21:25 +0000257 char *ifname, u_char flags, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000258
259int
260static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
261 char *ifname, u_char distance, u_int32_t vrf_id);
262
263#endif /* HAVE_IPV6 */
264
265#endif /*_ZEBRA_RIB_H */