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"
44 #include "ripd/ripd.h"
45 #include "ripd/rip_debug.h"
49 /* UDP receive buffer size */
50 #define RIP_UDP_RCV_BUF 41600
52 /* privileges global */
53 extern struct zebra_privs_t ripd_privs
;
56 struct rip
*rip
= NULL
;
58 /* RIP neighbor address table. */
59 struct route_table
*rip_neighbor_table
;
61 /* RIP route changes. */
62 long rip_global_route_changes
= 0;
65 long rip_global_queries
= 0;
68 static void rip_event (enum rip_event
, int);
69 static void rip_output_process (struct connected
*, struct sockaddr_in
*, int, u_char
);
70 static int rip_triggered_update (struct thread
*);
71 static int rip_update_jitter (unsigned long);
73 /* RIP output routes type. */
80 /* RIP command strings. */
81 static const struct message rip_msg
[] =
83 {RIP_REQUEST
, "REQUEST"},
84 {RIP_RESPONSE
, "RESPONSE"},
85 {RIP_TRACEON
, "TRACEON"},
86 {RIP_TRACEOFF
, "TRACEOFF"},
88 {RIP_POLL_ENTRY
, "POLL ENTRY"},
92 /* Utility function to set boradcast option to the socket. */
94 sockopt_broadcast (int sock
)
99 ret
= setsockopt (sock
, SOL_SOCKET
, SO_BROADCAST
, (char *) &on
, sizeof on
);
102 zlog_warn ("can't set sockopt SO_BROADCAST to socket %d", sock
);
109 rip_route_rte (struct rip_info
*rinfo
)
111 return (rinfo
->type
== ZEBRA_ROUTE_RIP
&& rinfo
->sub_type
== RIP_ROUTE_RTE
);
114 static struct rip_info
*
117 return XCALLOC (MTYPE_RIP_INFO
, sizeof (struct rip_info
));
121 rip_info_free (struct rip_info
*rinfo
)
123 XFREE (MTYPE_RIP_INFO
, rinfo
);
126 /* RIP route garbage collect timer. */
128 rip_garbage_collect (struct thread
*t
)
130 struct rip_info
*rinfo
;
131 struct route_node
*rp
;
133 rinfo
= THREAD_ARG (t
);
134 rinfo
->t_garbage_collect
= NULL
;
136 /* Off timeout timer. */
137 RIP_TIMER_OFF (rinfo
->t_timeout
);
139 /* Get route_node pointer. */
142 /* Unlock route_node. */
143 listnode_delete (rp
->info
, rinfo
);
144 if (list_isempty ((struct list
*)rp
->info
))
146 list_free (rp
->info
);
148 route_unlock_node (rp
);
151 /* Free RIP routing information. */
152 rip_info_free (rinfo
);
157 static void rip_timeout_update (struct rip_info
*rinfo
);
159 /* Add new route to the ECMP list.
160 * RETURN: the new entry added in the list, or NULL if it is not the first
161 * entry and ECMP is not allowed.
164 rip_ecmp_add (struct rip_info
*rinfo_new
)
166 struct route_node
*rp
= rinfo_new
->rp
;
167 struct rip_info
*rinfo
= NULL
;
168 struct list
*list
= NULL
;
170 if (rp
->info
== NULL
)
171 rp
->info
= list_new ();
172 list
= (struct list
*)rp
->info
;
174 /* If ECMP is not allowed and some entry already exists in the list,
176 if (listcount (list
) && !rip
->ecmp
)
179 rinfo
= rip_info_new ();
180 memcpy (rinfo
, rinfo_new
, sizeof (struct rip_info
));
181 listnode_add (list
, rinfo
);
183 if (rip_route_rte (rinfo
))
185 rip_timeout_update (rinfo
);
186 rip_zebra_ipv4_add (rp
);
189 /* Set the route change flag on the first entry. */
190 rinfo
= listgetdata (listhead (list
));
191 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
193 /* Signal the output process to trigger an update (see section 2.5). */
194 rip_event (RIP_TRIGGERED_UPDATE
, 0);
199 /* Replace the ECMP list with the new route.
200 * RETURN: the new entry added in the list
203 rip_ecmp_replace (struct rip_info
*rinfo_new
)
205 struct route_node
*rp
= rinfo_new
->rp
;
206 struct list
*list
= (struct list
*)rp
->info
;
207 struct rip_info
*rinfo
= NULL
, *tmp_rinfo
= NULL
;
208 struct listnode
*node
= NULL
, *nextnode
= NULL
;
210 if (list
== NULL
|| listcount (list
) == 0)
211 return rip_ecmp_add (rinfo_new
);
213 /* Get the first entry */
214 rinfo
= listgetdata (listhead (list
));
216 /* Learnt route replaced by a local one. Delete it from zebra. */
217 if (rip_route_rte (rinfo
) && !rip_route_rte (rinfo_new
))
218 if (CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
))
219 rip_zebra_ipv4_delete (rp
);
221 /* Re-use the first entry, and delete the others. */
222 for (ALL_LIST_ELEMENTS (list
, node
, nextnode
, tmp_rinfo
))
223 if (tmp_rinfo
!= rinfo
)
225 RIP_TIMER_OFF (tmp_rinfo
->t_timeout
);
226 RIP_TIMER_OFF (tmp_rinfo
->t_garbage_collect
);
227 list_delete_node (list
, node
);
228 rip_info_free (tmp_rinfo
);
231 RIP_TIMER_OFF (rinfo
->t_timeout
);
232 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
233 memcpy (rinfo
, rinfo_new
, sizeof (struct rip_info
));
235 if (rip_route_rte (rinfo
))
237 rip_timeout_update (rinfo
);
238 /* The ADD message implies an update. */
239 rip_zebra_ipv4_add (rp
);
242 /* Set the route change flag. */
243 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
245 /* Signal the output process to trigger an update (see section 2.5). */
246 rip_event (RIP_TRIGGERED_UPDATE
, 0);
251 /* Delete one route from the ECMP list.
253 * null - the entry is freed, and other entries exist in the list
254 * the entry - the entry is the last one in the list; its metric is set
255 * to INFINITY, and the garbage collector is started for it
258 rip_ecmp_delete (struct rip_info
*rinfo
)
260 struct route_node
*rp
= rinfo
->rp
;
261 struct list
*list
= (struct list
*)rp
->info
;
263 RIP_TIMER_OFF (rinfo
->t_timeout
);
265 if (listcount (list
) > 1)
267 /* Some other ECMP entries still exist. Just delete this entry. */
268 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
269 listnode_delete (list
, rinfo
);
270 if (rip_route_rte (rinfo
) && CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
))
271 /* The ADD message implies the update. */
272 rip_zebra_ipv4_add (rp
);
273 rip_info_free (rinfo
);
278 assert (rinfo
== listgetdata (listhead (list
)));
280 /* This is the only entry left in the list. We must keep it in
281 * the list for garbage collection time, with INFINITY metric. */
283 rinfo
->metric
= RIP_METRIC_INFINITY
;
284 RIP_TIMER_ON (rinfo
->t_garbage_collect
,
285 rip_garbage_collect
, rip
->garbage_time
);
287 if (rip_route_rte (rinfo
) && CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
))
288 rip_zebra_ipv4_delete (rp
);
291 /* Set the route change flag on the first entry. */
292 rinfo
= listgetdata (listhead (list
));
293 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
295 /* Signal the output process to trigger an update (see section 2.5). */
296 rip_event (RIP_TRIGGERED_UPDATE
, 0);
301 /* Timeout RIP routes. */
303 rip_timeout (struct thread
*t
)
305 rip_ecmp_delete ((struct rip_info
*)THREAD_ARG (t
));
310 rip_timeout_update (struct rip_info
*rinfo
)
312 if (rinfo
->metric
!= RIP_METRIC_INFINITY
)
314 RIP_TIMER_OFF (rinfo
->t_timeout
);
315 RIP_TIMER_ON (rinfo
->t_timeout
, rip_timeout
, rip
->timeout_time
);
320 rip_filter (int rip_distribute
, struct prefix_ipv4
*p
, struct rip_interface
*ri
)
322 struct distribute
*dist
;
323 struct access_list
*alist
;
324 struct prefix_list
*plist
;
325 int distribute
= rip_distribute
== RIP_FILTER_OUT
?
326 DISTRIBUTE_V4_OUT
: DISTRIBUTE_V4_IN
;
327 const char *inout
= rip_distribute
== RIP_FILTER_OUT
? "out" : "in";
329 /* Input distribute-list filtering. */
330 if (ri
->list
[rip_distribute
])
332 if (access_list_apply (ri
->list
[rip_distribute
],
333 (struct prefix
*) p
) == FILTER_DENY
)
335 if (IS_RIP_DEBUG_PACKET
)
336 zlog_debug ("%s/%d filtered by distribute %s",
337 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
341 if (ri
->prefix
[rip_distribute
])
343 if (prefix_list_apply (ri
->prefix
[rip_distribute
],
344 (struct prefix
*) p
) == PREFIX_DENY
)
346 if (IS_RIP_DEBUG_PACKET
)
347 zlog_debug ("%s/%d filtered by prefix-list %s",
348 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
353 /* All interface filter check. */
354 dist
= distribute_lookup (NULL
);
357 if (dist
->list
[distribute
])
359 alist
= access_list_lookup (AFI_IP
, dist
->list
[distribute
]);
363 if (access_list_apply (alist
, (struct prefix
*) p
) == FILTER_DENY
)
365 if (IS_RIP_DEBUG_PACKET
)
366 zlog_debug ("%s/%d filtered by distribute %s",
367 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
372 if (dist
->prefix
[distribute
])
374 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[distribute
]);
378 if (prefix_list_apply (plist
,
379 (struct prefix
*) p
) == PREFIX_DENY
)
381 if (IS_RIP_DEBUG_PACKET
)
382 zlog_debug ("%s/%d filtered by prefix-list %s",
383 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
392 /* Check nexthop address validity. */
394 rip_nexthop_check (struct in_addr
*addr
)
396 struct listnode
*node
;
397 struct listnode
*cnode
;
398 struct interface
*ifp
;
399 struct connected
*ifc
;
402 /* If nexthop address matches local configured address then it is
405 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
407 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, ifc
))
411 if (p
->family
== AF_INET
412 && IPV4_ADDR_SAME (&p
->u
.prefix4
, addr
))
419 /* RIP add route to routing table. */
421 rip_rte_process (struct rte
*rte
, struct sockaddr_in
*from
,
422 struct interface
*ifp
)
425 struct prefix_ipv4 p
;
426 struct route_node
*rp
;
427 struct rip_info
*rinfo
= NULL
, newinfo
;
428 struct rip_interface
*ri
;
429 struct in_addr
*nexthop
;
431 unsigned char old_dist
, new_dist
;
432 struct list
*list
= NULL
;
433 struct listnode
*node
= NULL
;
435 /* Make prefix structure. */
436 memset (&p
, 0, sizeof (struct prefix_ipv4
));
438 p
.prefix
= rte
->prefix
;
439 p
.prefixlen
= ip_masklen (rte
->mask
);
441 /* Make sure mask is applied. */
442 apply_mask_ipv4 (&p
);
444 /* Apply input filters. */
447 ret
= rip_filter (RIP_FILTER_IN
, &p
, ri
);
451 memset (&newinfo
, 0, sizeof (newinfo
));
452 newinfo
.type
= ZEBRA_ROUTE_RIP
;
453 newinfo
.sub_type
= RIP_ROUTE_RTE
;
454 newinfo
.nexthop
= rte
->nexthop
;
455 newinfo
.from
= from
->sin_addr
;
456 newinfo
.ifindex
= ifp
->ifindex
;
457 newinfo
.metric
= rte
->metric
;
458 newinfo
.metric_out
= rte
->metric
; /* XXX */
459 newinfo
.tag
= ntohs (rte
->tag
); /* XXX */
461 /* Modify entry according to the interface routemap. */
462 if (ri
->routemap
[RIP_FILTER_IN
])
466 /* The object should be of the type of rip_info */
467 ret
= route_map_apply (ri
->routemap
[RIP_FILTER_IN
],
468 (struct prefix
*) &p
, RMAP_RIP
, &newinfo
);
470 if (ret
== RMAP_DENYMATCH
)
472 if (IS_RIP_DEBUG_PACKET
)
473 zlog_debug ("RIP %s/%d is filtered by route-map in",
474 inet_ntoa (p
.prefix
), p
.prefixlen
);
478 /* Get back the object */
479 rte
->nexthop
= newinfo
.nexthop_out
;
480 rte
->tag
= htons (newinfo
.tag_out
); /* XXX */
481 rte
->metric
= newinfo
.metric_out
; /* XXX: the routemap uses the metric_out field */
484 /* Once the entry has been validated, update the metric by
485 adding the cost of the network on wich the message
486 arrived. If the result is greater than infinity, use infinity
487 (RFC2453 Sec. 3.9.2) */
488 /* Zebra ripd can handle offset-list in. */
489 ret
= rip_offset_list_apply_in (&p
, ifp
, &rte
->metric
);
491 /* If offset-list does not modify the metric use interface's
494 rte
->metric
+= ifp
->metric
? ifp
->metric
: 1;
496 if (rte
->metric
> RIP_METRIC_INFINITY
)
497 rte
->metric
= RIP_METRIC_INFINITY
;
499 /* Set nexthop pointer. */
500 if (rte
->nexthop
.s_addr
== 0)
501 nexthop
= &from
->sin_addr
;
503 nexthop
= &rte
->nexthop
;
505 /* Check if nexthop address is myself, then do nothing. */
506 if (rip_nexthop_check (nexthop
) < 0)
508 if (IS_RIP_DEBUG_PACKET
)
509 zlog_debug ("Nexthop address %s is myself", inet_ntoa (*nexthop
));
513 /* Get index for the prefix. */
514 rp
= route_node_get (rip
->table
, (struct prefix
*) &p
);
517 newinfo
.nexthop
= *nexthop
;
518 newinfo
.metric
= rte
->metric
;
519 newinfo
.tag
= ntohs (rte
->tag
);
520 newinfo
.distance
= rip_distance_apply (&newinfo
);
522 new_dist
= newinfo
.distance
? newinfo
.distance
: ZEBRA_RIP_DISTANCE_DEFAULT
;
524 /* Check to see whether there is already RIP route on the table. */
525 if ((list
= rp
->info
) != NULL
)
526 for (ALL_LIST_ELEMENTS_RO (list
, node
, rinfo
))
528 /* Need to compare with redistributed entry or local entry */
529 if (!rip_route_rte (rinfo
))
532 if (IPV4_ADDR_SAME (&rinfo
->from
, &from
->sin_addr
) &&
533 IPV4_ADDR_SAME (&rinfo
->nexthop
, nexthop
))
536 if (!listnextnode (node
))
538 /* Not found in the list */
540 if (rte
->metric
> rinfo
->metric
)
542 /* New route has a greater metric. Discard it. */
543 route_unlock_node (rp
);
547 if (rte
->metric
< rinfo
->metric
)
548 /* New route has a smaller metric. Replace the ECMP list
549 * with the new one in below. */
552 /* Metrics are same. We compare the distances. */
553 old_dist
= rinfo
->distance
? \
554 rinfo
->distance
: ZEBRA_RIP_DISTANCE_DEFAULT
;
556 if (new_dist
> old_dist
)
558 /* New route has a greater distance. Discard it. */
559 route_unlock_node (rp
);
563 if (new_dist
< old_dist
)
564 /* New route has a smaller distance. Replace the ECMP list
565 * with the new one in below. */
568 /* Metrics and distances are both same. Keep "rinfo" null and
569 * the new route is added in the ECMP list in below. */
575 /* Local static route. */
576 if (rinfo
->type
== ZEBRA_ROUTE_RIP
577 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
) ||
578 (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
))
579 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
581 route_unlock_node (rp
);
585 /* Redistributed route check. */
586 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
587 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
589 old_dist
= rinfo
->distance
;
590 /* Only routes directly connected to an interface (nexthop == 0)
591 * may have a valid NULL distance */
592 if (rinfo
->nexthop
.s_addr
!= 0)
593 old_dist
= old_dist
? old_dist
: ZEBRA_RIP_DISTANCE_DEFAULT
;
594 /* If imported route does not have STRICT precedence,
595 mark it as a ghost */
596 if (new_dist
<= old_dist
&& rte
->metric
!= RIP_METRIC_INFINITY
)
597 rip_ecmp_replace (&newinfo
);
599 route_unlock_node (rp
);
607 route_unlock_node (rp
);
609 /* Now, check to see whether there is already an explicit route
610 for the destination prefix. If there is no such route, add
611 this route to the routing table, unless the metric is
612 infinity (there is no point in adding a route which
614 if (rte
->metric
!= RIP_METRIC_INFINITY
)
615 rip_ecmp_add (&newinfo
);
619 /* Route is there but we are not sure the route is RIP or not. */
621 /* If there is an existing route, compare the next hop address
622 to the address of the router from which the datagram came.
623 If this datagram is from the same router as the existing
624 route, reinitialize the timeout. */
625 same
= (IPV4_ADDR_SAME (&rinfo
->from
, &from
->sin_addr
)
626 && (rinfo
->ifindex
== ifp
->ifindex
));
628 old_dist
= rinfo
->distance
? \
629 rinfo
->distance
: ZEBRA_RIP_DISTANCE_DEFAULT
;
631 /* Next, compare the metrics. If the datagram is from the same
632 router as the existing route, and the new metric is different
633 than the old one; or, if the new metric is lower than the old
634 one, or if the tag has been changed; or if there is a route
635 with a lower administrave distance; or an update of the
636 distance on the actual route; do the following actions: */
637 if ((same
&& rinfo
->metric
!= rte
->metric
)
638 || (rte
->metric
< rinfo
->metric
)
640 && (rinfo
->metric
== rte
->metric
)
641 && (newinfo
.tag
!= rinfo
->tag
))
642 || (old_dist
> new_dist
)
643 || ((old_dist
!= new_dist
) && same
))
645 if (listcount (list
) == 1)
647 if (newinfo
.metric
!= RIP_METRIC_INFINITY
)
648 rip_ecmp_replace (&newinfo
);
650 rip_ecmp_delete (rinfo
);
654 if (newinfo
.metric
< rinfo
->metric
)
655 rip_ecmp_replace (&newinfo
);
656 else if (newinfo
.metric
> rinfo
->metric
)
657 rip_ecmp_delete (rinfo
);
658 else if (new_dist
< old_dist
)
659 rip_ecmp_replace (&newinfo
);
660 else if (new_dist
> old_dist
)
661 rip_ecmp_delete (rinfo
);
664 int update
= CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
) ? 1 : 0;
666 assert (newinfo
.metric
!= RIP_METRIC_INFINITY
);
668 RIP_TIMER_OFF (rinfo
->t_timeout
);
669 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
670 memcpy (rinfo
, &newinfo
, sizeof (struct rip_info
));
671 rip_timeout_update (rinfo
);
674 rip_zebra_ipv4_add (rp
);
676 /* - Set the route change flag on the first entry. */
677 rinfo
= listgetdata (listhead (list
));
678 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
679 rip_event (RIP_TRIGGERED_UPDATE
, 0);
683 else /* same & no change */
684 rip_timeout_update (rinfo
);
686 /* Unlock tempolary lock of the route. */
687 route_unlock_node (rp
);
691 /* Dump RIP packet */
693 rip_packet_dump (struct rip_packet
*packet
, int size
, const char *sndrcv
)
697 const char *command_str
;
698 char pbuf
[BUFSIZ
], nbuf
[BUFSIZ
];
702 /* Set command string. */
703 if (packet
->command
> 0 && packet
->command
< RIP_COMMAND_MAX
)
704 command_str
= lookup (rip_msg
, packet
->command
);
706 command_str
= "unknown";
708 /* Dump packet header. */
709 zlog_debug ("%s %s version %d packet size %d",
710 sndrcv
, command_str
, packet
->version
, size
);
712 /* Dump each routing table entry. */
715 for (lim
= (caddr_t
) packet
+ size
; (caddr_t
) rte
< lim
; rte
++)
717 if (packet
->version
== RIPv2
)
719 netmask
= ip_masklen (rte
->mask
);
721 if (rte
->family
== htons (RIP_FAMILY_AUTH
))
723 if (rte
->tag
== htons (RIP_AUTH_SIMPLE_PASSWORD
))
725 p
= (u_char
*)&rte
->prefix
;
727 zlog_debug (" family 0x%X type %d auth string: %s",
728 ntohs (rte
->family
), ntohs (rte
->tag
), p
);
730 else if (rte
->tag
== htons (RIP_AUTH_MD5
))
732 struct rip_md5_info
*md5
;
734 md5
= (struct rip_md5_info
*) &packet
->rte
;
736 zlog_debug (" family 0x%X type %d (MD5 authentication)",
737 ntohs (md5
->family
), ntohs (md5
->type
));
738 zlog_debug (" RIP-2 packet len %d Key ID %d"
740 ntohs (md5
->packet_len
), md5
->keyid
,
742 zlog_debug (" Sequence Number %ld",
743 (u_long
) ntohl (md5
->sequence
));
745 else if (rte
->tag
== htons (RIP_AUTH_DATA
))
747 p
= (u_char
*)&rte
->prefix
;
749 zlog_debug (" family 0x%X type %d (MD5 data)",
750 ntohs (rte
->family
), ntohs (rte
->tag
));
751 zlog_debug (" MD5: %02X%02X%02X%02X%02X%02X%02X%02X"
752 "%02X%02X%02X%02X%02X%02X%02X%02X",
753 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6],
754 p
[7], p
[8], p
[9], p
[10], p
[11], p
[12], p
[13],
759 zlog_debug (" family 0x%X type %d (Unknown auth type)",
760 ntohs (rte
->family
), ntohs (rte
->tag
));
764 zlog_debug (" %s/%d -> %s family %d tag %"ROUTE_TAG_PRI
" metric %ld",
765 inet_ntop (AF_INET
, &rte
->prefix
, pbuf
, BUFSIZ
),
766 netmask
, inet_ntop (AF_INET
, &rte
->nexthop
, nbuf
,
767 BUFSIZ
), ntohs (rte
->family
),
768 (route_tag_t
)ntohs (rte
->tag
),
769 (u_long
) ntohl (rte
->metric
));
773 zlog_debug (" %s family %d tag %"ROUTE_TAG_PRI
" metric %ld",
774 inet_ntop (AF_INET
, &rte
->prefix
, pbuf
, BUFSIZ
),
775 ntohs (rte
->family
), (route_tag_t
)ntohs (rte
->tag
),
776 (u_long
)ntohl (rte
->metric
));
781 /* Check if the destination address is valid (unicast; not net 0
782 or 127) (RFC2453 Section 3.9.2 - Page 26). But we don't
783 check net 0 because we accept default route. */
785 rip_destination_check (struct in_addr addr
)
787 u_int32_t destination
;
789 /* Convert to host byte order. */
790 destination
= ntohl (addr
.s_addr
);
792 if (IPV4_NET127 (destination
))
795 /* Net 0 may match to the default route. */
796 if (IPV4_NET0 (destination
) && destination
!= 0)
799 /* Unicast address must belong to class A, B, C. */
800 if (IN_CLASSA (destination
))
802 if (IN_CLASSB (destination
))
804 if (IN_CLASSC (destination
))
810 /* RIP version 2 authentication. */
812 rip_auth_simple_password (struct rte
*rte
, struct sockaddr_in
*from
,
813 struct interface
*ifp
)
815 struct rip_interface
*ri
;
816 char *auth_str
= (char *) &rte
->prefix
;
819 /* reject passwords with zeros in the middle of the string */
820 for (i
= strlen (auth_str
); i
< 16; i
++)
822 if (auth_str
[i
] != '\0')
826 if (IS_RIP_DEBUG_EVENT
)
827 zlog_debug ("RIPv2 simple password authentication from %s",
828 inet_ntoa (from
->sin_addr
));
832 if (ri
->auth_type
!= RIP_AUTH_SIMPLE_PASSWORD
833 || rte
->tag
!= htons(RIP_AUTH_SIMPLE_PASSWORD
))
836 /* Simple password authentication. */
839 if (strncmp (auth_str
, ri
->auth_str
, 16) == 0)
844 struct keychain
*keychain
;
847 keychain
= keychain_lookup (ri
->key_chain
);
848 if (keychain
== NULL
)
851 key
= key_match_for_accept (keychain
, auth_str
);
858 /* RIP version 2 authentication with MD5. */
860 rip_auth_md5 (struct rip_packet
*packet
, struct sockaddr_in
*from
,
861 int length
, struct interface
*ifp
)
863 struct rip_interface
*ri
;
864 struct rip_md5_info
*md5
;
865 struct rip_md5_data
*md5data
;
866 struct keychain
*keychain
;
869 u_char digest
[RIP_AUTH_MD5_SIZE
];
870 u_int16_t packet_len
;
871 char auth_str
[RIP_AUTH_MD5_SIZE
];
873 if (IS_RIP_DEBUG_EVENT
)
874 zlog_debug ("RIPv2 MD5 authentication from %s",
875 inet_ntoa (from
->sin_addr
));
878 md5
= (struct rip_md5_info
*) &packet
->rte
;
880 /* Check auth type. */
881 if (ri
->auth_type
!= RIP_AUTH_MD5
|| md5
->type
!= htons(RIP_AUTH_MD5
))
884 /* If the authentication length is less than 16, then it must be wrong for
885 * any interpretation of rfc2082. Some implementations also interpret
886 * this as RIP_HEADER_SIZE+ RIP_AUTH_MD5_SIZE, aka RIP_AUTH_MD5_COMPAT_SIZE.
888 if ( !((md5
->auth_len
== RIP_AUTH_MD5_SIZE
)
889 || (md5
->auth_len
== RIP_AUTH_MD5_COMPAT_SIZE
)))
891 if (IS_RIP_DEBUG_EVENT
)
892 zlog_debug ("RIPv2 MD5 authentication, strange authentication "
893 "length field %d", md5
->auth_len
);
897 /* grab and verify check packet length */
898 packet_len
= ntohs (md5
->packet_len
);
900 if (packet_len
> (length
- RIP_HEADER_SIZE
- RIP_AUTH_MD5_SIZE
))
902 if (IS_RIP_DEBUG_EVENT
)
903 zlog_debug ("RIPv2 MD5 authentication, packet length field %d "
904 "greater than received length %d!",
905 md5
->packet_len
, length
);
909 /* retrieve authentication data */
910 md5data
= (struct rip_md5_data
*) (((u_char
*) packet
) + packet_len
);
912 memset (auth_str
, 0, RIP_AUTH_MD5_SIZE
);
916 keychain
= keychain_lookup (ri
->key_chain
);
917 if (keychain
== NULL
)
920 key
= key_lookup_for_accept (keychain
, md5
->keyid
);
924 strncpy (auth_str
, key
->string
, RIP_AUTH_MD5_SIZE
);
926 else if (ri
->auth_str
)
927 strncpy (auth_str
, ri
->auth_str
, RIP_AUTH_MD5_SIZE
);
929 if (auth_str
[0] == 0)
932 /* MD5 digest authentication. */
933 memset (&ctx
, 0, sizeof(ctx
));
935 MD5Update(&ctx
, packet
, packet_len
+ RIP_HEADER_SIZE
);
936 MD5Update(&ctx
, auth_str
, RIP_AUTH_MD5_SIZE
);
937 MD5Final(digest
, &ctx
);
939 if (memcmp (md5data
->digest
, digest
, RIP_AUTH_MD5_SIZE
) == 0)
945 /* Pick correct auth string for sends, prepare auth_str buffer for use.
946 * (left justified and padded).
948 * presumes one of ri or key is valid, and that the auth strings they point
949 * to are nul terminated. If neither are present, auth_str will be fully
954 rip_auth_prepare_str_send (struct rip_interface
*ri
, struct key
*key
,
955 char *auth_str
, int len
)
959 memset (auth_str
, 0, len
);
960 if (key
&& key
->string
)
961 strncpy (auth_str
, key
->string
, len
);
962 else if (ri
->auth_str
)
963 strncpy (auth_str
, ri
->auth_str
, len
);
968 /* Write RIPv2 simple password authentication information
970 * auth_str is presumed to be 2 bytes and correctly prepared
971 * (left justified and zero padded).
974 rip_auth_simple_write (struct stream
*s
, char *auth_str
, int len
)
976 assert (s
&& len
== RIP_AUTH_SIMPLE_SIZE
);
978 stream_putw (s
, RIP_FAMILY_AUTH
);
979 stream_putw (s
, RIP_AUTH_SIMPLE_PASSWORD
);
980 stream_put (s
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
985 /* write RIPv2 MD5 "authentication header"
986 * (uses the auth key data field)
988 * Digest offset field is set to 0.
990 * returns: offset of the digest offset field, which must be set when
991 * length to the auth-data MD5 digest is known.
994 rip_auth_md5_ah_write (struct stream
*s
, struct rip_interface
*ri
,
999 assert (s
&& ri
&& ri
->auth_type
== RIP_AUTH_MD5
);
1001 /* MD5 authentication. */
1002 stream_putw (s
, RIP_FAMILY_AUTH
);
1003 stream_putw (s
, RIP_AUTH_MD5
);
1005 /* MD5 AH digest offset field.
1007 * Set to placeholder value here, to true value when RIP-2 Packet length
1008 * is known. Actual value is set in .....().
1010 doff
= stream_get_endp(s
);
1015 stream_putc (s
, key
->index
% 256);
1019 /* Auth Data Len. Set 16 for MD5 authentication data. Older ripds
1020 * however expect RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE so we allow for this
1021 * to be configurable.
1023 stream_putc (s
, ri
->md5_auth_len
);
1025 /* Sequence Number (non-decreasing). */
1026 /* RFC2080: The value used in the sequence number is
1027 arbitrary, but two suggestions are the time of the
1028 message's creation or a simple message counter. */
1029 stream_putl (s
, time (NULL
));
1031 /* Reserved field must be zero. */
1038 /* If authentication is in used, write the appropriate header
1039 * returns stream offset to which length must later be written
1040 * or 0 if this is not required
1043 rip_auth_header_write (struct stream
*s
, struct rip_interface
*ri
,
1044 struct key
*key
, char *auth_str
, int len
)
1046 assert (ri
->auth_type
!= RIP_NO_AUTH
);
1048 switch (ri
->auth_type
)
1050 case RIP_AUTH_SIMPLE_PASSWORD
:
1051 rip_auth_prepare_str_send (ri
, key
, auth_str
, len
);
1052 rip_auth_simple_write (s
, auth_str
, len
);
1055 return rip_auth_md5_ah_write (s
, ri
, key
);
1061 /* Write RIPv2 MD5 authentication data trailer */
1063 rip_auth_md5_set (struct stream
*s
, struct rip_interface
*ri
, size_t doff
,
1064 char *auth_str
, int authlen
)
1068 unsigned char digest
[RIP_AUTH_MD5_SIZE
];
1070 /* Make it sure this interface is configured as MD5
1072 assert ((ri
->auth_type
== RIP_AUTH_MD5
) && (authlen
== RIP_AUTH_MD5_SIZE
));
1075 /* Get packet length. */
1076 len
= stream_get_endp(s
);
1078 /* Check packet length. */
1079 if (len
< (RIP_HEADER_SIZE
+ RIP_RTE_SIZE
))
1081 zlog_err ("rip_auth_md5_set(): packet length %ld is less than minimum length.", len
);
1085 /* Set the digest offset length in the header */
1086 stream_putw_at (s
, doff
, len
);
1088 /* Set authentication data. */
1089 stream_putw (s
, RIP_FAMILY_AUTH
);
1090 stream_putw (s
, RIP_AUTH_DATA
);
1092 /* Generate a digest for the RIP packet. */
1093 memset(&ctx
, 0, sizeof(ctx
));
1095 MD5Update(&ctx
, STREAM_DATA (s
), stream_get_endp (s
));
1096 MD5Update(&ctx
, auth_str
, RIP_AUTH_MD5_SIZE
);
1097 MD5Final(digest
, &ctx
);
1099 /* Copy the digest to the packet. */
1100 stream_write (s
, digest
, RIP_AUTH_MD5_SIZE
);
1103 /* RIP routing information. */
1105 rip_response_process (struct rip_packet
*packet
, int size
,
1106 struct sockaddr_in
*from
, struct connected
*ifc
)
1110 struct prefix_ipv4 ifaddr
;
1111 struct prefix_ipv4 ifaddrclass
;
1114 memset(&ifaddr
, 0, sizeof(ifaddr
));
1115 /* We don't know yet. */
1118 /* The Response must be ignored if it is not from the RIP
1119 port. (RFC2453 - Sec. 3.9.2)*/
1120 if (from
->sin_port
!= htons(RIP_PORT_DEFAULT
))
1122 zlog_info ("response doesn't come from RIP port: %d",
1124 rip_peer_bad_packet (from
);
1128 /* The datagram's IPv4 source address should be checked to see
1129 whether the datagram is from a valid neighbor; the source of the
1130 datagram must be on a directly connected network (RFC2453 - Sec. 3.9.2) */
1131 if (if_lookup_address((void *)&from
->sin_addr
, AF_INET
, VRF_DEFAULT
) == NULL
)
1133 zlog_info ("This datagram doesn't came from a valid neighbor: %s",
1134 inet_ntoa (from
->sin_addr
));
1135 rip_peer_bad_packet (from
);
1139 /* It is also worth checking to see whether the response is from one
1140 of the router's own addresses. */
1142 ; /* Alredy done in rip_read () */
1144 /* Update RIP peer. */
1145 rip_peer_update (from
, packet
->version
);
1147 /* Set RTE pointer. */
1150 for (lim
= (caddr_t
) packet
+ size
; (caddr_t
) rte
< lim
; rte
++)
1152 /* RIPv2 authentication check. */
1153 /* If the Address Family Identifier of the first (and only the
1154 first) entry in the message is 0xFFFF, then the remainder of
1155 the entry contains the authentication. */
1156 /* If the packet gets here it means authentication enabled */
1157 /* Check is done in rip_read(). So, just skipping it */
1158 if (packet
->version
== RIPv2
&&
1159 rte
== packet
->rte
&&
1160 rte
->family
== htons(RIP_FAMILY_AUTH
))
1163 if (rte
->family
!= htons(AF_INET
))
1165 /* Address family check. RIP only supports AF_INET. */
1166 zlog_info ("Unsupported family %d from %s.",
1167 ntohs (rte
->family
), inet_ntoa (from
->sin_addr
));
1171 /* - is the destination address valid (e.g., unicast; not net 0
1173 if (! rip_destination_check (rte
->prefix
))
1175 zlog_info ("Network is net 0 or net 127 or it is not unicast network");
1176 rip_peer_bad_route (from
);
1180 /* Convert metric value to host byte order. */
1181 rte
->metric
= ntohl (rte
->metric
);
1183 /* - is the metric valid (i.e., between 1 and 16, inclusive) */
1184 if (! (rte
->metric
>= 1 && rte
->metric
<= 16))
1186 zlog_info ("Route's metric is not in the 1-16 range.");
1187 rip_peer_bad_route (from
);
1191 /* RIPv1 does not have nexthop value. */
1192 if (packet
->version
== RIPv1
&& rte
->nexthop
.s_addr
!= 0)
1194 zlog_info ("RIPv1 packet with nexthop value %s",
1195 inet_ntoa (rte
->nexthop
));
1196 rip_peer_bad_route (from
);
1200 /* That is, if the provided information is ignored, a possibly
1201 sub-optimal, but absolutely valid, route may be taken. If
1202 the received Next Hop is not directly reachable, it should be
1203 treated as 0.0.0.0. */
1204 if (packet
->version
== RIPv2
&& rte
->nexthop
.s_addr
!= 0)
1208 /* Multicast address check. */
1209 addrval
= ntohl (rte
->nexthop
.s_addr
);
1210 if (IN_CLASSD (addrval
))
1212 zlog_info ("Nexthop %s is multicast address, skip this rte",
1213 inet_ntoa (rte
->nexthop
));
1217 if (! if_lookup_address ((void *)&rte
->nexthop
, AF_INET
, VRF_DEFAULT
))
1219 struct route_node
*rn
;
1220 struct rip_info
*rinfo
;
1222 rn
= route_node_match_ipv4 (rip
->table
, &rte
->nexthop
);
1228 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1229 && rinfo
->sub_type
== RIP_ROUTE_RTE
)
1231 if (IS_RIP_DEBUG_EVENT
)
1232 zlog_debug ("Next hop %s is on RIP network. Set nexthop to the packet's originator", inet_ntoa (rte
->nexthop
));
1233 rte
->nexthop
= rinfo
->from
;
1237 if (IS_RIP_DEBUG_EVENT
)
1238 zlog_debug ("Next hop %s is not directly reachable. Treat it as 0.0.0.0", inet_ntoa (rte
->nexthop
));
1239 rte
->nexthop
.s_addr
= 0;
1242 route_unlock_node (rn
);
1246 if (IS_RIP_DEBUG_EVENT
)
1247 zlog_debug ("Next hop %s is not directly reachable. Treat it as 0.0.0.0", inet_ntoa (rte
->nexthop
));
1248 rte
->nexthop
.s_addr
= 0;
1254 /* For RIPv1, there won't be a valid netmask.
1256 This is a best guess at the masks. If everyone was using old
1257 Ciscos before the 'ip subnet zero' option, it would be almost
1260 Cisco summarize ripv1 advertisments to the classful boundary
1261 (/16 for class B's) except when the RIP packet does to inside
1262 the classful network in question. */
1264 if ((packet
->version
== RIPv1
&& rte
->prefix
.s_addr
!= 0)
1265 || (packet
->version
== RIPv2
1266 && (rte
->prefix
.s_addr
!= 0 && rte
->mask
.s_addr
== 0)))
1268 u_int32_t destination
;
1270 if (subnetted
== -1)
1272 memcpy (&ifaddr
, ifc
->address
, sizeof (struct prefix_ipv4
));
1273 memcpy (&ifaddrclass
, &ifaddr
, sizeof (struct prefix_ipv4
));
1274 apply_classful_mask_ipv4 (&ifaddrclass
);
1276 if (ifaddr
.prefixlen
> ifaddrclass
.prefixlen
)
1280 destination
= ntohl (rte
->prefix
.s_addr
);
1282 if (IN_CLASSA (destination
))
1283 masklen2ip (8, &rte
->mask
);
1284 else if (IN_CLASSB (destination
))
1285 masklen2ip (16, &rte
->mask
);
1286 else if (IN_CLASSC (destination
))
1287 masklen2ip (24, &rte
->mask
);
1290 masklen2ip (ifaddrclass
.prefixlen
,
1291 (struct in_addr
*) &destination
);
1292 if ((subnetted
== 1) && ((rte
->prefix
.s_addr
& destination
) ==
1293 ifaddrclass
.prefix
.s_addr
))
1295 masklen2ip (ifaddr
.prefixlen
, &rte
->mask
);
1296 if ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
) != rte
->prefix
.s_addr
)
1297 masklen2ip (32, &rte
->mask
);
1298 if (IS_RIP_DEBUG_EVENT
)
1299 zlog_debug ("Subnetted route %s", inet_ntoa (rte
->prefix
));
1303 if ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
) != rte
->prefix
.s_addr
)
1307 if (IS_RIP_DEBUG_EVENT
)
1309 zlog_debug ("Resultant route %s", inet_ntoa (rte
->prefix
));
1310 zlog_debug ("Resultant mask %s", inet_ntoa (rte
->mask
));
1314 /* In case of RIPv2, if prefix in RTE is not netmask applied one
1315 ignore the entry. */
1316 if ((packet
->version
== RIPv2
)
1317 && (rte
->mask
.s_addr
!= 0)
1318 && ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
) != rte
->prefix
.s_addr
))
1320 zlog_warn ("RIPv2 address %s is not mask /%d applied one",
1321 inet_ntoa (rte
->prefix
), ip_masklen (rte
->mask
));
1322 rip_peer_bad_route (from
);
1326 /* Default route's netmask is ignored. */
1327 if (packet
->version
== RIPv2
1328 && (rte
->prefix
.s_addr
== 0)
1329 && (rte
->mask
.s_addr
!= 0))
1331 if (IS_RIP_DEBUG_EVENT
)
1332 zlog_debug ("Default route with non-zero netmask. Set zero to netmask");
1333 rte
->mask
.s_addr
= 0;
1336 /* Routing table updates. */
1337 rip_rte_process (rte
, from
, ifc
->ifp
);
1341 /* Make socket for RIP protocol. */
1343 rip_create_socket (void)
1347 struct sockaddr_in addr
;
1349 memset (&addr
, 0, sizeof (struct sockaddr_in
));
1350 addr
.sin_family
= AF_INET
;
1351 addr
.sin_addr
.s_addr
= INADDR_ANY
;
1352 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1353 addr
.sin_len
= sizeof (struct sockaddr_in
);
1354 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1355 /* sending port must always be the RIP port */
1356 addr
.sin_port
= htons (RIP_PORT_DEFAULT
);
1358 /* Make datagram socket. */
1359 sock
= socket (AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
1362 zlog_err("Cannot create UDP socket: %s", safe_strerror(errno
));
1366 sockopt_broadcast (sock
);
1367 sockopt_reuseaddr (sock
);
1368 sockopt_reuseport (sock
);
1369 setsockopt_ipv4_multicast_loop (sock
, 0);
1371 setsockopt_pktinfo (sock
);
1372 #endif /* RIP_RECVMSG */
1373 #ifdef IPTOS_PREC_INTERNETCONTROL
1374 setsockopt_ipv4_tos (sock
, IPTOS_PREC_INTERNETCONTROL
);
1377 if (ripd_privs
.change (ZPRIVS_RAISE
))
1378 zlog_err ("rip_create_socket: could not raise privs");
1379 setsockopt_so_recvbuf (sock
, RIP_UDP_RCV_BUF
);
1380 if ( (ret
= bind (sock
, (struct sockaddr
*) & addr
, sizeof (addr
))) < 0)
1383 int save_errno
= errno
;
1384 if (ripd_privs
.change (ZPRIVS_LOWER
))
1385 zlog_err ("rip_create_socket: could not lower privs");
1387 zlog_err("%s: Can't bind socket %d to %s port %d: %s", __func__
,
1388 sock
, inet_ntoa(addr
.sin_addr
),
1389 (int) ntohs(addr
.sin_port
),
1390 safe_strerror(save_errno
));
1396 if (ripd_privs
.change (ZPRIVS_LOWER
))
1397 zlog_err ("rip_create_socket: could not lower privs");
1402 /* RIP packet send to destination address, on interface denoted by
1403 * by connected argument. NULL to argument denotes destination should be
1404 * should be RIP multicast group
1407 rip_send_packet (u_char
* buf
, int size
, struct sockaddr_in
*to
,
1408 struct connected
*ifc
)
1411 struct sockaddr_in sin
;
1413 assert (ifc
!= NULL
);
1415 if (IS_RIP_DEBUG_PACKET
)
1417 #define ADDRESS_SIZE 20
1418 char dst
[ADDRESS_SIZE
];
1419 dst
[ADDRESS_SIZE
- 1] = '\0';
1423 strncpy (dst
, inet_ntoa(to
->sin_addr
), ADDRESS_SIZE
- 1);
1427 sin
.sin_addr
.s_addr
= htonl (INADDR_RIP_GROUP
);
1428 strncpy (dst
, inet_ntoa(sin
.sin_addr
), ADDRESS_SIZE
- 1);
1431 zlog_debug("rip_send_packet %s > %s (%s)",
1432 inet_ntoa(ifc
->address
->u
.prefix4
),
1433 dst
, ifc
->ifp
->name
);
1436 if ( CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
) )
1439 * ZEBRA_IFA_SECONDARY is set on linux when an interface is configured
1440 * with multiple addresses on the same subnet: the first address
1441 * on the subnet is configured "primary", and all subsequent addresses
1442 * on that subnet are treated as "secondary" addresses.
1443 * In order to avoid routing-table bloat on other rip listeners,
1444 * we do not send out RIP packets with ZEBRA_IFA_SECONDARY source addrs.
1445 * XXX Since Linux is the only system for which the ZEBRA_IFA_SECONDARY
1446 * flag is set, we would end up sending a packet for a "secondary"
1447 * source address on non-linux systems.
1449 if (IS_RIP_DEBUG_PACKET
)
1450 zlog_debug("duplicate dropped");
1454 /* Make destination address. */
1455 memset (&sin
, 0, sizeof (struct sockaddr_in
));
1456 sin
.sin_family
= AF_INET
;
1457 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1458 sin
.sin_len
= sizeof (struct sockaddr_in
);
1459 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1461 /* When destination is specified, use it's port and address. */
1464 sin
.sin_port
= to
->sin_port
;
1465 sin
.sin_addr
= to
->sin_addr
;
1469 sin
.sin_port
= htons (RIP_PORT_DEFAULT
);
1470 sin
.sin_addr
.s_addr
= htonl (INADDR_RIP_GROUP
);
1472 rip_interface_multicast_set (rip
->sock
, ifc
);
1475 ret
= sendto (rip
->sock
, buf
, size
, 0, (struct sockaddr
*)&sin
,
1476 sizeof (struct sockaddr_in
));
1478 if (IS_RIP_DEBUG_EVENT
)
1479 zlog_debug ("SEND to %s.%d", inet_ntoa(sin
.sin_addr
),
1480 ntohs (sin
.sin_port
));
1483 zlog_warn ("can't send packet : %s", safe_strerror (errno
));
1488 /* Add redistributed route to RIP table. */
1490 rip_redistribute_add (int type
, int sub_type
, struct prefix_ipv4
*p
,
1491 ifindex_t ifindex
, struct in_addr
*nexthop
,
1492 unsigned int metric
, unsigned char distance
,
1496 struct route_node
*rp
= NULL
;
1497 struct rip_info
*rinfo
= NULL
, newinfo
;
1498 struct list
*list
= NULL
;
1500 /* Redistribute route */
1501 ret
= rip_destination_check (p
->prefix
);
1505 rp
= route_node_get (rip
->table
, (struct prefix
*) p
);
1507 memset (&newinfo
, 0, sizeof (struct rip_info
));
1508 newinfo
.type
= type
;
1509 newinfo
.sub_type
= sub_type
;
1510 newinfo
.ifindex
= ifindex
;
1512 newinfo
.external_metric
= metric
;
1513 newinfo
.distance
= distance
;
1514 if (tag
<= UINT16_MAX
) /* RIP only supports 16 bit tags */
1518 newinfo
.nexthop
= *nexthop
;
1520 if ((list
= rp
->info
) != NULL
&& listcount (list
) != 0)
1522 rinfo
= listgetdata (listhead (list
));
1524 if (rinfo
->type
== ZEBRA_ROUTE_CONNECT
1525 && rinfo
->sub_type
== RIP_ROUTE_INTERFACE
1526 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
1528 route_unlock_node (rp
);
1532 /* Manually configured RIP route check. */
1533 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1534 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
) ||
1535 (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
)) )
1537 if (type
!= ZEBRA_ROUTE_RIP
|| ((sub_type
!= RIP_ROUTE_STATIC
) &&
1538 (sub_type
!= RIP_ROUTE_DEFAULT
)))
1540 route_unlock_node (rp
);
1545 rinfo
= rip_ecmp_replace (&newinfo
);
1546 route_unlock_node (rp
);
1549 rinfo
= rip_ecmp_add (&newinfo
);
1551 if (IS_RIP_DEBUG_EVENT
) {
1553 zlog_debug ("Redistribute new prefix %s/%d on the interface %s",
1554 inet_ntoa(p
->prefix
), p
->prefixlen
,
1555 ifindex2ifname(ifindex
, VRF_DEFAULT
));
1557 zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
1558 inet_ntoa(p
->prefix
), p
->prefixlen
, inet_ntoa(rinfo
->nexthop
),
1559 ifindex2ifname(ifindex
, VRF_DEFAULT
));
1562 rip_event (RIP_TRIGGERED_UPDATE
, 0);
1565 /* Delete redistributed route from RIP table. */
1567 rip_redistribute_delete (int type
, int sub_type
, struct prefix_ipv4
*p
,
1571 struct route_node
*rp
;
1572 struct rip_info
*rinfo
;
1574 ret
= rip_destination_check (p
->prefix
);
1578 rp
= route_node_lookup (rip
->table
, (struct prefix
*) p
);
1581 struct list
*list
= rp
->info
;
1583 if (list
!= NULL
&& listcount (list
) != 0)
1585 rinfo
= listgetdata (listhead (list
));
1587 && rinfo
->type
== type
1588 && rinfo
->sub_type
== sub_type
1589 && rinfo
->ifindex
== ifindex
)
1591 /* Perform poisoned reverse. */
1592 rinfo
->metric
= RIP_METRIC_INFINITY
;
1593 RIP_TIMER_ON (rinfo
->t_garbage_collect
,
1594 rip_garbage_collect
, rip
->garbage_time
);
1595 RIP_TIMER_OFF (rinfo
->t_timeout
);
1596 rinfo
->flags
|= RIP_RTF_CHANGED
;
1598 if (IS_RIP_DEBUG_EVENT
)
1599 zlog_debug ("Poisone %s/%d on the interface %s with an "
1600 "infinity metric [delete]",
1601 inet_ntoa(p
->prefix
), p
->prefixlen
,
1602 ifindex2ifname(ifindex
, VRF_DEFAULT
));
1604 rip_event (RIP_TRIGGERED_UPDATE
, 0);
1607 route_unlock_node (rp
);
1611 /* Response to request called from rip_read ().*/
1613 rip_request_process (struct rip_packet
*packet
, int size
,
1614 struct sockaddr_in
*from
, struct connected
*ifc
)
1618 struct prefix_ipv4 p
;
1619 struct route_node
*rp
;
1620 struct rip_info
*rinfo
;
1621 struct rip_interface
*ri
;
1623 /* Does not reponse to the requests on the loopback interfaces */
1624 if (if_is_loopback (ifc
->ifp
))
1627 /* Check RIP process is enabled on this interface. */
1628 ri
= ifc
->ifp
->info
;
1632 /* When passive interface is specified, suppress responses */
1636 /* RIP peer update. */
1637 rip_peer_update (from
, packet
->version
);
1639 lim
= ((caddr_t
) packet
) + size
;
1642 /* The Request is processed entry by entry. If there are no
1643 entries, no response is given. */
1644 if (lim
== (caddr_t
) rte
)
1647 /* There is one special case. If there is exactly one entry in the
1648 request, and it has an address family identifier of zero and a
1649 metric of infinity (i.e., 16), then this is a request to send the
1650 entire routing table. */
1651 if (lim
== ((caddr_t
) (rte
+ 1)) &&
1652 ntohs (rte
->family
) == 0 &&
1653 ntohl (rte
->metric
) == RIP_METRIC_INFINITY
)
1655 /* All route with split horizon */
1656 rip_output_process (ifc
, from
, rip_all_route
, packet
->version
);
1660 if (ntohs (rte
->family
) != AF_INET
)
1663 /* Examine the list of RTEs in the Request one by one. For each
1664 entry, look up the destination in the router's routing
1665 database and, if there is a route, put that route's metric in
1666 the metric field of the RTE. If there is no explicit route
1667 to the specified destination, put infinity in the metric
1668 field. Once all the entries have been filled in, change the
1669 command from Request to Response and send the datagram back
1670 to the requestor. */
1673 for (; ((caddr_t
) rte
) < lim
; rte
++)
1675 p
.prefix
= rte
->prefix
;
1676 p
.prefixlen
= ip_masklen (rte
->mask
);
1677 apply_mask_ipv4 (&p
);
1679 rp
= route_node_lookup (rip
->table
, (struct prefix
*) &p
);
1682 rinfo
= listgetdata (listhead ((struct list
*)rp
->info
));
1683 rte
->metric
= htonl (rinfo
->metric
);
1684 route_unlock_node (rp
);
1687 rte
->metric
= htonl (RIP_METRIC_INFINITY
);
1689 packet
->command
= RIP_RESPONSE
;
1691 rip_send_packet ((u_char
*)packet
, size
, from
, ifc
);
1693 rip_global_queries
++;
1697 /* Set IPv6 packet info to the socket. */
1699 setsockopt_pktinfo (int sock
)
1704 ret
= setsockopt(sock
, IPPROTO_IP
, IP_PKTINFO
, &val
, sizeof(val
));
1706 zlog_warn ("Can't setsockopt IP_PKTINFO : %s", safe_strerror (errno
));
1710 /* Read RIP packet by recvmsg function. */
1712 rip_recvmsg (int sock
, u_char
*buf
, int size
, struct sockaddr_in
*from
,
1718 struct cmsghdr
*ptr
;
1721 msg
.msg_name
= (void *) from
;
1722 msg
.msg_namelen
= sizeof (struct sockaddr_in
);
1725 msg
.msg_control
= (void *) adata
;
1726 msg
.msg_controllen
= sizeof adata
;
1730 ret
= recvmsg (sock
, &msg
, 0);
1734 for (ptr
= ZCMSG_FIRSTHDR(&msg
); ptr
!= NULL
; ptr
= CMSG_NXTHDR(&msg
, ptr
))
1735 if (ptr
->cmsg_level
== IPPROTO_IP
&& ptr
->cmsg_type
== IP_PKTINFO
)
1737 struct in_pktinfo
*pktinfo
;
1740 pktinfo
= (struct in_pktinfo
*) CMSG_DATA (ptr
);
1741 i
= pktinfo
->ipi_ifindex
;
1746 /* RIP packet read function. */
1748 rip_read_new (struct thread
*t
)
1752 char buf
[RIP_PACKET_MAXSIZ
];
1753 struct sockaddr_in from
;
1756 /* Fetch socket then register myself. */
1757 sock
= THREAD_FD (t
);
1758 rip_event (RIP_READ
, sock
);
1760 /* Read RIP packet. */
1761 ret
= rip_recvmsg (sock
, buf
, RIP_PACKET_MAXSIZ
, &from
, (int *)&ifindex
);
1764 zlog_warn ("Can't read RIP packet: %s", safe_strerror (errno
));
1770 #endif /* RIP_RECVMSG */
1772 /* First entry point of RIP packet. */
1774 rip_read (struct thread
*t
)
1779 union rip_buf rip_buf
;
1780 struct rip_packet
*packet
;
1781 struct sockaddr_in from
;
1785 struct interface
*ifp
= NULL
;
1786 struct connected
*ifc
;
1787 struct rip_interface
*ri
;
1790 /* Fetch socket then register myself. */
1791 sock
= THREAD_FD (t
);
1794 /* Add myself to tne next event */
1795 rip_event (RIP_READ
, sock
);
1797 /* RIPd manages only IPv4. */
1798 memset (&from
, 0, sizeof (struct sockaddr_in
));
1799 fromlen
= sizeof (struct sockaddr_in
);
1801 len
= recvfrom (sock
, (char *)&rip_buf
.buf
, sizeof (rip_buf
.buf
), 0,
1802 (struct sockaddr
*) &from
, &fromlen
);
1805 zlog_info ("recvfrom failed: %s", safe_strerror (errno
));
1809 /* Check is this packet comming from myself? */
1810 if (if_check_address (from
.sin_addr
))
1812 if (IS_RIP_DEBUG_PACKET
)
1813 zlog_debug ("ignore packet comes from myself");
1817 /* Which interface is this packet comes from. */
1818 ifc
= if_lookup_address ((void *)&from
.sin_addr
, AF_INET
, VRF_DEFAULT
);
1822 /* RIP packet received */
1823 if (IS_RIP_DEBUG_EVENT
)
1824 zlog_debug ("RECV packet from %s port %d on %s",
1825 inet_ntoa (from
.sin_addr
), ntohs (from
.sin_port
),
1826 ifp
? ifp
->name
: "unknown");
1828 /* If this packet come from unknown interface, ignore it. */
1831 zlog_info ("rip_read: cannot find interface for packet from %s port %d",
1832 inet_ntoa(from
.sin_addr
), ntohs (from
.sin_port
));
1837 p
.u
.prefix4
= from
.sin_addr
;
1838 p
.prefixlen
= IPV4_MAX_BITLEN
;
1840 ifc
= connected_lookup_prefix (ifp
, &p
);
1844 zlog_info ("rip_read: cannot find connected address for packet from %s "
1845 "port %d on interface %s",
1846 inet_ntoa(from
.sin_addr
), ntohs (from
.sin_port
), ifp
->name
);
1850 /* Packet length check. */
1851 if (len
< RIP_PACKET_MINSIZ
)
1853 zlog_warn ("packet size %d is smaller than minimum size %d",
1854 len
, RIP_PACKET_MINSIZ
);
1855 rip_peer_bad_packet (&from
);
1858 if (len
> RIP_PACKET_MAXSIZ
)
1860 zlog_warn ("packet size %d is larger than max size %d",
1861 len
, RIP_PACKET_MAXSIZ
);
1862 rip_peer_bad_packet (&from
);
1866 /* Packet alignment check. */
1867 if ((len
- RIP_PACKET_MINSIZ
) % 20)
1869 zlog_warn ("packet size %d is wrong for RIP packet alignment", len
);
1870 rip_peer_bad_packet (&from
);
1874 /* Set RTE number. */
1875 rtenum
= ((len
- RIP_PACKET_MINSIZ
) / 20);
1877 /* For easy to handle. */
1878 packet
= &rip_buf
.rip_packet
;
1880 /* RIP version check. */
1881 if (packet
->version
== 0)
1883 zlog_info ("version 0 with command %d received.", packet
->command
);
1884 rip_peer_bad_packet (&from
);
1888 /* Dump RIP packet. */
1889 if (IS_RIP_DEBUG_RECV
)
1890 rip_packet_dump (packet
, len
, "RECV");
1892 /* RIP version adjust. This code should rethink now. RFC1058 says
1893 that "Version 1 implementations are to ignore this extra data and
1894 process only the fields specified in this document.". So RIPv3
1895 packet should be treated as RIPv1 ignoring must be zero field. */
1896 if (packet
->version
> RIPv2
)
1897 packet
->version
= RIPv2
;
1899 /* Is RIP running or is this RIP neighbor ?*/
1901 if (! ri
->running
&& ! rip_neighbor_lookup (&from
))
1903 if (IS_RIP_DEBUG_EVENT
)
1904 zlog_debug ("RIP is not enabled on interface %s.", ifp
->name
);
1905 rip_peer_bad_packet (&from
);
1909 /* RIP Version check. RFC2453, 4.6 and 5.1 */
1910 vrecv
= ((ri
->ri_receive
== RI_RIP_UNSPEC
) ?
1911 rip
->version_recv
: ri
->ri_receive
);
1912 if (vrecv
== RI_RIP_VERSION_NONE
||
1913 ((packet
->version
== RIPv1
) && !(vrecv
& RIPv1
)) ||
1914 ((packet
->version
== RIPv2
) && !(vrecv
& RIPv2
)))
1916 if (IS_RIP_DEBUG_PACKET
)
1917 zlog_debug (" packet's v%d doesn't fit to if version spec",
1919 rip_peer_bad_packet (&from
);
1923 /* RFC2453 5.2 If the router is not configured to authenticate RIP-2
1924 messages, then RIP-1 and unauthenticated RIP-2 messages will be
1925 accepted; authenticated RIP-2 messages shall be discarded. */
1926 if ((ri
->auth_type
== RIP_NO_AUTH
)
1928 && (packet
->version
== RIPv2
)
1929 && (packet
->rte
->family
== htons(RIP_FAMILY_AUTH
)))
1931 if (IS_RIP_DEBUG_EVENT
)
1932 zlog_debug ("packet RIPv%d is dropped because authentication disabled",
1934 rip_peer_bad_packet (&from
);
1939 If the router is configured to authenticate RIP-2 messages, then
1940 RIP-1 messages and RIP-2 messages which pass authentication
1941 testing shall be accepted; unauthenticated and failed
1942 authentication RIP-2 messages shall be discarded. For maximum
1943 security, RIP-1 messages should be ignored when authentication is
1944 in use (see section 4.1); otherwise, the routing information from
1945 authenticated messages will be propagated by RIP-1 routers in an
1946 unauthenticated manner.
1948 /* We make an exception for RIPv1 REQUEST packets, to which we'll
1949 * always reply regardless of authentication settings, because:
1951 * - if there other authorised routers on-link, the REQUESTor can
1952 * passively obtain the routing updates anyway
1953 * - if there are no other authorised routers on-link, RIP can
1954 * easily be disabled for the link to prevent giving out information
1955 * on state of this routers RIP routing table..
1957 * I.e. if RIPv1 has any place anymore these days, it's as a very
1958 * simple way to distribute routing information (e.g. to embedded
1959 * hosts / appliances) and the ability to give out RIPv1
1960 * routing-information freely, while still requiring RIPv2
1961 * authentication for any RESPONSEs might be vaguely useful.
1963 if (ri
->auth_type
!= RIP_NO_AUTH
1964 && packet
->version
== RIPv1
)
1966 /* Discard RIPv1 messages other than REQUESTs */
1967 if (packet
->command
!= RIP_REQUEST
)
1969 if (IS_RIP_DEBUG_PACKET
)
1970 zlog_debug ("RIPv1" " dropped because authentication enabled");
1971 rip_peer_bad_packet (&from
);
1975 else if (ri
->auth_type
!= RIP_NO_AUTH
)
1977 const char *auth_desc
;
1981 /* There definitely is no authentication in the packet. */
1982 if (IS_RIP_DEBUG_PACKET
)
1983 zlog_debug ("RIPv2 authentication failed: no auth RTE in packet");
1984 rip_peer_bad_packet (&from
);
1988 /* First RTE must be an Authentication Family RTE */
1989 if (packet
->rte
->family
!= htons(RIP_FAMILY_AUTH
))
1991 if (IS_RIP_DEBUG_PACKET
)
1992 zlog_debug ("RIPv2" " dropped because authentication enabled");
1993 rip_peer_bad_packet (&from
);
1997 /* Check RIPv2 authentication. */
1998 switch (ntohs(packet
->rte
->tag
))
2000 case RIP_AUTH_SIMPLE_PASSWORD
:
2001 auth_desc
= "simple";
2002 ret
= rip_auth_simple_password (packet
->rte
, &from
, ifp
);
2007 ret
= rip_auth_md5 (packet
, &from
, len
, ifp
);
2008 /* Reset RIP packet length to trim MD5 data. */
2014 auth_desc
= "unknown type";
2015 if (IS_RIP_DEBUG_PACKET
)
2016 zlog_debug ("RIPv2 Unknown authentication type %d",
2017 ntohs (packet
->rte
->tag
));
2022 if (IS_RIP_DEBUG_PACKET
)
2023 zlog_debug ("RIPv2 %s authentication success", auth_desc
);
2027 if (IS_RIP_DEBUG_PACKET
)
2028 zlog_debug ("RIPv2 %s authentication failure", auth_desc
);
2029 rip_peer_bad_packet (&from
);
2034 /* Process each command. */
2035 switch (packet
->command
)
2038 rip_response_process (packet
, len
, &from
, ifc
);
2042 rip_request_process (packet
, len
, &from
, ifc
);
2046 zlog_info ("Obsolete command %s received, please sent it to routed",
2047 lookup (rip_msg
, packet
->command
));
2048 rip_peer_bad_packet (&from
);
2050 case RIP_POLL_ENTRY
:
2051 zlog_info ("Obsolete command %s received",
2052 lookup (rip_msg
, packet
->command
));
2053 rip_peer_bad_packet (&from
);
2056 zlog_info ("Unknown RIP command %d received", packet
->command
);
2057 rip_peer_bad_packet (&from
);
2064 /* Write routing table entry to the stream and return next index of
2065 the routing table entry in the stream. */
2067 rip_write_rte (int num
, struct stream
*s
, struct prefix_ipv4
*p
,
2068 u_char version
, struct rip_info
*rinfo
)
2070 struct in_addr mask
;
2072 /* Write routing table entry. */
2073 if (version
== RIPv1
)
2075 stream_putw (s
, AF_INET
);
2077 stream_put_ipv4 (s
, p
->prefix
.s_addr
);
2078 stream_put_ipv4 (s
, 0);
2079 stream_put_ipv4 (s
, 0);
2080 stream_putl (s
, rinfo
->metric_out
);
2084 masklen2ip (p
->prefixlen
, &mask
);
2086 stream_putw (s
, AF_INET
);
2087 stream_putw (s
, rinfo
->tag_out
);
2088 stream_put_ipv4 (s
, p
->prefix
.s_addr
);
2089 stream_put_ipv4 (s
, mask
.s_addr
);
2090 stream_put_ipv4 (s
, rinfo
->nexthop_out
.s_addr
);
2091 stream_putl (s
, rinfo
->metric_out
);
2097 /* Send update to the ifp or spcified neighbor. */
2099 rip_output_process (struct connected
*ifc
, struct sockaddr_in
*to
,
2100 int route_type
, u_char version
)
2104 struct route_node
*rp
;
2105 struct rip_info
*rinfo
;
2106 struct rip_interface
*ri
;
2107 struct prefix_ipv4
*p
;
2108 struct prefix_ipv4 classfull
;
2109 struct prefix_ipv4 ifaddrclass
;
2110 struct key
*key
= NULL
;
2111 /* this might need to made dynamic if RIP ever supported auth methods
2112 with larger key string sizes */
2113 char auth_str
[RIP_AUTH_SIMPLE_SIZE
];
2114 size_t doff
= 0; /* offset of digest offset field */
2118 struct list
*list
= NULL
;
2119 struct listnode
*listnode
= NULL
;
2121 /* Logging output event. */
2122 if (IS_RIP_DEBUG_EVENT
)
2125 zlog_debug ("update routes to neighbor %s", inet_ntoa (to
->sin_addr
));
2127 zlog_debug ("update routes on interface %s ifindex %d",
2128 ifc
->ifp
->name
, ifc
->ifp
->ifindex
);
2131 /* Set output stream. */
2134 /* Reset stream and RTE counter. */
2136 rtemax
= RIP_MAX_RTE
;
2138 /* Get RIP interface. */
2139 ri
= ifc
->ifp
->info
;
2141 /* If output interface is in simple password authentication mode, we
2142 need space for authentication data. */
2143 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
2146 /* If output interface is in MD5 authentication mode, we need space
2147 for authentication header and data. */
2148 if (ri
->auth_type
== RIP_AUTH_MD5
)
2151 /* If output interface is in simple password authentication mode
2152 and string or keychain is specified we need space for auth. data */
2153 if (ri
->auth_type
!= RIP_NO_AUTH
)
2157 struct keychain
*keychain
;
2159 keychain
= keychain_lookup (ri
->key_chain
);
2161 key
= key_lookup_for_send (keychain
);
2163 /* to be passed to auth functions later */
2164 rip_auth_prepare_str_send (ri
, key
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
2167 if (version
== RIPv1
)
2169 memcpy (&ifaddrclass
, ifc
->address
, sizeof (struct prefix_ipv4
));
2170 apply_classful_mask_ipv4 (&ifaddrclass
);
2172 if (ifc
->address
->prefixlen
> ifaddrclass
.prefixlen
)
2176 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2177 if ((list
= rp
->info
) != NULL
&& listcount (list
) != 0)
2179 rinfo
= listgetdata (listhead (list
));
2180 /* For RIPv1, if we are subnetted, output subnets in our network */
2181 /* that have the same mask as the output "interface". For other */
2182 /* networks, only the classfull version is output. */
2184 if (version
== RIPv1
)
2186 p
= (struct prefix_ipv4
*) &rp
->p
;
2188 if (IS_RIP_DEBUG_PACKET
)
2189 zlog_debug("RIPv1 mask check, %s/%d considered for output",
2190 inet_ntoa (rp
->p
.u
.prefix4
), rp
->p
.prefixlen
);
2193 prefix_match ((struct prefix
*) &ifaddrclass
, &rp
->p
))
2195 if ((ifc
->address
->prefixlen
!= rp
->p
.prefixlen
) &&
2196 (rp
->p
.prefixlen
!= 32))
2201 memcpy (&classfull
, &rp
->p
, sizeof(struct prefix_ipv4
));
2202 apply_classful_mask_ipv4(&classfull
);
2203 if (rp
->p
.u
.prefix4
.s_addr
!= 0 &&
2204 classfull
.prefixlen
!= rp
->p
.prefixlen
)
2207 if (IS_RIP_DEBUG_PACKET
)
2208 zlog_debug("RIPv1 mask check, %s/%d made it through",
2209 inet_ntoa (rp
->p
.u
.prefix4
), rp
->p
.prefixlen
);
2212 p
= (struct prefix_ipv4
*) &rp
->p
;
2214 /* Apply output filters. */
2215 ret
= rip_filter (RIP_FILTER_OUT
, p
, ri
);
2219 /* Changed route only output. */
2220 if (route_type
== rip_changed_route
&&
2221 (! (rinfo
->flags
& RIP_RTF_CHANGED
)))
2224 /* Split horizon. */
2225 /* if (split_horizon == rip_split_horizon) */
2226 if (ri
->split_horizon
== RIP_SPLIT_HORIZON
)
2229 * We perform split horizon for RIP and connected route.
2230 * For rip routes, we want to suppress the route if we would
2231 * end up sending the route back on the interface that we
2232 * learned it from, with a higher metric. For connected routes,
2233 * we suppress the route if the prefix is a subset of the
2234 * source address that we are going to use for the packet
2235 * (in order to handle the case when multiple subnets are
2236 * configured on the same interface).
2239 struct rip_info
*tmp_rinfo
= NULL
;
2241 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, tmp_rinfo
))
2242 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
&&
2243 tmp_rinfo
->ifindex
== ifc
->ifp
->ifindex
)
2249 if (!suppress
&& rinfo
->type
== ZEBRA_ROUTE_CONNECT
&&
2250 prefix_match((struct prefix
*)p
, ifc
->address
))
2257 /* Preparation for route-map. */
2258 rinfo
->metric_set
= 0;
2259 rinfo
->nexthop_out
.s_addr
= 0;
2260 rinfo
->metric_out
= rinfo
->metric
;
2261 rinfo
->tag_out
= rinfo
->tag
;
2262 rinfo
->ifindex_out
= ifc
->ifp
->ifindex
;
2264 /* In order to avoid some local loops,
2265 * if the RIP route has a nexthop via this interface, keep the nexthop,
2266 * otherwise set it to 0. The nexthop should not be propagated
2267 * beyond the local broadcast/multicast area in order
2268 * to avoid an IGP multi-level recursive look-up.
2271 if (rinfo
->ifindex
== ifc
->ifp
->ifindex
)
2272 rinfo
->nexthop_out
= rinfo
->nexthop
;
2274 /* Interface route-map */
2275 if (ri
->routemap
[RIP_FILTER_OUT
])
2277 ret
= route_map_apply (ri
->routemap
[RIP_FILTER_OUT
],
2278 (struct prefix
*) p
, RMAP_RIP
,
2281 if (ret
== RMAP_DENYMATCH
)
2283 if (IS_RIP_DEBUG_PACKET
)
2284 zlog_debug ("RIP %s/%d is filtered by route-map out",
2285 inet_ntoa (p
->prefix
), p
->prefixlen
);
2290 /* Apply redistribute route map - continue, if deny */
2291 if (rip
->route_map
[rinfo
->type
].name
2292 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
)
2294 ret
= route_map_apply (rip
->route_map
[rinfo
->type
].map
,
2295 (struct prefix
*)p
, RMAP_RIP
, rinfo
);
2297 if (ret
== RMAP_DENYMATCH
)
2299 if (IS_RIP_DEBUG_PACKET
)
2300 zlog_debug ("%s/%d is filtered by route-map",
2301 inet_ntoa (p
->prefix
), p
->prefixlen
);
2306 /* When route-map does not set metric. */
2307 if (! rinfo
->metric_set
)
2309 /* If redistribute metric is set. */
2310 if (rip
->route_map
[rinfo
->type
].metric_config
2311 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
2313 rinfo
->metric_out
= rip
->route_map
[rinfo
->type
].metric
;
2317 /* If the route is not connected or localy generated
2318 one, use default-metric value*/
2319 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
2320 && rinfo
->type
!= ZEBRA_ROUTE_CONNECT
2321 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
2322 rinfo
->metric_out
= rip
->default_metric
;
2326 /* Apply offset-list */
2327 if (rinfo
->metric
!= RIP_METRIC_INFINITY
)
2328 rip_offset_list_apply_out (p
, ifc
->ifp
, &rinfo
->metric_out
);
2330 if (rinfo
->metric_out
> RIP_METRIC_INFINITY
)
2331 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2333 /* Perform split-horizon with poisoned reverse
2334 * for RIP and connected routes.
2336 if (ri
->split_horizon
== RIP_SPLIT_HORIZON_POISONED_REVERSE
) {
2338 * We perform split horizon for RIP and connected route.
2339 * For rip routes, we want to suppress the route if we would
2340 * end up sending the route back on the interface that we
2341 * learned it from, with a higher metric. For connected routes,
2342 * we suppress the route if the prefix is a subset of the
2343 * source address that we are going to use for the packet
2344 * (in order to handle the case when multiple subnets are
2345 * configured on the same interface).
2347 struct rip_info
*tmp_rinfo
= NULL
;
2349 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, tmp_rinfo
))
2350 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
&&
2351 tmp_rinfo
->ifindex
== ifc
->ifp
->ifindex
)
2352 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2353 if (tmp_rinfo
->type
== ZEBRA_ROUTE_CONNECT
&&
2354 prefix_match((struct prefix
*)p
, ifc
->address
))
2355 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2358 /* Prepare preamble, auth headers, if needs be */
2361 stream_putc (s
, RIP_RESPONSE
);
2362 stream_putc (s
, version
);
2365 /* auth header for !v1 && !no_auth */
2366 if ( (ri
->auth_type
!= RIP_NO_AUTH
) && (version
!= RIPv1
) )
2367 doff
= rip_auth_header_write (s
, ri
, key
, auth_str
,
2368 RIP_AUTH_SIMPLE_SIZE
);
2371 /* Write RTE to the stream. */
2372 num
= rip_write_rte (num
, s
, p
, version
, rinfo
);
2375 if (version
== RIPv2
&& ri
->auth_type
== RIP_AUTH_MD5
)
2376 rip_auth_md5_set (s
, ri
, doff
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
2378 ret
= rip_send_packet (STREAM_DATA (s
), stream_get_endp (s
),
2381 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2382 rip_packet_dump ((struct rip_packet
*)STREAM_DATA (s
),
2383 stream_get_endp(s
), "SEND");
2389 /* Flush unwritten RTE. */
2392 if (version
== RIPv2
&& ri
->auth_type
== RIP_AUTH_MD5
)
2393 rip_auth_md5_set (s
, ri
, doff
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
2395 ret
= rip_send_packet (STREAM_DATA (s
), stream_get_endp (s
), to
, ifc
);
2397 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2398 rip_packet_dump ((struct rip_packet
*)STREAM_DATA (s
),
2399 stream_get_endp (s
), "SEND");
2403 /* Statistics updates. */
2407 /* Send RIP packet to the interface. */
2409 rip_update_interface (struct connected
*ifc
, u_char version
, int route_type
)
2411 struct interface
*ifp
= ifc
->ifp
;
2412 struct rip_interface
*ri
= ifp
->info
;
2413 struct sockaddr_in to
;
2415 /* When RIP version is 2 and multicast enable interface. */
2416 if (version
== RIPv2
&& !ri
->v2_broadcast
&& if_is_multicast (ifp
))
2418 if (IS_RIP_DEBUG_EVENT
)
2419 zlog_debug ("multicast announce on %s ", ifp
->name
);
2421 rip_output_process (ifc
, NULL
, route_type
, version
);
2425 /* If we can't send multicast packet, send it with unicast. */
2426 if (if_is_broadcast (ifp
) || if_is_pointopoint (ifp
))
2428 if (ifc
->address
->family
== AF_INET
)
2430 /* Destination address and port setting. */
2431 memset (&to
, 0, sizeof (struct sockaddr_in
));
2432 if (ifc
->destination
)
2433 /* use specified broadcast or peer destination addr */
2434 to
.sin_addr
= ifc
->destination
->u
.prefix4
;
2435 else if (ifc
->address
->prefixlen
< IPV4_MAX_PREFIXLEN
)
2436 /* calculate the appropriate broadcast address */
2437 to
.sin_addr
.s_addr
=
2438 ipv4_broadcast_addr(ifc
->address
->u
.prefix4
.s_addr
,
2439 ifc
->address
->prefixlen
);
2441 /* do not know where to send the packet */
2443 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
2445 if (IS_RIP_DEBUG_EVENT
)
2446 zlog_debug("%s announce to %s on %s",
2447 CONNECTED_PEER(ifc
) ? "unicast" : "broadcast",
2448 inet_ntoa (to
.sin_addr
), ifp
->name
);
2450 rip_output_process (ifc
, &to
, route_type
, version
);
2455 /* Update send to all interface and neighbor. */
2457 rip_update_process (int route_type
)
2459 struct listnode
*node
;
2460 struct listnode
*ifnode
, *ifnnode
;
2461 struct connected
*connected
;
2462 struct interface
*ifp
;
2463 struct rip_interface
*ri
;
2464 struct route_node
*rp
;
2465 struct sockaddr_in to
;
2468 /* Send RIP update to each interface. */
2469 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
2471 if (if_is_loopback (ifp
))
2474 if (! if_is_operative (ifp
))
2477 /* Fetch RIP interface information. */
2480 /* When passive interface is specified, suppress announce to the
2488 * If there is no version configuration in the interface,
2489 * use rip's version setting.
2491 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
) ?
2492 rip
->version_send
: ri
->ri_send
);
2494 if (IS_RIP_DEBUG_EVENT
)
2495 zlog_debug("SEND UPDATE to %s ifindex %d",
2496 ifp
->name
, ifp
->ifindex
);
2498 /* send update on each connected network */
2499 for (ALL_LIST_ELEMENTS (ifp
->connected
, ifnode
, ifnnode
, connected
))
2501 if (connected
->address
->family
== AF_INET
)
2504 rip_update_interface (connected
, RIPv1
, route_type
);
2505 if ((vsend
& RIPv2
) && if_is_multicast(ifp
))
2506 rip_update_interface (connected
, RIPv2
, route_type
);
2512 /* RIP send updates to each neighbor. */
2513 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
2514 if (rp
->info
!= NULL
)
2518 connected
= if_lookup_address (&p
->u
.prefix4
, AF_INET
, VRF_DEFAULT
);
2521 zlog_warn ("Neighbor %s doesnt have connected interface!",
2522 inet_ntoa (p
->u
.prefix4
));
2526 /* Set destination address and port */
2527 memset (&to
, 0, sizeof (struct sockaddr_in
));
2528 to
.sin_addr
= p
->u
.prefix4
;
2529 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
2531 /* RIP version is rip's configuration. */
2532 rip_output_process (connected
, &to
, route_type
, rip
->version_send
);
2536 /* RIP's periodical timer. */
2538 rip_update (struct thread
*t
)
2540 /* Clear timer pointer. */
2541 rip
->t_update
= NULL
;
2543 if (IS_RIP_DEBUG_EVENT
)
2544 zlog_debug ("update timer fire!");
2546 /* Process update output. */
2547 rip_update_process (rip_all_route
);
2549 /* Triggered updates may be suppressed if a regular update is due by
2550 the time the triggered update would be sent. */
2551 RIP_TIMER_OFF (rip
->t_triggered_interval
);
2554 /* Register myself. */
2555 rip_event (RIP_UPDATE_EVENT
, 0);
2560 /* Walk down the RIP routing table then clear changed flag. */
2562 rip_clear_changed_flag (void)
2564 struct route_node
*rp
;
2565 struct rip_info
*rinfo
= NULL
;
2566 struct list
*list
= NULL
;
2567 struct listnode
*listnode
= NULL
;
2569 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2570 if ((list
= rp
->info
) != NULL
)
2571 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2573 UNSET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
2574 /* This flag can be set only on the first entry. */
2579 /* Triggered update interval timer. */
2581 rip_triggered_interval (struct thread
*t
)
2583 int rip_triggered_update (struct thread
*);
2585 rip
->t_triggered_interval
= NULL
;
2590 rip_triggered_update (t
);
2595 /* Execute triggered update. */
2597 rip_triggered_update (struct thread
*t
)
2601 /* Clear thred pointer. */
2602 rip
->t_triggered_update
= NULL
;
2604 /* Cancel interval timer. */
2605 RIP_TIMER_OFF (rip
->t_triggered_interval
);
2608 /* Logging triggered update. */
2609 if (IS_RIP_DEBUG_EVENT
)
2610 zlog_debug ("triggered update!");
2612 /* Split Horizon processing is done when generating triggered
2613 updates as well as normal updates (see section 2.6). */
2614 rip_update_process (rip_changed_route
);
2616 /* Once all of the triggered updates have been generated, the route
2617 change flags should be cleared. */
2618 rip_clear_changed_flag ();
2620 /* After a triggered update is sent, a timer should be set for a
2621 random interval between 1 and 5 seconds. If other changes that
2622 would trigger updates occur before the timer expires, a single
2623 update is triggered when the timer expires. */
2624 interval
= (random () % 5) + 1;
2626 rip
->t_triggered_interval
= NULL
;
2627 thread_add_timer(master
, rip_triggered_interval
, NULL
, interval
,
2628 &rip
->t_triggered_interval
);
2633 /* Withdraw redistributed route. */
2635 rip_redistribute_withdraw (int type
)
2637 struct route_node
*rp
;
2638 struct rip_info
*rinfo
= NULL
;
2639 struct list
*list
= NULL
;
2644 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2645 if ((list
= rp
->info
) != NULL
)
2647 rinfo
= listgetdata (listhead (list
));
2648 if (rinfo
->type
== type
2649 && 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
, rip
->garbage_time
);
2655 RIP_TIMER_OFF (rinfo
->t_timeout
);
2656 rinfo
->flags
|= RIP_RTF_CHANGED
;
2658 if (IS_RIP_DEBUG_EVENT
) {
2659 struct prefix_ipv4
*p
= (struct prefix_ipv4
*) &rp
->p
;
2661 zlog_debug ("Poisone %s/%d on the interface %s with an infinity metric [withdraw]",
2662 inet_ntoa(p
->prefix
), p
->prefixlen
,
2663 ifindex2ifname(rinfo
->ifindex
, VRF_DEFAULT
));
2666 rip_event (RIP_TRIGGERED_UPDATE
, 0);
2671 /* Create new RIP instance and set it to global variable. */
2675 rip
= XCALLOC (MTYPE_RIP
, sizeof (struct rip
));
2677 /* Set initial value. */
2678 rip
->version_send
= RI_RIP_VERSION_2
;
2679 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2680 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
2681 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
2682 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
2683 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2685 /* Initialize RIP routig table. */
2686 rip
->table
= route_table_init ();
2687 rip
->route
= route_table_init ();
2688 rip
->neighbor
= route_table_init ();
2690 /* Make output stream. */
2691 rip
->obuf
= stream_new (1500);
2694 rip
->sock
= rip_create_socket ();
2698 /* Create read and timer thread. */
2699 rip_event (RIP_READ
, rip
->sock
);
2700 rip_event (RIP_UPDATE_EVENT
, 1);
2702 QOBJ_REG (rip
, rip
);
2707 /* Sned RIP request to the destination. */
2709 rip_request_send (struct sockaddr_in
*to
, struct interface
*ifp
,
2710 u_char version
, struct connected
*connected
)
2713 struct rip_packet rip_packet
;
2714 struct listnode
*node
, *nnode
;
2716 memset (&rip_packet
, 0, sizeof (rip_packet
));
2718 rip_packet
.command
= RIP_REQUEST
;
2719 rip_packet
.version
= version
;
2720 rte
= rip_packet
.rte
;
2721 rte
->metric
= htonl (RIP_METRIC_INFINITY
);
2726 * connected is only sent for ripv1 case, or when
2727 * interface does not support multicast. Caller loops
2728 * over each connected address for this case.
2730 if (rip_send_packet ((u_char
*) &rip_packet
, sizeof (rip_packet
),
2731 to
, connected
) != sizeof (rip_packet
))
2734 return sizeof (rip_packet
);
2737 /* send request on each connected network */
2738 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, connected
))
2740 struct prefix_ipv4
*p
;
2742 p
= (struct prefix_ipv4
*) connected
->address
;
2744 if (p
->family
!= AF_INET
)
2747 if (rip_send_packet ((u_char
*) &rip_packet
, sizeof (rip_packet
),
2748 to
, connected
) != sizeof (rip_packet
))
2751 return sizeof (rip_packet
);
2755 rip_update_jitter (unsigned long time
)
2757 #define JITTER_BOUND 4
2758 /* We want to get the jitter to +/- 1/JITTER_BOUND the interval.
2759 Given that, we cannot let time be less than JITTER_BOUND seconds.
2760 The RIPv2 RFC says jitter should be small compared to
2761 update_time. We consider 1/JITTER_BOUND to be small.
2764 int jitter_input
= time
;
2767 if (jitter_input
< JITTER_BOUND
)
2768 jitter_input
= JITTER_BOUND
;
2770 jitter
= (((random () % ((jitter_input
* 2) + 1)) - jitter_input
));
2772 return jitter
/JITTER_BOUND
;
2776 rip_event (enum rip_event event
, int sock
)
2784 thread_add_read(master
, rip_read
, NULL
, sock
, &rip
->t_read
);
2786 case RIP_UPDATE_EVENT
:
2787 RIP_TIMER_OFF (rip
->t_update
);
2788 jitter
= rip_update_jitter (rip
->update_time
);
2789 thread_add_timer(master
, rip_update
, NULL
, sock
? 2 : rip
->update_time
+ jitter
,
2792 case RIP_TRIGGERED_UPDATE
:
2793 if (rip
->t_triggered_interval
)
2795 else thread_add_event(master
, rip_triggered_update
, NULL
, 0,
2796 &rip
->t_triggered_update
);
2803 DEFUN_NOSH (router_rip
,
2806 "Enable a routing process\n"
2807 "Routing Information Protocol (RIP)\n")
2811 /* If rip is not enabled before. */
2814 ret
= rip_create ();
2817 zlog_info ("Can't create RIP");
2821 VTY_PUSH_CONTEXT(RIP_NODE
, rip
);
2826 DEFUN (no_router_rip
,
2830 "Enable a routing process\n"
2831 "Routing Information Protocol (RIP)\n")
2841 "Set routing protocol version\n"
2847 version
= atoi (argv
[idx_number
]->arg
);
2848 if (version
!= RIPv1
&& version
!= RIPv2
)
2850 vty_out (vty
, "invalid rip version %d%s", version
,
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;
2883 struct prefix_ipv4 p
;
2884 struct route_node
*node
;
2886 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2889 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2892 apply_mask_ipv4 (&p
);
2894 /* For router rip configuration. */
2895 node
= route_node_get (rip
->route
, (struct prefix
*) &p
);
2899 vty_out (vty
, "There is already same static route.%s", VTY_NEWLINE
);
2900 route_unlock_node (node
);
2904 node
->info
= (void *)1;
2906 rip_redistribute_add (ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0, NULL
, 0, 0, 0);
2911 DEFUN (no_rip_route
,
2913 "no route A.B.C.D/M",
2915 "RIP static route configuration\n"
2916 "IP prefix <network>/<length>\n")
2918 int idx_ipv4_prefixlen
= 2;
2920 struct prefix_ipv4 p
;
2921 struct route_node
*node
;
2923 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2926 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2929 apply_mask_ipv4 (&p
);
2931 /* For router rip configuration. */
2932 node
= route_node_lookup (rip
->route
, (struct prefix
*) &p
);
2935 vty_out (vty
, "Can't find route %s.%s", argv
[idx_ipv4_prefixlen
]->arg
,
2940 rip_redistribute_delete (ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0);
2941 route_unlock_node (node
);
2944 route_unlock_node (node
);
2951 rip_update_default_metric (void)
2953 struct route_node
*np
;
2954 struct rip_info
*rinfo
= NULL
;
2955 struct list
*list
= NULL
;
2956 struct listnode
*listnode
= NULL
;
2958 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
2959 if ((list
= np
->info
) != NULL
)
2960 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2961 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
&& rinfo
->type
!= ZEBRA_ROUTE_CONNECT
)
2962 rinfo
->metric
= rip
->default_metric
;
2966 DEFUN (rip_default_metric
,
2967 rip_default_metric_cmd
,
2968 "default-metric (1-16)",
2969 "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"
2990 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2991 /* rip_update_default_metric (); */
2999 "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
3000 "Adjust routing timers\n"
3001 "Basic routing protocol update timers\n"
3002 "Routing table update timer value in second. Default is 30.\n"
3003 "Routing information timeout timer. Default is 180.\n"
3004 "Garbage collection timer. Default is 120.\n")
3007 int idx_number_2
= 3;
3008 int idx_number_3
= 4;
3009 unsigned long update
;
3010 unsigned long timeout
;
3011 unsigned long garbage
;
3012 char *endptr
= NULL
;
3013 unsigned long RIP_TIMER_MAX
= 2147483647;
3014 unsigned long RIP_TIMER_MIN
= 5;
3016 update
= strtoul (argv
[idx_number
]->arg
, &endptr
, 10);
3017 if (update
> RIP_TIMER_MAX
|| update
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3019 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
3023 timeout
= strtoul (argv
[idx_number_2
]->arg
, &endptr
, 10);
3024 if (timeout
> RIP_TIMER_MAX
|| timeout
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3026 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
3030 garbage
= strtoul (argv
[idx_number_3
]->arg
, &endptr
, 10);
3031 if (garbage
> RIP_TIMER_MAX
|| garbage
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3033 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
3037 /* Set each timer value. */
3038 rip
->update_time
= update
;
3039 rip
->timeout_time
= timeout
;
3040 rip
->garbage_time
= garbage
;
3042 /* Reset update timer thread. */
3043 rip_event (RIP_UPDATE_EVENT
, 0);
3048 DEFUN (no_rip_timers
,
3050 "no timers basic [(0-65535) (0-65535) (0-65535)]",
3052 "Adjust routing timers\n"
3053 "Basic routing protocol update timers\n"
3054 "Routing table update timer value in second. Default is 30.\n"
3055 "Routing information timeout timer. Default is 180.\n"
3056 "Garbage collection timer. Default is 120.\n")
3058 /* Set each timer value to the default. */
3059 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
3060 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
3061 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
3063 /* Reset update timer thread. */
3064 rip_event (RIP_UPDATE_EVENT
, 0);
3071 struct route_table
*rip_distance_table
;
3075 /* Distance value for the IP source prefix. */
3078 /* Name of the access-list to be matched. */
3082 static struct rip_distance
*
3083 rip_distance_new (void)
3085 return XCALLOC (MTYPE_RIP_DISTANCE
, sizeof (struct rip_distance
));
3089 rip_distance_free (struct rip_distance
*rdistance
)
3091 XFREE (MTYPE_RIP_DISTANCE
, rdistance
);
3095 rip_distance_set (struct vty
*vty
, const char *distance_str
, const char *ip_str
,
3096 const char *access_list_str
)
3099 struct prefix_ipv4 p
;
3101 struct route_node
*rn
;
3102 struct rip_distance
*rdistance
;
3104 ret
= str2prefix_ipv4 (ip_str
, &p
);
3107 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
3111 distance
= atoi (distance_str
);
3113 /* Get RIP distance node. */
3114 rn
= route_node_get (rip_distance_table
, (struct prefix
*) &p
);
3117 rdistance
= rn
->info
;
3118 route_unlock_node (rn
);
3122 rdistance
= rip_distance_new ();
3123 rn
->info
= rdistance
;
3126 /* Set distance value. */
3127 rdistance
->distance
= distance
;
3129 /* Reset access-list configuration. */
3130 if (rdistance
->access_list
)
3132 free (rdistance
->access_list
);
3133 rdistance
->access_list
= NULL
;
3135 if (access_list_str
)
3136 rdistance
->access_list
= strdup (access_list_str
);
3142 rip_distance_unset (struct vty
*vty
, const char *distance_str
,
3143 const char *ip_str
, const char *access_list_str
)
3146 struct prefix_ipv4 p
;
3147 struct route_node
*rn
;
3148 struct rip_distance
*rdistance
;
3150 ret
= str2prefix_ipv4 (ip_str
, &p
);
3153 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
3157 rn
= route_node_lookup (rip_distance_table
, (struct prefix
*)&p
);
3160 vty_out (vty
, "Can't find specified prefix%s", VTY_NEWLINE
);
3164 rdistance
= rn
->info
;
3166 if (rdistance
->access_list
)
3167 free (rdistance
->access_list
);
3168 rip_distance_free (rdistance
);
3171 route_unlock_node (rn
);
3172 route_unlock_node (rn
);
3178 rip_distance_reset (void)
3180 struct route_node
*rn
;
3181 struct rip_distance
*rdistance
;
3183 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3184 if ((rdistance
= rn
->info
) != NULL
)
3186 if (rdistance
->access_list
)
3187 free (rdistance
->access_list
);
3188 rip_distance_free (rdistance
);
3190 route_unlock_node (rn
);
3194 /* Apply RIP information to distance method. */
3196 rip_distance_apply (struct rip_info
*rinfo
)
3198 struct route_node
*rn
;
3199 struct prefix_ipv4 p
;
3200 struct rip_distance
*rdistance
;
3201 struct access_list
*alist
;
3206 memset (&p
, 0, sizeof (struct prefix_ipv4
));
3208 p
.prefix
= rinfo
->from
;
3209 p
.prefixlen
= IPV4_MAX_BITLEN
;
3211 /* Check source address. */
3212 rn
= route_node_match (rip_distance_table
, (struct prefix
*) &p
);
3215 rdistance
= rn
->info
;
3216 route_unlock_node (rn
);
3218 if (rdistance
->access_list
)
3220 alist
= access_list_lookup (AFI_IP
, rdistance
->access_list
);
3223 if (access_list_apply (alist
, &rinfo
->rp
->p
) == FILTER_DENY
)
3226 return rdistance
->distance
;
3229 return rdistance
->distance
;
3233 return rip
->distance
;
3239 rip_distance_show (struct vty
*vty
)
3241 struct route_node
*rn
;
3242 struct rip_distance
*rdistance
;
3246 vty_out (vty
, " Distance: (default is %d)%s",
3247 rip
->distance
? rip
->distance
:ZEBRA_RIP_DISTANCE_DEFAULT
,
3250 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3251 if ((rdistance
= rn
->info
) != NULL
)
3255 vty_out (vty
, " Address Distance List%s",
3259 sprintf (buf
, "%s/%d", inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
3260 vty_out (vty
, " %-20s %4d %s%s",
3261 buf
, rdistance
->distance
,
3262 rdistance
->access_list
? rdistance
->access_list
: "",
3267 DEFUN (rip_distance
,
3270 "Administrative distance\n"
3274 rip
->distance
= atoi (argv
[idx_number
]->arg
);
3278 DEFUN (no_rip_distance
,
3279 no_rip_distance_cmd
,
3280 "no distance (1-255)",
3282 "Administrative distance\n"
3289 DEFUN (rip_distance_source
,
3290 rip_distance_source_cmd
,
3291 "distance (1-255) A.B.C.D/M",
3292 "Administrative distance\n"
3294 "IP source prefix\n")
3297 int idx_ipv4_prefixlen
= 2;
3298 rip_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3302 DEFUN (no_rip_distance_source
,
3303 no_rip_distance_source_cmd
,
3304 "no distance (1-255) A.B.C.D/M",
3306 "Administrative distance\n"
3308 "IP source prefix\n")
3311 int idx_ipv4_prefixlen
= 3;
3312 rip_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3316 DEFUN (rip_distance_source_access_list
,
3317 rip_distance_source_access_list_cmd
,
3318 "distance (1-255) A.B.C.D/M WORD",
3319 "Administrative distance\n"
3321 "IP source prefix\n"
3322 "Access list name\n")
3325 int idx_ipv4_prefixlen
= 2;
3327 rip_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3331 DEFUN (no_rip_distance_source_access_list
,
3332 no_rip_distance_source_access_list_cmd
,
3333 "no distance (1-255) A.B.C.D/M WORD",
3335 "Administrative distance\n"
3337 "IP source prefix\n"
3338 "Access list name\n")
3341 int idx_ipv4_prefixlen
= 3;
3343 rip_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3347 /* Update ECMP routes to zebra when ECMP is disabled. */
3349 rip_ecmp_disable (void)
3351 struct route_node
*rp
;
3352 struct rip_info
*rinfo
, *tmp_rinfo
;
3354 struct listnode
*node
, *nextnode
;
3359 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
3360 if ((list
= rp
->info
) != NULL
&& listcount (list
) > 1)
3362 rinfo
= listgetdata (listhead (list
));
3363 if (!rip_route_rte (rinfo
))
3366 /* Drop all other entries, except the first one. */
3367 for (ALL_LIST_ELEMENTS (list
, node
, nextnode
, tmp_rinfo
))
3368 if (tmp_rinfo
!= rinfo
)
3370 RIP_TIMER_OFF (tmp_rinfo
->t_timeout
);
3371 RIP_TIMER_OFF (tmp_rinfo
->t_garbage_collect
);
3372 list_delete_node (list
, node
);
3373 rip_info_free (tmp_rinfo
);
3377 rip_zebra_ipv4_add (rp
);
3379 /* Set the route change flag. */
3380 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
3382 /* Signal the output process to trigger an update. */
3383 rip_event (RIP_TRIGGERED_UPDATE
, 0);
3387 DEFUN (rip_allow_ecmp
,
3390 "Allow Equal Cost MultiPath\n")
3394 vty_out (vty
, "ECMP is already enabled.%s", VTY_NEWLINE
);
3399 zlog_info ("ECMP is enabled.");
3403 DEFUN (no_rip_allow_ecmp
,
3404 no_rip_allow_ecmp_cmd
,
3407 "Allow Equal Cost MultiPath\n")
3411 vty_out (vty
, "ECMP is already disabled.%s", VTY_NEWLINE
);
3416 zlog_info ("ECMP is disabled.");
3417 rip_ecmp_disable ();
3421 /* Print out routes update time. */
3423 rip_vty_out_uptime (struct vty
*vty
, struct rip_info
*rinfo
)
3428 char timebuf
[TIME_BUF
];
3429 struct thread
*thread
;
3431 if ((thread
= rinfo
->t_timeout
) != NULL
)
3433 clock
= thread_timer_remain_second (thread
);
3434 tm
= gmtime (&clock
);
3435 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
3436 vty_out (vty
, "%5s", timebuf
);
3438 else if ((thread
= rinfo
->t_garbage_collect
) != NULL
)
3440 clock
= thread_timer_remain_second (thread
);
3441 tm
= gmtime (&clock
);
3442 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
3443 vty_out (vty
, "%5s", timebuf
);
3448 rip_route_type_print (int sub_type
)
3454 case RIP_ROUTE_STATIC
:
3456 case RIP_ROUTE_DEFAULT
:
3458 case RIP_ROUTE_REDISTRIBUTE
:
3460 case RIP_ROUTE_INTERFACE
:
3472 "Show RIP routes\n")
3474 struct route_node
*np
;
3475 struct rip_info
*rinfo
= NULL
;
3476 struct list
*list
= NULL
;
3477 struct listnode
*listnode
= NULL
;
3482 vty_out (vty
, "Codes: R - RIP, C - connected, S - Static, O - OSPF, B - BGP%s"
3484 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
3485 " (i) - interface%s%s"
3486 " Network Next Hop Metric From Tag Time%s",
3487 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
3489 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
3490 if ((list
= np
->info
) != NULL
)
3491 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
3495 len
= vty_out (vty
, "%c(%s) %s/%d",
3496 /* np->lock, For debugging. */
3497 zebra_route_char(rinfo
->type
),
3498 rip_route_type_print (rinfo
->sub_type
),
3499 inet_ntoa (np
->p
.u
.prefix4
), np
->p
.prefixlen
);
3504 vty_out (vty
, "%*s", len
, " ");
3506 if (rinfo
->nexthop
.s_addr
)
3507 vty_out (vty
, "%-20s %2d ", inet_ntoa (rinfo
->nexthop
),
3510 vty_out (vty
, "0.0.0.0 %2d ", rinfo
->metric
);
3512 /* Route which exist in kernel routing table. */
3513 if ((rinfo
->type
== ZEBRA_ROUTE_RIP
) &&
3514 (rinfo
->sub_type
== RIP_ROUTE_RTE
))
3516 vty_out (vty
, "%-15s ", inet_ntoa (rinfo
->from
));
3517 vty_out (vty
, "%3"ROUTE_TAG_PRI
" ", (route_tag_t
)rinfo
->tag
);
3518 rip_vty_out_uptime (vty
, rinfo
);
3520 else if (rinfo
->metric
== RIP_METRIC_INFINITY
)
3522 vty_out (vty
, "self ");
3523 vty_out (vty
, "%3"ROUTE_TAG_PRI
" ", (route_tag_t
)rinfo
->tag
);
3524 rip_vty_out_uptime (vty
, rinfo
);
3528 if (rinfo
->external_metric
)
3530 len
= vty_out (vty
, "self (%s:%d)",
3531 zebra_route_string(rinfo
->type
),
3532 rinfo
->external_metric
);
3535 vty_out (vty
, "%*s", len
, " ");
3538 vty_out (vty
, "self ");
3539 vty_out (vty
, "%3"ROUTE_TAG_PRI
, (route_tag_t
)rinfo
->tag
);
3542 vty_out (vty
, "%s", VTY_NEWLINE
);
3547 /* Vincent: formerly, it was show_ip_protocols_rip: "show ip protocols" */
3548 DEFUN (show_ip_rip_status
,
3549 show_ip_rip_status_cmd
,
3550 "show ip rip status",
3554 "IP routing protocol process parameters and statistics\n")
3556 struct listnode
*node
;
3557 struct interface
*ifp
;
3558 struct rip_interface
*ri
;
3559 extern const struct message ri_version_msg
[];
3560 const char *send_version
;
3561 const char *receive_version
;
3566 vty_out (vty
, "Routing Protocol is \"rip\"%s", VTY_NEWLINE
);
3567 vty_out (vty
, " Sending updates every %ld seconds with +/-50%%,",
3569 vty_out (vty
, " next due in %lu seconds%s",
3570 thread_timer_remain_second(rip
->t_update
),
3572 vty_out (vty
, " Timeout after %ld seconds,", rip
->timeout_time
);
3573 vty_out (vty
, " garbage collect after %ld seconds%s", rip
->garbage_time
,
3576 /* Filtering status show. */
3577 config_show_distribute (vty
);
3579 /* Default metric information. */
3580 vty_out (vty
, " Default redistribution metric is %d%s",
3581 rip
->default_metric
, VTY_NEWLINE
);
3583 /* Redistribute information. */
3584 vty_out (vty
, " Redistributing:");
3585 config_write_rip_redistribute (vty
, 0);
3586 vty_out (vty
, "%s", VTY_NEWLINE
);
3588 vty_out (vty
, " Default version control: send version %s,",
3589 lookup(ri_version_msg
,rip
->version_send
));
3590 if (rip
->version_recv
== RI_RIP_VERSION_1_AND_2
)
3591 vty_out (vty
, " receive any version %s", VTY_NEWLINE
);
3593 vty_out (vty
, " receive version %s %s",
3594 lookup(ri_version_msg
,rip
->version_recv
), VTY_NEWLINE
);
3596 vty_out (vty
, " Interface Send Recv Key-chain%s", VTY_NEWLINE
);
3598 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
3605 if (ri
->enable_network
|| ri
->enable_interface
)
3607 if (ri
->ri_send
== RI_RIP_UNSPEC
)
3608 send_version
= lookup (ri_version_msg
, rip
->version_send
);
3610 send_version
= lookup (ri_version_msg
, ri
->ri_send
);
3612 if (ri
->ri_receive
== RI_RIP_UNSPEC
)
3613 receive_version
= lookup (ri_version_msg
, rip
->version_recv
);
3615 receive_version
= lookup (ri_version_msg
, ri
->ri_receive
);
3617 vty_out (vty
, " %-17s%-3s %-3s %s%s", ifp
->name
,
3620 ri
->key_chain
? ri
->key_chain
: "",
3625 vty_out (vty
, " Routing for Networks:%s", VTY_NEWLINE
);
3626 config_write_rip_network (vty
, 0);
3629 int found_passive
= 0;
3630 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
3634 if ((ri
->enable_network
|| ri
->enable_interface
) && ri
->passive
)
3638 vty_out (vty
, " Passive Interface(s):%s", VTY_NEWLINE
);
3641 vty_out (vty
, " %s%s", ifp
->name
, VTY_NEWLINE
);
3646 vty_out (vty
, " Routing Information Sources:%s", VTY_NEWLINE
);
3647 vty_out (vty
, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE
);
3648 rip_peer_display (vty
);
3650 rip_distance_show (vty
);
3655 /* RIP configuration write function. */
3657 config_write_rip (struct vty
*vty
)
3660 struct route_node
*rn
;
3661 struct rip_distance
*rdistance
;
3665 /* Router RIP statement. */
3666 vty_out (vty
, "router rip%s", VTY_NEWLINE
);
3669 /* RIP version statement. Default is RIP version 2. */
3670 if (rip
->version_send
!= RI_RIP_VERSION_2
3671 || rip
->version_recv
!= RI_RIP_VERSION_1_AND_2
)
3672 vty_out (vty
, " version %d%s", rip
->version_send
,
3675 /* RIP timer configuration. */
3676 if (rip
->update_time
!= RIP_UPDATE_TIMER_DEFAULT
3677 || rip
->timeout_time
!= RIP_TIMEOUT_TIMER_DEFAULT
3678 || rip
->garbage_time
!= RIP_GARBAGE_TIMER_DEFAULT
)
3679 vty_out (vty
, " timers basic %lu %lu %lu%s",
3685 /* Default information configuration. */
3686 if (rip
->default_information
)
3688 if (rip
->default_information_route_map
)
3689 vty_out (vty
, " default-information originate route-map %s%s",
3690 rip
->default_information_route_map
, VTY_NEWLINE
);
3692 vty_out (vty
, " default-information originate%s",
3696 /* Redistribute configuration. */
3697 config_write_rip_redistribute (vty
, 1);
3699 /* RIP offset-list configuration. */
3700 config_write_rip_offset_list (vty
);
3702 /* RIP enabled network and interface configuration. */
3703 config_write_rip_network (vty
, 1);
3705 /* RIP default metric configuration */
3706 if (rip
->default_metric
!= RIP_DEFAULT_METRIC_DEFAULT
)
3707 vty_out (vty
, " default-metric %d%s",
3708 rip
->default_metric
, VTY_NEWLINE
);
3710 /* Distribute configuration. */
3711 write
+= config_write_distribute (vty
);
3713 /* Interface routemap configuration */
3714 write
+= config_write_if_rmap (vty
);
3716 /* Distance configuration. */
3718 vty_out (vty
, " distance %d%s", rip
->distance
, VTY_NEWLINE
);
3720 /* RIP source IP prefix distance configuration. */
3721 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3722 if ((rdistance
= rn
->info
) != NULL
)
3723 vty_out (vty
, " distance %d %s/%d %s%s", rdistance
->distance
,
3724 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
3725 rdistance
->access_list
? rdistance
->access_list
: "",
3728 /* ECMP configuration. */
3730 vty_out (vty
, " allow-ecmp%s", VTY_NEWLINE
);
3732 /* RIP static route configuration. */
3733 for (rn
= route_top (rip
->route
); rn
; rn
= route_next (rn
))
3735 vty_out (vty
, " route %s/%d%s",
3736 inet_ntoa (rn
->p
.u
.prefix4
),
3744 /* RIP node structure. */
3745 static struct cmd_node rip_node
=
3748 "%s(config-router)# ",
3752 /* Distribute-list update functions. */
3754 rip_distribute_update (struct distribute
*dist
)
3756 struct interface
*ifp
;
3757 struct rip_interface
*ri
;
3758 struct access_list
*alist
;
3759 struct prefix_list
*plist
;
3764 ifp
= if_lookup_by_name (dist
->ifname
, VRF_DEFAULT
);
3770 if (dist
->list
[DISTRIBUTE_V4_IN
])
3772 alist
= access_list_lookup (AFI_IP
, dist
->list
[DISTRIBUTE_V4_IN
]);
3774 ri
->list
[RIP_FILTER_IN
] = alist
;
3776 ri
->list
[RIP_FILTER_IN
] = NULL
;
3779 ri
->list
[RIP_FILTER_IN
] = NULL
;
3781 if (dist
->list
[DISTRIBUTE_V4_OUT
])
3783 alist
= access_list_lookup (AFI_IP
, dist
->list
[DISTRIBUTE_V4_OUT
]);
3785 ri
->list
[RIP_FILTER_OUT
] = alist
;
3787 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3790 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3792 if (dist
->prefix
[DISTRIBUTE_V4_IN
])
3794 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_IN
]);
3796 ri
->prefix
[RIP_FILTER_IN
] = plist
;
3798 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3801 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3803 if (dist
->prefix
[DISTRIBUTE_V4_OUT
])
3805 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_OUT
]);
3807 ri
->prefix
[RIP_FILTER_OUT
] = plist
;
3809 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3812 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3816 rip_distribute_update_interface (struct interface
*ifp
)
3818 struct distribute
*dist
;
3820 dist
= distribute_lookup (ifp
->name
);
3822 rip_distribute_update (dist
);
3825 /* Update all interface's distribute list. */
3828 rip_distribute_update_all (struct prefix_list
*notused
)
3830 struct interface
*ifp
;
3831 struct listnode
*node
, *nnode
;
3833 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
3834 rip_distribute_update_interface (ifp
);
3838 rip_distribute_update_all_wrapper(struct access_list
*notused
)
3840 rip_distribute_update_all(NULL
);
3843 /* Delete all added rip route. */
3848 struct route_node
*rp
;
3849 struct rip_info
*rinfo
= NULL
;
3850 struct list
*list
= NULL
;
3851 struct listnode
*listnode
= NULL
;
3857 /* Clear RIP routes */
3858 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
3859 if ((list
= rp
->info
) != NULL
)
3861 rinfo
= listgetdata (listhead (list
));
3862 if (rip_route_rte (rinfo
))
3863 rip_zebra_ipv4_delete (rp
);
3865 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
3867 RIP_TIMER_OFF (rinfo
->t_timeout
);
3868 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
3869 rip_info_free (rinfo
);
3873 route_unlock_node (rp
);
3876 /* Cancel RIP related timers. */
3877 RIP_TIMER_OFF (rip
->t_update
);
3878 RIP_TIMER_OFF (rip
->t_triggered_update
);
3879 RIP_TIMER_OFF (rip
->t_triggered_interval
);
3881 /* Cancel read thread. */
3882 THREAD_READ_OFF (rip
->t_read
);
3884 /* Close RIP socket. */
3891 /* Static RIP route configuration. */
3892 for (rp
= route_top (rip
->route
); rp
; rp
= route_next (rp
))
3896 route_unlock_node (rp
);
3899 /* RIP neighbor configuration. */
3900 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
3904 route_unlock_node (rp
);
3907 /* Redistribute related clear. */
3908 if (rip
->default_information_route_map
)
3909 free (rip
->default_information_route_map
);
3911 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
3912 if (rip
->route_map
[i
].name
)
3913 free (rip
->route_map
[i
].name
);
3915 XFREE (MTYPE_ROUTE_TABLE
, rip
->table
);
3916 XFREE (MTYPE_ROUTE_TABLE
, rip
->route
);
3917 XFREE (MTYPE_ROUTE_TABLE
, rip
->neighbor
);
3919 XFREE (MTYPE_RIP
, rip
);
3923 rip_clean_network ();
3924 rip_passive_nondefault_clean ();
3925 rip_offset_clean ();
3926 rip_interfaces_clean ();
3927 rip_distance_reset ();
3928 rip_redistribute_clean ();
3931 /* Reset all values to the default settings. */
3935 /* Reset global counters. */
3936 rip_global_route_changes
= 0;
3937 rip_global_queries
= 0;
3939 /* Call ripd related reset functions. */
3941 rip_route_map_reset ();
3943 /* Call library reset functions. */
3945 access_list_reset ();
3946 prefix_list_reset ();
3948 distribute_list_reset ();
3950 rip_interfaces_reset ();
3951 rip_distance_reset ();
3953 rip_zclient_reset ();
3957 rip_if_rmap_update (struct if_rmap
*if_rmap
)
3959 struct interface
*ifp
;
3960 struct rip_interface
*ri
;
3961 struct route_map
*rmap
;
3963 ifp
= if_lookup_by_name (if_rmap
->ifname
, VRF_DEFAULT
);
3969 if (if_rmap
->routemap
[IF_RMAP_IN
])
3971 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_IN
]);
3973 ri
->routemap
[IF_RMAP_IN
] = rmap
;
3975 ri
->routemap
[IF_RMAP_IN
] = NULL
;
3978 ri
->routemap
[RIP_FILTER_IN
] = NULL
;
3980 if (if_rmap
->routemap
[IF_RMAP_OUT
])
3982 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_OUT
]);
3984 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
3986 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
3989 ri
->routemap
[RIP_FILTER_OUT
] = NULL
;
3993 rip_if_rmap_update_interface (struct interface
*ifp
)
3995 struct if_rmap
*if_rmap
;
3997 if_rmap
= if_rmap_lookup (ifp
->name
);
3999 rip_if_rmap_update (if_rmap
);
4003 rip_routemap_update_redistribute (void)
4009 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
4011 if (rip
->route_map
[i
].name
)
4012 rip
->route_map
[i
].map
=
4013 route_map_lookup_by_name (rip
->route_map
[i
].name
);
4020 rip_routemap_update (const char *notused
)
4022 struct interface
*ifp
;
4023 struct listnode
*node
, *nnode
;
4025 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
4026 rip_if_rmap_update_interface (ifp
);
4028 rip_routemap_update_redistribute ();
4031 /* Allocate new rip structure and set default value. */
4035 /* Install top nodes. */
4036 install_node (&rip_node
, config_write_rip
);
4038 /* Install rip commands. */
4039 install_element (VIEW_NODE
, &show_ip_rip_cmd
);
4040 install_element (VIEW_NODE
, &show_ip_rip_status_cmd
);
4041 install_element (CONFIG_NODE
, &router_rip_cmd
);
4042 install_element (CONFIG_NODE
, &no_router_rip_cmd
);
4044 install_default (RIP_NODE
);
4045 install_element (RIP_NODE
, &rip_version_cmd
);
4046 install_element (RIP_NODE
, &no_rip_version_cmd
);
4047 install_element (RIP_NODE
, &rip_default_metric_cmd
);
4048 install_element (RIP_NODE
, &no_rip_default_metric_cmd
);
4049 install_element (RIP_NODE
, &rip_timers_cmd
);
4050 install_element (RIP_NODE
, &no_rip_timers_cmd
);
4051 install_element (RIP_NODE
, &rip_route_cmd
);
4052 install_element (RIP_NODE
, &no_rip_route_cmd
);
4053 install_element (RIP_NODE
, &rip_distance_cmd
);
4054 install_element (RIP_NODE
, &no_rip_distance_cmd
);
4055 install_element (RIP_NODE
, &rip_distance_source_cmd
);
4056 install_element (RIP_NODE
, &no_rip_distance_source_cmd
);
4057 install_element (RIP_NODE
, &rip_distance_source_access_list_cmd
);
4058 install_element (RIP_NODE
, &no_rip_distance_source_access_list_cmd
);
4059 install_element (RIP_NODE
, &rip_allow_ecmp_cmd
);
4060 install_element (RIP_NODE
, &no_rip_allow_ecmp_cmd
);
4062 /* Debug related init. */
4065 /* Access list install. */
4066 access_list_init ();
4067 access_list_add_hook (rip_distribute_update_all_wrapper
);
4068 access_list_delete_hook (rip_distribute_update_all_wrapper
);
4070 /* Prefix list initialize.*/
4071 prefix_list_init ();
4072 prefix_list_add_hook (rip_distribute_update_all
);
4073 prefix_list_delete_hook (rip_distribute_update_all
);
4075 /* Distribute list install. */
4076 distribute_list_init (RIP_NODE
);
4077 distribute_list_add_hook (rip_distribute_update
);
4078 distribute_list_delete_hook (rip_distribute_update
);
4081 rip_route_map_init ();
4084 route_map_add_hook (rip_routemap_update
);
4085 route_map_delete_hook (rip_routemap_update
);
4087 if_rmap_init (RIP_NODE
);
4088 if_rmap_hook_add (rip_if_rmap_update
);
4089 if_rmap_hook_delete (rip_if_rmap_update
);
4091 /* Distance control. */
4092 rip_distance_table
= route_table_init ();