]> git.proxmox.com Git - mirror_frr.git/blob - zebra/rib.h
Initial revision
[mirror_frr.git] / zebra / rib.h
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
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. */
91 struct 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. */
113 struct 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. */
162 struct 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
183 struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
184 struct nexthop *nexthop_ifname_add (struct rib *, char *);
185 struct nexthop *nexthop_blackhole_add (struct rib *);
186 struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
187 #ifdef HAVE_IPV6
188 struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
189 #endif /* HAVE_IPV6 */
190
191 struct vrf *vrf_lookup (u_int32_t);
192 struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
193 struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
194
195 int
196 rib_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
200 int
201 rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
202
203 int
204 rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
205 struct in_addr *gate, unsigned int ifindex, u_int32_t);
206
207 struct rib *
208 rib_match_ipv4 (struct in_addr);
209
210 struct rib *
211 rib_lookup_ipv4 (struct prefix_ipv4 *);
212
213 void rib_update ();
214 void rib_sweep_route ();
215 void rib_close ();
216 void rib_init ();
217
218 int
219 static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
220 u_char distance, u_int32_t vrf_id);
221
222 int
223 static_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
227 int
228 rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
229 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
230
231 int
232 rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
233 struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id);
234
235 struct rib *rib_lookup_ipv6 (struct in6_addr *);
236
237 struct rib *rib_match_ipv6 (struct in6_addr *);
238
239 extern struct route_table *rib_table_ipv6;
240
241 int
242 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
243 char *ifname, u_char distance, u_int32_t vrf_id);
244
245 int
246 static_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 */