blob: b21e087f24098e291256fe838801a3fb6be33205 [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
paul7021c422003-07-15 12:52:22 +0000126enum nexthop_types_t
127{
128 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
129 NEXTHOP_TYPE_IFNAME, /* Interface route. */
130 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
131 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
132 NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
133 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
134 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
135 NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
136 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
137};
138
paul718e3742002-12-13 20:15:29 +0000139/* Nexthop structure. */
140struct nexthop
141{
142 struct nexthop *next;
143 struct nexthop *prev;
144
paul7021c422003-07-15 12:52:22 +0000145 enum nexthop_types_t type;
paul718e3742002-12-13 20:15:29 +0000146
147 u_char flags;
148#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
149#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
150#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
151
152 /* Interface index. */
153 unsigned int ifindex;
154 char *ifname;
155
156 /* Nexthop address or interface name. */
157 union
158 {
159 struct in_addr ipv4;
160#ifdef HAVE_IPV6
161 struct in6_addr ipv6;
162#endif /* HAVE_IPV6*/
163 } gate;
164
165 /* Recursive lookup nexthop. */
166 u_char rtype;
167 unsigned int rifindex;
168 union
169 {
170 struct in_addr ipv4;
171#ifdef HAVE_IPV6
172 struct in6_addr ipv6;
173#endif /* HAVE_IPV6 */
174 } rgate;
175
176 struct nexthop *indirect;
177};
178
179/* Routing table instance. */
180struct vrf
181{
182 /* Identifier. This is same as routing table vector index. */
183 u_int32_t id;
184
185 /* Routing table name. */
186 char *name;
187
188 /* Description. */
189 char *desc;
190
191 /* FIB identifier. */
192 u_char fib_id;
193
194 /* Routing table. */
195 struct route_table *table[AFI_MAX][SAFI_MAX];
196
197 /* Static route configuration. */
198 struct route_table *stable[AFI_MAX][SAFI_MAX];
199};
200
201struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
202struct nexthop *nexthop_ifname_add (struct rib *, char *);
paul595db7f2003-05-25 21:35:06 +0000203struct nexthop *nexthop_blackhole_add (struct rib *);
paul718e3742002-12-13 20:15:29 +0000204struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
205#ifdef HAVE_IPV6
206struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
207#endif /* HAVE_IPV6 */
208
209struct vrf *vrf_lookup (u_int32_t);
210struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
211struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
212
213int
214rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
215 struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
216 u_int32_t, u_char);
217
218int
219rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
220
221int
222rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
223 struct in_addr *gate, unsigned int ifindex, u_int32_t);
224
225struct rib *
226rib_match_ipv4 (struct in_addr);
227
228struct rib *
229rib_lookup_ipv4 (struct prefix_ipv4 *);
230
231void rib_update ();
232void rib_sweep_route ();
233void rib_close ();
234void rib_init ();
235
236int
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
240int
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
245int
246rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
247 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
248
249int
250rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
251 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
252
253struct rib *rib_lookup_ipv6 (struct in6_addr *);
254
255struct rib *rib_match_ipv6 (struct in6_addr *);
256
257extern struct route_table *rib_table_ipv6;
258
259int
260static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000261 const char *ifname, u_char flags, u_char distance,
262 u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000263
264int
265static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
hasso39db97e2004-10-12 20:50:58 +0000266 const char *ifname, u_char distance, u_int32_t vrf_id);
paul718e3742002-12-13 20:15:29 +0000267
268#endif /* HAVE_IPV6 */
269
270#endif /*_ZEBRA_RIB_H */