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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 #include "sockunion.h"
40 #include "distribute.h"
45 #include "ripd/ripd.h"
46 #include "ripd/rip_debug.h"
50 /* UDP receive buffer size */
51 #define RIP_UDP_RCV_BUF 41600
53 /* privileges global */
54 extern struct zebra_privs_t ripd_privs
;
57 struct rip
*rip
= NULL
;
59 /* RIP neighbor address table. */
60 struct route_table
*rip_neighbor_table
;
62 /* RIP route changes. */
63 long rip_global_route_changes
= 0;
66 long rip_global_queries
= 0;
69 static void rip_event (enum rip_event
, int);
70 static void rip_output_process (struct connected
*, struct sockaddr_in
*, int, u_char
);
71 static int rip_triggered_update (struct thread
*);
72 static int rip_update_jitter (unsigned long);
74 /* RIP output routes type. */
81 /* RIP command strings. */
82 static const struct message rip_msg
[] =
84 {RIP_REQUEST
, "REQUEST"},
85 {RIP_RESPONSE
, "RESPONSE"},
86 {RIP_TRACEON
, "TRACEON"},
87 {RIP_TRACEOFF
, "TRACEOFF"},
89 {RIP_POLL_ENTRY
, "POLL ENTRY"},
93 /* Utility function to set boradcast option to the socket. */
95 sockopt_broadcast (int sock
)
100 ret
= setsockopt (sock
, SOL_SOCKET
, SO_BROADCAST
, (char *) &on
, sizeof on
);
103 zlog_warn ("can't set sockopt SO_BROADCAST to socket %d", sock
);
110 rip_route_rte (struct rip_info
*rinfo
)
112 return (rinfo
->type
== ZEBRA_ROUTE_RIP
&& rinfo
->sub_type
== RIP_ROUTE_RTE
);
115 static struct rip_info
*
118 return XCALLOC (MTYPE_RIP_INFO
, sizeof (struct rip_info
));
122 rip_info_free (struct rip_info
*rinfo
)
124 XFREE (MTYPE_RIP_INFO
, rinfo
);
127 /* RIP route garbage collect timer. */
129 rip_garbage_collect (struct thread
*t
)
131 struct rip_info
*rinfo
;
132 struct route_node
*rp
;
134 rinfo
= THREAD_ARG (t
);
135 rinfo
->t_garbage_collect
= NULL
;
137 /* Off timeout timer. */
138 RIP_TIMER_OFF (rinfo
->t_timeout
);
140 /* Get route_node pointer. */
143 /* Unlock route_node. */
144 listnode_delete (rp
->info
, rinfo
);
145 if (list_isempty ((struct list
*)rp
->info
))
147 list_free (rp
->info
);
149 route_unlock_node (rp
);
152 /* Free RIP routing information. */
153 rip_info_free (rinfo
);
158 static void rip_timeout_update (struct rip_info
*rinfo
);
160 /* Add new route to the ECMP list.
161 * RETURN: the new entry added in the list, or NULL if it is not the first
162 * entry and ECMP is not allowed.
165 rip_ecmp_add (struct rip_info
*rinfo_new
)
167 struct route_node
*rp
= rinfo_new
->rp
;
168 struct rip_info
*rinfo
= NULL
;
169 struct list
*list
= NULL
;
171 if (rp
->info
== NULL
)
172 rp
->info
= list_new ();
173 list
= (struct list
*)rp
->info
;
175 /* If ECMP is not allowed and some entry already exists in the list,
177 if (listcount (list
) && !rip
->ecmp
)
180 rinfo
= rip_info_new ();
181 memcpy (rinfo
, rinfo_new
, sizeof (struct rip_info
));
182 listnode_add (list
, rinfo
);
184 if (rip_route_rte (rinfo
))
186 rip_timeout_update (rinfo
);
187 rip_zebra_ipv4_add (rp
);
190 /* Set the route change flag on the first entry. */
191 rinfo
= listgetdata (listhead (list
));
192 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
194 /* Signal the output process to trigger an update (see section 2.5). */
195 rip_event (RIP_TRIGGERED_UPDATE
, 0);
200 /* Replace the ECMP list with the new route.
201 * RETURN: the new entry added in the list
204 rip_ecmp_replace (struct rip_info
*rinfo_new
)
206 struct route_node
*rp
= rinfo_new
->rp
;
207 struct list
*list
= (struct list
*)rp
->info
;
208 struct rip_info
*rinfo
= NULL
, *tmp_rinfo
= NULL
;
209 struct listnode
*node
= NULL
, *nextnode
= NULL
;
211 if (list
== NULL
|| listcount (list
) == 0)
212 return rip_ecmp_add (rinfo_new
);
214 /* Get the first entry */
215 rinfo
= listgetdata (listhead (list
));
217 /* Learnt route replaced by a local one. Delete it from zebra. */
218 if (rip_route_rte (rinfo
) && !rip_route_rte (rinfo_new
))
219 if (CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
))
220 rip_zebra_ipv4_delete (rp
);
222 /* Re-use the first entry, and delete the others. */
223 for (ALL_LIST_ELEMENTS (list
, node
, nextnode
, tmp_rinfo
))
224 if (tmp_rinfo
!= rinfo
)
226 RIP_TIMER_OFF (tmp_rinfo
->t_timeout
);
227 RIP_TIMER_OFF (tmp_rinfo
->t_garbage_collect
);
228 list_delete_node (list
, node
);
229 rip_info_free (tmp_rinfo
);
232 RIP_TIMER_OFF (rinfo
->t_timeout
);
233 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
234 memcpy (rinfo
, rinfo_new
, sizeof (struct rip_info
));
236 if (rip_route_rte (rinfo
))
238 rip_timeout_update (rinfo
);
239 /* The ADD message implies an update. */
240 rip_zebra_ipv4_add (rp
);
243 /* Set the route change flag. */
244 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
246 /* Signal the output process to trigger an update (see section 2.5). */
247 rip_event (RIP_TRIGGERED_UPDATE
, 0);
252 /* Delete one route from the ECMP list.
254 * null - the entry is freed, and other entries exist in the list
255 * the entry - the entry is the last one in the list; its metric is set
256 * to INFINITY, and the garbage collector is started for it
259 rip_ecmp_delete (struct rip_info
*rinfo
)
261 struct route_node
*rp
= rinfo
->rp
;
262 struct list
*list
= (struct list
*)rp
->info
;
264 RIP_TIMER_OFF (rinfo
->t_timeout
);
266 if (listcount (list
) > 1)
268 /* Some other ECMP entries still exist. Just delete this entry. */
269 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
270 listnode_delete (list
, rinfo
);
271 if (rip_route_rte (rinfo
) && CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
))
272 /* The ADD message implies the update. */
273 rip_zebra_ipv4_add (rp
);
274 rip_info_free (rinfo
);
279 assert (rinfo
== listgetdata (listhead (list
)));
281 /* This is the only entry left in the list. We must keep it in
282 * the list for garbage collection time, with INFINITY metric. */
284 rinfo
->metric
= RIP_METRIC_INFINITY
;
285 RIP_TIMER_ON (rinfo
->t_garbage_collect
,
286 rip_garbage_collect
, rip
->garbage_time
);
288 if (rip_route_rte (rinfo
) && CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
))
289 rip_zebra_ipv4_delete (rp
);
292 /* Set the route change flag on the first entry. */
293 rinfo
= listgetdata (listhead (list
));
294 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
296 /* Signal the output process to trigger an update (see section 2.5). */
297 rip_event (RIP_TRIGGERED_UPDATE
, 0);
302 /* Timeout RIP routes. */
304 rip_timeout (struct thread
*t
)
306 rip_ecmp_delete ((struct rip_info
*)THREAD_ARG (t
));
311 rip_timeout_update (struct rip_info
*rinfo
)
313 if (rinfo
->metric
!= RIP_METRIC_INFINITY
)
315 RIP_TIMER_OFF (rinfo
->t_timeout
);
316 RIP_TIMER_ON (rinfo
->t_timeout
, rip_timeout
, rip
->timeout_time
);
321 rip_filter (int rip_distribute
, struct prefix_ipv4
*p
, struct rip_interface
*ri
)
323 struct distribute
*dist
;
324 struct access_list
*alist
;
325 struct prefix_list
*plist
;
326 int distribute
= rip_distribute
== RIP_FILTER_OUT
?
327 DISTRIBUTE_V4_OUT
: DISTRIBUTE_V4_IN
;
328 const char *inout
= rip_distribute
== RIP_FILTER_OUT
? "out" : "in";
330 /* Input distribute-list filtering. */
331 if (ri
->list
[rip_distribute
])
333 if (access_list_apply (ri
->list
[rip_distribute
],
334 (struct prefix
*) p
) == FILTER_DENY
)
336 if (IS_RIP_DEBUG_PACKET
)
337 zlog_debug ("%s/%d filtered by distribute %s",
338 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
342 if (ri
->prefix
[rip_distribute
])
344 if (prefix_list_apply (ri
->prefix
[rip_distribute
],
345 (struct prefix
*) p
) == PREFIX_DENY
)
347 if (IS_RIP_DEBUG_PACKET
)
348 zlog_debug ("%s/%d filtered by prefix-list %s",
349 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
354 /* All interface filter check. */
355 dist
= distribute_lookup (NULL
);
358 if (dist
->list
[distribute
])
360 alist
= access_list_lookup (AFI_IP
, dist
->list
[distribute
]);
364 if (access_list_apply (alist
, (struct prefix
*) p
) == FILTER_DENY
)
366 if (IS_RIP_DEBUG_PACKET
)
367 zlog_debug ("%s/%d filtered by distribute %s",
368 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
373 if (dist
->prefix
[distribute
])
375 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[distribute
]);
379 if (prefix_list_apply (plist
,
380 (struct prefix
*) p
) == PREFIX_DENY
)
382 if (IS_RIP_DEBUG_PACKET
)
383 zlog_debug ("%s/%d filtered by prefix-list %s",
384 inet_ntoa (p
->prefix
), p
->prefixlen
, inout
);
393 /* Check nexthop address validity. */
395 rip_nexthop_check (struct in_addr
*addr
)
397 struct listnode
*node
;
398 struct listnode
*cnode
;
399 struct interface
*ifp
;
400 struct connected
*ifc
;
403 /* If nexthop address matches local configured address then it is
406 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
408 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, ifc
))
412 if (p
->family
== AF_INET
413 && IPV4_ADDR_SAME (&p
->u
.prefix4
, addr
))
420 /* RIP add route to routing table. */
422 rip_rte_process (struct rte
*rte
, struct sockaddr_in
*from
,
423 struct interface
*ifp
)
426 struct prefix_ipv4 p
;
427 struct route_node
*rp
;
428 struct rip_info
*rinfo
= NULL
, newinfo
;
429 struct rip_interface
*ri
;
430 struct in_addr
*nexthop
;
432 unsigned char old_dist
, new_dist
;
433 struct list
*list
= NULL
;
434 struct listnode
*node
= NULL
;
436 /* Make prefix structure. */
437 memset (&p
, 0, sizeof (struct prefix_ipv4
));
439 p
.prefix
= rte
->prefix
;
440 p
.prefixlen
= ip_masklen (rte
->mask
);
442 /* Make sure mask is applied. */
443 apply_mask_ipv4 (&p
);
445 /* Apply input filters. */
448 ret
= rip_filter (RIP_FILTER_IN
, &p
, ri
);
452 memset (&newinfo
, 0, sizeof (newinfo
));
453 newinfo
.type
= ZEBRA_ROUTE_RIP
;
454 newinfo
.sub_type
= RIP_ROUTE_RTE
;
455 newinfo
.nexthop
= rte
->nexthop
;
456 newinfo
.from
= from
->sin_addr
;
457 newinfo
.ifindex
= ifp
->ifindex
;
458 newinfo
.metric
= rte
->metric
;
459 newinfo
.metric_out
= rte
->metric
; /* XXX */
460 newinfo
.tag
= ntohs (rte
->tag
); /* XXX */
462 /* Modify entry according to the interface routemap. */
463 if (ri
->routemap
[RIP_FILTER_IN
])
467 /* The object should be of the type of rip_info */
468 ret
= route_map_apply (ri
->routemap
[RIP_FILTER_IN
],
469 (struct prefix
*) &p
, RMAP_RIP
, &newinfo
);
471 if (ret
== RMAP_DENYMATCH
)
473 if (IS_RIP_DEBUG_PACKET
)
474 zlog_debug ("RIP %s/%d is filtered by route-map in",
475 inet_ntoa (p
.prefix
), p
.prefixlen
);
479 /* Get back the object */
480 rte
->nexthop
= newinfo
.nexthop_out
;
481 rte
->tag
= htons (newinfo
.tag_out
); /* XXX */
482 rte
->metric
= newinfo
.metric_out
; /* XXX: the routemap uses the metric_out field */
485 /* Once the entry has been validated, update the metric by
486 adding the cost of the network on wich the message
487 arrived. If the result is greater than infinity, use infinity
488 (RFC2453 Sec. 3.9.2) */
489 /* Zebra ripd can handle offset-list in. */
490 ret
= rip_offset_list_apply_in (&p
, ifp
, &rte
->metric
);
492 /* If offset-list does not modify the metric use interface's
495 rte
->metric
+= ifp
->metric
? ifp
->metric
: 1;
497 if (rte
->metric
> RIP_METRIC_INFINITY
)
498 rte
->metric
= RIP_METRIC_INFINITY
;
500 /* Set nexthop pointer. */
501 if (rte
->nexthop
.s_addr
== 0)
502 nexthop
= &from
->sin_addr
;
504 nexthop
= &rte
->nexthop
;
506 /* Check if nexthop address is myself, then do nothing. */
507 if (rip_nexthop_check (nexthop
) < 0)
509 if (IS_RIP_DEBUG_PACKET
)
510 zlog_debug ("Nexthop address %s is myself", inet_ntoa (*nexthop
));
514 /* Get index for the prefix. */
515 rp
= route_node_get (rip
->table
, (struct prefix
*) &p
);
518 newinfo
.nexthop
= *nexthop
;
519 newinfo
.metric
= rte
->metric
;
520 newinfo
.tag
= ntohs (rte
->tag
);
521 newinfo
.distance
= rip_distance_apply (&newinfo
);
523 new_dist
= newinfo
.distance
? newinfo
.distance
: ZEBRA_RIP_DISTANCE_DEFAULT
;
525 /* Check to see whether there is already RIP route on the table. */
526 if ((list
= rp
->info
) != NULL
)
527 for (ALL_LIST_ELEMENTS_RO (list
, node
, rinfo
))
529 /* Need to compare with redistributed entry or local entry */
530 if (!rip_route_rte (rinfo
))
533 if (IPV4_ADDR_SAME (&rinfo
->from
, &from
->sin_addr
) &&
534 IPV4_ADDR_SAME (&rinfo
->nexthop
, nexthop
))
537 if (!listnextnode (node
))
539 /* Not found in the list */
541 if (rte
->metric
> rinfo
->metric
)
543 /* New route has a greater metric. Discard it. */
544 route_unlock_node (rp
);
548 if (rte
->metric
< rinfo
->metric
)
549 /* New route has a smaller metric. Replace the ECMP list
550 * with the new one in below. */
553 /* Metrics are same. We compare the distances. */
554 old_dist
= rinfo
->distance
? \
555 rinfo
->distance
: ZEBRA_RIP_DISTANCE_DEFAULT
;
557 if (new_dist
> old_dist
)
559 /* New route has a greater distance. Discard it. */
560 route_unlock_node (rp
);
564 if (new_dist
< old_dist
)
565 /* New route has a smaller distance. Replace the ECMP list
566 * with the new one in below. */
569 /* Metrics and distances are both same. Keep "rinfo" null and
570 * the new route is added in the ECMP list in below. */
576 /* Local static route. */
577 if (rinfo
->type
== ZEBRA_ROUTE_RIP
578 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
) ||
579 (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
))
580 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
582 route_unlock_node (rp
);
586 /* Redistributed route check. */
587 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
588 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
590 old_dist
= rinfo
->distance
;
591 /* Only routes directly connected to an interface (nexthop == 0)
592 * may have a valid NULL distance */
593 if (rinfo
->nexthop
.s_addr
!= 0)
594 old_dist
= old_dist
? old_dist
: ZEBRA_RIP_DISTANCE_DEFAULT
;
595 /* If imported route does not have STRICT precedence,
596 mark it as a ghost */
597 if (new_dist
<= old_dist
&& rte
->metric
!= RIP_METRIC_INFINITY
)
598 rip_ecmp_replace (&newinfo
);
600 route_unlock_node (rp
);
608 route_unlock_node (rp
);
610 /* Now, check to see whether there is already an explicit route
611 for the destination prefix. If there is no such route, add
612 this route to the routing table, unless the metric is
613 infinity (there is no point in adding a route which
615 if (rte
->metric
!= RIP_METRIC_INFINITY
)
616 rip_ecmp_add (&newinfo
);
620 /* Route is there but we are not sure the route is RIP or not. */
622 /* If there is an existing route, compare the next hop address
623 to the address of the router from which the datagram came.
624 If this datagram is from the same router as the existing
625 route, reinitialize the timeout. */
626 same
= (IPV4_ADDR_SAME (&rinfo
->from
, &from
->sin_addr
)
627 && (rinfo
->ifindex
== ifp
->ifindex
));
629 old_dist
= rinfo
->distance
? \
630 rinfo
->distance
: ZEBRA_RIP_DISTANCE_DEFAULT
;
632 /* Next, compare the metrics. If the datagram is from the same
633 router as the existing route, and the new metric is different
634 than the old one; or, if the new metric is lower than the old
635 one, or if the tag has been changed; or if there is a route
636 with a lower administrave distance; or an update of the
637 distance on the actual route; do the following actions: */
638 if ((same
&& rinfo
->metric
!= rte
->metric
)
639 || (rte
->metric
< rinfo
->metric
)
641 && (rinfo
->metric
== rte
->metric
)
642 && (newinfo
.tag
!= rinfo
->tag
))
643 || (old_dist
> new_dist
)
644 || ((old_dist
!= new_dist
) && same
))
646 if (listcount (list
) == 1)
648 if (newinfo
.metric
!= RIP_METRIC_INFINITY
)
649 rip_ecmp_replace (&newinfo
);
651 rip_ecmp_delete (rinfo
);
655 if (newinfo
.metric
< rinfo
->metric
)
656 rip_ecmp_replace (&newinfo
);
657 else if (newinfo
.metric
> rinfo
->metric
)
658 rip_ecmp_delete (rinfo
);
659 else if (new_dist
< old_dist
)
660 rip_ecmp_replace (&newinfo
);
661 else if (new_dist
> old_dist
)
662 rip_ecmp_delete (rinfo
);
665 int update
= CHECK_FLAG (rinfo
->flags
, RIP_RTF_FIB
) ? 1 : 0;
667 assert (newinfo
.metric
!= RIP_METRIC_INFINITY
);
669 RIP_TIMER_OFF (rinfo
->t_timeout
);
670 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
671 memcpy (rinfo
, &newinfo
, sizeof (struct rip_info
));
672 rip_timeout_update (rinfo
);
675 rip_zebra_ipv4_add (rp
);
677 /* - Set the route change flag on the first entry. */
678 rinfo
= listgetdata (listhead (list
));
679 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
680 rip_event (RIP_TRIGGERED_UPDATE
, 0);
684 else /* same & no change */
685 rip_timeout_update (rinfo
);
687 /* Unlock tempolary lock of the route. */
688 route_unlock_node (rp
);
692 /* Dump RIP packet */
694 rip_packet_dump (struct rip_packet
*packet
, int size
, const char *sndrcv
)
698 const char *command_str
;
699 char pbuf
[BUFSIZ
], nbuf
[BUFSIZ
];
703 /* Set command string. */
704 if (packet
->command
> 0 && packet
->command
< RIP_COMMAND_MAX
)
705 command_str
= lookup (rip_msg
, packet
->command
);
707 command_str
= "unknown";
709 /* Dump packet header. */
710 zlog_debug ("%s %s version %d packet size %d",
711 sndrcv
, command_str
, packet
->version
, size
);
713 /* Dump each routing table entry. */
716 for (lim
= (caddr_t
) packet
+ size
; (caddr_t
) rte
< lim
; rte
++)
718 if (packet
->version
== RIPv2
)
720 netmask
= ip_masklen (rte
->mask
);
722 if (rte
->family
== htons (RIP_FAMILY_AUTH
))
724 if (rte
->tag
== htons (RIP_AUTH_SIMPLE_PASSWORD
))
726 p
= (u_char
*)&rte
->prefix
;
728 zlog_debug (" family 0x%X type %d auth string: %s",
729 ntohs (rte
->family
), ntohs (rte
->tag
), p
);
731 else if (rte
->tag
== htons (RIP_AUTH_MD5
))
733 struct rip_md5_info
*md5
;
735 md5
= (struct rip_md5_info
*) &packet
->rte
;
737 zlog_debug (" family 0x%X type %d (MD5 authentication)",
738 ntohs (md5
->family
), ntohs (md5
->type
));
739 zlog_debug (" RIP-2 packet len %d Key ID %d"
741 ntohs (md5
->packet_len
), md5
->keyid
,
743 zlog_debug (" Sequence Number %ld",
744 (u_long
) ntohl (md5
->sequence
));
746 else if (rte
->tag
== htons (RIP_AUTH_DATA
))
748 p
= (u_char
*)&rte
->prefix
;
750 zlog_debug (" family 0x%X type %d (MD5 data)",
751 ntohs (rte
->family
), ntohs (rte
->tag
));
752 zlog_debug (" MD5: %02X%02X%02X%02X%02X%02X%02X%02X"
753 "%02X%02X%02X%02X%02X%02X%02X%02X",
754 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6],
755 p
[7], p
[8], p
[9], p
[10], p
[11], p
[12], p
[13],
760 zlog_debug (" family 0x%X type %d (Unknown auth type)",
761 ntohs (rte
->family
), ntohs (rte
->tag
));
765 zlog_debug (" %s/%d -> %s family %d tag %"ROUTE_TAG_PRI
" metric %ld",
766 inet_ntop (AF_INET
, &rte
->prefix
, pbuf
, BUFSIZ
),
767 netmask
, inet_ntop (AF_INET
, &rte
->nexthop
, nbuf
,
768 BUFSIZ
), ntohs (rte
->family
),
769 (route_tag_t
)ntohs (rte
->tag
),
770 (u_long
) ntohl (rte
->metric
));
774 zlog_debug (" %s family %d tag %"ROUTE_TAG_PRI
" metric %ld",
775 inet_ntop (AF_INET
, &rte
->prefix
, pbuf
, BUFSIZ
),
776 ntohs (rte
->family
), (route_tag_t
)ntohs (rte
->tag
),
777 (u_long
)ntohl (rte
->metric
));
782 /* Check if the destination address is valid (unicast; not net 0
783 or 127) (RFC2453 Section 3.9.2 - Page 26). But we don't
784 check net 0 because we accept default route. */
786 rip_destination_check (struct in_addr addr
)
788 u_int32_t destination
;
790 /* Convert to host byte order. */
791 destination
= ntohl (addr
.s_addr
);
793 if (IPV4_NET127 (destination
))
796 /* Net 0 may match to the default route. */
797 if (IPV4_NET0 (destination
) && destination
!= 0)
800 /* Unicast address must belong to class A, B, C. */
801 if (IN_CLASSA (destination
))
803 if (IN_CLASSB (destination
))
805 if (IN_CLASSC (destination
))
811 /* RIP version 2 authentication. */
813 rip_auth_simple_password (struct rte
*rte
, struct sockaddr_in
*from
,
814 struct interface
*ifp
)
816 struct rip_interface
*ri
;
817 char *auth_str
= (char *) &rte
->prefix
;
820 /* reject passwords with zeros in the middle of the string */
821 for (i
= strlen (auth_str
); i
< 16; i
++)
823 if (auth_str
[i
] != '\0')
827 if (IS_RIP_DEBUG_EVENT
)
828 zlog_debug ("RIPv2 simple password authentication from %s",
829 inet_ntoa (from
->sin_addr
));
833 if (ri
->auth_type
!= RIP_AUTH_SIMPLE_PASSWORD
834 || rte
->tag
!= htons(RIP_AUTH_SIMPLE_PASSWORD
))
837 /* Simple password authentication. */
840 if (strncmp (auth_str
, ri
->auth_str
, 16) == 0)
845 struct keychain
*keychain
;
848 keychain
= keychain_lookup (ri
->key_chain
);
849 if (keychain
== NULL
)
852 key
= key_match_for_accept (keychain
, auth_str
);
859 /* RIP version 2 authentication with MD5. */
861 rip_auth_md5 (struct rip_packet
*packet
, struct sockaddr_in
*from
,
862 int length
, struct interface
*ifp
)
864 struct rip_interface
*ri
;
865 struct rip_md5_info
*md5
;
866 struct rip_md5_data
*md5data
;
867 struct keychain
*keychain
;
870 u_char digest
[RIP_AUTH_MD5_SIZE
];
871 u_int16_t packet_len
;
872 char auth_str
[RIP_AUTH_MD5_SIZE
];
874 if (IS_RIP_DEBUG_EVENT
)
875 zlog_debug ("RIPv2 MD5 authentication from %s",
876 inet_ntoa (from
->sin_addr
));
879 md5
= (struct rip_md5_info
*) &packet
->rte
;
881 /* Check auth type. */
882 if (ri
->auth_type
!= RIP_AUTH_MD5
|| md5
->type
!= htons(RIP_AUTH_MD5
))
885 /* If the authentication length is less than 16, then it must be wrong for
886 * any interpretation of rfc2082. Some implementations also interpret
887 * this as RIP_HEADER_SIZE+ RIP_AUTH_MD5_SIZE, aka RIP_AUTH_MD5_COMPAT_SIZE.
889 if ( !((md5
->auth_len
== RIP_AUTH_MD5_SIZE
)
890 || (md5
->auth_len
== RIP_AUTH_MD5_COMPAT_SIZE
)))
892 if (IS_RIP_DEBUG_EVENT
)
893 zlog_debug ("RIPv2 MD5 authentication, strange authentication "
894 "length field %d", md5
->auth_len
);
898 /* grab and verify check packet length */
899 packet_len
= ntohs (md5
->packet_len
);
901 if (packet_len
> (length
- RIP_HEADER_SIZE
- RIP_AUTH_MD5_SIZE
))
903 if (IS_RIP_DEBUG_EVENT
)
904 zlog_debug ("RIPv2 MD5 authentication, packet length field %d "
905 "greater than received length %d!",
906 md5
->packet_len
, length
);
910 /* retrieve authentication data */
911 md5data
= (struct rip_md5_data
*) (((u_char
*) packet
) + packet_len
);
913 memset (auth_str
, 0, RIP_AUTH_MD5_SIZE
);
917 keychain
= keychain_lookup (ri
->key_chain
);
918 if (keychain
== NULL
)
921 key
= key_lookup_for_accept (keychain
, md5
->keyid
);
925 strncpy (auth_str
, key
->string
, RIP_AUTH_MD5_SIZE
);
927 else if (ri
->auth_str
)
928 strncpy (auth_str
, ri
->auth_str
, RIP_AUTH_MD5_SIZE
);
930 if (auth_str
[0] == 0)
933 /* MD5 digest authentication. */
934 memset (&ctx
, 0, sizeof(ctx
));
936 MD5Update(&ctx
, packet
, packet_len
+ RIP_HEADER_SIZE
);
937 MD5Update(&ctx
, auth_str
, RIP_AUTH_MD5_SIZE
);
938 MD5Final(digest
, &ctx
);
940 if (memcmp (md5data
->digest
, digest
, RIP_AUTH_MD5_SIZE
) == 0)
946 /* Pick correct auth string for sends, prepare auth_str buffer for use.
947 * (left justified and padded).
949 * presumes one of ri or key is valid, and that the auth strings they point
950 * to are nul terminated. If neither are present, auth_str will be fully
955 rip_auth_prepare_str_send (struct rip_interface
*ri
, struct key
*key
,
956 char *auth_str
, int len
)
960 memset (auth_str
, 0, len
);
961 if (key
&& key
->string
)
962 strncpy (auth_str
, key
->string
, len
);
963 else if (ri
->auth_str
)
964 strncpy (auth_str
, ri
->auth_str
, len
);
969 /* Write RIPv2 simple password authentication information
971 * auth_str is presumed to be 2 bytes and correctly prepared
972 * (left justified and zero padded).
975 rip_auth_simple_write (struct stream
*s
, char *auth_str
, int len
)
977 assert (s
&& len
== RIP_AUTH_SIMPLE_SIZE
);
979 stream_putw (s
, RIP_FAMILY_AUTH
);
980 stream_putw (s
, RIP_AUTH_SIMPLE_PASSWORD
);
981 stream_put (s
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
986 /* write RIPv2 MD5 "authentication header"
987 * (uses the auth key data field)
989 * Digest offset field is set to 0.
991 * returns: offset of the digest offset field, which must be set when
992 * length to the auth-data MD5 digest is known.
995 rip_auth_md5_ah_write (struct stream
*s
, struct rip_interface
*ri
,
1000 assert (s
&& ri
&& ri
->auth_type
== RIP_AUTH_MD5
);
1002 /* MD5 authentication. */
1003 stream_putw (s
, RIP_FAMILY_AUTH
);
1004 stream_putw (s
, RIP_AUTH_MD5
);
1006 /* MD5 AH digest offset field.
1008 * Set to placeholder value here, to true value when RIP-2 Packet length
1009 * is known. Actual value is set in .....().
1011 doff
= stream_get_endp(s
);
1016 stream_putc (s
, key
->index
% 256);
1020 /* Auth Data Len. Set 16 for MD5 authentication data. Older ripds
1021 * however expect RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE so we allow for this
1022 * to be configurable.
1024 stream_putc (s
, ri
->md5_auth_len
);
1026 /* Sequence Number (non-decreasing). */
1027 /* RFC2080: The value used in the sequence number is
1028 arbitrary, but two suggestions are the time of the
1029 message's creation or a simple message counter. */
1030 stream_putl (s
, time (NULL
));
1032 /* Reserved field must be zero. */
1039 /* If authentication is in used, write the appropriate header
1040 * returns stream offset to which length must later be written
1041 * or 0 if this is not required
1044 rip_auth_header_write (struct stream
*s
, struct rip_interface
*ri
,
1045 struct key
*key
, char *auth_str
, int len
)
1047 assert (ri
->auth_type
!= RIP_NO_AUTH
);
1049 switch (ri
->auth_type
)
1051 case RIP_AUTH_SIMPLE_PASSWORD
:
1052 rip_auth_prepare_str_send (ri
, key
, auth_str
, len
);
1053 rip_auth_simple_write (s
, auth_str
, len
);
1056 return rip_auth_md5_ah_write (s
, ri
, key
);
1062 /* Write RIPv2 MD5 authentication data trailer */
1064 rip_auth_md5_set (struct stream
*s
, struct rip_interface
*ri
, size_t doff
,
1065 char *auth_str
, int authlen
)
1069 unsigned char digest
[RIP_AUTH_MD5_SIZE
];
1071 /* Make it sure this interface is configured as MD5
1073 assert ((ri
->auth_type
== RIP_AUTH_MD5
) && (authlen
== RIP_AUTH_MD5_SIZE
));
1076 /* Get packet length. */
1077 len
= stream_get_endp(s
);
1079 /* Check packet length. */
1080 if (len
< (RIP_HEADER_SIZE
+ RIP_RTE_SIZE
))
1082 zlog_err ("rip_auth_md5_set(): packet length %ld is less than minimum length.", len
);
1086 /* Set the digest offset length in the header */
1087 stream_putw_at (s
, doff
, len
);
1089 /* Set authentication data. */
1090 stream_putw (s
, RIP_FAMILY_AUTH
);
1091 stream_putw (s
, RIP_AUTH_DATA
);
1093 /* Generate a digest for the RIP packet. */
1094 memset(&ctx
, 0, sizeof(ctx
));
1096 MD5Update(&ctx
, STREAM_DATA (s
), stream_get_endp (s
));
1097 MD5Update(&ctx
, auth_str
, RIP_AUTH_MD5_SIZE
);
1098 MD5Final(digest
, &ctx
);
1100 /* Copy the digest to the packet. */
1101 stream_write (s
, digest
, RIP_AUTH_MD5_SIZE
);
1104 /* RIP routing information. */
1106 rip_response_process (struct rip_packet
*packet
, int size
,
1107 struct sockaddr_in
*from
, struct connected
*ifc
)
1111 struct prefix_ipv4 ifaddr
;
1112 struct prefix_ipv4 ifaddrclass
;
1115 memset(&ifaddr
, 0, sizeof(ifaddr
));
1116 /* We don't know yet. */
1119 /* The Response must be ignored if it is not from the RIP
1120 port. (RFC2453 - Sec. 3.9.2)*/
1121 if (from
->sin_port
!= htons(RIP_PORT_DEFAULT
))
1123 zlog_info ("response doesn't come from RIP port: %d",
1125 rip_peer_bad_packet (from
);
1129 /* The datagram's IPv4 source address should be checked to see
1130 whether the datagram is from a valid neighbor; the source of the
1131 datagram must be on a directly connected network (RFC2453 - Sec. 3.9.2) */
1132 if (if_lookup_address((void *)&from
->sin_addr
, AF_INET
, VRF_DEFAULT
) == NULL
)
1134 zlog_info ("This datagram doesn't came from a valid neighbor: %s",
1135 inet_ntoa (from
->sin_addr
));
1136 rip_peer_bad_packet (from
);
1140 /* It is also worth checking to see whether the response is from one
1141 of the router's own addresses. */
1143 ; /* Alredy done in rip_read () */
1145 /* Update RIP peer. */
1146 rip_peer_update (from
, packet
->version
);
1148 /* Set RTE pointer. */
1151 for (lim
= (caddr_t
) packet
+ size
; (caddr_t
) rte
< lim
; rte
++)
1153 /* RIPv2 authentication check. */
1154 /* If the Address Family Identifier of the first (and only the
1155 first) entry in the message is 0xFFFF, then the remainder of
1156 the entry contains the authentication. */
1157 /* If the packet gets here it means authentication enabled */
1158 /* Check is done in rip_read(). So, just skipping it */
1159 if (packet
->version
== RIPv2
&&
1160 rte
== packet
->rte
&&
1161 rte
->family
== htons(RIP_FAMILY_AUTH
))
1164 if (rte
->family
!= htons(AF_INET
))
1166 /* Address family check. RIP only supports AF_INET. */
1167 zlog_info ("Unsupported family %d from %s.",
1168 ntohs (rte
->family
), inet_ntoa (from
->sin_addr
));
1172 /* - is the destination address valid (e.g., unicast; not net 0
1174 if (! rip_destination_check (rte
->prefix
))
1176 zlog_info ("Network is net 0 or net 127 or it is not unicast network");
1177 rip_peer_bad_route (from
);
1181 /* Convert metric value to host byte order. */
1182 rte
->metric
= ntohl (rte
->metric
);
1184 /* - is the metric valid (i.e., between 1 and 16, inclusive) */
1185 if (! (rte
->metric
>= 1 && rte
->metric
<= 16))
1187 zlog_info ("Route's metric is not in the 1-16 range.");
1188 rip_peer_bad_route (from
);
1192 /* RIPv1 does not have nexthop value. */
1193 if (packet
->version
== RIPv1
&& rte
->nexthop
.s_addr
!= 0)
1195 zlog_info ("RIPv1 packet with nexthop value %s",
1196 inet_ntoa (rte
->nexthop
));
1197 rip_peer_bad_route (from
);
1201 /* That is, if the provided information is ignored, a possibly
1202 sub-optimal, but absolutely valid, route may be taken. If
1203 the received Next Hop is not directly reachable, it should be
1204 treated as 0.0.0.0. */
1205 if (packet
->version
== RIPv2
&& rte
->nexthop
.s_addr
!= 0)
1209 /* Multicast address check. */
1210 addrval
= ntohl (rte
->nexthop
.s_addr
);
1211 if (IN_CLASSD (addrval
))
1213 zlog_info ("Nexthop %s is multicast address, skip this rte",
1214 inet_ntoa (rte
->nexthop
));
1218 if (! if_lookup_address ((void *)&rte
->nexthop
, AF_INET
, VRF_DEFAULT
))
1220 struct route_node
*rn
;
1221 struct rip_info
*rinfo
;
1223 rn
= route_node_match_ipv4 (rip
->table
, &rte
->nexthop
);
1229 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1230 && rinfo
->sub_type
== RIP_ROUTE_RTE
)
1232 if (IS_RIP_DEBUG_EVENT
)
1233 zlog_debug ("Next hop %s is on RIP network. Set nexthop to the packet's originator", inet_ntoa (rte
->nexthop
));
1234 rte
->nexthop
= rinfo
->from
;
1238 if (IS_RIP_DEBUG_EVENT
)
1239 zlog_debug ("Next hop %s is not directly reachable. Treat it as 0.0.0.0", inet_ntoa (rte
->nexthop
));
1240 rte
->nexthop
.s_addr
= 0;
1243 route_unlock_node (rn
);
1247 if (IS_RIP_DEBUG_EVENT
)
1248 zlog_debug ("Next hop %s is not directly reachable. Treat it as 0.0.0.0", inet_ntoa (rte
->nexthop
));
1249 rte
->nexthop
.s_addr
= 0;
1255 /* For RIPv1, there won't be a valid netmask.
1257 This is a best guess at the masks. If everyone was using old
1258 Ciscos before the 'ip subnet zero' option, it would be almost
1261 Cisco summarize ripv1 advertisments to the classful boundary
1262 (/16 for class B's) except when the RIP packet does to inside
1263 the classful network in question. */
1265 if ((packet
->version
== RIPv1
&& rte
->prefix
.s_addr
!= 0)
1266 || (packet
->version
== RIPv2
1267 && (rte
->prefix
.s_addr
!= 0 && rte
->mask
.s_addr
== 0)))
1269 u_int32_t destination
;
1271 if (subnetted
== -1)
1273 memcpy (&ifaddr
, ifc
->address
, sizeof (struct prefix_ipv4
));
1274 memcpy (&ifaddrclass
, &ifaddr
, sizeof (struct prefix_ipv4
));
1275 apply_classful_mask_ipv4 (&ifaddrclass
);
1277 if (ifaddr
.prefixlen
> ifaddrclass
.prefixlen
)
1281 destination
= ntohl (rte
->prefix
.s_addr
);
1283 if (IN_CLASSA (destination
))
1284 masklen2ip (8, &rte
->mask
);
1285 else if (IN_CLASSB (destination
))
1286 masklen2ip (16, &rte
->mask
);
1287 else if (IN_CLASSC (destination
))
1288 masklen2ip (24, &rte
->mask
);
1291 masklen2ip (ifaddrclass
.prefixlen
,
1292 (struct in_addr
*) &destination
);
1293 if ((subnetted
== 1) && ((rte
->prefix
.s_addr
& destination
) ==
1294 ifaddrclass
.prefix
.s_addr
))
1296 masklen2ip (ifaddr
.prefixlen
, &rte
->mask
);
1297 if ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
) != rte
->prefix
.s_addr
)
1298 masklen2ip (32, &rte
->mask
);
1299 if (IS_RIP_DEBUG_EVENT
)
1300 zlog_debug ("Subnetted route %s", inet_ntoa (rte
->prefix
));
1304 if ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
) != rte
->prefix
.s_addr
)
1308 if (IS_RIP_DEBUG_EVENT
)
1310 zlog_debug ("Resultant route %s", inet_ntoa (rte
->prefix
));
1311 zlog_debug ("Resultant mask %s", inet_ntoa (rte
->mask
));
1315 /* In case of RIPv2, if prefix in RTE is not netmask applied one
1316 ignore the entry. */
1317 if ((packet
->version
== RIPv2
)
1318 && (rte
->mask
.s_addr
!= 0)
1319 && ((rte
->prefix
.s_addr
& rte
->mask
.s_addr
) != rte
->prefix
.s_addr
))
1321 zlog_warn ("RIPv2 address %s is not mask /%d applied one",
1322 inet_ntoa (rte
->prefix
), ip_masklen (rte
->mask
));
1323 rip_peer_bad_route (from
);
1327 /* Default route's netmask is ignored. */
1328 if (packet
->version
== RIPv2
1329 && (rte
->prefix
.s_addr
== 0)
1330 && (rte
->mask
.s_addr
!= 0))
1332 if (IS_RIP_DEBUG_EVENT
)
1333 zlog_debug ("Default route with non-zero netmask. Set zero to netmask");
1334 rte
->mask
.s_addr
= 0;
1337 /* Routing table updates. */
1338 rip_rte_process (rte
, from
, ifc
->ifp
);
1342 /* Make socket for RIP protocol. */
1344 rip_create_socket (void)
1348 struct sockaddr_in addr
;
1350 memset (&addr
, 0, sizeof (struct sockaddr_in
));
1351 addr
.sin_family
= AF_INET
;
1352 addr
.sin_addr
.s_addr
= INADDR_ANY
;
1353 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1354 addr
.sin_len
= sizeof (struct sockaddr_in
);
1355 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1356 /* sending port must always be the RIP port */
1357 addr
.sin_port
= htons (RIP_PORT_DEFAULT
);
1359 /* Make datagram socket. */
1360 sock
= socket (AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
1363 zlog_err("Cannot create UDP socket: %s", safe_strerror(errno
));
1367 sockopt_broadcast (sock
);
1368 sockopt_reuseaddr (sock
);
1369 sockopt_reuseport (sock
);
1370 setsockopt_ipv4_multicast_loop (sock
, 0);
1372 setsockopt_pktinfo (sock
);
1373 #endif /* RIP_RECVMSG */
1374 #ifdef IPTOS_PREC_INTERNETCONTROL
1375 setsockopt_ipv4_tos (sock
, IPTOS_PREC_INTERNETCONTROL
);
1378 if (ripd_privs
.change (ZPRIVS_RAISE
))
1379 zlog_err ("rip_create_socket: could not raise privs");
1380 setsockopt_so_recvbuf (sock
, RIP_UDP_RCV_BUF
);
1381 if ( (ret
= bind (sock
, (struct sockaddr
*) & addr
, sizeof (addr
))) < 0)
1384 int save_errno
= errno
;
1385 if (ripd_privs
.change (ZPRIVS_LOWER
))
1386 zlog_err ("rip_create_socket: could not lower privs");
1388 zlog_err("%s: Can't bind socket %d to %s port %d: %s", __func__
,
1389 sock
, inet_ntoa(addr
.sin_addr
),
1390 (int) ntohs(addr
.sin_port
),
1391 safe_strerror(save_errno
));
1397 if (ripd_privs
.change (ZPRIVS_LOWER
))
1398 zlog_err ("rip_create_socket: could not lower privs");
1403 /* RIP packet send to destination address, on interface denoted by
1404 * by connected argument. NULL to argument denotes destination should be
1405 * should be RIP multicast group
1408 rip_send_packet (u_char
* buf
, int size
, struct sockaddr_in
*to
,
1409 struct connected
*ifc
)
1412 struct sockaddr_in sin
;
1414 assert (ifc
!= NULL
);
1416 if (IS_RIP_DEBUG_PACKET
)
1418 #define ADDRESS_SIZE 20
1419 char dst
[ADDRESS_SIZE
];
1420 dst
[ADDRESS_SIZE
- 1] = '\0';
1424 strncpy (dst
, inet_ntoa(to
->sin_addr
), ADDRESS_SIZE
- 1);
1428 sin
.sin_addr
.s_addr
= htonl (INADDR_RIP_GROUP
);
1429 strncpy (dst
, inet_ntoa(sin
.sin_addr
), ADDRESS_SIZE
- 1);
1432 zlog_debug("rip_send_packet %s > %s (%s)",
1433 inet_ntoa(ifc
->address
->u
.prefix4
),
1434 dst
, ifc
->ifp
->name
);
1437 if ( CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
) )
1440 * ZEBRA_IFA_SECONDARY is set on linux when an interface is configured
1441 * with multiple addresses on the same subnet: the first address
1442 * on the subnet is configured "primary", and all subsequent addresses
1443 * on that subnet are treated as "secondary" addresses.
1444 * In order to avoid routing-table bloat on other rip listeners,
1445 * we do not send out RIP packets with ZEBRA_IFA_SECONDARY source addrs.
1446 * XXX Since Linux is the only system for which the ZEBRA_IFA_SECONDARY
1447 * flag is set, we would end up sending a packet for a "secondary"
1448 * source address on non-linux systems.
1450 if (IS_RIP_DEBUG_PACKET
)
1451 zlog_debug("duplicate dropped");
1455 /* Make destination address. */
1456 memset (&sin
, 0, sizeof (struct sockaddr_in
));
1457 sin
.sin_family
= AF_INET
;
1458 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1459 sin
.sin_len
= sizeof (struct sockaddr_in
);
1460 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1462 /* When destination is specified, use it's port and address. */
1465 sin
.sin_port
= to
->sin_port
;
1466 sin
.sin_addr
= to
->sin_addr
;
1470 sin
.sin_port
= htons (RIP_PORT_DEFAULT
);
1471 sin
.sin_addr
.s_addr
= htonl (INADDR_RIP_GROUP
);
1473 rip_interface_multicast_set (rip
->sock
, ifc
);
1476 ret
= sendto (rip
->sock
, buf
, size
, 0, (struct sockaddr
*)&sin
,
1477 sizeof (struct sockaddr_in
));
1479 if (IS_RIP_DEBUG_EVENT
)
1480 zlog_debug ("SEND to %s.%d", inet_ntoa(sin
.sin_addr
),
1481 ntohs (sin
.sin_port
));
1484 zlog_warn ("can't send packet : %s", safe_strerror (errno
));
1489 /* Add redistributed route to RIP table. */
1491 rip_redistribute_add (int type
, int sub_type
, struct prefix_ipv4
*p
,
1492 ifindex_t ifindex
, struct in_addr
*nexthop
,
1493 unsigned int metric
, unsigned char distance
,
1497 struct route_node
*rp
= NULL
;
1498 struct rip_info
*rinfo
= NULL
, newinfo
;
1499 struct list
*list
= NULL
;
1501 /* Redistribute route */
1502 ret
= rip_destination_check (p
->prefix
);
1506 rp
= route_node_get (rip
->table
, (struct prefix
*) p
);
1508 memset (&newinfo
, 0, sizeof (struct rip_info
));
1509 newinfo
.type
= type
;
1510 newinfo
.sub_type
= sub_type
;
1511 newinfo
.ifindex
= ifindex
;
1513 newinfo
.external_metric
= metric
;
1514 newinfo
.distance
= distance
;
1515 if (tag
<= UINT16_MAX
) /* RIP only supports 16 bit tags */
1519 newinfo
.nexthop
= *nexthop
;
1521 if ((list
= rp
->info
) != NULL
&& listcount (list
) != 0)
1523 rinfo
= listgetdata (listhead (list
));
1525 if (rinfo
->type
== ZEBRA_ROUTE_CONNECT
1526 && rinfo
->sub_type
== RIP_ROUTE_INTERFACE
1527 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
1529 route_unlock_node (rp
);
1533 /* Manually configured RIP route check. */
1534 if (rinfo
->type
== ZEBRA_ROUTE_RIP
1535 && ((rinfo
->sub_type
== RIP_ROUTE_STATIC
) ||
1536 (rinfo
->sub_type
== RIP_ROUTE_DEFAULT
)) )
1538 if (type
!= ZEBRA_ROUTE_RIP
|| ((sub_type
!= RIP_ROUTE_STATIC
) &&
1539 (sub_type
!= RIP_ROUTE_DEFAULT
)))
1541 route_unlock_node (rp
);
1546 rinfo
= rip_ecmp_replace (&newinfo
);
1547 route_unlock_node (rp
);
1550 rinfo
= rip_ecmp_add (&newinfo
);
1552 if (IS_RIP_DEBUG_EVENT
) {
1554 zlog_debug ("Redistribute new prefix %s/%d on the interface %s",
1555 inet_ntoa(p
->prefix
), p
->prefixlen
,
1556 ifindex2ifname(ifindex
, VRF_DEFAULT
));
1558 zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
1559 inet_ntoa(p
->prefix
), p
->prefixlen
, inet_ntoa(rinfo
->nexthop
),
1560 ifindex2ifname(ifindex
, VRF_DEFAULT
));
1563 rip_event (RIP_TRIGGERED_UPDATE
, 0);
1566 /* Delete redistributed route from RIP table. */
1568 rip_redistribute_delete (int type
, int sub_type
, struct prefix_ipv4
*p
,
1572 struct route_node
*rp
;
1573 struct rip_info
*rinfo
;
1575 ret
= rip_destination_check (p
->prefix
);
1579 rp
= route_node_lookup (rip
->table
, (struct prefix
*) p
);
1582 struct list
*list
= rp
->info
;
1584 if (list
!= NULL
&& listcount (list
) != 0)
1586 rinfo
= listgetdata (listhead (list
));
1588 && rinfo
->type
== type
1589 && rinfo
->sub_type
== sub_type
1590 && rinfo
->ifindex
== ifindex
)
1592 /* Perform poisoned reverse. */
1593 rinfo
->metric
= RIP_METRIC_INFINITY
;
1594 RIP_TIMER_ON (rinfo
->t_garbage_collect
,
1595 rip_garbage_collect
, rip
->garbage_time
);
1596 RIP_TIMER_OFF (rinfo
->t_timeout
);
1597 rinfo
->flags
|= RIP_RTF_CHANGED
;
1599 if (IS_RIP_DEBUG_EVENT
)
1600 zlog_debug ("Poisone %s/%d on the interface %s with an "
1601 "infinity metric [delete]",
1602 inet_ntoa(p
->prefix
), p
->prefixlen
,
1603 ifindex2ifname(ifindex
, VRF_DEFAULT
));
1605 rip_event (RIP_TRIGGERED_UPDATE
, 0);
1608 route_unlock_node (rp
);
1612 /* Response to request called from rip_read ().*/
1614 rip_request_process (struct rip_packet
*packet
, int size
,
1615 struct sockaddr_in
*from
, struct connected
*ifc
)
1619 struct prefix_ipv4 p
;
1620 struct route_node
*rp
;
1621 struct rip_info
*rinfo
;
1622 struct rip_interface
*ri
;
1624 /* Does not reponse to the requests on the loopback interfaces */
1625 if (if_is_loopback (ifc
->ifp
))
1628 /* Check RIP process is enabled on this interface. */
1629 ri
= ifc
->ifp
->info
;
1633 /* When passive interface is specified, suppress responses */
1637 /* RIP peer update. */
1638 rip_peer_update (from
, packet
->version
);
1640 lim
= ((caddr_t
) packet
) + size
;
1643 /* The Request is processed entry by entry. If there are no
1644 entries, no response is given. */
1645 if (lim
== (caddr_t
) rte
)
1648 /* There is one special case. If there is exactly one entry in the
1649 request, and it has an address family identifier of zero and a
1650 metric of infinity (i.e., 16), then this is a request to send the
1651 entire routing table. */
1652 if (lim
== ((caddr_t
) (rte
+ 1)) &&
1653 ntohs (rte
->family
) == 0 &&
1654 ntohl (rte
->metric
) == RIP_METRIC_INFINITY
)
1656 /* All route with split horizon */
1657 rip_output_process (ifc
, from
, rip_all_route
, packet
->version
);
1661 if (ntohs (rte
->family
) != AF_INET
)
1664 /* Examine the list of RTEs in the Request one by one. For each
1665 entry, look up the destination in the router's routing
1666 database and, if there is a route, put that route's metric in
1667 the metric field of the RTE. If there is no explicit route
1668 to the specified destination, put infinity in the metric
1669 field. Once all the entries have been filled in, change the
1670 command from Request to Response and send the datagram back
1671 to the requestor. */
1674 for (; ((caddr_t
) rte
) < lim
; rte
++)
1676 p
.prefix
= rte
->prefix
;
1677 p
.prefixlen
= ip_masklen (rte
->mask
);
1678 apply_mask_ipv4 (&p
);
1680 rp
= route_node_lookup (rip
->table
, (struct prefix
*) &p
);
1683 rinfo
= listgetdata (listhead ((struct list
*)rp
->info
));
1684 rte
->metric
= htonl (rinfo
->metric
);
1685 route_unlock_node (rp
);
1688 rte
->metric
= htonl (RIP_METRIC_INFINITY
);
1690 packet
->command
= RIP_RESPONSE
;
1692 rip_send_packet ((u_char
*)packet
, size
, from
, ifc
);
1694 rip_global_queries
++;
1698 /* Set IPv6 packet info to the socket. */
1700 setsockopt_pktinfo (int sock
)
1705 ret
= setsockopt(sock
, IPPROTO_IP
, IP_PKTINFO
, &val
, sizeof(val
));
1707 zlog_warn ("Can't setsockopt IP_PKTINFO : %s", safe_strerror (errno
));
1711 /* Read RIP packet by recvmsg function. */
1713 rip_recvmsg (int sock
, u_char
*buf
, int size
, struct sockaddr_in
*from
,
1719 struct cmsghdr
*ptr
;
1722 msg
.msg_name
= (void *) from
;
1723 msg
.msg_namelen
= sizeof (struct sockaddr_in
);
1726 msg
.msg_control
= (void *) adata
;
1727 msg
.msg_controllen
= sizeof adata
;
1731 ret
= recvmsg (sock
, &msg
, 0);
1735 for (ptr
= ZCMSG_FIRSTHDR(&msg
); ptr
!= NULL
; ptr
= CMSG_NXTHDR(&msg
, ptr
))
1736 if (ptr
->cmsg_level
== IPPROTO_IP
&& ptr
->cmsg_type
== IP_PKTINFO
)
1738 struct in_pktinfo
*pktinfo
;
1741 pktinfo
= (struct in_pktinfo
*) CMSG_DATA (ptr
);
1742 i
= pktinfo
->ipi_ifindex
;
1747 /* RIP packet read function. */
1749 rip_read_new (struct thread
*t
)
1753 char buf
[RIP_PACKET_MAXSIZ
];
1754 struct sockaddr_in from
;
1757 /* Fetch socket then register myself. */
1758 sock
= THREAD_FD (t
);
1759 rip_event (RIP_READ
, sock
);
1761 /* Read RIP packet. */
1762 ret
= rip_recvmsg (sock
, buf
, RIP_PACKET_MAXSIZ
, &from
, (int *)&ifindex
);
1765 zlog_warn ("Can't read RIP packet: %s", safe_strerror (errno
));
1771 #endif /* RIP_RECVMSG */
1773 /* First entry point of RIP packet. */
1775 rip_read (struct thread
*t
)
1780 union rip_buf rip_buf
;
1781 struct rip_packet
*packet
;
1782 struct sockaddr_in from
;
1786 struct interface
*ifp
= NULL
;
1787 struct connected
*ifc
;
1788 struct rip_interface
*ri
;
1791 /* Fetch socket then register myself. */
1792 sock
= THREAD_FD (t
);
1795 /* Add myself to tne next event */
1796 rip_event (RIP_READ
, sock
);
1798 /* RIPd manages only IPv4. */
1799 memset (&from
, 0, sizeof (struct sockaddr_in
));
1800 fromlen
= sizeof (struct sockaddr_in
);
1802 len
= recvfrom (sock
, (char *)&rip_buf
.buf
, sizeof (rip_buf
.buf
), 0,
1803 (struct sockaddr
*) &from
, &fromlen
);
1806 zlog_info ("recvfrom failed: %s", safe_strerror (errno
));
1810 /* Check is this packet comming from myself? */
1811 if (if_check_address (from
.sin_addr
))
1813 if (IS_RIP_DEBUG_PACKET
)
1814 zlog_debug ("ignore packet comes from myself");
1818 /* Which interface is this packet comes from. */
1819 ifc
= if_lookup_address ((void *)&from
.sin_addr
, AF_INET
, VRF_DEFAULT
);
1823 /* RIP packet received */
1824 if (IS_RIP_DEBUG_EVENT
)
1825 zlog_debug ("RECV packet from %s port %d on %s",
1826 inet_ntoa (from
.sin_addr
), ntohs (from
.sin_port
),
1827 ifp
? ifp
->name
: "unknown");
1829 /* If this packet come from unknown interface, ignore it. */
1832 zlog_info ("rip_read: cannot find interface for packet from %s port %d",
1833 inet_ntoa(from
.sin_addr
), ntohs (from
.sin_port
));
1838 p
.u
.prefix4
= from
.sin_addr
;
1839 p
.prefixlen
= IPV4_MAX_BITLEN
;
1841 ifc
= connected_lookup_prefix (ifp
, &p
);
1845 zlog_info ("rip_read: cannot find connected address for packet from %s "
1846 "port %d on interface %s",
1847 inet_ntoa(from
.sin_addr
), ntohs (from
.sin_port
), ifp
->name
);
1851 /* Packet length check. */
1852 if (len
< RIP_PACKET_MINSIZ
)
1854 zlog_warn ("packet size %d is smaller than minimum size %d",
1855 len
, RIP_PACKET_MINSIZ
);
1856 rip_peer_bad_packet (&from
);
1859 if (len
> RIP_PACKET_MAXSIZ
)
1861 zlog_warn ("packet size %d is larger than max size %d",
1862 len
, RIP_PACKET_MAXSIZ
);
1863 rip_peer_bad_packet (&from
);
1867 /* Packet alignment check. */
1868 if ((len
- RIP_PACKET_MINSIZ
) % 20)
1870 zlog_warn ("packet size %d is wrong for RIP packet alignment", len
);
1871 rip_peer_bad_packet (&from
);
1875 /* Set RTE number. */
1876 rtenum
= ((len
- RIP_PACKET_MINSIZ
) / 20);
1878 /* For easy to handle. */
1879 packet
= &rip_buf
.rip_packet
;
1881 /* RIP version check. */
1882 if (packet
->version
== 0)
1884 zlog_info ("version 0 with command %d received.", packet
->command
);
1885 rip_peer_bad_packet (&from
);
1889 /* Dump RIP packet. */
1890 if (IS_RIP_DEBUG_RECV
)
1891 rip_packet_dump (packet
, len
, "RECV");
1893 /* RIP version adjust. This code should rethink now. RFC1058 says
1894 that "Version 1 implementations are to ignore this extra data and
1895 process only the fields specified in this document.". So RIPv3
1896 packet should be treated as RIPv1 ignoring must be zero field. */
1897 if (packet
->version
> RIPv2
)
1898 packet
->version
= RIPv2
;
1900 /* Is RIP running or is this RIP neighbor ?*/
1902 if (! ri
->running
&& ! rip_neighbor_lookup (&from
))
1904 if (IS_RIP_DEBUG_EVENT
)
1905 zlog_debug ("RIP is not enabled on interface %s.", ifp
->name
);
1906 rip_peer_bad_packet (&from
);
1910 /* RIP Version check. RFC2453, 4.6 and 5.1 */
1911 vrecv
= ((ri
->ri_receive
== RI_RIP_UNSPEC
) ?
1912 rip
->version_recv
: ri
->ri_receive
);
1913 if (vrecv
== RI_RIP_VERSION_NONE
||
1914 ((packet
->version
== RIPv1
) && !(vrecv
& RIPv1
)) ||
1915 ((packet
->version
== RIPv2
) && !(vrecv
& RIPv2
)))
1917 if (IS_RIP_DEBUG_PACKET
)
1918 zlog_debug (" packet's v%d doesn't fit to if version spec",
1920 rip_peer_bad_packet (&from
);
1924 /* RFC2453 5.2 If the router is not configured to authenticate RIP-2
1925 messages, then RIP-1 and unauthenticated RIP-2 messages will be
1926 accepted; authenticated RIP-2 messages shall be discarded. */
1927 if ((ri
->auth_type
== RIP_NO_AUTH
)
1929 && (packet
->version
== RIPv2
)
1930 && (packet
->rte
->family
== htons(RIP_FAMILY_AUTH
)))
1932 if (IS_RIP_DEBUG_EVENT
)
1933 zlog_debug ("packet RIPv%d is dropped because authentication disabled",
1935 rip_peer_bad_packet (&from
);
1940 If the router is configured to authenticate RIP-2 messages, then
1941 RIP-1 messages and RIP-2 messages which pass authentication
1942 testing shall be accepted; unauthenticated and failed
1943 authentication RIP-2 messages shall be discarded. For maximum
1944 security, RIP-1 messages should be ignored when authentication is
1945 in use (see section 4.1); otherwise, the routing information from
1946 authenticated messages will be propagated by RIP-1 routers in an
1947 unauthenticated manner.
1949 /* We make an exception for RIPv1 REQUEST packets, to which we'll
1950 * always reply regardless of authentication settings, because:
1952 * - if there other authorised routers on-link, the REQUESTor can
1953 * passively obtain the routing updates anyway
1954 * - if there are no other authorised routers on-link, RIP can
1955 * easily be disabled for the link to prevent giving out information
1956 * on state of this routers RIP routing table..
1958 * I.e. if RIPv1 has any place anymore these days, it's as a very
1959 * simple way to distribute routing information (e.g. to embedded
1960 * hosts / appliances) and the ability to give out RIPv1
1961 * routing-information freely, while still requiring RIPv2
1962 * authentication for any RESPONSEs might be vaguely useful.
1964 if (ri
->auth_type
!= RIP_NO_AUTH
1965 && packet
->version
== RIPv1
)
1967 /* Discard RIPv1 messages other than REQUESTs */
1968 if (packet
->command
!= RIP_REQUEST
)
1970 if (IS_RIP_DEBUG_PACKET
)
1971 zlog_debug ("RIPv1" " dropped because authentication enabled");
1972 rip_peer_bad_packet (&from
);
1976 else if (ri
->auth_type
!= RIP_NO_AUTH
)
1978 const char *auth_desc
;
1982 /* There definitely is no authentication in the packet. */
1983 if (IS_RIP_DEBUG_PACKET
)
1984 zlog_debug ("RIPv2 authentication failed: no auth RTE in packet");
1985 rip_peer_bad_packet (&from
);
1989 /* First RTE must be an Authentication Family RTE */
1990 if (packet
->rte
->family
!= htons(RIP_FAMILY_AUTH
))
1992 if (IS_RIP_DEBUG_PACKET
)
1993 zlog_debug ("RIPv2" " dropped because authentication enabled");
1994 rip_peer_bad_packet (&from
);
1998 /* Check RIPv2 authentication. */
1999 switch (ntohs(packet
->rte
->tag
))
2001 case RIP_AUTH_SIMPLE_PASSWORD
:
2002 auth_desc
= "simple";
2003 ret
= rip_auth_simple_password (packet
->rte
, &from
, ifp
);
2008 ret
= rip_auth_md5 (packet
, &from
, len
, ifp
);
2009 /* Reset RIP packet length to trim MD5 data. */
2015 auth_desc
= "unknown type";
2016 if (IS_RIP_DEBUG_PACKET
)
2017 zlog_debug ("RIPv2 Unknown authentication type %d",
2018 ntohs (packet
->rte
->tag
));
2023 if (IS_RIP_DEBUG_PACKET
)
2024 zlog_debug ("RIPv2 %s authentication success", auth_desc
);
2028 if (IS_RIP_DEBUG_PACKET
)
2029 zlog_debug ("RIPv2 %s authentication failure", auth_desc
);
2030 rip_peer_bad_packet (&from
);
2035 /* Process each command. */
2036 switch (packet
->command
)
2039 rip_response_process (packet
, len
, &from
, ifc
);
2043 rip_request_process (packet
, len
, &from
, ifc
);
2047 zlog_info ("Obsolete command %s received, please sent it to routed",
2048 lookup (rip_msg
, packet
->command
));
2049 rip_peer_bad_packet (&from
);
2051 case RIP_POLL_ENTRY
:
2052 zlog_info ("Obsolete command %s received",
2053 lookup (rip_msg
, packet
->command
));
2054 rip_peer_bad_packet (&from
);
2057 zlog_info ("Unknown RIP command %d received", packet
->command
);
2058 rip_peer_bad_packet (&from
);
2065 /* Write routing table entry to the stream and return next index of
2066 the routing table entry in the stream. */
2068 rip_write_rte (int num
, struct stream
*s
, struct prefix_ipv4
*p
,
2069 u_char version
, struct rip_info
*rinfo
)
2071 struct in_addr mask
;
2073 /* Write routing table entry. */
2074 if (version
== RIPv1
)
2076 stream_putw (s
, AF_INET
);
2078 stream_put_ipv4 (s
, p
->prefix
.s_addr
);
2079 stream_put_ipv4 (s
, 0);
2080 stream_put_ipv4 (s
, 0);
2081 stream_putl (s
, rinfo
->metric_out
);
2085 masklen2ip (p
->prefixlen
, &mask
);
2087 stream_putw (s
, AF_INET
);
2088 stream_putw (s
, rinfo
->tag_out
);
2089 stream_put_ipv4 (s
, p
->prefix
.s_addr
);
2090 stream_put_ipv4 (s
, mask
.s_addr
);
2091 stream_put_ipv4 (s
, rinfo
->nexthop_out
.s_addr
);
2092 stream_putl (s
, rinfo
->metric_out
);
2098 /* Send update to the ifp or spcified neighbor. */
2100 rip_output_process (struct connected
*ifc
, struct sockaddr_in
*to
,
2101 int route_type
, u_char version
)
2105 struct route_node
*rp
;
2106 struct rip_info
*rinfo
;
2107 struct rip_interface
*ri
;
2108 struct prefix_ipv4
*p
;
2109 struct prefix_ipv4 classfull
;
2110 struct prefix_ipv4 ifaddrclass
;
2111 struct key
*key
= NULL
;
2112 /* this might need to made dynamic if RIP ever supported auth methods
2113 with larger key string sizes */
2114 char auth_str
[RIP_AUTH_SIMPLE_SIZE
];
2115 size_t doff
= 0; /* offset of digest offset field */
2119 struct list
*list
= NULL
;
2120 struct listnode
*listnode
= NULL
;
2122 /* Logging output event. */
2123 if (IS_RIP_DEBUG_EVENT
)
2126 zlog_debug ("update routes to neighbor %s", inet_ntoa (to
->sin_addr
));
2128 zlog_debug ("update routes on interface %s ifindex %d",
2129 ifc
->ifp
->name
, ifc
->ifp
->ifindex
);
2132 /* Set output stream. */
2135 /* Reset stream and RTE counter. */
2137 rtemax
= RIP_MAX_RTE
;
2139 /* Get RIP interface. */
2140 ri
= ifc
->ifp
->info
;
2142 /* If output interface is in simple password authentication mode, we
2143 need space for authentication data. */
2144 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
2147 /* If output interface is in MD5 authentication mode, we need space
2148 for authentication header and data. */
2149 if (ri
->auth_type
== RIP_AUTH_MD5
)
2152 /* If output interface is in simple password authentication mode
2153 and string or keychain is specified we need space for auth. data */
2154 if (ri
->auth_type
!= RIP_NO_AUTH
)
2158 struct keychain
*keychain
;
2160 keychain
= keychain_lookup (ri
->key_chain
);
2162 key
= key_lookup_for_send (keychain
);
2164 /* to be passed to auth functions later */
2165 rip_auth_prepare_str_send (ri
, key
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
2168 if (version
== RIPv1
)
2170 memcpy (&ifaddrclass
, ifc
->address
, sizeof (struct prefix_ipv4
));
2171 apply_classful_mask_ipv4 (&ifaddrclass
);
2173 if (ifc
->address
->prefixlen
> ifaddrclass
.prefixlen
)
2177 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2178 if ((list
= rp
->info
) != NULL
&& listcount (list
) != 0)
2180 rinfo
= listgetdata (listhead (list
));
2181 /* For RIPv1, if we are subnetted, output subnets in our network */
2182 /* that have the same mask as the output "interface". For other */
2183 /* networks, only the classfull version is output. */
2185 if (version
== RIPv1
)
2187 p
= (struct prefix_ipv4
*) &rp
->p
;
2189 if (IS_RIP_DEBUG_PACKET
)
2190 zlog_debug("RIPv1 mask check, %s/%d considered for output",
2191 inet_ntoa (rp
->p
.u
.prefix4
), rp
->p
.prefixlen
);
2194 prefix_match ((struct prefix
*) &ifaddrclass
, &rp
->p
))
2196 if ((ifc
->address
->prefixlen
!= rp
->p
.prefixlen
) &&
2197 (rp
->p
.prefixlen
!= 32))
2202 memcpy (&classfull
, &rp
->p
, sizeof(struct prefix_ipv4
));
2203 apply_classful_mask_ipv4(&classfull
);
2204 if (rp
->p
.u
.prefix4
.s_addr
!= 0 &&
2205 classfull
.prefixlen
!= rp
->p
.prefixlen
)
2208 if (IS_RIP_DEBUG_PACKET
)
2209 zlog_debug("RIPv1 mask check, %s/%d made it through",
2210 inet_ntoa (rp
->p
.u
.prefix4
), rp
->p
.prefixlen
);
2213 p
= (struct prefix_ipv4
*) &rp
->p
;
2215 /* Apply output filters. */
2216 ret
= rip_filter (RIP_FILTER_OUT
, p
, ri
);
2220 /* Changed route only output. */
2221 if (route_type
== rip_changed_route
&&
2222 (! (rinfo
->flags
& RIP_RTF_CHANGED
)))
2225 /* Split horizon. */
2226 /* if (split_horizon == rip_split_horizon) */
2227 if (ri
->split_horizon
== RIP_SPLIT_HORIZON
)
2230 * We perform split horizon for RIP and connected route.
2231 * For rip routes, we want to suppress the route if we would
2232 * end up sending the route back on the interface that we
2233 * learned it from, with a higher metric. For connected routes,
2234 * we suppress the route if the prefix is a subset of the
2235 * source address that we are going to use for the packet
2236 * (in order to handle the case when multiple subnets are
2237 * configured on the same interface).
2240 struct rip_info
*tmp_rinfo
= NULL
;
2242 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, tmp_rinfo
))
2243 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
&&
2244 tmp_rinfo
->ifindex
== ifc
->ifp
->ifindex
)
2250 if (!suppress
&& rinfo
->type
== ZEBRA_ROUTE_CONNECT
&&
2251 prefix_match((struct prefix
*)p
, ifc
->address
))
2258 /* Preparation for route-map. */
2259 rinfo
->metric_set
= 0;
2260 rinfo
->nexthop_out
.s_addr
= 0;
2261 rinfo
->metric_out
= rinfo
->metric
;
2262 rinfo
->tag_out
= rinfo
->tag
;
2263 rinfo
->ifindex_out
= ifc
->ifp
->ifindex
;
2265 /* In order to avoid some local loops,
2266 * if the RIP route has a nexthop via this interface, keep the nexthop,
2267 * otherwise set it to 0. The nexthop should not be propagated
2268 * beyond the local broadcast/multicast area in order
2269 * to avoid an IGP multi-level recursive look-up.
2272 if (rinfo
->ifindex
== ifc
->ifp
->ifindex
)
2273 rinfo
->nexthop_out
= rinfo
->nexthop
;
2275 /* Interface route-map */
2276 if (ri
->routemap
[RIP_FILTER_OUT
])
2278 ret
= route_map_apply (ri
->routemap
[RIP_FILTER_OUT
],
2279 (struct prefix
*) p
, RMAP_RIP
,
2282 if (ret
== RMAP_DENYMATCH
)
2284 if (IS_RIP_DEBUG_PACKET
)
2285 zlog_debug ("RIP %s/%d is filtered by route-map out",
2286 inet_ntoa (p
->prefix
), p
->prefixlen
);
2291 /* Apply redistribute route map - continue, if deny */
2292 if (rip
->route_map
[rinfo
->type
].name
2293 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
)
2295 ret
= route_map_apply (rip
->route_map
[rinfo
->type
].map
,
2296 (struct prefix
*)p
, RMAP_RIP
, rinfo
);
2298 if (ret
== RMAP_DENYMATCH
)
2300 if (IS_RIP_DEBUG_PACKET
)
2301 zlog_debug ("%s/%d is filtered by route-map",
2302 inet_ntoa (p
->prefix
), p
->prefixlen
);
2307 /* When route-map does not set metric. */
2308 if (! rinfo
->metric_set
)
2310 /* If redistribute metric is set. */
2311 if (rip
->route_map
[rinfo
->type
].metric_config
2312 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
2314 rinfo
->metric_out
= rip
->route_map
[rinfo
->type
].metric
;
2318 /* If the route is not connected or localy generated
2319 one, use default-metric value*/
2320 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
2321 && rinfo
->type
!= ZEBRA_ROUTE_CONNECT
2322 && rinfo
->metric
!= RIP_METRIC_INFINITY
)
2323 rinfo
->metric_out
= rip
->default_metric
;
2327 /* Apply offset-list */
2328 if (rinfo
->metric
!= RIP_METRIC_INFINITY
)
2329 rip_offset_list_apply_out (p
, ifc
->ifp
, &rinfo
->metric_out
);
2331 if (rinfo
->metric_out
> RIP_METRIC_INFINITY
)
2332 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2334 /* Perform split-horizon with poisoned reverse
2335 * for RIP and connected routes.
2337 if (ri
->split_horizon
== RIP_SPLIT_HORIZON_POISONED_REVERSE
) {
2339 * We perform split horizon for RIP and connected route.
2340 * For rip routes, we want to suppress the route if we would
2341 * end up sending the route back on the interface that we
2342 * learned it from, with a higher metric. For connected routes,
2343 * we suppress the route if the prefix is a subset of the
2344 * source address that we are going to use for the packet
2345 * (in order to handle the case when multiple subnets are
2346 * configured on the same interface).
2348 struct rip_info
*tmp_rinfo
= NULL
;
2350 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, tmp_rinfo
))
2351 if (tmp_rinfo
->type
== ZEBRA_ROUTE_RIP
&&
2352 tmp_rinfo
->ifindex
== ifc
->ifp
->ifindex
)
2353 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2354 if (tmp_rinfo
->type
== ZEBRA_ROUTE_CONNECT
&&
2355 prefix_match((struct prefix
*)p
, ifc
->address
))
2356 rinfo
->metric_out
= RIP_METRIC_INFINITY
;
2359 /* Prepare preamble, auth headers, if needs be */
2362 stream_putc (s
, RIP_RESPONSE
);
2363 stream_putc (s
, version
);
2366 /* auth header for !v1 && !no_auth */
2367 if ( (ri
->auth_type
!= RIP_NO_AUTH
) && (version
!= RIPv1
) )
2368 doff
= rip_auth_header_write (s
, ri
, key
, auth_str
,
2369 RIP_AUTH_SIMPLE_SIZE
);
2372 /* Write RTE to the stream. */
2373 num
= rip_write_rte (num
, s
, p
, version
, rinfo
);
2376 if (version
== RIPv2
&& ri
->auth_type
== RIP_AUTH_MD5
)
2377 rip_auth_md5_set (s
, ri
, doff
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
2379 ret
= rip_send_packet (STREAM_DATA (s
), stream_get_endp (s
),
2382 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2383 rip_packet_dump ((struct rip_packet
*)STREAM_DATA (s
),
2384 stream_get_endp(s
), "SEND");
2390 /* Flush unwritten RTE. */
2393 if (version
== RIPv2
&& ri
->auth_type
== RIP_AUTH_MD5
)
2394 rip_auth_md5_set (s
, ri
, doff
, auth_str
, RIP_AUTH_SIMPLE_SIZE
);
2396 ret
= rip_send_packet (STREAM_DATA (s
), stream_get_endp (s
), to
, ifc
);
2398 if (ret
>= 0 && IS_RIP_DEBUG_SEND
)
2399 rip_packet_dump ((struct rip_packet
*)STREAM_DATA (s
),
2400 stream_get_endp (s
), "SEND");
2404 /* Statistics updates. */
2408 /* Send RIP packet to the interface. */
2410 rip_update_interface (struct connected
*ifc
, u_char version
, int route_type
)
2412 struct interface
*ifp
= ifc
->ifp
;
2413 struct rip_interface
*ri
= ifp
->info
;
2414 struct sockaddr_in to
;
2416 /* When RIP version is 2 and multicast enable interface. */
2417 if (version
== RIPv2
&& !ri
->v2_broadcast
&& if_is_multicast (ifp
))
2419 if (IS_RIP_DEBUG_EVENT
)
2420 zlog_debug ("multicast announce on %s ", ifp
->name
);
2422 rip_output_process (ifc
, NULL
, route_type
, version
);
2426 /* If we can't send multicast packet, send it with unicast. */
2427 if (if_is_broadcast (ifp
) || if_is_pointopoint (ifp
))
2429 if (ifc
->address
->family
== AF_INET
)
2431 /* Destination address and port setting. */
2432 memset (&to
, 0, sizeof (struct sockaddr_in
));
2433 if (ifc
->destination
)
2434 /* use specified broadcast or peer destination addr */
2435 to
.sin_addr
= ifc
->destination
->u
.prefix4
;
2436 else if (ifc
->address
->prefixlen
< IPV4_MAX_PREFIXLEN
)
2437 /* calculate the appropriate broadcast address */
2438 to
.sin_addr
.s_addr
=
2439 ipv4_broadcast_addr(ifc
->address
->u
.prefix4
.s_addr
,
2440 ifc
->address
->prefixlen
);
2442 /* do not know where to send the packet */
2444 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
2446 if (IS_RIP_DEBUG_EVENT
)
2447 zlog_debug("%s announce to %s on %s",
2448 CONNECTED_PEER(ifc
) ? "unicast" : "broadcast",
2449 inet_ntoa (to
.sin_addr
), ifp
->name
);
2451 rip_output_process (ifc
, &to
, route_type
, version
);
2456 /* Update send to all interface and neighbor. */
2458 rip_update_process (int route_type
)
2460 struct listnode
*node
;
2461 struct listnode
*ifnode
, *ifnnode
;
2462 struct connected
*connected
;
2463 struct interface
*ifp
;
2464 struct rip_interface
*ri
;
2465 struct route_node
*rp
;
2466 struct sockaddr_in to
;
2469 /* Send RIP update to each interface. */
2470 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
2472 if (if_is_loopback (ifp
))
2475 if (! if_is_operative (ifp
))
2478 /* Fetch RIP interface information. */
2481 /* When passive interface is specified, suppress announce to the
2489 * If there is no version configuration in the interface,
2490 * use rip's version setting.
2492 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
) ?
2493 rip
->version_send
: ri
->ri_send
);
2495 if (IS_RIP_DEBUG_EVENT
)
2496 zlog_debug("SEND UPDATE to %s ifindex %d",
2497 ifp
->name
, ifp
->ifindex
);
2499 /* send update on each connected network */
2500 for (ALL_LIST_ELEMENTS (ifp
->connected
, ifnode
, ifnnode
, connected
))
2502 if (connected
->address
->family
== AF_INET
)
2505 rip_update_interface (connected
, RIPv1
, route_type
);
2506 if ((vsend
& RIPv2
) && if_is_multicast(ifp
))
2507 rip_update_interface (connected
, RIPv2
, route_type
);
2513 /* RIP send updates to each neighbor. */
2514 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
2515 if (rp
->info
!= NULL
)
2519 connected
= if_lookup_address (&p
->u
.prefix4
, AF_INET
, VRF_DEFAULT
);
2522 zlog_warn ("Neighbor %s doesnt have connected interface!",
2523 inet_ntoa (p
->u
.prefix4
));
2527 /* Set destination address and port */
2528 memset (&to
, 0, sizeof (struct sockaddr_in
));
2529 to
.sin_addr
= p
->u
.prefix4
;
2530 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
2532 /* RIP version is rip's configuration. */
2533 rip_output_process (connected
, &to
, route_type
, rip
->version_send
);
2537 /* RIP's periodical timer. */
2539 rip_update (struct thread
*t
)
2541 /* Clear timer pointer. */
2542 rip
->t_update
= NULL
;
2544 if (IS_RIP_DEBUG_EVENT
)
2545 zlog_debug ("update timer fire!");
2547 /* Process update output. */
2548 rip_update_process (rip_all_route
);
2550 /* Triggered updates may be suppressed if a regular update is due by
2551 the time the triggered update would be sent. */
2552 RIP_TIMER_OFF (rip
->t_triggered_interval
);
2555 /* Register myself. */
2556 rip_event (RIP_UPDATE_EVENT
, 0);
2561 /* Walk down the RIP routing table then clear changed flag. */
2563 rip_clear_changed_flag (void)
2565 struct route_node
*rp
;
2566 struct rip_info
*rinfo
= NULL
;
2567 struct list
*list
= NULL
;
2568 struct listnode
*listnode
= NULL
;
2570 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2571 if ((list
= rp
->info
) != NULL
)
2572 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2574 UNSET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
2575 /* This flag can be set only on the first entry. */
2580 /* Triggered update interval timer. */
2582 rip_triggered_interval (struct thread
*t
)
2584 int rip_triggered_update (struct thread
*);
2586 rip
->t_triggered_interval
= NULL
;
2591 rip_triggered_update (t
);
2596 /* Execute triggered update. */
2598 rip_triggered_update (struct thread
*t
)
2602 /* Clear thred pointer. */
2603 rip
->t_triggered_update
= NULL
;
2605 /* Cancel interval timer. */
2606 RIP_TIMER_OFF (rip
->t_triggered_interval
);
2609 /* Logging triggered update. */
2610 if (IS_RIP_DEBUG_EVENT
)
2611 zlog_debug ("triggered update!");
2613 /* Split Horizon processing is done when generating triggered
2614 updates as well as normal updates (see section 2.6). */
2615 rip_update_process (rip_changed_route
);
2617 /* Once all of the triggered updates have been generated, the route
2618 change flags should be cleared. */
2619 rip_clear_changed_flag ();
2621 /* After a triggered update is sent, a timer should be set for a
2622 random interval between 1 and 5 seconds. If other changes that
2623 would trigger updates occur before the timer expires, a single
2624 update is triggered when the timer expires. */
2625 interval
= (random () % 5) + 1;
2627 rip
->t_triggered_interval
=
2628 thread_add_timer (master
, rip_triggered_interval
, NULL
, 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
)
2783 rip
->t_read
= thread_add_read (master
, rip_read
, NULL
, sock
);
2785 case RIP_UPDATE_EVENT
:
2786 RIP_TIMER_OFF (rip
->t_update
);
2787 jitter
= rip_update_jitter (rip
->update_time
);
2789 thread_add_timer (master
, rip_update
, NULL
,
2790 sock
? 2 : rip
->update_time
+ jitter
);
2792 case RIP_TRIGGERED_UPDATE
:
2793 if (rip
->t_triggered_interval
)
2795 else if (! rip
->t_triggered_update
)
2796 rip
->t_triggered_update
=
2797 thread_add_event (master
, rip_triggered_update
, NULL
, 0);
2804 DEFUN_NOSH (router_rip
,
2807 "Enable a routing process\n"
2808 "Routing Information Protocol (RIP)\n")
2812 /* If rip is not enabled before. */
2815 ret
= rip_create ();
2818 zlog_info ("Can't create RIP");
2822 VTY_PUSH_CONTEXT(RIP_NODE
, rip
);
2827 DEFUN (no_router_rip
,
2831 "Enable a routing process\n"
2832 "Routing Information Protocol (RIP)\n")
2842 "Set routing protocol version\n"
2848 version
= atoi (argv
[idx_number
]->arg
);
2849 if (version
!= RIPv1
&& version
!= RIPv2
)
2851 vty_out (vty
, "invalid rip version %d%s", version
,
2855 rip
->version_send
= version
;
2856 rip
->version_recv
= version
;
2861 DEFUN (no_rip_version
,
2863 "no version [(1-2)]",
2865 "Set routing protocol version\n"
2868 /* Set RIP version to the default. */
2869 rip
->version_send
= RI_RIP_VERSION_2
;
2870 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2879 "RIP static route configuration\n"
2880 "IP prefix <network>/<length>\n")
2882 int idx_ipv4_prefixlen
= 1;
2884 struct prefix_ipv4 p
;
2885 struct route_node
*node
;
2887 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2890 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2893 apply_mask_ipv4 (&p
);
2895 /* For router rip configuration. */
2896 node
= route_node_get (rip
->route
, (struct prefix
*) &p
);
2900 vty_out (vty
, "There is already same static route.%s", VTY_NEWLINE
);
2901 route_unlock_node (node
);
2905 node
->info
= (void *)1;
2907 rip_redistribute_add (ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0, NULL
, 0, 0, 0);
2912 DEFUN (no_rip_route
,
2914 "no route A.B.C.D/M",
2916 "RIP static route configuration\n"
2917 "IP prefix <network>/<length>\n")
2919 int idx_ipv4_prefixlen
= 2;
2921 struct prefix_ipv4 p
;
2922 struct route_node
*node
;
2924 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2927 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2930 apply_mask_ipv4 (&p
);
2932 /* For router rip configuration. */
2933 node
= route_node_lookup (rip
->route
, (struct prefix
*) &p
);
2936 vty_out (vty
, "Can't find route %s.%s", argv
[idx_ipv4_prefixlen
]->arg
,
2941 rip_redistribute_delete (ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0);
2942 route_unlock_node (node
);
2945 route_unlock_node (node
);
2952 rip_update_default_metric (void)
2954 struct route_node
*np
;
2955 struct rip_info
*rinfo
= NULL
;
2956 struct list
*list
= NULL
;
2957 struct listnode
*listnode
= NULL
;
2959 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
2960 if ((list
= np
->info
) != NULL
)
2961 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2962 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
&& rinfo
->type
!= ZEBRA_ROUTE_CONNECT
)
2963 rinfo
->metric
= rip
->default_metric
;
2967 DEFUN (rip_default_metric
,
2968 rip_default_metric_cmd
,
2969 "default-metric (1-16)",
2970 "Set a metric of redistribute routes\n"
2976 rip
->default_metric
= atoi (argv
[idx_number
]->arg
);
2977 /* rip_update_default_metric (); */
2982 DEFUN (no_rip_default_metric
,
2983 no_rip_default_metric_cmd
,
2984 "no default-metric [(1-16)]",
2986 "Set a metric of redistribute routes\n"
2991 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2992 /* rip_update_default_metric (); */
3000 "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
3001 "Adjust routing timers\n"
3002 "Basic routing protocol update timers\n"
3003 "Routing table update timer value in second. Default is 30.\n"
3004 "Routing information timeout timer. Default is 180.\n"
3005 "Garbage collection timer. Default is 120.\n")
3008 int idx_number_2
= 3;
3009 int idx_number_3
= 4;
3010 unsigned long update
;
3011 unsigned long timeout
;
3012 unsigned long garbage
;
3013 char *endptr
= NULL
;
3014 unsigned long RIP_TIMER_MAX
= 2147483647;
3015 unsigned long RIP_TIMER_MIN
= 5;
3017 update
= strtoul (argv
[idx_number
]->arg
, &endptr
, 10);
3018 if (update
> RIP_TIMER_MAX
|| update
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3020 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
3024 timeout
= strtoul (argv
[idx_number_2
]->arg
, &endptr
, 10);
3025 if (timeout
> RIP_TIMER_MAX
|| timeout
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3027 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
3031 garbage
= strtoul (argv
[idx_number_3
]->arg
, &endptr
, 10);
3032 if (garbage
> RIP_TIMER_MAX
|| garbage
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3034 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
3038 /* Set each timer value. */
3039 rip
->update_time
= update
;
3040 rip
->timeout_time
= timeout
;
3041 rip
->garbage_time
= garbage
;
3043 /* Reset update timer thread. */
3044 rip_event (RIP_UPDATE_EVENT
, 0);
3049 DEFUN (no_rip_timers
,
3051 "no timers basic [(0-65535) (0-65535) (0-65535)]",
3053 "Adjust routing timers\n"
3054 "Basic routing protocol update timers\n"
3055 "Routing table update timer value in second. Default is 30.\n"
3056 "Routing information timeout timer. Default is 180.\n"
3057 "Garbage collection timer. Default is 120.\n")
3059 /* Set each timer value to the default. */
3060 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
3061 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
3062 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
3064 /* Reset update timer thread. */
3065 rip_event (RIP_UPDATE_EVENT
, 0);
3072 struct route_table
*rip_distance_table
;
3076 /* Distance value for the IP source prefix. */
3079 /* Name of the access-list to be matched. */
3083 static struct rip_distance
*
3084 rip_distance_new (void)
3086 return XCALLOC (MTYPE_RIP_DISTANCE
, sizeof (struct rip_distance
));
3090 rip_distance_free (struct rip_distance
*rdistance
)
3092 XFREE (MTYPE_RIP_DISTANCE
, rdistance
);
3096 rip_distance_set (struct vty
*vty
, const char *distance_str
, const char *ip_str
,
3097 const char *access_list_str
)
3100 struct prefix_ipv4 p
;
3102 struct route_node
*rn
;
3103 struct rip_distance
*rdistance
;
3105 ret
= str2prefix_ipv4 (ip_str
, &p
);
3108 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
3112 distance
= atoi (distance_str
);
3114 /* Get RIP distance node. */
3115 rn
= route_node_get (rip_distance_table
, (struct prefix
*) &p
);
3118 rdistance
= rn
->info
;
3119 route_unlock_node (rn
);
3123 rdistance
= rip_distance_new ();
3124 rn
->info
= rdistance
;
3127 /* Set distance value. */
3128 rdistance
->distance
= distance
;
3130 /* Reset access-list configuration. */
3131 if (rdistance
->access_list
)
3133 free (rdistance
->access_list
);
3134 rdistance
->access_list
= NULL
;
3136 if (access_list_str
)
3137 rdistance
->access_list
= strdup (access_list_str
);
3143 rip_distance_unset (struct vty
*vty
, const char *distance_str
,
3144 const char *ip_str
, const char *access_list_str
)
3147 struct prefix_ipv4 p
;
3148 struct route_node
*rn
;
3149 struct rip_distance
*rdistance
;
3151 ret
= str2prefix_ipv4 (ip_str
, &p
);
3154 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
3158 rn
= route_node_lookup (rip_distance_table
, (struct prefix
*)&p
);
3161 vty_out (vty
, "Can't find specified prefix%s", VTY_NEWLINE
);
3165 rdistance
= rn
->info
;
3167 if (rdistance
->access_list
)
3168 free (rdistance
->access_list
);
3169 rip_distance_free (rdistance
);
3172 route_unlock_node (rn
);
3173 route_unlock_node (rn
);
3179 rip_distance_reset (void)
3181 struct route_node
*rn
;
3182 struct rip_distance
*rdistance
;
3184 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3185 if ((rdistance
= rn
->info
) != NULL
)
3187 if (rdistance
->access_list
)
3188 free (rdistance
->access_list
);
3189 rip_distance_free (rdistance
);
3191 route_unlock_node (rn
);
3195 /* Apply RIP information to distance method. */
3197 rip_distance_apply (struct rip_info
*rinfo
)
3199 struct route_node
*rn
;
3200 struct prefix_ipv4 p
;
3201 struct rip_distance
*rdistance
;
3202 struct access_list
*alist
;
3207 memset (&p
, 0, sizeof (struct prefix_ipv4
));
3209 p
.prefix
= rinfo
->from
;
3210 p
.prefixlen
= IPV4_MAX_BITLEN
;
3212 /* Check source address. */
3213 rn
= route_node_match (rip_distance_table
, (struct prefix
*) &p
);
3216 rdistance
= rn
->info
;
3217 route_unlock_node (rn
);
3219 if (rdistance
->access_list
)
3221 alist
= access_list_lookup (AFI_IP
, rdistance
->access_list
);
3224 if (access_list_apply (alist
, &rinfo
->rp
->p
) == FILTER_DENY
)
3227 return rdistance
->distance
;
3230 return rdistance
->distance
;
3234 return rip
->distance
;
3240 rip_distance_show (struct vty
*vty
)
3242 struct route_node
*rn
;
3243 struct rip_distance
*rdistance
;
3247 vty_out (vty
, " Distance: (default is %d)%s",
3248 rip
->distance
? rip
->distance
:ZEBRA_RIP_DISTANCE_DEFAULT
,
3251 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3252 if ((rdistance
= rn
->info
) != NULL
)
3256 vty_out (vty
, " Address Distance List%s",
3260 sprintf (buf
, "%s/%d", inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
3261 vty_out (vty
, " %-20s %4d %s%s",
3262 buf
, rdistance
->distance
,
3263 rdistance
->access_list
? rdistance
->access_list
: "",
3268 DEFUN (rip_distance
,
3271 "Administrative distance\n"
3275 rip
->distance
= atoi (argv
[idx_number
]->arg
);
3279 DEFUN (no_rip_distance
,
3280 no_rip_distance_cmd
,
3281 "no distance (1-255)",
3283 "Administrative distance\n"
3290 DEFUN (rip_distance_source
,
3291 rip_distance_source_cmd
,
3292 "distance (1-255) A.B.C.D/M",
3293 "Administrative distance\n"
3295 "IP source prefix\n")
3298 int idx_ipv4_prefixlen
= 2;
3299 rip_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3303 DEFUN (no_rip_distance_source
,
3304 no_rip_distance_source_cmd
,
3305 "no distance (1-255) A.B.C.D/M",
3307 "Administrative distance\n"
3309 "IP source prefix\n")
3312 int idx_ipv4_prefixlen
= 3;
3313 rip_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3317 DEFUN (rip_distance_source_access_list
,
3318 rip_distance_source_access_list_cmd
,
3319 "distance (1-255) A.B.C.D/M WORD",
3320 "Administrative distance\n"
3322 "IP source prefix\n"
3323 "Access list name\n")
3326 int idx_ipv4_prefixlen
= 2;
3328 rip_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3332 DEFUN (no_rip_distance_source_access_list
,
3333 no_rip_distance_source_access_list_cmd
,
3334 "no distance (1-255) A.B.C.D/M WORD",
3336 "Administrative distance\n"
3338 "IP source prefix\n"
3339 "Access list name\n")
3342 int idx_ipv4_prefixlen
= 3;
3344 rip_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3348 /* Update ECMP routes to zebra when ECMP is disabled. */
3350 rip_ecmp_disable (void)
3352 struct route_node
*rp
;
3353 struct rip_info
*rinfo
, *tmp_rinfo
;
3355 struct listnode
*node
, *nextnode
;
3360 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
3361 if ((list
= rp
->info
) != NULL
&& listcount (list
) > 1)
3363 rinfo
= listgetdata (listhead (list
));
3364 if (!rip_route_rte (rinfo
))
3367 /* Drop all other entries, except the first one. */
3368 for (ALL_LIST_ELEMENTS (list
, node
, nextnode
, tmp_rinfo
))
3369 if (tmp_rinfo
!= rinfo
)
3371 RIP_TIMER_OFF (tmp_rinfo
->t_timeout
);
3372 RIP_TIMER_OFF (tmp_rinfo
->t_garbage_collect
);
3373 list_delete_node (list
, node
);
3374 rip_info_free (tmp_rinfo
);
3378 rip_zebra_ipv4_add (rp
);
3380 /* Set the route change flag. */
3381 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
3383 /* Signal the output process to trigger an update. */
3384 rip_event (RIP_TRIGGERED_UPDATE
, 0);
3388 DEFUN (rip_allow_ecmp
,
3391 "Allow Equal Cost MultiPath\n")
3395 vty_out (vty
, "ECMP is already enabled.%s", VTY_NEWLINE
);
3400 zlog_info ("ECMP is enabled.");
3404 DEFUN (no_rip_allow_ecmp
,
3405 no_rip_allow_ecmp_cmd
,
3408 "Allow Equal Cost MultiPath\n")
3412 vty_out (vty
, "ECMP is already disabled.%s", VTY_NEWLINE
);
3417 zlog_info ("ECMP is disabled.");
3418 rip_ecmp_disable ();
3422 /* Print out routes update time. */
3424 rip_vty_out_uptime (struct vty
*vty
, struct rip_info
*rinfo
)
3429 char timebuf
[TIME_BUF
];
3430 struct thread
*thread
;
3432 if ((thread
= rinfo
->t_timeout
) != NULL
)
3434 clock
= thread_timer_remain_second (thread
);
3435 tm
= gmtime (&clock
);
3436 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
3437 vty_out (vty
, "%5s", timebuf
);
3439 else if ((thread
= rinfo
->t_garbage_collect
) != NULL
)
3441 clock
= thread_timer_remain_second (thread
);
3442 tm
= gmtime (&clock
);
3443 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
3444 vty_out (vty
, "%5s", timebuf
);
3449 rip_route_type_print (int sub_type
)
3455 case RIP_ROUTE_STATIC
:
3457 case RIP_ROUTE_DEFAULT
:
3459 case RIP_ROUTE_REDISTRIBUTE
:
3461 case RIP_ROUTE_INTERFACE
:
3473 "Show RIP routes\n")
3475 struct route_node
*np
;
3476 struct rip_info
*rinfo
= NULL
;
3477 struct list
*list
= NULL
;
3478 struct listnode
*listnode
= NULL
;
3483 vty_out (vty
, "Codes: R - RIP, C - connected, S - Static, O - OSPF, B - BGP%s"
3485 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
3486 " (i) - interface%s%s"
3487 " Network Next Hop Metric From Tag Time%s",
3488 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
3490 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
3491 if ((list
= np
->info
) != NULL
)
3492 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
3496 len
= vty_out (vty
, "%c(%s) %s/%d",
3497 /* np->lock, For debugging. */
3498 zebra_route_char(rinfo
->type
),
3499 rip_route_type_print (rinfo
->sub_type
),
3500 inet_ntoa (np
->p
.u
.prefix4
), np
->p
.prefixlen
);
3505 vty_out (vty
, "%*s", len
, " ");
3507 if (rinfo
->nexthop
.s_addr
)
3508 vty_out (vty
, "%-20s %2d ", inet_ntoa (rinfo
->nexthop
),
3511 vty_out (vty
, "0.0.0.0 %2d ", rinfo
->metric
);
3513 /* Route which exist in kernel routing table. */
3514 if ((rinfo
->type
== ZEBRA_ROUTE_RIP
) &&
3515 (rinfo
->sub_type
== RIP_ROUTE_RTE
))
3517 vty_out (vty
, "%-15s ", inet_ntoa (rinfo
->from
));
3518 vty_out (vty
, "%3"ROUTE_TAG_PRI
" ", (route_tag_t
)rinfo
->tag
);
3519 rip_vty_out_uptime (vty
, rinfo
);
3521 else if (rinfo
->metric
== RIP_METRIC_INFINITY
)
3523 vty_out (vty
, "self ");
3524 vty_out (vty
, "%3"ROUTE_TAG_PRI
" ", (route_tag_t
)rinfo
->tag
);
3525 rip_vty_out_uptime (vty
, rinfo
);
3529 if (rinfo
->external_metric
)
3531 len
= vty_out (vty
, "self (%s:%d)",
3532 zebra_route_string(rinfo
->type
),
3533 rinfo
->external_metric
);
3536 vty_out (vty
, "%*s", len
, " ");
3539 vty_out (vty
, "self ");
3540 vty_out (vty
, "%3"ROUTE_TAG_PRI
, (route_tag_t
)rinfo
->tag
);
3543 vty_out (vty
, "%s", VTY_NEWLINE
);
3548 /* Vincent: formerly, it was show_ip_protocols_rip: "show ip protocols" */
3549 DEFUN (show_ip_rip_status
,
3550 show_ip_rip_status_cmd
,
3551 "show ip rip status",
3555 "IP routing protocol process parameters and statistics\n")
3557 struct listnode
*node
;
3558 struct interface
*ifp
;
3559 struct rip_interface
*ri
;
3560 extern const struct message ri_version_msg
[];
3561 const char *send_version
;
3562 const char *receive_version
;
3567 vty_out (vty
, "Routing Protocol is \"rip\"%s", VTY_NEWLINE
);
3568 vty_out (vty
, " Sending updates every %ld seconds with +/-50%%,",
3570 vty_out (vty
, " next due in %lu seconds%s",
3571 thread_timer_remain_second(rip
->t_update
),
3573 vty_out (vty
, " Timeout after %ld seconds,", rip
->timeout_time
);
3574 vty_out (vty
, " garbage collect after %ld seconds%s", rip
->garbage_time
,
3577 /* Filtering status show. */
3578 config_show_distribute (vty
);
3580 /* Default metric information. */
3581 vty_out (vty
, " Default redistribution metric is %d%s",
3582 rip
->default_metric
, VTY_NEWLINE
);
3584 /* Redistribute information. */
3585 vty_out (vty
, " Redistributing:");
3586 config_write_rip_redistribute (vty
, 0);
3587 vty_out (vty
, "%s", VTY_NEWLINE
);
3589 vty_out (vty
, " Default version control: send version %s,",
3590 lookup(ri_version_msg
,rip
->version_send
));
3591 if (rip
->version_recv
== RI_RIP_VERSION_1_AND_2
)
3592 vty_out (vty
, " receive any version %s", VTY_NEWLINE
);
3594 vty_out (vty
, " receive version %s %s",
3595 lookup(ri_version_msg
,rip
->version_recv
), VTY_NEWLINE
);
3597 vty_out (vty
, " Interface Send Recv Key-chain%s", VTY_NEWLINE
);
3599 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
3606 if (ri
->enable_network
|| ri
->enable_interface
)
3608 if (ri
->ri_send
== RI_RIP_UNSPEC
)
3609 send_version
= lookup (ri_version_msg
, rip
->version_send
);
3611 send_version
= lookup (ri_version_msg
, ri
->ri_send
);
3613 if (ri
->ri_receive
== RI_RIP_UNSPEC
)
3614 receive_version
= lookup (ri_version_msg
, rip
->version_recv
);
3616 receive_version
= lookup (ri_version_msg
, ri
->ri_receive
);
3618 vty_out (vty
, " %-17s%-3s %-3s %s%s", ifp
->name
,
3621 ri
->key_chain
? ri
->key_chain
: "",
3626 vty_out (vty
, " Routing for Networks:%s", VTY_NEWLINE
);
3627 config_write_rip_network (vty
, 0);
3630 int found_passive
= 0;
3631 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
3635 if ((ri
->enable_network
|| ri
->enable_interface
) && ri
->passive
)
3639 vty_out (vty
, " Passive Interface(s):%s", VTY_NEWLINE
);
3642 vty_out (vty
, " %s%s", ifp
->name
, VTY_NEWLINE
);
3647 vty_out (vty
, " Routing Information Sources:%s", VTY_NEWLINE
);
3648 vty_out (vty
, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE
);
3649 rip_peer_display (vty
);
3651 rip_distance_show (vty
);
3656 /* RIP configuration write function. */
3658 config_write_rip (struct vty
*vty
)
3661 struct route_node
*rn
;
3662 struct rip_distance
*rdistance
;
3666 /* Router RIP statement. */
3667 vty_out (vty
, "router rip%s", VTY_NEWLINE
);
3670 /* RIP version statement. Default is RIP version 2. */
3671 if (rip
->version_send
!= RI_RIP_VERSION_2
3672 || rip
->version_recv
!= RI_RIP_VERSION_1_AND_2
)
3673 vty_out (vty
, " version %d%s", rip
->version_send
,
3676 /* RIP timer configuration. */
3677 if (rip
->update_time
!= RIP_UPDATE_TIMER_DEFAULT
3678 || rip
->timeout_time
!= RIP_TIMEOUT_TIMER_DEFAULT
3679 || rip
->garbage_time
!= RIP_GARBAGE_TIMER_DEFAULT
)
3680 vty_out (vty
, " timers basic %lu %lu %lu%s",
3686 /* Default information configuration. */
3687 if (rip
->default_information
)
3689 if (rip
->default_information_route_map
)
3690 vty_out (vty
, " default-information originate route-map %s%s",
3691 rip
->default_information_route_map
, VTY_NEWLINE
);
3693 vty_out (vty
, " default-information originate%s",
3697 /* Redistribute configuration. */
3698 config_write_rip_redistribute (vty
, 1);
3700 /* RIP offset-list configuration. */
3701 config_write_rip_offset_list (vty
);
3703 /* RIP enabled network and interface configuration. */
3704 config_write_rip_network (vty
, 1);
3706 /* RIP default metric configuration */
3707 if (rip
->default_metric
!= RIP_DEFAULT_METRIC_DEFAULT
)
3708 vty_out (vty
, " default-metric %d%s",
3709 rip
->default_metric
, VTY_NEWLINE
);
3711 /* Distribute configuration. */
3712 write
+= config_write_distribute (vty
);
3714 /* Interface routemap configuration */
3715 write
+= config_write_if_rmap (vty
);
3717 /* Distance configuration. */
3719 vty_out (vty
, " distance %d%s", rip
->distance
, VTY_NEWLINE
);
3721 /* RIP source IP prefix distance configuration. */
3722 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3723 if ((rdistance
= rn
->info
) != NULL
)
3724 vty_out (vty
, " distance %d %s/%d %s%s", rdistance
->distance
,
3725 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
3726 rdistance
->access_list
? rdistance
->access_list
: "",
3729 /* ECMP configuration. */
3731 vty_out (vty
, " allow-ecmp%s", VTY_NEWLINE
);
3733 /* RIP static route configuration. */
3734 for (rn
= route_top (rip
->route
); rn
; rn
= route_next (rn
))
3736 vty_out (vty
, " route %s/%d%s",
3737 inet_ntoa (rn
->p
.u
.prefix4
),
3745 /* RIP node structure. */
3746 static struct cmd_node rip_node
=
3749 "%s(config-router)# ",
3753 /* Distribute-list update functions. */
3755 rip_distribute_update (struct distribute
*dist
)
3757 struct interface
*ifp
;
3758 struct rip_interface
*ri
;
3759 struct access_list
*alist
;
3760 struct prefix_list
*plist
;
3765 ifp
= if_lookup_by_name (dist
->ifname
, VRF_DEFAULT
);
3771 if (dist
->list
[DISTRIBUTE_V4_IN
])
3773 alist
= access_list_lookup (AFI_IP
, dist
->list
[DISTRIBUTE_V4_IN
]);
3775 ri
->list
[RIP_FILTER_IN
] = alist
;
3777 ri
->list
[RIP_FILTER_IN
] = NULL
;
3780 ri
->list
[RIP_FILTER_IN
] = NULL
;
3782 if (dist
->list
[DISTRIBUTE_V4_OUT
])
3784 alist
= access_list_lookup (AFI_IP
, dist
->list
[DISTRIBUTE_V4_OUT
]);
3786 ri
->list
[RIP_FILTER_OUT
] = alist
;
3788 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3791 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3793 if (dist
->prefix
[DISTRIBUTE_V4_IN
])
3795 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_IN
]);
3797 ri
->prefix
[RIP_FILTER_IN
] = plist
;
3799 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3802 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3804 if (dist
->prefix
[DISTRIBUTE_V4_OUT
])
3806 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_OUT
]);
3808 ri
->prefix
[RIP_FILTER_OUT
] = plist
;
3810 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3813 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3817 rip_distribute_update_interface (struct interface
*ifp
)
3819 struct distribute
*dist
;
3821 dist
= distribute_lookup (ifp
->name
);
3823 rip_distribute_update (dist
);
3826 /* Update all interface's distribute list. */
3829 rip_distribute_update_all (struct prefix_list
*notused
)
3831 struct interface
*ifp
;
3832 struct listnode
*node
, *nnode
;
3834 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
3835 rip_distribute_update_interface (ifp
);
3839 rip_distribute_update_all_wrapper(struct access_list
*notused
)
3841 rip_distribute_update_all(NULL
);
3844 /* Delete all added rip route. */
3849 struct route_node
*rp
;
3850 struct rip_info
*rinfo
= NULL
;
3851 struct list
*list
= NULL
;
3852 struct listnode
*listnode
= NULL
;
3858 /* Clear RIP routes */
3859 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
3860 if ((list
= rp
->info
) != NULL
)
3862 rinfo
= listgetdata (listhead (list
));
3863 if (rip_route_rte (rinfo
))
3864 rip_zebra_ipv4_delete (rp
);
3866 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
3868 RIP_TIMER_OFF (rinfo
->t_timeout
);
3869 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
3870 rip_info_free (rinfo
);
3874 route_unlock_node (rp
);
3877 /* Cancel RIP related timers. */
3878 RIP_TIMER_OFF (rip
->t_update
);
3879 RIP_TIMER_OFF (rip
->t_triggered_update
);
3880 RIP_TIMER_OFF (rip
->t_triggered_interval
);
3882 /* Cancel read thread. */
3883 THREAD_READ_OFF (rip
->t_read
);
3885 /* Close RIP socket. */
3892 /* Static RIP route configuration. */
3893 for (rp
= route_top (rip
->route
); rp
; rp
= route_next (rp
))
3897 route_unlock_node (rp
);
3900 /* RIP neighbor configuration. */
3901 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
3905 route_unlock_node (rp
);
3908 /* Redistribute related clear. */
3909 if (rip
->default_information_route_map
)
3910 free (rip
->default_information_route_map
);
3912 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
3913 if (rip
->route_map
[i
].name
)
3914 free (rip
->route_map
[i
].name
);
3916 XFREE (MTYPE_ROUTE_TABLE
, rip
->table
);
3917 XFREE (MTYPE_ROUTE_TABLE
, rip
->route
);
3918 XFREE (MTYPE_ROUTE_TABLE
, rip
->neighbor
);
3920 XFREE (MTYPE_RIP
, rip
);
3924 rip_clean_network ();
3925 rip_passive_nondefault_clean ();
3926 rip_offset_clean ();
3927 rip_interfaces_clean ();
3928 rip_distance_reset ();
3929 rip_redistribute_clean ();
3932 /* Reset all values to the default settings. */
3936 /* Reset global counters. */
3937 rip_global_route_changes
= 0;
3938 rip_global_queries
= 0;
3940 /* Call ripd related reset functions. */
3942 rip_route_map_reset ();
3944 /* Call library reset functions. */
3946 access_list_reset ();
3947 prefix_list_reset ();
3949 distribute_list_reset ();
3951 rip_interfaces_reset ();
3952 rip_distance_reset ();
3954 rip_zclient_reset ();
3958 rip_if_rmap_update (struct if_rmap
*if_rmap
)
3960 struct interface
*ifp
;
3961 struct rip_interface
*ri
;
3962 struct route_map
*rmap
;
3964 ifp
= if_lookup_by_name (if_rmap
->ifname
, VRF_DEFAULT
);
3970 if (if_rmap
->routemap
[IF_RMAP_IN
])
3972 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_IN
]);
3974 ri
->routemap
[IF_RMAP_IN
] = rmap
;
3976 ri
->routemap
[IF_RMAP_IN
] = NULL
;
3979 ri
->routemap
[RIP_FILTER_IN
] = NULL
;
3981 if (if_rmap
->routemap
[IF_RMAP_OUT
])
3983 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_OUT
]);
3985 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
3987 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
3990 ri
->routemap
[RIP_FILTER_OUT
] = NULL
;
3994 rip_if_rmap_update_interface (struct interface
*ifp
)
3996 struct if_rmap
*if_rmap
;
3998 if_rmap
= if_rmap_lookup (ifp
->name
);
4000 rip_if_rmap_update (if_rmap
);
4004 rip_routemap_update_redistribute (void)
4010 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
4012 if (rip
->route_map
[i
].name
)
4013 rip
->route_map
[i
].map
=
4014 route_map_lookup_by_name (rip
->route_map
[i
].name
);
4021 rip_routemap_update (const char *notused
)
4023 struct interface
*ifp
;
4024 struct listnode
*node
, *nnode
;
4026 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
4027 rip_if_rmap_update_interface (ifp
);
4029 rip_routemap_update_redistribute ();
4032 /* Allocate new rip structure and set default value. */
4036 /* Install top nodes. */
4037 install_node (&rip_node
, config_write_rip
);
4039 /* Install rip commands. */
4040 install_element (VIEW_NODE
, &show_ip_rip_cmd
);
4041 install_element (VIEW_NODE
, &show_ip_rip_status_cmd
);
4042 install_element (CONFIG_NODE
, &router_rip_cmd
);
4043 install_element (CONFIG_NODE
, &no_router_rip_cmd
);
4045 install_default (RIP_NODE
);
4046 install_element (RIP_NODE
, &rip_version_cmd
);
4047 install_element (RIP_NODE
, &no_rip_version_cmd
);
4048 install_element (RIP_NODE
, &rip_default_metric_cmd
);
4049 install_element (RIP_NODE
, &no_rip_default_metric_cmd
);
4050 install_element (RIP_NODE
, &rip_timers_cmd
);
4051 install_element (RIP_NODE
, &no_rip_timers_cmd
);
4052 install_element (RIP_NODE
, &rip_route_cmd
);
4053 install_element (RIP_NODE
, &no_rip_route_cmd
);
4054 install_element (RIP_NODE
, &rip_distance_cmd
);
4055 install_element (RIP_NODE
, &no_rip_distance_cmd
);
4056 install_element (RIP_NODE
, &rip_distance_source_cmd
);
4057 install_element (RIP_NODE
, &no_rip_distance_source_cmd
);
4058 install_element (RIP_NODE
, &rip_distance_source_access_list_cmd
);
4059 install_element (RIP_NODE
, &no_rip_distance_source_access_list_cmd
);
4060 install_element (RIP_NODE
, &rip_allow_ecmp_cmd
);
4061 install_element (RIP_NODE
, &no_rip_allow_ecmp_cmd
);
4063 /* Debug related init. */
4066 /* Access list install. */
4067 access_list_init ();
4068 access_list_add_hook (rip_distribute_update_all_wrapper
);
4069 access_list_delete_hook (rip_distribute_update_all_wrapper
);
4071 /* Prefix list initialize.*/
4072 prefix_list_init ();
4073 prefix_list_add_hook (rip_distribute_update_all
);
4074 prefix_list_delete_hook (rip_distribute_update_all
);
4076 /* Distribute list install. */
4077 distribute_list_init (RIP_NODE
);
4078 distribute_list_add_hook (rip_distribute_update
);
4079 distribute_list_delete_hook (rip_distribute_update
);
4082 rip_route_map_init ();
4085 route_map_add_hook (rip_routemap_update
);
4086 route_map_delete_hook (rip_routemap_update
);
4088 if_rmap_init (RIP_NODE
);
4089 if_rmap_hook_add (rip_if_rmap_update
);
4090 if_rmap_hook_delete (rip_if_rmap_update
);
4092 /* Distance control. */
4093 rip_distance_table
= route_table_init ();