1 /* RIP related values and structures.
2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "distribute.h"
29 /* RIP version number. */
32 /* N.B. stuff will break if
33 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
36 /* RIP command list. */
38 #define RIP_RESPONSE 2
39 #define RIP_TRACEON 3 /* Obsolete */
40 #define RIP_TRACEOFF 4 /* Obsolete */
42 #define RIP_POLL_ENTRY 6
43 #define RIP_COMMAND_MAX 7
45 /* RIP metric infinity value.*/
46 #define RIP_METRIC_INFINITY 16
48 /* Normal RIP packet min and max size. */
49 #define RIP_PACKET_MINSIZ 4
50 #define RIP_PACKET_MAXSIZ 512
52 #define RIP_HEADER_SIZE 4
53 #define RIP_RTE_SIZE 20
55 /* Max count of routing table entry in one rip packet. */
56 #define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
58 /* RIP version 2 multicast address. */
59 #ifndef INADDR_RIP_GROUP
60 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
63 /* RIP peer timeout value. */
64 #define RIP_PEER_TIMER_DEFAULT 180
66 /* RIP port number. */
67 #define RIP_PORT_DEFAULT 520
68 #define RIP_VTY_PORT 2602
70 /* Default configuration file name. */
71 #define RIPD_DEFAULT_CONFIG "ripd.conf"
73 /* RIP route types. */
74 #define RIP_ROUTE_RTE 0
75 #define RIP_ROUTE_STATIC 1
76 #define RIP_ROUTE_DEFAULT 2
77 #define RIP_ROUTE_REDISTRIBUTE 3
78 #define RIP_ROUTE_INTERFACE 4
80 /* RIPv2 special RTE family types */
81 #define RIP_FAMILY_AUTH 0xffff
83 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
85 #define RIP_AUTH_DATA 1
86 #define RIP_AUTH_SIMPLE_PASSWORD 2
87 #define RIP_AUTH_MD5 3
89 /* RIPv2 Simple authentication */
90 #define RIP_AUTH_SIMPLE_SIZE 16
92 /* RIPv2 MD5 authentication. */
93 #define RIP_AUTH_MD5_SIZE 16
94 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
97 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
98 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
106 /* VRF this routing instance is associated with. */
109 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
112 /* Status of the routing instance. */
118 /* Default version of rip instance. */
119 int version_send
; /* version 1 or 2 (but not both) */
120 int version_recv
; /* version 1 or 2 or both */
122 /* Output buffer of RIP. */
125 /* RIP routing information base. */
126 struct route_table
*table
;
128 /* RIP static neighbors. */
129 struct route_table
*neighbor
;
131 /* Linked list of RIP peers. */
132 struct list
*peer_list
;
135 struct thread
*t_read
;
137 /* Update and garbage timer. */
138 struct thread
*t_update
;
140 /* Triggered update hack. */
142 struct thread
*t_triggered_update
;
143 struct thread
*t_triggered_interval
;
145 /* RIP timer values. */
146 uint32_t update_time
;
147 uint32_t timeout_time
;
148 uint32_t garbage_time
;
150 /* RIP default metric. */
151 uint8_t default_metric
;
153 /* RIP default distance. */
155 struct route_table
*distance_table
;
160 /* Are we in passive-interface default mode? */
161 bool passive_default
;
163 /* RIP enabled interfaces. */
164 vector enable_interface
;
166 /* RIP enabled networks. */
167 struct route_table
*enable_network
;
169 /* Vector to store passive-interface name. */
170 vector passive_nondefault
;
172 /* RIP offset-lists. */
173 struct list
*offset_list_master
;
175 /* RIP redistribute configuration. */
180 struct route_map
*map
;
184 } redist
[ZEBRA_ROUTE_MAX
];
186 /* For distribute-list container */
187 struct distribute_ctx
*distribute_ctx
;
189 /* For if_rmap container */
190 struct if_rmap_ctx
*if_rmap_ctx
;
192 /* Counters for SNMP. */
194 /* RIP route changes. */
201 RB_HEAD(rip_instance_head
, rip
);
202 RB_PROTOTYPE(rip_instance_head
, rip
, entry
, rip_instance_compare
)
204 /* RIP routing table entry which belong to rip_packet. */
206 uint16_t family
; /* Address family of this route. */
207 uint16_t tag
; /* Route Tag which included in RIP2 packet. */
208 struct in_addr prefix
; /* Prefix of rip route. */
209 struct in_addr mask
; /* Netmask of rip route. */
210 struct in_addr nexthop
; /* Next hop of rip route. */
211 uint32_t metric
; /* Metric value of rip route. */
214 /* RIP packet structure. */
216 unsigned char command
; /* Command type of RIP packet. */
217 unsigned char version
; /* RIP version which coming from peer. */
218 unsigned char pad1
; /* Padding of RIP packet header. */
219 unsigned char pad2
; /* Same as above. */
220 struct rte rte
[1]; /* Address structure. */
223 /* Buffer to read RIP packet. */
225 struct rip_packet rip_packet
;
226 char buf
[RIP_PACKET_MAXSIZ
];
229 /* RIP route information. */
231 /* This route's type. */
241 /* Metric of this route. */
244 /* External metric of this route.
245 if learnt from an externalm proto */
246 uint32_t external_metric
;
248 /* Tag information of this route. */
251 /* Flags of RIP route. */
252 #define RIP_RTF_FIB 1
253 #define RIP_RTF_CHANGED 2
256 /* Garbage collect timer. */
257 struct thread
*t_timeout
;
258 struct thread
*t_garbage_collect
;
260 /* Route-map futures - this variables can be changed. */
261 struct in_addr nexthop_out
;
265 ifindex_t ifindex_out
;
267 struct route_node
*rp
;
273 RIP_NO_SPLIT_HORIZON
= 0,
275 RIP_SPLIT_HORIZON_POISONED_REVERSE
276 } split_horizon_policy_t
;
278 /* RIP specific interface configuration. */
279 struct rip_interface
{
280 /* Parent routing instance. */
283 /* RIP is enabled on this interface. */
285 int enable_interface
;
287 /* RIP is running on this interface. */
290 /* RIP version control. */
294 /* RIPv2 broadcast mode */
297 /* RIPv2 authentication type. */
300 /* RIPv2 authentication string. */
303 /* RIPv2 authentication key chain. */
306 /* value to use for md5->auth_len */
309 /* Split horizon flag. */
310 split_horizon_policy_t split_horizon
;
312 /* For filter type slot. */
313 #define RIP_FILTER_IN 0
314 #define RIP_FILTER_OUT 1
315 #define RIP_FILTER_MAX 2
318 struct access_list
*list
[RIP_FILTER_MAX
];
321 struct prefix_list
*prefix
[RIP_FILTER_MAX
];
324 struct route_map
*routemap
[RIP_FILTER_MAX
];
326 /* Wake up thread. */
327 struct thread
*t_wakeup
;
329 /* Interface statistics. */
334 /* Passive interface. */
338 /* RIP peer information. */
340 /* Parent routing instance. */
346 /* Peer RIP tag value. */
349 /* Last update time. */
352 /* Peer RIP version. */
359 /* Timeout thread. */
360 struct thread
*t_timeout
;
363 struct rip_distance
{
364 /* Distance value for the IP source prefix. */
367 /* Name of the access-list to be matched. */
371 struct rip_md5_info
{
382 struct rip_md5_data
{
388 /* RIP accepet/announce methods. */
389 #define RI_RIP_UNSPEC 0
390 #define RI_RIP_VERSION_1 1
391 #define RI_RIP_VERSION_2 2
392 #define RI_RIP_VERSION_1_AND_2 3
393 #define RI_RIP_VERSION_NONE 4
394 /* N.B. stuff will break if
395 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
401 RIP_TRIGGERED_UPDATE
,
404 /* Macro for timer turn on. */
405 #define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
407 /* Macro for timer turn off. */
408 #define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
410 #define RIP_OFFSET_LIST_IN 0
411 #define RIP_OFFSET_LIST_OUT 1
412 #define RIP_OFFSET_LIST_MAX 2
414 struct rip_offset_list
{
415 /* Parent routing instance. */
422 /* struct access_list *alist; */
424 } direct
[RIP_OFFSET_LIST_MAX
];
428 extern void rip_init(void);
429 extern void rip_clean(struct rip
*rip
);
430 extern void rip_clean_network(struct rip
*rip
);
431 extern void rip_interfaces_clean(struct rip
*rip
);
432 extern int rip_passive_nondefault_set(struct rip
*rip
, const char *ifname
);
433 extern int rip_passive_nondefault_unset(struct rip
*rip
, const char *ifname
);
434 extern void rip_passive_nondefault_clean(struct rip
*rip
);
435 extern void rip_if_init(void);
436 extern void rip_route_map_init(void);
437 extern void rip_zebra_vrf_register(struct vrf
*vrf
);
438 extern void rip_zebra_vrf_deregister(struct vrf
*vrf
);
439 extern void rip_zclient_init(struct thread_master
*);
440 extern void rip_zclient_stop(void);
441 extern int if_check_address(struct rip
*rip
, struct in_addr addr
);
442 extern struct rip
*rip_lookup_by_vrf_id(vrf_id_t vrf_id
);
443 extern struct rip
*rip_lookup_by_vrf_name(const char *vrf_name
);
444 extern struct rip
*rip_create(const char *vrf_name
, struct vrf
*vrf
,
447 extern int rip_request_send(struct sockaddr_in
*, struct interface
*, uint8_t,
449 extern int rip_neighbor_lookup(struct rip
*rip
, struct sockaddr_in
*from
);
450 extern int rip_neighbor_add(struct rip
*rip
, struct prefix_ipv4
*p
);
451 extern int rip_neighbor_delete(struct rip
*rip
, struct prefix_ipv4
*p
);
453 extern int rip_enable_network_add(struct rip
*rip
, struct prefix
*p
);
454 extern int rip_enable_network_delete(struct rip
*rip
, struct prefix
*p
);
455 extern int rip_enable_if_add(struct rip
*rip
, const char *ifname
);
456 extern int rip_enable_if_delete(struct rip
*rip
, const char *ifname
);
458 extern void rip_event(struct rip
*rip
, enum rip_event event
, int sock
);
459 extern void rip_ecmp_disable(struct rip
*rip
);
461 extern int rip_create_socket(struct vrf
*vrf
);
463 extern int rip_redistribute_check(struct rip
*rip
, int type
);
464 extern void rip_redistribute_conf_update(struct rip
*rip
, int type
);
465 extern void rip_redistribute_conf_delete(struct rip
*rip
, int type
);
466 extern void rip_redistribute_add(struct rip
*rip
, int type
, int sub_type
,
467 struct prefix_ipv4
*p
, struct nexthop
*nh
,
468 unsigned int metric
, unsigned char distance
,
470 extern void rip_redistribute_delete(struct rip
*rip
, int type
, int sub_type
,
471 struct prefix_ipv4
*p
, ifindex_t ifindex
);
472 extern void rip_redistribute_withdraw(struct rip
*rip
, int type
);
473 extern void rip_zebra_ipv4_add(struct rip
*rip
, struct route_node
*rp
);
474 extern void rip_zebra_ipv4_delete(struct rip
*rip
, struct route_node
*rp
);
475 extern void rip_interface_multicast_set(int, struct connected
*);
476 extern void rip_distribute_update_interface(struct interface
*);
477 extern void rip_if_rmap_update_interface(struct interface
*ifp
);
479 extern int rip_show_network_config(struct vty
*vty
, struct rip
*rip
);
480 extern void rip_show_redistribute_config(struct vty
*vty
, struct rip
*rip
);
482 extern void rip_peer_update(struct rip
*rip
, struct sockaddr_in
*from
,
484 extern void rip_peer_bad_route(struct rip
*rip
, struct sockaddr_in
*from
);
485 extern void rip_peer_bad_packet(struct rip
*rip
, struct sockaddr_in
*from
);
486 extern void rip_peer_display(struct vty
*vty
, struct rip
*rip
);
487 extern struct rip_peer
*rip_peer_lookup(struct rip
*rip
, struct in_addr
*addr
);
488 extern struct rip_peer
*rip_peer_lookup_next(struct rip
*rip
,
489 struct in_addr
*addr
);
490 extern int rip_peer_list_cmp(struct rip_peer
*p1
, struct rip_peer
*p2
);
491 extern void rip_peer_list_del(void *arg
);
493 extern void rip_info_free(struct rip_info
*);
494 extern struct rip
*rip_info_get_instance(const struct rip_info
*rinfo
);
495 extern struct rip_distance
*rip_distance_new(void);
496 extern void rip_distance_free(struct rip_distance
*rdistance
);
497 extern uint8_t rip_distance_apply(struct rip
*rip
, struct rip_info
*rinfo
);
498 extern void rip_redistribute_enable(struct rip
*rip
);
499 extern void rip_redistribute_disable(struct rip
*rip
);
501 extern int rip_route_rte(struct rip_info
*rinfo
);
502 extern struct rip_info
*rip_ecmp_add(struct rip
*rip
,
503 struct rip_info
*rinfo_new
);
504 extern struct rip_info
*rip_ecmp_replace(struct rip
*rip
,
505 struct rip_info
*rinfo_new
);
506 extern struct rip_info
*rip_ecmp_delete(struct rip
*rip
,
507 struct rip_info
*rinfo
);
509 extern struct rip_offset_list
*rip_offset_list_new(struct rip
*rip
,
511 extern void offset_list_del(struct rip_offset_list
*offset
);
512 extern void offset_list_free(struct rip_offset_list
*offset
);
513 extern struct rip_offset_list
*rip_offset_list_lookup(struct rip
*rip
,
515 extern int rip_offset_list_apply_in(struct prefix_ipv4
*, struct interface
*,
517 extern int rip_offset_list_apply_out(struct prefix_ipv4
*, struct interface
*,
519 extern int offset_list_cmp(struct rip_offset_list
*o1
,
520 struct rip_offset_list
*o2
);
522 extern void rip_vrf_init(void);
523 extern void rip_vrf_terminate(void);
524 extern void rip_cli_init(void);
526 extern struct zebra_privs_t ripd_privs
;
527 extern struct rip_instance_head rip_instances
;
529 /* Master thread strucutre. */
530 extern struct thread_master
*master
;
532 DECLARE_HOOK(rip_ifaddr_add
, (struct connected
* ifc
), (ifc
))
533 DECLARE_HOOK(rip_ifaddr_del
, (struct connected
* ifc
), (ifc
))
535 #endif /* _ZEBRA_RIP_H */