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