]> git.proxmox.com Git - mirror_frr.git/blob - ripd/ripd.h
Merge pull request #13484 from sri-mohan1/srib-ldpd
[mirror_frr.git] / ripd / ripd.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* RIP related values and structures.
3 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 */
5
6 #ifndef _ZEBRA_RIP_H
7 #define _ZEBRA_RIP_H
8
9 #include "hook.h"
10 #include "nexthop.h"
11 #include "distribute.h"
12 #include "memory.h"
13 #include "bfd.h"
14
15 /* RIP version number. */
16 #define RIPv1 1
17 #define RIPv2 2
18 /* N.B. stuff will break if
19 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
20
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. */
42 #define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
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
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
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
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
75 /* RIPv2 Simple authentication */
76 #define RIP_AUTH_SIMPLE_SIZE 16
77
78 /* RIPv2 MD5 authentication. */
79 #define RIP_AUTH_MD5_SIZE 16
80 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
81
82 /* YANG paths */
83 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
84 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
85
86 DECLARE_MGROUP(RIPD);
87
88 /* RIP structure. */
89 struct rip {
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;
100
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
114 /* RIP static neighbors. */
115 struct route_table *neighbor;
116
117 /* Linked list of RIP peers. */
118 struct list *peer_list;
119
120 /* RIP threads. */
121 struct event *t_read;
122
123 /* Update and garbage timer. */
124 struct event *t_update;
125
126 /* Triggered update hack. */
127 int trigger;
128 struct event *t_triggered_update;
129 struct event *t_triggered_interval;
130
131 /* RIP timer values. */
132 uint32_t update_time;
133 uint32_t timeout_time;
134 uint32_t garbage_time;
135
136 /* RIP default metric. */
137 uint8_t default_metric;
138
139 /* RIP default distance. */
140 uint8_t distance;
141 struct route_table *distance_table;
142
143 /* RIP ECMP flag */
144 bool ecmp;
145
146 /* Are we in passive-interface default mode? */
147 bool passive_default;
148
149 /* RIP enabled interfaces. */
150 vector enable_interface;
151
152 /* RIP enabled networks. */
153 struct route_table *enable_network;
154
155 /* Vector to store passive-interface name. */
156 vector passive_nondefault;
157
158 /* RIP offset-lists. */
159 struct list *offset_list_master;
160
161 /* RIP redistribute configuration. */
162 struct {
163 bool enabled;
164 struct {
165 char *name;
166 struct route_map *map;
167 } route_map;
168 bool metric_config;
169 uint8_t metric;
170 } redist[ZEBRA_ROUTE_MAX];
171
172 /* For distribute-list container */
173 struct distribute_ctx *distribute_ctx;
174
175 /* For if_rmap container */
176 struct if_rmap_ctx *if_rmap_ctx;
177
178 /* Counters for SNMP. */
179 struct {
180 /* RIP route changes. */
181 long route_changes;
182
183 /* RIP queries. */
184 long queries;
185 } counters;
186
187 /* Default BFD profile to use with BFD sessions. */
188 char *default_bfd_profile;
189 };
190 RB_HEAD(rip_instance_head, rip);
191 RB_PROTOTYPE(rip_instance_head, rip, entry, rip_instance_compare)
192
193 /* RIP routing table entry which belong to rip_packet. */
194 struct rte {
195 uint16_t family; /* Address family of this route. */
196 uint16_t tag; /* Route Tag which included in RIP2 packet. */
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. */
200 uint32_t metric; /* Metric value of rip route. */
201 };
202
203 /* RIP packet structure. */
204 struct 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. */
210 };
211
212 /* Buffer to read RIP packet. */
213 union rip_buf {
214 struct rip_packet rip_packet;
215 char buf[RIP_PACKET_MAXSIZ];
216 };
217
218 /* RIP route information. */
219 struct rip_info {
220 /* This route's type. */
221 int type;
222
223 /* Sub type. */
224 int sub_type;
225
226 /* RIP nexthop. */
227 struct nexthop nh;
228 struct in_addr from;
229
230 /* Metric of this route. */
231 uint32_t metric;
232
233 /* External metric of this route.
234 if learnt from an externalm proto */
235 uint32_t external_metric;
236
237 /* Tag information of this route. */
238 uint16_t tag;
239
240 /* Flags of RIP route. */
241 #define RIP_RTF_FIB 1
242 #define RIP_RTF_CHANGED 2
243 uint8_t flags;
244
245 /* Garbage collect timer. */
246 struct event *t_timeout;
247 struct event *t_garbage_collect;
248
249 /* Route-map futures - this variables can be changed. */
250 struct in_addr nexthop_out;
251 uint8_t metric_set;
252 uint32_t metric_out;
253 uint16_t tag_out;
254 ifindex_t ifindex_out;
255
256 struct route_node *rp;
257
258 uint8_t distance;
259 };
260
261 typedef enum {
262 RIP_NO_SPLIT_HORIZON = 0,
263 RIP_SPLIT_HORIZON,
264 RIP_SPLIT_HORIZON_POISONED_REVERSE
265 } split_horizon_policy_t;
266
267 /* RIP specific interface configuration. */
268 struct rip_interface {
269 /* Parent routing instance. */
270 struct rip *rip;
271
272 /* Interface data from zebra. */
273 struct interface *ifp;
274
275 /* RIP is enabled on this interface. */
276 int enable_network;
277 int enable_interface;
278
279 /* RIP is running on this interface. */
280 int running;
281
282 /* RIP version control. */
283 int ri_send;
284 int ri_receive;
285
286 /* RIPv2 broadcast mode */
287 bool v2_broadcast;
288
289 /* RIPv2 authentication type. */
290 int auth_type;
291
292 /* RIPv2 authentication string. */
293 char *auth_str;
294
295 /* RIPv2 authentication key chain. */
296 char *key_chain;
297
298 /* value to use for md5->auth_len */
299 int md5_auth_len;
300
301 /* Split horizon flag. */
302 split_horizon_policy_t split_horizon;
303
304 /* For filter type slot. */
305 #define RIP_FILTER_IN 0
306 #define RIP_FILTER_OUT 1
307 #define RIP_FILTER_MAX 2
308
309 /* Access-list. */
310 struct access_list *list[RIP_FILTER_MAX];
311
312 /* Prefix-list. */
313 struct prefix_list *prefix[RIP_FILTER_MAX];
314
315 /* Route-map. */
316 struct route_map *routemap[RIP_FILTER_MAX];
317
318 /* Wake up thread. */
319 struct event *t_wakeup;
320
321 /* Interface statistics. */
322 int recv_badpackets;
323 int recv_badroutes;
324 int sent_updates;
325
326 /* Passive interface. */
327 int passive;
328
329 /* BFD information. */
330 struct {
331 bool enabled;
332 char *profile;
333 } bfd;
334 };
335
336 /* RIP peer information. */
337 struct rip_peer {
338 /* Parent routing instance. */
339 struct rip *rip;
340
341 /* Back-pointer to RIP interface. */
342 struct rip_interface *ri;
343
344 /* Peer address. */
345 struct in_addr addr;
346
347 /* Peer RIP tag value. */
348 int domain;
349
350 /* Last update time. */
351 time_t uptime;
352
353 /* Peer RIP version. */
354 uint8_t version;
355
356 /* Statistics. */
357 int recv_badpackets;
358 int recv_badroutes;
359
360 /* Timeout thread. */
361 struct event *t_timeout;
362
363 /* BFD information */
364 struct bfd_session_params *bfd_session;
365 };
366
367 struct 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
375 struct rip_md5_info {
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;
384 };
385
386 struct rip_md5_data {
387 uint16_t family;
388 uint16_t type;
389 uint8_t digest[16];
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
397 #define RI_RIP_VERSION_NONE 4
398 /* N.B. stuff will break if
399 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
400
401 /* RIP event. */
402 enum rip_event {
403 RIP_READ,
404 RIP_UPDATE_EVENT,
405 RIP_TRIGGERED_UPDATE,
406 };
407
408 /* Macro for timer turn on. */
409 #define RIP_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
410
411 #define RIP_OFFSET_LIST_IN 0
412 #define RIP_OFFSET_LIST_OUT 1
413 #define RIP_OFFSET_LIST_MAX 2
414
415 struct rip_offset_list {
416 /* Parent routing instance. */
417 struct rip *rip;
418
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
428 /* Prototypes. */
429 extern void rip_init(void);
430 extern void rip_clean(struct rip *rip);
431 extern void rip_clean_network(struct rip *rip);
432 extern void rip_interfaces_clean(struct rip *rip);
433 extern int rip_passive_nondefault_set(struct rip *rip, const char *ifname);
434 extern int rip_passive_nondefault_unset(struct rip *rip, const char *ifname);
435 extern void rip_passive_nondefault_clean(struct rip *rip);
436 extern void rip_if_init(void);
437 extern void rip_route_map_init(void);
438 extern void rip_zebra_vrf_register(struct vrf *vrf);
439 extern void rip_zebra_vrf_deregister(struct vrf *vrf);
440 extern void rip_zclient_init(struct event_loop *e);
441 extern void rip_zclient_stop(void);
442 extern int if_check_address(struct rip *rip, struct in_addr addr);
443 extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id);
444 extern struct rip *rip_lookup_by_vrf_name(const char *vrf_name);
445 extern struct rip *rip_create(const char *vrf_name, struct vrf *vrf,
446 int socket);
447
448 extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
449 struct connected *);
450 extern int rip_neighbor_lookup(struct rip *rip, struct sockaddr_in *from);
451 extern int rip_neighbor_add(struct rip *rip, struct prefix_ipv4 *p);
452 extern int rip_neighbor_delete(struct rip *rip, struct prefix_ipv4 *p);
453
454 extern int rip_enable_network_add(struct rip *rip, struct prefix *p);
455 extern int rip_enable_network_delete(struct rip *rip, struct prefix *p);
456 extern int rip_enable_if_add(struct rip *rip, const char *ifname);
457 extern int rip_enable_if_delete(struct rip *rip, const char *ifname);
458
459 extern void rip_event(struct rip *rip, enum rip_event event, int sock);
460 extern void rip_ecmp_disable(struct rip *rip);
461
462 extern int rip_create_socket(struct vrf *vrf);
463
464 extern int rip_redistribute_check(struct rip *rip, int type);
465 extern void rip_redistribute_conf_update(struct rip *rip, int type);
466 extern void rip_redistribute_conf_delete(struct rip *rip, int type);
467 extern 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);
471 extern void rip_redistribute_delete(struct rip *rip, int type, int sub_type,
472 struct prefix_ipv4 *p, ifindex_t ifindex);
473 extern void rip_redistribute_withdraw(struct rip *rip, int type);
474 extern void rip_zebra_ipv4_add(struct rip *rip, struct route_node *rp);
475 extern void rip_zebra_ipv4_delete(struct rip *rip, struct route_node *rp);
476 extern void rip_interface_multicast_set(int, struct connected *);
477 extern void rip_distribute_update_interface(struct interface *);
478 extern void rip_if_rmap_update_interface(struct interface *ifp);
479
480 extern int rip_show_network_config(struct vty *vty, struct rip *rip);
481 extern void rip_show_redistribute_config(struct vty *vty, struct rip *rip);
482
483 extern void rip_peer_free(struct rip_peer *peer);
484 extern void rip_peer_update(struct rip *rip, struct rip_interface *ri,
485 struct sockaddr_in *from, uint8_t version);
486 extern void rip_peer_bad_route(struct rip *rip, struct rip_interface *ri,
487 struct sockaddr_in *from);
488 extern void rip_peer_bad_packet(struct rip *rip, struct rip_interface *ri,
489 struct sockaddr_in *from);
490 extern void rip_peer_display(struct vty *vty, struct rip *rip);
491 extern struct rip_peer *rip_peer_lookup(struct rip *rip, struct in_addr *addr);
492 extern struct rip_peer *rip_peer_lookup_next(struct rip *rip,
493 struct in_addr *addr);
494 extern int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2);
495 extern void rip_peer_list_del(void *arg);
496 void rip_peer_delete_routes(const struct rip_peer *peer);
497
498 extern void rip_info_free(struct rip_info *);
499 extern struct rip *rip_info_get_instance(const struct rip_info *rinfo);
500 extern struct rip_distance *rip_distance_new(void);
501 extern void rip_distance_free(struct rip_distance *rdistance);
502 extern uint8_t rip_distance_apply(struct rip *rip, struct rip_info *rinfo);
503 extern void rip_redistribute_enable(struct rip *rip);
504 extern void rip_redistribute_disable(struct rip *rip);
505
506 extern int rip_route_rte(struct rip_info *rinfo);
507 extern struct rip_info *rip_ecmp_add(struct rip *rip,
508 struct rip_info *rinfo_new);
509 extern struct rip_info *rip_ecmp_replace(struct rip *rip,
510 struct rip_info *rinfo_new);
511 extern struct rip_info *rip_ecmp_delete(struct rip *rip,
512 struct rip_info *rinfo);
513
514 extern struct rip_offset_list *rip_offset_list_new(struct rip *rip,
515 const char *ifname);
516 extern void offset_list_del(struct rip_offset_list *offset);
517 extern void offset_list_free(struct rip_offset_list *offset);
518 extern struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
519 const char *ifname);
520 extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
521 uint32_t *);
522 extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
523 uint32_t *);
524 extern int offset_list_cmp(struct rip_offset_list *o1,
525 struct rip_offset_list *o2);
526
527 extern void rip_vrf_init(void);
528 extern void rip_vrf_terminate(void);
529 extern void rip_cli_init(void);
530
531 extern struct zebra_privs_t ripd_privs;
532 extern struct rip_instance_head rip_instances;
533
534 /* Master thread structure. */
535 extern struct event_loop *master;
536
537 DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc));
538 DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc));
539
540 #endif /* _ZEBRA_RIP_H */