[cleanup] Make command nodes static
[jleu-quagga.git] / ripd / ripd.h
blob4d0c04e2f846329ba807b9411862e2b9ac976aba
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
9 * later version.
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
19 * 02111-1307, USA.
22 #ifndef _ZEBRA_RIP_H
23 #define _ZEBRA_RIP_H
25 /* RIP version number. */
26 #define RIPv1 1
27 #define RIPv2 2
28 /* N.B. stuff will break if
29 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
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
41 /* RIP metric infinity value.*/
42 #define RIP_METRIC_INFINITY 16
44 /* Normal RIP packet min and max size. */
45 #define RIP_PACKET_MINSIZ 4
46 #define RIP_PACKET_MAXSIZ 512
48 #define RIP_HEADER_SIZE 4
49 #define RIP_RTE_SIZE 20
51 /* Max count of routing table entry in one rip packet. */
52 #define RIP_MAX_RTE 25
54 /* RIP version 2 multicast address. */
55 #ifndef INADDR_RIP_GROUP
56 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
57 #endif
59 /* RIP timers */
60 #define RIP_UPDATE_TIMER_DEFAULT 30
61 #define RIP_TIMEOUT_TIMER_DEFAULT 180
62 #define RIP_GARBAGE_TIMER_DEFAULT 120
64 /* RIP peer timeout value. */
65 #define RIP_PEER_TIMER_DEFAULT 180
67 /* RIP port number. */
68 #define RIP_PORT_DEFAULT 520
69 #define RIP_VTY_PORT 2602
71 /* Default configuration file name. */
72 #define RIPD_DEFAULT_CONFIG "ripd.conf"
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
81 /* RIPv2 special RTE family types */
82 #define RIP_FAMILY_AUTH 0xffff
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
90 /* RIPv2 Simple authentication */
91 #define RIP_AUTH_SIMPLE_SIZE 16
93 /* RIPv2 MD5 authentication. */
94 #define RIP_AUTH_MD5_SIZE 16
95 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
97 /* RIP structure. */
98 struct rip
100 /* RIP socket. */
101 int sock;
103 /* Default version of rip instance. */
104 int version_send; /* version 1 or 2 (but not both) */
105 int version_recv; /* version 1 or 2 or both */
107 /* Output buffer of RIP. */
108 struct stream *obuf;
110 /* RIP routing information base. */
111 struct route_table *table;
113 /* RIP only static routing information. */
114 struct route_table *route;
116 /* RIP neighbor. */
117 struct route_table *neighbor;
119 /* RIP threads. */
120 struct thread *t_read;
122 /* Update and garbage timer. */
123 struct thread *t_update;
125 /* Triggered update hack. */
126 int trigger;
127 struct thread *t_triggered_update;
128 struct thread *t_triggered_interval;
130 /* RIP timer values. */
131 unsigned long update_time;
132 unsigned long timeout_time;
133 unsigned long garbage_time;
135 /* RIP default metric. */
136 int default_metric;
138 /* RIP default-information originate. */
139 u_char default_information;
140 char *default_information_route_map;
142 /* RIP default distance. */
143 u_char distance;
144 struct route_table *distance_table;
146 /* For redistribute route map. */
147 struct
149 char *name;
150 struct route_map *map;
151 int metric_config;
152 u_int32_t metric;
153 } route_map[ZEBRA_ROUTE_MAX];
156 /* RIP routing table entry which belong to rip_packet. */
157 struct rte
159 u_int16_t family; /* Address family of this route. */
160 u_int16_t tag; /* Route Tag which included in RIP2 packet. */
161 struct in_addr prefix; /* Prefix of rip route. */
162 struct in_addr mask; /* Netmask of rip route. */
163 struct in_addr nexthop; /* Next hop of rip route. */
164 u_int32_t metric; /* Metric value of rip route. */
167 /* RIP packet structure. */
168 struct rip_packet
170 unsigned char command; /* Command type of RIP packet. */
171 unsigned char version; /* RIP version which coming from peer. */
172 unsigned char pad1; /* Padding of RIP packet header. */
173 unsigned char pad2; /* Same as above. */
174 struct rte rte[1]; /* Address structure. */
177 /* Buffer to read RIP packet. */
178 union rip_buf
180 struct rip_packet rip_packet;
181 char buf[RIP_PACKET_MAXSIZ];
184 /* RIP route information. */
185 struct rip_info
187 /* This route's type. */
188 int type;
190 /* Sub type. */
191 int sub_type;
193 /* RIP nexthop. */
194 struct in_addr nexthop;
195 struct in_addr from;
197 /* Which interface does this route come from. */
198 unsigned int ifindex;
200 /* Metric of this route. */
201 u_int32_t metric;
203 /* External metric of this route.
204 if learnt from an externalm proto */
205 u_int32_t external_metric;
207 /* Tag information of this route. */
208 u_int16_t tag;
210 /* Flags of RIP route. */
211 #define RIP_RTF_FIB 1
212 #define RIP_RTF_CHANGED 2
213 u_char flags;
215 /* Garbage collect timer. */
216 struct thread *t_timeout;
217 struct thread *t_garbage_collect;
219 /* Route-map futures - this variables can be changed. */
220 struct in_addr nexthop_out;
221 u_char metric_set;
222 u_int32_t metric_out;
223 u_short tag_out;
224 unsigned int ifindex_out;
226 struct route_node *rp;
228 u_char distance;
230 #ifdef NEW_RIP_TABLE
231 struct rip_info *next;
232 struct rip_info *prev;
233 #endif /* NEW_RIP_TABLE */
236 typedef enum {
237 RIP_NO_SPLIT_HORIZON = 0,
238 RIP_SPLIT_HORIZON,
239 RIP_SPLIT_HORIZON_POISONED_REVERSE
240 } split_horizon_policy_t;
242 /* RIP specific interface configuration. */
243 struct rip_interface
245 /* RIP is enabled on this interface. */
246 int enable_network;
247 int enable_interface;
249 /* RIP is running on this interface. */
250 int running;
252 /* RIP version control. */
253 int ri_send;
254 int ri_receive;
256 /* RIPv2 authentication type. */
257 int auth_type;
259 /* RIPv2 authentication string. */
260 char *auth_str;
262 /* RIPv2 authentication key chain. */
263 char *key_chain;
265 /* value to use for md5->auth_len */
266 u_int8_t md5_auth_len;
268 /* Split horizon flag. */
269 split_horizon_policy_t split_horizon;
270 split_horizon_policy_t split_horizon_default;
272 /* For filter type slot. */
273 #define RIP_FILTER_IN 0
274 #define RIP_FILTER_OUT 1
275 #define RIP_FILTER_MAX 2
277 /* Access-list. */
278 struct access_list *list[RIP_FILTER_MAX];
280 /* Prefix-list. */
281 struct prefix_list *prefix[RIP_FILTER_MAX];
283 /* Route-map. */
284 struct route_map *routemap[RIP_FILTER_MAX];
286 /* Wake up thread. */
287 struct thread *t_wakeup;
289 /* Interface statistics. */
290 int recv_badpackets;
291 int recv_badroutes;
292 int sent_updates;
294 /* Passive interface. */
295 int passive;
298 /* RIP peer information. */
299 struct rip_peer
301 /* Peer address. */
302 struct in_addr addr;
304 /* Peer RIP tag value. */
305 int domain;
307 /* Last update time. */
308 time_t uptime;
310 /* Peer RIP version. */
311 u_char version;
313 /* Statistics. */
314 int recv_badpackets;
315 int recv_badroutes;
317 /* Timeout thread. */
318 struct thread *t_timeout;
321 struct rip_md5_info
323 u_int16_t family;
324 u_int16_t type;
325 u_int16_t packet_len;
326 u_char keyid;
327 u_char auth_len;
328 u_int32_t sequence;
329 u_int32_t reserv1;
330 u_int32_t reserv2;
333 struct rip_md5_data
335 u_int16_t family;
336 u_int16_t type;
337 u_char digest[16];
340 /* RIP accepet/announce methods. */
341 #define RI_RIP_UNSPEC 0
342 #define RI_RIP_VERSION_1 1
343 #define RI_RIP_VERSION_2 2
344 #define RI_RIP_VERSION_1_AND_2 3
345 /* N.B. stuff will break if
346 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
348 /* Default value for "default-metric" command. */
349 #define RIP_DEFAULT_METRIC_DEFAULT 1
351 /* RIP event. */
352 enum rip_event
354 RIP_READ,
355 RIP_UPDATE_EVENT,
356 RIP_TRIGGERED_UPDATE,
359 /* Macro for timer turn on. */
360 #define RIP_TIMER_ON(T,F,V) \
361 do { \
362 if (!(T)) \
363 (T) = thread_add_timer (master, (F), rinfo, (V)); \
364 } while (0)
366 /* Macro for timer turn off. */
367 #define RIP_TIMER_OFF(X) \
368 do { \
369 if (X) \
371 thread_cancel (X); \
372 (X) = NULL; \
374 } while (0)
376 /* Prototypes. */
377 extern void rip_init (void);
378 extern void rip_reset (void);
379 extern void rip_clean (void);
380 extern void rip_clean_network (void);
381 extern void rip_interface_clean (void);
382 extern void rip_interface_reset (void);
383 extern void rip_passive_nondefault_clean (void);
384 extern void rip_if_init (void);
385 extern void rip_if_down_all (void);
386 extern void rip_route_map_init (void);
387 extern void rip_route_map_reset (void);
388 extern void rip_snmp_init (void);
389 extern void rip_zclient_init (void);
390 extern void rip_zclient_start (void);
391 extern void rip_zclient_reset (void);
392 extern void rip_offset_init (void);
393 extern int if_check_address (struct in_addr addr);
395 extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char,
396 struct connected *);
397 extern int rip_neighbor_lookup (struct sockaddr_in *);
398 extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int,
399 struct in_addr *, unsigned int, unsigned char);
400 extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int);
401 extern void rip_redistribute_withdraw (int);
402 extern void rip_zebra_ipv4_add (struct prefix_ipv4 *, struct in_addr *, u_int32_t, u_char);
403 extern void rip_zebra_ipv4_delete (struct prefix_ipv4 *, struct in_addr *, u_int32_t);
404 extern void rip_interface_multicast_set (int, struct connected *);
405 extern void rip_distribute_update_interface (struct interface *);
406 extern void rip_if_rmap_update_interface (struct interface *);
408 extern int config_write_rip_network (struct vty *, int);
409 extern int config_write_rip_offset_list (struct vty *);
410 extern int config_write_rip_redistribute (struct vty *, int);
412 extern void rip_peer_init (void);
413 extern void rip_peer_update (struct sockaddr_in *, u_char);
414 extern void rip_peer_bad_route (struct sockaddr_in *);
415 extern void rip_peer_bad_packet (struct sockaddr_in *);
416 extern void rip_peer_display (struct vty *);
417 extern struct rip_peer *rip_peer_lookup (struct in_addr *);
418 extern struct rip_peer *rip_peer_lookup_next (struct in_addr *);
420 extern int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *);
421 extern int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *);
422 extern void rip_offset_clean (void);
424 extern void rip_info_free (struct rip_info *);
425 extern u_char rip_distance_apply (struct rip_info *);
426 extern void rip_redistribute_clean (void);
427 extern void rip_ifaddr_add (struct interface *, struct connected *);
428 extern void rip_ifaddr_delete (struct interface *, struct connected *);
430 /* There is only one rip strucutre. */
431 extern struct rip *rip;
433 /* Master thread strucutre. */
434 extern struct thread_master *master;
436 /* RIP statistics for SNMP. */
437 extern long rip_global_route_changes;
438 extern long rip_global_queries;
439 #endif /* _ZEBRA_RIP_H */