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"
14 /* RIP version number. */
17 /* N.B. stuff will break if
18 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
21 /* RIP command list. */
23 #define RIP_RESPONSE 2
24 #define RIP_TRACEON 3 /* Obsolete */
25 #define RIP_TRACEOFF 4 /* Obsolete */
27 #define RIP_POLL_ENTRY 6
28 #define RIP_COMMAND_MAX 7
30 /* RIP metric infinity value.*/
31 #define RIP_METRIC_INFINITY 16
33 /* Normal RIP packet min and max size. */
34 #define RIP_PACKET_MINSIZ 4
35 #define RIP_PACKET_MAXSIZ 512
37 #define RIP_HEADER_SIZE 4
38 #define RIP_RTE_SIZE 20
40 /* Max count of routing table entry in one rip packet. */
41 #define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
43 /* RIP version 2 multicast address. */
44 #ifndef INADDR_RIP_GROUP
45 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
48 /* RIP peer timeout value. */
49 #define RIP_PEER_TIMER_DEFAULT 180
51 /* RIP port number. */
52 #define RIP_PORT_DEFAULT 520
53 #define RIP_VTY_PORT 2602
55 /* Default configuration file name. */
56 #define RIPD_DEFAULT_CONFIG "ripd.conf"
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
65 /* RIPv2 special RTE family types */
66 #define RIP_FAMILY_AUTH 0xffff
68 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
70 #define RIP_AUTH_DATA 1
71 #define RIP_AUTH_SIMPLE_PASSWORD 2
72 #define RIP_AUTH_MD5 3
74 /* RIPv2 Simple authentication */
75 #define RIP_AUTH_SIMPLE_SIZE 16
77 /* RIPv2 MD5 authentication. */
78 #define RIP_AUTH_MD5_SIZE 16
79 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
82 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
83 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
91 /* VRF this routing instance is associated with. */
94 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
97 /* Status of the routing instance. */
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 */
107 /* Output buffer of RIP. */
110 /* RIP routing information base. */
111 struct route_table
*table
;
113 /* RIP static neighbors. */
114 struct route_table
*neighbor
;
116 /* Linked list of RIP peers. */
117 struct list
*peer_list
;
120 struct event
*t_read
;
122 /* Update and garbage timer. */
123 struct event
*t_update
;
125 /* Triggered update hack. */
127 struct event
*t_triggered_update
;
128 struct event
*t_triggered_interval
;
130 /* RIP timer values. */
131 uint32_t update_time
;
132 uint32_t timeout_time
;
133 uint32_t garbage_time
;
135 /* RIP default metric. */
136 uint8_t default_metric
;
138 /* RIP default distance. */
140 struct route_table
*distance_table
;
145 /* Are we in passive-interface default mode? */
146 bool passive_default
;
148 /* RIP enabled interfaces. */
149 vector enable_interface
;
151 /* RIP enabled networks. */
152 struct route_table
*enable_network
;
154 /* Vector to store passive-interface name. */
155 vector passive_nondefault
;
157 /* RIP offset-lists. */
158 struct list
*offset_list_master
;
160 /* RIP redistribute configuration. */
165 struct route_map
*map
;
169 } redist
[ZEBRA_ROUTE_MAX
];
171 /* For distribute-list container */
172 struct distribute_ctx
*distribute_ctx
;
174 /* For if_rmap container */
175 struct if_rmap_ctx
*if_rmap_ctx
;
177 /* Counters for SNMP. */
179 /* RIP route changes. */
186 RB_HEAD(rip_instance_head
, rip
);
187 RB_PROTOTYPE(rip_instance_head
, rip
, entry
, rip_instance_compare
)
189 /* RIP routing table entry which belong to rip_packet. */
191 uint16_t family
; /* Address family of this route. */
192 uint16_t tag
; /* Route Tag which included in RIP2 packet. */
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. */
196 uint32_t metric
; /* Metric value of rip route. */
199 /* RIP packet structure. */
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. */
208 /* Buffer to read RIP packet. */
210 struct rip_packet rip_packet
;
211 char buf
[RIP_PACKET_MAXSIZ
];
214 /* RIP route information. */
216 /* This route's type. */
226 /* Metric of this route. */
229 /* External metric of this route.
230 if learnt from an externalm proto */
231 uint32_t external_metric
;
233 /* Tag information of this route. */
236 /* Flags of RIP route. */
237 #define RIP_RTF_FIB 1
238 #define RIP_RTF_CHANGED 2
241 /* Garbage collect timer. */
242 struct event
*t_timeout
;
243 struct event
*t_garbage_collect
;
245 /* Route-map futures - this variables can be changed. */
246 struct in_addr nexthop_out
;
250 ifindex_t ifindex_out
;
252 struct route_node
*rp
;
258 RIP_NO_SPLIT_HORIZON
= 0,
260 RIP_SPLIT_HORIZON_POISONED_REVERSE
261 } split_horizon_policy_t
;
263 /* RIP specific interface configuration. */
264 struct rip_interface
{
265 /* Parent routing instance. */
268 /* RIP is enabled on this interface. */
270 int enable_interface
;
272 /* RIP is running on this interface. */
275 /* RIP version control. */
279 /* RIPv2 broadcast mode */
282 /* RIPv2 authentication type. */
285 /* RIPv2 authentication string. */
288 /* RIPv2 authentication key chain. */
291 /* value to use for md5->auth_len */
294 /* Split horizon flag. */
295 split_horizon_policy_t split_horizon
;
297 /* For filter type slot. */
298 #define RIP_FILTER_IN 0
299 #define RIP_FILTER_OUT 1
300 #define RIP_FILTER_MAX 2
303 struct access_list
*list
[RIP_FILTER_MAX
];
306 struct prefix_list
*prefix
[RIP_FILTER_MAX
];
309 struct route_map
*routemap
[RIP_FILTER_MAX
];
311 /* Wake up thread. */
312 struct event
*t_wakeup
;
314 /* Interface statistics. */
319 /* Passive interface. */
323 /* RIP peer information. */
325 /* Parent routing instance. */
331 /* Peer RIP tag value. */
334 /* Last update time. */
337 /* Peer RIP version. */
344 /* Timeout thread. */
345 struct event
*t_timeout
;
348 struct rip_distance
{
349 /* Distance value for the IP source prefix. */
352 /* Name of the access-list to be matched. */
356 struct rip_md5_info
{
367 struct rip_md5_data
{
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
378 #define RI_RIP_VERSION_NONE 4
379 /* N.B. stuff will break if
380 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
386 RIP_TRIGGERED_UPDATE
,
389 /* Macro for timer turn on. */
390 #define RIP_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
392 #define RIP_OFFSET_LIST_IN 0
393 #define RIP_OFFSET_LIST_OUT 1
394 #define RIP_OFFSET_LIST_MAX 2
396 struct rip_offset_list
{
397 /* Parent routing instance. */
404 /* struct access_list *alist; */
406 } direct
[RIP_OFFSET_LIST_MAX
];
410 extern void rip_init(void);
411 extern void rip_clean(struct rip
*rip
);
412 extern void rip_clean_network(struct rip
*rip
);
413 extern void rip_interfaces_clean(struct rip
*rip
);
414 extern int rip_passive_nondefault_set(struct rip
*rip
, const char *ifname
);
415 extern int rip_passive_nondefault_unset(struct rip
*rip
, const char *ifname
);
416 extern void rip_passive_nondefault_clean(struct rip
*rip
);
417 extern void rip_if_init(void);
418 extern void rip_route_map_init(void);
419 extern void rip_zebra_vrf_register(struct vrf
*vrf
);
420 extern void rip_zebra_vrf_deregister(struct vrf
*vrf
);
421 extern void rip_zclient_init(struct event_loop
*e
);
422 extern void rip_zclient_stop(void);
423 extern int if_check_address(struct rip
*rip
, struct in_addr addr
);
424 extern struct rip
*rip_lookup_by_vrf_id(vrf_id_t vrf_id
);
425 extern struct rip
*rip_lookup_by_vrf_name(const char *vrf_name
);
426 extern struct rip
*rip_create(const char *vrf_name
, struct vrf
*vrf
,
429 extern int rip_request_send(struct sockaddr_in
*, struct interface
*, uint8_t,
431 extern int rip_neighbor_lookup(struct rip
*rip
, struct sockaddr_in
*from
);
432 extern int rip_neighbor_add(struct rip
*rip
, struct prefix_ipv4
*p
);
433 extern int rip_neighbor_delete(struct rip
*rip
, struct prefix_ipv4
*p
);
435 extern int rip_enable_network_add(struct rip
*rip
, struct prefix
*p
);
436 extern int rip_enable_network_delete(struct rip
*rip
, struct prefix
*p
);
437 extern int rip_enable_if_add(struct rip
*rip
, const char *ifname
);
438 extern int rip_enable_if_delete(struct rip
*rip
, const char *ifname
);
440 extern void rip_event(struct rip
*rip
, enum rip_event event
, int sock
);
441 extern void rip_ecmp_disable(struct rip
*rip
);
443 extern int rip_create_socket(struct vrf
*vrf
);
445 extern int rip_redistribute_check(struct rip
*rip
, int type
);
446 extern void rip_redistribute_conf_update(struct rip
*rip
, int type
);
447 extern void rip_redistribute_conf_delete(struct rip
*rip
, int type
);
448 extern 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
,
452 extern void rip_redistribute_delete(struct rip
*rip
, int type
, int sub_type
,
453 struct prefix_ipv4
*p
, ifindex_t ifindex
);
454 extern void rip_redistribute_withdraw(struct rip
*rip
, int type
);
455 extern void rip_zebra_ipv4_add(struct rip
*rip
, struct route_node
*rp
);
456 extern void rip_zebra_ipv4_delete(struct rip
*rip
, struct route_node
*rp
);
457 extern void rip_interface_multicast_set(int, struct connected
*);
458 extern void rip_distribute_update_interface(struct interface
*);
459 extern void rip_if_rmap_update_interface(struct interface
*ifp
);
461 extern int rip_show_network_config(struct vty
*vty
, struct rip
*rip
);
462 extern void rip_show_redistribute_config(struct vty
*vty
, struct rip
*rip
);
464 extern void rip_peer_update(struct rip
*rip
, struct sockaddr_in
*from
,
466 extern void rip_peer_bad_route(struct rip
*rip
, struct sockaddr_in
*from
);
467 extern void rip_peer_bad_packet(struct rip
*rip
, struct sockaddr_in
*from
);
468 extern void rip_peer_display(struct vty
*vty
, struct rip
*rip
);
469 extern struct rip_peer
*rip_peer_lookup(struct rip
*rip
, struct in_addr
*addr
);
470 extern struct rip_peer
*rip_peer_lookup_next(struct rip
*rip
,
471 struct in_addr
*addr
);
472 extern int rip_peer_list_cmp(struct rip_peer
*p1
, struct rip_peer
*p2
);
473 extern void rip_peer_list_del(void *arg
);
475 extern void rip_info_free(struct rip_info
*);
476 extern struct rip
*rip_info_get_instance(const struct rip_info
*rinfo
);
477 extern struct rip_distance
*rip_distance_new(void);
478 extern void rip_distance_free(struct rip_distance
*rdistance
);
479 extern uint8_t rip_distance_apply(struct rip
*rip
, struct rip_info
*rinfo
);
480 extern void rip_redistribute_enable(struct rip
*rip
);
481 extern void rip_redistribute_disable(struct rip
*rip
);
483 extern int rip_route_rte(struct rip_info
*rinfo
);
484 extern struct rip_info
*rip_ecmp_add(struct rip
*rip
,
485 struct rip_info
*rinfo_new
);
486 extern struct rip_info
*rip_ecmp_replace(struct rip
*rip
,
487 struct rip_info
*rinfo_new
);
488 extern struct rip_info
*rip_ecmp_delete(struct rip
*rip
,
489 struct rip_info
*rinfo
);
491 extern struct rip_offset_list
*rip_offset_list_new(struct rip
*rip
,
493 extern void offset_list_del(struct rip_offset_list
*offset
);
494 extern void offset_list_free(struct rip_offset_list
*offset
);
495 extern struct rip_offset_list
*rip_offset_list_lookup(struct rip
*rip
,
497 extern int rip_offset_list_apply_in(struct prefix_ipv4
*, struct interface
*,
499 extern int rip_offset_list_apply_out(struct prefix_ipv4
*, struct interface
*,
501 extern int offset_list_cmp(struct rip_offset_list
*o1
,
502 struct rip_offset_list
*o2
);
504 extern void rip_vrf_init(void);
505 extern void rip_vrf_terminate(void);
506 extern void rip_cli_init(void);
508 extern struct zebra_privs_t ripd_privs
;
509 extern struct rip_instance_head rip_instances
;
511 /* Master thread structure. */
512 extern struct event_loop
*master
;
514 DECLARE_HOOK(rip_ifaddr_add
, (struct connected
* ifc
), (ifc
));
515 DECLARE_HOOK(rip_ifaddr_del
, (struct connected
* ifc
), (ifc
));
517 #endif /* _ZEBRA_RIP_H */