]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* RIP related values and structures. |
2 | * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org> | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | * 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #ifndef _ZEBRA_RIP_H | |
23 | #define _ZEBRA_RIP_H | |
24 | ||
25 | /* RIP version number. */ | |
26 | #define RIPv1 1 | |
27 | #define RIPv2 2 | |
f38a471c | 28 | /* N.B. stuff will break if |
29 | (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */ | |
30 | ||
718e3744 | 31 | |
32 | /* RIP command list. */ | |
33 | #define RIP_REQUEST 1 | |
34 | #define RIP_RESPONSE 2 | |
35 | #define RIP_TRACEON 3 /* Obsolete */ | |
36 | #define RIP_TRACEOFF 4 /* Obsolete */ | |
37 | #define RIP_POLL 5 | |
38 | #define RIP_POLL_ENTRY 6 | |
39 | #define RIP_COMMAND_MAX 7 | |
40 | ||
41 | /* RIP metric infinity value.*/ | |
42 | #define RIP_METRIC_INFINITY 16 | |
43 | ||
44 | /* Normal RIP packet min and max size. */ | |
45 | #define RIP_PACKET_MINSIZ 4 | |
46 | #define RIP_PACKET_MAXSIZ 512 | |
47 | ||
48 | #define RIP_HEADER_SIZE 4 | |
49 | #define RIP_RTE_SIZE 20 | |
50 | ||
51 | /* Max count of routing table entry in one rip packet. */ | |
52 | #define RIP_MAX_RTE 25 | |
53 | ||
54 | /* RIP version 2 multicast address. */ | |
55 | #ifndef INADDR_RIP_GROUP | |
56 | #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */ | |
57 | #endif | |
58 | ||
59 | /* RIP timers */ | |
60 | #define RIP_UPDATE_TIMER_DEFAULT 30 | |
61 | #define RIP_TIMEOUT_TIMER_DEFAULT 180 | |
62 | #define RIP_GARBAGE_TIMER_DEFAULT 120 | |
63 | ||
64 | /* RIP peer timeout value. */ | |
65 | #define RIP_PEER_TIMER_DEFAULT 180 | |
66 | ||
67 | /* RIP port number. */ | |
68 | #define RIP_PORT_DEFAULT 520 | |
69 | #define RIP_VTY_PORT 2602 | |
718e3744 | 70 | |
71 | /* Default configuration file name. */ | |
72 | #define RIPD_DEFAULT_CONFIG "ripd.conf" | |
73 | ||
74 | /* RIP route types. */ | |
75 | #define RIP_ROUTE_RTE 0 | |
76 | #define RIP_ROUTE_STATIC 1 | |
77 | #define RIP_ROUTE_DEFAULT 2 | |
78 | #define RIP_ROUTE_REDISTRIBUTE 3 | |
79 | #define RIP_ROUTE_INTERFACE 4 | |
80 | ||
ca5e516c | 81 | /* RIPv2 special RTE family types */ |
82 | #define RIP_FAMILY_AUTH 0xffff | |
83 | ||
84 | /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */ | |
85 | #define RIP_NO_AUTH 0 | |
86 | #define RIP_AUTH_DATA 1 | |
87 | #define RIP_AUTH_SIMPLE_PASSWORD 2 | |
88 | #define RIP_AUTH_MD5 3 | |
89 | ||
b14ee00b | 90 | /* RIPv2 Simple authentication */ |
91 | #define RIP_AUTH_SIMPLE_SIZE 16 | |
92 | ||
ca5e516c | 93 | /* RIPv2 MD5 authentication. */ |
718e3744 | 94 | #define RIP_AUTH_MD5_SIZE 16 |
ca5e516c | 95 | #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE |
718e3744 | 96 | |
97 | /* RIP structure. */ | |
98 | struct rip | |
99 | { | |
100 | /* RIP socket. */ | |
101 | int sock; | |
102 | ||
103 | /* Default version of rip instance. */ | |
f38a471c | 104 | int version_send; /* version 1 or 2 (but not both) */ |
105 | int version_recv; /* version 1 or 2 or both */ | |
718e3744 | 106 | |
107 | /* Output buffer of RIP. */ | |
108 | struct stream *obuf; | |
109 | ||
110 | /* RIP routing information base. */ | |
111 | struct route_table *table; | |
112 | ||
113 | /* RIP only static routing information. */ | |
114 | struct route_table *route; | |
115 | ||
116 | /* RIP neighbor. */ | |
117 | struct route_table *neighbor; | |
118 | ||
119 | /* RIP threads. */ | |
120 | struct thread *t_read; | |
121 | ||
122 | /* Update and garbage timer. */ | |
123 | struct thread *t_update; | |
124 | ||
125 | /* Triggered update hack. */ | |
126 | int trigger; | |
127 | struct thread *t_triggered_update; | |
128 | struct thread *t_triggered_interval; | |
129 | ||
130 | /* RIP timer values. */ | |
131 | unsigned long update_time; | |
132 | unsigned long timeout_time; | |
133 | unsigned long garbage_time; | |
134 | ||
135 | /* RIP default metric. */ | |
136 | int default_metric; | |
137 | ||
138 | /* RIP default-information originate. */ | |
139 | u_char default_information; | |
140 | char *default_information_route_map; | |
141 | ||
142 | /* RIP default distance. */ | |
143 | u_char distance; | |
144 | struct route_table *distance_table; | |
145 | ||
146 | /* For redistribute route map. */ | |
147 | struct | |
148 | { | |
149 | char *name; | |
150 | struct route_map *map; | |
151 | int metric_config; | |
152 | u_int32_t metric; | |
153 | } route_map[ZEBRA_ROUTE_MAX]; | |
154 | }; | |
155 | ||
156 | /* RIP routing table entry which belong to rip_packet. */ | |
157 | struct rte | |
158 | { | |
159 | u_int16_t family; /* Address family of this route. */ | |
160 | u_int16_t tag; /* Route Tag which included in RIP2 packet. */ | |
161 | struct in_addr prefix; /* Prefix of rip route. */ | |
162 | struct in_addr mask; /* Netmask of rip route. */ | |
163 | struct in_addr nexthop; /* Next hop of rip route. */ | |
164 | u_int32_t metric; /* Metric value of rip route. */ | |
165 | }; | |
166 | ||
167 | /* RIP packet structure. */ | |
168 | struct rip_packet | |
169 | { | |
170 | unsigned char command; /* Command type of RIP packet. */ | |
171 | unsigned char version; /* RIP version which coming from peer. */ | |
172 | unsigned char pad1; /* Padding of RIP packet header. */ | |
173 | unsigned char pad2; /* Same as above. */ | |
174 | struct rte rte[1]; /* Address structure. */ | |
175 | }; | |
176 | ||
177 | /* Buffer to read RIP packet. */ | |
178 | union rip_buf | |
179 | { | |
180 | struct rip_packet rip_packet; | |
181 | char buf[RIP_PACKET_MAXSIZ]; | |
182 | }; | |
183 | ||
184 | /* RIP route information. */ | |
185 | struct rip_info | |
186 | { | |
187 | /* This route's type. */ | |
188 | int type; | |
189 | ||
190 | /* Sub type. */ | |
191 | int sub_type; | |
192 | ||
193 | /* RIP nexthop. */ | |
194 | struct in_addr nexthop; | |
195 | struct in_addr from; | |
196 | ||
197 | /* Which interface does this route come from. */ | |
198 | unsigned int ifindex; | |
199 | ||
200 | /* Metric of this route. */ | |
201 | u_int32_t metric; | |
202 | ||
203 | /* Tag information of this route. */ | |
204 | u_int16_t tag; | |
205 | ||
206 | /* Flags of RIP route. */ | |
207 | #define RIP_RTF_FIB 1 | |
208 | #define RIP_RTF_CHANGED 2 | |
209 | u_char flags; | |
210 | ||
211 | /* Garbage collect timer. */ | |
212 | struct thread *t_timeout; | |
213 | struct thread *t_garbage_collect; | |
214 | ||
215 | /* Route-map futures - this variables can be changed. */ | |
216 | struct in_addr nexthop_out; | |
217 | u_char metric_set; | |
218 | u_int32_t metric_out; | |
16705130 | 219 | u_short tag_out; |
718e3744 | 220 | unsigned int ifindex_out; |
221 | ||
222 | struct route_node *rp; | |
223 | ||
224 | u_char distance; | |
225 | ||
226 | #ifdef NEW_RIP_TABLE | |
227 | struct rip_info *next; | |
228 | struct rip_info *prev; | |
229 | #endif /* NEW_RIP_TABLE */ | |
230 | }; | |
231 | ||
16705130 | 232 | typedef enum { |
233 | RIP_NO_SPLIT_HORIZON = 0, | |
234 | RIP_SPLIT_HORIZON, | |
235 | RIP_SPLIT_HORIZON_POISONED_REVERSE | |
236 | } split_horizon_policy_t; | |
237 | ||
718e3744 | 238 | /* RIP specific interface configuration. */ |
239 | struct rip_interface | |
240 | { | |
241 | /* RIP is enabled on this interface. */ | |
242 | int enable_network; | |
243 | int enable_interface; | |
244 | ||
245 | /* RIP is running on this interface. */ | |
246 | int running; | |
247 | ||
248 | /* RIP version control. */ | |
249 | int ri_send; | |
250 | int ri_receive; | |
251 | ||
252 | /* RIPv2 authentication type. */ | |
718e3744 | 253 | int auth_type; |
254 | ||
255 | /* RIPv2 authentication string. */ | |
256 | char *auth_str; | |
257 | ||
258 | /* RIPv2 authentication key chain. */ | |
259 | char *key_chain; | |
260 | ||
ca5e516c | 261 | /* value to use for md5->auth_len */ |
262 | u_int8_t md5_auth_len; | |
263 | ||
718e3744 | 264 | /* Split horizon flag. */ |
16705130 | 265 | split_horizon_policy_t split_horizon; |
266 | split_horizon_policy_t split_horizon_default; | |
718e3744 | 267 | |
268 | /* For filter type slot. */ | |
269 | #define RIP_FILTER_IN 0 | |
270 | #define RIP_FILTER_OUT 1 | |
271 | #define RIP_FILTER_MAX 2 | |
272 | ||
273 | /* Access-list. */ | |
274 | struct access_list *list[RIP_FILTER_MAX]; | |
275 | ||
276 | /* Prefix-list. */ | |
277 | struct prefix_list *prefix[RIP_FILTER_MAX]; | |
278 | ||
16705130 | 279 | /* Route-map. */ |
280 | struct route_map *routemap[RIP_FILTER_MAX]; | |
281 | ||
718e3744 | 282 | /* Wake up thread. */ |
283 | struct thread *t_wakeup; | |
284 | ||
285 | /* Interface statistics. */ | |
286 | int recv_badpackets; | |
287 | int recv_badroutes; | |
288 | int sent_updates; | |
289 | ||
290 | /* Passive interface. */ | |
291 | int passive; | |
292 | }; | |
293 | ||
294 | /* RIP peer information. */ | |
295 | struct rip_peer | |
296 | { | |
297 | /* Peer address. */ | |
298 | struct in_addr addr; | |
299 | ||
300 | /* Peer RIP tag value. */ | |
301 | int domain; | |
302 | ||
303 | /* Last update time. */ | |
304 | time_t uptime; | |
305 | ||
306 | /* Peer RIP version. */ | |
307 | u_char version; | |
308 | ||
309 | /* Statistics. */ | |
310 | int recv_badpackets; | |
311 | int recv_badroutes; | |
312 | ||
313 | /* Timeout thread. */ | |
314 | struct thread *t_timeout; | |
315 | }; | |
316 | ||
317 | struct rip_md5_info | |
318 | { | |
319 | u_int16_t family; | |
320 | u_int16_t type; | |
321 | u_int16_t packet_len; | |
322 | u_char keyid; | |
323 | u_char auth_len; | |
324 | u_int32_t sequence; | |
325 | u_int32_t reserv1; | |
326 | u_int32_t reserv2; | |
327 | }; | |
328 | ||
329 | struct rip_md5_data | |
330 | { | |
331 | u_int16_t family; | |
332 | u_int16_t type; | |
333 | u_char digest[16]; | |
334 | }; | |
335 | ||
336 | /* RIP accepet/announce methods. */ | |
337 | #define RI_RIP_UNSPEC 0 | |
338 | #define RI_RIP_VERSION_1 1 | |
339 | #define RI_RIP_VERSION_2 2 | |
340 | #define RI_RIP_VERSION_1_AND_2 3 | |
f38a471c | 341 | /* N.B. stuff will break if |
342 | (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */ | |
718e3744 | 343 | |
344 | /* Default value for "default-metric" command. */ | |
345 | #define RIP_DEFAULT_METRIC_DEFAULT 1 | |
346 | ||
347 | /* RIP event. */ | |
348 | enum rip_event | |
349 | { | |
350 | RIP_READ, | |
351 | RIP_UPDATE_EVENT, | |
352 | RIP_TRIGGERED_UPDATE, | |
353 | }; | |
354 | ||
355 | /* Macro for timer turn on. */ | |
356 | #define RIP_TIMER_ON(T,F,V) \ | |
357 | do { \ | |
358 | if (!(T)) \ | |
359 | (T) = thread_add_timer (master, (F), rinfo, (V)); \ | |
360 | } while (0) | |
361 | ||
362 | /* Macro for timer turn off. */ | |
363 | #define RIP_TIMER_OFF(X) \ | |
364 | do { \ | |
365 | if (X) \ | |
366 | { \ | |
367 | thread_cancel (X); \ | |
368 | (X) = NULL; \ | |
369 | } \ | |
370 | } while (0) | |
371 | ||
372 | /* Prototypes. */ | |
373 | void rip_init (); | |
374 | void rip_reset (); | |
375 | void rip_clean (); | |
376 | void rip_clean_network (); | |
377 | void rip_interface_clean (); | |
378 | void rip_interface_reset (); | |
4aaff3f8 | 379 | void rip_passive_nondefault_clean (); |
718e3744 | 380 | void rip_if_init (); |
381 | void rip_if_down_all (); | |
382 | void rip_route_map_init (); | |
383 | void rip_route_map_reset (); | |
384 | void rip_snmp_init (); | |
385 | void rip_zclient_init (); | |
386 | void rip_zclient_start (); | |
387 | void rip_zclient_reset (); | |
388 | void rip_offset_init (); | |
31a476c7 | 389 | int if_check_address (struct in_addr addr); |
390 | int if_valid_neighbor (struct in_addr addr); | |
718e3744 | 391 | |
931cd54d | 392 | int rip_request_send (struct sockaddr_in *, struct interface *, u_char, |
393 | struct connected *); | |
718e3744 | 394 | int rip_neighbor_lookup (struct sockaddr_in *); |
395 | void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int, | |
396 | struct in_addr *); | |
397 | void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int); | |
398 | void rip_redistribute_withdraw (int); | |
399 | void rip_zebra_ipv4_add (struct prefix_ipv4 *, struct in_addr *, u_int32_t, u_char); | |
400 | void rip_zebra_ipv4_delete (struct prefix_ipv4 *, struct in_addr *, u_int32_t); | |
1a51786a | 401 | void rip_interface_multicast_set (int, struct connected *); |
718e3744 | 402 | void rip_distribute_update_interface (struct interface *); |
16705130 | 403 | void rip_if_rmap_update_interface (struct interface *); |
718e3744 | 404 | |
405 | int config_write_rip_network (struct vty *, int); | |
406 | int config_write_rip_offset_list (struct vty *); | |
407 | int config_write_rip_redistribute (struct vty *, int); | |
408 | ||
409 | void rip_peer_init (); | |
410 | void rip_peer_update (struct sockaddr_in *, u_char); | |
411 | void rip_peer_bad_route (struct sockaddr_in *); | |
412 | void rip_peer_bad_packet (struct sockaddr_in *); | |
413 | void rip_peer_display (struct vty *); | |
414 | struct rip_peer *rip_peer_lookup (struct in_addr *); | |
415 | struct rip_peer *rip_peer_lookup_next (struct in_addr *); | |
416 | ||
417 | int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *); | |
418 | int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *); | |
419 | void rip_offset_clean (); | |
420 | ||
421 | void rip_info_free (struct rip_info *); | |
422 | u_char rip_distance_apply (struct rip_info *); | |
423 | void rip_redistribute_clean (); | |
424 | void rip_ifaddr_add (struct interface *, struct connected *); | |
425 | void rip_ifaddr_delete (struct interface *, struct connected *); | |
426 | ||
427 | /* There is only one rip strucutre. */ | |
428 | extern struct rip *rip; | |
429 | ||
430 | /* Master thread strucutre. */ | |
431 | extern struct thread_master *master; | |
432 | ||
433 | /* RIP statistics for SNMP. */ | |
434 | extern long rip_global_route_changes; | |
435 | extern long rip_global_queries; | |
436 | ||
437 | #endif /* _ZEBRA_RIP_H */ |