1 /* RIP version 1 and 2.
2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro <kunihiro@zebra.org>
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "sockunion.h"
39 #include "distribute.h"
43 #include "lib_errors.h"
45 #include "ripd/ripd.h"
46 #include "ripd/rip_debug.h"
47 #include "ripd/rip_errors.h"
51 /* UDP receive buffer size */
52 #define RIP_UDP_RCV_BUF 41600
55 struct rip
*rip
= NULL
;
57 /* RIP neighbor address table. */
58 struct route_table
*rip_neighbor_table
;
60 /* RIP route changes. */
61 long rip_global_route_changes
= 0;
64 long rip_global_queries
= 0;
67 static void rip_event(enum rip_event
, int);
68 static void rip_output_process(struct connected
*, struct sockaddr_in
*, int,
70 static int rip_triggered_update(struct thread
*);
71 static int rip_update_jitter(unsigned long);
73 /* RIP output routes type. */
74 enum { rip_all_route
, rip_changed_route
};
76 /* RIP command strings. */
77 static const struct message rip_msg
[] = {{RIP_REQUEST
, "REQUEST"},
78 {RIP_RESPONSE
, "RESPONSE"},
79 {RIP_TRACEON
, "TRACEON"},
80 {RIP_TRACEOFF
, "TRACEOFF"},
82 {RIP_POLL_ENTRY
, "POLL ENTRY"},
85 /* Utility function to set boradcast option to the socket. */
86 static int sockopt_broadcast(int sock
)
91 ret
= setsockopt(sock
, SOL_SOCKET
, SO_BROADCAST
, (char *)&on
,
94 zlog_warn("can't set sockopt SO_BROADCAST to socket %d", sock
);
100 static int rip_route_rte(struct rip_info
*rinfo
)
102 return (rinfo
->type
== ZEBRA_ROUTE_RIP
103 && rinfo
->sub_type
== RIP_ROUTE_RTE
);
106 static struct rip_info
*rip_info_new(void)
108 return XCALLOC(MTYPE_RIP_INFO
, sizeof(struct rip_info
));
111 void rip_info_free(struct rip_info
*rinfo
)
113 XFREE(MTYPE_RIP_INFO
, rinfo
);
116 /* RIP route garbage collect timer. */
117 static int rip_garbage_collect(struct thread
*t
)
119 struct rip_info
*rinfo
;
120 struct route_node
*rp
;
122 rinfo
= THREAD_ARG(t
);
123 rinfo
->t_garbage_collect
= NULL
;
125 /* Off timeout timer. */
126 RIP_TIMER_OFF(rinfo
->t_timeout
);
128 /* Get route_node pointer. */
131 /* Unlock route_node. */
132 listnode_delete(rp
->info
, rinfo
);
133 if (list_isempty((struct list
*)rp
->info
)) {
134 list_delete_and_null((struct list
**)&rp
->info
);
135 route_unlock_node(rp
);
138 /* Free RIP routing information. */
139 rip_info_free(rinfo
);
144 static void rip_timeout_update(struct rip_info
*rinfo
);
146 /* Add new route to the ECMP list.
147 * RETURN: the new entry added in the list, or NULL if it is not the first
148 * entry and ECMP is not allowed.
150 struct rip_info
*rip_ecmp_add(struct rip_info
*rinfo_new
)
152 struct route_node
*rp
= rinfo_new
->rp
;
153 struct rip_info
*rinfo
= NULL
;
154 struct list
*list
= NULL
;
156 if (rp
->info
== NULL
)
157 rp
->info
= list_new();
158 list
= (struct list
*)rp
->info
;
160 /* If ECMP is not allowed and some entry already exists in the list,
162 if (listcount(list
) && !rip
->ecmp
)
165 rinfo
= rip_info_new();
166 memcpy(rinfo
, rinfo_new
, sizeof(struct rip_info
));
167 listnode_add(list
, rinfo
);
169 if (rip_route_rte(rinfo
)) {
170 rip_timeout_update(rinfo
);
171 rip_zebra_ipv4_add(rp
);
174 /* Set the route change flag on the first entry. */
175 rinfo
= listgetdata(listhead(list
));
176 SET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
178 /* Signal the output process to trigger an update (see section 2.5). */
179 rip_event(RIP_TRIGGERED_UPDATE
, 0);
184 /* Replace the ECMP list with the new route.
185 * RETURN: the new entry added in the list
187 struct rip_info
*rip_ecmp_replace(struct rip_info
*rinfo_new
)
189 struct route_node
*rp
= rinfo_new
->rp
;
190 struct list
*list
= (struct list
*)rp
->info
;
191 struct rip_info
*rinfo
= NULL
, *tmp_rinfo
= NULL
;
192 struct listnode
*node
= NULL
, *nextnode
= NULL
;
194 if (list
== NULL
|| listcount(list
) == 0)
195 return rip_ecmp_add(rinfo_new
);
197 /* Get the first entry */
198 rinfo
= listgetdata(listhead(list
));
200 /* Learnt route replaced by a local one. Delete it from zebra. */
201 if (rip_route_rte(rinfo
) && !rip_route_rte(rinfo_new
))
202 if (CHECK_FLAG(rinfo
->flags
, RIP_RTF_FIB
))
203 rip_zebra_ipv4_delete(rp
);
205 /* Re-use the first entry, and delete the others. */
206 for (ALL_LIST_ELEMENTS(list
, node
, nextnode
, tmp_rinfo
))
207 if (tmp_rinfo
!= rinfo
) {
208 RIP_TIMER_OFF(tmp_rinfo
->t_timeout
);
209 RIP_TIMER_OFF(tmp_rinfo
->t_garbage_collect
);
210 list_delete_node(list
, node
);
211 rip_info_free(tmp_rinfo
);
214 RIP_TIMER_OFF(rinfo
->t_timeout
);
215 RIP_TIMER_OFF(rinfo
->t_garbage_collect
);
216 memcpy(rinfo
, rinfo_new
, sizeof(struct rip_info
));
218 if (rip_route_rte(rinfo
)) {
219 rip_timeout_update(rinfo
);
220 /* The ADD message implies an update. */
221 rip_zebra_ipv4_add(rp
);
224 /* Set the route change flag. */
225 SET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
227 /* Signal the output process to trigger an update (see section 2.5). */
228 rip_event(RIP_TRIGGERED_UPDATE
, 0);
233 /* Delete one route from the ECMP list.
235 * null - the entry is freed, and other entries exist in the list
236 * the entry - the entry is the last one in the list; its metric is set
237 * to INFINITY, and the garbage collector is started for it
239 struct rip_info
*rip_ecmp_delete(struct rip_info
*rinfo
)
241 struct route_node
*rp
= rinfo
->rp
;
242 struct list
*list
= (struct list
*)rp
->info
;
244 RIP_TIMER_OFF(rinfo
->t_timeout
);
246 if (listcount(list
) > 1) {
247 /* Some other ECMP entries still exist. Just delete this entry.
249 RIP_TIMER_OFF(rinfo
->t_garbage_collect
);
250 listnode_delete(list
, rinfo
);
251 if (rip_route_rte(rinfo
)
252 && CHECK_FLAG(rinfo
->flags
, RIP_RTF_FIB
))
253 /* The ADD message implies the update. */
254 rip_zebra_ipv4_add(rp
);
255 rip_info_free(rinfo
);
258 assert(rinfo
== listgetdata(listhead(list
)));
260 /* This is the only entry left in the list. We must keep it in
261 * the list for garbage collection time, with INFINITY metric.
264 rinfo
->metric
= RIP_METRIC_INFINITY
;
265 RIP_TIMER_ON(rinfo
->t_garbage_collect
, rip_garbage_collect
,
268 if (rip_route_rte(rinfo
)
269 && CHECK_FLAG(rinfo
->flags
, RIP_RTF_FIB
))
270 rip_zebra_ipv4_delete(rp
);
273 /* Set the route change flag on the first entry. */
274 rinfo
= listgetdata(listhead(list
));
275 SET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
277 /* Signal the output process to trigger an update (see section 2.5). */
278 rip_event(RIP_TRIGGERED_UPDATE
, 0);
283 /* Timeout RIP routes. */
284 static int rip_timeout(struct thread
*t
)
286 rip_ecmp_delete((struct rip_info
*)THREAD_ARG(t
));
290 static void rip_timeout_update(struct rip_info
*rinfo
)
292 if (rinfo
->metric
!= RIP_METRIC_INFINITY
) {
293 RIP_TIMER_OFF(rinfo
->t_timeout
);
294 RIP_TIMER_ON(rinfo
->t_timeout
, rip_timeout
, rip
->timeout_time
);
298 static int rip_filter(int rip_distribute
, struct prefix_ipv4
*p
,
299 struct rip_interface
*ri
)
301 struct distribute
*dist
;
302 struct access_list
*alist
;
303 struct prefix_list
*plist
;
304 int distribute
= rip_distribute
== RIP_FILTER_OUT
? DISTRIBUTE_V4_OUT
306 const char *inout
= rip_distribute
== RIP_FILTER_OUT
? "out" : "in";
308 /* Input distribute-list filtering. */
309 if (ri
->list
[rip_distribute
]) {
310 if (access_list_apply(ri
->list
[rip_distribute
],
313 if (IS_RIP_DEBUG_PACKET
)
314 zlog_debug("%s/%d filtered by distribute %s",
315 inet_ntoa(p
->prefix
), p
->prefixlen
,
320 if (ri
->prefix
[rip_distribute
]) {
321 if (prefix_list_apply(ri
->prefix
[rip_distribute
],
324 if (IS_RIP_DEBUG_PACKET
)
325 zlog_debug("%s/%d filtered by prefix-list %s",
326 inet_ntoa(p
->prefix
), p
->prefixlen
,
332 /* All interface filter check. */
333 dist
= distribute_lookup(NULL
);
335 if (dist
->list
[distribute
]) {
336 alist
= access_list_lookup(AFI_IP
,
337 dist
->list
[distribute
]);
340 if (access_list_apply(alist
, (struct prefix
*)p
)
342 if (IS_RIP_DEBUG_PACKET
)
344 "%s/%d filtered by distribute %s",
345 inet_ntoa(p
->prefix
),
346 p
->prefixlen
, inout
);
351 if (dist
->prefix
[distribute
]) {
352 plist
= prefix_list_lookup(AFI_IP
,
353 dist
->prefix
[distribute
]);
356 if (prefix_list_apply(plist
, (struct prefix
*)p
)
358 if (IS_RIP_DEBUG_PACKET
)
360 "%s/%d filtered by prefix-list %s",
361 inet_ntoa(p
->prefix
),
362 p
->prefixlen
, inout
);
371 /* Check nexthop address validity. */
372 static int rip_nexthop_check(struct in_addr
*addr
)
374 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
375 struct interface
*ifp
;
376 struct listnode
*cnode
;
377 struct connected
*ifc
;
380 /* If nexthop address matches local configured address then it is
383 FOR_ALL_INTERFACES (vrf
, ifp
) {
384 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, ifc
)) {
387 if (p
->family
== AF_INET
388 && IPV4_ADDR_SAME(&p
->u
.prefix4
, addr
))
395 /* RIP add route to routing table. */
396 static void rip_rte_process(struct rte
*rte
, struct sockaddr_in
*from
,
397 struct interface
*ifp
)
400 struct prefix_ipv4 p
;
401 struct route_node
*rp
;
402 struct rip_info
*rinfo
= NULL
, newinfo
;
403 struct rip_interface
*ri
;
404 struct in_addr
*nexthop
;
406 unsigned char old_dist
, new_dist
;
407 struct list
*list
= NULL
;
408 struct listnode
*node
= NULL
;
410 /* Make prefix structure. */
411 memset(&p
, 0, sizeof(struct prefix_ipv4
));
413 p
.prefix
= rte
->prefix
;
414 p
.prefixlen
= ip_masklen(rte
->mask
);
416 /* Make sure mask is applied. */
419 /* Apply input filters. */
422 ret
= rip_filter(RIP_FILTER_IN
, &p
, ri
);
426 memset(&newinfo
, 0, sizeof(newinfo
));
427 newinfo
.type
= ZEBRA_ROUTE_RIP
;
428 newinfo
.sub_type
= RIP_ROUTE_RTE
;
429 newinfo
.nh
.gate
.ipv4
= rte
->nexthop
;
430 newinfo
.from
= from
->sin_addr
;
431 newinfo
.nh
.ifindex
= ifp
->ifindex
;
432 newinfo
.nh
.type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
433 newinfo
.metric
= rte
->metric
;
434 newinfo
.metric_out
= rte
->metric
; /* XXX */
435 newinfo
.tag
= ntohs(rte
->tag
); /* XXX */
437 /* Modify entry according to the interface routemap. */
438 if (ri
->routemap
[RIP_FILTER_IN
]) {
441 /* The object should be of the type of rip_info */
442 ret
= route_map_apply(ri
->routemap
[RIP_FILTER_IN
],
443 (struct prefix
*)&p
, RMAP_RIP
, &newinfo
);
445 if (ret
== RMAP_DENYMATCH
) {
446 if (IS_RIP_DEBUG_PACKET
)
448 "RIP %s/%d is filtered by route-map in",
449 inet_ntoa(p
.prefix
), p
.prefixlen
);
453 /* Get back the object */
454 rte
->nexthop
= newinfo
.nexthop_out
;
455 rte
->tag
= htons(newinfo
.tag_out
); /* XXX */
456 rte
->metric
= newinfo
.metric_out
; /* XXX: the routemap uses the
460 /* Once the entry has been validated, update the metric by
461 adding the cost of the network on wich the message
462 arrived. If the result is greater than infinity, use infinity
463 (RFC2453 Sec. 3.9.2) */
464 /* Zebra ripd can handle offset-list in. */
465 ret
= rip_offset_list_apply_in(&p
, ifp
, &rte
->metric
);
467 /* If offset-list does not modify the metric use interface's
470 rte
->metric
+= ifp
->metric
? ifp
->metric
: 1;
472 if (rte
->metric
> RIP_METRIC_INFINITY
)
473 rte
->metric
= RIP_METRIC_INFINITY
;
475 /* Set nexthop pointer. */
476 if (rte
->nexthop
.s_addr
== 0)
477 nexthop
= &from
->sin_addr
;
479 nexthop
= &rte
->nexthop
;
481 /* Check if nexthop address is myself, then do nothing. */
482 if (rip_nexthop_check(nexthop
) < 0) {
483 if (IS_RIP_DEBUG_PACKET
)
484 zlog_debug("Nexthop address %s is myself",
485 inet_ntoa(*nexthop
));
489 /* Get index for the prefix. */
490 rp
= route_node_get(rip
->table
, (struct prefix
*)&p
);
493 newinfo
.nh
.gate
.ipv4
= *nexthop
;
494 newinfo
.nh
.type
= NEXTHOP_TYPE_IPV4
;
495 newinfo
.metric
= rte
->metric
;
496 newinfo
.tag
= ntohs(rte
->tag
);
497 newinfo
.distance
= rip_distance_apply(&newinfo
);
499 new_dist
= newinfo
.distance
? newinfo
.distance
500 : ZEBRA_RIP_DISTANCE_DEFAULT
;
502 /* Check to see whether there is already RIP route on the table. */
503 if ((list
= rp
->info
) != NULL
)
504 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
)) {
505 /* Need to compare with redistributed entry or local
507 if (!rip_route_rte(rinfo
))
510 if (IPV4_ADDR_SAME(&rinfo
->from
, &from
->sin_addr
)
511 && IPV4_ADDR_SAME(&rinfo
->nh
.gate
.ipv4
, nexthop
))
514 if (!listnextnode(node
)) {
515 /* Not found in the list */
517 if (rte
->metric
> rinfo
->metric
) {
518 /* New route has a greater metric.
520 route_unlock_node(rp
);
524 if (rte
->metric
< rinfo
->metric
)
525 /* New route has a smaller metric.
526 * Replace the ECMP list
527 * with the new one in below. */
530 /* Metrics are same. We compare the distances.
532 old_dist
= rinfo
->distance
534 : ZEBRA_RIP_DISTANCE_DEFAULT
;
536 if (new_dist
> old_dist
) {
537 /* New route has a greater distance.
539 route_unlock_node(rp
);
543 if (new_dist
< old_dist
)
544 /* New route has a smaller distance.
545 * Replace the ECMP list
546 * with the new one in below. */
549 /* Metrics and distances are both same. Keep
551 * the new route is added in the ECMP list in
557 /* Local static route. */
558 if (rinfo
->type
== ZEBRA_ROUTE_RIP
559 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
)
560 || (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
))
561 && rinfo
->metric
!= RIP_METRIC_INFINITY
) {
562 route_unlock_node(rp
);
566 /* Redistributed route check. */
567 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
568 && rinfo
->metric
!= RIP_METRIC_INFINITY
) {
569 old_dist
= rinfo
->distance
;
570 /* Only routes directly connected to an interface
572 * may have a valid NULL distance */
573 if (rinfo
->nh
.gate
.ipv4
.s_addr
!= 0)
576 : ZEBRA_RIP_DISTANCE_DEFAULT
;
577 /* If imported route does not have STRICT precedence,
578 mark it as a ghost */
579 if (new_dist
<= old_dist
580 && rte
->metric
!= RIP_METRIC_INFINITY
)
581 rip_ecmp_replace(&newinfo
);
583 route_unlock_node(rp
);
590 route_unlock_node(rp
);
592 /* Now, check to see whether there is already an explicit route
593 for the destination prefix. If there is no such route, add
594 this route to the routing table, unless the metric is
595 infinity (there is no point in adding a route which
597 if (rte
->metric
!= RIP_METRIC_INFINITY
)
598 rip_ecmp_add(&newinfo
);
600 /* Route is there but we are not sure the route is RIP or not.
603 /* If there is an existing route, compare the next hop address
604 to the address of the router from which the datagram came.
605 If this datagram is from the same router as the existing
606 route, reinitialize the timeout. */
607 same
= (IPV4_ADDR_SAME(&rinfo
->from
, &from
->sin_addr
)
608 && (rinfo
->nh
.ifindex
== ifp
->ifindex
));
610 old_dist
= rinfo
->distance
? rinfo
->distance
611 : ZEBRA_RIP_DISTANCE_DEFAULT
;
613 /* Next, compare the metrics. If the datagram is from the same
614 router as the existing route, and the new metric is different
615 than the old one; or, if the new metric is lower than the old
616 one, or if the tag has been changed; or if there is a route
617 with a lower administrave distance; or an update of the
618 distance on the actual route; do the following actions: */
619 if ((same
&& rinfo
->metric
!= rte
->metric
)
620 || (rte
->metric
< rinfo
->metric
)
621 || ((same
) && (rinfo
->metric
== rte
->metric
)
622 && (newinfo
.tag
!= rinfo
->tag
))
623 || (old_dist
> new_dist
)
624 || ((old_dist
!= new_dist
) && same
)) {
625 if (listcount(list
) == 1) {
626 if (newinfo
.metric
!= RIP_METRIC_INFINITY
)
627 rip_ecmp_replace(&newinfo
);
629 rip_ecmp_delete(rinfo
);
631 if (newinfo
.metric
< rinfo
->metric
)
632 rip_ecmp_replace(&newinfo
);
633 else if (newinfo
.metric
> rinfo
->metric
)
634 rip_ecmp_delete(rinfo
);
635 else if (new_dist
< old_dist
)
636 rip_ecmp_replace(&newinfo
);
637 else if (new_dist
> old_dist
)
638 rip_ecmp_delete(rinfo
);
640 int update
= CHECK_FLAG(rinfo
->flags
,
645 assert(newinfo
.metric
646 != RIP_METRIC_INFINITY
);
648 RIP_TIMER_OFF(rinfo
->t_timeout
);
649 RIP_TIMER_OFF(rinfo
->t_garbage_collect
);
650 memcpy(rinfo
, &newinfo
,
651 sizeof(struct rip_info
));
652 rip_timeout_update(rinfo
);
655 rip_zebra_ipv4_add(rp
);
657 /* - Set the route change flag on the
659 rinfo
= listgetdata(listhead(list
));
660 SET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
661 rip_event(RIP_TRIGGERED_UPDATE
, 0);
664 } else /* same & no change */
665 rip_timeout_update(rinfo
);
667 /* Unlock tempolary lock of the route. */
668 route_unlock_node(rp
);
672 /* Dump RIP packet */
673 static void rip_packet_dump(struct rip_packet
*packet
, int size
,
678 const char *command_str
;
679 char pbuf
[BUFSIZ
], nbuf
[BUFSIZ
];
683 /* Set command string. */
684 if (packet
->command
> 0 && packet
->command
< RIP_COMMAND_MAX
)
685 command_str
= lookup_msg(rip_msg
, packet
->command
, NULL
);
687 command_str
= "unknown";
689 /* Dump packet header. */
690 zlog_debug("%s %s version %d packet size %d", sndrcv
, command_str
,
691 packet
->version
, size
);
693 /* Dump each routing table entry. */
696 for (lim
= (caddr_t
)packet
+ size
; (caddr_t
)rte
< lim
; rte
++) {
697 if (packet
->version
== RIPv2
) {
698 netmask
= ip_masklen(rte
->mask
);
700 if (rte
->family
== htons(RIP_FAMILY_AUTH
)) {
702 == htons(RIP_AUTH_SIMPLE_PASSWORD
)) {
703 p
= (uint8_t *)&rte
->prefix
;
706 " family 0x%X type %d auth string: %s",
709 } else if (rte
->tag
== htons(RIP_AUTH_MD5
)) {
710 struct rip_md5_info
*md5
;
712 md5
= (struct rip_md5_info
*)&packet
716 " family 0x%X type %d (MD5 authentication)",
720 " RIP-2 packet len %d Key ID %d"
722 ntohs(md5
->packet_len
),
723 md5
->keyid
, md5
->auth_len
);
724 zlog_debug(" Sequence Number %ld",
725 (unsigned long)ntohl(
727 } else if (rte
->tag
== htons(RIP_AUTH_DATA
)) {
728 p
= (uint8_t *)&rte
->prefix
;
731 " family 0x%X type %d (MD5 data)",
735 " MD5: %02X%02X%02X%02X%02X%02X%02X%02X"
736 "%02X%02X%02X%02X%02X%02X%02X%02X",
737 p
[0], p
[1], p
[2], p
[3], p
[4],
738 p
[5], p
[6], p
[7], p
[8], p
[9],
739 p
[10], p
[11], p
[12], p
[13],
743 " family 0x%X type %d (Unknown auth type)",
749 " %s/%d -> %s family %d tag %" ROUTE_TAG_PRI
751 inet_ntop(AF_INET
, &rte
->prefix
, pbuf
,
754 inet_ntop(AF_INET
, &rte
->nexthop
, nbuf
,
757 (route_tag_t
)ntohs(rte
->tag
),
758 (unsigned long)ntohl(rte
->metric
));
761 " %s family %d tag %" ROUTE_TAG_PRI
763 inet_ntop(AF_INET
, &rte
->prefix
, pbuf
, BUFSIZ
),
765 (route_tag_t
)ntohs(rte
->tag
),
766 (unsigned long)ntohl(rte
->metric
));
771 /* Check if the destination address is valid (unicast; not net 0
772 or 127) (RFC2453 Section 3.9.2 - Page 26). But we don't
773 check net 0 because we accept default route. */
774 static int rip_destination_check(struct in_addr addr
)
776 uint32_t destination
;
778 /* Convert to host byte order. */
779 destination
= ntohl(addr
.s_addr
);
781 if (IPV4_NET127(destination
))
784 /* Net 0 may match to the default route. */
785 if (IPV4_NET0(destination
) && destination
!= 0)
788 /* Unicast address must belong to class A, B, C. */
789 if (IN_CLASSA(destination
))
791 if (IN_CLASSB(destination
))
793 if (IN_CLASSC(destination
))
799 /* RIP version 2 authentication. */
800 static int rip_auth_simple_password(struct rte
*rte
, struct sockaddr_in
*from
,
801 struct interface
*ifp
)
803 struct rip_interface
*ri
;
804 char *auth_str
= (char *)rte
+ offsetof(struct rte
, prefix
);
807 /* reject passwords with zeros in the middle of the string */
808 for (i
= strnlen(auth_str
, 16); i
< 16; i
++) {
809 if (auth_str
[i
] != '\0')
813 if (IS_RIP_DEBUG_EVENT
)
814 zlog_debug("RIPv2 simple password authentication from %s",
815 inet_ntoa(from
->sin_addr
));
819 if (ri
->auth_type
!= RIP_AUTH_SIMPLE_PASSWORD
820 || rte
->tag
!= htons(RIP_AUTH_SIMPLE_PASSWORD
))
823 /* Simple password authentication. */
825 if (strncmp(auth_str
, ri
->auth_str
, 16) == 0)
829 struct keychain
*keychain
;
832 keychain
= keychain_lookup(ri
->key_chain
);
833 if (keychain
== NULL
|| keychain
->key
== NULL
)
836 key
= key_match_for_accept(keychain
, auth_str
);
843 /* RIP version 2 authentication with MD5. */
844 static int rip_auth_md5(struct rip_packet
*packet
, struct sockaddr_in
*from
,
845 int length
, struct interface
*ifp
)
847 struct rip_interface
*ri
;
848 struct rip_md5_info
*md5
;
849 struct rip_md5_data
*md5data
;
850 struct keychain
*keychain
;
853 uint8_t digest
[RIP_AUTH_MD5_SIZE
];
855 char auth_str
[RIP_AUTH_MD5_SIZE
];
857 if (IS_RIP_DEBUG_EVENT
)
858 zlog_debug("RIPv2 MD5 authentication from %s",
859 inet_ntoa(from
->sin_addr
));
862 md5
= (struct rip_md5_info
*)&packet
->rte
;
864 /* Check auth type. */
865 if (ri
->auth_type
!= RIP_AUTH_MD5
|| md5
->type
!= htons(RIP_AUTH_MD5
))
868 /* If the authentication length is less than 16, then it must be wrong
870 * any interpretation of rfc2082. Some implementations also interpret
871 * this as RIP_HEADER_SIZE+ RIP_AUTH_MD5_SIZE, aka
872 * RIP_AUTH_MD5_COMPAT_SIZE.
874 if (!((md5
->auth_len
== RIP_AUTH_MD5_SIZE
)
875 || (md5
->auth_len
== RIP_AUTH_MD5_COMPAT_SIZE
))) {
876 if (IS_RIP_DEBUG_EVENT
)
878 "RIPv2 MD5 authentication, strange authentication "
884 /* grab and verify check packet length */
885 packet_len
= ntohs(md5
->packet_len
);
887 if (packet_len
> (length
- RIP_HEADER_SIZE
- RIP_AUTH_MD5_SIZE
)) {
888 if (IS_RIP_DEBUG_EVENT
)
890 "RIPv2 MD5 authentication, packet length field %d "
891 "greater than received length %d!",
892 md5
->packet_len
, length
);
896 /* retrieve authentication data */
897 md5data
= (struct rip_md5_data
*)(((uint8_t *)packet
) + packet_len
);
899 memset(auth_str
, 0, RIP_AUTH_MD5_SIZE
);
902 keychain
= keychain_lookup(ri
->key_chain
);
903 if (keychain
== NULL
)
906 key
= key_lookup_for_accept(keychain
, md5
->keyid
);
907 if (key
== NULL
|| key
->string
== NULL
)
910 strncpy(auth_str
, key
->string
, RIP_AUTH_MD5_SIZE
);
911 } else if (ri
->auth_str
)
912 strncpy(auth_str
, ri
->auth_str
, RIP_AUTH_MD5_SIZE
);
914 if (auth_str
[0] == 0)
917 /* MD5 digest authentication. */
918 memset(&ctx
, 0, sizeof(ctx
));
920 MD5Update(&ctx
, packet
, packet_len
+ RIP_HEADER_SIZE
);
921 MD5Update(&ctx
, auth_str
, RIP_AUTH_MD5_SIZE
);
922 MD5Final(digest
, &ctx
);
924 if (memcmp(md5data
->digest
, digest
, RIP_AUTH_MD5_SIZE
) == 0)
930 /* Pick correct auth string for sends, prepare auth_str buffer for use.
931 * (left justified and padded).
933 * presumes one of ri or key is valid, and that the auth strings they point
934 * to are nul terminated. If neither are present, auth_str will be fully
938 static void rip_auth_prepare_str_send(struct rip_interface
*ri
, struct key
*key
,
939 char *auth_str
, int len
)
943 memset(auth_str
, 0, len
);
944 if (key
&& key
->string
)
945 strncpy(auth_str
, key
->string
, len
);
946 else if (ri
->auth_str
)
947 strncpy(auth_str
, ri
->auth_str
, len
);
952 /* Write RIPv2 simple password authentication information
954 * auth_str is presumed to be 2 bytes and correctly prepared
955 * (left justified and zero padded).
957 static void rip_auth_simple_write(struct stream
*s
, char *auth_str
, int len
)
959 assert(s
&& len
== RIP_AUTH_SIMPLE_SIZE
);
961 stream_putw(s
, RIP_FAMILY_AUTH
);
962 stream_putw(s
, RIP_AUTH_SIMPLE_PASSWORD
);
963 stream_put(s
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
968 /* write RIPv2 MD5 "authentication header"
969 * (uses the auth key data field)
971 * Digest offset field is set to 0.
973 * returns: offset of the digest offset field, which must be set when
974 * length to the auth-data MD5 digest is known.
976 static size_t rip_auth_md5_ah_write(struct stream
*s
, struct rip_interface
*ri
,
981 assert(s
&& ri
&& ri
->auth_type
== RIP_AUTH_MD5
);
983 /* MD5 authentication. */
984 stream_putw(s
, RIP_FAMILY_AUTH
);
985 stream_putw(s
, RIP_AUTH_MD5
);
987 /* MD5 AH digest offset field.
989 * Set to placeholder value here, to true value when RIP-2 Packet length
990 * is known. Actual value is set in .....().
992 doff
= stream_get_endp(s
);
997 stream_putc(s
, key
->index
% 256);
1001 /* Auth Data Len. Set 16 for MD5 authentication data. Older ripds
1002 * however expect RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE so we allow for
1004 * to be configurable.
1006 stream_putc(s
, ri
->md5_auth_len
);
1008 /* Sequence Number (non-decreasing). */
1009 /* RFC2080: The value used in the sequence number is
1010 arbitrary, but two suggestions are the time of the
1011 message's creation or a simple message counter. */
1012 stream_putl(s
, time(NULL
));
1014 /* Reserved field must be zero. */
1021 /* If authentication is in used, write the appropriate header
1022 * returns stream offset to which length must later be written
1023 * or 0 if this is not required
1025 static size_t rip_auth_header_write(struct stream
*s
, struct rip_interface
*ri
,
1026 struct key
*key
, char *auth_str
, int len
)
1028 assert(ri
->auth_type
!= RIP_NO_AUTH
);
1030 switch (ri
->auth_type
) {
1031 case RIP_AUTH_SIMPLE_PASSWORD
:
1032 rip_auth_prepare_str_send(ri
, key
, auth_str
, len
);
1033 rip_auth_simple_write(s
, auth_str
, len
);
1036 return rip_auth_md5_ah_write(s
, ri
, key
);
1042 /* Write RIPv2 MD5 authentication data trailer */
1043 static void rip_auth_md5_set(struct stream
*s
, struct rip_interface
*ri
,
1044 size_t doff
, char *auth_str
, int authlen
)
1048 unsigned char digest
[RIP_AUTH_MD5_SIZE
];
1050 /* Make it sure this interface is configured as MD5
1052 assert((ri
->auth_type
== RIP_AUTH_MD5
)
1053 && (authlen
== RIP_AUTH_MD5_SIZE
));
1056 /* Get packet length. */
1057 len
= stream_get_endp(s
);
1059 /* Check packet length. */
1060 if (len
< (RIP_HEADER_SIZE
+ RIP_RTE_SIZE
)) {
1061 flog_err(RIP_ERR_PACKET
,
1062 "rip_auth_md5_set(): packet length %ld is less than minimum length.",
1067 /* Set the digest offset length in the header */
1068 stream_putw_at(s
, doff
, len
);
1070 /* Set authentication data. */
1071 stream_putw(s
, RIP_FAMILY_AUTH
);
1072 stream_putw(s
, RIP_AUTH_DATA
);
1074 /* Generate a digest for the RIP packet. */
1075 memset(&ctx
, 0, sizeof(ctx
));
1077 MD5Update(&ctx
, STREAM_DATA(s
), stream_get_endp(s
));
1078 MD5Update(&ctx
, auth_str
, RIP_AUTH_MD5_SIZE
);
1079 MD5Final(digest
, &ctx
);
1081 /* Copy the digest to the packet. */
1082 stream_write(s
, digest
, RIP_AUTH_MD5_SIZE
);
1085 /* RIP routing information. */
1086 static void rip_response_process(struct rip_packet
*packet
, int size
,
1087 struct sockaddr_in
*from
,
1088 struct connected
*ifc
)
1092 struct prefix_ipv4 ifaddr
;
1093 struct prefix_ipv4 ifaddrclass
;
1096 memset(&ifaddr
, 0, sizeof(ifaddr
));
1097 /* We don't know yet. */
1100 /* The Response must be ignored if it is not from the RIP
1101 port. (RFC2453 - Sec. 3.9.2)*/
1102 if (from
->sin_port
!= htons(RIP_PORT_DEFAULT
)) {
1103 zlog_info("response doesn't come from RIP port: %d",
1105 rip_peer_bad_packet(from
);
1109 /* The datagram's IPv4 source address should be checked to see
1110 whether the datagram is from a valid neighbor; the source of the
1111 datagram must be on a directly connected network (RFC2453 - Sec.
1113 if (if_lookup_address((void *)&from
->sin_addr
, AF_INET
, VRF_DEFAULT
)
1116 "This datagram doesn't came from a valid neighbor: %s",
1117 inet_ntoa(from
->sin_addr
));
1118 rip_peer_bad_packet(from
);
1122 /* It is also worth checking to see whether the response is from one
1123 of the router's own addresses. */
1125 ; /* Alredy done in rip_read () */
1127 /* Update RIP peer. */
1128 rip_peer_update(from
, packet
->version
);
1130 /* Set RTE pointer. */
1133 for (lim
= (caddr_t
)packet
+ size
; (caddr_t
)rte
< lim
; rte
++) {
1134 /* RIPv2 authentication check. */
1135 /* If the Address Family Identifier of the first (and only the
1136 first) entry in the message is 0xFFFF, then the remainder of
1137 the entry contains the authentication. */
1138 /* If the packet gets here it means authentication enabled */
1139 /* Check is done in rip_read(). So, just skipping it */
1140 if (packet
->version
== RIPv2
&& rte
== packet
->rte
1141 && rte
->family
== htons(RIP_FAMILY_AUTH
))
1144 if (rte
->family
!= htons(AF_INET
)) {
1145 /* Address family check. RIP only supports AF_INET. */
1146 zlog_info("Unsupported family %d from %s.",
1148 inet_ntoa(from
->sin_addr
));
1152 /* - is the destination address valid (e.g., unicast; not net 0
1154 if (!rip_destination_check(rte
->prefix
)) {
1156 "Network is net 0 or net 127 or it is not unicast network");
1157 rip_peer_bad_route(from
);
1161 /* Convert metric value to host byte order. */
1162 rte
->metric
= ntohl(rte
->metric
);
1164 /* - is the metric valid (i.e., between 1 and 16, inclusive) */
1165 if (!(rte
->metric
>= 1 && rte
->metric
<= 16)) {
1166 zlog_info("Route's metric is not in the 1-16 range.");
1167 rip_peer_bad_route(from
);
1171 /* RIPv1 does not have nexthop value. */
1172 if (packet
->version
== RIPv1
&& rte
->nexthop
.s_addr
!= 0) {
1173 zlog_info("RIPv1 packet with nexthop value %s",
1174 inet_ntoa(rte
->nexthop
));
1175 rip_peer_bad_route(from
);
1179 /* That is, if the provided information is ignored, a possibly
1180 sub-optimal, but absolutely valid, route may be taken. If
1181 the received Next Hop is not directly reachable, it should be
1182 treated as 0.0.0.0. */
1183 if (packet
->version
== RIPv2
&& rte
->nexthop
.s_addr
!= 0) {
1186 /* Multicast address check. */
1187 addrval
= ntohl(rte
->nexthop
.s_addr
);
1188 if (IN_CLASSD(addrval
)) {
1190 "Nexthop %s is multicast address, skip this rte",
1191 inet_ntoa(rte
->nexthop
));
1195 if (!if_lookup_address((void *)&rte
->nexthop
, AF_INET
,
1197 struct route_node
*rn
;
1198 struct rip_info
*rinfo
;
1200 rn
= route_node_match_ipv4(rip
->table
,
1206 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1209 if (IS_RIP_DEBUG_EVENT
)
1211 "Next hop %s is on RIP network. Set nexthop to the packet's originator",
1214 rte
->nexthop
= rinfo
->from
;
1216 if (IS_RIP_DEBUG_EVENT
)
1218 "Next hop %s is not directly reachable. Treat it as 0.0.0.0",
1221 rte
->nexthop
.s_addr
= 0;
1224 route_unlock_node(rn
);
1226 if (IS_RIP_DEBUG_EVENT
)
1228 "Next hop %s is not directly reachable. Treat it as 0.0.0.0",
1231 rte
->nexthop
.s_addr
= 0;
1236 /* For RIPv1, there won't be a valid netmask.
1238 This is a best guess at the masks. If everyone was using old
1239 Ciscos before the 'ip subnet zero' option, it would be almost
1242 Cisco summarize ripv1 advertisments to the classful boundary
1243 (/16 for class B's) except when the RIP packet does to inside
1244 the classful network in question. */
1246 if ((packet
->version
== RIPv1
&& rte
->prefix
.s_addr
!= 0)
1247 || (packet
->version
== RIPv2
1248 && (rte
->prefix
.s_addr
!= 0
1249 && rte
->mask
.s_addr
== 0))) {
1250 uint32_t destination
;
1252 if (subnetted
== -1) {
1253 memcpy(&ifaddr
, ifc
->address
,
1254 sizeof(struct prefix_ipv4
));
1255 memcpy(&ifaddrclass
, &ifaddr
,
1256 sizeof(struct prefix_ipv4
));
1257 apply_classful_mask_ipv4(&ifaddrclass
);
1259 if (ifaddr
.prefixlen
> ifaddrclass
.prefixlen
)
1263 destination
= ntohl(rte
->prefix
.s_addr
);
1265 if (IN_CLASSA(destination
))
1266 masklen2ip(8, &rte
->mask
);
1267 else if (IN_CLASSB(destination
))
1268 masklen2ip(16, &rte
->mask
);
1269 else if (IN_CLASSC(destination
))
1270 masklen2ip(24, &rte
->mask
);
1273 masklen2ip(ifaddrclass
.prefixlen
,
1274 (struct in_addr
*)&destination
);
1275 if ((subnetted
== 1)
1276 && ((rte
->prefix
.s_addr
& destination
)
1277 == ifaddrclass
.prefix
.s_addr
)) {
1278 masklen2ip(ifaddr
.prefixlen
, &rte
->mask
);
1279 if ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
)
1280 != rte
->prefix
.s_addr
)
1281 masklen2ip(32, &rte
->mask
);
1282 if (IS_RIP_DEBUG_EVENT
)
1283 zlog_debug("Subnetted route %s",
1284 inet_ntoa(rte
->prefix
));
1286 if ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
)
1287 != rte
->prefix
.s_addr
)
1291 if (IS_RIP_DEBUG_EVENT
) {
1292 zlog_debug("Resultant route %s",
1293 inet_ntoa(rte
->prefix
));
1294 zlog_debug("Resultant mask %s",
1295 inet_ntoa(rte
->mask
));
1299 /* In case of RIPv2, if prefix in RTE is not netmask applied one
1300 ignore the entry. */
1301 if ((packet
->version
== RIPv2
) && (rte
->mask
.s_addr
!= 0)
1302 && ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
)
1303 != rte
->prefix
.s_addr
)) {
1305 "RIPv2 address %s is not mask /%d applied one",
1306 inet_ntoa(rte
->prefix
), ip_masklen(rte
->mask
));
1307 rip_peer_bad_route(from
);
1311 /* Default route's netmask is ignored. */
1312 if (packet
->version
== RIPv2
&& (rte
->prefix
.s_addr
== 0)
1313 && (rte
->mask
.s_addr
!= 0)) {
1314 if (IS_RIP_DEBUG_EVENT
)
1316 "Default route with non-zero netmask. Set zero to netmask");
1317 rte
->mask
.s_addr
= 0;
1320 /* Routing table updates. */
1321 rip_rte_process(rte
, from
, ifc
->ifp
);
1325 /* Make socket for RIP protocol. */
1326 static int rip_create_socket(void)
1330 struct sockaddr_in addr
;
1332 memset(&addr
, 0, sizeof(struct sockaddr_in
));
1333 addr
.sin_family
= AF_INET
;
1334 addr
.sin_addr
.s_addr
= INADDR_ANY
;
1335 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1336 addr
.sin_len
= sizeof(struct sockaddr_in
);
1337 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1338 /* sending port must always be the RIP port */
1339 addr
.sin_port
= htons(RIP_PORT_DEFAULT
);
1341 /* Make datagram socket. */
1342 sock
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
1344 flog_err_sys(LIB_ERR_SOCKET
, "Cannot create UDP socket: %s",
1345 safe_strerror(errno
));
1349 sockopt_broadcast(sock
);
1350 sockopt_reuseaddr(sock
);
1351 sockopt_reuseport(sock
);
1352 setsockopt_ipv4_multicast_loop(sock
, 0);
1354 setsockopt_pktinfo(sock
);
1355 #endif /* RIP_RECVMSG */
1356 #ifdef IPTOS_PREC_INTERNETCONTROL
1357 setsockopt_ipv4_tos(sock
, IPTOS_PREC_INTERNETCONTROL
);
1360 frr_elevate_privs(&ripd_privs
) {
1361 setsockopt_so_recvbuf(sock
, RIP_UDP_RCV_BUF
);
1362 if ((ret
= bind(sock
, (struct sockaddr
*)&addr
, sizeof(addr
)))
1364 zlog_err("%s: Can't bind socket %d to %s port %d: %s",
1365 __func__
, sock
, inet_ntoa(addr
.sin_addr
),
1366 (int)ntohs(addr
.sin_port
),
1367 safe_strerror(errno
));
1377 /* RIP packet send to destination address, on interface denoted by
1378 * by connected argument. NULL to argument denotes destination should be
1379 * should be RIP multicast group
1381 static int rip_send_packet(uint8_t *buf
, int size
, struct sockaddr_in
*to
,
1382 struct connected
*ifc
)
1385 struct sockaddr_in sin
;
1387 assert(ifc
!= NULL
);
1389 if (IS_RIP_DEBUG_PACKET
) {
1390 #define ADDRESS_SIZE 20
1391 char dst
[ADDRESS_SIZE
];
1392 dst
[ADDRESS_SIZE
- 1] = '\0';
1395 strncpy(dst
, inet_ntoa(to
->sin_addr
), ADDRESS_SIZE
- 1);
1397 sin
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
1398 strncpy(dst
, inet_ntoa(sin
.sin_addr
), ADDRESS_SIZE
- 1);
1401 zlog_debug("rip_send_packet %s > %s (%s)",
1402 inet_ntoa(ifc
->address
->u
.prefix4
), dst
,
1406 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
1408 * ZEBRA_IFA_SECONDARY is set on linux when an interface is
1410 * with multiple addresses on the same subnet: the first address
1411 * on the subnet is configured "primary", and all subsequent
1413 * on that subnet are treated as "secondary" addresses.
1414 * In order to avoid routing-table bloat on other rip listeners,
1415 * we do not send out RIP packets with ZEBRA_IFA_SECONDARY
1417 * XXX Since Linux is the only system for which the
1418 * ZEBRA_IFA_SECONDARY
1419 * flag is set, we would end up sending a packet for a
1421 * source address on non-linux systems.
1423 if (IS_RIP_DEBUG_PACKET
)
1424 zlog_debug("duplicate dropped");
1428 /* Make destination address. */
1429 memset(&sin
, 0, sizeof(struct sockaddr_in
));
1430 sin
.sin_family
= AF_INET
;
1431 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1432 sin
.sin_len
= sizeof(struct sockaddr_in
);
1433 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1435 /* When destination is specified, use it's port and address. */
1437 sin
.sin_port
= to
->sin_port
;
1438 sin
.sin_addr
= to
->sin_addr
;
1440 sin
.sin_port
= htons(RIP_PORT_DEFAULT
);
1441 sin
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
1443 rip_interface_multicast_set(rip
->sock
, ifc
);
1446 ret
= sendto(rip
->sock
, buf
, size
, 0, (struct sockaddr
*)&sin
,
1447 sizeof(struct sockaddr_in
));
1449 if (IS_RIP_DEBUG_EVENT
)
1450 zlog_debug("SEND to %s.%d", inet_ntoa(sin
.sin_addr
),
1451 ntohs(sin
.sin_port
));
1454 zlog_warn("can't send packet : %s", safe_strerror(errno
));
1459 /* Add redistributed route to RIP table. */
1460 void rip_redistribute_add(int type
, int sub_type
, struct prefix_ipv4
*p
,
1461 struct nexthop
*nh
, unsigned int metric
,
1462 unsigned char distance
, route_tag_t tag
)
1465 struct route_node
*rp
= NULL
;
1466 struct rip_info
*rinfo
= NULL
, newinfo
;
1467 struct list
*list
= NULL
;
1469 /* Redistribute route */
1470 ret
= rip_destination_check(p
->prefix
);
1474 rp
= route_node_get(rip
->table
, (struct prefix
*)p
);
1476 memset(&newinfo
, 0, sizeof(struct rip_info
));
1477 newinfo
.type
= type
;
1478 newinfo
.sub_type
= sub_type
;
1480 newinfo
.external_metric
= metric
;
1481 newinfo
.distance
= distance
;
1482 if (tag
<= UINT16_MAX
) /* RIP only supports 16 bit tags */
1487 if ((list
= rp
->info
) != NULL
&& listcount(list
) != 0) {
1488 rinfo
= listgetdata(listhead(list
));
1490 if (rinfo
->type
== ZEBRA_ROUTE_CONNECT
1491 && rinfo
->sub_type
== RIP_ROUTE_INTERFACE
1492 && rinfo
->metric
!= RIP_METRIC_INFINITY
) {
1493 route_unlock_node(rp
);
1497 /* Manually configured RIP route check. */
1498 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1499 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
)
1500 || (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
))) {
1501 if (type
!= ZEBRA_ROUTE_RIP
1502 || ((sub_type
!= RIP_ROUTE_STATIC
)
1503 && (sub_type
!= RIP_ROUTE_DEFAULT
))) {
1504 route_unlock_node(rp
);
1509 (void)rip_ecmp_replace(&newinfo
);
1510 route_unlock_node(rp
);
1512 (void)rip_ecmp_add(&newinfo
);
1514 if (IS_RIP_DEBUG_EVENT
) {
1515 zlog_debug("Redistribute new prefix %s/%d",
1516 inet_ntoa(p
->prefix
), p
->prefixlen
);
1519 rip_event(RIP_TRIGGERED_UPDATE
, 0);
1522 /* Delete redistributed route from RIP table. */
1523 void rip_redistribute_delete(int type
, int sub_type
, struct prefix_ipv4
*p
,
1527 struct route_node
*rp
;
1528 struct rip_info
*rinfo
;
1530 ret
= rip_destination_check(p
->prefix
);
1534 rp
= route_node_lookup(rip
->table
, (struct prefix
*)p
);
1536 struct list
*list
= rp
->info
;
1538 if (list
!= NULL
&& listcount(list
) != 0) {
1539 rinfo
= listgetdata(listhead(list
));
1540 if (rinfo
!= NULL
&& rinfo
->type
== type
1541 && rinfo
->sub_type
== sub_type
1542 && rinfo
->nh
.ifindex
== ifindex
) {
1543 /* Perform poisoned reverse. */
1544 rinfo
->metric
= RIP_METRIC_INFINITY
;
1545 RIP_TIMER_ON(rinfo
->t_garbage_collect
,
1546 rip_garbage_collect
,
1548 RIP_TIMER_OFF(rinfo
->t_timeout
);
1549 rinfo
->flags
|= RIP_RTF_CHANGED
;
1551 if (IS_RIP_DEBUG_EVENT
)
1553 "Poison %s/%d on the interface %s with an "
1554 "infinity metric [delete]",
1555 inet_ntoa(p
->prefix
),
1557 ifindex2ifname(ifindex
,
1560 rip_event(RIP_TRIGGERED_UPDATE
, 0);
1563 route_unlock_node(rp
);
1567 /* Response to request called from rip_read ().*/
1568 static void rip_request_process(struct rip_packet
*packet
, int size
,
1569 struct sockaddr_in
*from
, struct connected
*ifc
)
1573 struct prefix_ipv4 p
;
1574 struct route_node
*rp
;
1575 struct rip_info
*rinfo
;
1576 struct rip_interface
*ri
;
1578 /* Does not reponse to the requests on the loopback interfaces */
1579 if (if_is_loopback(ifc
->ifp
))
1582 /* Check RIP process is enabled on this interface. */
1583 ri
= ifc
->ifp
->info
;
1587 /* When passive interface is specified, suppress responses */
1591 /* RIP peer update. */
1592 rip_peer_update(from
, packet
->version
);
1594 lim
= ((caddr_t
)packet
) + size
;
1597 /* The Request is processed entry by entry. If there are no
1598 entries, no response is given. */
1599 if (lim
== (caddr_t
)rte
)
1602 /* There is one special case. If there is exactly one entry in the
1603 request, and it has an address family identifier of zero and a
1604 metric of infinity (i.e., 16), then this is a request to send the
1605 entire routing table. */
1606 if (lim
== ((caddr_t
)(rte
+ 1)) && ntohs(rte
->family
) == 0
1607 && ntohl(rte
->metric
) == RIP_METRIC_INFINITY
) {
1608 /* All route with split horizon */
1609 rip_output_process(ifc
, from
, rip_all_route
, packet
->version
);
1611 if (ntohs(rte
->family
) != AF_INET
)
1614 /* Examine the list of RTEs in the Request one by one. For each
1615 entry, look up the destination in the router's routing
1616 database and, if there is a route, put that route's metric in
1617 the metric field of the RTE. If there is no explicit route
1618 to the specified destination, put infinity in the metric
1619 field. Once all the entries have been filled in, change the
1620 command from Request to Response and send the datagram back
1621 to the requestor. */
1624 for (; ((caddr_t
)rte
) < lim
; rte
++) {
1625 p
.prefix
= rte
->prefix
;
1626 p
.prefixlen
= ip_masklen(rte
->mask
);
1627 apply_mask_ipv4(&p
);
1629 rp
= route_node_lookup(rip
->table
, (struct prefix
*)&p
);
1631 rinfo
= listgetdata(
1632 listhead((struct list
*)rp
->info
));
1633 rte
->metric
= htonl(rinfo
->metric
);
1634 route_unlock_node(rp
);
1636 rte
->metric
= htonl(RIP_METRIC_INFINITY
);
1638 packet
->command
= RIP_RESPONSE
;
1640 (void)rip_send_packet((uint8_t *)packet
, size
, from
, ifc
);
1642 rip_global_queries
++;
1646 /* Set IPv6 packet info to the socket. */
1647 static int setsockopt_pktinfo(int sock
)
1652 ret
= setsockopt(sock
, IPPROTO_IP
, IP_PKTINFO
, &val
, sizeof(val
));
1654 zlog_warn("Can't setsockopt IP_PKTINFO : %s",
1655 safe_strerror(errno
));
1659 /* Read RIP packet by recvmsg function. */
1660 int rip_recvmsg(int sock
, uint8_t *buf
, int size
, struct sockaddr_in
*from
,
1666 struct cmsghdr
*ptr
;
1669 memset(&msg
, 0, sizeof(msg
));
1670 msg
.msg_name
= (void *)from
;
1671 msg
.msg_namelen
= sizeof(struct sockaddr_in
);
1674 msg
.msg_control
= (void *)adata
;
1675 msg
.msg_controllen
= sizeof adata
;
1679 ret
= recvmsg(sock
, &msg
, 0);
1683 for (ptr
= ZCMSG_FIRSTHDR(&msg
); ptr
!= NULL
;
1684 ptr
= CMSG_NXTHDR(&msg
, ptr
))
1685 if (ptr
->cmsg_level
== IPPROTO_IP
1686 && ptr
->cmsg_type
== IP_PKTINFO
) {
1687 struct in_pktinfo
*pktinfo
;
1690 pktinfo
= (struct in_pktinfo
*)CMSG_DATA(ptr
);
1691 i
= pktinfo
->ipi_ifindex
;
1696 /* RIP packet read function. */
1697 int rip_read_new(struct thread
*t
)
1701 char buf
[RIP_PACKET_MAXSIZ
];
1702 struct sockaddr_in from
;
1705 /* Fetch socket then register myself. */
1706 sock
= THREAD_FD(t
);
1707 rip_event(RIP_READ
, sock
);
1709 /* Read RIP packet. */
1710 ret
= rip_recvmsg(sock
, buf
, RIP_PACKET_MAXSIZ
, &from
, (int *)&ifindex
);
1712 zlog_warn("Can't read RIP packet: %s", safe_strerror(errno
));
1718 #endif /* RIP_RECVMSG */
1720 /* First entry point of RIP packet. */
1721 static int rip_read(struct thread
*t
)
1726 union rip_buf rip_buf
;
1727 struct rip_packet
*packet
;
1728 struct sockaddr_in from
;
1732 struct interface
*ifp
= NULL
;
1733 struct connected
*ifc
;
1734 struct rip_interface
*ri
;
1737 /* Fetch socket then register myself. */
1738 sock
= THREAD_FD(t
);
1741 /* Add myself to tne next event */
1742 rip_event(RIP_READ
, sock
);
1744 /* RIPd manages only IPv4. */
1745 memset(&from
, 0, sizeof(struct sockaddr_in
));
1746 fromlen
= sizeof(struct sockaddr_in
);
1748 len
= recvfrom(sock
, (char *)&rip_buf
.buf
, sizeof(rip_buf
.buf
), 0,
1749 (struct sockaddr
*)&from
, &fromlen
);
1751 zlog_info("recvfrom failed: %s", safe_strerror(errno
));
1755 /* Check is this packet comming from myself? */
1756 if (if_check_address(from
.sin_addr
)) {
1757 if (IS_RIP_DEBUG_PACKET
)
1758 zlog_debug("ignore packet comes from myself");
1762 /* Which interface is this packet comes from. */
1763 ifc
= if_lookup_address((void *)&from
.sin_addr
, AF_INET
, VRF_DEFAULT
);
1767 /* RIP packet received */
1768 if (IS_RIP_DEBUG_EVENT
)
1769 zlog_debug("RECV packet from %s port %d on %s",
1770 inet_ntoa(from
.sin_addr
), ntohs(from
.sin_port
),
1771 ifp
? ifp
->name
: "unknown");
1773 /* If this packet come from unknown interface, ignore it. */
1776 "rip_read: cannot find interface for packet from %s port %d",
1777 inet_ntoa(from
.sin_addr
), ntohs(from
.sin_port
));
1782 p
.u
.prefix4
= from
.sin_addr
;
1783 p
.prefixlen
= IPV4_MAX_BITLEN
;
1785 ifc
= connected_lookup_prefix(ifp
, &p
);
1789 "rip_read: cannot find connected address for packet from %s "
1790 "port %d on interface %s",
1791 inet_ntoa(from
.sin_addr
), ntohs(from
.sin_port
),
1796 /* Packet length check. */
1797 if (len
< RIP_PACKET_MINSIZ
) {
1798 zlog_warn("packet size %d is smaller than minimum size %d", len
,
1800 rip_peer_bad_packet(&from
);
1803 if (len
> RIP_PACKET_MAXSIZ
) {
1804 zlog_warn("packet size %d is larger than max size %d", len
,
1806 rip_peer_bad_packet(&from
);
1810 /* Packet alignment check. */
1811 if ((len
- RIP_PACKET_MINSIZ
) % 20) {
1812 zlog_warn("packet size %d is wrong for RIP packet alignment",
1814 rip_peer_bad_packet(&from
);
1818 /* Set RTE number. */
1819 rtenum
= ((len
- RIP_PACKET_MINSIZ
) / 20);
1821 /* For easy to handle. */
1822 packet
= &rip_buf
.rip_packet
;
1824 /* RIP version check. */
1825 if (packet
->version
== 0) {
1826 zlog_info("version 0 with command %d received.",
1828 rip_peer_bad_packet(&from
);
1832 /* Dump RIP packet. */
1833 if (IS_RIP_DEBUG_RECV
)
1834 rip_packet_dump(packet
, len
, "RECV");
1836 /* RIP version adjust. This code should rethink now. RFC1058 says
1837 that "Version 1 implementations are to ignore this extra data and
1838 process only the fields specified in this document.". So RIPv3
1839 packet should be treated as RIPv1 ignoring must be zero field. */
1840 if (packet
->version
> RIPv2
)
1841 packet
->version
= RIPv2
;
1843 /* Is RIP running or is this RIP neighbor ?*/
1845 if (!ri
->running
&& !rip_neighbor_lookup(&from
)) {
1846 if (IS_RIP_DEBUG_EVENT
)
1847 zlog_debug("RIP is not enabled on interface %s.",
1849 rip_peer_bad_packet(&from
);
1853 /* RIP Version check. RFC2453, 4.6 and 5.1 */
1854 vrecv
= ((ri
->ri_receive
== RI_RIP_UNSPEC
) ? rip
->version_recv
1856 if (vrecv
== RI_RIP_VERSION_NONE
1857 || ((packet
->version
== RIPv1
) && !(vrecv
& RIPv1
))
1858 || ((packet
->version
== RIPv2
) && !(vrecv
& RIPv2
))) {
1859 if (IS_RIP_DEBUG_PACKET
)
1861 " packet's v%d doesn't fit to if version spec",
1863 rip_peer_bad_packet(&from
);
1867 /* RFC2453 5.2 If the router is not configured to authenticate RIP-2
1868 messages, then RIP-1 and unauthenticated RIP-2 messages will be
1869 accepted; authenticated RIP-2 messages shall be discarded. */
1870 if ((ri
->auth_type
== RIP_NO_AUTH
) && rtenum
1871 && (packet
->version
== RIPv2
)
1872 && (packet
->rte
->family
== htons(RIP_FAMILY_AUTH
))) {
1873 if (IS_RIP_DEBUG_EVENT
)
1875 "packet RIPv%d is dropped because authentication disabled",
1877 rip_peer_bad_packet(&from
);
1882 If the router is configured to authenticate RIP-2 messages, then
1883 RIP-1 messages and RIP-2 messages which pass authentication
1884 testing shall be accepted; unauthenticated and failed
1885 authentication RIP-2 messages shall be discarded. For maximum
1886 security, RIP-1 messages should be ignored when authentication is
1887 in use (see section 4.1); otherwise, the routing information from
1888 authenticated messages will be propagated by RIP-1 routers in an
1889 unauthenticated manner.
1891 /* We make an exception for RIPv1 REQUEST packets, to which we'll
1892 * always reply regardless of authentication settings, because:
1894 * - if there other authorised routers on-link, the REQUESTor can
1895 * passively obtain the routing updates anyway
1896 * - if there are no other authorised routers on-link, RIP can
1897 * easily be disabled for the link to prevent giving out information
1898 * on state of this routers RIP routing table..
1900 * I.e. if RIPv1 has any place anymore these days, it's as a very
1901 * simple way to distribute routing information (e.g. to embedded
1902 * hosts / appliances) and the ability to give out RIPv1
1903 * routing-information freely, while still requiring RIPv2
1904 * authentication for any RESPONSEs might be vaguely useful.
1906 if (ri
->auth_type
!= RIP_NO_AUTH
&& packet
->version
== RIPv1
) {
1907 /* Discard RIPv1 messages other than REQUESTs */
1908 if (packet
->command
!= RIP_REQUEST
) {
1909 if (IS_RIP_DEBUG_PACKET
)
1912 " dropped because authentication enabled");
1913 rip_peer_bad_packet(&from
);
1916 } else if (ri
->auth_type
!= RIP_NO_AUTH
) {
1917 const char *auth_desc
;
1920 /* There definitely is no authentication in the packet.
1922 if (IS_RIP_DEBUG_PACKET
)
1924 "RIPv2 authentication failed: no auth RTE in packet");
1925 rip_peer_bad_packet(&from
);
1929 /* First RTE must be an Authentication Family RTE */
1930 if (packet
->rte
->family
!= htons(RIP_FAMILY_AUTH
)) {
1931 if (IS_RIP_DEBUG_PACKET
)
1934 " dropped because authentication enabled");
1935 rip_peer_bad_packet(&from
);
1939 /* Check RIPv2 authentication. */
1940 switch (ntohs(packet
->rte
->tag
)) {
1941 case RIP_AUTH_SIMPLE_PASSWORD
:
1942 auth_desc
= "simple";
1943 ret
= rip_auth_simple_password(packet
->rte
, &from
, ifp
);
1948 ret
= rip_auth_md5(packet
, &from
, len
, ifp
);
1949 /* Reset RIP packet length to trim MD5 data. */
1955 auth_desc
= "unknown type";
1956 if (IS_RIP_DEBUG_PACKET
)
1958 "RIPv2 Unknown authentication type %d",
1959 ntohs(packet
->rte
->tag
));
1963 if (IS_RIP_DEBUG_PACKET
)
1964 zlog_debug("RIPv2 %s authentication success",
1967 if (IS_RIP_DEBUG_PACKET
)
1968 zlog_debug("RIPv2 %s authentication failure",
1970 rip_peer_bad_packet(&from
);
1975 /* Process each command. */
1976 switch (packet
->command
) {
1978 rip_response_process(packet
, len
, &from
, ifc
);
1982 rip_request_process(packet
, len
, &from
, ifc
);
1987 "Obsolete command %s received, please sent it to routed",
1988 lookup_msg(rip_msg
, packet
->command
, NULL
));
1989 rip_peer_bad_packet(&from
);
1991 case RIP_POLL_ENTRY
:
1992 zlog_info("Obsolete command %s received",
1993 lookup_msg(rip_msg
, packet
->command
, NULL
));
1994 rip_peer_bad_packet(&from
);
1997 zlog_info("Unknown RIP command %d received", packet
->command
);
1998 rip_peer_bad_packet(&from
);
2005 /* Write routing table entry to the stream and return next index of
2006 the routing table entry in the stream. */
2007 static int rip_write_rte(int num
, struct stream
*s
, struct prefix_ipv4
*p
,
2008 uint8_t version
, struct rip_info
*rinfo
)
2010 struct in_addr mask
;
2012 /* Write routing table entry. */
2013 if (version
== RIPv1
) {
2014 stream_putw(s
, AF_INET
);
2016 stream_put_ipv4(s
, p
->prefix
.s_addr
);
2017 stream_put_ipv4(s
, 0);
2018 stream_put_ipv4(s
, 0);
2019 stream_putl(s
, rinfo
->metric_out
);
2021 masklen2ip(p
->prefixlen
, &mask
);
2023 stream_putw(s
, AF_INET
);
2024 stream_putw(s
, rinfo
->tag_out
);
2025 stream_put_ipv4(s
, p
->prefix
.s_addr
);
2026 stream_put_ipv4(s
, mask
.s_addr
);
2027 stream_put_ipv4(s
, rinfo
->nexthop_out
.s_addr
);
2028 stream_putl(s
, rinfo
->metric_out
);
2034 /* Send update to the ifp or spcified neighbor. */
2035 void rip_output_process(struct connected
*ifc
, struct sockaddr_in
*to
,
2036 int route_type
, uint8_t version
)
2040 struct route_node
*rp
;
2041 struct rip_info
*rinfo
;
2042 struct rip_interface
*ri
;
2043 struct prefix_ipv4
*p
;
2044 struct prefix_ipv4 classfull
;
2045 struct prefix_ipv4 ifaddrclass
;
2046 struct key
*key
= NULL
;
2047 /* this might need to made dynamic if RIP ever supported auth methods
2048 with larger key string sizes */
2049 char auth_str
[RIP_AUTH_SIMPLE_SIZE
];
2050 size_t doff
= 0; /* offset of digest offset field */
2054 struct list
*list
= NULL
;
2055 struct listnode
*listnode
= NULL
;
2057 /* Logging output event. */
2058 if (IS_RIP_DEBUG_EVENT
) {
2060 zlog_debug("update routes to neighbor %s",
2061 inet_ntoa(to
->sin_addr
));
2063 zlog_debug("update routes on interface %s ifindex %d",
2064 ifc
->ifp
->name
, ifc
->ifp
->ifindex
);
2067 /* Set output stream. */
2070 /* Reset stream and RTE counter. */
2072 rtemax
= RIP_MAX_RTE
;
2074 /* Get RIP interface. */
2075 ri
= ifc
->ifp
->info
;
2077 /* If output interface is in simple password authentication mode, we
2078 need space for authentication data. */
2079 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
2082 /* If output interface is in MD5 authentication mode, we need space
2083 for authentication header and data. */
2084 if (ri
->auth_type
== RIP_AUTH_MD5
)
2087 /* If output interface is in simple password authentication mode
2088 and string or keychain is specified we need space for auth. data */
2089 if (ri
->auth_type
!= RIP_NO_AUTH
) {
2090 if (ri
->key_chain
) {
2091 struct keychain
*keychain
;
2093 keychain
= keychain_lookup(ri
->key_chain
);
2095 key
= key_lookup_for_send(keychain
);
2097 /* to be passed to auth functions later */
2098 rip_auth_prepare_str_send(ri
, key
, auth_str
,
2099 RIP_AUTH_SIMPLE_SIZE
);
2100 if (strlen(auth_str
) == 0)
2104 if (version
== RIPv1
) {
2105 memcpy(&ifaddrclass
, ifc
->address
, sizeof(struct prefix_ipv4
));
2106 apply_classful_mask_ipv4(&ifaddrclass
);
2108 if (ifc
->address
->prefixlen
> ifaddrclass
.prefixlen
)
2112 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
2113 if ((list
= rp
->info
) != NULL
&& listcount(list
) != 0) {
2114 rinfo
= listgetdata(listhead(list
));
2115 /* For RIPv1, if we are subnetted, output subnets in our
2117 /* that have the same mask as the output "interface".
2119 /* networks, only the classfull version is output. */
2121 if (version
== RIPv1
) {
2122 p
= (struct prefix_ipv4
*)&rp
->p
;
2124 if (IS_RIP_DEBUG_PACKET
)
2126 "RIPv1 mask check, %s/%d considered for output",
2127 inet_ntoa(rp
->p
.u
.prefix4
),
2132 (struct prefix
*)&ifaddrclass
,
2134 if ((ifc
->address
->prefixlen
2136 && (rp
->p
.prefixlen
!= 32))
2139 memcpy(&classfull
, &rp
->p
,
2140 sizeof(struct prefix_ipv4
));
2141 apply_classful_mask_ipv4(&classfull
);
2142 if (rp
->p
.u
.prefix4
.s_addr
!= 0
2143 && classfull
.prefixlen
2147 if (IS_RIP_DEBUG_PACKET
)
2149 "RIPv1 mask check, %s/%d made it through",
2150 inet_ntoa(rp
->p
.u
.prefix4
),
2153 p
= (struct prefix_ipv4
*)&rp
->p
;
2155 /* Apply output filters. */
2156 ret
= rip_filter(RIP_FILTER_OUT
, p
, ri
);
2160 /* Changed route only output. */
2161 if (route_type
== rip_changed_route
2162 && (!(rinfo
->flags
& RIP_RTF_CHANGED
)))
2165 /* Split horizon. */
2166 /* if (split_horizon == rip_split_horizon) */
2167 if (ri
->split_horizon
== RIP_SPLIT_HORIZON
) {
2169 * We perform split horizon for RIP and
2171 * For rip routes, we want to suppress the route
2173 * end up sending the route back on the
2175 * learned it from, with a higher metric. For
2177 * we suppress the route if the prefix is a
2179 * source address that we are going to use for
2181 * (in order to handle the case when multiple
2183 * configured on the same interface).
2186 struct rip_info
*tmp_rinfo
= NULL
;
2187 struct connected
*tmp_ifc
= NULL
;
2189 for (ALL_LIST_ELEMENTS_RO(list
, listnode
,
2191 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
2192 && tmp_rinfo
->nh
.ifindex
2193 == ifc
->ifp
->ifindex
) {
2199 && rinfo
->type
== ZEBRA_ROUTE_CONNECT
) {
2200 for (ALL_LIST_ELEMENTS_RO(
2201 ifc
->ifp
->connected
,
2205 tmp_ifc
->address
)) {
2215 /* Preparation for route-map. */
2216 rinfo
->metric_set
= 0;
2217 rinfo
->nexthop_out
.s_addr
= 0;
2218 rinfo
->metric_out
= rinfo
->metric
;
2219 rinfo
->tag_out
= rinfo
->tag
;
2220 rinfo
->ifindex_out
= ifc
->ifp
->ifindex
;
2222 /* In order to avoid some local loops,
2223 * if the RIP route has a nexthop via this interface,
2225 * otherwise set it to 0. The nexthop should not be
2227 * beyond the local broadcast/multicast area in order
2228 * to avoid an IGP multi-level recursive look-up.
2231 if (rinfo
->nh
.ifindex
== ifc
->ifp
->ifindex
)
2232 rinfo
->nexthop_out
= rinfo
->nh
.gate
.ipv4
;
2234 /* Interface route-map */
2235 if (ri
->routemap
[RIP_FILTER_OUT
]) {
2236 ret
= route_map_apply(
2237 ri
->routemap
[RIP_FILTER_OUT
],
2238 (struct prefix
*)p
, RMAP_RIP
, rinfo
);
2240 if (ret
== RMAP_DENYMATCH
) {
2241 if (IS_RIP_DEBUG_PACKET
)
2243 "RIP %s/%d is filtered by route-map out",
2244 inet_ntoa(p
->prefix
),
2250 /* Apply redistribute route map - continue, if deny */
2251 if (rip
->route_map
[rinfo
->type
].name
2252 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
) {
2253 ret
= route_map_apply(
2254 rip
->route_map
[rinfo
->type
].map
,
2255 (struct prefix
*)p
, RMAP_RIP
, rinfo
);
2257 if (ret
== RMAP_DENYMATCH
) {
2258 if (IS_RIP_DEBUG_PACKET
)
2260 "%s/%d is filtered by route-map",
2261 inet_ntoa(p
->prefix
),
2267 /* When route-map does not set metric. */
2268 if (!rinfo
->metric_set
) {
2269 /* If redistribute metric is set. */
2270 if (rip
->route_map
[rinfo
->type
].metric_config
2271 && rinfo
->metric
!= RIP_METRIC_INFINITY
) {
2273 rip
->route_map
[rinfo
->type
]
2276 /* If the route is not connected or
2278 one, use default-metric value*/
2279 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
2281 != ZEBRA_ROUTE_CONNECT
2283 != RIP_METRIC_INFINITY
)
2285 rip
->default_metric
;
2289 /* Apply offset-list */
2290 if (rinfo
->metric
!= RIP_METRIC_INFINITY
)
2291 rip_offset_list_apply_out(p
, ifc
->ifp
,
2292 &rinfo
->metric_out
);
2294 if (rinfo
->metric_out
> RIP_METRIC_INFINITY
)
2295 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2297 /* Perform split-horizon with poisoned reverse
2298 * for RIP and connected routes.
2300 if (ri
->split_horizon
2301 == RIP_SPLIT_HORIZON_POISONED_REVERSE
) {
2303 * We perform split horizon for RIP and
2305 * For rip routes, we want to suppress the route
2307 * end up sending the route back on the
2309 * learned it from, with a higher metric. For
2311 * we suppress the route if the prefix is a
2313 * source address that we are going to use for
2315 * (in order to handle the case when multiple
2317 * configured on the same interface).
2319 struct rip_info
*tmp_rinfo
= NULL
;
2320 struct connected
*tmp_ifc
= NULL
;
2322 for (ALL_LIST_ELEMENTS_RO(list
, listnode
,
2324 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
2325 && tmp_rinfo
->nh
.ifindex
2326 == ifc
->ifp
->ifindex
)
2328 RIP_METRIC_INFINITY
;
2330 if (rinfo
->metric_out
!= RIP_METRIC_INFINITY
2331 && rinfo
->type
== ZEBRA_ROUTE_CONNECT
) {
2332 for (ALL_LIST_ELEMENTS_RO(
2333 ifc
->ifp
->connected
,
2337 tmp_ifc
->address
)) {
2339 RIP_METRIC_INFINITY
;
2345 /* Prepare preamble, auth headers, if needs be */
2347 stream_putc(s
, RIP_RESPONSE
);
2348 stream_putc(s
, version
);
2351 /* auth header for !v1 && !no_auth */
2352 if ((ri
->auth_type
!= RIP_NO_AUTH
)
2353 && (version
!= RIPv1
))
2354 doff
= rip_auth_header_write(
2355 s
, ri
, key
, auth_str
,
2356 RIP_AUTH_SIMPLE_SIZE
);
2359 /* Write RTE to the stream. */
2360 num
= rip_write_rte(num
, s
, p
, version
, rinfo
);
2361 if (num
== rtemax
) {
2362 if (version
== RIPv2
2363 && ri
->auth_type
== RIP_AUTH_MD5
)
2364 rip_auth_md5_set(s
, ri
, doff
, auth_str
,
2365 RIP_AUTH_SIMPLE_SIZE
);
2367 ret
= rip_send_packet(STREAM_DATA(s
),
2368 stream_get_endp(s
), to
,
2371 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2372 rip_packet_dump((struct rip_packet
*)
2381 /* Flush unwritten RTE. */
2383 if (version
== RIPv2
&& ri
->auth_type
== RIP_AUTH_MD5
)
2384 rip_auth_md5_set(s
, ri
, doff
, auth_str
,
2385 RIP_AUTH_SIMPLE_SIZE
);
2387 ret
= rip_send_packet(STREAM_DATA(s
), stream_get_endp(s
), to
,
2390 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2391 rip_packet_dump((struct rip_packet
*)STREAM_DATA(s
),
2392 stream_get_endp(s
), "SEND");
2396 /* Statistics updates. */
2400 /* Send RIP packet to the interface. */
2401 static void rip_update_interface(struct connected
*ifc
, uint8_t version
,
2404 struct interface
*ifp
= ifc
->ifp
;
2405 struct rip_interface
*ri
= ifp
->info
;
2406 struct sockaddr_in to
;
2408 /* When RIP version is 2 and multicast enable interface. */
2409 if (version
== RIPv2
&& !ri
->v2_broadcast
&& if_is_multicast(ifp
)) {
2410 if (IS_RIP_DEBUG_EVENT
)
2411 zlog_debug("multicast announce on %s ", ifp
->name
);
2413 rip_output_process(ifc
, NULL
, route_type
, version
);
2417 /* If we can't send multicast packet, send it with unicast. */
2418 if (if_is_broadcast(ifp
) || if_is_pointopoint(ifp
)) {
2419 if (ifc
->address
->family
== AF_INET
) {
2420 /* Destination address and port setting. */
2421 memset(&to
, 0, sizeof(struct sockaddr_in
));
2422 if (ifc
->destination
)
2423 /* use specified broadcast or peer destination
2425 to
.sin_addr
= ifc
->destination
->u
.prefix4
;
2426 else if (ifc
->address
->prefixlen
< IPV4_MAX_PREFIXLEN
)
2427 /* calculate the appropriate broadcast address
2429 to
.sin_addr
.s_addr
= ipv4_broadcast_addr(
2430 ifc
->address
->u
.prefix4
.s_addr
,
2431 ifc
->address
->prefixlen
);
2433 /* do not know where to send the packet */
2435 to
.sin_port
= htons(RIP_PORT_DEFAULT
);
2437 if (IS_RIP_DEBUG_EVENT
)
2438 zlog_debug("%s announce to %s on %s",
2439 CONNECTED_PEER(ifc
) ? "unicast"
2441 inet_ntoa(to
.sin_addr
), ifp
->name
);
2443 rip_output_process(ifc
, &to
, route_type
, version
);
2448 /* Update send to all interface and neighbor. */
2449 static void rip_update_process(int route_type
)
2451 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2452 struct listnode
*ifnode
, *ifnnode
;
2453 struct connected
*connected
;
2454 struct interface
*ifp
;
2455 struct rip_interface
*ri
;
2456 struct route_node
*rp
;
2457 struct sockaddr_in to
;
2460 /* Send RIP update to each interface. */
2461 FOR_ALL_INTERFACES (vrf
, ifp
) {
2462 if (if_is_loopback(ifp
))
2465 if (!if_is_operative(ifp
))
2468 /* Fetch RIP interface information. */
2471 /* When passive interface is specified, suppress announce to the
2478 * If there is no version configuration in the
2480 * use rip's version setting.
2482 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
)
2486 if (IS_RIP_DEBUG_EVENT
)
2487 zlog_debug("SEND UPDATE to %s ifindex %d",
2488 ifp
->name
, ifp
->ifindex
);
2490 /* send update on each connected network */
2491 for (ALL_LIST_ELEMENTS(ifp
->connected
, ifnode
, ifnnode
,
2493 if (connected
->address
->family
== AF_INET
) {
2495 rip_update_interface(
2499 && if_is_multicast(ifp
))
2500 rip_update_interface(
2508 /* RIP send updates to each neighbor. */
2509 for (rp
= route_top(rip
->neighbor
); rp
; rp
= route_next(rp
))
2510 if (rp
->info
!= NULL
) {
2513 connected
= if_lookup_address(&p
->u
.prefix4
, AF_INET
,
2517 "Neighbor %s doesnt have connected interface!",
2518 inet_ntoa(p
->u
.prefix4
));
2522 /* Set destination address and port */
2523 memset(&to
, 0, sizeof(struct sockaddr_in
));
2524 to
.sin_addr
= p
->u
.prefix4
;
2525 to
.sin_port
= htons(RIP_PORT_DEFAULT
);
2527 /* RIP version is rip's configuration. */
2528 rip_output_process(connected
, &to
, route_type
,
2533 /* RIP's periodical timer. */
2534 static int rip_update(struct thread
*t
)
2536 /* Clear timer pointer. */
2537 rip
->t_update
= NULL
;
2539 if (IS_RIP_DEBUG_EVENT
)
2540 zlog_debug("update timer fire!");
2542 /* Process update output. */
2543 rip_update_process(rip_all_route
);
2545 /* Triggered updates may be suppressed if a regular update is due by
2546 the time the triggered update would be sent. */
2547 RIP_TIMER_OFF(rip
->t_triggered_interval
);
2550 /* Register myself. */
2551 rip_event(RIP_UPDATE_EVENT
, 0);
2556 /* Walk down the RIP routing table then clear changed flag. */
2557 static void rip_clear_changed_flag(void)
2559 struct route_node
*rp
;
2560 struct rip_info
*rinfo
= NULL
;
2561 struct list
*list
= NULL
;
2562 struct listnode
*listnode
= NULL
;
2564 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
2565 if ((list
= rp
->info
) != NULL
)
2566 for (ALL_LIST_ELEMENTS_RO(list
, listnode
, rinfo
)) {
2567 UNSET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
2568 /* This flag can be set only on the first entry.
2574 /* Triggered update interval timer. */
2575 static int rip_triggered_interval(struct thread
*t
)
2577 int rip_triggered_update(struct thread
*);
2579 rip
->t_triggered_interval
= NULL
;
2583 rip_triggered_update(t
);
2588 /* Execute triggered update. */
2589 static int rip_triggered_update(struct thread
*t
)
2593 /* Clear thred pointer. */
2594 rip
->t_triggered_update
= NULL
;
2596 /* Cancel interval timer. */
2597 RIP_TIMER_OFF(rip
->t_triggered_interval
);
2600 /* Logging triggered update. */
2601 if (IS_RIP_DEBUG_EVENT
)
2602 zlog_debug("triggered update!");
2604 /* Split Horizon processing is done when generating triggered
2605 updates as well as normal updates (see section 2.6). */
2606 rip_update_process(rip_changed_route
);
2608 /* Once all of the triggered updates have been generated, the route
2609 change flags should be cleared. */
2610 rip_clear_changed_flag();
2612 /* After a triggered update is sent, a timer should be set for a
2613 random interval between 1 and 5 seconds. If other changes that
2614 would trigger updates occur before the timer expires, a single
2615 update is triggered when the timer expires. */
2616 interval
= (random() % 5) + 1;
2618 rip
->t_triggered_interval
= NULL
;
2619 thread_add_timer(master
, rip_triggered_interval
, NULL
, interval
,
2620 &rip
->t_triggered_interval
);
2625 /* Withdraw redistributed route. */
2626 void rip_redistribute_withdraw(int type
)
2628 struct route_node
*rp
;
2629 struct rip_info
*rinfo
= NULL
;
2630 struct list
*list
= NULL
;
2635 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
2636 if ((list
= rp
->info
) != NULL
) {
2637 rinfo
= listgetdata(listhead(list
));
2638 if (rinfo
->type
== type
2639 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
) {
2640 /* Perform poisoned reverse. */
2641 rinfo
->metric
= RIP_METRIC_INFINITY
;
2642 RIP_TIMER_ON(rinfo
->t_garbage_collect
,
2643 rip_garbage_collect
,
2645 RIP_TIMER_OFF(rinfo
->t_timeout
);
2646 rinfo
->flags
|= RIP_RTF_CHANGED
;
2648 if (IS_RIP_DEBUG_EVENT
) {
2649 struct prefix_ipv4
*p
=
2650 (struct prefix_ipv4
*)&rp
->p
;
2653 "Poisone %s/%d on the interface %s with an infinity metric [withdraw]",
2654 inet_ntoa(p
->prefix
),
2661 rip_event(RIP_TRIGGERED_UPDATE
, 0);
2666 /* Create new RIP instance and set it to global variable. */
2667 static int rip_create(void)
2669 rip
= XCALLOC(MTYPE_RIP
, sizeof(struct rip
));
2671 /* Set initial value. */
2672 rip
->version_send
= RI_RIP_VERSION_2
;
2673 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2674 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
2675 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
2676 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
2677 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2679 /* Initialize RIP routig table. */
2680 rip
->table
= route_table_init();
2681 rip
->route
= route_table_init();
2682 rip
->neighbor
= route_table_init();
2684 /* Make output stream. */
2685 rip
->obuf
= stream_new(1500);
2688 rip
->sock
= rip_create_socket();
2692 /* Create read and timer thread. */
2693 rip_event(RIP_READ
, rip
->sock
);
2694 rip_event(RIP_UPDATE_EVENT
, 1);
2701 /* Sned RIP request to the destination. */
2702 int rip_request_send(struct sockaddr_in
*to
, struct interface
*ifp
,
2703 uint8_t version
, struct connected
*connected
)
2706 struct rip_packet rip_packet
;
2707 struct listnode
*node
, *nnode
;
2709 memset(&rip_packet
, 0, sizeof(rip_packet
));
2711 rip_packet
.command
= RIP_REQUEST
;
2712 rip_packet
.version
= version
;
2713 rte
= rip_packet
.rte
;
2714 rte
->metric
= htonl(RIP_METRIC_INFINITY
);
2718 * connected is only sent for ripv1 case, or when
2719 * interface does not support multicast. Caller loops
2720 * over each connected address for this case.
2722 if (rip_send_packet((uint8_t *)&rip_packet
, sizeof(rip_packet
),
2724 != sizeof(rip_packet
))
2727 return sizeof(rip_packet
);
2730 /* send request on each connected network */
2731 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
2732 struct prefix_ipv4
*p
;
2734 p
= (struct prefix_ipv4
*)connected
->address
;
2736 if (p
->family
!= AF_INET
)
2739 if (rip_send_packet((uint8_t *)&rip_packet
, sizeof(rip_packet
),
2741 != sizeof(rip_packet
))
2744 return sizeof(rip_packet
);
2747 static int rip_update_jitter(unsigned long time
)
2749 #define JITTER_BOUND 4
2750 /* We want to get the jitter to +/- 1/JITTER_BOUND the interval.
2751 Given that, we cannot let time be less than JITTER_BOUND seconds.
2752 The RIPv2 RFC says jitter should be small compared to
2753 update_time. We consider 1/JITTER_BOUND to be small.
2756 int jitter_input
= time
;
2759 if (jitter_input
< JITTER_BOUND
)
2760 jitter_input
= JITTER_BOUND
;
2762 jitter
= (((random() % ((jitter_input
* 2) + 1)) - jitter_input
));
2764 return jitter
/ JITTER_BOUND
;
2767 void rip_event(enum rip_event event
, int sock
)
2774 thread_add_read(master
, rip_read
, NULL
, sock
, &rip
->t_read
);
2776 case RIP_UPDATE_EVENT
:
2777 RIP_TIMER_OFF(rip
->t_update
);
2778 jitter
= rip_update_jitter(rip
->update_time
);
2779 thread_add_timer(master
, rip_update
, NULL
,
2780 sock
? 2 : rip
->update_time
+ jitter
,
2783 case RIP_TRIGGERED_UPDATE
:
2784 if (rip
->t_triggered_interval
)
2787 thread_add_event(master
, rip_triggered_update
, NULL
, 0,
2788 &rip
->t_triggered_update
);
2795 DEFUN_NOSH (router_rip
,
2798 "Enable a routing process\n"
2799 "Routing Information Protocol (RIP)\n")
2803 /* If rip is not enabled before. */
2807 zlog_info("Can't create RIP");
2808 return CMD_WARNING_CONFIG_FAILED
;
2812 VTY_PUSH_CONTEXT(RIP_NODE
, rip
);
2817 DEFUN (no_router_rip
,
2821 "Enable a routing process\n"
2822 "Routing Information Protocol (RIP)\n")
2832 "Set routing protocol version\n"
2838 version
= atoi(argv
[idx_number
]->arg
);
2839 if (version
!= RIPv1
&& version
!= RIPv2
) {
2840 vty_out(vty
, "invalid rip version %d\n", version
);
2841 return CMD_WARNING_CONFIG_FAILED
;
2843 rip
->version_send
= version
;
2844 rip
->version_recv
= version
;
2849 DEFUN (no_rip_version
,
2851 "no version [(1-2)]",
2853 "Set routing protocol version\n"
2856 /* Set RIP version to the default. */
2857 rip
->version_send
= RI_RIP_VERSION_2
;
2858 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2867 "RIP static route configuration\n"
2868 "IP prefix <network>/<length>\n")
2870 int idx_ipv4_prefixlen
= 1;
2873 struct prefix_ipv4 p
;
2874 struct route_node
*node
;
2876 memset(&nh
, 0, sizeof(nh
));
2877 nh
.type
= NEXTHOP_TYPE_IPV4
;
2879 ret
= str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2881 vty_out(vty
, "Malformed address\n");
2882 return CMD_WARNING_CONFIG_FAILED
;
2884 apply_mask_ipv4(&p
);
2886 /* For router rip configuration. */
2887 node
= route_node_get(rip
->route
, (struct prefix
*)&p
);
2890 vty_out(vty
, "There is already same static route.\n");
2891 route_unlock_node(node
);
2895 node
->info
= (void *)1;
2897 rip_redistribute_add(ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, &nh
, 0, 0,
2903 DEFUN (no_rip_route
,
2905 "no route A.B.C.D/M",
2907 "RIP static route configuration\n"
2908 "IP prefix <network>/<length>\n")
2910 int idx_ipv4_prefixlen
= 2;
2912 struct prefix_ipv4 p
;
2913 struct route_node
*node
;
2915 ret
= str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2917 vty_out(vty
, "Malformed address\n");
2918 return CMD_WARNING_CONFIG_FAILED
;
2920 apply_mask_ipv4(&p
);
2922 /* For router rip configuration. */
2923 node
= route_node_lookup(rip
->route
, (struct prefix
*)&p
);
2925 vty_out(vty
, "Can't find route %s.\n",
2926 argv
[idx_ipv4_prefixlen
]->arg
);
2927 return CMD_WARNING_CONFIG_FAILED
;
2930 rip_redistribute_delete(ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0);
2931 route_unlock_node(node
);
2934 route_unlock_node(node
);
2941 rip_update_default_metric (void)
2943 struct route_node
*np
;
2944 struct rip_info
*rinfo
= NULL
;
2945 struct list
*list
= NULL
;
2946 struct listnode
*listnode
= NULL
;
2948 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
2949 if ((list
= np
->info
) != NULL
)
2950 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2951 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
&& rinfo
->type
!= ZEBRA_ROUTE_CONNECT
)
2952 rinfo
->metric
= rip
->default_metric
;
2956 DEFUN (rip_default_metric
,
2957 rip_default_metric_cmd
,
2958 "default-metric (1-16)",
2959 "Set a metric of redistribute routes\n"
2964 rip
->default_metric
= atoi(argv
[idx_number
]->arg
);
2965 /* rip_update_default_metric (); */
2970 DEFUN (no_rip_default_metric
,
2971 no_rip_default_metric_cmd
,
2972 "no default-metric [(1-16)]",
2974 "Set a metric of redistribute routes\n"
2978 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2979 /* rip_update_default_metric (); */
2987 "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
2988 "Adjust routing timers\n"
2989 "Basic routing protocol update timers\n"
2990 "Routing table update timer value in second. Default is 30.\n"
2991 "Routing information timeout timer. Default is 180.\n"
2992 "Garbage collection timer. Default is 120.\n")
2995 int idx_number_2
= 3;
2996 int idx_number_3
= 4;
2997 unsigned long update
;
2998 unsigned long timeout
;
2999 unsigned long garbage
;
3000 char *endptr
= NULL
;
3001 unsigned long RIP_TIMER_MAX
= 2147483647;
3002 unsigned long RIP_TIMER_MIN
= 5;
3004 update
= strtoul(argv
[idx_number
]->arg
, &endptr
, 10);
3005 if (update
> RIP_TIMER_MAX
|| update
< RIP_TIMER_MIN
3006 || *endptr
!= '\0') {
3007 vty_out(vty
, "update timer value error\n");
3008 return CMD_WARNING_CONFIG_FAILED
;
3011 timeout
= strtoul(argv
[idx_number_2
]->arg
, &endptr
, 10);
3012 if (timeout
> RIP_TIMER_MAX
|| timeout
< RIP_TIMER_MIN
3013 || *endptr
!= '\0') {
3014 vty_out(vty
, "timeout timer value error\n");
3015 return CMD_WARNING_CONFIG_FAILED
;
3018 garbage
= strtoul(argv
[idx_number_3
]->arg
, &endptr
, 10);
3019 if (garbage
> RIP_TIMER_MAX
|| garbage
< RIP_TIMER_MIN
3020 || *endptr
!= '\0') {
3021 vty_out(vty
, "garbage timer value error\n");
3022 return CMD_WARNING_CONFIG_FAILED
;
3025 /* Set each timer value. */
3026 rip
->update_time
= update
;
3027 rip
->timeout_time
= timeout
;
3028 rip
->garbage_time
= garbage
;
3030 /* Reset update timer thread. */
3031 rip_event(RIP_UPDATE_EVENT
, 0);
3036 DEFUN (no_rip_timers
,
3038 "no timers basic [(0-65535) (0-65535) (0-65535)]",
3040 "Adjust routing timers\n"
3041 "Basic routing protocol update timers\n"
3042 "Routing table update timer value in second. Default is 30.\n"
3043 "Routing information timeout timer. Default is 180.\n"
3044 "Garbage collection timer. Default is 120.\n")
3046 /* Set each timer value to the default. */
3047 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
3048 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
3049 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
3051 /* Reset update timer thread. */
3052 rip_event(RIP_UPDATE_EVENT
, 0);
3058 struct route_table
*rip_distance_table
;
3060 struct rip_distance
{
3061 /* Distance value for the IP source prefix. */
3064 /* Name of the access-list to be matched. */
3068 static struct rip_distance
*rip_distance_new(void)
3070 return XCALLOC(MTYPE_RIP_DISTANCE
, sizeof(struct rip_distance
));
3073 static void rip_distance_free(struct rip_distance
*rdistance
)
3075 XFREE(MTYPE_RIP_DISTANCE
, rdistance
);
3078 static int rip_distance_set(struct vty
*vty
, const char *distance_str
,
3079 const char *ip_str
, const char *access_list_str
)
3082 struct prefix_ipv4 p
;
3084 struct route_node
*rn
;
3085 struct rip_distance
*rdistance
;
3087 ret
= str2prefix_ipv4(ip_str
, &p
);
3089 vty_out(vty
, "Malformed prefix\n");
3090 return CMD_WARNING_CONFIG_FAILED
;
3093 distance
= atoi(distance_str
);
3095 /* Get RIP distance node. */
3096 rn
= route_node_get(rip_distance_table
, (struct prefix
*)&p
);
3098 rdistance
= rn
->info
;
3099 route_unlock_node(rn
);
3101 rdistance
= rip_distance_new();
3102 rn
->info
= rdistance
;
3105 /* Set distance value. */
3106 rdistance
->distance
= distance
;
3108 /* Reset access-list configuration. */
3109 if (rdistance
->access_list
) {
3110 free(rdistance
->access_list
);
3111 rdistance
->access_list
= NULL
;
3113 if (access_list_str
)
3114 rdistance
->access_list
= strdup(access_list_str
);
3119 static int rip_distance_unset(struct vty
*vty
, const char *distance_str
,
3120 const char *ip_str
, const char *access_list_str
)
3123 struct prefix_ipv4 p
;
3124 struct route_node
*rn
;
3125 struct rip_distance
*rdistance
;
3127 ret
= str2prefix_ipv4(ip_str
, &p
);
3129 vty_out(vty
, "Malformed prefix\n");
3130 return CMD_WARNING_CONFIG_FAILED
;
3133 rn
= route_node_lookup(rip_distance_table
, (struct prefix
*)&p
);
3135 vty_out(vty
, "Can't find specified prefix\n");
3136 return CMD_WARNING_CONFIG_FAILED
;
3139 rdistance
= rn
->info
;
3141 if (rdistance
->access_list
)
3142 free(rdistance
->access_list
);
3143 rip_distance_free(rdistance
);
3146 route_unlock_node(rn
);
3147 route_unlock_node(rn
);
3152 static void rip_distance_reset(void)
3154 struct route_node
*rn
;
3155 struct rip_distance
*rdistance
;
3157 for (rn
= route_top(rip_distance_table
); rn
; rn
= route_next(rn
))
3158 if ((rdistance
= rn
->info
) != NULL
) {
3159 if (rdistance
->access_list
)
3160 free(rdistance
->access_list
);
3161 rip_distance_free(rdistance
);
3163 route_unlock_node(rn
);
3167 /* Apply RIP information to distance method. */
3168 uint8_t rip_distance_apply(struct rip_info
*rinfo
)
3170 struct route_node
*rn
;
3171 struct prefix_ipv4 p
;
3172 struct rip_distance
*rdistance
;
3173 struct access_list
*alist
;
3178 memset(&p
, 0, sizeof(struct prefix_ipv4
));
3180 p
.prefix
= rinfo
->from
;
3181 p
.prefixlen
= IPV4_MAX_BITLEN
;
3183 /* Check source address. */
3184 rn
= route_node_match(rip_distance_table
, (struct prefix
*)&p
);
3186 rdistance
= rn
->info
;
3187 route_unlock_node(rn
);
3189 if (rdistance
->access_list
) {
3190 alist
= access_list_lookup(AFI_IP
,
3191 rdistance
->access_list
);
3194 if (access_list_apply(alist
, &rinfo
->rp
->p
)
3198 return rdistance
->distance
;
3200 return rdistance
->distance
;
3204 return rip
->distance
;
3209 static void rip_distance_show(struct vty
*vty
)
3211 struct route_node
*rn
;
3212 struct rip_distance
*rdistance
;
3216 vty_out(vty
, " Distance: (default is %d)\n",
3217 rip
->distance
? rip
->distance
: ZEBRA_RIP_DISTANCE_DEFAULT
);
3219 for (rn
= route_top(rip_distance_table
); rn
; rn
= route_next(rn
))
3220 if ((rdistance
= rn
->info
) != NULL
) {
3223 " Address Distance List\n");
3226 sprintf(buf
, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
3228 vty_out(vty
, " %-20s %4d %s\n", buf
,
3229 rdistance
->distance
,
3230 rdistance
->access_list
? rdistance
->access_list
3235 DEFUN (rip_distance
,
3238 "Administrative distance\n"
3242 rip
->distance
= atoi(argv
[idx_number
]->arg
);
3246 DEFUN (no_rip_distance
,
3247 no_rip_distance_cmd
,
3248 "no distance (1-255)",
3250 "Administrative distance\n"
3257 DEFUN (rip_distance_source
,
3258 rip_distance_source_cmd
,
3259 "distance (1-255) A.B.C.D/M",
3260 "Administrative distance\n"
3262 "IP source prefix\n")
3265 int idx_ipv4_prefixlen
= 2;
3266 rip_distance_set(vty
, argv
[idx_number
]->arg
,
3267 argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3271 DEFUN (no_rip_distance_source
,
3272 no_rip_distance_source_cmd
,
3273 "no distance (1-255) A.B.C.D/M",
3275 "Administrative distance\n"
3277 "IP source prefix\n")
3280 int idx_ipv4_prefixlen
= 3;
3281 rip_distance_unset(vty
, argv
[idx_number
]->arg
,
3282 argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3286 DEFUN (rip_distance_source_access_list
,
3287 rip_distance_source_access_list_cmd
,
3288 "distance (1-255) A.B.C.D/M WORD",
3289 "Administrative distance\n"
3291 "IP source prefix\n"
3292 "Access list name\n")
3295 int idx_ipv4_prefixlen
= 2;
3297 rip_distance_set(vty
, argv
[idx_number
]->arg
,
3298 argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3302 DEFUN (no_rip_distance_source_access_list
,
3303 no_rip_distance_source_access_list_cmd
,
3304 "no distance (1-255) A.B.C.D/M WORD",
3306 "Administrative distance\n"
3308 "IP source prefix\n"
3309 "Access list name\n")
3312 int idx_ipv4_prefixlen
= 3;
3314 rip_distance_unset(vty
, argv
[idx_number
]->arg
,
3315 argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3319 /* Update ECMP routes to zebra when ECMP is disabled. */
3320 static void rip_ecmp_disable(void)
3322 struct route_node
*rp
;
3323 struct rip_info
*rinfo
, *tmp_rinfo
;
3325 struct listnode
*node
, *nextnode
;
3330 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
3331 if ((list
= rp
->info
) != NULL
&& listcount(list
) > 1) {
3332 rinfo
= listgetdata(listhead(list
));
3333 if (!rip_route_rte(rinfo
))
3336 /* Drop all other entries, except the first one. */
3337 for (ALL_LIST_ELEMENTS(list
, node
, nextnode
, tmp_rinfo
))
3338 if (tmp_rinfo
!= rinfo
) {
3339 RIP_TIMER_OFF(tmp_rinfo
->t_timeout
);
3341 tmp_rinfo
->t_garbage_collect
);
3342 list_delete_node(list
, node
);
3343 rip_info_free(tmp_rinfo
);
3347 rip_zebra_ipv4_add(rp
);
3349 /* Set the route change flag. */
3350 SET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
3352 /* Signal the output process to trigger an update. */
3353 rip_event(RIP_TRIGGERED_UPDATE
, 0);
3357 DEFUN (rip_allow_ecmp
,
3360 "Allow Equal Cost MultiPath\n")
3363 vty_out(vty
, "ECMP is already enabled.\n");
3368 zlog_info("ECMP is enabled.");
3372 DEFUN (no_rip_allow_ecmp
,
3373 no_rip_allow_ecmp_cmd
,
3376 "Allow Equal Cost MultiPath\n")
3379 vty_out(vty
, "ECMP is already disabled.\n");
3384 zlog_info("ECMP is disabled.");
3389 /* Print out routes update time. */
3390 static void rip_vty_out_uptime(struct vty
*vty
, struct rip_info
*rinfo
)
3395 char timebuf
[TIME_BUF
];
3396 struct thread
*thread
;
3398 if ((thread
= rinfo
->t_timeout
) != NULL
) {
3399 clock
= thread_timer_remain_second(thread
);
3400 tm
= gmtime(&clock
);
3401 strftime(timebuf
, TIME_BUF
, "%M:%S", tm
);
3402 vty_out(vty
, "%5s", timebuf
);
3403 } else if ((thread
= rinfo
->t_garbage_collect
) != NULL
) {
3404 clock
= thread_timer_remain_second(thread
);
3405 tm
= gmtime(&clock
);
3406 strftime(timebuf
, TIME_BUF
, "%M:%S", tm
);
3407 vty_out(vty
, "%5s", timebuf
);
3411 static const char *rip_route_type_print(int sub_type
)
3416 case RIP_ROUTE_STATIC
:
3418 case RIP_ROUTE_DEFAULT
:
3420 case RIP_ROUTE_REDISTRIBUTE
:
3422 case RIP_ROUTE_INTERFACE
:
3434 "Show RIP routes\n")
3436 struct route_node
*np
;
3437 struct rip_info
*rinfo
= NULL
;
3438 struct list
*list
= NULL
;
3439 struct listnode
*listnode
= NULL
;
3445 "Codes: R - RIP, C - connected, S - Static, O - OSPF, B - BGP\n"
3447 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,\n"
3448 " (i) - interface\n\n"
3449 " Network Next Hop Metric From Tag Time\n");
3451 for (np
= route_top(rip
->table
); np
; np
= route_next(np
))
3452 if ((list
= np
->info
) != NULL
)
3453 for (ALL_LIST_ELEMENTS_RO(list
, listnode
, rinfo
)) {
3457 vty
, "%c(%s) %s/%d",
3458 /* np->lock, For debugging. */
3459 zebra_route_char(rinfo
->type
),
3460 rip_route_type_print(rinfo
->sub_type
),
3461 inet_ntoa(np
->p
.u
.prefix4
),
3467 vty_out(vty
, "%*s", len
, " ");
3469 switch (rinfo
->nh
.type
) {
3470 case NEXTHOP_TYPE_IPV4
:
3471 case NEXTHOP_TYPE_IPV4_IFINDEX
:
3472 vty_out(vty
, "%-20s %2d ",
3473 inet_ntoa(rinfo
->nh
.gate
.ipv4
),
3476 case NEXTHOP_TYPE_IFINDEX
:
3481 case NEXTHOP_TYPE_BLACKHOLE
:
3486 case NEXTHOP_TYPE_IPV6
:
3487 case NEXTHOP_TYPE_IPV6_IFINDEX
:
3489 "V6 Address Hidden %2d ",
3494 /* Route which exist in kernel routing table. */
3495 if ((rinfo
->type
== ZEBRA_ROUTE_RIP
)
3496 && (rinfo
->sub_type
== RIP_ROUTE_RTE
)) {
3497 vty_out(vty
, "%-15s ",
3498 inet_ntoa(rinfo
->from
));
3499 vty_out(vty
, "%3" ROUTE_TAG_PRI
" ",
3500 (route_tag_t
)rinfo
->tag
);
3501 rip_vty_out_uptime(vty
, rinfo
);
3502 } else if (rinfo
->metric
3503 == RIP_METRIC_INFINITY
) {
3504 vty_out(vty
, "self ");
3505 vty_out(vty
, "%3" ROUTE_TAG_PRI
" ",
3506 (route_tag_t
)rinfo
->tag
);
3507 rip_vty_out_uptime(vty
, rinfo
);
3509 if (rinfo
->external_metric
) {
3511 vty
, "self (%s:%d)",
3514 rinfo
->external_metric
);
3517 vty_out(vty
, "%*s", len
,
3522 vty_out(vty
, "%3" ROUTE_TAG_PRI
,
3523 (route_tag_t
)rinfo
->tag
);
3531 /* Vincent: formerly, it was show_ip_protocols_rip: "show ip protocols" */
3532 DEFUN (show_ip_rip_status
,
3533 show_ip_rip_status_cmd
,
3534 "show ip rip status",
3538 "IP routing protocol process parameters and statistics\n")
3540 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
3541 struct interface
*ifp
;
3542 struct rip_interface
*ri
;
3543 extern const struct message ri_version_msg
[];
3544 const char *send_version
;
3545 const char *receive_version
;
3550 vty_out(vty
, "Routing Protocol is \"rip\"\n");
3551 vty_out(vty
, " Sending updates every %ld seconds with +/-50%%,",
3553 vty_out(vty
, " next due in %lu seconds\n",
3554 thread_timer_remain_second(rip
->t_update
));
3555 vty_out(vty
, " Timeout after %ld seconds,", rip
->timeout_time
);
3556 vty_out(vty
, " garbage collect after %ld seconds\n", rip
->garbage_time
);
3558 /* Filtering status show. */
3559 config_show_distribute(vty
);
3561 /* Default metric information. */
3562 vty_out(vty
, " Default redistribution metric is %d\n",
3563 rip
->default_metric
);
3565 /* Redistribute information. */
3566 vty_out(vty
, " Redistributing:");
3567 config_write_rip_redistribute(vty
, 0);
3570 vty_out(vty
, " Default version control: send version %s,",
3571 lookup_msg(ri_version_msg
, rip
->version_send
, NULL
));
3572 if (rip
->version_recv
== RI_RIP_VERSION_1_AND_2
)
3573 vty_out(vty
, " receive any version \n");
3575 vty_out(vty
, " receive version %s \n",
3576 lookup_msg(ri_version_msg
, rip
->version_recv
, NULL
));
3578 vty_out(vty
, " Interface Send Recv Key-chain\n");
3580 FOR_ALL_INTERFACES (vrf
, ifp
) {
3586 if (ri
->enable_network
|| ri
->enable_interface
) {
3587 if (ri
->ri_send
== RI_RIP_UNSPEC
)
3589 lookup_msg(ri_version_msg
,
3590 rip
->version_send
, NULL
);
3592 send_version
= lookup_msg(ri_version_msg
,
3595 if (ri
->ri_receive
== RI_RIP_UNSPEC
)
3597 lookup_msg(ri_version_msg
,
3598 rip
->version_recv
, NULL
);
3600 receive_version
= lookup_msg(
3601 ri_version_msg
, ri
->ri_receive
, NULL
);
3603 vty_out(vty
, " %-17s%-3s %-3s %s\n", ifp
->name
,
3604 send_version
, receive_version
,
3605 ri
->key_chain
? ri
->key_chain
: "");
3609 vty_out(vty
, " Routing for Networks:\n");
3610 config_write_rip_network(vty
, 0);
3613 int found_passive
= 0;
3614 FOR_ALL_INTERFACES (vrf
, ifp
) {
3617 if ((ri
->enable_network
|| ri
->enable_interface
)
3619 if (!found_passive
) {
3621 " Passive Interface(s):\n");
3624 vty_out(vty
, " %s\n", ifp
->name
);
3629 vty_out(vty
, " Routing Information Sources:\n");
3631 " Gateway BadPackets BadRoutes Distance Last Update\n");
3632 rip_peer_display(vty
);
3634 rip_distance_show(vty
);
3639 /* RIP configuration write function. */
3640 static int config_write_rip(struct vty
*vty
)
3643 struct route_node
*rn
;
3644 struct rip_distance
*rdistance
;
3647 /* Router RIP statement. */
3648 vty_out(vty
, "router rip\n");
3651 /* RIP version statement. Default is RIP version 2. */
3652 if (rip
->version_send
!= RI_RIP_VERSION_2
3653 || rip
->version_recv
!= RI_RIP_VERSION_1_AND_2
)
3654 vty_out(vty
, " version %d\n", rip
->version_send
);
3656 /* RIP timer configuration. */
3657 if (rip
->update_time
!= RIP_UPDATE_TIMER_DEFAULT
3658 || rip
->timeout_time
!= RIP_TIMEOUT_TIMER_DEFAULT
3659 || rip
->garbage_time
!= RIP_GARBAGE_TIMER_DEFAULT
)
3660 vty_out(vty
, " timers basic %lu %lu %lu\n",
3661 rip
->update_time
, rip
->timeout_time
,
3664 /* Default information configuration. */
3665 if (rip
->default_information
) {
3666 if (rip
->default_information_route_map
)
3668 " default-information originate route-map %s\n",
3669 rip
->default_information_route_map
);
3672 " default-information originate\n");
3675 /* Redistribute configuration. */
3676 config_write_rip_redistribute(vty
, 1);
3678 /* RIP offset-list configuration. */
3679 config_write_rip_offset_list(vty
);
3681 /* RIP enabled network and interface configuration. */
3682 config_write_rip_network(vty
, 1);
3684 /* RIP default metric configuration */
3685 if (rip
->default_metric
!= RIP_DEFAULT_METRIC_DEFAULT
)
3686 vty_out(vty
, " default-metric %d\n",
3687 rip
->default_metric
);
3689 /* Distribute configuration. */
3690 write
+= config_write_distribute(vty
);
3692 /* Interface routemap configuration */
3693 write
+= config_write_if_rmap(vty
);
3695 /* Distance configuration. */
3697 vty_out(vty
, " distance %d\n", rip
->distance
);
3699 /* RIP source IP prefix distance configuration. */
3700 for (rn
= route_top(rip_distance_table
); rn
;
3701 rn
= route_next(rn
))
3702 if ((rdistance
= rn
->info
) != NULL
)
3703 vty_out(vty
, " distance %d %s/%d %s\n",
3704 rdistance
->distance
,
3705 inet_ntoa(rn
->p
.u
.prefix4
),
3707 rdistance
->access_list
3708 ? rdistance
->access_list
3711 /* ECMP configuration. */
3713 vty_out(vty
, " allow-ecmp\n");
3715 /* RIP static route configuration. */
3716 for (rn
= route_top(rip
->route
); rn
; rn
= route_next(rn
))
3718 vty_out(vty
, " route %s/%d\n",
3719 inet_ntoa(rn
->p
.u
.prefix4
),
3725 /* RIP node structure. */
3726 static struct cmd_node rip_node
= {RIP_NODE
, "%s(config-router)# ", 1};
3728 /* Distribute-list update functions. */
3729 static void rip_distribute_update(struct distribute
*dist
)
3731 struct interface
*ifp
;
3732 struct rip_interface
*ri
;
3733 struct access_list
*alist
;
3734 struct prefix_list
*plist
;
3739 ifp
= if_lookup_by_name(dist
->ifname
, VRF_DEFAULT
);
3745 if (dist
->list
[DISTRIBUTE_V4_IN
]) {
3746 alist
= access_list_lookup(AFI_IP
,
3747 dist
->list
[DISTRIBUTE_V4_IN
]);
3749 ri
->list
[RIP_FILTER_IN
] = alist
;
3751 ri
->list
[RIP_FILTER_IN
] = NULL
;
3753 ri
->list
[RIP_FILTER_IN
] = NULL
;
3755 if (dist
->list
[DISTRIBUTE_V4_OUT
]) {
3756 alist
= access_list_lookup(AFI_IP
,
3757 dist
->list
[DISTRIBUTE_V4_OUT
]);
3759 ri
->list
[RIP_FILTER_OUT
] = alist
;
3761 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3763 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3765 if (dist
->prefix
[DISTRIBUTE_V4_IN
]) {
3766 plist
= prefix_list_lookup(AFI_IP
,
3767 dist
->prefix
[DISTRIBUTE_V4_IN
]);
3769 ri
->prefix
[RIP_FILTER_IN
] = plist
;
3771 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3773 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3775 if (dist
->prefix
[DISTRIBUTE_V4_OUT
]) {
3776 plist
= prefix_list_lookup(AFI_IP
,
3777 dist
->prefix
[DISTRIBUTE_V4_OUT
]);
3779 ri
->prefix
[RIP_FILTER_OUT
] = plist
;
3781 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3783 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3786 void rip_distribute_update_interface(struct interface
*ifp
)
3788 struct distribute
*dist
;
3790 dist
= distribute_lookup(ifp
->name
);
3792 rip_distribute_update(dist
);
3795 /* Update all interface's distribute list. */
3797 static void rip_distribute_update_all(struct prefix_list
*notused
)
3799 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
3800 struct interface
*ifp
;
3802 FOR_ALL_INTERFACES (vrf
, ifp
)
3803 rip_distribute_update_interface(ifp
);
3806 static void rip_distribute_update_all_wrapper(struct access_list
*notused
)
3808 rip_distribute_update_all(NULL
);
3811 /* Delete all added rip route. */
3812 void rip_clean(void)
3815 struct route_node
*rp
;
3816 struct rip_info
*rinfo
= NULL
;
3817 struct list
*list
= NULL
;
3818 struct listnode
*listnode
= NULL
;
3823 /* Clear RIP routes */
3824 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
3825 if ((list
= rp
->info
) != NULL
) {
3826 rinfo
= listgetdata(listhead(list
));
3827 if (rip_route_rte(rinfo
))
3828 rip_zebra_ipv4_delete(rp
);
3830 for (ALL_LIST_ELEMENTS_RO(list
, listnode
,
3832 RIP_TIMER_OFF(rinfo
->t_timeout
);
3833 RIP_TIMER_OFF(rinfo
->t_garbage_collect
);
3834 rip_info_free(rinfo
);
3836 list_delete_and_null(&list
);
3838 route_unlock_node(rp
);
3841 /* Cancel RIP related timers. */
3842 RIP_TIMER_OFF(rip
->t_update
);
3843 RIP_TIMER_OFF(rip
->t_triggered_update
);
3844 RIP_TIMER_OFF(rip
->t_triggered_interval
);
3846 /* Cancel read thread. */
3847 THREAD_READ_OFF(rip
->t_read
);
3849 /* Close RIP socket. */
3850 if (rip
->sock
>= 0) {
3855 stream_free(rip
->obuf
);
3856 /* Static RIP route configuration. */
3857 for (rp
= route_top(rip
->route
); rp
; rp
= route_next(rp
))
3860 route_unlock_node(rp
);
3863 /* RIP neighbor configuration. */
3864 for (rp
= route_top(rip
->neighbor
); rp
; rp
= route_next(rp
))
3867 route_unlock_node(rp
);
3870 /* Redistribute related clear. */
3871 if (rip
->default_information_route_map
)
3872 free(rip
->default_information_route_map
);
3874 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
3875 if (rip
->route_map
[i
].name
)
3876 free(rip
->route_map
[i
].name
);
3878 XFREE(MTYPE_ROUTE_TABLE
, rip
->table
);
3879 XFREE(MTYPE_ROUTE_TABLE
, rip
->route
);
3880 XFREE(MTYPE_ROUTE_TABLE
, rip
->neighbor
);
3882 XFREE(MTYPE_RIP
, rip
);
3886 rip_clean_network();
3887 rip_passive_nondefault_clean();
3889 rip_interfaces_clean();
3890 rip_distance_reset();
3891 rip_redistribute_clean();
3894 /* Reset all values to the default settings. */
3895 void rip_reset(void)
3897 /* Reset global counters. */
3898 rip_global_route_changes
= 0;
3899 rip_global_queries
= 0;
3901 /* Call ripd related reset functions. */
3903 rip_route_map_reset();
3905 /* Call library reset functions. */
3907 access_list_reset();
3908 prefix_list_reset();
3910 distribute_list_reset();
3912 rip_interfaces_reset();
3913 rip_distance_reset();
3915 rip_zclient_reset();
3918 static void rip_if_rmap_update(struct if_rmap
*if_rmap
)
3920 struct interface
*ifp
;
3921 struct rip_interface
*ri
;
3922 struct route_map
*rmap
;
3924 ifp
= if_lookup_by_name(if_rmap
->ifname
, VRF_DEFAULT
);
3930 if (if_rmap
->routemap
[IF_RMAP_IN
]) {
3931 rmap
= route_map_lookup_by_name(if_rmap
->routemap
[IF_RMAP_IN
]);
3933 ri
->routemap
[IF_RMAP_IN
] = rmap
;
3935 ri
->routemap
[IF_RMAP_IN
] = NULL
;
3937 ri
->routemap
[RIP_FILTER_IN
] = NULL
;
3939 if (if_rmap
->routemap
[IF_RMAP_OUT
]) {
3940 rmap
= route_map_lookup_by_name(if_rmap
->routemap
[IF_RMAP_OUT
]);
3942 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
3944 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
3946 ri
->routemap
[RIP_FILTER_OUT
] = NULL
;
3949 void rip_if_rmap_update_interface(struct interface
*ifp
)
3951 struct if_rmap
*if_rmap
;
3953 if_rmap
= if_rmap_lookup(ifp
->name
);
3955 rip_if_rmap_update(if_rmap
);
3958 static void rip_routemap_update_redistribute(void)
3963 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3964 if (rip
->route_map
[i
].name
)
3965 rip
->route_map
[i
].map
=
3966 route_map_lookup_by_name(
3967 rip
->route_map
[i
].name
);
3973 static void rip_routemap_update(const char *notused
)
3975 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
3976 struct interface
*ifp
;
3978 FOR_ALL_INTERFACES (vrf
, ifp
)
3979 rip_if_rmap_update_interface(ifp
);
3981 rip_routemap_update_redistribute();
3984 /* Allocate new rip structure and set default value. */
3987 /* Install top nodes. */
3988 install_node(&rip_node
, config_write_rip
);
3990 /* Install rip commands. */
3991 install_element(VIEW_NODE
, &show_ip_rip_cmd
);
3992 install_element(VIEW_NODE
, &show_ip_rip_status_cmd
);
3993 install_element(CONFIG_NODE
, &router_rip_cmd
);
3994 install_element(CONFIG_NODE
, &no_router_rip_cmd
);
3996 install_default(RIP_NODE
);
3997 install_element(RIP_NODE
, &rip_version_cmd
);
3998 install_element(RIP_NODE
, &no_rip_version_cmd
);
3999 install_element(RIP_NODE
, &rip_default_metric_cmd
);
4000 install_element(RIP_NODE
, &no_rip_default_metric_cmd
);
4001 install_element(RIP_NODE
, &rip_timers_cmd
);
4002 install_element(RIP_NODE
, &no_rip_timers_cmd
);
4003 install_element(RIP_NODE
, &rip_route_cmd
);
4004 install_element(RIP_NODE
, &no_rip_route_cmd
);
4005 install_element(RIP_NODE
, &rip_distance_cmd
);
4006 install_element(RIP_NODE
, &no_rip_distance_cmd
);
4007 install_element(RIP_NODE
, &rip_distance_source_cmd
);
4008 install_element(RIP_NODE
, &no_rip_distance_source_cmd
);
4009 install_element(RIP_NODE
, &rip_distance_source_access_list_cmd
);
4010 install_element(RIP_NODE
, &no_rip_distance_source_access_list_cmd
);
4011 install_element(RIP_NODE
, &rip_allow_ecmp_cmd
);
4012 install_element(RIP_NODE
, &no_rip_allow_ecmp_cmd
);
4014 /* Debug related init. */
4017 /* Access list install. */
4019 access_list_add_hook(rip_distribute_update_all_wrapper
);
4020 access_list_delete_hook(rip_distribute_update_all_wrapper
);
4022 /* Prefix list initialize.*/
4024 prefix_list_add_hook(rip_distribute_update_all
);
4025 prefix_list_delete_hook(rip_distribute_update_all
);
4027 /* Distribute list install. */
4028 distribute_list_init(RIP_NODE
);
4029 distribute_list_add_hook(rip_distribute_update
);
4030 distribute_list_delete_hook(rip_distribute_update
);
4033 rip_route_map_init();
4036 route_map_add_hook(rip_routemap_update
);
4037 route_map_delete_hook(rip_routemap_update
);
4039 if_rmap_init(RIP_NODE
);
4040 if_rmap_hook_add(rip_if_rmap_update
);
4041 if_rmap_hook_delete(rip_if_rmap_update
);
4043 /* Distance control. */
4044 rip_distance_table
= route_table_init();