blob: 29e4f67c2b3272150e0811872531fb1e36b737df [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
paulf38a4712003-06-07 01:10:00 +000028/* N.B. stuff will break if
29 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
30
paul718e3742002-12-13 20:15:29 +000031
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
paul718e3742002-12-13 20:15:29 +000070
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
81/* RIP MD5 authentication. */
82#define RIP_AUTH_MD5_SIZE 16
83
84/* RIP structure. */
85struct rip
86{
87 /* RIP socket. */
88 int sock;
89
90 /* Default version of rip instance. */
paulf38a4712003-06-07 01:10:00 +000091 int version_send; /* version 1 or 2 (but not both) */
92 int version_recv; /* version 1 or 2 or both */
paul718e3742002-12-13 20:15:29 +000093
94 /* Output buffer of RIP. */
95 struct stream *obuf;
96
97 /* RIP routing information base. */
98 struct route_table *table;
99
100 /* RIP only static routing information. */
101 struct route_table *route;
102
103 /* RIP neighbor. */
104 struct route_table *neighbor;
105
106 /* RIP threads. */
107 struct thread *t_read;
108
109 /* Update and garbage timer. */
110 struct thread *t_update;
111
112 /* Triggered update hack. */
113 int trigger;
114 struct thread *t_triggered_update;
115 struct thread *t_triggered_interval;
116
117 /* RIP timer values. */
118 unsigned long update_time;
119 unsigned long timeout_time;
120 unsigned long garbage_time;
121
122 /* RIP default metric. */
123 int default_metric;
124
125 /* RIP default-information originate. */
126 u_char default_information;
127 char *default_information_route_map;
128
129 /* RIP default distance. */
130 u_char distance;
131 struct route_table *distance_table;
132
133 /* For redistribute route map. */
134 struct
135 {
136 char *name;
137 struct route_map *map;
138 int metric_config;
139 u_int32_t metric;
140 } route_map[ZEBRA_ROUTE_MAX];
141};
142
143/* RIP routing table entry which belong to rip_packet. */
144struct rte
145{
146 u_int16_t family; /* Address family of this route. */
147 u_int16_t tag; /* Route Tag which included in RIP2 packet. */
148 struct in_addr prefix; /* Prefix of rip route. */
149 struct in_addr mask; /* Netmask of rip route. */
150 struct in_addr nexthop; /* Next hop of rip route. */
151 u_int32_t metric; /* Metric value of rip route. */
152};
153
154/* RIP packet structure. */
155struct rip_packet
156{
157 unsigned char command; /* Command type of RIP packet. */
158 unsigned char version; /* RIP version which coming from peer. */
159 unsigned char pad1; /* Padding of RIP packet header. */
160 unsigned char pad2; /* Same as above. */
161 struct rte rte[1]; /* Address structure. */
162};
163
164/* Buffer to read RIP packet. */
165union rip_buf
166{
167 struct rip_packet rip_packet;
168 char buf[RIP_PACKET_MAXSIZ];
169};
170
171/* RIP route information. */
172struct rip_info
173{
174 /* This route's type. */
175 int type;
176
177 /* Sub type. */
178 int sub_type;
179
180 /* RIP nexthop. */
181 struct in_addr nexthop;
182 struct in_addr from;
183
184 /* Which interface does this route come from. */
185 unsigned int ifindex;
186
187 /* Metric of this route. */
188 u_int32_t metric;
189
190 /* Tag information of this route. */
191 u_int16_t tag;
192
193 /* Flags of RIP route. */
194#define RIP_RTF_FIB 1
195#define RIP_RTF_CHANGED 2
196 u_char flags;
197
198 /* Garbage collect timer. */
199 struct thread *t_timeout;
200 struct thread *t_garbage_collect;
201
202 /* Route-map futures - this variables can be changed. */
203 struct in_addr nexthop_out;
204 u_char metric_set;
205 u_int32_t metric_out;
hasso16705132003-05-25 14:49:19 +0000206 u_short tag_out;
paul718e3742002-12-13 20:15:29 +0000207 unsigned int ifindex_out;
208
209 struct route_node *rp;
210
211 u_char distance;
212
213#ifdef NEW_RIP_TABLE
214 struct rip_info *next;
215 struct rip_info *prev;
216#endif /* NEW_RIP_TABLE */
217};
218
hasso16705132003-05-25 14:49:19 +0000219typedef enum {
220 RIP_NO_SPLIT_HORIZON = 0,
221 RIP_SPLIT_HORIZON,
222 RIP_SPLIT_HORIZON_POISONED_REVERSE
223} split_horizon_policy_t;
224
paul718e3742002-12-13 20:15:29 +0000225/* RIP specific interface configuration. */
226struct rip_interface
227{
228 /* RIP is enabled on this interface. */
229 int enable_network;
230 int enable_interface;
231
232 /* RIP is running on this interface. */
233 int running;
234
235 /* RIP version control. */
236 int ri_send;
237 int ri_receive;
238
239 /* RIPv2 authentication type. */
240#define RIP_NO_AUTH 0
241#define RIP_AUTH_DATA 1
242#define RIP_AUTH_SIMPLE_PASSWORD 2
243#define RIP_AUTH_MD5 3
244 int auth_type;
245
246 /* RIPv2 authentication string. */
247 char *auth_str;
248
249 /* RIPv2 authentication key chain. */
250 char *key_chain;
251
252 /* Split horizon flag. */
hasso16705132003-05-25 14:49:19 +0000253 split_horizon_policy_t split_horizon;
254 split_horizon_policy_t split_horizon_default;
paul718e3742002-12-13 20:15:29 +0000255
256 /* For filter type slot. */
257#define RIP_FILTER_IN 0
258#define RIP_FILTER_OUT 1
259#define RIP_FILTER_MAX 2
260
261 /* Access-list. */
262 struct access_list *list[RIP_FILTER_MAX];
263
264 /* Prefix-list. */
265 struct prefix_list *prefix[RIP_FILTER_MAX];
266
hasso16705132003-05-25 14:49:19 +0000267 /* Route-map. */
268 struct route_map *routemap[RIP_FILTER_MAX];
269
paul718e3742002-12-13 20:15:29 +0000270 /* Wake up thread. */
271 struct thread *t_wakeup;
272
273 /* Interface statistics. */
274 int recv_badpackets;
275 int recv_badroutes;
276 int sent_updates;
277
278 /* Passive interface. */
279 int passive;
280};
281
282/* RIP peer information. */
283struct rip_peer
284{
285 /* Peer address. */
286 struct in_addr addr;
287
288 /* Peer RIP tag value. */
289 int domain;
290
291 /* Last update time. */
292 time_t uptime;
293
294 /* Peer RIP version. */
295 u_char version;
296
297 /* Statistics. */
298 int recv_badpackets;
299 int recv_badroutes;
300
301 /* Timeout thread. */
302 struct thread *t_timeout;
303};
304
305struct rip_md5_info
306{
307 u_int16_t family;
308 u_int16_t type;
309 u_int16_t packet_len;
310 u_char keyid;
311 u_char auth_len;
312 u_int32_t sequence;
313 u_int32_t reserv1;
314 u_int32_t reserv2;
315};
316
317struct rip_md5_data
318{
319 u_int16_t family;
320 u_int16_t type;
321 u_char digest[16];
322};
323
324/* RIP accepet/announce methods. */
325#define RI_RIP_UNSPEC 0
326#define RI_RIP_VERSION_1 1
327#define RI_RIP_VERSION_2 2
328#define RI_RIP_VERSION_1_AND_2 3
paulf38a4712003-06-07 01:10:00 +0000329/* N.B. stuff will break if
330 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
paul718e3742002-12-13 20:15:29 +0000331
332/* Default value for "default-metric" command. */
333#define RIP_DEFAULT_METRIC_DEFAULT 1
334
335/* RIP event. */
336enum rip_event
337{
338 RIP_READ,
339 RIP_UPDATE_EVENT,
340 RIP_TRIGGERED_UPDATE,
341};
342
343/* Macro for timer turn on. */
344#define RIP_TIMER_ON(T,F,V) \
345 do { \
346 if (!(T)) \
347 (T) = thread_add_timer (master, (F), rinfo, (V)); \
348 } while (0)
349
350/* Macro for timer turn off. */
351#define RIP_TIMER_OFF(X) \
352 do { \
353 if (X) \
354 { \
355 thread_cancel (X); \
356 (X) = NULL; \
357 } \
358 } while (0)
359
360/* Prototypes. */
361void rip_init ();
362void rip_reset ();
363void rip_clean ();
364void rip_clean_network ();
365void rip_interface_clean ();
366void rip_interface_reset ();
paul4aaff3f2003-06-07 01:04:45 +0000367void rip_passive_nondefault_clean ();
paul718e3742002-12-13 20:15:29 +0000368void rip_if_init ();
369void rip_if_down_all ();
370void rip_route_map_init ();
371void rip_route_map_reset ();
372void rip_snmp_init ();
373void rip_zclient_init ();
374void rip_zclient_start ();
375void rip_zclient_reset ();
376void rip_offset_init ();
paul31a476c2003-09-29 19:54:53 +0000377int if_check_address (struct in_addr addr);
378int if_valid_neighbor (struct in_addr addr);
paul718e3742002-12-13 20:15:29 +0000379
380int rip_request_send (struct sockaddr_in *, struct interface *, u_char);
381int rip_neighbor_lookup (struct sockaddr_in *);
382void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int,
383 struct in_addr *);
384void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int);
385void rip_redistribute_withdraw (int);
386void rip_zebra_ipv4_add (struct prefix_ipv4 *, struct in_addr *, u_int32_t, u_char);
387void rip_zebra_ipv4_delete (struct prefix_ipv4 *, struct in_addr *, u_int32_t);
paulcc1131a2003-10-15 23:20:17 +0000388void rip_interface_multicast_set (int, struct connected *, int);
paul718e3742002-12-13 20:15:29 +0000389void rip_distribute_update_interface (struct interface *);
hasso16705132003-05-25 14:49:19 +0000390void rip_if_rmap_update_interface (struct interface *);
paul718e3742002-12-13 20:15:29 +0000391
392int config_write_rip_network (struct vty *, int);
393int config_write_rip_offset_list (struct vty *);
394int config_write_rip_redistribute (struct vty *, int);
395
396void rip_peer_init ();
397void rip_peer_update (struct sockaddr_in *, u_char);
398void rip_peer_bad_route (struct sockaddr_in *);
399void rip_peer_bad_packet (struct sockaddr_in *);
400void rip_peer_display (struct vty *);
401struct rip_peer *rip_peer_lookup (struct in_addr *);
402struct rip_peer *rip_peer_lookup_next (struct in_addr *);
403
404int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *);
405int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *);
406void rip_offset_clean ();
407
408void rip_info_free (struct rip_info *);
409u_char rip_distance_apply (struct rip_info *);
410void rip_redistribute_clean ();
411void rip_ifaddr_add (struct interface *, struct connected *);
412void rip_ifaddr_delete (struct interface *, struct connected *);
413
414/* There is only one rip strucutre. */
415extern struct rip *rip;
416
417/* Master thread strucutre. */
418extern struct thread_master *master;
419
420/* RIP statistics for SNMP. */
421extern long rip_global_route_changes;
422extern long rip_global_queries;
423
424#endif /* _ZEBRA_RIP_H */