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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "sockunion.h"
38 #include "zebra/connected.h"
40 #include "ripd/ripd.h"
41 #include "ripd/rip_debug.h"
42 #include "ripd/rip_interface.h"
44 DEFINE_HOOK(rip_ifaddr_add
, (struct connected
* ifc
), (ifc
))
45 DEFINE_HOOK(rip_ifaddr_del
, (struct connected
* ifc
), (ifc
))
47 /* static prototypes */
48 static void rip_enable_apply(struct interface
*);
49 static void rip_passive_interface_apply(struct interface
*);
50 static int rip_if_down(struct interface
*ifp
);
51 static int rip_enable_if_lookup(const char *ifname
);
52 static int rip_enable_network_lookup2(struct connected
*connected
);
53 static void rip_enable_apply_all(void);
55 const struct message ri_version_msg
[] = {{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 /* RIP enabled network vector. */
62 vector rip_enable_interface
;
64 /* RIP enabled interface table. */
65 struct route_table
*rip_enable_network
;
67 /* Vector to store passive-interface name. */
68 static int passive_default
; /* are we in passive-interface default mode? */
69 vector Vrip_passive_nondefault
;
71 /* Join to the RIP version 2 multicast group. */
72 static int ipv4_multicast_join(int sock
, struct in_addr group
,
73 struct in_addr ifa
, ifindex_t ifindex
)
77 ret
= setsockopt_ipv4_multicast(sock
, IP_ADD_MEMBERSHIP
, ifa
,
78 group
.s_addr
, ifindex
);
81 zlog_info("can't setsockopt IP_ADD_MEMBERSHIP %s",
82 safe_strerror(errno
));
87 /* Leave from the RIP version 2 multicast group. */
88 static int ipv4_multicast_leave(int sock
, struct in_addr group
,
89 struct in_addr ifa
, ifindex_t ifindex
)
93 ret
= setsockopt_ipv4_multicast(sock
, IP_DROP_MEMBERSHIP
, ifa
,
94 group
.s_addr
, ifindex
);
97 zlog_info("can't setsockopt IP_DROP_MEMBERSHIP");
102 static void rip_interface_reset(struct rip_interface
*);
104 /* Allocate new RIP's interface configuration. */
105 static struct rip_interface
*rip_interface_new(void)
107 struct rip_interface
*ri
;
109 ri
= XCALLOC(MTYPE_RIP_INTERFACE
, sizeof(struct rip_interface
));
111 rip_interface_reset(ri
);
116 void rip_interface_multicast_set(int sock
, struct connected
*connected
)
120 assert(connected
!= NULL
);
122 addr
= CONNECTED_ID(connected
)->u
.prefix4
;
124 if (setsockopt_ipv4_multicast_if(sock
, addr
, connected
->ifp
->ifindex
)
127 "Can't setsockopt IP_MULTICAST_IF on fd %d to "
128 "ifindex %d for interface %s",
129 sock
, connected
->ifp
->ifindex
, connected
->ifp
->name
);
135 /* Send RIP request packet to specified interface. */
136 static void rip_request_interface_send(struct interface
*ifp
, uint8_t version
)
138 struct sockaddr_in to
;
140 /* RIPv2 support multicast. */
141 if (version
== RIPv2
&& if_is_multicast(ifp
)) {
143 if (IS_RIP_DEBUG_EVENT
)
144 zlog_debug("multicast request on %s", ifp
->name
);
146 rip_request_send(NULL
, ifp
, version
, NULL
);
150 /* RIPv1 and non multicast interface. */
151 if (if_is_pointopoint(ifp
) || if_is_broadcast(ifp
)) {
152 struct listnode
*cnode
, *cnnode
;
153 struct connected
*connected
;
155 if (IS_RIP_DEBUG_EVENT
)
156 zlog_debug("broadcast request to %s", ifp
->name
);
158 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
,
160 if (connected
->address
->family
== AF_INET
) {
161 memset(&to
, 0, sizeof(struct sockaddr_in
));
162 to
.sin_port
= htons(RIP_PORT_DEFAULT
);
163 if (connected
->destination
)
164 /* use specified broadcast or peer
165 * destination addr */
166 to
.sin_addr
= connected
->destination
->u
168 else if (connected
->address
->prefixlen
169 < IPV4_MAX_PREFIXLEN
)
170 /* calculate the appropriate broadcast
173 .s_addr
= ipv4_broadcast_addr(
174 connected
->address
->u
.prefix4
176 connected
->address
->prefixlen
);
178 /* do not know where to send the packet
182 if (IS_RIP_DEBUG_EVENT
)
183 zlog_debug("SEND request to %s",
184 inet_ntoa(to
.sin_addr
));
186 rip_request_send(&to
, ifp
, version
, connected
);
192 /* This will be executed when interface goes up. */
193 static void rip_request_interface(struct interface
*ifp
)
195 struct rip_interface
*ri
;
197 /* In default ripd doesn't send RIP_REQUEST to the loopback interface.
199 if (if_is_loopback(ifp
))
202 /* If interface is down, don't send RIP packet. */
203 if (!if_is_operative(ifp
))
206 /* Fetch RIP interface information. */
210 /* If there is no version configuration in the interface,
211 use rip's version setting. */
213 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
) ? rip
->version_send
216 rip_request_interface_send(ifp
, RIPv1
);
218 rip_request_interface_send(ifp
, RIPv2
);
223 /* Send RIP request to the neighbor. */
225 rip_request_neighbor (struct in_addr addr
)
227 struct sockaddr_in to
;
229 memset (&to
, 0, sizeof (struct sockaddr_in
));
230 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
233 rip_request_send (&to
, NULL
, rip
->version_send
, NULL
);
236 /* Request routes at all interfaces. */
238 rip_request_neighbor_all (void)
240 struct route_node
*rp
;
245 if (IS_RIP_DEBUG_EVENT
)
246 zlog_debug ("request to the all neighbor");
248 /* Send request to all neighbor. */
249 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
251 rip_request_neighbor (rp
->p
.u
.prefix4
);
255 /* Multicast packet receive socket. */
256 static int rip_multicast_join(struct interface
*ifp
, int sock
)
258 struct listnode
*cnode
;
259 struct connected
*ifc
;
261 if (if_is_operative(ifp
) && if_is_multicast(ifp
)) {
262 if (IS_RIP_DEBUG_EVENT
)
263 zlog_debug("multicast join at %s", ifp
->name
);
265 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, ifc
)) {
266 struct prefix_ipv4
*p
;
267 struct in_addr group
;
269 p
= (struct prefix_ipv4
*)ifc
->address
;
271 if (p
->family
!= AF_INET
)
274 group
.s_addr
= htonl(INADDR_RIP_GROUP
);
275 if (ipv4_multicast_join(sock
, group
, p
->prefix
,
286 /* Leave from multicast group. */
287 static void rip_multicast_leave(struct interface
*ifp
, int sock
)
289 struct listnode
*cnode
;
290 struct connected
*connected
;
292 if (if_is_up(ifp
) && if_is_multicast(ifp
)) {
293 if (IS_RIP_DEBUG_EVENT
)
294 zlog_debug("multicast leave from %s", ifp
->name
);
296 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
297 struct prefix_ipv4
*p
;
298 struct in_addr group
;
300 p
= (struct prefix_ipv4
*)connected
->address
;
302 if (p
->family
!= AF_INET
)
305 group
.s_addr
= htonl(INADDR_RIP_GROUP
);
306 if (ipv4_multicast_leave(sock
, group
, p
->prefix
,
314 /* Is there and address on interface that I could use ? */
315 static int rip_if_ipv4_address_check(struct interface
*ifp
)
318 struct connected
*connected
;
321 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, nn
, connected
)) {
324 p
= connected
->address
;
326 if (p
->family
== AF_INET
)
334 /* Does this address belongs to me ? */
335 int if_check_address(struct in_addr addr
)
337 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
338 struct interface
*ifp
;
340 FOR_ALL_INTERFACES (vrf
, ifp
) {
341 struct listnode
*cnode
;
342 struct connected
*connected
;
344 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
345 struct prefix_ipv4
*p
;
347 p
= (struct prefix_ipv4
*)connected
->address
;
349 if (p
->family
!= AF_INET
)
352 if (IPV4_ADDR_CMP(&p
->prefix
, &addr
) == 0)
359 /* Inteface link down message processing. */
360 int rip_interface_down(int command
, struct zclient
*zclient
,
361 zebra_size_t length
, vrf_id_t vrf_id
)
363 struct interface
*ifp
;
368 /* zebra_interface_state_read() updates interface structure in
370 ifp
= zebra_interface_state_read(s
, vrf_id
);
377 if (IS_RIP_DEBUG_ZEBRA
)
379 "interface %s index %d flags %llx metric %d mtu %d is down",
380 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
381 ifp
->metric
, ifp
->mtu
);
386 /* Inteface link up message processing */
387 int rip_interface_up(int command
, struct zclient
*zclient
, zebra_size_t length
,
390 struct interface
*ifp
;
392 /* zebra_interface_state_read () updates interface structure in
394 ifp
= zebra_interface_state_read(zclient
->ibuf
, vrf_id
);
399 if (IS_RIP_DEBUG_ZEBRA
)
401 "interface %s index %d flags %#llx metric %d mtu %d is up",
402 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
403 ifp
->metric
, ifp
->mtu
);
405 /* Check if this interface is RIP enabled or not.*/
406 rip_enable_apply(ifp
);
408 /* Check for a passive interface */
409 rip_passive_interface_apply(ifp
);
411 /* Apply distribute list to the all interface. */
412 rip_distribute_update_interface(ifp
);
417 /* Inteface addition message from zebra. */
418 int rip_interface_add(int command
, struct zclient
*zclient
, zebra_size_t length
,
421 struct interface
*ifp
;
423 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
425 if (IS_RIP_DEBUG_ZEBRA
)
427 "interface add %s index %d flags %#llx metric %d mtu %d",
428 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
429 ifp
->metric
, ifp
->mtu
);
431 /* Check if this interface is RIP enabled or not.*/
432 rip_enable_apply(ifp
);
434 /* Check for a passive interface */
435 rip_passive_interface_apply(ifp
);
437 /* Apply distribute list to the all interface. */
438 rip_distribute_update_interface(ifp
);
440 /* rip_request_neighbor_all (); */
442 /* Check interface routemap. */
443 rip_if_rmap_update_interface(ifp
);
448 int rip_interface_delete(int command
, struct zclient
*zclient
,
449 zebra_size_t length
, vrf_id_t vrf_id
)
451 struct interface
*ifp
;
456 /* zebra_interface_state_read() updates interface structure in iflist */
457 ifp
= zebra_interface_state_read(s
, vrf_id
);
466 zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d",
467 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
468 ifp
->metric
, ifp
->mtu
);
470 /* To support pseudo interface do not free interface structure. */
471 /* if_delete(ifp); */
472 if_set_index(ifp
, IFINDEX_INTERNAL
);
477 static void rip_interface_clean(struct rip_interface
*ri
)
479 ri
->enable_network
= 0;
480 ri
->enable_interface
= 0;
484 thread_cancel(ri
->t_wakeup
);
489 void rip_interfaces_clean(void)
491 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
492 struct interface
*ifp
;
494 FOR_ALL_INTERFACES (vrf
, ifp
)
495 rip_interface_clean(ifp
->info
);
498 static void rip_interface_reset(struct rip_interface
*ri
)
500 /* Default authentication type is simple password for Cisco
502 ri
->auth_type
= RIP_NO_AUTH
;
503 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
505 /* Set default split-horizon behavior. If the interface is Frame
506 Relay or SMDS is enabled, the default value for split-horizon is
507 off. But currently Zebra does detect Frame Relay or SMDS
508 interface. So all interface is set to split horizon. */
509 ri
->split_horizon_default
= RIP_SPLIT_HORIZON
;
510 ri
->split_horizon
= ri
->split_horizon_default
;
512 ri
->ri_send
= RI_RIP_UNSPEC
;
513 ri
->ri_receive
= RI_RIP_UNSPEC
;
515 ri
->v2_broadcast
= 0;
523 ri
->key_chain
= NULL
;
526 ri
->list
[RIP_FILTER_IN
] = NULL
;
527 ri
->list
[RIP_FILTER_OUT
] = NULL
;
529 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
530 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
532 ri
->recv_badpackets
= 0;
533 ri
->recv_badroutes
= 0;
534 ri
->sent_updates
= 0;
538 rip_interface_clean(ri
);
541 void rip_interfaces_reset(void)
543 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
544 struct interface
*ifp
;
546 FOR_ALL_INTERFACES (vrf
, ifp
)
547 rip_interface_reset(ifp
->info
);
550 int rip_if_down(struct interface
*ifp
)
552 struct route_node
*rp
;
553 struct rip_info
*rinfo
;
554 struct rip_interface
*ri
= NULL
;
555 struct list
*list
= NULL
;
556 struct listnode
*listnode
= NULL
, *nextnode
= NULL
;
558 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
))
559 if ((list
= rp
->info
) != NULL
)
560 for (ALL_LIST_ELEMENTS(list
, listnode
, nextnode
,
562 if (rinfo
->nh
.ifindex
== ifp
->ifindex
)
563 rip_ecmp_delete(rinfo
);
568 if (IS_RIP_DEBUG_EVENT
)
569 zlog_debug("turn off %s", ifp
->name
);
571 /* Leave from multicast group. */
572 rip_multicast_leave(ifp
, rip
->sock
);
581 /* Needed for stop RIP process. */
582 void rip_if_down_all()
584 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
585 struct interface
*ifp
;
587 FOR_ALL_INTERFACES (vrf
, ifp
)
591 static void rip_apply_address_add(struct connected
*ifc
)
593 struct prefix_ipv4 address
;
600 if (!if_is_up(ifc
->ifp
))
605 memset(&address
, 0, sizeof(address
));
606 memset(&nh
, 0, sizeof(nh
));
608 address
.family
= p
->family
;
609 address
.prefix
= p
->u
.prefix4
;
610 address
.prefixlen
= p
->prefixlen
;
611 apply_mask_ipv4(&address
);
613 nh
.ifindex
= ifc
->ifp
->ifindex
;
614 nh
.type
= NEXTHOP_TYPE_IFINDEX
;
616 /* Check if this interface is RIP enabled or not
617 or Check if this address's prefix is RIP enabled */
618 if ((rip_enable_if_lookup(ifc
->ifp
->name
) >= 0)
619 || (rip_enable_network_lookup2(ifc
) >= 0))
620 rip_redistribute_add(ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
621 &address
, &nh
, 0, 0, 0);
624 int rip_interface_address_add(int command
, struct zclient
*zclient
,
625 zebra_size_t length
, vrf_id_t vrf_id
)
627 struct connected
*ifc
;
630 ifc
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
631 zclient
->ibuf
, vrf_id
);
638 if (p
->family
== AF_INET
) {
639 if (IS_RIP_DEBUG_ZEBRA
)
640 zlog_debug("connected address %s/%d is added",
641 inet_ntoa(p
->u
.prefix4
), p
->prefixlen
);
643 rip_enable_apply(ifc
->ifp
);
644 /* Check if this prefix needs to be redistributed */
645 rip_apply_address_add(ifc
);
647 hook_call(rip_ifaddr_add
, ifc
);
653 static void rip_apply_address_del(struct connected
*ifc
)
655 struct prefix_ipv4 address
;
661 if (!if_is_up(ifc
->ifp
))
666 memset(&address
, 0, sizeof(address
));
667 address
.family
= p
->family
;
668 address
.prefix
= p
->u
.prefix4
;
669 address
.prefixlen
= p
->prefixlen
;
670 apply_mask_ipv4(&address
);
672 rip_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
673 &address
, ifc
->ifp
->ifindex
);
676 int rip_interface_address_delete(int command
, struct zclient
*zclient
,
677 zebra_size_t length
, vrf_id_t vrf_id
)
679 struct connected
*ifc
;
682 ifc
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
683 zclient
->ibuf
, vrf_id
);
687 if (p
->family
== AF_INET
) {
688 if (IS_RIP_DEBUG_ZEBRA
)
689 zlog_debug("connected address %s/%d is deleted",
690 inet_ntoa(p
->u
.prefix4
),
693 hook_call(rip_ifaddr_del
, ifc
);
695 /* Chech wether this prefix needs to be removed */
696 rip_apply_address_del(ifc
);
705 /* Check interface is enabled by network statement. */
706 /* Check wether the interface has at least a connected prefix that
707 * is within the ripng_enable_network table. */
708 static int rip_enable_network_lookup_if(struct interface
*ifp
)
710 struct listnode
*node
, *nnode
;
711 struct connected
*connected
;
712 struct prefix_ipv4 address
;
714 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
716 struct route_node
*node
;
718 p
= connected
->address
;
720 if (p
->family
== AF_INET
) {
721 address
.family
= AF_INET
;
722 address
.prefix
= p
->u
.prefix4
;
723 address
.prefixlen
= IPV4_MAX_BITLEN
;
725 node
= route_node_match(rip_enable_network
,
726 (struct prefix
*)&address
);
728 route_unlock_node(node
);
736 /* Check wether connected is within the ripng_enable_network table. */
737 int rip_enable_network_lookup2(struct connected
*connected
)
739 struct prefix_ipv4 address
;
742 p
= connected
->address
;
744 if (p
->family
== AF_INET
) {
745 struct route_node
*node
;
747 address
.family
= p
->family
;
748 address
.prefix
= p
->u
.prefix4
;
749 address
.prefixlen
= IPV4_MAX_BITLEN
;
751 /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within
752 * rip_enable_network */
753 node
= route_node_match(rip_enable_network
,
754 (struct prefix
*)&address
);
757 route_unlock_node(node
);
764 /* Add RIP enable network. */
765 static int rip_enable_network_add(struct prefix
*p
)
767 struct route_node
*node
;
769 node
= route_node_get(rip_enable_network
, p
);
772 route_unlock_node(node
);
775 node
->info
= (void *)1;
777 /* XXX: One should find a better solution than a generic one */
778 rip_enable_apply_all();
783 /* Delete RIP enable network. */
784 static int rip_enable_network_delete(struct prefix
*p
)
786 struct route_node
*node
;
788 node
= route_node_lookup(rip_enable_network
, p
);
792 /* Unlock info lock. */
793 route_unlock_node(node
);
795 /* Unlock lookup lock. */
796 route_unlock_node(node
);
798 /* XXX: One should find a better solution than a generic one */
799 rip_enable_apply_all();
806 /* Check interface is enabled by ifname statement. */
807 static int rip_enable_if_lookup(const char *ifname
)
812 for (i
= 0; i
< vector_active(rip_enable_interface
); i
++)
813 if ((str
= vector_slot(rip_enable_interface
, i
)) != NULL
)
814 if (strcmp(str
, ifname
) == 0)
819 /* Add interface to rip_enable_if. */
820 static int rip_enable_if_add(const char *ifname
)
824 ret
= rip_enable_if_lookup(ifname
);
828 vector_set(rip_enable_interface
, strdup(ifname
));
830 rip_enable_apply_all(); /* TODOVJ */
835 /* Delete interface from rip_enable_if. */
836 static int rip_enable_if_delete(const char *ifname
)
841 index
= rip_enable_if_lookup(ifname
);
845 str
= vector_slot(rip_enable_interface
, index
);
847 vector_unset(rip_enable_interface
, index
);
849 rip_enable_apply_all(); /* TODOVJ */
854 /* Join to multicast group and send request to the interface. */
855 static int rip_interface_wakeup(struct thread
*t
)
857 struct interface
*ifp
;
858 struct rip_interface
*ri
;
866 /* Join to multicast group. */
867 if (rip_multicast_join(ifp
, rip
->sock
) < 0) {
868 zlog_err("multicast join failed, interface %s not running",
873 /* Set running flag. */
876 /* Send RIP request to the interface. */
877 rip_request_interface(ifp
);
882 static void rip_connect_set(struct interface
*ifp
, int set
)
884 struct listnode
*node
, *nnode
;
885 struct connected
*connected
;
886 struct prefix_ipv4 address
;
889 memset(&nh
, 0, sizeof(nh
));
891 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
893 p
= connected
->address
;
895 if (p
->family
!= AF_INET
)
898 address
.family
= AF_INET
;
899 address
.prefix
= p
->u
.prefix4
;
900 address
.prefixlen
= p
->prefixlen
;
901 apply_mask_ipv4(&address
);
903 nh
.ifindex
= connected
->ifp
->ifindex
;
904 nh
.type
= NEXTHOP_TYPE_IFINDEX
;
906 /* Check once more wether this prefix is within a
907 * "network IF_OR_PREF" one */
908 if ((rip_enable_if_lookup(connected
->ifp
->name
) >= 0)
909 || (rip_enable_network_lookup2(connected
) >= 0))
910 rip_redistribute_add(ZEBRA_ROUTE_CONNECT
,
912 &address
, &nh
, 0, 0, 0);
914 rip_redistribute_delete(ZEBRA_ROUTE_CONNECT
,
915 RIP_ROUTE_INTERFACE
, &address
,
916 connected
->ifp
->ifindex
);
917 if (rip_redistribute_check(ZEBRA_ROUTE_CONNECT
))
918 rip_redistribute_add(ZEBRA_ROUTE_CONNECT
,
919 RIP_ROUTE_REDISTRIBUTE
,
920 &address
, &nh
, 0, 0, 0);
925 /* Update interface status. */
926 void rip_enable_apply(struct interface
*ifp
)
929 struct rip_interface
*ri
= NULL
;
931 /* Check interface. */
932 if (!if_is_operative(ifp
))
937 /* Check network configuration. */
938 ret
= rip_enable_network_lookup_if(ifp
);
940 /* If the interface is matched. */
942 ri
->enable_network
= 1;
944 ri
->enable_network
= 0;
946 /* Check interface name configuration. */
947 ret
= rip_enable_if_lookup(ifp
->name
);
949 ri
->enable_interface
= 1;
951 ri
->enable_interface
= 0;
953 /* any interface MUST have an IPv4 address */
954 if (!rip_if_ipv4_address_check(ifp
)) {
955 ri
->enable_network
= 0;
956 ri
->enable_interface
= 0;
959 /* Update running status of the interface. */
960 if (ri
->enable_network
|| ri
->enable_interface
) {
962 if (IS_RIP_DEBUG_EVENT
)
963 zlog_debug("turn on %s", ifp
->name
);
965 /* Add interface wake up thread. */
966 thread_add_timer(master
, rip_interface_wakeup
, ifp
, 1,
968 rip_connect_set(ifp
, 1);
972 /* Might as well clean up the route table as well
973 * rip_if_down sets to 0 ri->running, and displays "turn
978 rip_connect_set(ifp
, 0);
983 /* Apply network configuration to all interface. */
984 void rip_enable_apply_all()
986 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
987 struct interface
*ifp
;
989 /* Check each interface. */
990 FOR_ALL_INTERFACES (vrf
, ifp
)
991 rip_enable_apply(ifp
);
994 int rip_neighbor_lookup(struct sockaddr_in
*from
)
996 struct prefix_ipv4 p
;
997 struct route_node
*node
;
999 memset(&p
, 0, sizeof(struct prefix_ipv4
));
1001 p
.prefix
= from
->sin_addr
;
1002 p
.prefixlen
= IPV4_MAX_BITLEN
;
1004 node
= route_node_lookup(rip
->neighbor
, (struct prefix
*)&p
);
1006 route_unlock_node(node
);
1012 /* Add new RIP neighbor to the neighbor tree. */
1013 static int rip_neighbor_add(struct prefix_ipv4
*p
)
1015 struct route_node
*node
;
1017 node
= route_node_get(rip
->neighbor
, (struct prefix
*)p
);
1022 node
->info
= rip
->neighbor
;
1027 /* Delete RIP neighbor from the neighbor tree. */
1028 static int rip_neighbor_delete(struct prefix_ipv4
*p
)
1030 struct route_node
*node
;
1032 /* Lock for look up. */
1033 node
= route_node_lookup(rip
->neighbor
, (struct prefix
*)p
);
1039 /* Unlock lookup lock. */
1040 route_unlock_node(node
);
1042 /* Unlock real neighbor information lock. */
1043 route_unlock_node(node
);
1048 /* Clear all network and neighbor configuration. */
1049 void rip_clean_network()
1053 struct route_node
*rn
;
1055 /* rip_enable_network. */
1056 for (rn
= route_top(rip_enable_network
); rn
; rn
= route_next(rn
))
1059 route_unlock_node(rn
);
1062 /* rip_enable_interface. */
1063 for (i
= 0; i
< vector_active(rip_enable_interface
); i
++)
1064 if ((str
= vector_slot(rip_enable_interface
, i
)) != NULL
) {
1066 vector_slot(rip_enable_interface
, i
) = NULL
;
1070 /* Utility function for looking up passive interface settings. */
1071 static int rip_passive_nondefault_lookup(const char *ifname
)
1076 for (i
= 0; i
< vector_active(Vrip_passive_nondefault
); i
++)
1077 if ((str
= vector_slot(Vrip_passive_nondefault
, i
)) != NULL
)
1078 if (strcmp(str
, ifname
) == 0)
1083 void rip_passive_interface_apply(struct interface
*ifp
)
1085 struct rip_interface
*ri
;
1089 ri
->passive
= ((rip_passive_nondefault_lookup(ifp
->name
) < 0)
1091 : !passive_default
);
1093 if (IS_RIP_DEBUG_ZEBRA
)
1094 zlog_debug("interface %s: passive = %d", ifp
->name
,
1098 static void rip_passive_interface_apply_all(void)
1100 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1101 struct interface
*ifp
;
1103 FOR_ALL_INTERFACES (vrf
, ifp
)
1104 rip_passive_interface_apply(ifp
);
1107 /* Passive interface. */
1108 static int rip_passive_nondefault_set(struct vty
*vty
, const char *ifname
)
1110 if (rip_passive_nondefault_lookup(ifname
) >= 0)
1111 return CMD_WARNING_CONFIG_FAILED
;
1113 vector_set(Vrip_passive_nondefault
, strdup(ifname
));
1115 rip_passive_interface_apply_all();
1120 static int rip_passive_nondefault_unset(struct vty
*vty
, const char *ifname
)
1125 i
= rip_passive_nondefault_lookup(ifname
);
1127 return CMD_WARNING_CONFIG_FAILED
;
1129 str
= vector_slot(Vrip_passive_nondefault
, i
);
1131 vector_unset(Vrip_passive_nondefault
, i
);
1133 rip_passive_interface_apply_all();
1138 /* Free all configured RIP passive-interface settings. */
1139 void rip_passive_nondefault_clean(void)
1144 for (i
= 0; i
< vector_active(Vrip_passive_nondefault
); i
++)
1145 if ((str
= vector_slot(Vrip_passive_nondefault
, i
)) != NULL
) {
1147 vector_slot(Vrip_passive_nondefault
, i
) = NULL
;
1149 rip_passive_interface_apply_all();
1152 /* RIP enable network or interface configuration. */
1155 "network <A.B.C.D/M|WORD>",
1156 "Enable routing on an IP network\n"
1157 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1160 int idx_ipv4_word
= 1;
1162 struct prefix_ipv4 p
;
1164 ret
= str2prefix_ipv4(argv
[idx_ipv4_word
]->arg
, &p
);
1167 ret
= rip_enable_network_add((struct prefix
*)&p
);
1169 ret
= rip_enable_if_add(argv
[idx_ipv4_word
]->arg
);
1172 vty_out(vty
, "There is a same network configuration %s\n",
1173 argv
[idx_ipv4_word
]->arg
);
1174 return CMD_WARNING_CONFIG_FAILED
;
1180 /* RIP enable network or interface configuration. */
1181 DEFUN (no_rip_network
,
1183 "no network <A.B.C.D/M|WORD>",
1185 "Enable routing on an IP network\n"
1186 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1189 int idx_ipv4_word
= 2;
1191 struct prefix_ipv4 p
;
1193 ret
= str2prefix_ipv4(argv
[idx_ipv4_word
]->arg
, &p
);
1196 ret
= rip_enable_network_delete((struct prefix
*)&p
);
1198 ret
= rip_enable_if_delete(argv
[idx_ipv4_word
]->arg
);
1201 vty_out(vty
, "Can't find network configuration %s\n",
1202 argv
[idx_ipv4_word
]->arg
);
1203 return CMD_WARNING_CONFIG_FAILED
;
1209 /* RIP neighbor configuration set. */
1210 DEFUN (rip_neighbor
,
1213 "Specify a neighbor router\n"
1214 "Neighbor address\n")
1218 struct prefix_ipv4 p
;
1220 ret
= str2prefix_ipv4(argv
[idx_ipv4
]->arg
, &p
);
1223 vty_out(vty
, "Please specify address by A.B.C.D\n");
1224 return CMD_WARNING_CONFIG_FAILED
;
1227 rip_neighbor_add(&p
);
1232 /* RIP neighbor configuration unset. */
1233 DEFUN (no_rip_neighbor
,
1234 no_rip_neighbor_cmd
,
1235 "no neighbor A.B.C.D",
1237 "Specify a neighbor router\n"
1238 "Neighbor address\n")
1242 struct prefix_ipv4 p
;
1244 ret
= str2prefix_ipv4(argv
[idx_ipv4
]->arg
, &p
);
1247 vty_out(vty
, "Please specify address by A.B.C.D\n");
1248 return CMD_WARNING_CONFIG_FAILED
;
1251 rip_neighbor_delete(&p
);
1256 DEFUN (ip_rip_receive_version
,
1257 ip_rip_receive_version_cmd
,
1258 "ip rip receive version <(1-2)|none>",
1260 "Routing Information Protocol\n"
1261 "Advertisement reception\n"
1266 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1268 struct rip_interface
*ri
;
1272 switch (argv
[idx_type
]->arg
[0]) {
1274 ri
->ri_receive
= RI_RIP_VERSION_1
;
1277 ri
->ri_receive
= RI_RIP_VERSION_2
;
1280 ri
->ri_receive
= RI_RIP_VERSION_NONE
;
1286 return CMD_WARNING_CONFIG_FAILED
;
1289 DEFUN (ip_rip_receive_version_1
,
1290 ip_rip_receive_version_1_cmd
,
1291 "ip rip receive version <1 2|2 1>",
1293 "Routing Information Protocol\n"
1294 "Advertisement reception\n"
1301 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1302 struct rip_interface
*ri
;
1306 /* Version 1 and 2. */
1307 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1311 DEFUN (no_ip_rip_receive_version
,
1312 no_ip_rip_receive_version_cmd
,
1313 "no ip rip receive version [(1-2)]",
1316 "Routing Information Protocol\n"
1317 "Advertisement reception\n"
1321 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1322 struct rip_interface
*ri
;
1326 ri
->ri_receive
= RI_RIP_UNSPEC
;
1331 DEFUN (ip_rip_send_version
,
1332 ip_rip_send_version_cmd
,
1333 "ip rip send version (1-2)",
1335 "Routing Information Protocol\n"
1336 "Advertisement transmission\n"
1340 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1342 struct rip_interface
*ri
;
1347 if (atoi(argv
[idx_type
]->arg
) == 1) {
1348 ri
->ri_send
= RI_RIP_VERSION_1
;
1351 if (atoi(argv
[idx_type
]->arg
) == 2) {
1352 ri
->ri_send
= RI_RIP_VERSION_2
;
1355 return CMD_WARNING_CONFIG_FAILED
;
1358 DEFUN (ip_rip_send_version_1
,
1359 ip_rip_send_version_1_cmd
,
1360 "ip rip send version <1 2|2 1>",
1362 "Routing Information Protocol\n"
1363 "Advertisement transmission\n"
1370 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1371 struct rip_interface
*ri
;
1375 /* Version 1 and 2. */
1376 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1380 DEFUN (no_ip_rip_send_version
,
1381 no_ip_rip_send_version_cmd
,
1382 "no ip rip send version [(1-2)]",
1385 "Routing Information Protocol\n"
1386 "Advertisement transmission\n"
1390 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1391 struct rip_interface
*ri
;
1395 ri
->ri_send
= RI_RIP_UNSPEC
;
1400 DEFUN (ip_rip_v2_broadcast
,
1401 ip_rip_v2_broadcast_cmd
,
1402 "ip rip v2-broadcast",
1404 "Routing Information Protocol\n"
1405 "Send ip broadcast v2 update\n")
1407 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1408 struct rip_interface
*ri
;
1412 ri
->v2_broadcast
= 1;
1416 DEFUN (no_ip_rip_v2_broadcast
,
1417 no_ip_rip_v2_broadcast_cmd
,
1418 "no ip rip v2-broadcast",
1421 "Routing Information Protocol\n"
1422 "Send ip broadcast v2 update\n")
1424 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1425 struct rip_interface
*ri
;
1429 ri
->v2_broadcast
= 0;
1433 DEFUN (ip_rip_authentication_mode
,
1434 ip_rip_authentication_mode_cmd
,
1435 "ip rip authentication mode <md5|text> [auth-length <rfc|old-ripd>]",
1437 "Routing Information Protocol\n"
1438 "Authentication control\n"
1439 "Authentication mode\n"
1440 "Keyed message digest\n"
1441 "Clear text authentication\n"
1442 "MD5 authentication data length\n"
1444 "Old ripd compatible\n")
1446 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1447 char *cryptmode
= argv
[4]->text
;
1448 char *authlen
= (argc
> 5) ? argv
[6]->text
: NULL
;
1449 struct rip_interface
*ri
;
1454 if (strmatch("md5", cryptmode
))
1455 auth_type
= RIP_AUTH_MD5
;
1457 assert(strmatch("text", cryptmode
));
1458 auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1461 ri
->auth_type
= auth_type
;
1464 if (auth_type
!= RIP_AUTH_MD5
) {
1466 "auth length argument only valid for md5\n");
1467 return CMD_WARNING_CONFIG_FAILED
;
1469 if (strmatch("rfc", authlen
))
1470 ri
->md5_auth_len
= RIP_AUTH_MD5_SIZE
;
1472 assert(strmatch("old-ripd", authlen
));
1473 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
1480 DEFUN (no_ip_rip_authentication_mode
,
1481 no_ip_rip_authentication_mode_cmd
,
1482 "no ip rip authentication mode [<md5|text> [auth-length <rfc|old-ripd>]]",
1485 "Routing Information Protocol\n"
1486 "Authentication control\n"
1487 "Authentication mode\n"
1488 "Keyed message digest\n"
1489 "Clear text authentication\n"
1490 "MD5 authentication data length\n"
1492 "Old ripd compatible\n")
1494 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1495 struct rip_interface
*ri
;
1499 ri
->auth_type
= RIP_NO_AUTH
;
1500 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
1505 DEFUN (ip_rip_authentication_string
,
1506 ip_rip_authentication_string_cmd
,
1507 "ip rip authentication string LINE",
1509 "Routing Information Protocol\n"
1510 "Authentication control\n"
1511 "Authentication string\n"
1512 "Authentication string\n")
1514 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1516 struct rip_interface
*ri
;
1520 if (strlen(argv
[idx_line
]->arg
) > 16) {
1522 "%% RIPv2 authentication string must be shorter than 16\n");
1523 return CMD_WARNING_CONFIG_FAILED
;
1526 if (ri
->key_chain
) {
1527 vty_out(vty
, "%% key-chain configuration exists\n");
1528 return CMD_WARNING_CONFIG_FAILED
;
1534 ri
->auth_str
= strdup(argv
[idx_line
]->arg
);
1539 DEFUN (no_ip_rip_authentication_string
,
1540 no_ip_rip_authentication_string_cmd
,
1541 "no ip rip authentication string [LINE]",
1544 "Routing Information Protocol\n"
1545 "Authentication control\n"
1546 "Authentication string\n"
1547 "Authentication string\n")
1549 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1550 struct rip_interface
*ri
;
1557 ri
->auth_str
= NULL
;
1563 DEFUN (ip_rip_authentication_key_chain
,
1564 ip_rip_authentication_key_chain_cmd
,
1565 "ip rip authentication key-chain LINE",
1567 "Routing Information Protocol\n"
1568 "Authentication control\n"
1569 "Authentication key-chain\n"
1570 "name of key-chain\n")
1572 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1574 struct rip_interface
*ri
;
1579 vty_out(vty
, "%% authentication string configuration exists\n");
1580 return CMD_WARNING_CONFIG_FAILED
;
1584 free(ri
->key_chain
);
1586 ri
->key_chain
= strdup(argv
[idx_line
]->arg
);
1591 DEFUN (no_ip_rip_authentication_key_chain
,
1592 no_ip_rip_authentication_key_chain_cmd
,
1593 "no ip rip authentication key-chain [LINE]",
1596 "Routing Information Protocol\n"
1597 "Authentication control\n"
1598 "Authentication key-chain\n"
1599 "name of key-chain\n")
1601 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1602 struct rip_interface
*ri
;
1607 free(ri
->key_chain
);
1609 ri
->key_chain
= NULL
;
1615 /* CHANGED: ip rip split-horizon
1616 Cisco and Zebra's command is
1619 DEFUN (ip_rip_split_horizon
,
1620 ip_rip_split_horizon_cmd
,
1621 "ip rip split-horizon",
1623 "Routing Information Protocol\n"
1624 "Perform split horizon\n")
1626 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1627 struct rip_interface
*ri
;
1631 ri
->split_horizon
= RIP_SPLIT_HORIZON
;
1635 DEFUN (ip_rip_split_horizon_poisoned_reverse
,
1636 ip_rip_split_horizon_poisoned_reverse_cmd
,
1637 "ip rip split-horizon poisoned-reverse",
1639 "Routing Information Protocol\n"
1640 "Perform split horizon\n"
1641 "With poisoned-reverse\n")
1643 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1644 struct rip_interface
*ri
;
1648 ri
->split_horizon
= RIP_SPLIT_HORIZON_POISONED_REVERSE
;
1652 /* CHANGED: no ip rip split-horizon
1653 Cisco and Zebra's command is
1656 DEFUN (no_ip_rip_split_horizon
,
1657 no_ip_rip_split_horizon_cmd
,
1658 "no ip rip split-horizon",
1661 "Routing Information Protocol\n"
1662 "Perform split horizon\n")
1664 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1665 struct rip_interface
*ri
;
1669 ri
->split_horizon
= RIP_NO_SPLIT_HORIZON
;
1673 DEFUN (no_ip_rip_split_horizon_poisoned_reverse
,
1674 no_ip_rip_split_horizon_poisoned_reverse_cmd
,
1675 "no ip rip split-horizon poisoned-reverse",
1678 "Routing Information Protocol\n"
1679 "Perform split horizon\n"
1680 "With poisoned-reverse\n")
1682 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1683 struct rip_interface
*ri
;
1687 switch (ri
->split_horizon
) {
1688 case RIP_SPLIT_HORIZON_POISONED_REVERSE
:
1689 ri
->split_horizon
= RIP_SPLIT_HORIZON
;
1697 DEFUN (rip_passive_interface
,
1698 rip_passive_interface_cmd
,
1699 "passive-interface <IFNAME|default>",
1700 "Suppress routing updates on an interface\n"
1702 "default for all interfaces\n")
1704 if (argv
[1]->type
== WORD_TKN
) { // user passed 'default'
1705 passive_default
= 1;
1706 rip_passive_nondefault_clean();
1709 if (passive_default
)
1710 return rip_passive_nondefault_unset(vty
, argv
[1]->arg
);
1712 return rip_passive_nondefault_set(vty
, argv
[1]->arg
);
1715 DEFUN (no_rip_passive_interface
,
1716 no_rip_passive_interface_cmd
,
1717 "no passive-interface <IFNAME|default>",
1719 "Suppress routing updates on an interface\n"
1721 "default for all interfaces\n")
1723 if (argv
[2]->type
== WORD_TKN
) {
1724 passive_default
= 0;
1725 rip_passive_nondefault_clean();
1728 if (passive_default
)
1729 return rip_passive_nondefault_set(vty
, argv
[2]->arg
);
1731 return rip_passive_nondefault_unset(vty
, argv
[2]->arg
);
1734 /* Write rip configuration of each interface. */
1735 static int rip_interface_config_write(struct vty
*vty
)
1737 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1738 struct interface
*ifp
;
1740 FOR_ALL_INTERFACES (vrf
, ifp
) {
1741 struct rip_interface
*ri
;
1745 /* Do not display the interface if there is no
1746 * configuration about it.
1749 && (ri
->split_horizon
== ri
->split_horizon_default
)
1750 && (ri
->ri_send
== RI_RIP_UNSPEC
)
1751 && (ri
->ri_receive
== RI_RIP_UNSPEC
)
1752 && (ri
->auth_type
!= RIP_AUTH_MD5
) && (!ri
->v2_broadcast
)
1753 && (ri
->md5_auth_len
!= RIP_AUTH_MD5_SIZE
)
1754 && (!ri
->auth_str
) && (!ri
->key_chain
))
1757 vty_frame(vty
, "interface %s\n", ifp
->name
);
1760 vty_out(vty
, " description %s\n", ifp
->desc
);
1762 /* Split horizon. */
1763 if (ri
->split_horizon
!= ri
->split_horizon_default
) {
1764 switch (ri
->split_horizon
) {
1765 case RIP_SPLIT_HORIZON
:
1766 vty_out(vty
, " ip rip split-horizon\n");
1768 case RIP_SPLIT_HORIZON_POISONED_REVERSE
:
1770 " ip rip split-horizon poisoned-reverse\n");
1772 case RIP_NO_SPLIT_HORIZON
:
1774 vty_out(vty
, " no ip rip split-horizon\n");
1779 /* RIP version setting. */
1780 if (ri
->ri_send
!= RI_RIP_UNSPEC
)
1781 vty_out(vty
, " ip rip send version %s\n",
1782 lookup_msg(ri_version_msg
, ri
->ri_send
, NULL
));
1784 if (ri
->ri_receive
!= RI_RIP_UNSPEC
)
1785 vty_out(vty
, " ip rip receive version %s \n",
1786 lookup_msg(ri_version_msg
, ri
->ri_receive
,
1789 if (ri
->v2_broadcast
)
1790 vty_out(vty
, " ip rip v2-broadcast\n");
1792 /* RIP authentication. */
1793 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
1794 vty_out(vty
, " ip rip authentication mode text\n");
1796 if (ri
->auth_type
== RIP_AUTH_MD5
) {
1797 vty_out(vty
, " ip rip authentication mode md5");
1798 if (ri
->md5_auth_len
== RIP_AUTH_MD5_COMPAT_SIZE
)
1799 vty_out(vty
, " auth-length old-ripd");
1801 vty_out(vty
, " auth-length rfc");
1806 vty_out(vty
, " ip rip authentication string %s\n",
1810 vty_out(vty
, " ip rip authentication key-chain %s\n",
1813 vty_endframe(vty
, "!\n");
1818 int config_write_rip_network(struct vty
*vty
, int config_mode
)
1822 struct route_node
*node
;
1824 /* Network type RIP enable interface statement. */
1825 for (node
= route_top(rip_enable_network
); node
;
1826 node
= route_next(node
))
1828 vty_out(vty
, "%s%s/%d\n",
1829 config_mode
? " network " : " ",
1830 inet_ntoa(node
->p
.u
.prefix4
),
1833 /* Interface name RIP enable statement. */
1834 for (i
= 0; i
< vector_active(rip_enable_interface
); i
++)
1835 if ((ifname
= vector_slot(rip_enable_interface
, i
)) != NULL
)
1836 vty_out(vty
, "%s%s\n",
1837 config_mode
? " network " : " ", ifname
);
1839 /* RIP neighbors listing. */
1840 for (node
= route_top(rip
->neighbor
); node
; node
= route_next(node
))
1842 vty_out(vty
, "%s%s\n",
1843 config_mode
? " neighbor " : " ",
1844 inet_ntoa(node
->p
.u
.prefix4
));
1846 /* RIP passive interface listing. */
1848 if (passive_default
)
1849 vty_out(vty
, " passive-interface default\n");
1850 for (i
= 0; i
< vector_active(Vrip_passive_nondefault
); i
++)
1851 if ((ifname
= vector_slot(Vrip_passive_nondefault
, i
))
1853 vty_out(vty
, " %spassive-interface %s\n",
1854 (passive_default
? "no " : ""), ifname
);
1860 static struct cmd_node interface_node
= {
1861 INTERFACE_NODE
, "%s(config-if)# ", 1,
1864 /* Called when interface structure allocated. */
1865 static int rip_interface_new_hook(struct interface
*ifp
)
1867 ifp
->info
= rip_interface_new();
1871 /* Called when interface structure deleted. */
1872 static int rip_interface_delete_hook(struct interface
*ifp
)
1874 XFREE(MTYPE_RIP_INTERFACE
, ifp
->info
);
1879 /* Allocate and initialize interface vector. */
1880 void rip_if_init(void)
1882 /* Default initial size of interface vector. */
1883 hook_register_prio(if_add
, 0, rip_interface_new_hook
);
1884 hook_register_prio(if_del
, 0, rip_interface_delete_hook
);
1886 /* RIP network init. */
1887 rip_enable_interface
= vector_init(1);
1888 rip_enable_network
= route_table_init();
1890 /* RIP passive interface. */
1891 Vrip_passive_nondefault
= vector_init(1);
1893 /* Install interface node. */
1894 install_node(&interface_node
, rip_interface_config_write
);
1897 /* Install commands. */
1898 install_element(RIP_NODE
, &rip_network_cmd
);
1899 install_element(RIP_NODE
, &no_rip_network_cmd
);
1900 install_element(RIP_NODE
, &rip_neighbor_cmd
);
1901 install_element(RIP_NODE
, &no_rip_neighbor_cmd
);
1903 install_element(RIP_NODE
, &rip_passive_interface_cmd
);
1904 install_element(RIP_NODE
, &no_rip_passive_interface_cmd
);
1906 install_element(INTERFACE_NODE
, &ip_rip_send_version_cmd
);
1907 install_element(INTERFACE_NODE
, &ip_rip_send_version_1_cmd
);
1908 install_element(INTERFACE_NODE
, &no_ip_rip_send_version_cmd
);
1910 install_element(INTERFACE_NODE
, &ip_rip_receive_version_cmd
);
1911 install_element(INTERFACE_NODE
, &ip_rip_receive_version_1_cmd
);
1912 install_element(INTERFACE_NODE
, &no_ip_rip_receive_version_cmd
);
1914 install_element(INTERFACE_NODE
, &ip_rip_v2_broadcast_cmd
);
1915 install_element(INTERFACE_NODE
, &no_ip_rip_v2_broadcast_cmd
);
1917 install_element(INTERFACE_NODE
, &ip_rip_authentication_mode_cmd
);
1918 install_element(INTERFACE_NODE
, &no_ip_rip_authentication_mode_cmd
);
1920 install_element(INTERFACE_NODE
, &ip_rip_authentication_key_chain_cmd
);
1921 install_element(INTERFACE_NODE
,
1922 &no_ip_rip_authentication_key_chain_cmd
);
1924 install_element(INTERFACE_NODE
, &ip_rip_authentication_string_cmd
);
1925 install_element(INTERFACE_NODE
, &no_ip_rip_authentication_string_cmd
);
1927 install_element(INTERFACE_NODE
, &ip_rip_split_horizon_cmd
);
1928 install_element(INTERFACE_NODE
,
1929 &ip_rip_split_horizon_poisoned_reverse_cmd
);
1930 install_element(INTERFACE_NODE
, &no_ip_rip_split_horizon_cmd
);
1931 install_element(INTERFACE_NODE
,
1932 &no_ip_rip_split_horizon_poisoned_reverse_cmd
);