blob: f50126106c5927bf0eec61c6720e0970d2294f52 [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
79#define STATIC_IPV4_BLACKHOLE 3
80
81 /* Nexthop value. */
82 union
83 {
84 struct in_addr ipv4;
85 char *ifname;
86 } gate;
87};
88
89#ifdef HAVE_IPV6
90/* Static route information. */
91struct static_ipv6
92{
93 /* For linked list. */
94 struct static_ipv6 *prev;
95 struct static_ipv6 *next;
96
97 /* Administrative distance. */
98 u_char distance;
99
100 /* Flag for this static route's type. */
101 u_char type;
102#define STATIC_IPV6_GATEWAY 1
103#define STATIC_IPV6_GATEWAY_IFNAME 2
104#define STATIC_IPV6_IFNAME 3
105
106 /* Nexthop value. */
107 struct in6_addr ipv6;
108 char *ifname;
109};
110#endif /* HAVE_IPV6 */
111
112/* Nexthop structure. */
113struct nexthop
114{
115 struct nexthop *next;
116 struct nexthop *prev;
117
118 u_char type;
119#define NEXTHOP_TYPE_IFINDEX 1 /* Directly connected. */
120#define NEXTHOP_TYPE_IFNAME 2 /* Interface route. */
121#define NEXTHOP_TYPE_IPV4 3 /* IPv4 nexthop. */
122#define NEXTHOP_TYPE_IPV4_IFINDEX 4 /* IPv4 nexthop with ifindex. */
123#define NEXTHOP_TYPE_IPV4_IFNAME 5 /* IPv4 nexthop with ifname. */
124#define NEXTHOP_TYPE_IPV6 6 /* IPv6 nexthop. */
125#define NEXTHOP_TYPE_IPV6_IFINDEX 7 /* IPv6 nexthop with ifindex. */
126#define NEXTHOP_TYPE_IPV6_IFNAME 8 /* IPv6 nexthop with ifname. */
127#define NEXTHOP_TYPE_BLACKHOLE 9 /* Null0 nexthop. */
128
129 u_char flags;
130#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
131#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
132#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
133
134 /* Interface index. */
135 unsigned int ifindex;
136 char *ifname;
137
138 /* Nexthop address or interface name. */
139 union
140 {
141 struct in_addr ipv4;
142#ifdef HAVE_IPV6
143 struct in6_addr ipv6;
144#endif /* HAVE_IPV6*/
145 } gate;
146
147 /* Recursive lookup nexthop. */
148 u_char rtype;
149 unsigned int rifindex;
150 union
151 {
152 struct in_addr ipv4;
153#ifdef HAVE_IPV6
154 struct in6_addr ipv6;
155#endif /* HAVE_IPV6 */
156 } rgate;
157
158 struct nexthop *indirect;
159};
160
161/* Routing table instance. */
162struct vrf
163{
164 /* Identifier. This is same as routing table vector index. */
165 u_int32_t id;
166
167 /* Routing table name. */
168 char *name;
169
170 /* Description. */
171 char *desc;
172
173 /* FIB identifier. */
174 u_char fib_id;
175
176 /* Routing table. */
177 struct route_table *table[AFI_MAX][SAFI_MAX];
178
179 /* Static route configuration. */
180 struct route_table *stable[AFI_MAX][SAFI_MAX];
181};
182
183struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
184struct nexthop *nexthop_ifname_add (struct rib *, char *);
185struct nexthop *nexthop_blackhole_add (struct rib *);
186struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
187#ifdef HAVE_IPV6
188struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
189#endif /* HAVE_IPV6 */
190
191struct vrf *vrf_lookup (u_int32_t);
192struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
193struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
194
195int
196rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
197 struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
198 u_int32_t, u_char);
199
200int
201rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
202
203int
204rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
205 struct in_addr *gate, unsigned int ifindex, u_int32_t);
206
207struct rib *
208rib_match_ipv4 (struct in_addr);
209
210struct rib *
211rib_lookup_ipv4 (struct prefix_ipv4 *);
212
213void rib_update ();
214void rib_sweep_route ();
215void rib_close ();
216void rib_init ();
217
218int
219static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
220 u_char distance, u_int32_t vrf_id);
221
222int
223static_delete_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
224 u_char distance, u_int32_t vrf_id);
225
226#ifdef HAVE_IPV6
227int
228rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
229 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
230
231int
232rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
233 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
234
235struct rib *rib_lookup_ipv6 (struct in6_addr *);
236
237struct rib *rib_match_ipv6 (struct in6_addr *);
238
239extern struct route_table *rib_table_ipv6;
240
241int
242static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
243 char *ifname, u_char distance, u_int32_t vrf_id);
244
245int
246static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
247 char *ifname, u_char distance, u_int32_t vrf_id);
248
249#endif /* HAVE_IPV6 */
250
251#endif /*_ZEBRA_RIB_H */