]> git.proxmox.com Git - mirror_frr.git/blob - ripd/ripd.h
debian: add pkg-config to build-depends
[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
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 #include "qobj.h"
26 #include "hook.h"
27 #include "rip_memory.h"
28
29 /* RIP version number. */
30 #define RIPv1 1
31 #define RIPv2 2
32 /* N.B. stuff will break if
33 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
34
35
36 /* RIP command list. */
37 #define RIP_REQUEST 1
38 #define RIP_RESPONSE 2
39 #define RIP_TRACEON 3 /* Obsolete */
40 #define RIP_TRACEOFF 4 /* Obsolete */
41 #define RIP_POLL 5
42 #define RIP_POLL_ENTRY 6
43 #define RIP_COMMAND_MAX 7
44
45 /* RIP metric infinity value.*/
46 #define RIP_METRIC_INFINITY 16
47
48 /* Normal RIP packet min and max size. */
49 #define RIP_PACKET_MINSIZ 4
50 #define RIP_PACKET_MAXSIZ 512
51
52 #define RIP_HEADER_SIZE 4
53 #define RIP_RTE_SIZE 20
54
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)
57
58 /* RIP version 2 multicast address. */
59 #ifndef INADDR_RIP_GROUP
60 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
61 #endif
62
63 /* RIP timers */
64 #define RIP_UPDATE_TIMER_DEFAULT 30
65 #define RIP_TIMEOUT_TIMER_DEFAULT 180
66 #define RIP_GARBAGE_TIMER_DEFAULT 120
67
68 /* RIP peer timeout value. */
69 #define RIP_PEER_TIMER_DEFAULT 180
70
71 /* RIP port number. */
72 #define RIP_PORT_DEFAULT 520
73 #define RIP_VTY_PORT 2602
74
75 /* Default configuration file name. */
76 #define RIPD_DEFAULT_CONFIG "ripd.conf"
77
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
84
85 /* RIPv2 special RTE family types */
86 #define RIP_FAMILY_AUTH 0xffff
87
88 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
89 #define RIP_NO_AUTH 0
90 #define RIP_AUTH_DATA 1
91 #define RIP_AUTH_SIMPLE_PASSWORD 2
92 #define RIP_AUTH_MD5 3
93
94 /* RIPv2 Simple authentication */
95 #define RIP_AUTH_SIMPLE_SIZE 16
96
97 /* RIPv2 MD5 authentication. */
98 #define RIP_AUTH_MD5_SIZE 16
99 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
100
101 /* RIP structure. */
102 struct rip {
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 char *name;
155 struct route_map *map;
156 int metric_config;
157 u_int32_t metric;
158 } route_map[ZEBRA_ROUTE_MAX];
159
160 QOBJ_FIELDS
161 };
162 DECLARE_QOBJ_TYPE(rip)
163
164 /* RIP routing table entry which belong to rip_packet. */
165 struct rte {
166 u_int16_t family; /* Address family of this route. */
167 u_int16_t tag; /* Route Tag which included in RIP2 packet. */
168 struct in_addr prefix; /* Prefix of rip route. */
169 struct in_addr mask; /* Netmask of rip route. */
170 struct in_addr nexthop; /* Next hop of rip route. */
171 u_int32_t metric; /* Metric value of rip route. */
172 };
173
174 /* RIP packet structure. */
175 struct rip_packet {
176 unsigned char command; /* Command type of RIP packet. */
177 unsigned char version; /* RIP version which coming from peer. */
178 unsigned char pad1; /* Padding of RIP packet header. */
179 unsigned char pad2; /* Same as above. */
180 struct rte rte[1]; /* Address structure. */
181 };
182
183 /* Buffer to read RIP packet. */
184 union rip_buf {
185 struct rip_packet rip_packet;
186 char buf[RIP_PACKET_MAXSIZ];
187 };
188
189 /* RIP route information. */
190 struct rip_info {
191 /* This route's type. */
192 int type;
193
194 /* Sub type. */
195 int sub_type;
196
197 /* RIP nexthop. */
198 struct in_addr nexthop;
199 struct in_addr from;
200
201 /* Which interface does this route come from. */
202 ifindex_t ifindex;
203
204 /* Metric of this route. */
205 u_int32_t metric;
206
207 /* External metric of this route.
208 if learnt from an externalm proto */
209 u_int32_t external_metric;
210
211 /* Tag information of this route. */
212 u_int16_t tag;
213
214 /* Flags of RIP route. */
215 #define RIP_RTF_FIB 1
216 #define RIP_RTF_CHANGED 2
217 u_char flags;
218
219 /* Garbage collect timer. */
220 struct thread *t_timeout;
221 struct thread *t_garbage_collect;
222
223 /* Route-map futures - this variables can be changed. */
224 struct in_addr nexthop_out;
225 u_char metric_set;
226 u_int32_t metric_out;
227 u_int16_t tag_out;
228 ifindex_t ifindex_out;
229
230 struct route_node *rp;
231
232 u_char distance;
233
234 #ifdef NEW_RIP_TABLE
235 struct rip_info *next;
236 struct rip_info *prev;
237 #endif /* NEW_RIP_TABLE */
238 };
239
240 typedef enum {
241 RIP_NO_SPLIT_HORIZON = 0,
242 RIP_SPLIT_HORIZON,
243 RIP_SPLIT_HORIZON_POISONED_REVERSE
244 } split_horizon_policy_t;
245
246 /* RIP specific interface configuration. */
247 struct rip_interface {
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 broadcast mode */
260 int v2_broadcast;
261
262 /* RIPv2 authentication type. */
263 int auth_type;
264
265 /* RIPv2 authentication string. */
266 char *auth_str;
267
268 /* RIPv2 authentication key chain. */
269 char *key_chain;
270
271 /* value to use for md5->auth_len */
272 u_int8_t md5_auth_len;
273
274 /* Split horizon flag. */
275 split_horizon_policy_t split_horizon;
276 split_horizon_policy_t split_horizon_default;
277
278 /* For filter type slot. */
279 #define RIP_FILTER_IN 0
280 #define RIP_FILTER_OUT 1
281 #define RIP_FILTER_MAX 2
282
283 /* Access-list. */
284 struct access_list *list[RIP_FILTER_MAX];
285
286 /* Prefix-list. */
287 struct prefix_list *prefix[RIP_FILTER_MAX];
288
289 /* Route-map. */
290 struct route_map *routemap[RIP_FILTER_MAX];
291
292 /* Wake up thread. */
293 struct thread *t_wakeup;
294
295 /* Interface statistics. */
296 int recv_badpackets;
297 int recv_badroutes;
298 int sent_updates;
299
300 /* Passive interface. */
301 int passive;
302 };
303
304 /* RIP peer information. */
305 struct rip_peer {
306 /* Peer address. */
307 struct in_addr addr;
308
309 /* Peer RIP tag value. */
310 int domain;
311
312 /* Last update time. */
313 time_t uptime;
314
315 /* Peer RIP version. */
316 u_char version;
317
318 /* Statistics. */
319 int recv_badpackets;
320 int recv_badroutes;
321
322 /* Timeout thread. */
323 struct thread *t_timeout;
324 };
325
326 struct rip_md5_info {
327 u_int16_t family;
328 u_int16_t type;
329 u_int16_t packet_len;
330 u_char keyid;
331 u_char auth_len;
332 u_int32_t sequence;
333 u_int32_t reserv1;
334 u_int32_t reserv2;
335 };
336
337 struct rip_md5_data {
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
348 #define RI_RIP_VERSION_NONE 4
349 /* N.B. stuff will break if
350 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
351
352 /* Default value for "default-metric" command. */
353 #define RIP_DEFAULT_METRIC_DEFAULT 1
354
355 /* RIP event. */
356 enum rip_event {
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) THREAD_TIMER_OFF(X)
371
372 /* Prototypes. */
373 extern void rip_init(void);
374 extern void rip_reset(void);
375 extern void rip_clean(void);
376 extern void rip_clean_network(void);
377 extern void rip_interfaces_clean(void);
378 extern void rip_interfaces_reset(void);
379 extern void rip_passive_nondefault_clean(void);
380 extern void rip_if_init(void);
381 extern void rip_if_down_all(void);
382 extern void rip_route_map_init(void);
383 extern void rip_route_map_reset(void);
384 extern void rip_zclient_init(struct thread_master *);
385 extern void rip_zclient_reset(void);
386 extern void rip_offset_init(void);
387 extern int if_check_address(struct in_addr addr);
388
389 extern int rip_request_send(struct sockaddr_in *, struct interface *, u_char,
390 struct connected *);
391 extern int rip_neighbor_lookup(struct sockaddr_in *);
392
393 extern int rip_redistribute_check(int);
394 extern void rip_redistribute_add(int, int, struct prefix_ipv4 *, ifindex_t,
395 struct in_addr *, unsigned int, unsigned char,
396 route_tag_t);
397 extern void rip_redistribute_delete(int, int, struct prefix_ipv4 *, ifindex_t);
398 extern void rip_redistribute_withdraw(int);
399 extern void rip_zebra_ipv4_add(struct route_node *);
400 extern void rip_zebra_ipv4_delete(struct route_node *);
401 extern void rip_interface_multicast_set(int, struct connected *);
402 extern void rip_distribute_update_interface(struct interface *);
403 extern void rip_if_rmap_update_interface(struct interface *);
404
405 extern int config_write_rip_network(struct vty *, int);
406 extern int config_write_rip_offset_list(struct vty *);
407 extern int config_write_rip_redistribute(struct vty *, int);
408
409 extern void rip_peer_init(void);
410 extern void rip_peer_update(struct sockaddr_in *, u_char);
411 extern void rip_peer_bad_route(struct sockaddr_in *);
412 extern void rip_peer_bad_packet(struct sockaddr_in *);
413 extern void rip_peer_display(struct vty *);
414 extern struct rip_peer *rip_peer_lookup(struct in_addr *);
415 extern struct rip_peer *rip_peer_lookup_next(struct in_addr *);
416
417 extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
418 u_int32_t *);
419 extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
420 u_int32_t *);
421 extern void rip_offset_clean(void);
422
423 extern void rip_info_free(struct rip_info *);
424 extern u_char rip_distance_apply(struct rip_info *);
425 extern void rip_redistribute_clean(void);
426
427 extern struct rip_info *rip_ecmp_add(struct rip_info *);
428 extern struct rip_info *rip_ecmp_replace(struct rip_info *);
429 extern struct rip_info *rip_ecmp_delete(struct rip_info *);
430
431 /* There is only one rip strucutre. */
432 extern struct rip *rip;
433
434 /* Master thread strucutre. */
435 extern struct thread_master *master;
436
437 /* RIP statistics for SNMP. */
438 extern long rip_global_route_changes;
439 extern long rip_global_queries;
440
441 DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
442 DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
443
444 #endif /* _ZEBRA_RIP_H */