blob: a768ccc6adb2132991da5f0646457c308a6e8747 [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. */
Lu Feng342a31b2014-06-25 07:43:15 +000052#define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
paul718e3742002-12-13 20:15:29 +000053
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
paulca5e5162004-06-06 22:06:33 +000081/* 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
paulb14ee002005-02-04 23:42:41 +000090/* RIPv2 Simple authentication */
91#define RIP_AUTH_SIMPLE_SIZE 16
92
paulca5e5162004-06-06 22:06:33 +000093/* RIPv2 MD5 authentication. */
paul718e3742002-12-13 20:15:29 +000094#define RIP_AUTH_MD5_SIZE 16
paulca5e5162004-06-06 22:06:33 +000095#define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
paul718e3742002-12-13 20:15:29 +000096
97/* RIP structure. */
98struct rip
99{
100 /* RIP socket. */
101 int sock;
102
103 /* Default version of rip instance. */
paulf38a4712003-06-07 01:10:00 +0000104 int version_send; /* version 1 or 2 (but not both) */
105 int version_recv; /* version 1 or 2 or both */
paul718e3742002-12-13 20:15:29 +0000106
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
Lu Feng0b74a0a2014-07-18 06:13:19 +0000146 /* RIP ECMP flag */
147 unsigned int ecmp;
148
paul718e3742002-12-13 20:15:29 +0000149 /* For redistribute route map. */
150 struct
151 {
152 char *name;
153 struct route_map *map;
154 int metric_config;
155 u_int32_t metric;
156 } route_map[ZEBRA_ROUTE_MAX];
157};
158
159/* RIP routing table entry which belong to rip_packet. */
160struct rte
161{
162 u_int16_t family; /* Address family of this route. */
163 u_int16_t tag; /* Route Tag which included in RIP2 packet. */
164 struct in_addr prefix; /* Prefix of rip route. */
165 struct in_addr mask; /* Netmask of rip route. */
166 struct in_addr nexthop; /* Next hop of rip route. */
167 u_int32_t metric; /* Metric value of rip route. */
168};
169
170/* RIP packet structure. */
171struct rip_packet
172{
173 unsigned char command; /* Command type of RIP packet. */
174 unsigned char version; /* RIP version which coming from peer. */
175 unsigned char pad1; /* Padding of RIP packet header. */
176 unsigned char pad2; /* Same as above. */
177 struct rte rte[1]; /* Address structure. */
178};
179
180/* Buffer to read RIP packet. */
181union rip_buf
182{
183 struct rip_packet rip_packet;
184 char buf[RIP_PACKET_MAXSIZ];
185};
186
187/* RIP route information. */
188struct rip_info
189{
190 /* This route's type. */
191 int type;
192
193 /* Sub type. */
194 int sub_type;
195
196 /* RIP nexthop. */
197 struct in_addr nexthop;
198 struct in_addr from;
199
200 /* Which interface does this route come from. */
201 unsigned int ifindex;
202
203 /* Metric of this route. */
204 u_int32_t metric;
205
vincentfbf5d032005-09-29 11:25:50 +0000206 /* External metric of this route.
207 if learnt from an externalm proto */
208 u_int32_t external_metric;
209
paul718e3742002-12-13 20:15:29 +0000210 /* Tag information of this route. */
211 u_int16_t tag;
212
213 /* Flags of RIP route. */
214#define RIP_RTF_FIB 1
215#define RIP_RTF_CHANGED 2
216 u_char flags;
217
218 /* Garbage collect timer. */
219 struct thread *t_timeout;
220 struct thread *t_garbage_collect;
221
222 /* Route-map futures - this variables can be changed. */
223 struct in_addr nexthop_out;
224 u_char metric_set;
225 u_int32_t metric_out;
hasso16705132003-05-25 14:49:19 +0000226 u_short tag_out;
paul718e3742002-12-13 20:15:29 +0000227 unsigned int ifindex_out;
228
229 struct route_node *rp;
230
231 u_char distance;
232
233#ifdef NEW_RIP_TABLE
234 struct rip_info *next;
235 struct rip_info *prev;
236#endif /* NEW_RIP_TABLE */
237};
238
hasso16705132003-05-25 14:49:19 +0000239typedef enum {
240 RIP_NO_SPLIT_HORIZON = 0,
241 RIP_SPLIT_HORIZON,
242 RIP_SPLIT_HORIZON_POISONED_REVERSE
243} split_horizon_policy_t;
244
paul718e3742002-12-13 20:15:29 +0000245/* RIP specific interface configuration. */
246struct rip_interface
247{
248 /* RIP is enabled on this interface. */
249 int enable_network;
250 int enable_interface;
251
252 /* RIP is running on this interface. */
253 int running;
254
255 /* RIP version control. */
256 int ri_send;
257 int ri_receive;
258
259 /* RIPv2 authentication type. */
paul718e3742002-12-13 20:15:29 +0000260 int auth_type;
261
262 /* RIPv2 authentication string. */
263 char *auth_str;
264
265 /* RIPv2 authentication key chain. */
266 char *key_chain;
267
paulca5e5162004-06-06 22:06:33 +0000268 /* value to use for md5->auth_len */
269 u_int8_t md5_auth_len;
270
paul718e3742002-12-13 20:15:29 +0000271 /* Split horizon flag. */
hasso16705132003-05-25 14:49:19 +0000272 split_horizon_policy_t split_horizon;
273 split_horizon_policy_t split_horizon_default;
paul718e3742002-12-13 20:15:29 +0000274
275 /* For filter type slot. */
276#define RIP_FILTER_IN 0
277#define RIP_FILTER_OUT 1
278#define RIP_FILTER_MAX 2
279
280 /* Access-list. */
281 struct access_list *list[RIP_FILTER_MAX];
282
283 /* Prefix-list. */
284 struct prefix_list *prefix[RIP_FILTER_MAX];
285
hasso16705132003-05-25 14:49:19 +0000286 /* Route-map. */
287 struct route_map *routemap[RIP_FILTER_MAX];
288
paul718e3742002-12-13 20:15:29 +0000289 /* Wake up thread. */
290 struct thread *t_wakeup;
291
292 /* Interface statistics. */
293 int recv_badpackets;
294 int recv_badroutes;
295 int sent_updates;
296
297 /* Passive interface. */
298 int passive;
299};
300
301/* RIP peer information. */
302struct rip_peer
303{
304 /* Peer address. */
305 struct in_addr addr;
306
307 /* Peer RIP tag value. */
308 int domain;
309
310 /* Last update time. */
311 time_t uptime;
312
313 /* Peer RIP version. */
314 u_char version;
315
316 /* Statistics. */
317 int recv_badpackets;
318 int recv_badroutes;
319
320 /* Timeout thread. */
321 struct thread *t_timeout;
322};
323
324struct rip_md5_info
325{
326 u_int16_t family;
327 u_int16_t type;
328 u_int16_t packet_len;
329 u_char keyid;
330 u_char auth_len;
331 u_int32_t sequence;
332 u_int32_t reserv1;
333 u_int32_t reserv2;
334};
335
336struct rip_md5_data
337{
338 u_int16_t family;
339 u_int16_t type;
340 u_char digest[16];
341};
342
343/* RIP accepet/announce methods. */
344#define RI_RIP_UNSPEC 0
345#define RI_RIP_VERSION_1 1
346#define RI_RIP_VERSION_2 2
347#define RI_RIP_VERSION_1_AND_2 3
paulf38a4712003-06-07 01:10:00 +0000348/* N.B. stuff will break if
349 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
paul718e3742002-12-13 20:15:29 +0000350
351/* Default value for "default-metric" command. */
352#define RIP_DEFAULT_METRIC_DEFAULT 1
353
354/* RIP event. */
355enum rip_event
356{
357 RIP_READ,
358 RIP_UPDATE_EVENT,
359 RIP_TRIGGERED_UPDATE,
360};
361
362/* Macro for timer turn on. */
363#define RIP_TIMER_ON(T,F,V) \
364 do { \
365 if (!(T)) \
366 (T) = thread_add_timer (master, (F), rinfo, (V)); \
367 } while (0)
368
369/* Macro for timer turn off. */
370#define RIP_TIMER_OFF(X) \
371 do { \
372 if (X) \
373 { \
374 thread_cancel (X); \
375 (X) = NULL; \
376 } \
377 } while (0)
378
379/* Prototypes. */
pauldc63bfd2005-10-25 23:31:05 +0000380extern void rip_init (void);
381extern void rip_reset (void);
382extern void rip_clean (void);
383extern void rip_clean_network (void);
384extern void rip_interface_clean (void);
385extern void rip_interface_reset (void);
386extern void rip_passive_nondefault_clean (void);
387extern void rip_if_init (void);
388extern void rip_if_down_all (void);
389extern void rip_route_map_init (void);
390extern void rip_route_map_reset (void);
391extern void rip_snmp_init (void);
Donald Sharp71252932015-09-24 09:25:19 -0400392extern void rip_zclient_init (struct thread_master *);
pauldc63bfd2005-10-25 23:31:05 +0000393extern void rip_zclient_start (void);
394extern void rip_zclient_reset (void);
395extern void rip_offset_init (void);
396extern int if_check_address (struct in_addr addr);
paul718e3742002-12-13 20:15:29 +0000397
pauldc63bfd2005-10-25 23:31:05 +0000398extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char,
paul931cd542004-01-23 15:31:42 +0000399 struct connected *);
pauldc63bfd2005-10-25 23:31:05 +0000400extern int rip_neighbor_lookup (struct sockaddr_in *);
Stephen Hemminger2c239702009-12-10 19:16:05 +0300401
402extern int rip_redistribute_check (int);
pauldc63bfd2005-10-25 23:31:05 +0000403extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int,
vincentfbf5d032005-09-29 11:25:50 +0000404 struct in_addr *, unsigned int, unsigned char);
pauldc63bfd2005-10-25 23:31:05 +0000405extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int);
406extern void rip_redistribute_withdraw (int);
Lu Fengb397cf42014-07-18 06:13:18 +0000407extern void rip_zebra_ipv4_add (struct route_node *);
408extern void rip_zebra_ipv4_delete (struct route_node *);
pauldc63bfd2005-10-25 23:31:05 +0000409extern void rip_interface_multicast_set (int, struct connected *);
410extern void rip_distribute_update_interface (struct interface *);
411extern void rip_if_rmap_update_interface (struct interface *);
paul718e3742002-12-13 20:15:29 +0000412
pauldc63bfd2005-10-25 23:31:05 +0000413extern int config_write_rip_network (struct vty *, int);
414extern int config_write_rip_offset_list (struct vty *);
415extern int config_write_rip_redistribute (struct vty *, int);
paul718e3742002-12-13 20:15:29 +0000416
pauldc63bfd2005-10-25 23:31:05 +0000417extern void rip_peer_init (void);
418extern void rip_peer_update (struct sockaddr_in *, u_char);
419extern void rip_peer_bad_route (struct sockaddr_in *);
420extern void rip_peer_bad_packet (struct sockaddr_in *);
421extern void rip_peer_display (struct vty *);
422extern struct rip_peer *rip_peer_lookup (struct in_addr *);
423extern struct rip_peer *rip_peer_lookup_next (struct in_addr *);
paul718e3742002-12-13 20:15:29 +0000424
pauldc63bfd2005-10-25 23:31:05 +0000425extern int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *);
426extern int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *);
427extern void rip_offset_clean (void);
paul718e3742002-12-13 20:15:29 +0000428
pauldc63bfd2005-10-25 23:31:05 +0000429extern void rip_info_free (struct rip_info *);
430extern u_char rip_distance_apply (struct rip_info *);
431extern void rip_redistribute_clean (void);
432extern void rip_ifaddr_add (struct interface *, struct connected *);
433extern void rip_ifaddr_delete (struct interface *, struct connected *);
paul718e3742002-12-13 20:15:29 +0000434
Lu Fengb397cf42014-07-18 06:13:18 +0000435extern struct rip_info *rip_ecmp_add (struct rip_info *);
436extern struct rip_info *rip_ecmp_replace (struct rip_info *);
437extern struct rip_info *rip_ecmp_delete (struct rip_info *);
438
paul718e3742002-12-13 20:15:29 +0000439/* There is only one rip strucutre. */
440extern struct rip *rip;
441
442/* Master thread strucutre. */
443extern struct thread_master *master;
444
445/* RIP statistics for SNMP. */
446extern long rip_global_route_changes;
447extern long rip_global_queries;
paul718e3742002-12-13 20:15:29 +0000448#endif /* _ZEBRA_RIP_H */