]> git.proxmox.com Git - mirror_frr.git/blame - ripd/ripd.h
ripd: move "peer_list" to the rip structure
[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
3012671f 24#include "hook.h"
dd127197 25#include "nexthop.h"
03a38493 26#include "distribute.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
718e3744 63/* RIP peer timeout value. */
64#define RIP_PEER_TIMER_DEFAULT 180
65
66/* RIP port number. */
67#define RIP_PORT_DEFAULT 520
68#define RIP_VTY_PORT 2602
718e3744 69
70/* Default configuration file name. */
71#define RIPD_DEFAULT_CONFIG "ripd.conf"
72
73/* RIP route types. */
74#define RIP_ROUTE_RTE 0
75#define RIP_ROUTE_STATIC 1
76#define RIP_ROUTE_DEFAULT 2
77#define RIP_ROUTE_REDISTRIBUTE 3
78#define RIP_ROUTE_INTERFACE 4
79
ca5e516c 80/* RIPv2 special RTE family types */
81#define RIP_FAMILY_AUTH 0xffff
82
83/* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
84#define RIP_NO_AUTH 0
85#define RIP_AUTH_DATA 1
86#define RIP_AUTH_SIMPLE_PASSWORD 2
87#define RIP_AUTH_MD5 3
88
b14ee00b 89/* RIPv2 Simple authentication */
90#define RIP_AUTH_SIMPLE_SIZE 16
91
ca5e516c 92/* RIPv2 MD5 authentication. */
718e3744 93#define RIP_AUTH_MD5_SIZE 16
ca5e516c 94#define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
718e3744 95
707656ec
RW
96/* YANG paths */
97#define RIP_INSTANCE "/frr-ripd:ripd/instance"
98#define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
99
718e3744 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
29e897ad 115 /* RIP static neighbors. */
d62a17ae 116 struct route_table *neighbor;
117
29e897ad
RW
118 /* Linked list of RIP peers. */
119 struct list *peer_list;
120
d62a17ae 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. */
b745780b
RW
133 uint32_t update_time;
134 uint32_t timeout_time;
135 uint32_t garbage_time;
d62a17ae 136
137 /* RIP default metric. */
282ae30c 138 uint8_t default_metric;
d62a17ae 139
d62a17ae 140 /* RIP default distance. */
d7c0a89a 141 uint8_t distance;
d62a17ae 142 struct route_table *distance_table;
143
144 /* RIP ECMP flag */
edbf59d2 145 bool ecmp;
d62a17ae 146
44f2f852
RW
147 /* Are we in passive-interface default mode? */
148 bool passive_default;
149
ca046902
RW
150 /* RIP enabled interfaces. */
151 vector enable_interface;
152
1205fdc4
RW
153 /* RIP enabled networks. */
154 struct route_table *enable_network;
155
5a29c0d5
RW
156 /* Vector to store passive-interface name. */
157 vector passive_nondefault;
158
d62a17ae 159 /* For redistribute route map. */
160 struct {
161 char *name;
162 struct route_map *map;
908f0020
RW
163 bool metric_config;
164 uint8_t metric;
d62a17ae 165 } route_map[ZEBRA_ROUTE_MAX];
03a38493
PG
166
167 /* For distribute-list container */
168 struct distribute_ctx *distribute_ctx;
718e3744 169};
170
171/* RIP routing table entry which belong to rip_packet. */
d62a17ae 172struct rte {
d7c0a89a
QY
173 uint16_t family; /* Address family of this route. */
174 uint16_t tag; /* Route Tag which included in RIP2 packet. */
d62a17ae 175 struct in_addr prefix; /* Prefix of rip route. */
176 struct in_addr mask; /* Netmask of rip route. */
177 struct in_addr nexthop; /* Next hop of rip route. */
d7c0a89a 178 uint32_t metric; /* Metric value of rip route. */
718e3744 179};
180
181/* RIP packet structure. */
d62a17ae 182struct rip_packet {
183 unsigned char command; /* Command type of RIP packet. */
184 unsigned char version; /* RIP version which coming from peer. */
185 unsigned char pad1; /* Padding of RIP packet header. */
186 unsigned char pad2; /* Same as above. */
187 struct rte rte[1]; /* Address structure. */
718e3744 188};
189
190/* Buffer to read RIP packet. */
d62a17ae 191union rip_buf {
192 struct rip_packet rip_packet;
193 char buf[RIP_PACKET_MAXSIZ];
718e3744 194};
195
196/* RIP route information. */
d62a17ae 197struct rip_info {
198 /* This route's type. */
199 int type;
718e3744 200
d62a17ae 201 /* Sub type. */
202 int sub_type;
718e3744 203
d62a17ae 204 /* RIP nexthop. */
dd127197 205 struct nexthop nh;
d62a17ae 206 struct in_addr from;
718e3744 207
d62a17ae 208 /* Metric of this route. */
d7c0a89a 209 uint32_t metric;
718e3744 210
d62a17ae 211 /* External metric of this route.
212 if learnt from an externalm proto */
d7c0a89a 213 uint32_t external_metric;
fbf5d033 214
d62a17ae 215 /* Tag information of this route. */
d7c0a89a 216 uint16_t tag;
718e3744 217
d62a17ae 218/* Flags of RIP route. */
718e3744 219#define RIP_RTF_FIB 1
220#define RIP_RTF_CHANGED 2
d7c0a89a 221 uint8_t flags;
718e3744 222
d62a17ae 223 /* Garbage collect timer. */
224 struct thread *t_timeout;
225 struct thread *t_garbage_collect;
718e3744 226
d62a17ae 227 /* Route-map futures - this variables can be changed. */
228 struct in_addr nexthop_out;
d7c0a89a
QY
229 uint8_t metric_set;
230 uint32_t metric_out;
231 uint16_t tag_out;
d62a17ae 232 ifindex_t ifindex_out;
718e3744 233
d62a17ae 234 struct route_node *rp;
718e3744 235
d7c0a89a 236 uint8_t distance;
718e3744 237
238#ifdef NEW_RIP_TABLE
d62a17ae 239 struct rip_info *next;
240 struct rip_info *prev;
718e3744 241#endif /* NEW_RIP_TABLE */
242};
243
16705130 244typedef enum {
d62a17ae 245 RIP_NO_SPLIT_HORIZON = 0,
246 RIP_SPLIT_HORIZON,
247 RIP_SPLIT_HORIZON_POISONED_REVERSE
16705130 248} split_horizon_policy_t;
249
718e3744 250/* RIP specific interface configuration. */
d62a17ae 251struct rip_interface {
252 /* RIP is enabled on this interface. */
253 int enable_network;
254 int enable_interface;
718e3744 255
d62a17ae 256 /* RIP is running on this interface. */
257 int running;
718e3744 258
d62a17ae 259 /* RIP version control. */
260 int ri_send;
261 int ri_receive;
718e3744 262
d62a17ae 263 /* RIPv2 broadcast mode */
94b117b2 264 bool v2_broadcast;
f90310cf 265
d62a17ae 266 /* RIPv2 authentication type. */
267 int auth_type;
718e3744 268
d62a17ae 269 /* RIPv2 authentication string. */
270 char *auth_str;
718e3744 271
d62a17ae 272 /* RIPv2 authentication key chain. */
273 char *key_chain;
718e3744 274
d62a17ae 275 /* value to use for md5->auth_len */
94b117b2 276 int md5_auth_len;
ca5e516c 277
d62a17ae 278 /* Split horizon flag. */
279 split_horizon_policy_t split_horizon;
718e3744 280
d62a17ae 281/* For filter type slot. */
718e3744 282#define RIP_FILTER_IN 0
283#define RIP_FILTER_OUT 1
284#define RIP_FILTER_MAX 2
285
d62a17ae 286 /* Access-list. */
287 struct access_list *list[RIP_FILTER_MAX];
718e3744 288
d62a17ae 289 /* Prefix-list. */
290 struct prefix_list *prefix[RIP_FILTER_MAX];
718e3744 291
d62a17ae 292 /* Route-map. */
293 struct route_map *routemap[RIP_FILTER_MAX];
16705130 294
d62a17ae 295 /* Wake up thread. */
296 struct thread *t_wakeup;
718e3744 297
d62a17ae 298 /* Interface statistics. */
299 int recv_badpackets;
300 int recv_badroutes;
301 int sent_updates;
718e3744 302
d62a17ae 303 /* Passive interface. */
304 int passive;
718e3744 305};
306
307/* RIP peer information. */
d62a17ae 308struct rip_peer {
309 /* Peer address. */
310 struct in_addr addr;
718e3744 311
d62a17ae 312 /* Peer RIP tag value. */
313 int domain;
718e3744 314
d62a17ae 315 /* Last update time. */
316 time_t uptime;
718e3744 317
d62a17ae 318 /* Peer RIP version. */
d7c0a89a 319 uint8_t version;
718e3744 320
d62a17ae 321 /* Statistics. */
322 int recv_badpackets;
323 int recv_badroutes;
718e3744 324
d62a17ae 325 /* Timeout thread. */
326 struct thread *t_timeout;
718e3744 327};
328
23b23d8c
RW
329struct rip_distance {
330 /* Distance value for the IP source prefix. */
331 uint8_t distance;
332
333 /* Name of the access-list to be matched. */
334 char *access_list;
335};
336
d62a17ae 337struct rip_md5_info {
d7c0a89a
QY
338 uint16_t family;
339 uint16_t type;
340 uint16_t packet_len;
341 uint8_t keyid;
342 uint8_t auth_len;
343 uint32_t sequence;
344 uint32_t reserv1;
345 uint32_t reserv2;
718e3744 346};
347
d62a17ae 348struct rip_md5_data {
d7c0a89a
QY
349 uint16_t family;
350 uint16_t type;
351 uint8_t digest[16];
718e3744 352};
353
354/* RIP accepet/announce methods. */
355#define RI_RIP_UNSPEC 0
356#define RI_RIP_VERSION_1 1
357#define RI_RIP_VERSION_2 2
358#define RI_RIP_VERSION_1_AND_2 3
6aec4b41 359#define RI_RIP_VERSION_NONE 4
f38a471c 360/* N.B. stuff will break if
361 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
718e3744 362
718e3744 363/* RIP event. */
d62a17ae 364enum rip_event {
365 RIP_READ,
366 RIP_UPDATE_EVENT,
367 RIP_TRIGGERED_UPDATE,
718e3744 368};
369
370/* Macro for timer turn on. */
ffa2c898 371#define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
718e3744 372
373/* Macro for timer turn off. */
8578874d 374#define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
718e3744 375
8c942f65
RW
376#define RIP_OFFSET_LIST_IN 0
377#define RIP_OFFSET_LIST_OUT 1
378#define RIP_OFFSET_LIST_MAX 2
379
380struct rip_offset_list {
381 char *ifname;
382
383 struct {
384 char *alist_name;
385 /* struct access_list *alist; */
386 uint8_t metric;
387 } direct[RIP_OFFSET_LIST_MAX];
388};
389
718e3744 390/* Prototypes. */
d62a17ae 391extern void rip_init(void);
d62a17ae 392extern void rip_clean(void);
393extern void rip_clean_network(void);
394extern void rip_interfaces_clean(void);
44f2f852
RW
395extern int rip_passive_nondefault_set(const char *ifname);
396extern int rip_passive_nondefault_unset(const char *ifname);
d62a17ae 397extern void rip_passive_nondefault_clean(void);
398extern void rip_if_init(void);
399extern void rip_if_down_all(void);
400extern void rip_route_map_init(void);
4140ca4d 401extern void rip_zclient_init(struct thread_master *);
a2f9eb82 402extern void rip_zclient_stop(void);
d62a17ae 403extern int if_check_address(struct in_addr addr);
8c9226c2 404extern int rip_create(int socket);
d62a17ae 405
d7c0a89a 406extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
d62a17ae 407 struct connected *);
408extern int rip_neighbor_lookup(struct sockaddr_in *);
f0ab22fb
RW
409extern int rip_neighbor_add(struct prefix_ipv4 *p);
410extern int rip_neighbor_delete(struct prefix_ipv4 *p);
d62a17ae 411
3d7a1be8
RW
412extern int rip_enable_network_add(struct prefix *p);
413extern int rip_enable_network_delete(struct prefix *p);
414extern int rip_enable_if_add(const char *ifname);
415extern int rip_enable_if_delete(const char *ifname);
416
b745780b 417extern void rip_event(enum rip_event, int);
edbf59d2
RW
418extern void rip_ecmp_disable(void);
419
8c9226c2
RW
420extern int rip_create_socket(void);
421
d62a17ae 422extern int rip_redistribute_check(int);
908f0020
RW
423extern void rip_redistribute_conf_update(int type);
424extern void rip_redistribute_conf_delete(int type);
996c9314
LB
425extern void rip_redistribute_add(int type, int sub_type, struct prefix_ipv4 *p,
426 struct nexthop *nh, unsigned int metric,
427 unsigned char distance, route_tag_t tag);
d62a17ae 428extern void rip_redistribute_delete(int, int, struct prefix_ipv4 *, ifindex_t);
429extern void rip_redistribute_withdraw(int);
430extern void rip_zebra_ipv4_add(struct route_node *);
431extern void rip_zebra_ipv4_delete(struct route_node *);
432extern void rip_interface_multicast_set(int, struct connected *);
433extern void rip_distribute_update_interface(struct interface *);
434extern void rip_if_rmap_update_interface(struct interface *);
435
44f2f852 436extern int rip_show_network_config(struct vty *);
908f0020 437extern void rip_show_redistribute_config(struct vty *);
d62a17ae 438
d7c0a89a 439extern void rip_peer_update(struct sockaddr_in *, uint8_t);
d62a17ae 440extern void rip_peer_bad_route(struct sockaddr_in *);
441extern void rip_peer_bad_packet(struct sockaddr_in *);
442extern void rip_peer_display(struct vty *);
443extern struct rip_peer *rip_peer_lookup(struct in_addr *);
444extern struct rip_peer *rip_peer_lookup_next(struct in_addr *);
29e897ad 445extern int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2);
d62a17ae 446
d62a17ae 447extern void rip_info_free(struct rip_info *);
23b23d8c
RW
448extern struct rip_distance *rip_distance_new(void);
449extern void rip_distance_free(struct rip_distance *rdistance);
d7c0a89a 450extern uint8_t rip_distance_apply(struct rip_info *);
d62a17ae 451extern void rip_redistribute_clean(void);
452
1137aef4 453extern int rip_route_rte(struct rip_info *rinfo);
d62a17ae 454extern struct rip_info *rip_ecmp_add(struct rip_info *);
455extern struct rip_info *rip_ecmp_replace(struct rip_info *);
456extern struct rip_info *rip_ecmp_delete(struct rip_info *);
bce8e868 457
8c942f65
RW
458extern struct rip_offset_list *rip_offset_list_new(const char *ifname);
459extern void offset_list_del(struct rip_offset_list *offset);
460extern struct rip_offset_list *rip_offset_list_lookup(const char *ifname);
461extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
462 uint32_t *);
463extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
464 uint32_t *);
465extern void rip_offset_init(void);
466extern void rip_offset_clean(void);
467
fe339c95
RW
468/* YANG notifications */
469extern void ripd_notif_send_auth_type_failure(const char *ifname);
470extern void ripd_notif_send_auth_failure(const char *ifname);
471
718e3744 472/* There is only one rip strucutre. */
473extern struct rip *rip;
474
32b5a493
DS
475extern struct zebra_privs_t ripd_privs;
476
718e3744 477/* Master thread strucutre. */
478extern struct thread_master *master;
479
480/* RIP statistics for SNMP. */
481extern long rip_global_route_changes;
482extern long rip_global_queries;
3012671f 483
d62a17ae 484DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
485DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
3012671f 486
23b23d8c
RW
487extern struct route_table *rip_distance_table;
488
707656ec
RW
489/* Northbound. */
490extern void rip_cli_init(void);
491extern const struct frr_yang_module_info frr_ripd_info;
492
718e3744 493#endif /* _ZEBRA_RIP_H */