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>
11 #include "distribute.h"
15 /* RIP version number. */
18 /* N.B. stuff will break if
19 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
22 /* RIP command list. */
24 #define RIP_RESPONSE 2
25 #define RIP_TRACEON 3 /* Obsolete */
26 #define RIP_TRACEOFF 4 /* Obsolete */
28 #define RIP_POLL_ENTRY 6
29 #define RIP_COMMAND_MAX 7
31 /* RIP metric infinity value.*/
32 #define RIP_METRIC_INFINITY 16
34 /* Normal RIP packet min and max size. */
35 #define RIP_PACKET_MINSIZ 4
36 #define RIP_PACKET_MAXSIZ 512
38 #define RIP_HEADER_SIZE 4
39 #define RIP_RTE_SIZE 20
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)
44 /* RIP version 2 multicast address. */
45 #ifndef INADDR_RIP_GROUP
46 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
49 /* RIP peer timeout value. */
50 #define RIP_PEER_TIMER_DEFAULT 180
52 /* RIP port number. */
53 #define RIP_PORT_DEFAULT 520
54 #define RIP_VTY_PORT 2602
56 /* Default configuration file name. */
57 #define RIPD_DEFAULT_CONFIG "ripd.conf"
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
66 /* RIPv2 special RTE family types */
67 #define RIP_FAMILY_AUTH 0xffff
69 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
71 #define RIP_AUTH_DATA 1
72 #define RIP_AUTH_SIMPLE_PASSWORD 2
73 #define RIP_AUTH_MD5 3
75 /* RIPv2 Simple authentication */
76 #define RIP_AUTH_SIMPLE_SIZE 16
78 /* RIPv2 MD5 authentication. */
79 #define RIP_AUTH_MD5_SIZE 16
80 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
83 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
84 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
92 /* VRF this routing instance is associated with. */
95 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
98 /* Status of the routing instance. */
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 */
108 /* Output buffer of RIP. */
111 /* RIP routing information base. */
112 struct route_table
*table
;
114 /* RIP static neighbors. */
115 struct route_table
*neighbor
;
117 /* Linked list of RIP peers. */
118 struct list
*peer_list
;
121 struct event
*t_read
;
123 /* Update and garbage timer. */
124 struct event
*t_update
;
126 /* Triggered update hack. */
128 struct event
*t_triggered_update
;
129 struct event
*t_triggered_interval
;
131 /* RIP timer values. */
132 uint32_t update_time
;
133 uint32_t timeout_time
;
134 uint32_t garbage_time
;
136 /* RIP default metric. */
137 uint8_t default_metric
;
139 /* RIP default distance. */
141 struct route_table
*distance_table
;
146 /* Are we in passive-interface default mode? */
147 bool passive_default
;
149 /* RIP enabled interfaces. */
150 vector enable_interface
;
152 /* RIP enabled networks. */
153 struct route_table
*enable_network
;
155 /* Vector to store passive-interface name. */
156 vector passive_nondefault
;
158 /* RIP offset-lists. */
159 struct list
*offset_list_master
;
161 /* RIP redistribute configuration. */
166 struct route_map
*map
;
170 } redist
[ZEBRA_ROUTE_MAX
];
172 /* For distribute-list container */
173 struct distribute_ctx
*distribute_ctx
;
175 /* For if_rmap container */
176 struct if_rmap_ctx
*if_rmap_ctx
;
178 /* Counters for SNMP. */
180 /* RIP route changes. */
187 /* Default BFD profile to use with BFD sessions. */
188 char *default_bfd_profile
;
190 RB_HEAD(rip_instance_head
, rip
);
191 RB_PROTOTYPE(rip_instance_head
, rip
, entry
, rip_instance_compare
)
193 /* RIP routing table entry which belong to rip_packet. */
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. */
203 /* RIP packet structure. */
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. */
212 /* Buffer to read RIP packet. */
214 struct rip_packet rip_packet
;
215 char buf
[RIP_PACKET_MAXSIZ
];
218 /* RIP route information. */
220 /* This route's type. */
230 /* Metric of this route. */
233 /* External metric of this route.
234 if learnt from an externalm proto */
235 uint32_t external_metric
;
237 /* Tag information of this route. */
240 /* Flags of RIP route. */
241 #define RIP_RTF_FIB 1
242 #define RIP_RTF_CHANGED 2
245 /* Garbage collect timer. */
246 struct event
*t_timeout
;
247 struct event
*t_garbage_collect
;
249 /* Route-map futures - this variables can be changed. */
250 struct in_addr nexthop_out
;
254 ifindex_t ifindex_out
;
256 struct route_node
*rp
;
262 RIP_NO_SPLIT_HORIZON
= 0,
264 RIP_SPLIT_HORIZON_POISONED_REVERSE
265 } split_horizon_policy_t
;
267 /* RIP specific interface configuration. */
268 struct rip_interface
{
269 /* Parent routing instance. */
272 /* Interface data from zebra. */
273 struct interface
*ifp
;
275 /* RIP is enabled on this interface. */
277 int enable_interface
;
279 /* RIP is running on this interface. */
282 /* RIP version control. */
286 /* RIPv2 broadcast mode */
289 /* RIPv2 authentication type. */
292 /* RIPv2 authentication string. */
295 /* RIPv2 authentication key chain. */
298 /* value to use for md5->auth_len */
301 /* Split horizon flag. */
302 split_horizon_policy_t split_horizon
;
304 /* For filter type slot. */
305 #define RIP_FILTER_IN 0
306 #define RIP_FILTER_OUT 1
307 #define RIP_FILTER_MAX 2
310 struct access_list
*list
[RIP_FILTER_MAX
];
313 struct prefix_list
*prefix
[RIP_FILTER_MAX
];
316 struct route_map
*routemap
[RIP_FILTER_MAX
];
318 /* Wake up thread. */
319 struct event
*t_wakeup
;
321 /* Interface statistics. */
326 /* Passive interface. */
329 /* BFD information. */
336 /* RIP peer information. */
338 /* Parent routing instance. */
341 /* Back-pointer to RIP interface. */
342 struct rip_interface
*ri
;
347 /* Peer RIP tag value. */
350 /* Last update time. */
353 /* Peer RIP version. */
360 /* Timeout thread. */
361 struct event
*t_timeout
;
363 /* BFD information */
364 struct bfd_session_params
*bfd_session
;
367 struct rip_distance
{
368 /* Distance value for the IP source prefix. */
371 /* Name of the access-list to be matched. */
375 struct rip_md5_info
{
386 struct rip_md5_data
{
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) */
405 RIP_TRIGGERED_UPDATE
,
408 /* Macro for timer turn on. */
409 #define RIP_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
411 #define RIP_OFFSET_LIST_IN 0
412 #define RIP_OFFSET_LIST_OUT 1
413 #define RIP_OFFSET_LIST_MAX 2
415 struct rip_offset_list
{
416 /* Parent routing instance. */
423 /* struct access_list *alist; */
425 } direct
[RIP_OFFSET_LIST_MAX
];
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
,
448 extern int rip_request_send(struct sockaddr_in
*, struct interface
*, uint8_t,
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
);
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
);
459 extern void rip_event(struct rip
*rip
, enum rip_event event
, int sock
);
460 extern void rip_ecmp_disable(struct rip
*rip
);
462 extern int rip_create_socket(struct vrf
*vrf
);
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
,
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
);
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
);
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
);
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
);
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
);
514 extern struct rip_offset_list
*rip_offset_list_new(struct rip
*rip
,
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
,
520 extern int rip_offset_list_apply_in(struct prefix_ipv4
*, struct interface
*,
522 extern int rip_offset_list_apply_out(struct prefix_ipv4
*, struct interface
*,
524 extern int offset_list_cmp(struct rip_offset_list
*o1
,
525 struct rip_offset_list
*o2
);
527 extern void rip_vrf_init(void);
528 extern void rip_vrf_terminate(void);
529 extern void rip_cli_init(void);
531 extern struct zebra_privs_t ripd_privs
;
532 extern struct rip_instance_head rip_instances
;
534 /* Master thread structure. */
535 extern struct event_loop
*master
;
537 DECLARE_HOOK(rip_ifaddr_add
, (struct connected
* ifc
), (ifc
));
538 DECLARE_HOOK(rip_ifaddr_del
, (struct connected
* ifc
), (ifc
));
540 extern void rip_ecmp_change(struct rip
*rip
);
542 #endif /* _ZEBRA_RIP_H */