MiniDLNA update: 1.0.19.1 to 1.0.20
[tomato.git] / release / src / router / zebra / ripd / rip_interface.c
blob8c2d9d7fda0291e793df6705b32177679e2ea82a
1 /* Interface related function for RIP.
2 * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
22 #include <zebra.h>
24 #include "command.h"
25 #include "if.h"
26 #include "sockunion.h"
27 #include "prefix.h"
28 #include "memory.h"
29 #include "network.h"
30 #include "table.h"
31 #include "log.h"
32 #include "stream.h"
33 #include "thread.h"
34 #include "zclient.h"
35 #include "filter.h"
36 #include "sockopt.h"
38 #include "zebra/connected.h"
40 #include "ripd/ripd.h"
41 #include "ripd/rip_debug.h"
43 void rip_enable_apply (struct interface *);
44 void rip_passive_interface_apply (struct interface *);
45 int rip_if_down(struct interface *ifp);
47 struct message ri_version_msg[] =
49 {RI_RIP_VERSION_1, "1"},
50 {RI_RIP_VERSION_2, "2"},
51 {RI_RIP_VERSION_1_AND_2, "1 2"},
52 {0, NULL}
55 /* RIP enabled network vector. */
56 vector rip_enable_interface;
58 /* RIP enabled interface table. */
59 struct route_table *rip_enable_network;
61 /* Vector to store passive-interface name. */
62 vector Vrip_passive_interface;
64 /* Join to the RIP version 2 multicast group. */
65 int
66 ipv4_multicast_join (int sock,
67 struct in_addr group,
68 struct in_addr ifa,
69 unsigned int ifindex)
71 int ret;
73 ret = setsockopt_multicast_ipv4 (sock,
74 IP_ADD_MEMBERSHIP,
75 ifa,
76 group.s_addr,
77 ifindex);
79 if (ret < 0)
80 zlog (NULL, LOG_INFO, "can't setsockopt IP_ADD_MEMBERSHIP %s",
81 strerror (errno));
83 return ret;
86 /* Leave from the RIP version 2 multicast group. */
87 int
88 ipv4_multicast_leave (int sock,
89 struct in_addr group,
90 struct in_addr ifa,
91 unsigned int ifindex)
93 int ret;
95 ret = setsockopt_multicast_ipv4 (sock,
96 IP_DROP_MEMBERSHIP,
97 ifa,
98 group.s_addr,
99 ifindex);
101 if (ret < 0)
102 zlog (NULL, LOG_INFO, "can't setsockopt IP_DROP_MEMBERSHIP");
104 return ret;
107 /* Allocate new RIP's interface configuration. */
108 struct rip_interface *
109 rip_interface_new ()
111 struct rip_interface *ri;
113 ri = XMALLOC (MTYPE_RIP_INTERFACE, sizeof (struct rip_interface));
114 memset (ri, 0, sizeof (struct rip_interface));
116 /* Default authentication type is simple password for Cisco
117 compatibility. */
118 /* ri->auth_type = RIP_NO_AUTH; */
119 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
121 /* Set default split-horizon behavior. If the interface is Frame
122 Relay or SMDS is enabled, the default value for split-horizon is
123 off. But currently Zebra does detect Frame Relay or SMDS
124 interface. So all interface is set to split horizon. */
125 ri->split_horizon_default = 1;
126 ri->split_horizon = ri->split_horizon_default;
128 return ri;
131 void
132 rip_interface_multicast_set (int sock, struct interface *ifp)
134 int ret;
135 listnode node;
136 struct servent *sp;
137 struct sockaddr_in from;
139 for (node = listhead (ifp->connected); node; nextnode (node))
141 struct prefix_ipv4 *p;
142 struct connected *connected;
143 struct in_addr addr;
145 connected = getdata (node);
146 p = (struct prefix_ipv4 *) connected->address;
148 if (p->family == AF_INET)
150 addr = p->prefix;
152 if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF,
153 addr, 0, ifp->ifindex) < 0)
155 zlog_warn ("Can't setsockopt IP_MULTICAST_IF to fd %d", sock);
156 return;
159 /* Bind myself. */
160 memset (&from, 0, sizeof (struct sockaddr_in));
162 /* Set RIP port. */
163 sp = getservbyname ("router", "udp");
164 if (sp)
165 from.sin_port = sp->s_port;
166 else
167 from.sin_port = htons (RIP_PORT_DEFAULT);
169 /* Address shoud be any address. */
170 from.sin_family = AF_INET;
171 from.sin_addr = addr;
172 #ifdef HAVE_SIN_LEN
173 from.sin_len = sizeof (struct sockaddr_in);
174 #endif /* HAVE_SIN_LEN */
176 ret = bind (sock, (struct sockaddr *) & from,
177 sizeof (struct sockaddr_in));
178 if (ret < 0)
180 zlog_warn ("Can't bind socket: %s", strerror (errno));
181 return;
184 return;
190 /* Send RIP request packet to specified interface. */
191 void
192 rip_request_interface_send (struct interface *ifp, u_char version)
194 struct sockaddr_in to;
196 /* RIPv2 support multicast. */
197 if (version == RIPv2 && if_is_multicast (ifp))
200 if (IS_RIP_DEBUG_EVENT)
201 zlog_info ("multicast request on %s", ifp->name);
203 rip_request_send (NULL, ifp, version);
204 return;
207 /* RIPv1 and non multicast interface. */
208 if (if_is_pointopoint (ifp) || if_is_broadcast (ifp))
210 listnode cnode;
212 if (IS_RIP_DEBUG_EVENT)
213 zlog_info ("broadcast request to %s", ifp->name);
215 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
217 struct prefix_ipv4 *p;
218 struct connected *connected;
220 connected = getdata (cnode);
221 p = (struct prefix_ipv4 *) connected->destination;
223 if (p->family == AF_INET)
225 memset (&to, 0, sizeof (struct sockaddr_in));
226 to.sin_port = htons (RIP_PORT_DEFAULT);
227 to.sin_addr = p->prefix;
229 rip_request_send (&to, ifp, version);
235 /* This will be executed when interface goes up. */
236 void
237 rip_request_interface (struct interface *ifp)
239 struct rip_interface *ri;
241 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
242 if (if_is_loopback (ifp))
243 return;
245 /* If interface is down, don't send RIP packet. */
246 if (! if_is_up (ifp))
247 return;
249 /* Fetch RIP interface information. */
250 ri = ifp->info;
253 /* If there is no version configuration in the interface,
254 use rip's version setting. */
255 if (ri->ri_send == RI_RIP_UNSPEC)
257 if (rip->version == RIPv1)
258 rip_request_interface_send (ifp, RIPv1);
259 else
260 rip_request_interface_send (ifp, RIPv2);
262 /* If interface has RIP version configuration use it. */
263 else
265 if (ri->ri_send & RIPv1)
266 rip_request_interface_send (ifp, RIPv1);
267 if (ri->ri_send & RIPv2)
268 rip_request_interface_send (ifp, RIPv2);
272 /* Send RIP request to the neighbor. */
273 void
274 rip_request_neighbor (struct in_addr addr)
276 struct sockaddr_in to;
278 memset (&to, 0, sizeof (struct sockaddr_in));
279 to.sin_port = htons (RIP_PORT_DEFAULT);
280 to.sin_addr = addr;
282 rip_request_send (&to, NULL, rip->version);
285 /* Request routes at all interfaces. */
286 void
287 rip_request_neighbor_all ()
289 struct route_node *rp;
291 if (! rip)
292 return;
294 if (IS_RIP_DEBUG_EVENT)
295 zlog_info ("request to the all neighbor");
297 /* Send request to all neighbor. */
298 for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
299 if (rp->info)
300 rip_request_neighbor (rp->p.u.prefix4);
303 /* Multicast packet receive socket. */
305 rip_multicast_join (struct interface *ifp, int sock)
307 struct rip_interface *ri;
308 listnode cnode;
310 ri = ifp->info;
312 if (if_is_up (ifp) && if_is_multicast (ifp))
314 if (IS_RIP_DEBUG_EVENT)
315 zlog_info ("multicast join at %s", ifp->name);
317 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
319 struct prefix_ipv4 *p;
320 struct connected *connected;
321 struct in_addr group;
323 connected = getdata (cnode);
324 p = (struct prefix_ipv4 *) connected->address;
326 if (p->family != AF_INET)
327 continue;
329 group.s_addr = htonl (INADDR_RIP_GROUP);
330 if (ipv4_multicast_join (sock, group, p->prefix, ifp->ifindex) < 0)
331 return -1;
332 else
334 ri->joined_multicast = 1;
335 return 0;
339 return 0;
342 /* Leave from multicast group. */
343 void
344 rip_multicast_leave (struct interface *ifp, int sock)
346 struct rip_interface *ri;
347 listnode cnode;
349 ri = ifp->info;
351 if (ri->joined_multicast)
353 ri->joined_multicast = 0;
354 if (IS_RIP_DEBUG_EVENT)
355 zlog_info ("multicast leave from %s", ifp->name);
357 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
359 struct prefix_ipv4 *p;
360 struct connected *connected;
361 struct in_addr group;
363 connected = getdata (cnode);
364 p = (struct prefix_ipv4 *) connected->address;
366 if (p->family != AF_INET)
367 continue;
369 group.s_addr = htonl (INADDR_RIP_GROUP);
370 if (ipv4_multicast_leave (sock, group, p->prefix, ifp->ifindex) == 0)
371 return;
376 /* Is there and address on interface that I could use ? */
378 rip_if_ipv4_address_check (struct interface *ifp)
380 struct listnode *nn;
381 struct connected *connected;
382 int count = 0;
384 for (nn = listhead (ifp->connected); nn; nextnode (nn))
385 if ((connected = getdata (nn)) != NULL)
387 struct prefix *p;
389 p = connected->address;
391 if (p->family == AF_INET)
393 count++;
397 return count;
403 /* Does this address belongs to me ? */
405 if_check_address (struct in_addr addr)
407 listnode node;
409 for (node = listhead (iflist); node; nextnode (node))
411 listnode cnode;
412 struct interface *ifp;
414 ifp = getdata (node);
416 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
418 struct connected *connected;
419 struct prefix_ipv4 *p;
421 connected = getdata (cnode);
422 p = (struct prefix_ipv4 *) connected->address;
424 if (p->family != AF_INET)
425 continue;
427 if (IPV4_ADDR_CMP (&p->prefix, &addr) == 0)
428 return 1;
431 return 0;
434 /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */
436 if_valid_neighbor (struct in_addr addr)
438 listnode node;
439 struct connected *connected = NULL;
440 struct prefix_ipv4 *p;
442 for (node = listhead (iflist); node; nextnode (node))
444 listnode cnode;
445 struct interface *ifp;
447 ifp = getdata (node);
449 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
451 struct prefix *pxn = NULL; /* Prefix of the neighbor */
452 struct prefix *pxc = NULL; /* Prefix of the connected network */
454 connected = getdata (cnode);
456 if (if_is_pointopoint (ifp))
458 p = (struct prefix_ipv4 *) connected->address;
460 if (p && p->family == AF_INET)
462 if (IPV4_ADDR_SAME (&p->prefix, &addr))
463 return 1;
465 p = (struct prefix_ipv4 *) connected->destination;
466 if (p && IPV4_ADDR_SAME (&p->prefix, &addr))
467 return 1;
470 else
472 p = (struct prefix_ipv4 *) connected->address;
474 if (p->family != AF_INET)
475 continue;
477 pxn = prefix_new();
478 pxn->family = AF_INET;
479 pxn->prefixlen = 32;
480 pxn->u.prefix4 = addr;
482 pxc = prefix_new();
483 prefix_copy(pxc, (struct prefix *) p);
484 apply_mask(pxc);
486 if (prefix_match (pxc, pxn))
488 prefix_free (pxn);
489 prefix_free (pxc);
490 return 1;
492 prefix_free(pxc);
493 prefix_free(pxn);
497 return 0;
500 /* Inteface link down message processing. */
502 rip_interface_down (int command, struct zclient *zclient, zebra_size_t length)
504 struct interface *ifp;
505 struct stream *s;
507 s = zclient->ibuf;
509 /* zebra_interface_state_read() updates interface structure in
510 iflist. */
511 ifp = zebra_interface_state_read(s);
513 if (ifp == NULL)
514 return 0;
516 rip_if_down(ifp);
518 if (IS_RIP_DEBUG_ZEBRA)
519 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is down",
520 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
522 return 0;
525 /* Inteface link up message processing */
527 rip_interface_up (int command, struct zclient *zclient, zebra_size_t length)
529 struct interface *ifp;
531 /* zebra_interface_state_read () updates interface structure in
532 iflist. */
533 ifp = zebra_interface_state_read (zclient->ibuf);
535 if (ifp == NULL)
536 return 0;
538 if (IS_RIP_DEBUG_ZEBRA)
539 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is up",
540 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
542 /* Check if this interface is RIP enabled or not.*/
543 rip_enable_apply (ifp);
545 /* Check for a passive interface */
546 rip_passive_interface_apply (ifp);
548 /* Apply distribute list to the all interface. */
549 rip_distribute_update_interface (ifp);
551 return 0;
554 /* Inteface addition message from zebra. */
556 rip_interface_add (int command, struct zclient *zclient, zebra_size_t length)
558 struct interface *ifp;
560 ifp = zebra_interface_add_read (zclient->ibuf);
562 if (IS_RIP_DEBUG_ZEBRA)
563 zlog_info ("interface add %s index %d flags %ld metric %d mtu %d",
564 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
566 /* Check if this interface is RIP enabled or not.*/
567 rip_enable_apply (ifp);
569 /* Apply distribute list to the all interface. */
570 rip_distribute_update_interface (ifp);
572 /* rip_request_neighbor_all (); */
574 return 0;
578 rip_interface_delete (int command, struct zclient *zclient,
579 zebra_size_t length)
581 struct interface *ifp;
582 struct stream *s;
585 s = zclient->ibuf;
586 /* zebra_interface_state_read() updates interface structure in iflist */
587 ifp = zebra_interface_state_read(s);
589 if (ifp == NULL)
590 return 0;
592 if (if_is_up (ifp)) {
593 rip_if_down(ifp);
596 zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
597 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
599 /* To support pseudo interface do not free interface structure. */
600 /* if_delete(ifp); */
602 return 0;
605 void
606 rip_interface_clean ()
608 listnode node;
609 struct interface *ifp;
610 struct rip_interface *ri;
612 for (node = listhead (iflist); node; nextnode (node))
614 ifp = getdata (node);
615 ri = ifp->info;
617 ri->enable_network = 0;
618 ri->enable_interface = 0;
619 ri->running = 0;
621 if (ri->t_wakeup)
623 thread_cancel (ri->t_wakeup);
624 ri->t_wakeup = NULL;
629 void
630 rip_interface_reset ()
632 listnode node;
633 struct interface *ifp;
634 struct rip_interface *ri;
636 for (node = listhead (iflist); node; nextnode (node))
638 ifp = getdata (node);
639 ri = ifp->info;
641 ri->enable_network = 0;
642 ri->enable_interface = 0;
643 ri->running = 0;
645 ri->ri_send = RI_RIP_UNSPEC;
646 ri->ri_receive = RI_RIP_UNSPEC;
648 /* ri->auth_type = RIP_NO_AUTH; */
649 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
651 if (ri->auth_str)
653 free (ri->auth_str);
654 ri->auth_str = NULL;
656 if (ri->key_chain)
658 free (ri->key_chain);
659 ri->key_chain = NULL;
662 ri->split_horizon = 0;
663 ri->split_horizon_default = 0;
665 ri->list[RIP_FILTER_IN] = NULL;
666 ri->list[RIP_FILTER_OUT] = NULL;
668 ri->prefix[RIP_FILTER_IN] = NULL;
669 ri->prefix[RIP_FILTER_OUT] = NULL;
671 if (ri->t_wakeup)
673 thread_cancel (ri->t_wakeup);
674 ri->t_wakeup = NULL;
677 ri->recv_badpackets = 0;
678 ri->recv_badroutes = 0;
679 ri->sent_updates = 0;
681 ri->passive = 0;
686 rip_if_down(struct interface *ifp)
688 struct route_node *rp;
689 struct rip_info *rinfo;
690 struct rip_interface *ri = NULL;
691 if (rip)
693 for (rp = route_top (rip->table); rp; rp = route_next (rp))
694 if ((rinfo = rp->info) != NULL)
696 /* Routes got through this interface. */
697 if (rinfo->ifindex == ifp->ifindex &&
698 rinfo->type == ZEBRA_ROUTE_RIP &&
699 rinfo->sub_type == RIP_ROUTE_RTE)
701 rip_zebra_ipv4_delete ((struct prefix_ipv4 *) &rp->p,
702 &rinfo->nexthop,
703 rinfo->ifindex);
705 rip_redistribute_delete (rinfo->type,rinfo->sub_type,
706 (struct prefix_ipv4 *)&rp->p,
707 rinfo->ifindex);
709 else
711 /* All redistributed routes but static and system */
712 if ((rinfo->ifindex == ifp->ifindex) &&
713 (rinfo->type != ZEBRA_ROUTE_STATIC) &&
714 (rinfo->type != ZEBRA_ROUTE_SYSTEM))
715 rip_redistribute_delete (rinfo->type,rinfo->sub_type,
716 (struct prefix_ipv4 *)&rp->p,
717 rinfo->ifindex);
722 ri = ifp->info;
724 if (ri->running)
726 if (IS_RIP_DEBUG_EVENT)
727 zlog_info ("turn off %s", ifp->name);
729 /* Leave from multicast group. */
730 rip_multicast_leave (ifp, rip->sock);
732 ri->running = 0;
735 return 0;
738 /* Needed for stop RIP process. */
739 void
740 rip_if_down_all ()
742 struct interface *ifp;
743 listnode node;
745 for (node = listhead (iflist); node; nextnode (node))
747 ifp = getdata (node);
748 rip_if_down (ifp);
753 rip_interface_address_add (int command, struct zclient *zclient,
754 zebra_size_t length)
756 struct connected *ifc;
757 struct prefix *p;
759 ifc = zebra_interface_address_add_read (zclient->ibuf);
761 if (ifc == NULL)
762 return 0;
764 p = ifc->address;
766 if (p->family == AF_INET)
768 if (IS_RIP_DEBUG_ZEBRA)
769 zlog_info ("connected address %s/%d is added",
770 inet_ntoa (p->u.prefix4), p->prefixlen);
772 /* Check is this interface is RIP enabled or not.*/
773 rip_enable_apply (ifc->ifp);
775 #ifdef HAVE_SNMP
776 rip_ifaddr_add (ifc->ifp, ifc);
777 #endif /* HAVE_SNMP */
780 return 0;
784 rip_interface_address_delete (int command, struct zclient *zclient,
785 zebra_size_t length)
787 struct connected *ifc;
788 struct prefix *p;
790 ifc = zebra_interface_address_delete_read (zclient->ibuf);
792 if (ifc)
794 p = ifc->address;
795 if (p->family == AF_INET)
797 if (IS_RIP_DEBUG_ZEBRA)
799 zlog_info ("connected address %s/%d is deleted",
800 inet_ntoa (p->u.prefix4), p->prefixlen);
802 #ifdef HAVE_SNMP
803 rip_ifaddr_delete (ifc->ifp, ifc);
804 #endif /* HAVE_SNMP */
806 /* Check if this interface is RIP enabled or not.*/
807 rip_enable_apply (ifc->ifp);
810 connected_free (ifc);
814 return 0;
817 /* Check interface is enabled by network statement. */
819 rip_enable_network_lookup (struct interface *ifp)
821 struct listnode *nn;
822 struct connected *connected;
823 struct prefix_ipv4 address;
825 for (nn = listhead (ifp->connected); nn; nextnode (nn))
826 if ((connected = getdata (nn)) != NULL)
828 struct prefix *p;
829 struct route_node *node;
831 p = connected->address;
833 if (p->family == AF_INET)
835 address.family = AF_INET;
836 address.prefix = p->u.prefix4;
837 address.prefixlen = IPV4_MAX_BITLEN;
839 node = route_node_match (rip_enable_network,
840 (struct prefix *)&address);
841 if (node)
843 route_unlock_node (node);
844 return 1;
848 return -1;
851 /* Add RIP enable network. */
853 rip_enable_network_add (struct prefix *p)
855 struct route_node *node;
857 node = route_node_get (rip_enable_network, p);
859 if (node->info)
861 route_unlock_node (node);
862 return -1;
864 else
865 node->info = "enabled";
867 return 1;
870 /* Delete RIP enable network. */
872 rip_enable_network_delete (struct prefix *p)
874 struct route_node *node;
876 node = route_node_lookup (rip_enable_network, p);
877 if (node)
879 node->info = NULL;
881 /* Unlock info lock. */
882 route_unlock_node (node);
884 /* Unlock lookup lock. */
885 route_unlock_node (node);
887 return 1;
889 return -1;
892 /* Check interface is enabled by ifname statement. */
894 rip_enable_if_lookup (char *ifname)
896 int i;
897 char *str;
899 for (i = 0; i < vector_max (rip_enable_interface); i++)
900 if ((str = vector_slot (rip_enable_interface, i)) != NULL)
901 if (strcmp (str, ifname) == 0)
902 return i;
903 return -1;
906 /* Add interface to rip_enable_if. */
908 rip_enable_if_add (char *ifname)
910 int ret;
912 ret = rip_enable_if_lookup (ifname);
913 if (ret >= 0)
914 return -1;
916 vector_set (rip_enable_interface, strdup (ifname));
918 return 1;
921 /* Delete interface from rip_enable_if. */
923 rip_enable_if_delete (char *ifname)
925 int index;
926 char *str;
928 index = rip_enable_if_lookup (ifname);
929 if (index < 0)
930 return -1;
932 str = vector_slot (rip_enable_interface, index);
933 free (str);
934 vector_unset (rip_enable_interface, index);
936 return 1;
939 /* Join to multicast group and send request to the interface. */
941 rip_interface_wakeup (struct thread *t)
943 struct interface *ifp;
944 struct rip_interface *ri;
946 /* Get interface. */
947 ifp = THREAD_ARG (t);
949 ri = ifp->info;
950 ri->t_wakeup = NULL;
952 /* Join to multicast group. */
953 if (rip_multicast_join (ifp, rip->sock) < 0)
955 zlog_err ("multicast join failed, interface %s not running", ifp->name);
956 return 0;
959 /* Set running flag. */
960 ri->running = 1;
962 /* Send RIP request to the interface. */
963 rip_request_interface (ifp);
965 return 0;
968 int rip_redistribute_check (int);
970 void
971 rip_connect_set (struct interface *ifp, int set)
973 struct listnode *nn;
974 struct connected *connected;
975 struct prefix_ipv4 address;
977 for (nn = listhead (ifp->connected); nn; nextnode (nn))
978 if ((connected = getdata (nn)) != NULL)
980 struct prefix *p;
981 p = connected->address;
983 if (p->family != AF_INET)
984 continue;
986 address.family = AF_INET;
987 address.prefix = p->u.prefix4;
988 address.prefixlen = p->prefixlen;
989 apply_mask_ipv4 (&address);
991 if (set)
992 rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
993 &address, connected->ifp->ifindex, NULL);
994 else
996 rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
997 &address, connected->ifp->ifindex);
998 if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT))
999 rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE,
1000 &address, connected->ifp->ifindex, NULL);
1005 /* Update interface status. */
1006 void
1007 rip_enable_apply (struct interface *ifp)
1009 int ret;
1010 struct rip_interface *ri = NULL;
1012 /* Check interface. */
1013 if (if_is_loopback (ifp))
1014 return;
1016 if (! if_is_up (ifp))
1017 return;
1019 ri = ifp->info;
1021 /* Check network configuration. */
1022 ret = rip_enable_network_lookup (ifp);
1024 /* If the interface is matched. */
1025 if (ret > 0)
1026 ri->enable_network = 1;
1027 else
1028 ri->enable_network = 0;
1030 /* Check interface name configuration. */
1031 ret = rip_enable_if_lookup (ifp->name);
1032 if (ret >= 0)
1033 ri->enable_interface = 1;
1034 else
1035 ri->enable_interface = 0;
1037 /* any interface MUST have an IPv4 address */
1038 if ( ! rip_if_ipv4_address_check (ifp) )
1040 ri->enable_network = 0;
1041 ri->enable_interface = 0;
1044 /* Update running status of the interface. */
1045 if (ri->enable_network || ri->enable_interface)
1047 if (! ri->running)
1049 if (IS_RIP_DEBUG_EVENT)
1050 zlog_info ("turn on %s", ifp->name);
1052 /* Add interface wake up thread. */
1053 if (! ri->t_wakeup)
1054 ri->t_wakeup = thread_add_timer (master, rip_interface_wakeup,
1055 ifp, 1);
1056 rip_connect_set (ifp, 1);
1059 else
1061 if (ri->running)
1063 if (IS_RIP_DEBUG_EVENT)
1064 zlog_info ("turn off %s", ifp->name);
1066 /* Might as well clean up the route table as well */
1067 rip_if_down(ifp);
1069 ri->running = 0;
1070 rip_connect_set (ifp, 0);
1075 /* Apply network configuration to all interface. */
1076 void
1077 rip_enable_apply_all ()
1079 struct interface *ifp;
1080 listnode node;
1082 /* Check each interface. */
1083 for (node = listhead (iflist); node; nextnode (node))
1085 ifp = getdata (node);
1086 rip_enable_apply (ifp);
1091 rip_neighbor_lookup (struct sockaddr_in *from)
1093 struct prefix_ipv4 p;
1094 struct route_node *node;
1096 memset (&p, 0, sizeof (struct prefix_ipv4));
1097 p.family = AF_INET;
1098 p.prefix = from->sin_addr;
1099 p.prefixlen = IPV4_MAX_BITLEN;
1101 node = route_node_lookup (rip->neighbor, (struct prefix *) &p);
1102 if (node)
1104 route_unlock_node (node);
1105 return 1;
1107 return 0;
1110 /* Add new RIP neighbor to the neighbor tree. */
1112 rip_neighbor_add (struct prefix_ipv4 *p)
1114 struct route_node *node;
1116 node = route_node_get (rip->neighbor, (struct prefix *) p);
1118 if (node->info)
1119 return -1;
1121 node->info = rip->neighbor;
1123 return 0;
1126 /* Delete RIP neighbor from the neighbor tree. */
1128 rip_neighbor_delete (struct prefix_ipv4 *p)
1130 struct route_node *node;
1132 /* Lock for look up. */
1133 node = route_node_lookup (rip->neighbor, (struct prefix *) p);
1134 if (! node)
1135 return -1;
1137 node->info = NULL;
1139 /* Unlock lookup lock. */
1140 route_unlock_node (node);
1142 /* Unlock real neighbor information lock. */
1143 route_unlock_node (node);
1145 return 0;
1148 /* Clear all network and neighbor configuration. */
1149 void
1150 rip_clean_network ()
1152 int i;
1153 char *str;
1154 struct route_node *rn;
1156 /* rip_enable_network. */
1157 for (rn = route_top (rip_enable_network); rn; rn = route_next (rn))
1158 if (rn->info)
1160 rn->info = NULL;
1161 route_unlock_node (rn);
1164 /* rip_enable_interface. */
1165 for (i = 0; i < vector_max (rip_enable_interface); i++)
1166 if ((str = vector_slot (rip_enable_interface, i)) != NULL)
1168 free (str);
1169 vector_slot (rip_enable_interface, i) = NULL;
1173 /* Utility function for looking up passive interface settings. */
1175 rip_passive_interface_lookup (char *ifname)
1177 int i;
1178 char *str;
1180 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1181 if ((str = vector_slot (Vrip_passive_interface, i)) != NULL)
1182 if (strcmp (str, ifname) == 0)
1183 return i;
1184 return -1;
1187 void
1188 rip_passive_interface_apply (struct interface *ifp)
1190 int ret;
1191 struct rip_interface *ri;
1193 ri = ifp->info;
1195 ret = rip_passive_interface_lookup (ifp->name);
1196 if (ret < 0)
1197 ri->passive = 0;
1198 else
1199 ri->passive = 1;
1202 void
1203 rip_passive_interface_apply_all ()
1205 struct interface *ifp;
1206 listnode node;
1208 for (node = listhead (iflist); node; nextnode (node))
1210 ifp = getdata (node);
1211 rip_passive_interface_apply (ifp);
1215 /* Passive interface. */
1217 rip_passive_interface_set (struct vty *vty, char *ifname)
1219 if (rip_passive_interface_lookup (ifname) >= 0)
1220 return CMD_WARNING;
1222 vector_set (Vrip_passive_interface, strdup (ifname));
1224 rip_passive_interface_apply_all ();
1226 return CMD_SUCCESS;
1230 rip_passive_interface_unset (struct vty *vty, char *ifname)
1232 int i;
1233 char *str;
1235 i = rip_passive_interface_lookup (ifname);
1236 if (i < 0)
1237 return CMD_WARNING;
1239 str = vector_slot (Vrip_passive_interface, i);
1240 free (str);
1241 vector_unset (Vrip_passive_interface, i);
1243 rip_passive_interface_apply_all ();
1245 return CMD_SUCCESS;
1248 /* Free all configured RIP passive-interface settings. */
1249 void
1250 rip_passive_interface_clean ()
1252 int i;
1253 char *str;
1255 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1256 if ((str = vector_slot (Vrip_passive_interface, i)) != NULL)
1258 free (str);
1259 vector_slot (Vrip_passive_interface, i) = NULL;
1261 rip_passive_interface_apply_all ();
1264 /* RIP enable network or interface configuration. */
1265 DEFUN (rip_network,
1266 rip_network_cmd,
1267 "network (A.B.C.D/M|WORD)",
1268 "Enable routing on an IP network\n"
1269 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1270 "Interface name\n")
1272 int ret;
1273 struct prefix_ipv4 p;
1275 ret = str2prefix_ipv4 (argv[0], &p);
1277 if (ret)
1278 ret = rip_enable_network_add ((struct prefix *) &p);
1279 else
1280 ret = rip_enable_if_add (argv[0]);
1282 if (ret < 0)
1284 vty_out (vty, "There is a same network configuration %s%s", argv[0],
1285 VTY_NEWLINE);
1286 return CMD_WARNING;
1289 rip_enable_apply_all ();
1291 return CMD_SUCCESS;
1294 /* RIP enable network or interface configuration. */
1295 DEFUN (no_rip_network,
1296 no_rip_network_cmd,
1297 "no network (A.B.C.D/M|WORD)",
1298 NO_STR
1299 "Enable routing on an IP network\n"
1300 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1301 "Interface name\n")
1303 int ret;
1304 struct prefix_ipv4 p;
1306 ret = str2prefix_ipv4 (argv[0], &p);
1308 if (ret)
1309 ret = rip_enable_network_delete ((struct prefix *) &p);
1310 else
1311 ret = rip_enable_if_delete (argv[0]);
1313 if (ret < 0)
1315 vty_out (vty, "Can't find network configuration %s%s", argv[0],
1316 VTY_NEWLINE);
1317 return CMD_WARNING;
1320 rip_enable_apply_all ();
1322 return CMD_SUCCESS;
1325 /* RIP neighbor configuration set. */
1326 DEFUN (rip_neighbor,
1327 rip_neighbor_cmd,
1328 "neighbor A.B.C.D",
1329 "Specify a neighbor router\n"
1330 "Neighbor address\n")
1332 int ret;
1333 struct prefix_ipv4 p;
1335 ret = str2prefix_ipv4 (argv[0], &p);
1337 if (ret <= 0)
1339 vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
1340 return CMD_WARNING;
1343 rip_neighbor_add (&p);
1345 return CMD_SUCCESS;
1348 /* RIP neighbor configuration unset. */
1349 DEFUN (no_rip_neighbor,
1350 no_rip_neighbor_cmd,
1351 "no neighbor A.B.C.D",
1352 NO_STR
1353 "Specify a neighbor router\n"
1354 "Neighbor address\n")
1356 int ret;
1357 struct prefix_ipv4 p;
1359 ret = str2prefix_ipv4 (argv[0], &p);
1361 if (ret <= 0)
1363 vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
1364 return CMD_WARNING;
1367 rip_neighbor_delete (&p);
1369 return CMD_SUCCESS;
1372 DEFUN (ip_rip_receive_version,
1373 ip_rip_receive_version_cmd,
1374 "ip rip receive version (1|2)",
1375 IP_STR
1376 "Routing Information Protocol\n"
1377 "Advertisement reception\n"
1378 "Version control\n"
1379 "RIP version 1\n"
1380 "RIP version 2\n")
1382 struct interface *ifp;
1383 struct rip_interface *ri;
1385 ifp = (struct interface *)vty->index;
1386 ri = ifp->info;
1388 /* Version 1. */
1389 if (atoi (argv[0]) == 1)
1391 ri->ri_receive = RI_RIP_VERSION_1;
1392 return CMD_SUCCESS;
1394 if (atoi (argv[0]) == 2)
1396 ri->ri_receive = RI_RIP_VERSION_2;
1397 return CMD_SUCCESS;
1399 return CMD_WARNING;
1402 DEFUN (ip_rip_receive_version_1,
1403 ip_rip_receive_version_1_cmd,
1404 "ip rip receive version 1 2",
1405 IP_STR
1406 "Routing Information Protocol\n"
1407 "Advertisement reception\n"
1408 "Version control\n"
1409 "RIP version 1\n"
1410 "RIP version 2\n")
1412 struct interface *ifp;
1413 struct rip_interface *ri;
1415 ifp = (struct interface *)vty->index;
1416 ri = ifp->info;
1418 /* Version 1 and 2. */
1419 ri->ri_receive = RI_RIP_VERSION_1_AND_2;
1420 return CMD_SUCCESS;
1423 DEFUN (ip_rip_receive_version_2,
1424 ip_rip_receive_version_2_cmd,
1425 "ip rip receive version 2 1",
1426 IP_STR
1427 "Routing Information Protocol\n"
1428 "Advertisement reception\n"
1429 "Version control\n"
1430 "RIP version 2\n"
1431 "RIP version 1\n")
1433 struct interface *ifp;
1434 struct rip_interface *ri;
1436 ifp = (struct interface *)vty->index;
1437 ri = ifp->info;
1439 /* Version 1 and 2. */
1440 ri->ri_receive = RI_RIP_VERSION_1_AND_2;
1441 return CMD_SUCCESS;
1444 DEFUN (no_ip_rip_receive_version,
1445 no_ip_rip_receive_version_cmd,
1446 "no ip rip receive version",
1447 NO_STR
1448 IP_STR
1449 "Routing Information Protocol\n"
1450 "Advertisement reception\n"
1451 "Version control\n")
1453 struct interface *ifp;
1454 struct rip_interface *ri;
1456 ifp = (struct interface *)vty->index;
1457 ri = ifp->info;
1459 ri->ri_receive = RI_RIP_UNSPEC;
1460 return CMD_SUCCESS;
1463 ALIAS (no_ip_rip_receive_version,
1464 no_ip_rip_receive_version_num_cmd,
1465 "no ip rip receive version (1|2)",
1466 NO_STR
1467 IP_STR
1468 "Routing Information Protocol\n"
1469 "Advertisement reception\n"
1470 "Version control\n"
1471 "Version 1\n"
1472 "Version 2\n");
1474 DEFUN (ip_rip_send_version,
1475 ip_rip_send_version_cmd,
1476 "ip rip send version (1|2)",
1477 IP_STR
1478 "Routing Information Protocol\n"
1479 "Advertisement transmission\n"
1480 "Version control\n"
1481 "RIP version 1\n"
1482 "RIP version 2\n")
1484 struct interface *ifp;
1485 struct rip_interface *ri;
1487 ifp = (struct interface *)vty->index;
1488 ri = ifp->info;
1490 /* Version 1. */
1491 if (atoi (argv[0]) == 1)
1493 ri->ri_send = RI_RIP_VERSION_1;
1494 return CMD_SUCCESS;
1496 if (atoi (argv[0]) == 2)
1498 ri->ri_send = RI_RIP_VERSION_2;
1499 return CMD_SUCCESS;
1501 return CMD_WARNING;
1504 DEFUN (ip_rip_send_version_1,
1505 ip_rip_send_version_1_cmd,
1506 "ip rip send version 1 2",
1507 IP_STR
1508 "Routing Information Protocol\n"
1509 "Advertisement transmission\n"
1510 "Version control\n"
1511 "RIP version 1\n"
1512 "RIP version 2\n")
1514 struct interface *ifp;
1515 struct rip_interface *ri;
1517 ifp = (struct interface *)vty->index;
1518 ri = ifp->info;
1520 /* Version 1 and 2. */
1521 ri->ri_send = RI_RIP_VERSION_1_AND_2;
1522 return CMD_SUCCESS;
1525 DEFUN (ip_rip_send_version_2,
1526 ip_rip_send_version_2_cmd,
1527 "ip rip send version 2 1",
1528 IP_STR
1529 "Routing Information Protocol\n"
1530 "Advertisement transmission\n"
1531 "Version control\n"
1532 "RIP version 2\n"
1533 "RIP version 1\n")
1535 struct interface *ifp;
1536 struct rip_interface *ri;
1538 ifp = (struct interface *)vty->index;
1539 ri = ifp->info;
1541 /* Version 1 and 2. */
1542 ri->ri_send = RI_RIP_VERSION_1_AND_2;
1543 return CMD_SUCCESS;
1546 DEFUN (no_ip_rip_send_version,
1547 no_ip_rip_send_version_cmd,
1548 "no ip rip send version",
1549 NO_STR
1550 IP_STR
1551 "Routing Information Protocol\n"
1552 "Advertisement transmission\n"
1553 "Version control\n")
1555 struct interface *ifp;
1556 struct rip_interface *ri;
1558 ifp = (struct interface *)vty->index;
1559 ri = ifp->info;
1561 ri->ri_send = RI_RIP_UNSPEC;
1562 return CMD_SUCCESS;
1565 ALIAS (no_ip_rip_send_version,
1566 no_ip_rip_send_version_num_cmd,
1567 "no ip rip send version (1|2)",
1568 NO_STR
1569 IP_STR
1570 "Routing Information Protocol\n"
1571 "Advertisement transmission\n"
1572 "Version control\n"
1573 "Version 1\n"
1574 "Version 2\n");
1576 DEFUN (ip_rip_authentication_mode,
1577 ip_rip_authentication_mode_cmd,
1578 "ip rip authentication mode (md5|text)",
1579 IP_STR
1580 "Routing Information Protocol\n"
1581 "Authentication control\n"
1582 "Authentication mode\n"
1583 "Keyed message digest\n"
1584 "Clear text authentication\n")
1586 struct interface *ifp;
1587 struct rip_interface *ri;
1589 ifp = (struct interface *)vty->index;
1590 ri = ifp->info;
1592 if (strncmp ("md5", argv[0], strlen (argv[0])) == 0)
1593 ri->auth_type = RIP_AUTH_MD5;
1594 else if (strncmp ("text", argv[0], strlen (argv[0])) == 0)
1595 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
1596 else
1598 vty_out (vty, "mode should be md5 or text%s", VTY_NEWLINE);
1599 return CMD_WARNING;
1602 return CMD_SUCCESS;
1605 DEFUN (no_ip_rip_authentication_mode,
1606 no_ip_rip_authentication_mode_cmd,
1607 "no ip rip authentication mode",
1608 NO_STR
1609 IP_STR
1610 "Routing Information Protocol\n"
1611 "Authentication control\n"
1612 "Authentication mode\n")
1614 struct interface *ifp;
1615 struct rip_interface *ri;
1617 ifp = (struct interface *)vty->index;
1618 ri = ifp->info;
1620 /* ri->auth_type = RIP_NO_AUTH; */
1621 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
1623 return CMD_SUCCESS;
1626 ALIAS (no_ip_rip_authentication_mode,
1627 no_ip_rip_authentication_mode_type_cmd,
1628 "no ip rip authentication mode (md5|text)",
1629 NO_STR
1630 IP_STR
1631 "Routing Information Protocol\n"
1632 "Authentication control\n"
1633 "Authentication mode\n"
1634 "Keyed message digest\n"
1635 "Clear text authentication\n");
1637 DEFUN (ip_rip_authentication_string,
1638 ip_rip_authentication_string_cmd,
1639 "ip rip authentication string LINE",
1640 IP_STR
1641 "Routing Information Protocol\n"
1642 "Authentication control\n"
1643 "Authentication string\n"
1644 "Authentication string\n")
1646 struct interface *ifp;
1647 struct rip_interface *ri;
1649 ifp = (struct interface *)vty->index;
1650 ri = ifp->info;
1652 if (strlen (argv[0]) > 16)
1654 vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s",
1655 VTY_NEWLINE);
1656 return CMD_WARNING;
1659 if (ri->key_chain)
1661 vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE);
1662 return CMD_WARNING;
1665 if (ri->auth_str)
1666 free (ri->auth_str);
1668 ri->auth_str = strdup (argv[0]);
1670 return CMD_SUCCESS;
1673 DEFUN (no_ip_rip_authentication_string,
1674 no_ip_rip_authentication_string_cmd,
1675 "no ip rip authentication string",
1676 NO_STR
1677 IP_STR
1678 "Routing Information Protocol\n"
1679 "Authentication control\n"
1680 "Authentication string\n")
1682 struct interface *ifp;
1683 struct rip_interface *ri;
1685 ifp = (struct interface *)vty->index;
1686 ri = ifp->info;
1688 if (ri->auth_str)
1689 free (ri->auth_str);
1691 ri->auth_str = NULL;
1693 return CMD_SUCCESS;
1696 ALIAS (no_ip_rip_authentication_string,
1697 no_ip_rip_authentication_string2_cmd,
1698 "no ip rip authentication string LINE",
1699 NO_STR
1700 IP_STR
1701 "Routing Information Protocol\n"
1702 "Authentication control\n"
1703 "Authentication string\n"
1704 "Authentication string\n");
1706 DEFUN (ip_rip_authentication_key_chain,
1707 ip_rip_authentication_key_chain_cmd,
1708 "ip rip authentication key-chain LINE",
1709 IP_STR
1710 "Routing Information Protocol\n"
1711 "Authentication control\n"
1712 "Authentication key-chain\n"
1713 "name of key-chain\n")
1715 struct interface *ifp;
1716 struct rip_interface *ri;
1718 ifp = (struct interface *) vty->index;
1719 ri = ifp->info;
1721 if (ri->auth_str)
1723 vty_out (vty, "%% authentication string configuration exists%s",
1724 VTY_NEWLINE);
1725 return CMD_WARNING;
1728 if (ri->key_chain)
1729 free (ri->key_chain);
1731 ri->key_chain = strdup (argv[0]);
1733 return CMD_SUCCESS;
1736 DEFUN (no_ip_rip_authentication_key_chain,
1737 no_ip_rip_authentication_key_chain_cmd,
1738 "no ip rip authentication key-chain",
1739 NO_STR
1740 IP_STR
1741 "Routing Information Protocol\n"
1742 "Authentication control\n"
1743 "Authentication key-chain\n")
1745 struct interface *ifp;
1746 struct rip_interface *ri;
1748 ifp = (struct interface *) vty->index;
1749 ri = ifp->info;
1751 if (ri->key_chain)
1752 free (ri->key_chain);
1754 ri->key_chain = NULL;
1756 return CMD_SUCCESS;
1759 ALIAS (no_ip_rip_authentication_key_chain,
1760 no_ip_rip_authentication_key_chain2_cmd,
1761 "no ip rip authentication key-chain LINE",
1762 NO_STR
1763 IP_STR
1764 "Routing Information Protocol\n"
1765 "Authentication control\n"
1766 "Authentication key-chain\n"
1767 "name of key-chain\n");
1769 DEFUN (rip_split_horizon,
1770 rip_split_horizon_cmd,
1771 "ip split-horizon",
1772 IP_STR
1773 "Perform split horizon\n")
1775 struct interface *ifp;
1776 struct rip_interface *ri;
1778 ifp = vty->index;
1779 ri = ifp->info;
1781 ri->split_horizon = 1;
1782 return CMD_SUCCESS;
1785 DEFUN (no_rip_split_horizon,
1786 no_rip_split_horizon_cmd,
1787 "no ip split-horizon",
1788 NO_STR
1789 IP_STR
1790 "Perform split horizon\n")
1792 struct interface *ifp;
1793 struct rip_interface *ri;
1795 ifp = vty->index;
1796 ri = ifp->info;
1798 ri->split_horizon = 0;
1799 return CMD_SUCCESS;
1802 DEFUN (rip_passive_interface,
1803 rip_passive_interface_cmd,
1804 "passive-interface IFNAME",
1805 "Suppress routing updates on an interface\n"
1806 "Interface name\n")
1808 return rip_passive_interface_set (vty, argv[0]);
1811 DEFUN (no_rip_passive_interface,
1812 no_rip_passive_interface_cmd,
1813 "no passive-interface IFNAME",
1814 NO_STR
1815 "Suppress routing updates on an interface\n"
1816 "Interface name\n")
1818 return rip_passive_interface_unset (vty, argv[0]);
1821 /* Write rip configuration of each interface. */
1823 rip_interface_config_write (struct vty *vty)
1825 listnode node;
1826 struct interface *ifp;
1828 for (node = listhead (iflist); node; nextnode (node))
1830 struct rip_interface *ri;
1832 ifp = getdata (node);
1833 ri = ifp->info;
1835 vty_out (vty, "interface %s%s", ifp->name,
1836 VTY_NEWLINE);
1838 if (ifp->desc)
1839 vty_out (vty, " description %s%s", ifp->desc,
1840 VTY_NEWLINE);
1842 /* Split horizon. */
1843 if (ri->split_horizon != ri->split_horizon_default)
1845 if (ri->split_horizon)
1846 vty_out (vty, " ip split-horizon%s", VTY_NEWLINE);
1847 else
1848 vty_out (vty, " no ip split-horizon%s", VTY_NEWLINE);
1851 /* RIP version setting. */
1852 if (ri->ri_send != RI_RIP_UNSPEC)
1853 vty_out (vty, " ip rip send version %s%s",
1854 lookup (ri_version_msg, ri->ri_send),
1855 VTY_NEWLINE);
1857 if (ri->ri_receive != RI_RIP_UNSPEC)
1858 vty_out (vty, " ip rip receive version %s%s",
1859 lookup (ri_version_msg, ri->ri_receive),
1860 VTY_NEWLINE);
1862 /* RIP authentication. */
1863 if (ri->auth_type == RIP_AUTH_MD5)
1864 vty_out (vty, " ip rip authentication mode md5%s", VTY_NEWLINE);
1866 if (ri->auth_str)
1867 vty_out (vty, " ip rip authentication string %s%s",
1868 ri->auth_str, VTY_NEWLINE);
1870 if (ri->key_chain)
1871 vty_out (vty, " ip rip authentication key-chain %s%s",
1872 ri->key_chain, VTY_NEWLINE);
1874 vty_out (vty, "!%s", VTY_NEWLINE);
1876 return 0;
1880 config_write_rip_network (struct vty *vty, int config_mode)
1882 int i;
1883 char *ifname;
1884 struct route_node *node;
1886 /* Network type RIP enable interface statement. */
1887 for (node = route_top (rip_enable_network); node; node = route_next (node))
1888 if (node->info)
1889 vty_out (vty, "%s%s/%d%s",
1890 config_mode ? " network " : " ",
1891 inet_ntoa (node->p.u.prefix4),
1892 node->p.prefixlen,
1893 VTY_NEWLINE);
1895 /* Interface name RIP enable statement. */
1896 for (i = 0; i < vector_max (rip_enable_interface); i++)
1897 if ((ifname = vector_slot (rip_enable_interface, i)) != NULL)
1898 vty_out (vty, "%s%s%s",
1899 config_mode ? " network " : " ",
1900 ifname,
1901 VTY_NEWLINE);
1903 /* RIP neighbors listing. */
1904 for (node = route_top (rip->neighbor); node; node = route_next (node))
1905 if (node->info)
1906 vty_out (vty, "%s%s%s",
1907 config_mode ? " neighbor " : " ",
1908 inet_ntoa (node->p.u.prefix4),
1909 VTY_NEWLINE);
1911 /* RIP passive interface listing. */
1912 if (config_mode)
1913 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1914 if ((ifname = vector_slot (Vrip_passive_interface, i)) != NULL)
1915 vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE);
1917 return 0;
1920 struct cmd_node interface_node =
1922 INTERFACE_NODE,
1923 "%s(config-if)# ",
1927 /* Called when interface structure allocated. */
1929 rip_interface_new_hook (struct interface *ifp)
1931 ifp->info = rip_interface_new ();
1932 return 0;
1935 /* Called when interface structure deleted. */
1937 rip_interface_delete_hook (struct interface *ifp)
1939 XFREE (MTYPE_RIP_INTERFACE, ifp->info);
1940 return 0;
1943 /* Allocate and initialize interface vector. */
1944 void
1945 rip_if_init ()
1947 /* Default initial size of interface vector. */
1948 if_init();
1949 if_add_hook (IF_NEW_HOOK, rip_interface_new_hook);
1950 if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook);
1952 /* RIP network init. */
1953 rip_enable_interface = vector_init (1);
1954 rip_enable_network = route_table_init ();
1956 /* RIP passive interface. */
1957 Vrip_passive_interface = vector_init (1);
1959 /* Install interface node. */
1960 install_node (&interface_node, rip_interface_config_write);
1962 /* Install commands. */
1963 install_element (CONFIG_NODE, &interface_cmd);
1964 install_default (INTERFACE_NODE);
1965 install_element (INTERFACE_NODE, &interface_desc_cmd);
1966 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1967 install_element (RIP_NODE, &rip_network_cmd);
1968 install_element (RIP_NODE, &no_rip_network_cmd);
1969 install_element (RIP_NODE, &rip_neighbor_cmd);
1970 install_element (RIP_NODE, &no_rip_neighbor_cmd);
1972 install_element (RIP_NODE, &rip_passive_interface_cmd);
1973 install_element (RIP_NODE, &no_rip_passive_interface_cmd);
1975 install_element (INTERFACE_NODE, &ip_rip_send_version_cmd);
1976 install_element (INTERFACE_NODE, &ip_rip_send_version_1_cmd);
1977 install_element (INTERFACE_NODE, &ip_rip_send_version_2_cmd);
1978 install_element (INTERFACE_NODE, &no_ip_rip_send_version_cmd);
1979 install_element (INTERFACE_NODE, &no_ip_rip_send_version_num_cmd);
1981 install_element (INTERFACE_NODE, &ip_rip_receive_version_cmd);
1982 install_element (INTERFACE_NODE, &ip_rip_receive_version_1_cmd);
1983 install_element (INTERFACE_NODE, &ip_rip_receive_version_2_cmd);
1984 install_element (INTERFACE_NODE, &no_ip_rip_receive_version_cmd);
1985 install_element (INTERFACE_NODE, &no_ip_rip_receive_version_num_cmd);
1987 install_element (INTERFACE_NODE, &ip_rip_authentication_mode_cmd);
1988 install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd);
1989 install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_type_cmd);
1991 install_element (INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd);
1992 install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain_cmd);
1993 install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain2_cmd);
1995 install_element (INTERFACE_NODE, &ip_rip_authentication_string_cmd);
1996 install_element (INTERFACE_NODE, &no_ip_rip_authentication_string_cmd);
1997 install_element (INTERFACE_NODE, &no_ip_rip_authentication_string2_cmd);
1999 install_element (INTERFACE_NODE, &rip_split_horizon_cmd);
2000 install_element (INTERFACE_NODE, &no_rip_split_horizon_cmd);