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