1 /* RIP related values and structures.
2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
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
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.
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
27 #include "rip_memory.h"
29 /* RIP version number. */
32 /* N.B. stuff will break if
33 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
36 /* RIP command list. */
38 #define RIP_RESPONSE 2
39 #define RIP_TRACEON 3 /* Obsolete */
40 #define RIP_TRACEOFF 4 /* Obsolete */
42 #define RIP_POLL_ENTRY 6
43 #define RIP_COMMAND_MAX 7
45 /* RIP metric infinity value.*/
46 #define RIP_METRIC_INFINITY 16
48 /* Normal RIP packet min and max size. */
49 #define RIP_PACKET_MINSIZ 4
50 #define RIP_PACKET_MAXSIZ 512
52 #define RIP_HEADER_SIZE 4
53 #define RIP_RTE_SIZE 20
55 /* Max count of routing table entry in one rip packet. */
56 #define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
58 /* RIP version 2 multicast address. */
59 #ifndef INADDR_RIP_GROUP
60 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
64 #define RIP_UPDATE_TIMER_DEFAULT 30
65 #define RIP_TIMEOUT_TIMER_DEFAULT 180
66 #define RIP_GARBAGE_TIMER_DEFAULT 120
68 /* RIP peer timeout value. */
69 #define RIP_PEER_TIMER_DEFAULT 180
71 /* RIP port number. */
72 #define RIP_PORT_DEFAULT 520
73 #define RIP_VTY_PORT 2602
75 /* Default configuration file name. */
76 #define RIPD_DEFAULT_CONFIG "ripd.conf"
78 /* RIP route types. */
79 #define RIP_ROUTE_RTE 0
80 #define RIP_ROUTE_STATIC 1
81 #define RIP_ROUTE_DEFAULT 2
82 #define RIP_ROUTE_REDISTRIBUTE 3
83 #define RIP_ROUTE_INTERFACE 4
85 /* RIPv2 special RTE family types */
86 #define RIP_FAMILY_AUTH 0xffff
88 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
90 #define RIP_AUTH_DATA 1
91 #define RIP_AUTH_SIMPLE_PASSWORD 2
92 #define RIP_AUTH_MD5 3
94 /* RIPv2 Simple authentication */
95 #define RIP_AUTH_SIMPLE_SIZE 16
97 /* RIPv2 MD5 authentication. */
98 #define RIP_AUTH_MD5_SIZE 16
99 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
107 /* Default version of rip instance. */
108 int version_send
; /* version 1 or 2 (but not both) */
109 int version_recv
; /* version 1 or 2 or both */
111 /* Output buffer of RIP. */
114 /* RIP routing information base. */
115 struct route_table
*table
;
117 /* RIP only static routing information. */
118 struct route_table
*route
;
121 struct route_table
*neighbor
;
124 struct thread
*t_read
;
126 /* Update and garbage timer. */
127 struct thread
*t_update
;
129 /* Triggered update hack. */
131 struct thread
*t_triggered_update
;
132 struct thread
*t_triggered_interval
;
134 /* RIP timer values. */
135 unsigned long update_time
;
136 unsigned long timeout_time
;
137 unsigned long garbage_time
;
139 /* RIP default metric. */
142 /* RIP default-information originate. */
143 u_char default_information
;
144 char *default_information_route_map
;
146 /* RIP default distance. */
148 struct route_table
*distance_table
;
153 /* For redistribute route map. */
157 struct route_map
*map
;
160 } route_map
[ZEBRA_ROUTE_MAX
];
164 DECLARE_QOBJ_TYPE(rip
)
166 /* RIP routing table entry which belong to rip_packet. */
169 u_int16_t family
; /* Address family of this route. */
170 u_int16_t tag
; /* Route Tag which included in RIP2 packet. */
171 struct in_addr prefix
; /* Prefix of rip route. */
172 struct in_addr mask
; /* Netmask of rip route. */
173 struct in_addr nexthop
; /* Next hop of rip route. */
174 u_int32_t metric
; /* Metric value of rip route. */
177 /* RIP packet structure. */
180 unsigned char command
; /* Command type of RIP packet. */
181 unsigned char version
; /* RIP version which coming from peer. */
182 unsigned char pad1
; /* Padding of RIP packet header. */
183 unsigned char pad2
; /* Same as above. */
184 struct rte rte
[1]; /* Address structure. */
187 /* Buffer to read RIP packet. */
190 struct rip_packet rip_packet
;
191 char buf
[RIP_PACKET_MAXSIZ
];
194 /* RIP route information. */
197 /* This route's type. */
204 struct in_addr nexthop
;
207 /* Which interface does this route come from. */
210 /* Metric of this route. */
213 /* External metric of this route.
214 if learnt from an externalm proto */
215 u_int32_t external_metric
;
217 /* Tag information of this route. */
220 /* Flags of RIP route. */
221 #define RIP_RTF_FIB 1
222 #define RIP_RTF_CHANGED 2
225 /* Garbage collect timer. */
226 struct thread
*t_timeout
;
227 struct thread
*t_garbage_collect
;
229 /* Route-map futures - this variables can be changed. */
230 struct in_addr nexthop_out
;
232 u_int32_t metric_out
;
234 ifindex_t ifindex_out
;
236 struct route_node
*rp
;
241 struct rip_info
*next
;
242 struct rip_info
*prev
;
243 #endif /* NEW_RIP_TABLE */
247 RIP_NO_SPLIT_HORIZON
= 0,
249 RIP_SPLIT_HORIZON_POISONED_REVERSE
250 } split_horizon_policy_t
;
252 /* RIP specific interface configuration. */
255 /* RIP is enabled on this interface. */
257 int enable_interface
;
259 /* RIP is running on this interface. */
262 /* RIP version control. */
266 /* RIPv2 broadcast mode */
269 /* RIPv2 authentication type. */
272 /* RIPv2 authentication string. */
275 /* RIPv2 authentication key chain. */
278 /* value to use for md5->auth_len */
279 u_int8_t md5_auth_len
;
281 /* Split horizon flag. */
282 split_horizon_policy_t split_horizon
;
283 split_horizon_policy_t split_horizon_default
;
285 /* For filter type slot. */
286 #define RIP_FILTER_IN 0
287 #define RIP_FILTER_OUT 1
288 #define RIP_FILTER_MAX 2
291 struct access_list
*list
[RIP_FILTER_MAX
];
294 struct prefix_list
*prefix
[RIP_FILTER_MAX
];
297 struct route_map
*routemap
[RIP_FILTER_MAX
];
299 /* Wake up thread. */
300 struct thread
*t_wakeup
;
302 /* Interface statistics. */
307 /* Passive interface. */
311 /* RIP peer information. */
317 /* Peer RIP tag value. */
320 /* Last update time. */
323 /* Peer RIP version. */
330 /* Timeout thread. */
331 struct thread
*t_timeout
;
338 u_int16_t packet_len
;
353 /* RIP accepet/announce methods. */
354 #define RI_RIP_UNSPEC 0
355 #define RI_RIP_VERSION_1 1
356 #define RI_RIP_VERSION_2 2
357 #define RI_RIP_VERSION_1_AND_2 3
358 #define RI_RIP_VERSION_NONE 4
359 /* N.B. stuff will break if
360 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
362 /* Default value for "default-metric" command. */
363 #define RIP_DEFAULT_METRIC_DEFAULT 1
370 RIP_TRIGGERED_UPDATE
,
373 /* Macro for timer turn on. */
374 #define RIP_TIMER_ON(T,F,V) \
377 (T) = thread_add_timer (master, (F), rinfo, (V)); \
380 /* Macro for timer turn off. */
381 #define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
384 extern void rip_init (void);
385 extern void rip_reset (void);
386 extern void rip_clean (void);
387 extern void rip_clean_network (void);
388 extern void rip_interfaces_clean (void);
389 extern void rip_interfaces_reset (void);
390 extern void rip_passive_nondefault_clean (void);
391 extern void rip_if_init (void);
392 extern void rip_if_down_all (void);
393 extern void rip_route_map_init (void);
394 extern void rip_route_map_reset (void);
395 extern void rip_zclient_init(struct thread_master
*);
396 extern void rip_zclient_reset (void);
397 extern void rip_offset_init (void);
398 extern int if_check_address (struct in_addr addr
);
400 extern int rip_request_send (struct sockaddr_in
*, struct interface
*, u_char
,
402 extern int rip_neighbor_lookup (struct sockaddr_in
*);
404 extern int rip_redistribute_check (int);
405 extern void rip_redistribute_add (int, int, struct prefix_ipv4
*, ifindex_t
,
406 struct in_addr
*, unsigned int, unsigned char,
408 extern void rip_redistribute_delete (int, int, struct prefix_ipv4
*, ifindex_t
);
409 extern void rip_redistribute_withdraw (int);
410 extern void rip_zebra_ipv4_add (struct route_node
*);
411 extern void rip_zebra_ipv4_delete (struct route_node
*);
412 extern void rip_interface_multicast_set (int, struct connected
*);
413 extern void rip_distribute_update_interface (struct interface
*);
414 extern void rip_if_rmap_update_interface (struct interface
*);
416 extern int config_write_rip_network (struct vty
*, int);
417 extern int config_write_rip_offset_list (struct vty
*);
418 extern int config_write_rip_redistribute (struct vty
*, int);
420 extern void rip_peer_init (void);
421 extern void rip_peer_update (struct sockaddr_in
*, u_char
);
422 extern void rip_peer_bad_route (struct sockaddr_in
*);
423 extern void rip_peer_bad_packet (struct sockaddr_in
*);
424 extern void rip_peer_display (struct vty
*);
425 extern struct rip_peer
*rip_peer_lookup (struct in_addr
*);
426 extern struct rip_peer
*rip_peer_lookup_next (struct in_addr
*);
428 extern int rip_offset_list_apply_in (struct prefix_ipv4
*, struct interface
*, u_int32_t
*);
429 extern int rip_offset_list_apply_out (struct prefix_ipv4
*, struct interface
*, u_int32_t
*);
430 extern void rip_offset_clean (void);
432 extern void rip_info_free (struct rip_info
*);
433 extern u_char
rip_distance_apply (struct rip_info
*);
434 extern void rip_redistribute_clean (void);
436 extern struct rip_info
*rip_ecmp_add (struct rip_info
*);
437 extern struct rip_info
*rip_ecmp_replace (struct rip_info
*);
438 extern struct rip_info
*rip_ecmp_delete (struct rip_info
*);
440 /* There is only one rip strucutre. */
441 extern struct rip
*rip
;
443 /* Master thread strucutre. */
444 extern struct thread_master
*master
;
446 /* RIP statistics for SNMP. */
447 extern long rip_global_route_changes
;
448 extern long rip_global_queries
;
450 DECLARE_HOOK(rip_ifaddr_add
, (struct connected
*ifc
), (ifc
))
451 DECLARE_HOOK(rip_ifaddr_del
, (struct connected
*ifc
), (ifc
))
453 #endif /* _ZEBRA_RIP_H */