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