]> git.proxmox.com Git - mirror_frr.git/blame - ripd/ripd.h
Merge pull request #531 from qlyoung/fix-stack-ref
[mirror_frr.git] / ripd / ripd.h
CommitLineData
718e3744 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
f6eacff4 25#include "qobj.h"
3012671f 26#include "hook.h"
4a1ab8e4
DL
27#include "rip_memory.h"
28
718e3744 29/* RIP version number. */
30#define RIPv1 1
31#define RIPv2 2
f38a471c 32/* N.B. stuff will break if
33 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
34
718e3744 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. */
6a7cff75 56#define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
718e3744 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
718e3744 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
ca5e516c 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
b14ee00b 94/* RIPv2 Simple authentication */
95#define RIP_AUTH_SIMPLE_SIZE 16
96
ca5e516c 97/* RIPv2 MD5 authentication. */
718e3744 98#define RIP_AUTH_MD5_SIZE 16
ca5e516c 99#define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
718e3744 100
101/* RIP structure. */
102struct rip
103{
104 /* RIP socket. */
105 int sock;
106
107 /* Default version of rip instance. */
f38a471c 108 int version_send; /* version 1 or 2 (but not both) */
109 int version_recv; /* version 1 or 2 or both */
718e3744 110
111 /* Output buffer of RIP. */
112 struct stream *obuf;
113
114 /* RIP routing information base. */
115 struct route_table *table;
116
117 /* RIP only static routing information. */
118 struct route_table *route;
119
120 /* RIP neighbor. */
121 struct route_table *neighbor;
122
123 /* RIP threads. */
124 struct thread *t_read;
125
126 /* Update and garbage timer. */
127 struct thread *t_update;
128
129 /* Triggered update hack. */
130 int trigger;
131 struct thread *t_triggered_update;
132 struct thread *t_triggered_interval;
133
134 /* RIP timer values. */
135 unsigned long update_time;
136 unsigned long timeout_time;
137 unsigned long garbage_time;
138
139 /* RIP default metric. */
140 int default_metric;
141
142 /* RIP default-information originate. */
143 u_char default_information;
144 char *default_information_route_map;
145
146 /* RIP default distance. */
147 u_char distance;
148 struct route_table *distance_table;
149
8478ae7e
LF
150 /* RIP ECMP flag */
151 unsigned int ecmp;
152
718e3744 153 /* For redistribute route map. */
154 struct
155 {
156 char *name;
157 struct route_map *map;
158 int metric_config;
159 u_int32_t metric;
160 } route_map[ZEBRA_ROUTE_MAX];
f6eacff4
DL
161
162 QOBJ_FIELDS
718e3744 163};
f6eacff4 164DECLARE_QOBJ_TYPE(rip)
718e3744 165
166/* RIP routing table entry which belong to rip_packet. */
167struct rte
168{
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. */
175};
176
177/* RIP packet structure. */
178struct rip_packet
179{
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. */
185};
186
187/* Buffer to read RIP packet. */
188union rip_buf
189{
190 struct rip_packet rip_packet;
191 char buf[RIP_PACKET_MAXSIZ];
192};
193
194/* RIP route information. */
195struct rip_info
196{
197 /* This route's type. */
198 int type;
199
200 /* Sub type. */
201 int sub_type;
202
203 /* RIP nexthop. */
204 struct in_addr nexthop;
205 struct in_addr from;
206
207 /* Which interface does this route come from. */
b892f1dd 208 ifindex_t ifindex;
718e3744 209
210 /* Metric of this route. */
211 u_int32_t metric;
212
fbf5d033 213 /* External metric of this route.
214 if learnt from an externalm proto */
215 u_int32_t external_metric;
216
718e3744 217 /* Tag information of this route. */
218 u_int16_t tag;
219
220 /* Flags of RIP route. */
221#define RIP_RTF_FIB 1
222#define RIP_RTF_CHANGED 2
223 u_char flags;
224
225 /* Garbage collect timer. */
226 struct thread *t_timeout;
227 struct thread *t_garbage_collect;
228
229 /* Route-map futures - this variables can be changed. */
230 struct in_addr nexthop_out;
231 u_char metric_set;
232 u_int32_t metric_out;
dc9ffce8 233 u_int16_t tag_out;
b892f1dd 234 ifindex_t ifindex_out;
718e3744 235
236 struct route_node *rp;
237
238 u_char distance;
239
240#ifdef NEW_RIP_TABLE
241 struct rip_info *next;
242 struct rip_info *prev;
243#endif /* NEW_RIP_TABLE */
244};
245
16705130 246typedef enum {
247 RIP_NO_SPLIT_HORIZON = 0,
248 RIP_SPLIT_HORIZON,
249 RIP_SPLIT_HORIZON_POISONED_REVERSE
250} split_horizon_policy_t;
251
718e3744 252/* RIP specific interface configuration. */
253struct rip_interface
254{
255 /* RIP is enabled on this interface. */
256 int enable_network;
257 int enable_interface;
258
259 /* RIP is running on this interface. */
260 int running;
261
262 /* RIP version control. */
263 int ri_send;
264 int ri_receive;
265
f90310cf
RW
266 /* RIPv2 broadcast mode */
267 int v2_broadcast;
268
718e3744 269 /* RIPv2 authentication type. */
718e3744 270 int auth_type;
271
272 /* RIPv2 authentication string. */
273 char *auth_str;
274
275 /* RIPv2 authentication key chain. */
276 char *key_chain;
277
ca5e516c 278 /* value to use for md5->auth_len */
279 u_int8_t md5_auth_len;
280
718e3744 281 /* Split horizon flag. */
16705130 282 split_horizon_policy_t split_horizon;
283 split_horizon_policy_t split_horizon_default;
718e3744 284
285 /* For filter type slot. */
286#define RIP_FILTER_IN 0
287#define RIP_FILTER_OUT 1
288#define RIP_FILTER_MAX 2
289
290 /* Access-list. */
291 struct access_list *list[RIP_FILTER_MAX];
292
293 /* Prefix-list. */
294 struct prefix_list *prefix[RIP_FILTER_MAX];
295
16705130 296 /* Route-map. */
297 struct route_map *routemap[RIP_FILTER_MAX];
298
718e3744 299 /* Wake up thread. */
300 struct thread *t_wakeup;
301
302 /* Interface statistics. */
303 int recv_badpackets;
304 int recv_badroutes;
305 int sent_updates;
306
307 /* Passive interface. */
308 int passive;
309};
310
311/* RIP peer information. */
312struct rip_peer
313{
314 /* Peer address. */
315 struct in_addr addr;
316
317 /* Peer RIP tag value. */
318 int domain;
319
320 /* Last update time. */
321 time_t uptime;
322
323 /* Peer RIP version. */
324 u_char version;
325
326 /* Statistics. */
327 int recv_badpackets;
328 int recv_badroutes;
329
330 /* Timeout thread. */
331 struct thread *t_timeout;
332};
333
334struct rip_md5_info
335{
336 u_int16_t family;
337 u_int16_t type;
338 u_int16_t packet_len;
339 u_char keyid;
340 u_char auth_len;
341 u_int32_t sequence;
342 u_int32_t reserv1;
343 u_int32_t reserv2;
344};
345
346struct rip_md5_data
347{
348 u_int16_t family;
349 u_int16_t type;
350 u_char digest[16];
351};
352
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
6aec4b41 358#define RI_RIP_VERSION_NONE 4
f38a471c 359/* N.B. stuff will break if
360 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
718e3744 361
362/* Default value for "default-metric" command. */
363#define RIP_DEFAULT_METRIC_DEFAULT 1
364
365/* RIP event. */
366enum rip_event
367{
368 RIP_READ,
369 RIP_UPDATE_EVENT,
370 RIP_TRIGGERED_UPDATE,
371};
372
373/* Macro for timer turn on. */
ffa2c898 374#define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
718e3744 375
376/* Macro for timer turn off. */
8578874d 377#define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
718e3744 378
379/* Prototypes. */
dc63bfd4 380extern void rip_init (void);
381extern void rip_reset (void);
382extern void rip_clean (void);
383extern void rip_clean_network (void);
1dec2166
PJ
384extern void rip_interfaces_clean (void);
385extern void rip_interfaces_reset (void);
dc63bfd4 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);
4140ca4d 391extern void rip_zclient_init(struct thread_master *);
dc63bfd4 392extern void rip_zclient_reset (void);
393extern void rip_offset_init (void);
394extern int if_check_address (struct in_addr addr);
dc63bfd4 395
396extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char,
931cd54d 397 struct connected *);
dc63bfd4 398extern int rip_neighbor_lookup (struct sockaddr_in *);
2c239705
SH
399
400extern int rip_redistribute_check (int);
b892f1dd 401extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, ifindex_t,
9471675f
CF
402 struct in_addr *, unsigned int, unsigned char,
403 route_tag_t);
b892f1dd 404extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, ifindex_t);
dc63bfd4 405extern void rip_redistribute_withdraw (int);
bce8e868
LF
406extern void rip_zebra_ipv4_add (struct route_node *);
407extern void rip_zebra_ipv4_delete (struct route_node *);
dc63bfd4 408extern void rip_interface_multicast_set (int, struct connected *);
409extern void rip_distribute_update_interface (struct interface *);
410extern void rip_if_rmap_update_interface (struct interface *);
411
412extern int config_write_rip_network (struct vty *, int);
413extern int config_write_rip_offset_list (struct vty *);
414extern int config_write_rip_redistribute (struct vty *, int);
415
416extern void rip_peer_init (void);
417extern void rip_peer_update (struct sockaddr_in *, u_char);
418extern void rip_peer_bad_route (struct sockaddr_in *);
419extern void rip_peer_bad_packet (struct sockaddr_in *);
420extern void rip_peer_display (struct vty *);
421extern struct rip_peer *rip_peer_lookup (struct in_addr *);
422extern struct rip_peer *rip_peer_lookup_next (struct in_addr *);
423
424extern int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *);
425extern int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *);
426extern void rip_offset_clean (void);
427
428extern void rip_info_free (struct rip_info *);
429extern u_char rip_distance_apply (struct rip_info *);
430extern void rip_redistribute_clean (void);
718e3744 431
bce8e868
LF
432extern struct rip_info *rip_ecmp_add (struct rip_info *);
433extern struct rip_info *rip_ecmp_replace (struct rip_info *);
434extern struct rip_info *rip_ecmp_delete (struct rip_info *);
435
718e3744 436/* There is only one rip strucutre. */
437extern struct rip *rip;
438
439/* Master thread strucutre. */
440extern struct thread_master *master;
441
442/* RIP statistics for SNMP. */
443extern long rip_global_route_changes;
444extern long rip_global_queries;
3012671f
DL
445
446DECLARE_HOOK(rip_ifaddr_add, (struct connected *ifc), (ifc))
447DECLARE_HOOK(rip_ifaddr_del, (struct connected *ifc), (ifc))
448
718e3744 449#endif /* _ZEBRA_RIP_H */