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