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