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");
2405 /* Statistics updates. */
2409 /* Send RIP packet to the interface. */
2411 rip_update_interface (struct connected
*ifc
, u_char version
, int route_type
)
2413 struct interface
*ifp
= ifc
->ifp
;
2414 struct rip_interface
*ri
= ifp
->info
;
2415 struct sockaddr_in to
;
2417 /* When RIP version is 2 and multicast enable interface. */
2418 if (version
== RIPv2
&& !ri
->v2_broadcast
&& if_is_multicast (ifp
))
2420 if (IS_RIP_DEBUG_EVENT
)
2421 zlog_debug ("multicast announce on %s ", ifp
->name
);
2423 rip_output_process (ifc
, NULL
, route_type
, version
);
2427 /* If we can't send multicast packet, send it with unicast. */
2428 if (if_is_broadcast (ifp
) || if_is_pointopoint (ifp
))
2430 if (ifc
->address
->family
== AF_INET
)
2432 /* Destination address and port setting. */
2433 memset (&to
, 0, sizeof (struct sockaddr_in
));
2434 if (ifc
->destination
)
2435 /* use specified broadcast or peer destination addr */
2436 to
.sin_addr
= ifc
->destination
->u
.prefix4
;
2437 else if (ifc
->address
->prefixlen
< IPV4_MAX_PREFIXLEN
)
2438 /* calculate the appropriate broadcast address */
2439 to
.sin_addr
.s_addr
=
2440 ipv4_broadcast_addr(ifc
->address
->u
.prefix4
.s_addr
,
2441 ifc
->address
->prefixlen
);
2443 /* do not know where to send the packet */
2445 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
2447 if (IS_RIP_DEBUG_EVENT
)
2448 zlog_debug("%s announce to %s on %s",
2449 CONNECTED_PEER(ifc
) ? "unicast" : "broadcast",
2450 inet_ntoa (to
.sin_addr
), ifp
->name
);
2452 rip_output_process (ifc
, &to
, route_type
, version
);
2457 /* Update send to all interface and neighbor. */
2459 rip_update_process (int route_type
)
2461 struct listnode
*node
;
2462 struct listnode
*ifnode
, *ifnnode
;
2463 struct connected
*connected
;
2464 struct interface
*ifp
;
2465 struct rip_interface
*ri
;
2466 struct route_node
*rp
;
2467 struct sockaddr_in to
;
2470 /* Send RIP update to each interface. */
2471 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
2473 if (if_is_loopback (ifp
))
2476 if (! if_is_operative (ifp
))
2479 /* Fetch RIP interface information. */
2482 /* When passive interface is specified, suppress announce to the
2490 * If there is no version configuration in the interface,
2491 * use rip's version setting.
2493 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
) ?
2494 rip
->version_send
: ri
->ri_send
);
2496 if (IS_RIP_DEBUG_EVENT
)
2497 zlog_debug("SEND UPDATE to %s ifindex %d",
2498 ifp
->name
, ifp
->ifindex
);
2500 /* send update on each connected network */
2501 for (ALL_LIST_ELEMENTS (ifp
->connected
, ifnode
, ifnnode
, connected
))
2503 if (connected
->address
->family
== AF_INET
)
2506 rip_update_interface (connected
, RIPv1
, route_type
);
2507 if ((vsend
& RIPv2
) && if_is_multicast(ifp
))
2508 rip_update_interface (connected
, RIPv2
, route_type
);
2514 /* RIP send updates to each neighbor. */
2515 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
2516 if (rp
->info
!= NULL
)
2520 connected
= if_lookup_address (&p
->u
.prefix4
, AF_INET
, VRF_DEFAULT
);
2523 zlog_warn ("Neighbor %s doesnt have connected interface!",
2524 inet_ntoa (p
->u
.prefix4
));
2528 /* Set destination address and port */
2529 memset (&to
, 0, sizeof (struct sockaddr_in
));
2530 to
.sin_addr
= p
->u
.prefix4
;
2531 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
2533 /* RIP version is rip's configuration. */
2534 rip_output_process (connected
, &to
, route_type
, rip
->version_send
);
2538 /* RIP's periodical timer. */
2540 rip_update (struct thread
*t
)
2542 /* Clear timer pointer. */
2543 rip
->t_update
= NULL
;
2545 if (IS_RIP_DEBUG_EVENT
)
2546 zlog_debug ("update timer fire!");
2548 /* Process update output. */
2549 rip_update_process (rip_all_route
);
2551 /* Triggered updates may be suppressed if a regular update is due by
2552 the time the triggered update would be sent. */
2553 RIP_TIMER_OFF (rip
->t_triggered_interval
);
2556 /* Register myself. */
2557 rip_event (RIP_UPDATE_EVENT
, 0);
2562 /* Walk down the RIP routing table then clear changed flag. */
2564 rip_clear_changed_flag (void)
2566 struct route_node
*rp
;
2567 struct rip_info
*rinfo
= NULL
;
2568 struct list
*list
= NULL
;
2569 struct listnode
*listnode
= NULL
;
2571 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2572 if ((list
= rp
->info
) != NULL
)
2573 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2575 UNSET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
2576 /* This flag can be set only on the first entry. */
2581 /* Triggered update interval timer. */
2583 rip_triggered_interval (struct thread
*t
)
2585 int rip_triggered_update (struct thread
*);
2587 rip
->t_triggered_interval
= NULL
;
2592 rip_triggered_update (t
);
2597 /* Execute triggered update. */
2599 rip_triggered_update (struct thread
*t
)
2603 /* Clear thred pointer. */
2604 rip
->t_triggered_update
= NULL
;
2606 /* Cancel interval timer. */
2607 RIP_TIMER_OFF (rip
->t_triggered_interval
);
2610 /* Logging triggered update. */
2611 if (IS_RIP_DEBUG_EVENT
)
2612 zlog_debug ("triggered update!");
2614 /* Split Horizon processing is done when generating triggered
2615 updates as well as normal updates (see section 2.6). */
2616 rip_update_process (rip_changed_route
);
2618 /* Once all of the triggered updates have been generated, the route
2619 change flags should be cleared. */
2620 rip_clear_changed_flag ();
2622 /* After a triggered update is sent, a timer should be set for a
2623 random interval between 1 and 5 seconds. If other changes that
2624 would trigger updates occur before the timer expires, a single
2625 update is triggered when the timer expires. */
2626 interval
= (random () % 5) + 1;
2628 rip
->t_triggered_interval
=
2629 thread_add_timer (master
, rip_triggered_interval
, NULL
, interval
);
2634 /* Withdraw redistributed route. */
2636 rip_redistribute_withdraw (int type
)
2638 struct route_node
*rp
;
2639 struct rip_info
*rinfo
= NULL
;
2640 struct list
*list
= NULL
;
2645 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
2646 if ((list
= rp
->info
) != NULL
)
2648 rinfo
= listgetdata (listhead (list
));
2649 if (rinfo
->type
== type
2650 && rinfo
->sub_type
!= RIP_ROUTE_INTERFACE
)
2652 /* Perform poisoned reverse. */
2653 rinfo
->metric
= RIP_METRIC_INFINITY
;
2654 RIP_TIMER_ON (rinfo
->t_garbage_collect
,
2655 rip_garbage_collect
, rip
->garbage_time
);
2656 RIP_TIMER_OFF (rinfo
->t_timeout
);
2657 rinfo
->flags
|= RIP_RTF_CHANGED
;
2659 if (IS_RIP_DEBUG_EVENT
) {
2660 struct prefix_ipv4
*p
= (struct prefix_ipv4
*) &rp
->p
;
2662 zlog_debug ("Poisone %s/%d on the interface %s with an infinity metric [withdraw]",
2663 inet_ntoa(p
->prefix
), p
->prefixlen
,
2664 ifindex2ifname(rinfo
->ifindex
, VRF_DEFAULT
));
2667 rip_event (RIP_TRIGGERED_UPDATE
, 0);
2672 /* Create new RIP instance and set it to global variable. */
2676 rip
= XCALLOC (MTYPE_RIP
, sizeof (struct rip
));
2678 /* Set initial value. */
2679 rip
->version_send
= RI_RIP_VERSION_2
;
2680 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2681 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
2682 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
2683 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
2684 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2686 /* Initialize RIP routig table. */
2687 rip
->table
= route_table_init ();
2688 rip
->route
= route_table_init ();
2689 rip
->neighbor
= route_table_init ();
2691 /* Make output stream. */
2692 rip
->obuf
= stream_new (1500);
2695 rip
->sock
= rip_create_socket ();
2699 /* Create read and timer thread. */
2700 rip_event (RIP_READ
, rip
->sock
);
2701 rip_event (RIP_UPDATE_EVENT
, 1);
2703 QOBJ_REG (rip
, rip
);
2708 /* Sned RIP request to the destination. */
2710 rip_request_send (struct sockaddr_in
*to
, struct interface
*ifp
,
2711 u_char version
, struct connected
*connected
)
2714 struct rip_packet rip_packet
;
2715 struct listnode
*node
, *nnode
;
2717 memset (&rip_packet
, 0, sizeof (rip_packet
));
2719 rip_packet
.command
= RIP_REQUEST
;
2720 rip_packet
.version
= version
;
2721 rte
= rip_packet
.rte
;
2722 rte
->metric
= htonl (RIP_METRIC_INFINITY
);
2727 * connected is only sent for ripv1 case, or when
2728 * interface does not support multicast. Caller loops
2729 * over each connected address for this case.
2731 if (rip_send_packet ((u_char
*) &rip_packet
, sizeof (rip_packet
),
2732 to
, connected
) != sizeof (rip_packet
))
2735 return sizeof (rip_packet
);
2738 /* send request on each connected network */
2739 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, connected
))
2741 struct prefix_ipv4
*p
;
2743 p
= (struct prefix_ipv4
*) connected
->address
;
2745 if (p
->family
!= AF_INET
)
2748 if (rip_send_packet ((u_char
*) &rip_packet
, sizeof (rip_packet
),
2749 to
, connected
) != sizeof (rip_packet
))
2752 return sizeof (rip_packet
);
2756 rip_update_jitter (unsigned long time
)
2758 #define JITTER_BOUND 4
2759 /* We want to get the jitter to +/- 1/JITTER_BOUND the interval.
2760 Given that, we cannot let time be less than JITTER_BOUND seconds.
2761 The RIPv2 RFC says jitter should be small compared to
2762 update_time. We consider 1/JITTER_BOUND to be small.
2765 int jitter_input
= time
;
2768 if (jitter_input
< JITTER_BOUND
)
2769 jitter_input
= JITTER_BOUND
;
2771 jitter
= (((random () % ((jitter_input
* 2) + 1)) - jitter_input
));
2773 return jitter
/JITTER_BOUND
;
2777 rip_event (enum rip_event event
, int sock
)
2784 rip
->t_read
= thread_add_read (master
, rip_read
, NULL
, sock
);
2786 case RIP_UPDATE_EVENT
:
2787 RIP_TIMER_OFF (rip
->t_update
);
2788 jitter
= rip_update_jitter (rip
->update_time
);
2790 thread_add_timer (master
, rip_update
, NULL
,
2791 sock
? 2 : rip
->update_time
+ jitter
);
2793 case RIP_TRIGGERED_UPDATE
:
2794 if (rip
->t_triggered_interval
)
2796 else if (! rip
->t_triggered_update
)
2797 rip
->t_triggered_update
=
2798 thread_add_event (master
, rip_triggered_update
, NULL
, 0);
2805 DEFUN_NOSH (router_rip
,
2808 "Enable a routing process\n"
2809 "Routing Information Protocol (RIP)\n")
2813 /* If rip is not enabled before. */
2816 ret
= rip_create ();
2819 zlog_info ("Can't create RIP");
2823 VTY_PUSH_CONTEXT(RIP_NODE
, rip
);
2828 DEFUN (no_router_rip
,
2832 "Enable a routing process\n"
2833 "Routing Information Protocol (RIP)\n")
2843 "Set routing protocol version\n"
2849 version
= atoi (argv
[idx_number
]->arg
);
2850 if (version
!= RIPv1
&& version
!= RIPv2
)
2852 vty_out (vty
, "invalid rip version %d%s", version
,
2856 rip
->version_send
= version
;
2857 rip
->version_recv
= version
;
2862 DEFUN (no_rip_version
,
2864 "no version [(1-2)]",
2866 "Set routing protocol version\n"
2869 /* Set RIP version to the default. */
2870 rip
->version_send
= RI_RIP_VERSION_2
;
2871 rip
->version_recv
= RI_RIP_VERSION_1_AND_2
;
2880 "RIP static route configuration\n"
2881 "IP prefix <network>/<length>\n")
2883 int idx_ipv4_prefixlen
= 1;
2885 struct prefix_ipv4 p
;
2886 struct route_node
*node
;
2888 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2891 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2894 apply_mask_ipv4 (&p
);
2896 /* For router rip configuration. */
2897 node
= route_node_get (rip
->route
, (struct prefix
*) &p
);
2901 vty_out (vty
, "There is already same static route.%s", VTY_NEWLINE
);
2902 route_unlock_node (node
);
2906 node
->info
= (void *)1;
2908 rip_redistribute_add (ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0, NULL
, 0, 0, 0);
2913 DEFUN (no_rip_route
,
2915 "no route A.B.C.D/M",
2917 "RIP static route configuration\n"
2918 "IP prefix <network>/<length>\n")
2920 int idx_ipv4_prefixlen
= 2;
2922 struct prefix_ipv4 p
;
2923 struct route_node
*node
;
2925 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2928 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2931 apply_mask_ipv4 (&p
);
2933 /* For router rip configuration. */
2934 node
= route_node_lookup (rip
->route
, (struct prefix
*) &p
);
2937 vty_out (vty
, "Can't find route %s.%s", argv
[idx_ipv4_prefixlen
]->arg
,
2942 rip_redistribute_delete (ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0);
2943 route_unlock_node (node
);
2946 route_unlock_node (node
);
2953 rip_update_default_metric (void)
2955 struct route_node
*np
;
2956 struct rip_info
*rinfo
= NULL
;
2957 struct list
*list
= NULL
;
2958 struct listnode
*listnode
= NULL
;
2960 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
2961 if ((list
= np
->info
) != NULL
)
2962 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
2963 if (rinfo
->type
!= ZEBRA_ROUTE_RIP
&& rinfo
->type
!= ZEBRA_ROUTE_CONNECT
)
2964 rinfo
->metric
= rip
->default_metric
;
2968 DEFUN (rip_default_metric
,
2969 rip_default_metric_cmd
,
2970 "default-metric (1-16)",
2971 "Set a metric of redistribute routes\n"
2977 rip
->default_metric
= atoi (argv
[idx_number
]->arg
);
2978 /* rip_update_default_metric (); */
2983 DEFUN (no_rip_default_metric
,
2984 no_rip_default_metric_cmd
,
2985 "no default-metric [(1-16)]",
2987 "Set a metric of redistribute routes\n"
2992 rip
->default_metric
= RIP_DEFAULT_METRIC_DEFAULT
;
2993 /* rip_update_default_metric (); */
3001 "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
3002 "Adjust routing timers\n"
3003 "Basic routing protocol update timers\n"
3004 "Routing table update timer value in second. Default is 30.\n"
3005 "Routing information timeout timer. Default is 180.\n"
3006 "Garbage collection timer. Default is 120.\n")
3009 int idx_number_2
= 3;
3010 int idx_number_3
= 4;
3011 unsigned long update
;
3012 unsigned long timeout
;
3013 unsigned long garbage
;
3014 char *endptr
= NULL
;
3015 unsigned long RIP_TIMER_MAX
= 2147483647;
3016 unsigned long RIP_TIMER_MIN
= 5;
3018 update
= strtoul (argv
[idx_number
]->arg
, &endptr
, 10);
3019 if (update
> RIP_TIMER_MAX
|| update
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3021 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
3025 timeout
= strtoul (argv
[idx_number_2
]->arg
, &endptr
, 10);
3026 if (timeout
> RIP_TIMER_MAX
|| timeout
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3028 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
3032 garbage
= strtoul (argv
[idx_number_3
]->arg
, &endptr
, 10);
3033 if (garbage
> RIP_TIMER_MAX
|| garbage
< RIP_TIMER_MIN
|| *endptr
!= '\0')
3035 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
3039 /* Set each timer value. */
3040 rip
->update_time
= update
;
3041 rip
->timeout_time
= timeout
;
3042 rip
->garbage_time
= garbage
;
3044 /* Reset update timer thread. */
3045 rip_event (RIP_UPDATE_EVENT
, 0);
3050 DEFUN (no_rip_timers
,
3052 "no timers basic [(0-65535) (0-65535) (0-65535)]",
3054 "Adjust routing timers\n"
3055 "Basic routing protocol update timers\n"
3056 "Routing table update timer value in second. Default is 30.\n"
3057 "Routing information timeout timer. Default is 180.\n"
3058 "Garbage collection timer. Default is 120.\n")
3060 /* Set each timer value to the default. */
3061 rip
->update_time
= RIP_UPDATE_TIMER_DEFAULT
;
3062 rip
->timeout_time
= RIP_TIMEOUT_TIMER_DEFAULT
;
3063 rip
->garbage_time
= RIP_GARBAGE_TIMER_DEFAULT
;
3065 /* Reset update timer thread. */
3066 rip_event (RIP_UPDATE_EVENT
, 0);
3073 struct route_table
*rip_distance_table
;
3077 /* Distance value for the IP source prefix. */
3080 /* Name of the access-list to be matched. */
3084 static struct rip_distance
*
3085 rip_distance_new (void)
3087 return XCALLOC (MTYPE_RIP_DISTANCE
, sizeof (struct rip_distance
));
3091 rip_distance_free (struct rip_distance
*rdistance
)
3093 XFREE (MTYPE_RIP_DISTANCE
, rdistance
);
3097 rip_distance_set (struct vty
*vty
, const char *distance_str
, const char *ip_str
,
3098 const char *access_list_str
)
3101 struct prefix_ipv4 p
;
3103 struct route_node
*rn
;
3104 struct rip_distance
*rdistance
;
3106 ret
= str2prefix_ipv4 (ip_str
, &p
);
3109 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
3113 distance
= atoi (distance_str
);
3115 /* Get RIP distance node. */
3116 rn
= route_node_get (rip_distance_table
, (struct prefix
*) &p
);
3119 rdistance
= rn
->info
;
3120 route_unlock_node (rn
);
3124 rdistance
= rip_distance_new ();
3125 rn
->info
= rdistance
;
3128 /* Set distance value. */
3129 rdistance
->distance
= distance
;
3131 /* Reset access-list configuration. */
3132 if (rdistance
->access_list
)
3134 free (rdistance
->access_list
);
3135 rdistance
->access_list
= NULL
;
3137 if (access_list_str
)
3138 rdistance
->access_list
= strdup (access_list_str
);
3144 rip_distance_unset (struct vty
*vty
, const char *distance_str
,
3145 const char *ip_str
, const char *access_list_str
)
3148 struct prefix_ipv4 p
;
3149 struct route_node
*rn
;
3150 struct rip_distance
*rdistance
;
3152 ret
= str2prefix_ipv4 (ip_str
, &p
);
3155 vty_out (vty
, "Malformed prefix%s", VTY_NEWLINE
);
3159 rn
= route_node_lookup (rip_distance_table
, (struct prefix
*)&p
);
3162 vty_out (vty
, "Can't find specified prefix%s", VTY_NEWLINE
);
3166 rdistance
= rn
->info
;
3168 if (rdistance
->access_list
)
3169 free (rdistance
->access_list
);
3170 rip_distance_free (rdistance
);
3173 route_unlock_node (rn
);
3174 route_unlock_node (rn
);
3180 rip_distance_reset (void)
3182 struct route_node
*rn
;
3183 struct rip_distance
*rdistance
;
3185 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3186 if ((rdistance
= rn
->info
) != NULL
)
3188 if (rdistance
->access_list
)
3189 free (rdistance
->access_list
);
3190 rip_distance_free (rdistance
);
3192 route_unlock_node (rn
);
3196 /* Apply RIP information to distance method. */
3198 rip_distance_apply (struct rip_info
*rinfo
)
3200 struct route_node
*rn
;
3201 struct prefix_ipv4 p
;
3202 struct rip_distance
*rdistance
;
3203 struct access_list
*alist
;
3208 memset (&p
, 0, sizeof (struct prefix_ipv4
));
3210 p
.prefix
= rinfo
->from
;
3211 p
.prefixlen
= IPV4_MAX_BITLEN
;
3213 /* Check source address. */
3214 rn
= route_node_match (rip_distance_table
, (struct prefix
*) &p
);
3217 rdistance
= rn
->info
;
3218 route_unlock_node (rn
);
3220 if (rdistance
->access_list
)
3222 alist
= access_list_lookup (AFI_IP
, rdistance
->access_list
);
3225 if (access_list_apply (alist
, &rinfo
->rp
->p
) == FILTER_DENY
)
3228 return rdistance
->distance
;
3231 return rdistance
->distance
;
3235 return rip
->distance
;
3241 rip_distance_show (struct vty
*vty
)
3243 struct route_node
*rn
;
3244 struct rip_distance
*rdistance
;
3248 vty_out (vty
, " Distance: (default is %d)%s",
3249 rip
->distance
? rip
->distance
:ZEBRA_RIP_DISTANCE_DEFAULT
,
3252 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3253 if ((rdistance
= rn
->info
) != NULL
)
3257 vty_out (vty
, " Address Distance List%s",
3261 sprintf (buf
, "%s/%d", inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
);
3262 vty_out (vty
, " %-20s %4d %s%s",
3263 buf
, rdistance
->distance
,
3264 rdistance
->access_list
? rdistance
->access_list
: "",
3269 DEFUN (rip_distance
,
3272 "Administrative distance\n"
3276 rip
->distance
= atoi (argv
[idx_number
]->arg
);
3280 DEFUN (no_rip_distance
,
3281 no_rip_distance_cmd
,
3282 "no distance (1-255)",
3284 "Administrative distance\n"
3291 DEFUN (rip_distance_source
,
3292 rip_distance_source_cmd
,
3293 "distance (1-255) A.B.C.D/M",
3294 "Administrative distance\n"
3296 "IP source prefix\n")
3299 int idx_ipv4_prefixlen
= 2;
3300 rip_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3304 DEFUN (no_rip_distance_source
,
3305 no_rip_distance_source_cmd
,
3306 "no distance (1-255) A.B.C.D/M",
3308 "Administrative distance\n"
3310 "IP source prefix\n")
3313 int idx_ipv4_prefixlen
= 3;
3314 rip_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
3318 DEFUN (rip_distance_source_access_list
,
3319 rip_distance_source_access_list_cmd
,
3320 "distance (1-255) A.B.C.D/M WORD",
3321 "Administrative distance\n"
3323 "IP source prefix\n"
3324 "Access list name\n")
3327 int idx_ipv4_prefixlen
= 2;
3329 rip_distance_set (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3333 DEFUN (no_rip_distance_source_access_list
,
3334 no_rip_distance_source_access_list_cmd
,
3335 "no distance (1-255) A.B.C.D/M WORD",
3337 "Administrative distance\n"
3339 "IP source prefix\n"
3340 "Access list name\n")
3343 int idx_ipv4_prefixlen
= 3;
3345 rip_distance_unset (vty
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
3349 /* Update ECMP routes to zebra when ECMP is disabled. */
3351 rip_ecmp_disable (void)
3353 struct route_node
*rp
;
3354 struct rip_info
*rinfo
, *tmp_rinfo
;
3356 struct listnode
*node
, *nextnode
;
3361 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
3362 if ((list
= rp
->info
) != NULL
&& listcount (list
) > 1)
3364 rinfo
= listgetdata (listhead (list
));
3365 if (!rip_route_rte (rinfo
))
3368 /* Drop all other entries, except the first one. */
3369 for (ALL_LIST_ELEMENTS (list
, node
, nextnode
, tmp_rinfo
))
3370 if (tmp_rinfo
!= rinfo
)
3372 RIP_TIMER_OFF (tmp_rinfo
->t_timeout
);
3373 RIP_TIMER_OFF (tmp_rinfo
->t_garbage_collect
);
3374 list_delete_node (list
, node
);
3375 rip_info_free (tmp_rinfo
);
3379 rip_zebra_ipv4_add (rp
);
3381 /* Set the route change flag. */
3382 SET_FLAG (rinfo
->flags
, RIP_RTF_CHANGED
);
3384 /* Signal the output process to trigger an update. */
3385 rip_event (RIP_TRIGGERED_UPDATE
, 0);
3389 DEFUN (rip_allow_ecmp
,
3392 "Allow Equal Cost MultiPath\n")
3396 vty_out (vty
, "ECMP is already enabled.%s", VTY_NEWLINE
);
3401 zlog_info ("ECMP is enabled.");
3405 DEFUN (no_rip_allow_ecmp
,
3406 no_rip_allow_ecmp_cmd
,
3409 "Allow Equal Cost MultiPath\n")
3413 vty_out (vty
, "ECMP is already disabled.%s", VTY_NEWLINE
);
3418 zlog_info ("ECMP is disabled.");
3419 rip_ecmp_disable ();
3423 /* Print out routes update time. */
3425 rip_vty_out_uptime (struct vty
*vty
, struct rip_info
*rinfo
)
3430 char timebuf
[TIME_BUF
];
3431 struct thread
*thread
;
3433 if ((thread
= rinfo
->t_timeout
) != NULL
)
3435 clock
= thread_timer_remain_second (thread
);
3436 tm
= gmtime (&clock
);
3437 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
3438 vty_out (vty
, "%5s", timebuf
);
3440 else if ((thread
= rinfo
->t_garbage_collect
) != NULL
)
3442 clock
= thread_timer_remain_second (thread
);
3443 tm
= gmtime (&clock
);
3444 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
3445 vty_out (vty
, "%5s", timebuf
);
3450 rip_route_type_print (int sub_type
)
3456 case RIP_ROUTE_STATIC
:
3458 case RIP_ROUTE_DEFAULT
:
3460 case RIP_ROUTE_REDISTRIBUTE
:
3462 case RIP_ROUTE_INTERFACE
:
3474 "Show RIP routes\n")
3476 struct route_node
*np
;
3477 struct rip_info
*rinfo
= NULL
;
3478 struct list
*list
= NULL
;
3479 struct listnode
*listnode
= NULL
;
3484 vty_out (vty
, "Codes: R - RIP, C - connected, S - Static, O - OSPF, B - BGP%s"
3486 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
3487 " (i) - interface%s%s"
3488 " Network Next Hop Metric From Tag Time%s",
3489 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
3491 for (np
= route_top (rip
->table
); np
; np
= route_next (np
))
3492 if ((list
= np
->info
) != NULL
)
3493 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
3497 len
= vty_out (vty
, "%c(%s) %s/%d",
3498 /* np->lock, For debugging. */
3499 zebra_route_char(rinfo
->type
),
3500 rip_route_type_print (rinfo
->sub_type
),
3501 inet_ntoa (np
->p
.u
.prefix4
), np
->p
.prefixlen
);
3506 vty_out (vty
, "%*s", len
, " ");
3508 if (rinfo
->nexthop
.s_addr
)
3509 vty_out (vty
, "%-20s %2d ", inet_ntoa (rinfo
->nexthop
),
3512 vty_out (vty
, "0.0.0.0 %2d ", rinfo
->metric
);
3514 /* Route which exist in kernel routing table. */
3515 if ((rinfo
->type
== ZEBRA_ROUTE_RIP
) &&
3516 (rinfo
->sub_type
== RIP_ROUTE_RTE
))
3518 vty_out (vty
, "%-15s ", inet_ntoa (rinfo
->from
));
3519 vty_out (vty
, "%3"ROUTE_TAG_PRI
" ", (route_tag_t
)rinfo
->tag
);
3520 rip_vty_out_uptime (vty
, rinfo
);
3522 else if (rinfo
->metric
== RIP_METRIC_INFINITY
)
3524 vty_out (vty
, "self ");
3525 vty_out (vty
, "%3"ROUTE_TAG_PRI
" ", (route_tag_t
)rinfo
->tag
);
3526 rip_vty_out_uptime (vty
, rinfo
);
3530 if (rinfo
->external_metric
)
3532 len
= vty_out (vty
, "self (%s:%d)",
3533 zebra_route_string(rinfo
->type
),
3534 rinfo
->external_metric
);
3537 vty_out (vty
, "%*s", len
, " ");
3540 vty_out (vty
, "self ");
3541 vty_out (vty
, "%3"ROUTE_TAG_PRI
, (route_tag_t
)rinfo
->tag
);
3544 vty_out (vty
, "%s", VTY_NEWLINE
);
3549 /* Vincent: formerly, it was show_ip_protocols_rip: "show ip protocols" */
3550 DEFUN (show_ip_rip_status
,
3551 show_ip_rip_status_cmd
,
3552 "show ip rip status",
3556 "IP routing protocol process parameters and statistics\n")
3558 struct listnode
*node
;
3559 struct interface
*ifp
;
3560 struct rip_interface
*ri
;
3561 extern const struct message ri_version_msg
[];
3562 const char *send_version
;
3563 const char *receive_version
;
3568 vty_out (vty
, "Routing Protocol is \"rip\"%s", VTY_NEWLINE
);
3569 vty_out (vty
, " Sending updates every %ld seconds with +/-50%%,",
3571 vty_out (vty
, " next due in %lu seconds%s",
3572 thread_timer_remain_second(rip
->t_update
),
3574 vty_out (vty
, " Timeout after %ld seconds,", rip
->timeout_time
);
3575 vty_out (vty
, " garbage collect after %ld seconds%s", rip
->garbage_time
,
3578 /* Filtering status show. */
3579 config_show_distribute (vty
);
3581 /* Default metric information. */
3582 vty_out (vty
, " Default redistribution metric is %d%s",
3583 rip
->default_metric
, VTY_NEWLINE
);
3585 /* Redistribute information. */
3586 vty_out (vty
, " Redistributing:");
3587 config_write_rip_redistribute (vty
, 0);
3588 vty_out (vty
, "%s", VTY_NEWLINE
);
3590 vty_out (vty
, " Default version control: send version %s,",
3591 lookup(ri_version_msg
,rip
->version_send
));
3592 if (rip
->version_recv
== RI_RIP_VERSION_1_AND_2
)
3593 vty_out (vty
, " receive any version %s", VTY_NEWLINE
);
3595 vty_out (vty
, " receive version %s %s",
3596 lookup(ri_version_msg
,rip
->version_recv
), VTY_NEWLINE
);
3598 vty_out (vty
, " Interface Send Recv Key-chain%s", VTY_NEWLINE
);
3600 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
3607 if (ri
->enable_network
|| ri
->enable_interface
)
3609 if (ri
->ri_send
== RI_RIP_UNSPEC
)
3610 send_version
= lookup (ri_version_msg
, rip
->version_send
);
3612 send_version
= lookup (ri_version_msg
, ri
->ri_send
);
3614 if (ri
->ri_receive
== RI_RIP_UNSPEC
)
3615 receive_version
= lookup (ri_version_msg
, rip
->version_recv
);
3617 receive_version
= lookup (ri_version_msg
, ri
->ri_receive
);
3619 vty_out (vty
, " %-17s%-3s %-3s %s%s", ifp
->name
,
3622 ri
->key_chain
? ri
->key_chain
: "",
3627 vty_out (vty
, " Routing for Networks:%s", VTY_NEWLINE
);
3628 config_write_rip_network (vty
, 0);
3631 int found_passive
= 0;
3632 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
3636 if ((ri
->enable_network
|| ri
->enable_interface
) && ri
->passive
)
3640 vty_out (vty
, " Passive Interface(s):%s", VTY_NEWLINE
);
3643 vty_out (vty
, " %s%s", ifp
->name
, VTY_NEWLINE
);
3648 vty_out (vty
, " Routing Information Sources:%s", VTY_NEWLINE
);
3649 vty_out (vty
, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE
);
3650 rip_peer_display (vty
);
3652 rip_distance_show (vty
);
3657 /* RIP configuration write function. */
3659 config_write_rip (struct vty
*vty
)
3662 struct route_node
*rn
;
3663 struct rip_distance
*rdistance
;
3667 /* Router RIP statement. */
3668 vty_out (vty
, "router rip%s", VTY_NEWLINE
);
3671 /* RIP version statement. Default is RIP version 2. */
3672 if (rip
->version_send
!= RI_RIP_VERSION_2
3673 || rip
->version_recv
!= RI_RIP_VERSION_1_AND_2
)
3674 vty_out (vty
, " version %d%s", rip
->version_send
,
3677 /* RIP timer configuration. */
3678 if (rip
->update_time
!= RIP_UPDATE_TIMER_DEFAULT
3679 || rip
->timeout_time
!= RIP_TIMEOUT_TIMER_DEFAULT
3680 || rip
->garbage_time
!= RIP_GARBAGE_TIMER_DEFAULT
)
3681 vty_out (vty
, " timers basic %lu %lu %lu%s",
3687 /* Default information configuration. */
3688 if (rip
->default_information
)
3690 if (rip
->default_information_route_map
)
3691 vty_out (vty
, " default-information originate route-map %s%s",
3692 rip
->default_information_route_map
, VTY_NEWLINE
);
3694 vty_out (vty
, " default-information originate%s",
3698 /* Redistribute configuration. */
3699 config_write_rip_redistribute (vty
, 1);
3701 /* RIP offset-list configuration. */
3702 config_write_rip_offset_list (vty
);
3704 /* RIP enabled network and interface configuration. */
3705 config_write_rip_network (vty
, 1);
3707 /* RIP default metric configuration */
3708 if (rip
->default_metric
!= RIP_DEFAULT_METRIC_DEFAULT
)
3709 vty_out (vty
, " default-metric %d%s",
3710 rip
->default_metric
, VTY_NEWLINE
);
3712 /* Distribute configuration. */
3713 write
+= config_write_distribute (vty
);
3715 /* Interface routemap configuration */
3716 write
+= config_write_if_rmap (vty
);
3718 /* Distance configuration. */
3720 vty_out (vty
, " distance %d%s", rip
->distance
, VTY_NEWLINE
);
3722 /* RIP source IP prefix distance configuration. */
3723 for (rn
= route_top (rip_distance_table
); rn
; rn
= route_next (rn
))
3724 if ((rdistance
= rn
->info
) != NULL
)
3725 vty_out (vty
, " distance %d %s/%d %s%s", rdistance
->distance
,
3726 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
3727 rdistance
->access_list
? rdistance
->access_list
: "",
3730 /* ECMP configuration. */
3732 vty_out (vty
, " allow-ecmp%s", VTY_NEWLINE
);
3734 /* RIP static route configuration. */
3735 for (rn
= route_top (rip
->route
); rn
; rn
= route_next (rn
))
3737 vty_out (vty
, " route %s/%d%s",
3738 inet_ntoa (rn
->p
.u
.prefix4
),
3746 /* RIP node structure. */
3747 static struct cmd_node rip_node
=
3750 "%s(config-router)# ",
3754 /* Distribute-list update functions. */
3756 rip_distribute_update (struct distribute
*dist
)
3758 struct interface
*ifp
;
3759 struct rip_interface
*ri
;
3760 struct access_list
*alist
;
3761 struct prefix_list
*plist
;
3766 ifp
= if_lookup_by_name (dist
->ifname
, VRF_DEFAULT
);
3772 if (dist
->list
[DISTRIBUTE_V4_IN
])
3774 alist
= access_list_lookup (AFI_IP
, dist
->list
[DISTRIBUTE_V4_IN
]);
3776 ri
->list
[RIP_FILTER_IN
] = alist
;
3778 ri
->list
[RIP_FILTER_IN
] = NULL
;
3781 ri
->list
[RIP_FILTER_IN
] = NULL
;
3783 if (dist
->list
[DISTRIBUTE_V4_OUT
])
3785 alist
= access_list_lookup (AFI_IP
, dist
->list
[DISTRIBUTE_V4_OUT
]);
3787 ri
->list
[RIP_FILTER_OUT
] = alist
;
3789 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3792 ri
->list
[RIP_FILTER_OUT
] = NULL
;
3794 if (dist
->prefix
[DISTRIBUTE_V4_IN
])
3796 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_IN
]);
3798 ri
->prefix
[RIP_FILTER_IN
] = plist
;
3800 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3803 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
3805 if (dist
->prefix
[DISTRIBUTE_V4_OUT
])
3807 plist
= prefix_list_lookup (AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_OUT
]);
3809 ri
->prefix
[RIP_FILTER_OUT
] = plist
;
3811 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3814 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
3818 rip_distribute_update_interface (struct interface
*ifp
)
3820 struct distribute
*dist
;
3822 dist
= distribute_lookup (ifp
->name
);
3824 rip_distribute_update (dist
);
3827 /* Update all interface's distribute list. */
3830 rip_distribute_update_all (struct prefix_list
*notused
)
3832 struct interface
*ifp
;
3833 struct listnode
*node
, *nnode
;
3835 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
3836 rip_distribute_update_interface (ifp
);
3840 rip_distribute_update_all_wrapper(struct access_list
*notused
)
3842 rip_distribute_update_all(NULL
);
3845 /* Delete all added rip route. */
3850 struct route_node
*rp
;
3851 struct rip_info
*rinfo
= NULL
;
3852 struct list
*list
= NULL
;
3853 struct listnode
*listnode
= NULL
;
3859 /* Clear RIP routes */
3860 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
3861 if ((list
= rp
->info
) != NULL
)
3863 rinfo
= listgetdata (listhead (list
));
3864 if (rip_route_rte (rinfo
))
3865 rip_zebra_ipv4_delete (rp
);
3867 for (ALL_LIST_ELEMENTS_RO (list
, listnode
, rinfo
))
3869 RIP_TIMER_OFF (rinfo
->t_timeout
);
3870 RIP_TIMER_OFF (rinfo
->t_garbage_collect
);
3871 rip_info_free (rinfo
);
3875 route_unlock_node (rp
);
3878 /* Cancel RIP related timers. */
3879 RIP_TIMER_OFF (rip
->t_update
);
3880 RIP_TIMER_OFF (rip
->t_triggered_update
);
3881 RIP_TIMER_OFF (rip
->t_triggered_interval
);
3883 /* Cancel read thread. */
3884 THREAD_READ_OFF (rip
->t_read
);
3886 /* Close RIP socket. */
3893 /* Static RIP route configuration. */
3894 for (rp
= route_top (rip
->route
); rp
; rp
= route_next (rp
))
3898 route_unlock_node (rp
);
3901 /* RIP neighbor configuration. */
3902 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
3906 route_unlock_node (rp
);
3909 /* Redistribute related clear. */
3910 if (rip
->default_information_route_map
)
3911 free (rip
->default_information_route_map
);
3913 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
3914 if (rip
->route_map
[i
].name
)
3915 free (rip
->route_map
[i
].name
);
3917 XFREE (MTYPE_ROUTE_TABLE
, rip
->table
);
3918 XFREE (MTYPE_ROUTE_TABLE
, rip
->route
);
3919 XFREE (MTYPE_ROUTE_TABLE
, rip
->neighbor
);
3921 XFREE (MTYPE_RIP
, rip
);
3925 rip_clean_network ();
3926 rip_passive_nondefault_clean ();
3927 rip_offset_clean ();
3928 rip_interfaces_clean ();
3929 rip_distance_reset ();
3930 rip_redistribute_clean ();
3933 /* Reset all values to the default settings. */
3937 /* Reset global counters. */
3938 rip_global_route_changes
= 0;
3939 rip_global_queries
= 0;
3941 /* Call ripd related reset functions. */
3943 rip_route_map_reset ();
3945 /* Call library reset functions. */
3947 access_list_reset ();
3948 prefix_list_reset ();
3950 distribute_list_reset ();
3952 rip_interfaces_reset ();
3953 rip_distance_reset ();
3955 rip_zclient_reset ();
3959 rip_if_rmap_update (struct if_rmap
*if_rmap
)
3961 struct interface
*ifp
;
3962 struct rip_interface
*ri
;
3963 struct route_map
*rmap
;
3965 ifp
= if_lookup_by_name (if_rmap
->ifname
, VRF_DEFAULT
);
3971 if (if_rmap
->routemap
[IF_RMAP_IN
])
3973 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_IN
]);
3975 ri
->routemap
[IF_RMAP_IN
] = rmap
;
3977 ri
->routemap
[IF_RMAP_IN
] = NULL
;
3980 ri
->routemap
[RIP_FILTER_IN
] = NULL
;
3982 if (if_rmap
->routemap
[IF_RMAP_OUT
])
3984 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_OUT
]);
3986 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
3988 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
3991 ri
->routemap
[RIP_FILTER_OUT
] = NULL
;
3995 rip_if_rmap_update_interface (struct interface
*ifp
)
3997 struct if_rmap
*if_rmap
;
3999 if_rmap
= if_rmap_lookup (ifp
->name
);
4001 rip_if_rmap_update (if_rmap
);
4005 rip_routemap_update_redistribute (void)
4011 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
4013 if (rip
->route_map
[i
].name
)
4014 rip
->route_map
[i
].map
=
4015 route_map_lookup_by_name (rip
->route_map
[i
].name
);
4022 rip_routemap_update (const char *notused
)
4024 struct interface
*ifp
;
4025 struct listnode
*node
, *nnode
;
4027 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
4028 rip_if_rmap_update_interface (ifp
);
4030 rip_routemap_update_redistribute ();
4033 /* Allocate new rip structure and set default value. */
4037 /* Install top nodes. */
4038 install_node (&rip_node
, config_write_rip
);
4040 /* Install rip commands. */
4041 install_element (VIEW_NODE
, &show_ip_rip_cmd
);
4042 install_element (VIEW_NODE
, &show_ip_rip_status_cmd
);
4043 install_element (CONFIG_NODE
, &router_rip_cmd
);
4044 install_element (CONFIG_NODE
, &no_router_rip_cmd
);
4046 install_default (RIP_NODE
);
4047 install_element (RIP_NODE
, &rip_version_cmd
);
4048 install_element (RIP_NODE
, &no_rip_version_cmd
);
4049 install_element (RIP_NODE
, &rip_default_metric_cmd
);
4050 install_element (RIP_NODE
, &no_rip_default_metric_cmd
);
4051 install_element (RIP_NODE
, &rip_timers_cmd
);
4052 install_element (RIP_NODE
, &no_rip_timers_cmd
);
4053 install_element (RIP_NODE
, &rip_route_cmd
);
4054 install_element (RIP_NODE
, &no_rip_route_cmd
);
4055 install_element (RIP_NODE
, &rip_distance_cmd
);
4056 install_element (RIP_NODE
, &no_rip_distance_cmd
);
4057 install_element (RIP_NODE
, &rip_distance_source_cmd
);
4058 install_element (RIP_NODE
, &no_rip_distance_source_cmd
);
4059 install_element (RIP_NODE
, &rip_distance_source_access_list_cmd
);
4060 install_element (RIP_NODE
, &no_rip_distance_source_access_list_cmd
);
4061 install_element (RIP_NODE
, &rip_allow_ecmp_cmd
);
4062 install_element (RIP_NODE
, &no_rip_allow_ecmp_cmd
);
4064 /* Debug related init. */
4067 /* Access list install. */
4068 access_list_init ();
4069 access_list_add_hook (rip_distribute_update_all_wrapper
);
4070 access_list_delete_hook (rip_distribute_update_all_wrapper
);
4072 /* Prefix list initialize.*/
4073 prefix_list_init ();
4074 prefix_list_add_hook (rip_distribute_update_all
);
4075 prefix_list_delete_hook (rip_distribute_update_all
);
4077 /* Distribute list install. */
4078 distribute_list_init (RIP_NODE
);
4079 distribute_list_add_hook (rip_distribute_update
);
4080 distribute_list_delete_hook (rip_distribute_update
);
4083 rip_route_map_init ();
4086 route_map_add_hook (rip_routemap_update
);
4087 route_map_delete_hook (rip_routemap_update
);
4089 if_rmap_init (RIP_NODE
);
4090 if_rmap_hook_add (rip_if_rmap_update
);
4091 if_rmap_hook_delete (rip_if_rmap_update
);
4093 /* Distance control. */
4094 rip_distance_table
= route_table_init ();