]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
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. */ | |
29 | struct 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. */ | |
66 | struct 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 | |
595db7f1 | 79 | #define STATIC_IPV4_BLACKHOLE 3 |
718e3744 | 80 | |
81 | /* Nexthop value. */ | |
82 | union | |
83 | { | |
84 | struct in_addr ipv4; | |
85 | char *ifname; | |
86 | } gate; | |
81dfcaa2 | 87 | |
88 | /* bit flags */ | |
89 | u_char flags; | |
90 | /* | |
91 | see ZEBRA_FLAG_REJECT | |
92 | ZEBRA_FLAG_BLACKHOLE | |
93 | */ | |
718e3744 | 94 | }; |
95 | ||
96 | #ifdef HAVE_IPV6 | |
97 | /* Static route information. */ | |
98 | struct 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; | |
81dfcaa2 | 116 | |
117 | /* bit flags */ | |
118 | u_char flags; | |
119 | /* | |
120 | see ZEBRA_FLAG_REJECT | |
121 | ZEBRA_FLAG_BLACKHOLE | |
122 | */ | |
718e3744 | 123 | }; |
124 | #endif /* HAVE_IPV6 */ | |
125 | ||
7021c425 | 126 | enum 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 | ||
718e3744 | 139 | /* Nexthop structure. */ |
140 | struct nexthop | |
141 | { | |
142 | struct nexthop *next; | |
143 | struct nexthop *prev; | |
144 | ||
7021c425 | 145 | enum nexthop_types_t type; |
718e3744 | 146 | |
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. */ | |
180 | struct 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 | ||
201 | struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); | |
202 | struct nexthop *nexthop_ifname_add (struct rib *, char *); | |
595db7f1 | 203 | struct nexthop *nexthop_blackhole_add (struct rib *); |
718e3744 | 204 | struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *); |
205 | #ifdef HAVE_IPV6 | |
206 | struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); | |
207 | #endif /* HAVE_IPV6 */ | |
208 | ||
209 | struct vrf *vrf_lookup (u_int32_t); | |
210 | struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id); | |
211 | struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id); | |
212 | ||
213 | int | |
214 | rib_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 | ||
218 | int | |
219 | rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *); | |
220 | ||
221 | int | |
222 | rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, | |
223 | struct in_addr *gate, unsigned int ifindex, u_int32_t); | |
224 | ||
225 | struct rib * | |
226 | rib_match_ipv4 (struct in_addr); | |
227 | ||
228 | struct rib * | |
229 | rib_lookup_ipv4 (struct prefix_ipv4 *); | |
230 | ||
231 | void rib_update (); | |
232 | void rib_sweep_route (); | |
233 | void rib_close (); | |
234 | void rib_init (); | |
235 | ||
236 | int | |
237 | static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname, | |
81dfcaa2 | 238 | u_char flags, u_char distance, u_int32_t vrf_id); |
718e3744 | 239 | |
240 | int | |
241 | static_delete_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname, | |
242 | u_char distance, u_int32_t vrf_id); | |
243 | ||
244 | #ifdef HAVE_IPV6 | |
245 | int | |
246 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, | |
247 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); | |
248 | ||
249 | int | |
250 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, | |
251 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); | |
252 | ||
253 | struct rib *rib_lookup_ipv6 (struct in6_addr *); | |
254 | ||
255 | struct rib *rib_match_ipv6 (struct in6_addr *); | |
256 | ||
257 | extern struct route_table *rib_table_ipv6; | |
258 | ||
259 | int | |
260 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, | |
81dfcaa2 | 261 | char *ifname, u_char flags, u_char distance, u_int32_t vrf_id); |
718e3744 | 262 | |
263 | int | |
264 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, | |
265 | char *ifname, u_char distance, u_int32_t vrf_id); | |
266 | ||
267 | #endif /* HAVE_IPV6 */ | |
268 | ||
269 | #endif /*_ZEBRA_RIB_H */ |