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(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 if (ripd_privs
.change(ZPRIVS_RAISE
))
1361 flog_err(LIB_ERR_PRIVILEGES
,
1362 "rip_create_socket: could not raise privs");
1363 setsockopt_so_recvbuf(sock
, RIP_UDP_RCV_BUF
);
1364 if ((ret
= bind(sock
, (struct sockaddr
*)&addr
, sizeof(addr
))) < 0)
1367 int save_errno
= errno
;
1368 if (ripd_privs
.change(ZPRIVS_LOWER
))
1369 flog_err(LIB_ERR_PRIVILEGES
,
1370 "rip_create_socket: could not lower privs");
1372 flog_err(LIB_ERR_SOCKET
,
1373 "%s: Can't bind socket %d to %s port %d: %s",
1374 __func__
, sock
, inet_ntoa(addr
.sin_addr
),
1375 (int)ntohs(addr
.sin_port
), safe_strerror(save_errno
));
1381 if (ripd_privs
.change(ZPRIVS_LOWER
))
1382 flog_err(LIB_ERR_PRIVILEGES
,
1383 "rip_create_socket: could not lower privs");
1388 /* RIP packet send to destination address, on interface denoted by
1389 * by connected argument. NULL to argument denotes destination should be
1390 * should be RIP multicast group
1392 static int rip_send_packet(uint8_t *buf
, int size
, struct sockaddr_in
*to
,
1393 struct connected
*ifc
)
1396 struct sockaddr_in sin
;
1398 assert(ifc
!= NULL
);
1400 if (IS_RIP_DEBUG_PACKET
) {
1401 #define ADDRESS_SIZE 20
1402 char dst
[ADDRESS_SIZE
];
1403 dst
[ADDRESS_SIZE
- 1] = '\0';
1406 strncpy(dst
, inet_ntoa(to
->sin_addr
), ADDRESS_SIZE
- 1);
1408 sin
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
1409 strncpy(dst
, inet_ntoa(sin
.sin_addr
), ADDRESS_SIZE
- 1);
1412 zlog_debug("rip_send_packet %s > %s (%s)",
1413 inet_ntoa(ifc
->address
->u
.prefix4
), dst
,
1417 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
1419 * ZEBRA_IFA_SECONDARY is set on linux when an interface is
1421 * with multiple addresses on the same subnet: the first address
1422 * on the subnet is configured "primary", and all subsequent
1424 * on that subnet are treated as "secondary" addresses.
1425 * In order to avoid routing-table bloat on other rip listeners,
1426 * we do not send out RIP packets with ZEBRA_IFA_SECONDARY
1428 * XXX Since Linux is the only system for which the
1429 * ZEBRA_IFA_SECONDARY
1430 * flag is set, we would end up sending a packet for a
1432 * source address on non-linux systems.
1434 if (IS_RIP_DEBUG_PACKET
)
1435 zlog_debug("duplicate dropped");
1439 /* Make destination address. */
1440 memset(&sin
, 0, sizeof(struct sockaddr_in
));
1441 sin
.sin_family
= AF_INET
;
1442 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1443 sin
.sin_len
= sizeof(struct sockaddr_in
);
1444 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1446 /* When destination is specified, use it's port and address. */
1448 sin
.sin_port
= to
->sin_port
;
1449 sin
.sin_addr
= to
->sin_addr
;
1451 sin
.sin_port
= htons(RIP_PORT_DEFAULT
);
1452 sin
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
1454 rip_interface_multicast_set(rip
->sock
, ifc
);
1457 ret
= sendto(rip
->sock
, buf
, size
, 0, (struct sockaddr
*)&sin
,
1458 sizeof(struct sockaddr_in
));
1460 if (IS_RIP_DEBUG_EVENT
)
1461 zlog_debug("SEND to %s.%d", inet_ntoa(sin
.sin_addr
),
1462 ntohs(sin
.sin_port
));
1465 zlog_warn("can't send packet : %s", safe_strerror(errno
));
1470 /* Add redistributed route to RIP table. */
1471 void rip_redistribute_add(int type
, int sub_type
, struct prefix_ipv4
*p
,
1472 struct nexthop
*nh
, unsigned int metric
,
1473 unsigned char distance
, route_tag_t tag
)
1476 struct route_node
*rp
= NULL
;
1477 struct rip_info
*rinfo
= NULL
, newinfo
;
1478 struct list
*list
= NULL
;
1480 /* Redistribute route */
1481 ret
= rip_destination_check(p
->prefix
);
1485 rp
= route_node_get(rip
->table
, (struct prefix
*)p
);
1487 memset(&newinfo
, 0, sizeof(struct rip_info
));
1488 newinfo
.type
= type
;
1489 newinfo
.sub_type
= sub_type
;
1491 newinfo
.external_metric
= metric
;
1492 newinfo
.distance
= distance
;
1493 if (tag
<= UINT16_MAX
) /* RIP only supports 16 bit tags */
1498 if ((list
= rp
->info
) != NULL
&& listcount(list
) != 0) {
1499 rinfo
= listgetdata(listhead(list
));
1501 if (rinfo
->type
== ZEBRA_ROUTE_CONNECT
1502 && rinfo
->sub_type
== RIP_ROUTE_INTERFACE
1503 && rinfo
->metric
!= RIP_METRIC_INFINITY
) {
1504 route_unlock_node(rp
);
1508 /* Manually configured RIP route check. */
1509 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1510 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
)
1511 || (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
))) {
1512 if (type
!= ZEBRA_ROUTE_RIP
1513 || ((sub_type
!= RIP_ROUTE_STATIC
)
1514 && (sub_type
!= RIP_ROUTE_DEFAULT
))) {
1515 route_unlock_node(rp
);
1520 (void)rip_ecmp_replace(&newinfo
);
1521 route_unlock_node(rp
);
1523 (void)rip_ecmp_add(&newinfo
);
1525 if (IS_RIP_DEBUG_EVENT
) {
1526 zlog_debug("Redistribute new prefix %s/%d",
1527 inet_ntoa(p
->prefix
), p
->prefixlen
);
1530 rip_event(RIP_TRIGGERED_UPDATE
, 0);
1533 /* Delete redistributed route from RIP table. */
1534 void rip_redistribute_delete(int type
, int sub_type
, struct prefix_ipv4
*p
,
1538 struct route_node
*rp
;
1539 struct rip_info
*rinfo
;
1541 ret
= rip_destination_check(p
->prefix
);
1545 rp
= route_node_lookup(rip
->table
, (struct prefix
*)p
);
1547 struct list
*list
= rp
->info
;
1549 if (list
!= NULL
&& listcount(list
) != 0) {
1550 rinfo
= listgetdata(listhead(list
));
1551 if (rinfo
!= NULL
&& rinfo
->type
== type
1552 && rinfo
->sub_type
== sub_type
1553 && rinfo
->nh
.ifindex
== ifindex
) {
1554 /* Perform poisoned reverse. */
1555 rinfo
->metric
= RIP_METRIC_INFINITY
;
1556 RIP_TIMER_ON(rinfo
->t_garbage_collect
,
1557 rip_garbage_collect
,
1559 RIP_TIMER_OFF(rinfo
->t_timeout
);
1560 rinfo
->flags
|= RIP_RTF_CHANGED
;
1562 if (IS_RIP_DEBUG_EVENT
)
1564 "Poison %s/%d on the interface %s with an "
1565 "infinity metric [delete]",
1566 inet_ntoa(p
->prefix
),
1568 ifindex2ifname(ifindex
,
1571 rip_event(RIP_TRIGGERED_UPDATE
, 0);
1574 route_unlock_node(rp
);
1578 /* Response to request called from rip_read ().*/
1579 static void rip_request_process(struct rip_packet
*packet
, int size
,
1580 struct sockaddr_in
*from
, struct connected
*ifc
)
1584 struct prefix_ipv4 p
;
1585 struct route_node
*rp
;
1586 struct rip_info
*rinfo
;
1587 struct rip_interface
*ri
;
1589 /* Does not reponse to the requests on the loopback interfaces */
1590 if (if_is_loopback(ifc
->ifp
))
1593 /* Check RIP process is enabled on this interface. */
1594 ri
= ifc
->ifp
->info
;
1598 /* When passive interface is specified, suppress responses */
1602 /* RIP peer update. */
1603 rip_peer_update(from
, packet
->version
);
1605 lim
= ((caddr_t
)packet
) + size
;
1608 /* The Request is processed entry by entry. If there are no
1609 entries, no response is given. */
1610 if (lim
== (caddr_t
)rte
)
1613 /* There is one special case. If there is exactly one entry in the
1614 request, and it has an address family identifier of zero and a
1615 metric of infinity (i.e., 16), then this is a request to send the
1616 entire routing table. */
1617 if (lim
== ((caddr_t
)(rte
+ 1)) && ntohs(rte
->family
) == 0
1618 && ntohl(rte
->metric
) == RIP_METRIC_INFINITY
) {
1619 /* All route with split horizon */
1620 rip_output_process(ifc
, from
, rip_all_route
, packet
->version
);
1622 if (ntohs(rte
->family
) != AF_INET
)
1625 /* Examine the list of RTEs in the Request one by one. For each
1626 entry, look up the destination in the router's routing
1627 database and, if there is a route, put that route's metric in
1628 the metric field of the RTE. If there is no explicit route
1629 to the specified destination, put infinity in the metric
1630 field. Once all the entries have been filled in, change the
1631 command from Request to Response and send the datagram back
1632 to the requestor. */
1635 for (; ((caddr_t
)rte
) < lim
; rte
++) {
1636 p
.prefix
= rte
->prefix
;
1637 p
.prefixlen
= ip_masklen(rte
->mask
);
1638 apply_mask_ipv4(&p
);
1640 rp
= route_node_lookup(rip
->table
, (struct prefix
*)&p
);
1642 rinfo
= listgetdata(
1643 listhead((struct list
*)rp
->info
));
1644 rte
->metric
= htonl(rinfo
->metric
);
1645 route_unlock_node(rp
);
1647 rte
->metric
= htonl(RIP_METRIC_INFINITY
);
1649 packet
->command
= RIP_RESPONSE
;
1651 (void)rip_send_packet((uint8_t *)packet
, size
, from
, ifc
);
1653 rip_global_queries
++;
1657 /* Set IPv6 packet info to the socket. */
1658 static int setsockopt_pktinfo(int sock
)
1663 ret
= setsockopt(sock
, IPPROTO_IP
, IP_PKTINFO
, &val
, sizeof(val
));
1665 zlog_warn("Can't setsockopt IP_PKTINFO : %s",
1666 safe_strerror(errno
));
1670 /* Read RIP packet by recvmsg function. */
1671 int rip_recvmsg(int sock
, uint8_t *buf
, int size
, struct sockaddr_in
*from
,
1677 struct cmsghdr
*ptr
;
1680 memset(&msg
, 0, sizeof(msg
));
1681 msg
.msg_name
= (void *)from
;
1682 msg
.msg_namelen
= sizeof(struct sockaddr_in
);
1685 msg
.msg_control
= (void *)adata
;
1686 msg
.msg_controllen
= sizeof adata
;
1690 ret
= recvmsg(sock
, &msg
, 0);
1694 for (ptr
= ZCMSG_FIRSTHDR(&msg
); ptr
!= NULL
;
1695 ptr
= CMSG_NXTHDR(&msg
, ptr
))
1696 if (ptr
->cmsg_level
== IPPROTO_IP
1697 && ptr
->cmsg_type
== IP_PKTINFO
) {
1698 struct in_pktinfo
*pktinfo
;
1701 pktinfo
= (struct in_pktinfo
*)CMSG_DATA(ptr
);
1702 i
= pktinfo
->ipi_ifindex
;
1707 /* RIP packet read function. */
1708 int rip_read_new(struct thread
*t
)
1712 char buf
[RIP_PACKET_MAXSIZ
];
1713 struct sockaddr_in from
;
1716 /* Fetch socket then register myself. */
1717 sock
= THREAD_FD(t
);
1718 rip_event(RIP_READ
, sock
);
1720 /* Read RIP packet. */
1721 ret
= rip_recvmsg(sock
, buf
, RIP_PACKET_MAXSIZ
, &from
, (int *)&ifindex
);
1723 zlog_warn("Can't read RIP packet: %s", safe_strerror(errno
));
1729 #endif /* RIP_RECVMSG */
1731 /* First entry point of RIP packet. */
1732 static int rip_read(struct thread
*t
)
1737 union rip_buf rip_buf
;
1738 struct rip_packet
*packet
;
1739 struct sockaddr_in from
;
1743 struct interface
*ifp
= NULL
;
1744 struct connected
*ifc
;
1745 struct rip_interface
*ri
;
1748 /* Fetch socket then register myself. */
1749 sock
= THREAD_FD(t
);
1752 /* Add myself to tne next event */
1753 rip_event(RIP_READ
, sock
);
1755 /* RIPd manages only IPv4. */
1756 memset(&from
, 0, sizeof(struct sockaddr_in
));
1757 fromlen
= sizeof(struct sockaddr_in
);
1759 len
= recvfrom(sock
, (char *)&rip_buf
.buf
, sizeof(rip_buf
.buf
), 0,
1760 (struct sockaddr
*)&from
, &fromlen
);
1762 zlog_info("recvfrom failed: %s", safe_strerror(errno
));
1766 /* Check is this packet comming from myself? */
1767 if (if_check_address(from
.sin_addr
)) {
1768 if (IS_RIP_DEBUG_PACKET
)
1769 zlog_debug("ignore packet comes from myself");
1773 /* Which interface is this packet comes from. */
1774 ifc
= if_lookup_address((void *)&from
.sin_addr
, AF_INET
, VRF_DEFAULT
);
1778 /* RIP packet received */
1779 if (IS_RIP_DEBUG_EVENT
)
1780 zlog_debug("RECV packet from %s port %d on %s",
1781 inet_ntoa(from
.sin_addr
), ntohs(from
.sin_port
),
1782 ifp
? ifp
->name
: "unknown");
1784 /* If this packet come from unknown interface, ignore it. */
1787 "rip_read: cannot find interface for packet from %s port %d",
1788 inet_ntoa(from
.sin_addr
), ntohs(from
.sin_port
));
1793 p
.u
.prefix4
= from
.sin_addr
;
1794 p
.prefixlen
= IPV4_MAX_BITLEN
;
1796 ifc
= connected_lookup_prefix(ifp
, &p
);
1800 "rip_read: cannot find connected address for packet from %s "
1801 "port %d on interface %s",
1802 inet_ntoa(from
.sin_addr
), ntohs(from
.sin_port
),
1807 /* Packet length check. */
1808 if (len
< RIP_PACKET_MINSIZ
) {
1809 zlog_warn("packet size %d is smaller than minimum size %d", len
,
1811 rip_peer_bad_packet(&from
);
1814 if (len
> RIP_PACKET_MAXSIZ
) {
1815 zlog_warn("packet size %d is larger than max size %d", len
,
1817 rip_peer_bad_packet(&from
);
1821 /* Packet alignment check. */
1822 if ((len
- RIP_PACKET_MINSIZ
) % 20) {
1823 zlog_warn("packet size %d is wrong for RIP packet alignment",
1825 rip_peer_bad_packet(&from
);
1829 /* Set RTE number. */
1830 rtenum
= ((len
- RIP_PACKET_MINSIZ
) / 20);
1832 /* For easy to handle. */
1833 packet
= &rip_buf
.rip_packet
;
1835 /* RIP version check. */
1836 if (packet
->version
== 0) {
1837 zlog_info("version 0 with command %d received.",
1839 rip_peer_bad_packet(&from
);
1843 /* Dump RIP packet. */
1844 if (IS_RIP_DEBUG_RECV
)
1845 rip_packet_dump(packet
, len
, "RECV");
1847 /* RIP version adjust. This code should rethink now. RFC1058 says
1848 that "Version 1 implementations are to ignore this extra data and
1849 process only the fields specified in this document.". So RIPv3
1850 packet should be treated as RIPv1 ignoring must be zero field. */
1851 if (packet
->version
> RIPv2
)
1852 packet
->version
= RIPv2
;
1854 /* Is RIP running or is this RIP neighbor ?*/
1856 if (!ri
->running
&& !rip_neighbor_lookup(&from
)) {
1857 if (IS_RIP_DEBUG_EVENT
)
1858 zlog_debug("RIP is not enabled on interface %s.",
1860 rip_peer_bad_packet(&from
);
1864 /* RIP Version check. RFC2453, 4.6 and 5.1 */
1865 vrecv
= ((ri
->ri_receive
== RI_RIP_UNSPEC
) ? rip
->version_recv
1867 if (vrecv
== RI_RIP_VERSION_NONE
1868 || ((packet
->version
== RIPv1
) && !(vrecv
& RIPv1
))
1869 || ((packet
->version
== RIPv2
) && !(vrecv
& RIPv2
))) {
1870 if (IS_RIP_DEBUG_PACKET
)
1872 " packet's v%d doesn't fit to if version spec",
1874 rip_peer_bad_packet(&from
);
1878 /* RFC2453 5.2 If the router is not configured to authenticate RIP-2
1879 messages, then RIP-1 and unauthenticated RIP-2 messages will be
1880 accepted; authenticated RIP-2 messages shall be discarded. */
1881 if ((ri
->auth_type
== RIP_NO_AUTH
) && rtenum
1882 && (packet
->version
== RIPv2
)
1883 && (packet
->rte
->family
== htons(RIP_FAMILY_AUTH
))) {
1884 if (IS_RIP_DEBUG_EVENT
)
1886 "packet RIPv%d is dropped because authentication disabled",
1888 rip_peer_bad_packet(&from
);
1893 If the router is configured to authenticate RIP-2 messages, then
1894 RIP-1 messages and RIP-2 messages which pass authentication
1895 testing shall be accepted; unauthenticated and failed
1896 authentication RIP-2 messages shall be discarded. For maximum
1897 security, RIP-1 messages should be ignored when authentication is
1898 in use (see section 4.1); otherwise, the routing information from
1899 authenticated messages will be propagated by RIP-1 routers in an
1900 unauthenticated manner.
1902 /* We make an exception for RIPv1 REQUEST packets, to which we'll
1903 * always reply regardless of authentication settings, because:
1905 * - if there other authorised routers on-link, the REQUESTor can
1906 * passively obtain the routing updates anyway
1907 * - if there are no other authorised routers on-link, RIP can
1908 * easily be disabled for the link to prevent giving out information
1909 * on state of this routers RIP routing table..
1911 * I.e. if RIPv1 has any place anymore these days, it's as a very
1912 * simple way to distribute routing information (e.g. to embedded
1913 * hosts / appliances) and the ability to give out RIPv1
1914 * routing-information freely, while still requiring RIPv2
1915 * authentication for any RESPONSEs might be vaguely useful.
1917 if (ri
->auth_type
!= RIP_NO_AUTH
&& packet
->version
== RIPv1
) {
1918 /* Discard RIPv1 messages other than REQUESTs */
1919 if (packet
->command
!= RIP_REQUEST
) {
1920 if (IS_RIP_DEBUG_PACKET
)
1923 " dropped because authentication enabled");
1924 rip_peer_bad_packet(&from
);
1927 } else if (ri
->auth_type
!= RIP_NO_AUTH
) {
1928 const char *auth_desc
;
1931 /* There definitely is no authentication in the packet.
1933 if (IS_RIP_DEBUG_PACKET
)
1935 "RIPv2 authentication failed: no auth RTE in packet");
1936 rip_peer_bad_packet(&from
);
1940 /* First RTE must be an Authentication Family RTE */
1941 if (packet
->rte
->family
!= htons(RIP_FAMILY_AUTH
)) {
1942 if (IS_RIP_DEBUG_PACKET
)
1945 " dropped because authentication enabled");
1946 rip_peer_bad_packet(&from
);
1950 /* Check RIPv2 authentication. */
1951 switch (ntohs(packet
->rte
->tag
)) {
1952 case RIP_AUTH_SIMPLE_PASSWORD
:
1953 auth_desc
= "simple";
1954 ret
= rip_auth_simple_password(packet
->rte
, &from
, ifp
);
1959 ret
= rip_auth_md5(packet
, &from
, len
, ifp
);
1960 /* Reset RIP packet length to trim MD5 data. */
1966 auth_desc
= "unknown type";
1967 if (IS_RIP_DEBUG_PACKET
)
1969 "RIPv2 Unknown authentication type %d",
1970 ntohs(packet
->rte
->tag
));
1974 if (IS_RIP_DEBUG_PACKET
)
1975 zlog_debug("RIPv2 %s authentication success",
1978 if (IS_RIP_DEBUG_PACKET
)
1979 zlog_debug("RIPv2 %s authentication failure",
1981 rip_peer_bad_packet(&from
);
1986 /* Process each command. */
1987 switch (packet
->command
) {
1989 rip_response_process(packet
, len
, &from
, ifc
);
1993 rip_request_process(packet
, len
, &from
, ifc
);
1998 "Obsolete command %s received, please sent it to routed",
1999 lookup_msg(rip_msg
, packet
->command
, NULL
));
2000 rip_peer_bad_packet(&from
);
2002 case RIP_POLL_ENTRY
:
2003 zlog_info("Obsolete command %s received",
2004 lookup_msg(rip_msg
, packet
->command
, NULL
));
2005 rip_peer_bad_packet(&from
);
2008 zlog_info("Unknown RIP command %d received", packet
->command
);
2009 rip_peer_bad_packet(&from
);
2016 /* Write routing table entry to the stream and return next index of
2017 the routing table entry in the stream. */
2018 static int rip_write_rte(int num
, struct stream
*s
, struct prefix_ipv4
*p
,
2019 uint8_t version
, struct rip_info
*rinfo
)
2021 struct in_addr mask
;
2023 /* Write routing table entry. */
2024 if (version
== RIPv1
) {
2025 stream_putw(s
, AF_INET
);
2027 stream_put_ipv4(s
, p
->prefix
.s_addr
);
2028 stream_put_ipv4(s
, 0);
2029 stream_put_ipv4(s
, 0);
2030 stream_putl(s
, rinfo
->metric_out
);
2032 masklen2ip(p
->prefixlen
, &mask
);
2034 stream_putw(s
, AF_INET
);
2035 stream_putw(s
, rinfo
->tag_out
);
2036 stream_put_ipv4(s
, p
->prefix
.s_addr
);
2037 stream_put_ipv4(s
, mask
.s_addr
);
2038 stream_put_ipv4(s
, rinfo
->nexthop_out
.s_addr
);
2039 stream_putl(s
, rinfo
->metric_out
);
2045 /* Send update to the ifp or spcified neighbor. */
2046 void rip_output_process(struct connected
*ifc
, struct sockaddr_in
*to
,
2047 int route_type
, uint8_t version
)
2051 struct route_node
*rp
;
2052 struct rip_info
*rinfo
;
2053 struct rip_interface
*ri
;
2054 struct prefix_ipv4
*p
;
2055 struct prefix_ipv4 classfull
;
2056 struct prefix_ipv4 ifaddrclass
;
2057 struct key
*key
= NULL
;
2058 /* this might need to made dynamic if RIP ever supported auth methods
2059 with larger key string sizes */
2060 char auth_str
[RIP_AUTH_SIMPLE_SIZE
];
2061 size_t doff
= 0; /* offset of digest offset field */
2065 struct list
*list
= NULL
;
2066 struct listnode
*listnode
= NULL
;
2068 /* Logging output event. */
2069 if (IS_RIP_DEBUG_EVENT
) {
2071 zlog_debug("update routes to neighbor %s",
2072 inet_ntoa(to
->sin_addr
));
2074 zlog_debug("update routes on interface %s ifindex %d",
2075 ifc
->ifp
->name
, ifc
->ifp
->ifindex
);
2078 /* Set output stream. */
2081 /* Reset stream and RTE counter. */
2083 rtemax
= RIP_MAX_RTE
;
2085 /* Get RIP interface. */
2086 ri
= ifc
->ifp
->info
;
2088 /* If output interface is in simple password authentication mode, we
2089 need space for authentication data. */
2090 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
2093 /* If output interface is in MD5 authentication mode, we need space
2094 for authentication header and data. */
2095 if (ri
->auth_type
== RIP_AUTH_MD5
)
2098 /* If output interface is in simple password authentication mode
2099 and string or keychain is specified we need space for auth. data */
2100 if (ri
->auth_type
!= RIP_NO_AUTH
) {
2101 if (ri
->key_chain
) {
2102 struct keychain
*keychain
;
2104 keychain
= keychain_lookup(ri
->key_chain
);
2106 key
= key_lookup_for_send(keychain
);
2108 /* to be passed to auth functions later */
2109 rip_auth_prepare_str_send(ri
, key
, auth_str
,
2110 RIP_AUTH_SIMPLE_SIZE
);
2111 if (strlen(auth_str
) == 0)
2115 if (version
== RIPv1
) {
2116 memcpy(&ifaddrclass
, ifc
->address
, sizeof(struct prefix_ipv4
));
2117 apply_classful_mask_ipv4(&ifaddrclass
);
2119 if (ifc
->address
->prefixlen
> ifaddrclass
.prefixlen
)
2123 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
2124 if ((list
= rp
->info
) != NULL
&& listcount(list
) != 0) {
2125 rinfo
= listgetdata(listhead(list
));
2126 /* For RIPv1, if we are subnetted, output subnets in our
2128 /* that have the same mask as the output "interface".
2130 /* networks, only the classfull version is output. */
2132 if (version
== RIPv1
) {
2133 p
= (struct prefix_ipv4
*)&rp
->p
;
2135 if (IS_RIP_DEBUG_PACKET
)
2137 "RIPv1 mask check, %s/%d considered for output",
2138 inet_ntoa(rp
->p
.u
.prefix4
),
2143 (struct prefix
*)&ifaddrclass
,
2145 if ((ifc
->address
->prefixlen
2147 && (rp
->p
.prefixlen
!= 32))
2150 memcpy(&classfull
, &rp
->p
,
2151 sizeof(struct prefix_ipv4
));
2152 apply_classful_mask_ipv4(&classfull
);
2153 if (rp
->p
.u
.prefix4
.s_addr
!= 0
2154 && classfull
.prefixlen
2158 if (IS_RIP_DEBUG_PACKET
)
2160 "RIPv1 mask check, %s/%d made it through",
2161 inet_ntoa(rp
->p
.u
.prefix4
),
2164 p
= (struct prefix_ipv4
*)&rp
->p
;
2166 /* Apply output filters. */
2167 ret
= rip_filter(RIP_FILTER_OUT
, p
, ri
);
2171 /* Changed route only output. */
2172 if (route_type
== rip_changed_route
2173 && (!(rinfo
->flags
& RIP_RTF_CHANGED
)))
2176 /* Split horizon. */
2177 /* if (split_horizon == rip_split_horizon) */
2178 if (ri
->split_horizon
== RIP_SPLIT_HORIZON
) {
2180 * We perform split horizon for RIP and
2182 * For rip routes, we want to suppress the route
2184 * end up sending the route back on the
2186 * learned it from, with a higher metric. For
2188 * we suppress the route if the prefix is a
2190 * source address that we are going to use for
2192 * (in order to handle the case when multiple
2194 * configured on the same interface).
2197 struct rip_info
*tmp_rinfo
= NULL
;
2198 struct connected
*tmp_ifc
= NULL
;
2200 for (ALL_LIST_ELEMENTS_RO(list
, listnode
,
2202 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
2203 && tmp_rinfo
->nh
.ifindex
2204 == ifc
->ifp
->ifindex
) {
2210 && rinfo
->type
== ZEBRA_ROUTE_CONNECT
) {
2211 for (ALL_LIST_ELEMENTS_RO(
2212 ifc
->ifp
->connected
,
2216 tmp_ifc
->address
)) {
2226 /* Preparation for route-map. */
2227 rinfo
->metric_set
= 0;
2228 rinfo
->nexthop_out
.s_addr
= 0;
2229 rinfo
->metric_out
= rinfo
->metric
;
2230 rinfo
->tag_out
= rinfo
->tag
;
2231 rinfo
->ifindex_out
= ifc
->ifp
->ifindex
;
2233 /* In order to avoid some local loops,
2234 * if the RIP route has a nexthop via this interface,
2236 * otherwise set it to 0. The nexthop should not be
2238 * beyond the local broadcast/multicast area in order
2239 * to avoid an IGP multi-level recursive look-up.
2242 if (rinfo
->nh
.ifindex
== ifc
->ifp
->ifindex
)
2243 rinfo
->nexthop_out
= rinfo
->nh
.gate
.ipv4
;
2245 /* Interface route-map */
2246 if (ri
->routemap
[RIP_FILTER_OUT
]) {
2247 ret
= route_map_apply(
2248 ri
->routemap
[RIP_FILTER_OUT
],
2249 (struct prefix
*)p
, RMAP_RIP
, rinfo
);
2251 if (ret
== RMAP_DENYMATCH
) {
2252 if (IS_RIP_DEBUG_PACKET
)
2254 "RIP %s/%d is filtered by route-map out",
2255 inet_ntoa(p
->prefix
),
2261 /* Apply redistribute route map - continue, if deny */
2262 if (rip
->route_map
[rinfo
->type
].name
2263 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
) {
2264 ret
= route_map_apply(
2265 rip
->route_map
[rinfo
->type
].map
,
2266 (struct prefix
*)p
, RMAP_RIP
, rinfo
);
2268 if (ret
== RMAP_DENYMATCH
) {
2269 if (IS_RIP_DEBUG_PACKET
)
2271 "%s/%d is filtered by route-map",
2272 inet_ntoa(p
->prefix
),
2278 /* When route-map does not set metric. */
2279 if (!rinfo
->metric_set
) {
2280 /* If redistribute metric is set. */
2281 if (rip
->route_map
[rinfo
->type
].metric_config
2282 && rinfo
->metric
!= RIP_METRIC_INFINITY
) {
2284 rip
->route_map
[rinfo
->type
]
2287 /* If the route is not connected or
2289 one, use default-metric value*/
2290 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
2292 != ZEBRA_ROUTE_CONNECT
2294 != RIP_METRIC_INFINITY
)
2296 rip
->default_metric
;
2300 /* Apply offset-list */
2301 if (rinfo
->metric
!= RIP_METRIC_INFINITY
)
2302 rip_offset_list_apply_out(p
, ifc
->ifp
,
2303 &rinfo
->metric_out
);
2305 if (rinfo
->metric_out
> RIP_METRIC_INFINITY
)
2306 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2308 /* Perform split-horizon with poisoned reverse
2309 * for RIP and connected routes.
2311 if (ri
->split_horizon
2312 == RIP_SPLIT_HORIZON_POISONED_REVERSE
) {
2314 * We perform split horizon for RIP and
2316 * For rip routes, we want to suppress the route
2318 * end up sending the route back on the
2320 * learned it from, with a higher metric. For
2322 * we suppress the route if the prefix is a
2324 * source address that we are going to use for
2326 * (in order to handle the case when multiple
2328 * configured on the same interface).
2330 struct rip_info
*tmp_rinfo
= NULL
;
2331 struct connected
*tmp_ifc
= NULL
;
2333 for (ALL_LIST_ELEMENTS_RO(list
, listnode
,
2335 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
2336 && tmp_rinfo
->nh
.ifindex
2337 == ifc
->ifp
->ifindex
)
2339 RIP_METRIC_INFINITY
;
2341 if (rinfo
->metric_out
!= RIP_METRIC_INFINITY
2342 && rinfo
->type
== ZEBRA_ROUTE_CONNECT
) {
2343 for (ALL_LIST_ELEMENTS_RO(
2344 ifc
->ifp
->connected
,
2348 tmp_ifc
->address
)) {
2350 RIP_METRIC_INFINITY
;
2356 /* Prepare preamble, auth headers, if needs be */
2358 stream_putc(s
, RIP_RESPONSE
);
2359 stream_putc(s
, version
);
2362 /* auth header for !v1 && !no_auth */
2363 if ((ri
->auth_type
!= RIP_NO_AUTH
)
2364 && (version
!= RIPv1
))
2365 doff
= rip_auth_header_write(
2366 s
, ri
, key
, auth_str
,
2367 RIP_AUTH_SIMPLE_SIZE
);
2370 /* Write RTE to the stream. */
2371 num
= rip_write_rte(num
, s
, p
, version
, rinfo
);
2372 if (num
== rtemax
) {
2373 if (version
== RIPv2
2374 && ri
->auth_type
== RIP_AUTH_MD5
)
2375 rip_auth_md5_set(s
, ri
, doff
, auth_str
,
2376 RIP_AUTH_SIMPLE_SIZE
);
2378 ret
= rip_send_packet(STREAM_DATA(s
),
2379 stream_get_endp(s
), to
,
2382 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2383 rip_packet_dump((struct rip_packet
*)
2392 /* Flush unwritten RTE. */
2394 if (version
== RIPv2
&& ri
->auth_type
== RIP_AUTH_MD5
)
2395 rip_auth_md5_set(s
, ri
, doff
, auth_str
,
2396 RIP_AUTH_SIMPLE_SIZE
);
2398 ret
= rip_send_packet(STREAM_DATA(s
), stream_get_endp(s
), to
,
2401 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2402 rip_packet_dump((struct rip_packet
*)STREAM_DATA(s
),
2403 stream_get_endp(s
), "SEND");
2407 /* Statistics updates. */
2411 /* Send RIP packet to the interface. */
2412 static void rip_update_interface(struct connected
*ifc
, uint8_t version
,
2415 struct interface
*ifp
= ifc
->ifp
;
2416 struct rip_interface
*ri
= ifp
->info
;
2417 struct sockaddr_in to
;
2419 /* When RIP version is 2 and multicast enable interface. */
2420 if (version
== RIPv2
&& !ri
->v2_broadcast
&& if_is_multicast(ifp
)) {
2421 if (IS_RIP_DEBUG_EVENT
)
2422 zlog_debug("multicast announce on %s ", ifp
->name
);
2424 rip_output_process(ifc
, NULL
, route_type
, version
);
2428 /* If we can't send multicast packet, send it with unicast. */
2429 if (if_is_broadcast(ifp
) || if_is_pointopoint(ifp
)) {
2430 if (ifc
->address
->family
== AF_INET
) {
2431 /* Destination address and port setting. */
2432 memset(&to
, 0, sizeof(struct sockaddr_in
));
2433 if (ifc
->destination
)
2434 /* use specified broadcast or peer destination
2436 to
.sin_addr
= ifc
->destination
->u
.prefix4
;
2437 else if (ifc
->address
->prefixlen
< IPV4_MAX_PREFIXLEN
)
2438 /* calculate the appropriate broadcast address
2440 to
.sin_addr
.s_addr
= ipv4_broadcast_addr(
2441 ifc
->address
->u
.prefix4
.s_addr
,
2442 ifc
->address
->prefixlen
);
2444 /* do not know where to send the packet */
2446 to
.sin_port
= htons(RIP_PORT_DEFAULT
);
2448 if (IS_RIP_DEBUG_EVENT
)
2449 zlog_debug("%s announce to %s on %s",
2450 CONNECTED_PEER(ifc
) ? "unicast"
2452 inet_ntoa(to
.sin_addr
), ifp
->name
);
2454 rip_output_process(ifc
, &to
, route_type
, version
);
2459 /* Update send to all interface and neighbor. */
2460 static void rip_update_process(int route_type
)
2462 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2463 struct listnode
*ifnode
, *ifnnode
;
2464 struct connected
*connected
;
2465 struct interface
*ifp
;
2466 struct rip_interface
*ri
;
2467 struct route_node
*rp
;
2468 struct sockaddr_in to
;
2471 /* Send RIP update to each interface. */
2472 FOR_ALL_INTERFACES (vrf
, ifp
) {
2473 if (if_is_loopback(ifp
))
2476 if (!if_is_operative(ifp
))
2479 /* Fetch RIP interface information. */
2482 /* When passive interface is specified, suppress announce to the
2489 * If there is no version configuration in the
2491 * use rip's version setting.
2493 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
)
2497 if (IS_RIP_DEBUG_EVENT
)
2498 zlog_debug("SEND UPDATE to %s ifindex %d",
2499 ifp
->name
, ifp
->ifindex
);
2501 /* send update on each connected network */
2502 for (ALL_LIST_ELEMENTS(ifp
->connected
, ifnode
, ifnnode
,
2504 if (connected
->address
->family
== AF_INET
) {
2506 rip_update_interface(
2510 && if_is_multicast(ifp
))
2511 rip_update_interface(
2519 /* RIP send updates to each neighbor. */
2520 for (rp
= route_top(rip
->neighbor
); rp
; rp
= route_next(rp
))
2521 if (rp
->info
!= NULL
) {
2524 connected
= if_lookup_address(&p
->u
.prefix4
, AF_INET
,
2528 "Neighbor %s doesnt have connected interface!",
2529 inet_ntoa(p
->u
.prefix4
));
2533 /* Set destination address and port */
2534 memset(&to
, 0, sizeof(struct sockaddr_in
));
2535 to
.sin_addr
= p
->u
.prefix4
;
2536 to
.sin_port
= htons(RIP_PORT_DEFAULT
);
2538 /* RIP version is rip's configuration. */
2539 rip_output_process(connected
, &to
, route_type
,
2544 /* RIP's periodical timer. */
2545 static int rip_update(struct thread
*t
)
2547 /* Clear timer pointer. */
2548 rip
->t_update
= NULL
;
2550 if (IS_RIP_DEBUG_EVENT
)
2551 zlog_debug("update timer fire!");
2553 /* Process update output. */
2554 rip_update_process(rip_all_route
);
2556 /* Triggered updates may be suppressed if a regular update is due by
2557 the time the triggered update would be sent. */
2558 RIP_TIMER_OFF(rip
->t_triggered_interval
);
2561 /* Register myself. */
2562 rip_event(RIP_UPDATE_EVENT
, 0);
2567 /* Walk down the RIP routing table then clear changed flag. */
2568 static void rip_clear_changed_flag(void)
2570 struct route_node
*rp
;
2571 struct rip_info
*rinfo
= NULL
;
2572 struct list
*list
= NULL
;
2573 struct listnode
*listnode
= NULL
;
2575 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
2576 if ((list
= rp
->info
) != NULL
)
2577 for (ALL_LIST_ELEMENTS_RO(list
, listnode
, rinfo
)) {
2578 UNSET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
2579 /* This flag can be set only on the first entry.
2585 /* Triggered update interval timer. */
2586 static int rip_triggered_interval(struct thread
*t
)
2588 int rip_triggered_update(struct thread
*);
2590 rip
->t_triggered_interval
= NULL
;
2594 rip_triggered_update(t
);
2599 /* Execute triggered update. */
2600 static int rip_triggered_update(struct thread
*t
)
2604 /* Clear thred pointer. */
2605 rip
->t_triggered_update
= NULL
;
2607 /* Cancel interval timer. */
2608 RIP_TIMER_OFF(rip
->t_triggered_interval
);
2611 /* Logging triggered update. */
2612 if (IS_RIP_DEBUG_EVENT
)
2613 zlog_debug("triggered update!");
2615 /* Split Horizon processing is done when generating triggered
2616 updates as well as normal updates (see section 2.6). */
2617 rip_update_process(rip_changed_route
);
2619 /* Once all of the triggered updates have been generated, the route
2620 change flags should be cleared. */
2621 rip_clear_changed_flag();
2623 /* After a triggered update is sent, a timer should be set for a
2624 random interval between 1 and 5 seconds. If other changes that
2625 would trigger updates occur before the timer expires, a single
2626 update is triggered when the timer expires. */
2627 interval
= (random() % 5) + 1;
2629 rip
->t_triggered_interval
= NULL
;
2630 thread_add_timer(master
, rip_triggered_interval
, NULL
, interval
,
2631 &rip
->t_triggered_interval
);
2636 /* Withdraw redistributed route. */
2637 void rip_redistribute_withdraw(int type
)
2639 struct route_node
*rp
;
2640 struct rip_info
*rinfo
= NULL
;
2641 struct list
*list
= NULL
;
2646 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
2647 if ((list
= rp
->info
) != NULL
) {
2648 rinfo
= listgetdata(listhead(list
));
2649 if (rinfo
->type
== type
2650 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
) {
2651 /* Perform poisoned reverse. */
2652 rinfo
->metric
= RIP_METRIC_INFINITY
;
2653 RIP_TIMER_ON(rinfo
->t_garbage_collect
,
2654 rip_garbage_collect
,
2656 RIP_TIMER_OFF(rinfo
->t_timeout
);
2657 rinfo
->flags
|= RIP_RTF_CHANGED
;
2659 if (IS_RIP_DEBUG_EVENT
) {
2660 struct prefix_ipv4
*p
=
2661 (struct prefix_ipv4
*)&rp
->p
;
2664 "Poisone %s/%d on the interface %s with an infinity metric [withdraw]",
2665 inet_ntoa(p
->prefix
),
2672 rip_event(RIP_TRIGGERED_UPDATE
, 0);
2677 /* Create new RIP instance and set it to global variable. */
2678 static int rip_create(void)
2680 rip
= XCALLOC(MTYPE_RIP
, sizeof(struct rip
));
2682 /* Set initial value. */
2683 rip
->version_send
= RI_RIP_VERSION_2
;
2684 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2685 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
2686 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
2687 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
2688 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2690 /* Initialize RIP routig table. */
2691 rip
->table
= route_table_init();
2692 rip
->route
= route_table_init();
2693 rip
->neighbor
= route_table_init();
2695 /* Make output stream. */
2696 rip
->obuf
= stream_new(1500);
2699 rip
->sock
= rip_create_socket();
2703 /* Create read and timer thread. */
2704 rip_event(RIP_READ
, rip
->sock
);
2705 rip_event(RIP_UPDATE_EVENT
, 1);
2712 /* Sned RIP request to the destination. */
2713 int rip_request_send(struct sockaddr_in
*to
, struct interface
*ifp
,
2714 uint8_t version
, struct connected
*connected
)
2717 struct rip_packet rip_packet
;
2718 struct listnode
*node
, *nnode
;
2720 memset(&rip_packet
, 0, sizeof(rip_packet
));
2722 rip_packet
.command
= RIP_REQUEST
;
2723 rip_packet
.version
= version
;
2724 rte
= rip_packet
.rte
;
2725 rte
->metric
= htonl(RIP_METRIC_INFINITY
);
2729 * connected is only sent for ripv1 case, or when
2730 * interface does not support multicast. Caller loops
2731 * over each connected address for this case.
2733 if (rip_send_packet((uint8_t *)&rip_packet
, sizeof(rip_packet
),
2735 != sizeof(rip_packet
))
2738 return sizeof(rip_packet
);
2741 /* send request on each connected network */
2742 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
2743 struct prefix_ipv4
*p
;
2745 p
= (struct prefix_ipv4
*)connected
->address
;
2747 if (p
->family
!= AF_INET
)
2750 if (rip_send_packet((uint8_t *)&rip_packet
, sizeof(rip_packet
),
2752 != sizeof(rip_packet
))
2755 return sizeof(rip_packet
);
2758 static int rip_update_jitter(unsigned long time
)
2760 #define JITTER_BOUND 4
2761 /* We want to get the jitter to +/- 1/JITTER_BOUND the interval.
2762 Given that, we cannot let time be less than JITTER_BOUND seconds.
2763 The RIPv2 RFC says jitter should be small compared to
2764 update_time. We consider 1/JITTER_BOUND to be small.
2767 int jitter_input
= time
;
2770 if (jitter_input
< JITTER_BOUND
)
2771 jitter_input
= JITTER_BOUND
;
2773 jitter
= (((random() % ((jitter_input
* 2) + 1)) - jitter_input
));
2775 return jitter
/ JITTER_BOUND
;
2778 void rip_event(enum rip_event event
, int sock
)
2785 thread_add_read(master
, rip_read
, NULL
, sock
, &rip
->t_read
);
2787 case RIP_UPDATE_EVENT
:
2788 RIP_TIMER_OFF(rip
->t_update
);
2789 jitter
= rip_update_jitter(rip
->update_time
);
2790 thread_add_timer(master
, rip_update
, NULL
,
2791 sock
? 2 : rip
->update_time
+ jitter
,
2794 case RIP_TRIGGERED_UPDATE
:
2795 if (rip
->t_triggered_interval
)
2798 thread_add_event(master
, rip_triggered_update
, NULL
, 0,
2799 &rip
->t_triggered_update
);
2806 DEFUN_NOSH (router_rip
,
2809 "Enable a routing process\n"
2810 "Routing Information Protocol (RIP)\n")
2814 /* If rip is not enabled before. */
2818 zlog_info("Can't create RIP");
2819 return CMD_WARNING_CONFIG_FAILED
;
2823 VTY_PUSH_CONTEXT(RIP_NODE
, rip
);
2828 DEFUN (no_router_rip
,
2832 "Enable a routing process\n"
2833 "Routing Information Protocol (RIP)\n")
2843 "Set routing protocol version\n"
2849 version
= atoi(argv
[idx_number
]->arg
);
2850 if (version
!= RIPv1
&& version
!= RIPv2
) {
2851 vty_out(vty
, "invalid rip version %d\n", version
);
2852 return CMD_WARNING_CONFIG_FAILED
;
2854 rip
->version_send
= version
;
2855 rip
->version_recv
= version
;
2860 DEFUN (no_rip_version
,
2862 "no version [(1-2)]",
2864 "Set routing protocol version\n"
2867 /* Set RIP version to the default. */
2868 rip
->version_send
= RI_RIP_VERSION_2
;
2869 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2878 "RIP static route configuration\n"
2879 "IP prefix <network>/<length>\n")
2881 int idx_ipv4_prefixlen
= 1;
2884 struct prefix_ipv4 p
;
2885 struct route_node
*node
;
2887 memset(&nh
, 0, sizeof(nh
));
2888 nh
.type
= NEXTHOP_TYPE_IPV4
;
2890 ret
= str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2892 vty_out(vty
, "Malformed address\n");
2893 return CMD_WARNING_CONFIG_FAILED
;
2895 apply_mask_ipv4(&p
);
2897 /* For router rip configuration. */
2898 node
= route_node_get(rip
->route
, (struct prefix
*)&p
);
2901 vty_out(vty
, "There is already same static route.\n");
2902 route_unlock_node(node
);
2906 node
->info
= (void *)1;
2908 rip_redistribute_add(ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, &nh
, 0, 0,
2914 DEFUN (no_rip_route
,
2916 "no route A.B.C.D/M",
2918 "RIP static route configuration\n"
2919 "IP prefix <network>/<length>\n")
2921 int idx_ipv4_prefixlen
= 2;
2923 struct prefix_ipv4 p
;
2924 struct route_node
*node
;
2926 ret
= str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2928 vty_out(vty
, "Malformed address\n");
2929 return CMD_WARNING_CONFIG_FAILED
;
2931 apply_mask_ipv4(&p
);
2933 /* For router rip configuration. */
2934 node
= route_node_lookup(rip
->route
, (struct prefix
*)&p
);
2936 vty_out(vty
, "Can't find route %s.\n",
2937 argv
[idx_ipv4_prefixlen
]->arg
);
2938 return CMD_WARNING_CONFIG_FAILED
;
2941 rip_redistribute_delete(ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0);
2942 route_unlock_node(node
);
2945 route_unlock_node(node
);
2952 rip_update_default_metric (void)
2954 struct route_node
*np
;
2955 struct rip_info
*rinfo
= NULL
;
2956 struct list
*list
= NULL
;
2957 struct listnode
*listnode
= NULL
;
2959 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
2960 if ((list
= np
->info
) != NULL
)
2961 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2962 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
&& rinfo
->type
!= ZEBRA_ROUTE_CONNECT
)
2963 rinfo
->metric
= rip
->default_metric
;
2967 DEFUN (rip_default_metric
,
2968 rip_default_metric_cmd
,
2969 "default-metric (1-16)",
2970 "Set a metric of redistribute routes\n"
2975 rip
->default_metric
= atoi(argv
[idx_number
]->arg
);
2976 /* rip_update_default_metric (); */
2981 DEFUN (no_rip_default_metric
,
2982 no_rip_default_metric_cmd
,
2983 "no default-metric [(1-16)]",
2985 "Set a metric of redistribute routes\n"
2989 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2990 /* rip_update_default_metric (); */
2998 "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
2999 "Adjust routing timers\n"
3000 "Basic routing protocol update timers\n"
3001 "Routing table update timer value in second. Default is 30.\n"
3002 "Routing information timeout timer. Default is 180.\n"
3003 "Garbage collection timer. Default is 120.\n")
3006 int idx_number_2
= 3;
3007 int idx_number_3
= 4;
3008 unsigned long update
;
3009 unsigned long timeout
;
3010 unsigned long garbage
;
3011 char *endptr
= NULL
;
3012 unsigned long RIP_TIMER_MAX
= 2147483647;
3013 unsigned long RIP_TIMER_MIN
= 5;
3015 update
= strtoul(argv
[idx_number
]->arg
, &endptr
, 10);
3016 if (update
> RIP_TIMER_MAX
|| update
< RIP_TIMER_MIN
3017 || *endptr
!= '\0') {
3018 vty_out(vty
, "update timer value error\n");
3019 return CMD_WARNING_CONFIG_FAILED
;
3022 timeout
= strtoul(argv
[idx_number_2
]->arg
, &endptr
, 10);
3023 if (timeout
> RIP_TIMER_MAX
|| timeout
< RIP_TIMER_MIN
3024 || *endptr
!= '\0') {
3025 vty_out(vty
, "timeout timer value error\n");
3026 return CMD_WARNING_CONFIG_FAILED
;
3029 garbage
= strtoul(argv
[idx_number_3
]->arg
, &endptr
, 10);
3030 if (garbage
> RIP_TIMER_MAX
|| garbage
< RIP_TIMER_MIN
3031 || *endptr
!= '\0') {
3032 vty_out(vty
, "garbage timer value error\n");
3033 return CMD_WARNING_CONFIG_FAILED
;
3036 /* Set each timer value. */
3037 rip
->update_time
= update
;
3038 rip
->timeout_time
= timeout
;
3039 rip
->garbage_time
= garbage
;
3041 /* Reset update timer thread. */
3042 rip_event(RIP_UPDATE_EVENT
, 0);
3047 DEFUN (no_rip_timers
,
3049 "no timers basic [(0-65535) (0-65535) (0-65535)]",
3051 "Adjust routing timers\n"
3052 "Basic routing protocol update timers\n"
3053 "Routing table update timer value in second. Default is 30.\n"
3054 "Routing information timeout timer. Default is 180.\n"
3055 "Garbage collection timer. Default is 120.\n")
3057 /* Set each timer value to the default. */
3058 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
3059 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
3060 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
3062 /* Reset update timer thread. */
3063 rip_event(RIP_UPDATE_EVENT
, 0);
3069 struct route_table
*rip_distance_table
;
3071 struct rip_distance
{
3072 /* Distance value for the IP source prefix. */
3075 /* Name of the access-list to be matched. */
3079 static struct rip_distance
*rip_distance_new(void)
3081 return XCALLOC(MTYPE_RIP_DISTANCE
, sizeof(struct rip_distance
));
3084 static void rip_distance_free(struct rip_distance
*rdistance
)
3086 XFREE(MTYPE_RIP_DISTANCE
, rdistance
);
3089 static int rip_distance_set(struct vty
*vty
, const char *distance_str
,
3090 const char *ip_str
, const char *access_list_str
)
3093 struct prefix_ipv4 p
;
3095 struct route_node
*rn
;
3096 struct rip_distance
*rdistance
;
3098 ret
= str2prefix_ipv4(ip_str
, &p
);
3100 vty_out(vty
, "Malformed prefix\n");
3101 return CMD_WARNING_CONFIG_FAILED
;
3104 distance
= atoi(distance_str
);
3106 /* Get RIP distance node. */
3107 rn
= route_node_get(rip_distance_table
, (struct prefix
*)&p
);
3109 rdistance
= rn
->info
;
3110 route_unlock_node(rn
);
3112 rdistance
= rip_distance_new();
3113 rn
->info
= rdistance
;
3116 /* Set distance value. */
3117 rdistance
->distance
= distance
;
3119 /* Reset access-list configuration. */
3120 if (rdistance
->access_list
) {
3121 free(rdistance
->access_list
);
3122 rdistance
->access_list
= NULL
;
3124 if (access_list_str
)
3125 rdistance
->access_list
= strdup(access_list_str
);
3130 static int rip_distance_unset(struct vty
*vty
, const char *distance_str
,
3131 const char *ip_str
, const char *access_list_str
)
3134 struct prefix_ipv4 p
;
3135 struct route_node
*rn
;
3136 struct rip_distance
*rdistance
;
3138 ret
= str2prefix_ipv4(ip_str
, &p
);
3140 vty_out(vty
, "Malformed prefix\n");
3141 return CMD_WARNING_CONFIG_FAILED
;
3144 rn
= route_node_lookup(rip_distance_table
, (struct prefix
*)&p
);
3146 vty_out(vty
, "Can't find specified prefix\n");
3147 return CMD_WARNING_CONFIG_FAILED
;
3150 rdistance
= rn
->info
;
3152 if (rdistance
->access_list
)
3153 free(rdistance
->access_list
);
3154 rip_distance_free(rdistance
);
3157 route_unlock_node(rn
);
3158 route_unlock_node(rn
);
3163 static void rip_distance_reset(void)
3165 struct route_node
*rn
;
3166 struct rip_distance
*rdistance
;
3168 for (rn
= route_top(rip_distance_table
); rn
; rn
= route_next(rn
))
3169 if ((rdistance
= rn
->info
) != NULL
) {
3170 if (rdistance
->access_list
)
3171 free(rdistance
->access_list
);
3172 rip_distance_free(rdistance
);
3174 route_unlock_node(rn
);
3178 /* Apply RIP information to distance method. */
3179 uint8_t rip_distance_apply(struct rip_info
*rinfo
)
3181 struct route_node
*rn
;
3182 struct prefix_ipv4 p
;
3183 struct rip_distance
*rdistance
;
3184 struct access_list
*alist
;
3189 memset(&p
, 0, sizeof(struct prefix_ipv4
));
3191 p
.prefix
= rinfo
->from
;
3192 p
.prefixlen
= IPV4_MAX_BITLEN
;
3194 /* Check source address. */
3195 rn
= route_node_match(rip_distance_table
, (struct prefix
*)&p
);
3197 rdistance
= rn
->info
;
3198 route_unlock_node(rn
);
3200 if (rdistance
->access_list
) {
3201 alist
= access_list_lookup(AFI_IP
,
3202 rdistance
->access_list
);
3205 if (access_list_apply(alist
, &rinfo
->rp
->p
)
3209 return rdistance
->distance
;
3211 return rdistance
->distance
;
3215 return rip
->distance
;
3220 static void rip_distance_show(struct vty
*vty
)
3222 struct route_node
*rn
;
3223 struct rip_distance
*rdistance
;
3227 vty_out(vty
, " Distance: (default is %d)\n",
3228 rip
->distance
? rip
->distance
: ZEBRA_RIP_DISTANCE_DEFAULT
);
3230 for (rn
= route_top(rip_distance_table
); rn
; rn
= route_next(rn
))
3231 if ((rdistance
= rn
->info
) != NULL
) {
3234 " Address Distance List\n");
3237 sprintf(buf
, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
3239 vty_out(vty
, " %-20s %4d %s\n", buf
,
3240 rdistance
->distance
,
3241 rdistance
->access_list
? rdistance
->access_list
3246 DEFUN (rip_distance
,
3249 "Administrative distance\n"
3253 rip
->distance
= atoi(argv
[idx_number
]->arg
);
3257 DEFUN (no_rip_distance
,
3258 no_rip_distance_cmd
,
3259 "no distance (1-255)",
3261 "Administrative distance\n"
3268 DEFUN (rip_distance_source
,
3269 rip_distance_source_cmd
,
3270 "distance (1-255) A.B.C.D/M",
3271 "Administrative distance\n"
3273 "IP source prefix\n")
3276 int idx_ipv4_prefixlen
= 2;
3277 rip_distance_set(vty
, argv
[idx_number
]->arg
,
3278 argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3282 DEFUN (no_rip_distance_source
,
3283 no_rip_distance_source_cmd
,
3284 "no distance (1-255) A.B.C.D/M",
3286 "Administrative distance\n"
3288 "IP source prefix\n")
3291 int idx_ipv4_prefixlen
= 3;
3292 rip_distance_unset(vty
, argv
[idx_number
]->arg
,
3293 argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3297 DEFUN (rip_distance_source_access_list
,
3298 rip_distance_source_access_list_cmd
,
3299 "distance (1-255) A.B.C.D/M WORD",
3300 "Administrative distance\n"
3302 "IP source prefix\n"
3303 "Access list name\n")
3306 int idx_ipv4_prefixlen
= 2;
3308 rip_distance_set(vty
, argv
[idx_number
]->arg
,
3309 argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3313 DEFUN (no_rip_distance_source_access_list
,
3314 no_rip_distance_source_access_list_cmd
,
3315 "no distance (1-255) A.B.C.D/M WORD",
3317 "Administrative distance\n"
3319 "IP source prefix\n"
3320 "Access list name\n")
3323 int idx_ipv4_prefixlen
= 3;
3325 rip_distance_unset(vty
, argv
[idx_number
]->arg
,
3326 argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3330 /* Update ECMP routes to zebra when ECMP is disabled. */
3331 static void rip_ecmp_disable(void)
3333 struct route_node
*rp
;
3334 struct rip_info
*rinfo
, *tmp_rinfo
;
3336 struct listnode
*node
, *nextnode
;
3341 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
3342 if ((list
= rp
->info
) != NULL
&& listcount(list
) > 1) {
3343 rinfo
= listgetdata(listhead(list
));
3344 if (!rip_route_rte(rinfo
))
3347 /* Drop all other entries, except the first one. */
3348 for (ALL_LIST_ELEMENTS(list
, node
, nextnode
, tmp_rinfo
))
3349 if (tmp_rinfo
!= rinfo
) {
3350 RIP_TIMER_OFF(tmp_rinfo
->t_timeout
);
3352 tmp_rinfo
->t_garbage_collect
);
3353 list_delete_node(list
, node
);
3354 rip_info_free(tmp_rinfo
);
3358 rip_zebra_ipv4_add(rp
);
3360 /* Set the route change flag. */
3361 SET_FLAG(rinfo
->flags
, RIP_RTF_CHANGED
);
3363 /* Signal the output process to trigger an update. */
3364 rip_event(RIP_TRIGGERED_UPDATE
, 0);
3368 DEFUN (rip_allow_ecmp
,
3371 "Allow Equal Cost MultiPath\n")
3374 vty_out(vty
, "ECMP is already enabled.\n");
3379 zlog_info("ECMP is enabled.");
3383 DEFUN (no_rip_allow_ecmp
,
3384 no_rip_allow_ecmp_cmd
,
3387 "Allow Equal Cost MultiPath\n")
3390 vty_out(vty
, "ECMP is already disabled.\n");
3395 zlog_info("ECMP is disabled.");
3400 /* Print out routes update time. */
3401 static void rip_vty_out_uptime(struct vty
*vty
, struct rip_info
*rinfo
)
3406 char timebuf
[TIME_BUF
];
3407 struct thread
*thread
;
3409 if ((thread
= rinfo
->t_timeout
) != NULL
) {
3410 clock
= thread_timer_remain_second(thread
);
3411 tm
= gmtime(&clock
);
3412 strftime(timebuf
, TIME_BUF
, "%M:%S", tm
);
3413 vty_out(vty
, "%5s", timebuf
);
3414 } else if ((thread
= rinfo
->t_garbage_collect
) != NULL
) {
3415 clock
= thread_timer_remain_second(thread
);
3416 tm
= gmtime(&clock
);
3417 strftime(timebuf
, TIME_BUF
, "%M:%S", tm
);
3418 vty_out(vty
, "%5s", timebuf
);
3422 static const char *rip_route_type_print(int sub_type
)
3427 case RIP_ROUTE_STATIC
:
3429 case RIP_ROUTE_DEFAULT
:
3431 case RIP_ROUTE_REDISTRIBUTE
:
3433 case RIP_ROUTE_INTERFACE
:
3445 "Show RIP routes\n")
3447 struct route_node
*np
;
3448 struct rip_info
*rinfo
= NULL
;
3449 struct list
*list
= NULL
;
3450 struct listnode
*listnode
= NULL
;
3456 "Codes: R - RIP, C - connected, S - Static, O - OSPF, B - BGP\n"
3458 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,\n"
3459 " (i) - interface\n\n"
3460 " Network Next Hop Metric From Tag Time\n");
3462 for (np
= route_top(rip
->table
); np
; np
= route_next(np
))
3463 if ((list
= np
->info
) != NULL
)
3464 for (ALL_LIST_ELEMENTS_RO(list
, listnode
, rinfo
)) {
3468 vty
, "%c(%s) %s/%d",
3469 /* np->lock, For debugging. */
3470 zebra_route_char(rinfo
->type
),
3471 rip_route_type_print(rinfo
->sub_type
),
3472 inet_ntoa(np
->p
.u
.prefix4
),
3478 vty_out(vty
, "%*s", len
, " ");
3480 switch (rinfo
->nh
.type
) {
3481 case NEXTHOP_TYPE_IPV4
:
3482 case NEXTHOP_TYPE_IPV4_IFINDEX
:
3483 vty_out(vty
, "%-20s %2d ",
3484 inet_ntoa(rinfo
->nh
.gate
.ipv4
),
3487 case NEXTHOP_TYPE_IFINDEX
:
3492 case NEXTHOP_TYPE_BLACKHOLE
:
3497 case NEXTHOP_TYPE_IPV6
:
3498 case NEXTHOP_TYPE_IPV6_IFINDEX
:
3500 "V6 Address Hidden %2d ",
3505 /* Route which exist in kernel routing table. */
3506 if ((rinfo
->type
== ZEBRA_ROUTE_RIP
)
3507 && (rinfo
->sub_type
== RIP_ROUTE_RTE
)) {
3508 vty_out(vty
, "%-15s ",
3509 inet_ntoa(rinfo
->from
));
3510 vty_out(vty
, "%3" ROUTE_TAG_PRI
" ",
3511 (route_tag_t
)rinfo
->tag
);
3512 rip_vty_out_uptime(vty
, rinfo
);
3513 } else if (rinfo
->metric
3514 == RIP_METRIC_INFINITY
) {
3515 vty_out(vty
, "self ");
3516 vty_out(vty
, "%3" ROUTE_TAG_PRI
" ",
3517 (route_tag_t
)rinfo
->tag
);
3518 rip_vty_out_uptime(vty
, rinfo
);
3520 if (rinfo
->external_metric
) {
3522 vty
, "self (%s:%d)",
3525 rinfo
->external_metric
);
3528 vty_out(vty
, "%*s", len
,
3533 vty_out(vty
, "%3" ROUTE_TAG_PRI
,
3534 (route_tag_t
)rinfo
->tag
);
3542 /* Vincent: formerly, it was show_ip_protocols_rip: "show ip protocols" */
3543 DEFUN (show_ip_rip_status
,
3544 show_ip_rip_status_cmd
,
3545 "show ip rip status",
3549 "IP routing protocol process parameters and statistics\n")
3551 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
3552 struct interface
*ifp
;
3553 struct rip_interface
*ri
;
3554 extern const struct message ri_version_msg
[];
3555 const char *send_version
;
3556 const char *receive_version
;
3561 vty_out(vty
, "Routing Protocol is \"rip\"\n");
3562 vty_out(vty
, " Sending updates every %ld seconds with +/-50%%,",
3564 vty_out(vty
, " next due in %lu seconds\n",
3565 thread_timer_remain_second(rip
->t_update
));
3566 vty_out(vty
, " Timeout after %ld seconds,", rip
->timeout_time
);
3567 vty_out(vty
, " garbage collect after %ld seconds\n", rip
->garbage_time
);
3569 /* Filtering status show. */
3570 config_show_distribute(vty
);
3572 /* Default metric information. */
3573 vty_out(vty
, " Default redistribution metric is %d\n",
3574 rip
->default_metric
);
3576 /* Redistribute information. */
3577 vty_out(vty
, " Redistributing:");
3578 config_write_rip_redistribute(vty
, 0);
3581 vty_out(vty
, " Default version control: send version %s,",
3582 lookup_msg(ri_version_msg
, rip
->version_send
, NULL
));
3583 if (rip
->version_recv
== RI_RIP_VERSION_1_AND_2
)
3584 vty_out(vty
, " receive any version \n");
3586 vty_out(vty
, " receive version %s \n",
3587 lookup_msg(ri_version_msg
, rip
->version_recv
, NULL
));
3589 vty_out(vty
, " Interface Send Recv Key-chain\n");
3591 FOR_ALL_INTERFACES (vrf
, ifp
) {
3597 if (ri
->enable_network
|| ri
->enable_interface
) {
3598 if (ri
->ri_send
== RI_RIP_UNSPEC
)
3600 lookup_msg(ri_version_msg
,
3601 rip
->version_send
, NULL
);
3603 send_version
= lookup_msg(ri_version_msg
,
3606 if (ri
->ri_receive
== RI_RIP_UNSPEC
)
3608 lookup_msg(ri_version_msg
,
3609 rip
->version_recv
, NULL
);
3611 receive_version
= lookup_msg(
3612 ri_version_msg
, ri
->ri_receive
, NULL
);
3614 vty_out(vty
, " %-17s%-3s %-3s %s\n", ifp
->name
,
3615 send_version
, receive_version
,
3616 ri
->key_chain
? ri
->key_chain
: "");
3620 vty_out(vty
, " Routing for Networks:\n");
3621 config_write_rip_network(vty
, 0);
3624 int found_passive
= 0;
3625 FOR_ALL_INTERFACES (vrf
, ifp
) {
3628 if ((ri
->enable_network
|| ri
->enable_interface
)
3630 if (!found_passive
) {
3632 " Passive Interface(s):\n");
3635 vty_out(vty
, " %s\n", ifp
->name
);
3640 vty_out(vty
, " Routing Information Sources:\n");
3642 " Gateway BadPackets BadRoutes Distance Last Update\n");
3643 rip_peer_display(vty
);
3645 rip_distance_show(vty
);
3650 /* RIP configuration write function. */
3651 static int config_write_rip(struct vty
*vty
)
3654 struct route_node
*rn
;
3655 struct rip_distance
*rdistance
;
3658 /* Router RIP statement. */
3659 vty_out(vty
, "router rip\n");
3662 /* RIP version statement. Default is RIP version 2. */
3663 if (rip
->version_send
!= RI_RIP_VERSION_2
3664 || rip
->version_recv
!= RI_RIP_VERSION_1_AND_2
)
3665 vty_out(vty
, " version %d\n", rip
->version_send
);
3667 /* RIP timer configuration. */
3668 if (rip
->update_time
!= RIP_UPDATE_TIMER_DEFAULT
3669 || rip
->timeout_time
!= RIP_TIMEOUT_TIMER_DEFAULT
3670 || rip
->garbage_time
!= RIP_GARBAGE_TIMER_DEFAULT
)
3671 vty_out(vty
, " timers basic %lu %lu %lu\n",
3672 rip
->update_time
, rip
->timeout_time
,
3675 /* Default information configuration. */
3676 if (rip
->default_information
) {
3677 if (rip
->default_information_route_map
)
3679 " default-information originate route-map %s\n",
3680 rip
->default_information_route_map
);
3683 " default-information originate\n");
3686 /* Redistribute configuration. */
3687 config_write_rip_redistribute(vty
, 1);
3689 /* RIP offset-list configuration. */
3690 config_write_rip_offset_list(vty
);
3692 /* RIP enabled network and interface configuration. */
3693 config_write_rip_network(vty
, 1);
3695 /* RIP default metric configuration */
3696 if (rip
->default_metric
!= RIP_DEFAULT_METRIC_DEFAULT
)
3697 vty_out(vty
, " default-metric %d\n",
3698 rip
->default_metric
);
3700 /* Distribute configuration. */
3701 write
+= config_write_distribute(vty
);
3703 /* Interface routemap configuration */
3704 write
+= config_write_if_rmap(vty
);
3706 /* Distance configuration. */
3708 vty_out(vty
, " distance %d\n", rip
->distance
);
3710 /* RIP source IP prefix distance configuration. */
3711 for (rn
= route_top(rip_distance_table
); rn
;
3712 rn
= route_next(rn
))
3713 if ((rdistance
= rn
->info
) != NULL
)
3714 vty_out(vty
, " distance %d %s/%d %s\n",
3715 rdistance
->distance
,
3716 inet_ntoa(rn
->p
.u
.prefix4
),
3718 rdistance
->access_list
3719 ? rdistance
->access_list
3722 /* ECMP configuration. */
3724 vty_out(vty
, " allow-ecmp\n");
3726 /* RIP static route configuration. */
3727 for (rn
= route_top(rip
->route
); rn
; rn
= route_next(rn
))
3729 vty_out(vty
, " route %s/%d\n",
3730 inet_ntoa(rn
->p
.u
.prefix4
),
3736 /* RIP node structure. */
3737 static struct cmd_node rip_node
= {RIP_NODE
, "%s(config-router)# ", 1};
3739 /* Distribute-list update functions. */
3740 static void rip_distribute_update(struct distribute
*dist
)
3742 struct interface
*ifp
;
3743 struct rip_interface
*ri
;
3744 struct access_list
*alist
;
3745 struct prefix_list
*plist
;
3750 ifp
= if_lookup_by_name(dist
->ifname
, VRF_DEFAULT
);
3756 if (dist
->list
[DISTRIBUTE_V4_IN
]) {
3757 alist
= access_list_lookup(AFI_IP
,
3758 dist
->list
[DISTRIBUTE_V4_IN
]);
3760 ri
->list
[RIP_FILTER_IN
] = alist
;
3762 ri
->list
[RIP_FILTER_IN
] = NULL
;
3764 ri
->list
[RIP_FILTER_IN
] = NULL
;
3766 if (dist
->list
[DISTRIBUTE_V4_OUT
]) {
3767 alist
= access_list_lookup(AFI_IP
,
3768 dist
->list
[DISTRIBUTE_V4_OUT
]);
3770 ri
->list
[RIP_FILTER_OUT
] = alist
;
3772 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3774 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3776 if (dist
->prefix
[DISTRIBUTE_V4_IN
]) {
3777 plist
= prefix_list_lookup(AFI_IP
,
3778 dist
->prefix
[DISTRIBUTE_V4_IN
]);
3780 ri
->prefix
[RIP_FILTER_IN
] = plist
;
3782 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3784 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3786 if (dist
->prefix
[DISTRIBUTE_V4_OUT
]) {
3787 plist
= prefix_list_lookup(AFI_IP
,
3788 dist
->prefix
[DISTRIBUTE_V4_OUT
]);
3790 ri
->prefix
[RIP_FILTER_OUT
] = plist
;
3792 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3794 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3797 void rip_distribute_update_interface(struct interface
*ifp
)
3799 struct distribute
*dist
;
3801 dist
= distribute_lookup(ifp
->name
);
3803 rip_distribute_update(dist
);
3806 /* Update all interface's distribute list. */
3808 static void rip_distribute_update_all(struct prefix_list
*notused
)
3810 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
3811 struct interface
*ifp
;
3813 FOR_ALL_INTERFACES (vrf
, ifp
)
3814 rip_distribute_update_interface(ifp
);
3817 static void rip_distribute_update_all_wrapper(struct access_list
*notused
)
3819 rip_distribute_update_all(NULL
);
3822 /* Delete all added rip route. */
3823 void rip_clean(void)
3826 struct route_node
*rp
;
3827 struct rip_info
*rinfo
= NULL
;
3828 struct list
*list
= NULL
;
3829 struct listnode
*listnode
= NULL
;
3834 /* Clear RIP routes */
3835 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
3836 if ((list
= rp
->info
) != NULL
) {
3837 rinfo
= listgetdata(listhead(list
));
3838 if (rip_route_rte(rinfo
))
3839 rip_zebra_ipv4_delete(rp
);
3841 for (ALL_LIST_ELEMENTS_RO(list
, listnode
,
3843 RIP_TIMER_OFF(rinfo
->t_timeout
);
3844 RIP_TIMER_OFF(rinfo
->t_garbage_collect
);
3845 rip_info_free(rinfo
);
3847 list_delete_and_null(&list
);
3849 route_unlock_node(rp
);
3852 /* Cancel RIP related timers. */
3853 RIP_TIMER_OFF(rip
->t_update
);
3854 RIP_TIMER_OFF(rip
->t_triggered_update
);
3855 RIP_TIMER_OFF(rip
->t_triggered_interval
);
3857 /* Cancel read thread. */
3858 THREAD_READ_OFF(rip
->t_read
);
3860 /* Close RIP socket. */
3861 if (rip
->sock
>= 0) {
3866 stream_free(rip
->obuf
);
3867 /* Static RIP route configuration. */
3868 for (rp
= route_top(rip
->route
); rp
; rp
= route_next(rp
))
3871 route_unlock_node(rp
);
3874 /* RIP neighbor configuration. */
3875 for (rp
= route_top(rip
->neighbor
); rp
; rp
= route_next(rp
))
3878 route_unlock_node(rp
);
3881 /* Redistribute related clear. */
3882 if (rip
->default_information_route_map
)
3883 free(rip
->default_information_route_map
);
3885 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
3886 if (rip
->route_map
[i
].name
)
3887 free(rip
->route_map
[i
].name
);
3889 XFREE(MTYPE_ROUTE_TABLE
, rip
->table
);
3890 XFREE(MTYPE_ROUTE_TABLE
, rip
->route
);
3891 XFREE(MTYPE_ROUTE_TABLE
, rip
->neighbor
);
3893 XFREE(MTYPE_RIP
, rip
);
3897 rip_clean_network();
3898 rip_passive_nondefault_clean();
3900 rip_interfaces_clean();
3901 rip_distance_reset();
3902 rip_redistribute_clean();
3905 /* Reset all values to the default settings. */
3906 void rip_reset(void)
3908 /* Reset global counters. */
3909 rip_global_route_changes
= 0;
3910 rip_global_queries
= 0;
3912 /* Call ripd related reset functions. */
3914 rip_route_map_reset();
3916 /* Call library reset functions. */
3918 access_list_reset();
3919 prefix_list_reset();
3921 distribute_list_reset();
3923 rip_interfaces_reset();
3924 rip_distance_reset();
3926 rip_zclient_reset();
3929 static void rip_if_rmap_update(struct if_rmap
*if_rmap
)
3931 struct interface
*ifp
;
3932 struct rip_interface
*ri
;
3933 struct route_map
*rmap
;
3935 ifp
= if_lookup_by_name(if_rmap
->ifname
, VRF_DEFAULT
);
3941 if (if_rmap
->routemap
[IF_RMAP_IN
]) {
3942 rmap
= route_map_lookup_by_name(if_rmap
->routemap
[IF_RMAP_IN
]);
3944 ri
->routemap
[IF_RMAP_IN
] = rmap
;
3946 ri
->routemap
[IF_RMAP_IN
] = NULL
;
3948 ri
->routemap
[RIP_FILTER_IN
] = NULL
;
3950 if (if_rmap
->routemap
[IF_RMAP_OUT
]) {
3951 rmap
= route_map_lookup_by_name(if_rmap
->routemap
[IF_RMAP_OUT
]);
3953 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
3955 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
3957 ri
->routemap
[RIP_FILTER_OUT
] = NULL
;
3960 void rip_if_rmap_update_interface(struct interface
*ifp
)
3962 struct if_rmap
*if_rmap
;
3964 if_rmap
= if_rmap_lookup(ifp
->name
);
3966 rip_if_rmap_update(if_rmap
);
3969 static void rip_routemap_update_redistribute(void)
3974 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3975 if (rip
->route_map
[i
].name
)
3976 rip
->route_map
[i
].map
=
3977 route_map_lookup_by_name(
3978 rip
->route_map
[i
].name
);
3984 static void rip_routemap_update(const char *notused
)
3986 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
3987 struct interface
*ifp
;
3989 FOR_ALL_INTERFACES (vrf
, ifp
)
3990 rip_if_rmap_update_interface(ifp
);
3992 rip_routemap_update_redistribute();
3995 /* Allocate new rip structure and set default value. */
3998 /* Install top nodes. */
3999 install_node(&rip_node
, config_write_rip
);
4001 /* Install rip commands. */
4002 install_element(VIEW_NODE
, &show_ip_rip_cmd
);
4003 install_element(VIEW_NODE
, &show_ip_rip_status_cmd
);
4004 install_element(CONFIG_NODE
, &router_rip_cmd
);
4005 install_element(CONFIG_NODE
, &no_router_rip_cmd
);
4007 install_default(RIP_NODE
);
4008 install_element(RIP_NODE
, &rip_version_cmd
);
4009 install_element(RIP_NODE
, &no_rip_version_cmd
);
4010 install_element(RIP_NODE
, &rip_default_metric_cmd
);
4011 install_element(RIP_NODE
, &no_rip_default_metric_cmd
);
4012 install_element(RIP_NODE
, &rip_timers_cmd
);
4013 install_element(RIP_NODE
, &no_rip_timers_cmd
);
4014 install_element(RIP_NODE
, &rip_route_cmd
);
4015 install_element(RIP_NODE
, &no_rip_route_cmd
);
4016 install_element(RIP_NODE
, &rip_distance_cmd
);
4017 install_element(RIP_NODE
, &no_rip_distance_cmd
);
4018 install_element(RIP_NODE
, &rip_distance_source_cmd
);
4019 install_element(RIP_NODE
, &no_rip_distance_source_cmd
);
4020 install_element(RIP_NODE
, &rip_distance_source_access_list_cmd
);
4021 install_element(RIP_NODE
, &no_rip_distance_source_access_list_cmd
);
4022 install_element(RIP_NODE
, &rip_allow_ecmp_cmd
);
4023 install_element(RIP_NODE
, &no_rip_allow_ecmp_cmd
);
4025 /* Debug related init. */
4028 /* Access list install. */
4030 access_list_add_hook(rip_distribute_update_all_wrapper
);
4031 access_list_delete_hook(rip_distribute_update_all_wrapper
);
4033 /* Prefix list initialize.*/
4035 prefix_list_add_hook(rip_distribute_update_all
);
4036 prefix_list_delete_hook(rip_distribute_update_all
);
4038 /* Distribute list install. */
4039 distribute_list_init(RIP_NODE
);
4040 distribute_list_add_hook(rip_distribute_update
);
4041 distribute_list_delete_hook(rip_distribute_update
);
4044 rip_route_map_init();
4047 route_map_add_hook(rip_routemap_update
);
4048 route_map_delete_hook(rip_routemap_update
);
4050 if_rmap_init(RIP_NODE
);
4051 if_rmap_hook_add(rip_if_rmap_update
);
4052 if_rmap_hook_delete(rip_if_rmap_update
);
4054 /* Distance control. */
4055 rip_distance_table
= route_table_init();