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