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