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