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
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
26 #include "sockunion.h"
39 #include "zebra/connected.h"
41 #include "ripd/ripd.h"
42 #include "ripd/rip_debug.h"
43 #include "ripd/rip_interface.h"
45 /* static prototypes */
46 static void rip_enable_apply (struct interface
*);
47 static void rip_passive_interface_apply (struct interface
*);
48 static int rip_if_down(struct interface
*ifp
);
49 static int rip_enable_if_lookup (const char *ifname
);
50 static int rip_enable_network_lookup2 (struct connected
*connected
);
51 static void rip_enable_apply_all (void);
53 const struct message ri_version_msg
[] =
55 {RI_RIP_VERSION_1
, "1"},
56 {RI_RIP_VERSION_2
, "2"},
57 {RI_RIP_VERSION_1_AND_2
, "1 2"},
58 {RI_RIP_VERSION_NONE
, "none"},
61 extern struct zebra_privs_t ripd_privs
;
63 /* RIP enabled network vector. */
64 vector rip_enable_interface
;
66 /* RIP enabled interface table. */
67 struct route_table
*rip_enable_network
;
69 /* Vector to store passive-interface name. */
70 static int passive_default
; /* are we in passive-interface default mode? */
71 vector Vrip_passive_nondefault
;
73 /* Join to the RIP version 2 multicast group. */
75 ipv4_multicast_join (int sock
,
82 ret
= setsockopt_ipv4_multicast (sock
,
89 zlog (NULL
, LOG_INFO
, "can't setsockopt IP_ADD_MEMBERSHIP %s",
90 safe_strerror (errno
));
95 /* Leave from the RIP version 2 multicast group. */
97 ipv4_multicast_leave (int sock
,
104 ret
= setsockopt_ipv4_multicast (sock
,
111 zlog (NULL
, LOG_INFO
, "can't setsockopt IP_DROP_MEMBERSHIP");
116 static void rip_interface_reset (struct rip_interface
*);
118 /* Allocate new RIP's interface configuration. */
119 static struct rip_interface
*
120 rip_interface_new (void)
122 struct rip_interface
*ri
;
124 ri
= XCALLOC (MTYPE_RIP_INTERFACE
, sizeof (struct rip_interface
));
126 rip_interface_reset (ri
);
132 rip_interface_multicast_set (int sock
, struct connected
*connected
)
136 assert (connected
!= NULL
);
138 addr
= CONNECTED_ID(connected
)->u
.prefix4
;
140 if (setsockopt_ipv4_multicast_if (sock
, addr
, connected
->ifp
->ifindex
) < 0)
142 zlog_warn ("Can't setsockopt IP_MULTICAST_IF on fd %d to "
143 "ifindex %d for interface %s",
144 sock
, connected
->ifp
->ifindex
,
145 connected
->ifp
->name
);
151 /* Send RIP request packet to specified interface. */
153 rip_request_interface_send (struct interface
*ifp
, u_char version
)
155 struct sockaddr_in to
;
157 /* RIPv2 support multicast. */
158 if (version
== RIPv2
&& if_is_multicast (ifp
))
161 if (IS_RIP_DEBUG_EVENT
)
162 zlog_debug ("multicast request on %s", ifp
->name
);
164 rip_request_send (NULL
, ifp
, version
, NULL
);
168 /* RIPv1 and non multicast interface. */
169 if (if_is_pointopoint (ifp
) || if_is_broadcast (ifp
))
171 struct listnode
*cnode
, *cnnode
;
172 struct connected
*connected
;
174 if (IS_RIP_DEBUG_EVENT
)
175 zlog_debug ("broadcast request to %s", ifp
->name
);
177 for (ALL_LIST_ELEMENTS (ifp
->connected
, cnode
, cnnode
, connected
))
179 if (connected
->address
->family
== AF_INET
)
181 memset (&to
, 0, sizeof (struct sockaddr_in
));
182 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
183 if (connected
->destination
)
184 /* use specified broadcast or peer destination addr */
185 to
.sin_addr
= connected
->destination
->u
.prefix4
;
186 else if (connected
->address
->prefixlen
< IPV4_MAX_PREFIXLEN
)
187 /* calculate the appropriate broadcast address */
189 ipv4_broadcast_addr(connected
->address
->u
.prefix4
.s_addr
,
190 connected
->address
->prefixlen
);
192 /* do not know where to send the packet */
195 if (IS_RIP_DEBUG_EVENT
)
196 zlog_debug ("SEND request to %s", inet_ntoa (to
.sin_addr
));
198 rip_request_send (&to
, ifp
, version
, connected
);
204 /* This will be executed when interface goes up. */
206 rip_request_interface (struct interface
*ifp
)
208 struct rip_interface
*ri
;
210 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
211 if (if_is_loopback (ifp
))
214 /* If interface is down, don't send RIP packet. */
215 if (! if_is_operative (ifp
))
218 /* Fetch RIP interface information. */
222 /* If there is no version configuration in the interface,
223 use rip's version setting. */
225 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
) ?
226 rip
->version_send
: ri
->ri_send
);
228 rip_request_interface_send (ifp
, RIPv1
);
230 rip_request_interface_send (ifp
, RIPv2
);
235 /* Send RIP request to the neighbor. */
237 rip_request_neighbor (struct in_addr addr
)
239 struct sockaddr_in to
;
241 memset (&to
, 0, sizeof (struct sockaddr_in
));
242 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
245 rip_request_send (&to
, NULL
, rip
->version_send
, NULL
);
248 /* Request routes at all interfaces. */
250 rip_request_neighbor_all (void)
252 struct route_node
*rp
;
257 if (IS_RIP_DEBUG_EVENT
)
258 zlog_debug ("request to the all neighbor");
260 /* Send request to all neighbor. */
261 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
263 rip_request_neighbor (rp
->p
.u
.prefix4
);
267 /* Multicast packet receive socket. */
269 rip_multicast_join (struct interface
*ifp
, int sock
)
271 struct listnode
*cnode
;
272 struct connected
*ifc
;
274 if (if_is_operative (ifp
) && if_is_multicast (ifp
))
276 if (IS_RIP_DEBUG_EVENT
)
277 zlog_debug ("multicast join at %s", ifp
->name
);
279 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, ifc
))
281 struct prefix_ipv4
*p
;
282 struct in_addr group
;
284 p
= (struct prefix_ipv4
*) ifc
->address
;
286 if (p
->family
!= AF_INET
)
289 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
290 if (ipv4_multicast_join (sock
, group
, p
->prefix
, ifp
->ifindex
) < 0)
299 /* Leave from multicast group. */
301 rip_multicast_leave (struct interface
*ifp
, int sock
)
303 struct listnode
*cnode
;
304 struct connected
*connected
;
306 if (if_is_up (ifp
) && if_is_multicast (ifp
))
308 if (IS_RIP_DEBUG_EVENT
)
309 zlog_debug ("multicast leave from %s", ifp
->name
);
311 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
313 struct prefix_ipv4
*p
;
314 struct in_addr group
;
316 p
= (struct prefix_ipv4
*) connected
->address
;
318 if (p
->family
!= AF_INET
)
321 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
322 if (ipv4_multicast_leave (sock
, group
, p
->prefix
, ifp
->ifindex
) == 0)
328 /* Is there and address on interface that I could use ? */
330 rip_if_ipv4_address_check (struct interface
*ifp
)
333 struct connected
*connected
;
336 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, nn
, connected
))
340 p
= connected
->address
;
342 if (p
->family
== AF_INET
)
352 /* Does this address belongs to me ? */
354 if_check_address (struct in_addr addr
)
356 struct listnode
*node
;
357 struct interface
*ifp
;
359 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
361 struct listnode
*cnode
;
362 struct connected
*connected
;
364 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
366 struct prefix_ipv4
*p
;
368 p
= (struct prefix_ipv4
*) connected
->address
;
370 if (p
->family
!= AF_INET
)
373 if (IPV4_ADDR_CMP (&p
->prefix
, &addr
) == 0)
380 /* Inteface link down message processing. */
382 rip_interface_down (int command
, struct zclient
*zclient
, zebra_size_t length
,
385 struct interface
*ifp
;
390 /* zebra_interface_state_read() updates interface structure in
392 ifp
= zebra_interface_state_read (s
, vrf_id
);
399 if (IS_RIP_DEBUG_ZEBRA
)
400 zlog_debug ("interface %s index %d flags %llx metric %d mtu %d is down",
401 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
402 ifp
->metric
, ifp
->mtu
);
407 /* Inteface link up message processing */
409 rip_interface_up (int command
, struct zclient
*zclient
, zebra_size_t length
,
412 struct interface
*ifp
;
414 /* zebra_interface_state_read () updates interface structure in
416 ifp
= zebra_interface_state_read (zclient
->ibuf
, vrf_id
);
421 if (IS_RIP_DEBUG_ZEBRA
)
422 zlog_debug ("interface %s index %d flags %#llx metric %d mtu %d is up",
423 ifp
->name
, ifp
->ifindex
, (unsigned long long) ifp
->flags
,
424 ifp
->metric
, ifp
->mtu
);
426 /* Check if this interface is RIP enabled or not.*/
427 rip_enable_apply (ifp
);
429 /* Check for a passive interface */
430 rip_passive_interface_apply (ifp
);
432 /* Apply distribute list to the all interface. */
433 rip_distribute_update_interface (ifp
);
438 /* Inteface addition message from zebra. */
440 rip_interface_add (int command
, struct zclient
*zclient
, zebra_size_t length
,
443 struct interface
*ifp
;
445 ifp
= zebra_interface_add_read (zclient
->ibuf
, vrf_id
);
447 if (IS_RIP_DEBUG_ZEBRA
)
448 zlog_debug ("interface add %s index %d flags %#llx metric %d mtu %d",
449 ifp
->name
, ifp
->ifindex
, (unsigned long long) ifp
->flags
,
450 ifp
->metric
, ifp
->mtu
);
452 /* Check if this interface is RIP enabled or not.*/
453 rip_enable_apply (ifp
);
455 /* Check for a passive interface */
456 rip_passive_interface_apply (ifp
);
458 /* Apply distribute list to the all interface. */
459 rip_distribute_update_interface (ifp
);
461 /* rip_request_neighbor_all (); */
463 /* Check interface routemap. */
464 rip_if_rmap_update_interface (ifp
);
470 rip_interface_delete (int command
, struct zclient
*zclient
,
471 zebra_size_t length
, vrf_id_t vrf_id
)
473 struct interface
*ifp
;
478 /* zebra_interface_state_read() updates interface structure in iflist */
479 ifp
= zebra_interface_state_read (s
, vrf_id
);
484 if (if_is_up (ifp
)) {
488 zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d",
489 ifp
->name
, ifp
->ifindex
, (unsigned long long) ifp
->flags
,
490 ifp
->metric
, ifp
->mtu
);
492 /* To support pseudo interface do not free interface structure. */
493 /* if_delete(ifp); */
494 ifp
->ifindex
= IFINDEX_DELETED
;
500 rip_interface_clean (struct rip_interface
*ri
)
502 ri
->enable_network
= 0;
503 ri
->enable_interface
= 0;
508 thread_cancel (ri
->t_wakeup
);
514 rip_interfaces_clean (void)
516 struct listnode
*node
;
517 struct interface
*ifp
;
519 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
520 rip_interface_clean (ifp
->info
);
524 rip_interface_reset (struct rip_interface
*ri
)
526 /* Default authentication type is simple password for Cisco
528 ri
->auth_type
= RIP_NO_AUTH
;
529 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
531 /* Set default split-horizon behavior. If the interface is Frame
532 Relay or SMDS is enabled, the default value for split-horizon is
533 off. But currently Zebra does detect Frame Relay or SMDS
534 interface. So all interface is set to split horizon. */
535 ri
->split_horizon_default
= RIP_SPLIT_HORIZON
;
536 ri
->split_horizon
= ri
->split_horizon_default
;
538 ri
->ri_send
= RI_RIP_UNSPEC
;
539 ri
->ri_receive
= RI_RIP_UNSPEC
;
541 ri
->v2_broadcast
= 0;
550 free (ri
->key_chain
);
551 ri
->key_chain
= NULL
;
554 ri
->list
[RIP_FILTER_IN
] = NULL
;
555 ri
->list
[RIP_FILTER_OUT
] = NULL
;
557 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
558 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
560 ri
->recv_badpackets
= 0;
561 ri
->recv_badroutes
= 0;
562 ri
->sent_updates
= 0;
566 rip_interface_clean (ri
);
570 rip_interfaces_reset (void)
572 struct listnode
*node
;
573 struct interface
*ifp
;
575 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
576 rip_interface_reset (ifp
->info
);
580 rip_if_down(struct interface
*ifp
)
582 struct route_node
*rp
;
583 struct rip_info
*rinfo
;
584 struct rip_interface
*ri
= NULL
;
585 struct list
*list
= NULL
;
586 struct listnode
*listnode
= NULL
, *nextnode
= NULL
;
588 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
589 if ((list
= rp
->info
) != NULL
)
590 for (ALL_LIST_ELEMENTS (list
, listnode
, nextnode
, rinfo
))
591 if (rinfo
->ifindex
== ifp
->ifindex
)
592 rip_ecmp_delete (rinfo
);
598 if (IS_RIP_DEBUG_EVENT
)
599 zlog_debug ("turn off %s", ifp
->name
);
601 /* Leave from multicast group. */
602 rip_multicast_leave (ifp
, rip
->sock
);
610 /* Needed for stop RIP process. */
614 struct interface
*ifp
;
615 struct listnode
*node
, *nnode
;
617 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
622 rip_apply_address_add (struct connected
*ifc
)
624 struct prefix_ipv4 address
;
630 if (! if_is_up(ifc
->ifp
))
635 memset (&address
, 0, sizeof (address
));
636 address
.family
= p
->family
;
637 address
.prefix
= p
->u
.prefix4
;
638 address
.prefixlen
= p
->prefixlen
;
639 apply_mask_ipv4(&address
);
641 /* Check if this interface is RIP enabled or not
642 or Check if this address's prefix is RIP enabled */
643 if ((rip_enable_if_lookup(ifc
->ifp
->name
) >= 0) ||
644 (rip_enable_network_lookup2(ifc
) >= 0))
645 rip_redistribute_add(ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
646 &address
, ifc
->ifp
->ifindex
, NULL
, 0, 0, 0);
651 rip_interface_address_add (int command
, struct zclient
*zclient
,
652 zebra_size_t length
, vrf_id_t vrf_id
)
654 struct connected
*ifc
;
657 ifc
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD
,
658 zclient
->ibuf
, vrf_id
);
665 if (p
->family
== AF_INET
)
667 if (IS_RIP_DEBUG_ZEBRA
)
668 zlog_debug ("connected address %s/%d is added",
669 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
671 rip_enable_apply(ifc
->ifp
);
672 /* Check if this prefix needs to be redistributed */
673 rip_apply_address_add(ifc
);
676 rip_ifaddr_add (ifc
->ifp
, ifc
);
677 #endif /* HAVE_SNMP */
684 rip_apply_address_del (struct connected
*ifc
) {
685 struct prefix_ipv4 address
;
691 if (! if_is_up(ifc
->ifp
))
696 memset (&address
, 0, sizeof (address
));
697 address
.family
= p
->family
;
698 address
.prefix
= p
->u
.prefix4
;
699 address
.prefixlen
= p
->prefixlen
;
700 apply_mask_ipv4(&address
);
702 rip_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
703 &address
, ifc
->ifp
->ifindex
);
707 rip_interface_address_delete (int command
, struct zclient
*zclient
,
708 zebra_size_t length
, vrf_id_t vrf_id
)
710 struct connected
*ifc
;
713 ifc
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE
,
714 zclient
->ibuf
, vrf_id
);
719 if (p
->family
== AF_INET
)
721 if (IS_RIP_DEBUG_ZEBRA
)
722 zlog_debug ("connected address %s/%d is deleted",
723 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
726 rip_ifaddr_delete (ifc
->ifp
, ifc
);
727 #endif /* HAVE_SNMP */
729 /* Chech wether this prefix needs to be removed */
730 rip_apply_address_del(ifc
);
734 connected_free (ifc
);
741 /* Check interface is enabled by network statement. */
742 /* Check wether the interface has at least a connected prefix that
743 * is within the ripng_enable_network table. */
745 rip_enable_network_lookup_if (struct interface
*ifp
)
747 struct listnode
*node
, *nnode
;
748 struct connected
*connected
;
749 struct prefix_ipv4 address
;
751 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, connected
))
754 struct route_node
*node
;
756 p
= connected
->address
;
758 if (p
->family
== AF_INET
)
760 address
.family
= AF_INET
;
761 address
.prefix
= p
->u
.prefix4
;
762 address
.prefixlen
= IPV4_MAX_BITLEN
;
764 node
= route_node_match (rip_enable_network
,
765 (struct prefix
*)&address
);
768 route_unlock_node (node
);
776 /* Check wether connected is within the ripng_enable_network table. */
778 rip_enable_network_lookup2 (struct connected
*connected
)
780 struct prefix_ipv4 address
;
783 p
= connected
->address
;
785 if (p
->family
== AF_INET
) {
786 struct route_node
*node
;
788 address
.family
= p
->family
;
789 address
.prefix
= p
->u
.prefix4
;
790 address
.prefixlen
= IPV4_MAX_BITLEN
;
792 /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within rip_enable_network */
793 node
= route_node_match (rip_enable_network
,
794 (struct prefix
*)&address
);
797 route_unlock_node (node
);
804 /* Add RIP enable network. */
806 rip_enable_network_add (struct prefix
*p
)
808 struct route_node
*node
;
810 node
= route_node_get (rip_enable_network
, p
);
814 route_unlock_node (node
);
818 node
->info
= (void *)1;
820 /* XXX: One should find a better solution than a generic one */
821 rip_enable_apply_all();
826 /* Delete RIP enable network. */
828 rip_enable_network_delete (struct prefix
*p
)
830 struct route_node
*node
;
832 node
= route_node_lookup (rip_enable_network
, p
);
837 /* Unlock info lock. */
838 route_unlock_node (node
);
840 /* Unlock lookup lock. */
841 route_unlock_node (node
);
843 /* XXX: One should find a better solution than a generic one */
844 rip_enable_apply_all ();
851 /* Check interface is enabled by ifname statement. */
853 rip_enable_if_lookup (const char *ifname
)
858 for (i
= 0; i
< vector_active (rip_enable_interface
); i
++)
859 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
860 if (strcmp (str
, ifname
) == 0)
865 /* Add interface to rip_enable_if. */
867 rip_enable_if_add (const char *ifname
)
871 ret
= rip_enable_if_lookup (ifname
);
875 vector_set (rip_enable_interface
, strdup (ifname
));
877 rip_enable_apply_all(); /* TODOVJ */
882 /* Delete interface from rip_enable_if. */
884 rip_enable_if_delete (const char *ifname
)
889 index
= rip_enable_if_lookup (ifname
);
893 str
= vector_slot (rip_enable_interface
, index
);
895 vector_unset (rip_enable_interface
, index
);
897 rip_enable_apply_all(); /* TODOVJ */
902 /* Join to multicast group and send request to the interface. */
904 rip_interface_wakeup (struct thread
*t
)
906 struct interface
*ifp
;
907 struct rip_interface
*ri
;
910 ifp
= THREAD_ARG (t
);
915 /* Join to multicast group. */
916 if (rip_multicast_join (ifp
, rip
->sock
) < 0)
918 zlog_err ("multicast join failed, interface %s not running", ifp
->name
);
922 /* Set running flag. */
925 /* Send RIP request to the interface. */
926 rip_request_interface (ifp
);
932 rip_connect_set (struct interface
*ifp
, int set
)
934 struct listnode
*node
, *nnode
;
935 struct connected
*connected
;
936 struct prefix_ipv4 address
;
938 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, connected
))
941 p
= connected
->address
;
943 if (p
->family
!= AF_INET
)
946 address
.family
= AF_INET
;
947 address
.prefix
= p
->u
.prefix4
;
948 address
.prefixlen
= p
->prefixlen
;
949 apply_mask_ipv4 (&address
);
952 /* Check once more wether this prefix is within a "network IF_OR_PREF" one */
953 if ((rip_enable_if_lookup(connected
->ifp
->name
) >= 0) ||
954 (rip_enable_network_lookup2(connected
) >= 0))
955 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
956 &address
, connected
->ifp
->ifindex
,
960 rip_redistribute_delete (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
961 &address
, connected
->ifp
->ifindex
);
962 if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT
))
963 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_REDISTRIBUTE
,
964 &address
, connected
->ifp
->ifindex
,
970 /* Update interface status. */
972 rip_enable_apply (struct interface
*ifp
)
975 struct rip_interface
*ri
= NULL
;
977 /* Check interface. */
978 if (! if_is_operative (ifp
))
983 /* Check network configuration. */
984 ret
= rip_enable_network_lookup_if (ifp
);
986 /* If the interface is matched. */
988 ri
->enable_network
= 1;
990 ri
->enable_network
= 0;
992 /* Check interface name configuration. */
993 ret
= rip_enable_if_lookup (ifp
->name
);
995 ri
->enable_interface
= 1;
997 ri
->enable_interface
= 0;
999 /* any interface MUST have an IPv4 address */
1000 if ( ! rip_if_ipv4_address_check (ifp
) )
1002 ri
->enable_network
= 0;
1003 ri
->enable_interface
= 0;
1006 /* Update running status of the interface. */
1007 if (ri
->enable_network
|| ri
->enable_interface
)
1010 if (IS_RIP_DEBUG_EVENT
)
1011 zlog_debug ("turn on %s", ifp
->name
);
1013 /* Add interface wake up thread. */
1015 ri
->t_wakeup
= thread_add_timer (master
, rip_interface_wakeup
,
1017 rip_connect_set (ifp
, 1);
1024 /* Might as well clean up the route table as well
1025 * rip_if_down sets to 0 ri->running, and displays "turn off %s"
1029 rip_connect_set (ifp
, 0);
1034 /* Apply network configuration to all interface. */
1036 rip_enable_apply_all ()
1038 struct interface
*ifp
;
1039 struct listnode
*node
, *nnode
;
1041 /* Check each interface. */
1042 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
1043 rip_enable_apply (ifp
);
1047 rip_neighbor_lookup (struct sockaddr_in
*from
)
1049 struct prefix_ipv4 p
;
1050 struct route_node
*node
;
1052 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1054 p
.prefix
= from
->sin_addr
;
1055 p
.prefixlen
= IPV4_MAX_BITLEN
;
1057 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) &p
);
1060 route_unlock_node (node
);
1066 /* Add new RIP neighbor to the neighbor tree. */
1068 rip_neighbor_add (struct prefix_ipv4
*p
)
1070 struct route_node
*node
;
1072 node
= route_node_get (rip
->neighbor
, (struct prefix
*) p
);
1077 node
->info
= rip
->neighbor
;
1082 /* Delete RIP neighbor from the neighbor tree. */
1084 rip_neighbor_delete (struct prefix_ipv4
*p
)
1086 struct route_node
*node
;
1088 /* Lock for look up. */
1089 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) p
);
1095 /* Unlock lookup lock. */
1096 route_unlock_node (node
);
1098 /* Unlock real neighbor information lock. */
1099 route_unlock_node (node
);
1104 /* Clear all network and neighbor configuration. */
1106 rip_clean_network ()
1110 struct route_node
*rn
;
1112 /* rip_enable_network. */
1113 for (rn
= route_top (rip_enable_network
); rn
; rn
= route_next (rn
))
1117 route_unlock_node (rn
);
1120 /* rip_enable_interface. */
1121 for (i
= 0; i
< vector_active (rip_enable_interface
); i
++)
1122 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
1125 vector_slot (rip_enable_interface
, i
) = NULL
;
1129 /* Utility function for looking up passive interface settings. */
1131 rip_passive_nondefault_lookup (const char *ifname
)
1136 for (i
= 0; i
< vector_active (Vrip_passive_nondefault
); i
++)
1137 if ((str
= vector_slot (Vrip_passive_nondefault
, i
)) != NULL
)
1138 if (strcmp (str
, ifname
) == 0)
1144 rip_passive_interface_apply (struct interface
*ifp
)
1146 struct rip_interface
*ri
;
1150 ri
->passive
= ((rip_passive_nondefault_lookup (ifp
->name
) < 0) ?
1151 passive_default
: !passive_default
);
1153 if (IS_RIP_DEBUG_ZEBRA
)
1154 zlog_debug ("interface %s: passive = %d",ifp
->name
,ri
->passive
);
1158 rip_passive_interface_apply_all (void)
1160 struct interface
*ifp
;
1161 struct listnode
*node
, *nnode
;
1163 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
1164 rip_passive_interface_apply (ifp
);
1167 /* Passive interface. */
1169 rip_passive_nondefault_set (struct vty
*vty
, const char *ifname
)
1171 if (rip_passive_nondefault_lookup (ifname
) >= 0)
1174 vector_set (Vrip_passive_nondefault
, strdup (ifname
));
1176 rip_passive_interface_apply_all ();
1182 rip_passive_nondefault_unset (struct vty
*vty
, const char *ifname
)
1187 i
= rip_passive_nondefault_lookup (ifname
);
1191 str
= vector_slot (Vrip_passive_nondefault
, i
);
1193 vector_unset (Vrip_passive_nondefault
, i
);
1195 rip_passive_interface_apply_all ();
1200 /* Free all configured RIP passive-interface settings. */
1202 rip_passive_nondefault_clean (void)
1207 for (i
= 0; i
< vector_active (Vrip_passive_nondefault
); i
++)
1208 if ((str
= vector_slot (Vrip_passive_nondefault
, i
)) != NULL
)
1211 vector_slot (Vrip_passive_nondefault
, i
) = NULL
;
1213 rip_passive_interface_apply_all ();
1216 /* RIP enable network or interface configuration. */
1219 "network (A.B.C.D/M|WORD)",
1220 "Enable routing on an IP network\n"
1221 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1225 struct prefix_ipv4 p
;
1227 ret
= str2prefix_ipv4 (argv
[0], &p
);
1230 ret
= rip_enable_network_add ((struct prefix
*) &p
);
1232 ret
= rip_enable_if_add (argv
[0]);
1236 vty_out (vty
, "There is a same network configuration %s%s", argv
[0],
1244 /* RIP enable network or interface configuration. */
1245 DEFUN (no_rip_network
,
1247 "no network (A.B.C.D/M|WORD)",
1249 "Enable routing on an IP network\n"
1250 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1254 struct prefix_ipv4 p
;
1256 ret
= str2prefix_ipv4 (argv
[0], &p
);
1259 ret
= rip_enable_network_delete ((struct prefix
*) &p
);
1261 ret
= rip_enable_if_delete (argv
[0]);
1265 vty_out (vty
, "Can't find network configuration %s%s", argv
[0],
1273 /* RIP neighbor configuration set. */
1274 DEFUN (rip_neighbor
,
1277 "Specify a neighbor router\n"
1278 "Neighbor address\n")
1281 struct prefix_ipv4 p
;
1283 ret
= str2prefix_ipv4 (argv
[0], &p
);
1287 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1291 rip_neighbor_add (&p
);
1296 /* RIP neighbor configuration unset. */
1297 DEFUN (no_rip_neighbor
,
1298 no_rip_neighbor_cmd
,
1299 "no neighbor A.B.C.D",
1301 "Specify a neighbor router\n"
1302 "Neighbor address\n")
1305 struct prefix_ipv4 p
;
1307 ret
= str2prefix_ipv4 (argv
[0], &p
);
1311 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1315 rip_neighbor_delete (&p
);
1320 DEFUN (ip_rip_receive_version
,
1321 ip_rip_receive_version_cmd
,
1322 "ip rip receive version (1|2|none)",
1324 "Routing Information Protocol\n"
1325 "Advertisement reception\n"
1331 struct interface
*ifp
;
1332 struct rip_interface
*ri
;
1334 ifp
= (struct interface
*)vty
->index
;
1340 ri
->ri_receive
= RI_RIP_VERSION_1
;
1343 ri
->ri_receive
= RI_RIP_VERSION_2
;
1346 ri
->ri_receive
= RI_RIP_VERSION_NONE
;
1355 DEFUN (ip_rip_receive_version_1
,
1356 ip_rip_receive_version_1_cmd
,
1357 "ip rip receive version 1 2",
1359 "Routing Information Protocol\n"
1360 "Advertisement reception\n"
1365 struct interface
*ifp
;
1366 struct rip_interface
*ri
;
1368 ifp
= (struct interface
*)vty
->index
;
1371 /* Version 1 and 2. */
1372 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1376 DEFUN (ip_rip_receive_version_2
,
1377 ip_rip_receive_version_2_cmd
,
1378 "ip rip receive version 2 1",
1380 "Routing Information Protocol\n"
1381 "Advertisement reception\n"
1386 struct interface
*ifp
;
1387 struct rip_interface
*ri
;
1389 ifp
= (struct interface
*)vty
->index
;
1392 /* Version 1 and 2. */
1393 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1397 DEFUN (no_ip_rip_receive_version
,
1398 no_ip_rip_receive_version_cmd
,
1399 "no ip rip receive version",
1402 "Routing Information Protocol\n"
1403 "Advertisement reception\n"
1404 "Version control\n")
1406 struct interface
*ifp
;
1407 struct rip_interface
*ri
;
1409 ifp
= (struct interface
*)vty
->index
;
1412 ri
->ri_receive
= RI_RIP_UNSPEC
;
1416 ALIAS (no_ip_rip_receive_version
,
1417 no_ip_rip_receive_version_num_cmd
,
1418 "no ip rip receive version (1|2)",
1421 "Routing Information Protocol\n"
1422 "Advertisement reception\n"
1427 DEFUN (ip_rip_send_version
,
1428 ip_rip_send_version_cmd
,
1429 "ip rip send version (1|2)",
1431 "Routing Information Protocol\n"
1432 "Advertisement transmission\n"
1437 struct interface
*ifp
;
1438 struct rip_interface
*ri
;
1440 ifp
= (struct interface
*)vty
->index
;
1444 if (atoi (argv
[0]) == 1)
1446 ri
->ri_send
= RI_RIP_VERSION_1
;
1449 if (atoi (argv
[0]) == 2)
1451 ri
->ri_send
= RI_RIP_VERSION_2
;
1457 DEFUN (ip_rip_send_version_1
,
1458 ip_rip_send_version_1_cmd
,
1459 "ip rip send version 1 2",
1461 "Routing Information Protocol\n"
1462 "Advertisement transmission\n"
1467 struct interface
*ifp
;
1468 struct rip_interface
*ri
;
1470 ifp
= (struct interface
*)vty
->index
;
1473 /* Version 1 and 2. */
1474 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1478 DEFUN (ip_rip_send_version_2
,
1479 ip_rip_send_version_2_cmd
,
1480 "ip rip send version 2 1",
1482 "Routing Information Protocol\n"
1483 "Advertisement transmission\n"
1488 struct interface
*ifp
;
1489 struct rip_interface
*ri
;
1491 ifp
= (struct interface
*)vty
->index
;
1494 /* Version 1 and 2. */
1495 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1499 DEFUN (no_ip_rip_send_version
,
1500 no_ip_rip_send_version_cmd
,
1501 "no ip rip send version",
1504 "Routing Information Protocol\n"
1505 "Advertisement transmission\n"
1506 "Version control\n")
1508 struct interface
*ifp
;
1509 struct rip_interface
*ri
;
1511 ifp
= (struct interface
*)vty
->index
;
1514 ri
->ri_send
= RI_RIP_UNSPEC
;
1518 ALIAS (no_ip_rip_send_version
,
1519 no_ip_rip_send_version_num_cmd
,
1520 "no ip rip send version (1|2)",
1523 "Routing Information Protocol\n"
1524 "Advertisement transmission\n"
1529 DEFUN (ip_rip_v2_broadcast
,
1530 ip_rip_v2_broadcast_cmd
,
1531 "ip rip v2-broadcast",
1533 "Routing Information Protocol\n"
1534 "Send ip broadcast v2 update\n")
1536 struct interface
*ifp
;
1537 struct rip_interface
*ri
;
1539 ifp
= (struct interface
*)vty
->index
;
1542 ri
->v2_broadcast
= 1;
1546 DEFUN (no_ip_rip_v2_broadcast
,
1547 no_ip_rip_v2_broadcast_cmd
,
1548 "no ip rip v2-broadcast",
1551 "Routing Information Protocol\n"
1552 "Send ip broadcast v2 update\n")
1554 struct interface
*ifp
;
1555 struct rip_interface
*ri
;
1557 ifp
= (struct interface
*)vty
->index
;
1560 ri
->v2_broadcast
= 0;
1564 DEFUN (ip_rip_authentication_mode
,
1565 ip_rip_authentication_mode_cmd
,
1566 "ip rip authentication mode (md5|text)",
1568 "Routing Information Protocol\n"
1569 "Authentication control\n"
1570 "Authentication mode\n"
1571 "Keyed message digest\n"
1572 "Clear text authentication\n")
1574 struct interface
*ifp
;
1575 struct rip_interface
*ri
;
1578 ifp
= (struct interface
*)vty
->index
;
1581 if ( (argc
< 1) || (argc
> 2) )
1583 vty_out (vty
, "incorrect argument count%s", VTY_NEWLINE
);
1587 if (strncmp ("md5", argv
[0], strlen (argv
[0])) == 0)
1588 auth_type
= RIP_AUTH_MD5
;
1589 else if (strncmp ("text", argv
[0], strlen (argv
[0])) == 0)
1590 auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1593 vty_out (vty
, "mode should be md5 or text%s", VTY_NEWLINE
);
1599 ri
->auth_type
= auth_type
;
1603 if ( (argc
== 2) && (auth_type
!= RIP_AUTH_MD5
) )
1605 vty_out (vty
, "auth length argument only valid for md5%s", VTY_NEWLINE
);
1609 if (strncmp ("r", argv
[1], 1) == 0)
1610 ri
->md5_auth_len
= RIP_AUTH_MD5_SIZE
;
1611 else if (strncmp ("o", argv
[1], 1) == 0)
1612 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
1616 ri
->auth_type
= auth_type
;
1621 ALIAS (ip_rip_authentication_mode
,
1622 ip_rip_authentication_mode_authlen_cmd
,
1623 "ip rip authentication mode (md5|text) auth-length (rfc|old-ripd)",
1625 "Routing Information Protocol\n"
1626 "Authentication control\n"
1627 "Authentication mode\n"
1628 "Keyed message digest\n"
1629 "Clear text authentication\n"
1630 "MD5 authentication data length\n"
1632 "Old ripd compatible\n")
1634 DEFUN (no_ip_rip_authentication_mode
,
1635 no_ip_rip_authentication_mode_cmd
,
1636 "no ip rip authentication mode",
1639 "Routing Information Protocol\n"
1640 "Authentication control\n"
1641 "Authentication mode\n")
1643 struct interface
*ifp
;
1644 struct rip_interface
*ri
;
1646 ifp
= (struct interface
*)vty
->index
;
1649 ri
->auth_type
= RIP_NO_AUTH
;
1650 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
1655 ALIAS (no_ip_rip_authentication_mode
,
1656 no_ip_rip_authentication_mode_type_cmd
,
1657 "no ip rip authentication mode (md5|text)",
1660 "Routing Information Protocol\n"
1661 "Authentication control\n"
1662 "Authentication mode\n"
1663 "Keyed message digest\n"
1664 "Clear text authentication\n")
1666 ALIAS (no_ip_rip_authentication_mode
,
1667 no_ip_rip_authentication_mode_type_authlen_cmd
,
1668 "no ip rip authentication mode (md5|text) auth-length (rfc|old-ripd)",
1671 "Routing Information Protocol\n"
1672 "Authentication control\n"
1673 "Authentication mode\n"
1674 "Keyed message digest\n"
1675 "Clear text authentication\n"
1676 "MD5 authentication data length\n"
1678 "Old ripd compatible\n")
1680 DEFUN (ip_rip_authentication_string
,
1681 ip_rip_authentication_string_cmd
,
1682 "ip rip authentication string LINE",
1684 "Routing Information Protocol\n"
1685 "Authentication control\n"
1686 "Authentication string\n"
1687 "Authentication string\n")
1689 struct interface
*ifp
;
1690 struct rip_interface
*ri
;
1692 ifp
= (struct interface
*)vty
->index
;
1695 if (strlen (argv
[0]) > 16)
1697 vty_out (vty
, "%% RIPv2 authentication string must be shorter than 16%s",
1704 vty_out (vty
, "%% key-chain configuration exists%s", VTY_NEWLINE
);
1709 free (ri
->auth_str
);
1711 ri
->auth_str
= strdup (argv
[0]);
1716 DEFUN (no_ip_rip_authentication_string
,
1717 no_ip_rip_authentication_string_cmd
,
1718 "no ip rip authentication string",
1721 "Routing Information Protocol\n"
1722 "Authentication control\n"
1723 "Authentication string\n")
1725 struct interface
*ifp
;
1726 struct rip_interface
*ri
;
1728 ifp
= (struct interface
*)vty
->index
;
1732 free (ri
->auth_str
);
1734 ri
->auth_str
= NULL
;
1739 ALIAS (no_ip_rip_authentication_string
,
1740 no_ip_rip_authentication_string2_cmd
,
1741 "no ip rip authentication string LINE",
1744 "Routing Information Protocol\n"
1745 "Authentication control\n"
1746 "Authentication string\n"
1747 "Authentication string\n")
1749 DEFUN (ip_rip_authentication_key_chain
,
1750 ip_rip_authentication_key_chain_cmd
,
1751 "ip rip authentication key-chain LINE",
1753 "Routing Information Protocol\n"
1754 "Authentication control\n"
1755 "Authentication key-chain\n"
1756 "name of key-chain\n")
1758 struct interface
*ifp
;
1759 struct rip_interface
*ri
;
1761 ifp
= (struct interface
*) vty
->index
;
1766 vty_out (vty
, "%% authentication string configuration exists%s",
1772 free (ri
->key_chain
);
1774 ri
->key_chain
= strdup (argv
[0]);
1779 DEFUN (no_ip_rip_authentication_key_chain
,
1780 no_ip_rip_authentication_key_chain_cmd
,
1781 "no ip rip authentication key-chain",
1784 "Routing Information Protocol\n"
1785 "Authentication control\n"
1786 "Authentication key-chain\n")
1788 struct interface
*ifp
;
1789 struct rip_interface
*ri
;
1791 ifp
= (struct interface
*) vty
->index
;
1795 free (ri
->key_chain
);
1797 ri
->key_chain
= NULL
;
1802 ALIAS (no_ip_rip_authentication_key_chain
,
1803 no_ip_rip_authentication_key_chain2_cmd
,
1804 "no ip rip authentication key-chain LINE",
1807 "Routing Information Protocol\n"
1808 "Authentication control\n"
1809 "Authentication key-chain\n"
1810 "name of key-chain\n")
1812 /* CHANGED: ip rip split-horizon
1813 Cisco and Zebra's command is
1816 DEFUN (ip_rip_split_horizon
,
1817 ip_rip_split_horizon_cmd
,
1818 "ip rip split-horizon",
1820 "Routing Information Protocol\n"
1821 "Perform split horizon\n")
1823 struct interface
*ifp
;
1824 struct rip_interface
*ri
;
1829 ri
->split_horizon
= RIP_SPLIT_HORIZON
;
1833 DEFUN (ip_rip_split_horizon_poisoned_reverse
,
1834 ip_rip_split_horizon_poisoned_reverse_cmd
,
1835 "ip rip split-horizon poisoned-reverse",
1837 "Routing Information Protocol\n"
1838 "Perform split horizon\n"
1839 "With poisoned-reverse\n")
1841 struct interface
*ifp
;
1842 struct rip_interface
*ri
;
1847 ri
->split_horizon
= RIP_SPLIT_HORIZON_POISONED_REVERSE
;
1851 /* CHANGED: no ip rip split-horizon
1852 Cisco and Zebra's command is
1855 DEFUN (no_ip_rip_split_horizon
,
1856 no_ip_rip_split_horizon_cmd
,
1857 "no ip rip split-horizon",
1860 "Routing Information Protocol\n"
1861 "Perform split horizon\n")
1863 struct interface
*ifp
;
1864 struct rip_interface
*ri
;
1869 ri
->split_horizon
= RIP_NO_SPLIT_HORIZON
;
1873 DEFUN (no_ip_rip_split_horizon_poisoned_reverse
,
1874 no_ip_rip_split_horizon_poisoned_reverse_cmd
,
1875 "no ip rip split-horizon poisoned-reverse",
1878 "Routing Information Protocol\n"
1879 "Perform split horizon\n"
1880 "With poisoned-reverse\n")
1882 struct interface
*ifp
;
1883 struct rip_interface
*ri
;
1888 switch( ri
->split_horizon
)
1890 case RIP_SPLIT_HORIZON_POISONED_REVERSE
:
1891 ri
->split_horizon
= RIP_SPLIT_HORIZON
;
1899 DEFUN (rip_passive_interface
,
1900 rip_passive_interface_cmd
,
1901 "passive-interface (IFNAME|default)",
1902 "Suppress routing updates on an interface\n"
1904 "default for all interfaces\n")
1906 const char *ifname
= argv
[0];
1908 if (!strcmp(ifname
,"default")) {
1909 passive_default
= 1;
1910 rip_passive_nondefault_clean();
1913 if (passive_default
)
1914 return rip_passive_nondefault_unset (vty
, ifname
);
1916 return rip_passive_nondefault_set (vty
, ifname
);
1919 DEFUN (no_rip_passive_interface
,
1920 no_rip_passive_interface_cmd
,
1921 "no passive-interface (IFNAME|default)",
1923 "Suppress routing updates on an interface\n"
1925 "default for all interfaces\n")
1927 const char *ifname
= argv
[0];
1929 if (!strcmp(ifname
,"default")) {
1930 passive_default
= 0;
1931 rip_passive_nondefault_clean();
1934 if (passive_default
)
1935 return rip_passive_nondefault_set (vty
, ifname
);
1937 return rip_passive_nondefault_unset (vty
, ifname
);
1940 /* Write rip configuration of each interface. */
1942 rip_interface_config_write (struct vty
*vty
)
1944 struct listnode
*node
;
1945 struct interface
*ifp
;
1947 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
1949 struct rip_interface
*ri
;
1951 if (ifp
->ifindex
== IFINDEX_DELETED
)
1956 /* Do not display the interface if there is no
1957 * configuration about it.
1960 (ri
->split_horizon
== ri
->split_horizon_default
) &&
1961 (ri
->ri_send
== RI_RIP_UNSPEC
) &&
1962 (ri
->ri_receive
== RI_RIP_UNSPEC
) &&
1963 (ri
->auth_type
!= RIP_AUTH_MD5
) &&
1964 (!ri
->v2_broadcast
) &&
1965 (ri
->md5_auth_len
!= RIP_AUTH_MD5_SIZE
) &&
1970 vty_out (vty
, "interface %s%s", ifp
->name
,
1974 vty_out (vty
, " description %s%s", ifp
->desc
,
1977 /* Split horizon. */
1978 if (ri
->split_horizon
!= ri
->split_horizon_default
)
1980 switch (ri
->split_horizon
) {
1981 case RIP_SPLIT_HORIZON
:
1982 vty_out (vty
, " ip rip split-horizon%s", VTY_NEWLINE
);
1984 case RIP_SPLIT_HORIZON_POISONED_REVERSE
:
1985 vty_out (vty
, " ip rip split-horizon poisoned-reverse%s",
1988 case RIP_NO_SPLIT_HORIZON
:
1990 vty_out (vty
, " no ip rip split-horizon%s", VTY_NEWLINE
);
1995 /* RIP version setting. */
1996 if (ri
->ri_send
!= RI_RIP_UNSPEC
)
1997 vty_out (vty
, " ip rip send version %s%s",
1998 lookup (ri_version_msg
, ri
->ri_send
),
2001 if (ri
->ri_receive
!= RI_RIP_UNSPEC
)
2002 vty_out (vty
, " ip rip receive version %s%s",
2003 lookup (ri_version_msg
, ri
->ri_receive
),
2006 if (ri
->v2_broadcast
)
2007 vty_out (vty
, " ip rip v2-broadcast%s", VTY_NEWLINE
);
2009 /* RIP authentication. */
2010 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
2011 vty_out (vty
, " ip rip authentication mode text%s", VTY_NEWLINE
);
2013 if (ri
->auth_type
== RIP_AUTH_MD5
)
2015 vty_out (vty
, " ip rip authentication mode md5");
2016 if (ri
->md5_auth_len
== RIP_AUTH_MD5_COMPAT_SIZE
)
2017 vty_out (vty
, " auth-length old-ripd");
2019 vty_out (vty
, " auth-length rfc");
2020 vty_out (vty
, "%s", VTY_NEWLINE
);
2024 vty_out (vty
, " ip rip authentication string %s%s",
2025 ri
->auth_str
, VTY_NEWLINE
);
2028 vty_out (vty
, " ip rip authentication key-chain %s%s",
2029 ri
->key_chain
, VTY_NEWLINE
);
2031 vty_out (vty
, "!%s", VTY_NEWLINE
);
2037 config_write_rip_network (struct vty
*vty
, int config_mode
)
2041 struct route_node
*node
;
2043 /* Network type RIP enable interface statement. */
2044 for (node
= route_top (rip_enable_network
); node
; node
= route_next (node
))
2046 vty_out (vty
, "%s%s/%d%s",
2047 config_mode
? " network " : " ",
2048 inet_ntoa (node
->p
.u
.prefix4
),
2052 /* Interface name RIP enable statement. */
2053 for (i
= 0; i
< vector_active (rip_enable_interface
); i
++)
2054 if ((ifname
= vector_slot (rip_enable_interface
, i
)) != NULL
)
2055 vty_out (vty
, "%s%s%s",
2056 config_mode
? " network " : " ",
2060 /* RIP neighbors listing. */
2061 for (node
= route_top (rip
->neighbor
); node
; node
= route_next (node
))
2063 vty_out (vty
, "%s%s%s",
2064 config_mode
? " neighbor " : " ",
2065 inet_ntoa (node
->p
.u
.prefix4
),
2068 /* RIP passive interface listing. */
2070 if (passive_default
)
2071 vty_out (vty
, " passive-interface default%s", VTY_NEWLINE
);
2072 for (i
= 0; i
< vector_active (Vrip_passive_nondefault
); i
++)
2073 if ((ifname
= vector_slot (Vrip_passive_nondefault
, i
)) != NULL
)
2074 vty_out (vty
, " %spassive-interface %s%s",
2075 (passive_default
? "no " : ""), ifname
, VTY_NEWLINE
);
2081 static struct cmd_node interface_node
=
2088 /* Called when interface structure allocated. */
2090 rip_interface_new_hook (struct interface
*ifp
)
2092 ifp
->info
= rip_interface_new ();
2096 /* Called when interface structure deleted. */
2098 rip_interface_delete_hook (struct interface
*ifp
)
2100 XFREE (MTYPE_RIP_INTERFACE
, ifp
->info
);
2105 /* Allocate and initialize interface vector. */
2109 /* Default initial size of interface vector. */
2110 if_add_hook (IF_NEW_HOOK
, rip_interface_new_hook
);
2111 if_add_hook (IF_DELETE_HOOK
, rip_interface_delete_hook
);
2113 /* RIP network init. */
2114 rip_enable_interface
= vector_init (1);
2115 rip_enable_network
= route_table_init ();
2117 /* RIP passive interface. */
2118 Vrip_passive_nondefault
= vector_init (1);
2120 /* Install interface node. */
2121 install_node (&interface_node
, rip_interface_config_write
);
2123 /* Install commands. */
2124 install_element (CONFIG_NODE
, &interface_cmd
);
2125 install_element (CONFIG_NODE
, &no_interface_cmd
);
2126 install_default (INTERFACE_NODE
);
2127 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
2128 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
2129 install_element (RIP_NODE
, &rip_network_cmd
);
2130 install_element (RIP_NODE
, &no_rip_network_cmd
);
2131 install_element (RIP_NODE
, &rip_neighbor_cmd
);
2132 install_element (RIP_NODE
, &no_rip_neighbor_cmd
);
2134 install_element (RIP_NODE
, &rip_passive_interface_cmd
);
2135 install_element (RIP_NODE
, &no_rip_passive_interface_cmd
);
2137 install_element (INTERFACE_NODE
, &ip_rip_send_version_cmd
);
2138 install_element (INTERFACE_NODE
, &ip_rip_send_version_1_cmd
);
2139 install_element (INTERFACE_NODE
, &ip_rip_send_version_2_cmd
);
2140 install_element (INTERFACE_NODE
, &no_ip_rip_send_version_cmd
);
2141 install_element (INTERFACE_NODE
, &no_ip_rip_send_version_num_cmd
);
2143 install_element (INTERFACE_NODE
, &ip_rip_receive_version_cmd
);
2144 install_element (INTERFACE_NODE
, &ip_rip_receive_version_1_cmd
);
2145 install_element (INTERFACE_NODE
, &ip_rip_receive_version_2_cmd
);
2146 install_element (INTERFACE_NODE
, &no_ip_rip_receive_version_cmd
);
2147 install_element (INTERFACE_NODE
, &no_ip_rip_receive_version_num_cmd
);
2149 install_element (INTERFACE_NODE
, &ip_rip_v2_broadcast_cmd
);
2150 install_element (INTERFACE_NODE
, &no_ip_rip_v2_broadcast_cmd
);
2152 install_element (INTERFACE_NODE
, &ip_rip_authentication_mode_cmd
);
2153 install_element (INTERFACE_NODE
, &ip_rip_authentication_mode_authlen_cmd
);
2154 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_cmd
);
2155 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_type_cmd
);
2156 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_type_authlen_cmd
);
2158 install_element (INTERFACE_NODE
, &ip_rip_authentication_key_chain_cmd
);
2159 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_key_chain_cmd
);
2160 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_key_chain2_cmd
);
2162 install_element (INTERFACE_NODE
, &ip_rip_authentication_string_cmd
);
2163 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_string_cmd
);
2164 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_string2_cmd
);
2166 install_element (INTERFACE_NODE
, &ip_rip_split_horizon_cmd
);
2167 install_element (INTERFACE_NODE
, &ip_rip_split_horizon_poisoned_reverse_cmd
);
2168 install_element (INTERFACE_NODE
, &no_ip_rip_split_horizon_cmd
);
2169 install_element (INTERFACE_NODE
, &no_ip_rip_split_horizon_poisoned_reverse_cmd
);