]> git.proxmox.com Git - mirror_frr.git/blame - ripd/ripd.h
Merge pull request #13601 from opensourcerouting/build-yang-embed-20230525
[mirror_frr.git] / ripd / ripd.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* RIP related values and structures.
3 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
718e3744 4 */
5
6#ifndef _ZEBRA_RIP_H
7#define _ZEBRA_RIP_H
8
3012671f 9#include "hook.h"
dd127197 10#include "nexthop.h"
03a38493 11#include "distribute.h"
814a2585 12#include "memory.h"
c262df82 13#include "bfd.h"
4a1ab8e4 14
718e3744 15/* RIP version number. */
16#define RIPv1 1
17#define RIPv2 2
f38a471c 18/* N.B. stuff will break if
19 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
20
718e3744 21
22/* RIP command list. */
23#define RIP_REQUEST 1
24#define RIP_RESPONSE 2
25#define RIP_TRACEON 3 /* Obsolete */
26#define RIP_TRACEOFF 4 /* Obsolete */
27#define RIP_POLL 5
28#define RIP_POLL_ENTRY 6
29#define RIP_COMMAND_MAX 7
30
31/* RIP metric infinity value.*/
32#define RIP_METRIC_INFINITY 16
33
34/* Normal RIP packet min and max size. */
35#define RIP_PACKET_MINSIZ 4
36#define RIP_PACKET_MAXSIZ 512
37
38#define RIP_HEADER_SIZE 4
39#define RIP_RTE_SIZE 20
40
41/* Max count of routing table entry in one rip packet. */
6a7cff75 42#define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
718e3744 43
44/* RIP version 2 multicast address. */
45#ifndef INADDR_RIP_GROUP
46#define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
47#endif
48
718e3744 49/* RIP peer timeout value. */
50#define RIP_PEER_TIMER_DEFAULT 180
51
52/* RIP port number. */
53#define RIP_PORT_DEFAULT 520
54#define RIP_VTY_PORT 2602
718e3744 55
56/* Default configuration file name. */
57#define RIPD_DEFAULT_CONFIG "ripd.conf"
58
59/* RIP route types. */
60#define RIP_ROUTE_RTE 0
61#define RIP_ROUTE_STATIC 1
62#define RIP_ROUTE_DEFAULT 2
63#define RIP_ROUTE_REDISTRIBUTE 3
64#define RIP_ROUTE_INTERFACE 4
65
ca5e516c 66/* RIPv2 special RTE family types */
67#define RIP_FAMILY_AUTH 0xffff
68
69/* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
70#define RIP_NO_AUTH 0
71#define RIP_AUTH_DATA 1
72#define RIP_AUTH_SIMPLE_PASSWORD 2
73#define RIP_AUTH_MD5 3
74
b14ee00b 75/* RIPv2 Simple authentication */
76#define RIP_AUTH_SIMPLE_SIZE 16
77
ca5e516c 78/* RIPv2 MD5 authentication. */
718e3744 79#define RIP_AUTH_MD5_SIZE 16
ca5e516c 80#define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
718e3744 81
707656ec
RW
82/* YANG paths */
83#define RIP_INSTANCE "/frr-ripd:ripd/instance"
84#define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
85
bf8d3d6a 86DECLARE_MGROUP(RIPD);
814a2585 87
718e3744 88/* RIP structure. */
d62a17ae 89struct rip {
ae7b826a
RW
90 RB_ENTRY(rip) entry;
91
92 /* VRF this routing instance is associated with. */
93 char *vrf_name;
94
95 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
96 struct vrf *vrf;
97
98 /* Status of the routing instance. */
99 bool enabled;
045c5389 100
d62a17ae 101 /* RIP socket. */
102 int sock;
103
104 /* Default version of rip instance. */
105 int version_send; /* version 1 or 2 (but not both) */
106 int version_recv; /* version 1 or 2 or both */
107
108 /* Output buffer of RIP. */
109 struct stream *obuf;
110
111 /* RIP routing information base. */
112 struct route_table *table;
113
29e897ad 114 /* RIP static neighbors. */
d62a17ae 115 struct route_table *neighbor;
116
29e897ad
RW
117 /* Linked list of RIP peers. */
118 struct list *peer_list;
119
d62a17ae 120 /* RIP threads. */
e6685141 121 struct event *t_read;
d62a17ae 122
123 /* Update and garbage timer. */
e6685141 124 struct event *t_update;
d62a17ae 125
126 /* Triggered update hack. */
127 int trigger;
e6685141
DS
128 struct event *t_triggered_update;
129 struct event *t_triggered_interval;
d62a17ae 130
131 /* RIP timer values. */
b745780b
RW
132 uint32_t update_time;
133 uint32_t timeout_time;
134 uint32_t garbage_time;
d62a17ae 135
136 /* RIP default metric. */
282ae30c 137 uint8_t default_metric;
d62a17ae 138
d62a17ae 139 /* RIP default distance. */
d7c0a89a 140 uint8_t distance;
d62a17ae 141 struct route_table *distance_table;
142
143 /* RIP ECMP flag */
75fce464 144 uint8_t ecmp;
d62a17ae 145
44f2f852
RW
146 /* Are we in passive-interface default mode? */
147 bool passive_default;
148
ca046902
RW
149 /* RIP enabled interfaces. */
150 vector enable_interface;
151
1205fdc4
RW
152 /* RIP enabled networks. */
153 struct route_table *enable_network;
154
5a29c0d5
RW
155 /* Vector to store passive-interface name. */
156 vector passive_nondefault;
157
3f21c8c4
RW
158 /* RIP offset-lists. */
159 struct list *offset_list_master;
160
f9120f71 161 /* RIP redistribute configuration. */
d62a17ae 162 struct {
f9120f71
RW
163 bool enabled;
164 struct {
165 char *name;
166 struct route_map *map;
167 } route_map;
908f0020
RW
168 bool metric_config;
169 uint8_t metric;
f9120f71 170 } redist[ZEBRA_ROUTE_MAX];
03a38493
PG
171
172 /* For distribute-list container */
173 struct distribute_ctx *distribute_ctx;
c08a2107 174
4b23867c
PG
175 /* For if_rmap container */
176 struct if_rmap_ctx *if_rmap_ctx;
8f88441d 177
c08a2107
RW
178 /* Counters for SNMP. */
179 struct {
180 /* RIP route changes. */
181 long route_changes;
182
183 /* RIP queries. */
184 long queries;
185 } counters;
c262df82
RW
186
187 /* Default BFD profile to use with BFD sessions. */
188 char *default_bfd_profile;
718e3744 189};
ae7b826a
RW
190RB_HEAD(rip_instance_head, rip);
191RB_PROTOTYPE(rip_instance_head, rip, entry, rip_instance_compare)
718e3744 192
193/* RIP routing table entry which belong to rip_packet. */
d62a17ae 194struct rte {
d7c0a89a
QY
195 uint16_t family; /* Address family of this route. */
196 uint16_t tag; /* Route Tag which included in RIP2 packet. */
d62a17ae 197 struct in_addr prefix; /* Prefix of rip route. */
198 struct in_addr mask; /* Netmask of rip route. */
199 struct in_addr nexthop; /* Next hop of rip route. */
d7c0a89a 200 uint32_t metric; /* Metric value of rip route. */
718e3744 201};
202
203/* RIP packet structure. */
d62a17ae 204struct rip_packet {
205 unsigned char command; /* Command type of RIP packet. */
206 unsigned char version; /* RIP version which coming from peer. */
207 unsigned char pad1; /* Padding of RIP packet header. */
208 unsigned char pad2; /* Same as above. */
209 struct rte rte[1]; /* Address structure. */
718e3744 210};
211
212/* Buffer to read RIP packet. */
d62a17ae 213union rip_buf {
214 struct rip_packet rip_packet;
215 char buf[RIP_PACKET_MAXSIZ];
718e3744 216};
217
218/* RIP route information. */
d62a17ae 219struct rip_info {
220 /* This route's type. */
221 int type;
718e3744 222
d62a17ae 223 /* Sub type. */
224 int sub_type;
718e3744 225
d62a17ae 226 /* RIP nexthop. */
dd127197 227 struct nexthop nh;
d62a17ae 228 struct in_addr from;
718e3744 229
d62a17ae 230 /* Metric of this route. */
d7c0a89a 231 uint32_t metric;
718e3744 232
d62a17ae 233 /* External metric of this route.
234 if learnt from an externalm proto */
d7c0a89a 235 uint32_t external_metric;
fbf5d033 236
d62a17ae 237 /* Tag information of this route. */
d7c0a89a 238 uint16_t tag;
718e3744 239
d62a17ae 240/* Flags of RIP route. */
718e3744 241#define RIP_RTF_FIB 1
242#define RIP_RTF_CHANGED 2
d7c0a89a 243 uint8_t flags;
718e3744 244
d62a17ae 245 /* Garbage collect timer. */
e6685141
DS
246 struct event *t_timeout;
247 struct event *t_garbage_collect;
718e3744 248
d62a17ae 249 /* Route-map futures - this variables can be changed. */
250 struct in_addr nexthop_out;
d7c0a89a
QY
251 uint8_t metric_set;
252 uint32_t metric_out;
253 uint16_t tag_out;
d62a17ae 254 ifindex_t ifindex_out;
718e3744 255
d62a17ae 256 struct route_node *rp;
718e3744 257
d7c0a89a 258 uint8_t distance;
718e3744 259};
260
16705130 261typedef enum {
d62a17ae 262 RIP_NO_SPLIT_HORIZON = 0,
263 RIP_SPLIT_HORIZON,
264 RIP_SPLIT_HORIZON_POISONED_REVERSE
16705130 265} split_horizon_policy_t;
266
718e3744 267/* RIP specific interface configuration. */
d62a17ae 268struct rip_interface {
045c5389
RW
269 /* Parent routing instance. */
270 struct rip *rip;
271
c262df82
RW
272 /* Interface data from zebra. */
273 struct interface *ifp;
274
d62a17ae 275 /* RIP is enabled on this interface. */
276 int enable_network;
277 int enable_interface;
718e3744 278
d62a17ae 279 /* RIP is running on this interface. */
280 int running;
718e3744 281
d62a17ae 282 /* RIP version control. */
283 int ri_send;
284 int ri_receive;
718e3744 285
d62a17ae 286 /* RIPv2 broadcast mode */
94b117b2 287 bool v2_broadcast;
f90310cf 288
d62a17ae 289 /* RIPv2 authentication type. */
290 int auth_type;
718e3744 291
d62a17ae 292 /* RIPv2 authentication string. */
293 char *auth_str;
718e3744 294
d62a17ae 295 /* RIPv2 authentication key chain. */
296 char *key_chain;
718e3744 297
d62a17ae 298 /* value to use for md5->auth_len */
94b117b2 299 int md5_auth_len;
ca5e516c 300
d62a17ae 301 /* Split horizon flag. */
302 split_horizon_policy_t split_horizon;
718e3744 303
d62a17ae 304/* For filter type slot. */
718e3744 305#define RIP_FILTER_IN 0
306#define RIP_FILTER_OUT 1
307#define RIP_FILTER_MAX 2
308
d62a17ae 309 /* Access-list. */
310 struct access_list *list[RIP_FILTER_MAX];
718e3744 311
d62a17ae 312 /* Prefix-list. */
313 struct prefix_list *prefix[RIP_FILTER_MAX];
718e3744 314
d62a17ae 315 /* Route-map. */
316 struct route_map *routemap[RIP_FILTER_MAX];
16705130 317
d62a17ae 318 /* Wake up thread. */
e6685141 319 struct event *t_wakeup;
718e3744 320
d62a17ae 321 /* Interface statistics. */
322 int recv_badpackets;
323 int recv_badroutes;
324 int sent_updates;
718e3744 325
d62a17ae 326 /* Passive interface. */
327 int passive;
c262df82
RW
328
329 /* BFD information. */
330 struct {
331 bool enabled;
332 char *profile;
333 } bfd;
718e3744 334};
335
336/* RIP peer information. */
d62a17ae 337struct rip_peer {
045c5389
RW
338 /* Parent routing instance. */
339 struct rip *rip;
340
c262df82
RW
341 /* Back-pointer to RIP interface. */
342 struct rip_interface *ri;
343
d62a17ae 344 /* Peer address. */
345 struct in_addr addr;
718e3744 346
d62a17ae 347 /* Peer RIP tag value. */
348 int domain;
718e3744 349
d62a17ae 350 /* Last update time. */
351 time_t uptime;
718e3744 352
d62a17ae 353 /* Peer RIP version. */
d7c0a89a 354 uint8_t version;
718e3744 355
d62a17ae 356 /* Statistics. */
357 int recv_badpackets;
358 int recv_badroutes;
718e3744 359
d62a17ae 360 /* Timeout thread. */
e6685141 361 struct event *t_timeout;
c262df82
RW
362
363 /* BFD information */
364 struct bfd_session_params *bfd_session;
718e3744 365};
366
23b23d8c
RW
367struct rip_distance {
368 /* Distance value for the IP source prefix. */
369 uint8_t distance;
370
371 /* Name of the access-list to be matched. */
372 char *access_list;
373};
374
d62a17ae 375struct rip_md5_info {
d7c0a89a
QY
376 uint16_t family;
377 uint16_t type;
378 uint16_t packet_len;
379 uint8_t keyid;
380 uint8_t auth_len;
381 uint32_t sequence;
382 uint32_t reserv1;
383 uint32_t reserv2;
718e3744 384};
385
d62a17ae 386struct rip_md5_data {
d7c0a89a
QY
387 uint16_t family;
388 uint16_t type;
389 uint8_t digest[16];
718e3744 390};
391
392/* RIP accepet/announce methods. */
393#define RI_RIP_UNSPEC 0
394#define RI_RIP_VERSION_1 1
395#define RI_RIP_VERSION_2 2
396#define RI_RIP_VERSION_1_AND_2 3
6aec4b41 397#define RI_RIP_VERSION_NONE 4
f38a471c 398/* N.B. stuff will break if
399 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
718e3744 400
718e3744 401/* RIP event. */
d62a17ae 402enum rip_event {
403 RIP_READ,
404 RIP_UPDATE_EVENT,
405 RIP_TRIGGERED_UPDATE,
718e3744 406};
407
408/* Macro for timer turn on. */
907a2395 409#define RIP_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
718e3744 410
8c942f65
RW
411#define RIP_OFFSET_LIST_IN 0
412#define RIP_OFFSET_LIST_OUT 1
413#define RIP_OFFSET_LIST_MAX 2
414
415struct rip_offset_list {
045c5389
RW
416 /* Parent routing instance. */
417 struct rip *rip;
418
8c942f65
RW
419 char *ifname;
420
421 struct {
422 char *alist_name;
423 /* struct access_list *alist; */
424 uint8_t metric;
425 } direct[RIP_OFFSET_LIST_MAX];
426};
427
718e3744 428/* Prototypes. */
d62a17ae 429extern void rip_init(void);
045c5389
RW
430extern void rip_clean(struct rip *rip);
431extern void rip_clean_network(struct rip *rip);
432extern void rip_interfaces_clean(struct rip *rip);
433extern int rip_passive_nondefault_set(struct rip *rip, const char *ifname);
434extern int rip_passive_nondefault_unset(struct rip *rip, const char *ifname);
435extern void rip_passive_nondefault_clean(struct rip *rip);
d62a17ae 436extern void rip_if_init(void);
d62a17ae 437extern void rip_route_map_init(void);
ae7b826a
RW
438extern void rip_zebra_vrf_register(struct vrf *vrf);
439extern void rip_zebra_vrf_deregister(struct vrf *vrf);
02e701e4 440extern void rip_zclient_init(struct event_loop *e);
a2f9eb82 441extern void rip_zclient_stop(void);
045c5389
RW
442extern int if_check_address(struct rip *rip, struct in_addr addr);
443extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id);
ae7b826a
RW
444extern struct rip *rip_lookup_by_vrf_name(const char *vrf_name);
445extern struct rip *rip_create(const char *vrf_name, struct vrf *vrf,
446 int socket);
d62a17ae 447
d7c0a89a 448extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
d62a17ae 449 struct connected *);
045c5389
RW
450extern int rip_neighbor_lookup(struct rip *rip, struct sockaddr_in *from);
451extern int rip_neighbor_add(struct rip *rip, struct prefix_ipv4 *p);
452extern int rip_neighbor_delete(struct rip *rip, struct prefix_ipv4 *p);
d62a17ae 453
045c5389
RW
454extern int rip_enable_network_add(struct rip *rip, struct prefix *p);
455extern int rip_enable_network_delete(struct rip *rip, struct prefix *p);
456extern int rip_enable_if_add(struct rip *rip, const char *ifname);
457extern int rip_enable_if_delete(struct rip *rip, const char *ifname);
3d7a1be8 458
045c5389
RW
459extern void rip_event(struct rip *rip, enum rip_event event, int sock);
460extern void rip_ecmp_disable(struct rip *rip);
edbf59d2 461
ae7b826a 462extern int rip_create_socket(struct vrf *vrf);
8c9226c2 463
045c5389
RW
464extern int rip_redistribute_check(struct rip *rip, int type);
465extern void rip_redistribute_conf_update(struct rip *rip, int type);
466extern void rip_redistribute_conf_delete(struct rip *rip, int type);
467extern void rip_redistribute_add(struct rip *rip, int type, int sub_type,
468 struct prefix_ipv4 *p, struct nexthop *nh,
469 unsigned int metric, unsigned char distance,
470 route_tag_t tag);
471extern void rip_redistribute_delete(struct rip *rip, int type, int sub_type,
472 struct prefix_ipv4 *p, ifindex_t ifindex);
473extern void rip_redistribute_withdraw(struct rip *rip, int type);
474extern void rip_zebra_ipv4_add(struct rip *rip, struct route_node *rp);
475extern void rip_zebra_ipv4_delete(struct rip *rip, struct route_node *rp);
d62a17ae 476extern void rip_interface_multicast_set(int, struct connected *);
477extern void rip_distribute_update_interface(struct interface *);
4b23867c 478extern void rip_if_rmap_update_interface(struct interface *ifp);
d62a17ae 479
045c5389
RW
480extern int rip_show_network_config(struct vty *vty, struct rip *rip);
481extern void rip_show_redistribute_config(struct vty *vty, struct rip *rip);
482
c262df82
RW
483extern void rip_peer_free(struct rip_peer *peer);
484extern void rip_peer_update(struct rip *rip, struct rip_interface *ri,
485 struct sockaddr_in *from, uint8_t version);
486extern void rip_peer_bad_route(struct rip *rip, struct rip_interface *ri,
487 struct sockaddr_in *from);
488extern void rip_peer_bad_packet(struct rip *rip, struct rip_interface *ri,
489 struct sockaddr_in *from);
045c5389
RW
490extern void rip_peer_display(struct vty *vty, struct rip *rip);
491extern struct rip_peer *rip_peer_lookup(struct rip *rip, struct in_addr *addr);
492extern struct rip_peer *rip_peer_lookup_next(struct rip *rip,
493 struct in_addr *addr);
29e897ad 494extern int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2);
711915d2 495extern void rip_peer_list_del(void *arg);
c262df82 496void rip_peer_delete_routes(const struct rip_peer *peer);
d62a17ae 497
d62a17ae 498extern void rip_info_free(struct rip_info *);
045c5389 499extern struct rip *rip_info_get_instance(const struct rip_info *rinfo);
23b23d8c
RW
500extern struct rip_distance *rip_distance_new(void);
501extern void rip_distance_free(struct rip_distance *rdistance);
045c5389 502extern uint8_t rip_distance_apply(struct rip *rip, struct rip_info *rinfo);
f9120f71
RW
503extern void rip_redistribute_enable(struct rip *rip);
504extern void rip_redistribute_disable(struct rip *rip);
d62a17ae 505
1137aef4 506extern int rip_route_rte(struct rip_info *rinfo);
045c5389
RW
507extern struct rip_info *rip_ecmp_add(struct rip *rip,
508 struct rip_info *rinfo_new);
509extern struct rip_info *rip_ecmp_replace(struct rip *rip,
510 struct rip_info *rinfo_new);
511extern struct rip_info *rip_ecmp_delete(struct rip *rip,
512 struct rip_info *rinfo);
513
514extern struct rip_offset_list *rip_offset_list_new(struct rip *rip,
515 const char *ifname);
8c942f65 516extern void offset_list_del(struct rip_offset_list *offset);
6c4c3561 517extern void offset_list_free(struct rip_offset_list *offset);
045c5389
RW
518extern struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
519 const char *ifname);
8c942f65
RW
520extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
521 uint32_t *);
522extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
523 uint32_t *);
3f21c8c4
RW
524extern int offset_list_cmp(struct rip_offset_list *o1,
525 struct rip_offset_list *o2);
8c942f65 526
ae7b826a
RW
527extern void rip_vrf_init(void);
528extern void rip_vrf_terminate(void);
f80ec39e 529extern void rip_cli_init(void);
fe339c95 530
32b5a493 531extern struct zebra_privs_t ripd_privs;
32600a98 532extern struct rip_instance_head rip_instances;
32b5a493 533
544be979 534/* Master thread structure. */
cd9d0537 535extern struct event_loop *master;
718e3744 536
8451921b
DL
537DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc));
538DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc));
3012671f 539
75fce464
DA
540extern void rip_ecmp_change(struct rip *rip);
541
1b839d48
DA
542extern uint32_t zebra_ecmp_count;
543
718e3744 544#endif /* _ZEBRA_RIP_H */