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"
44 void rip_enable_apply (struct interface
*);
45 void rip_passive_interface_apply (struct interface
*);
46 int rip_if_down(struct interface
*ifp
);
47 int rip_enable_if_lookup (const char *ifname
);
48 int rip_enable_network_lookup2 (struct connected
*connected
);
49 void rip_enable_apply_all ();
52 struct message ri_version_msg
[] =
54 {RI_RIP_VERSION_1
, "1"},
55 {RI_RIP_VERSION_2
, "2"},
56 {RI_RIP_VERSION_1_AND_2
, "1 2"},
60 extern struct zebra_privs_t ripd_privs
;
62 /* RIP enabled network vector. */
63 vector rip_enable_interface
;
65 /* RIP enabled interface table. */
66 struct route_table
*rip_enable_network
;
68 /* Vector to store passive-interface name. */
69 static int passive_default
; /* are we in passive-interface default mode? */
70 vector Vrip_passive_nondefault
;
72 /* Join to the RIP version 2 multicast group. */
74 ipv4_multicast_join (int sock
,
81 ret
= setsockopt_multicast_ipv4 (sock
,
88 zlog (NULL
, LOG_INFO
, "can't setsockopt IP_ADD_MEMBERSHIP %s",
94 /* Leave from the RIP version 2 multicast group. */
96 ipv4_multicast_leave (int sock
,
103 ret
= setsockopt_multicast_ipv4 (sock
,
110 zlog (NULL
, LOG_INFO
, "can't setsockopt IP_DROP_MEMBERSHIP");
115 /* Allocate new RIP's interface configuration. */
116 struct rip_interface
*
119 struct rip_interface
*ri
;
121 ri
= XMALLOC (MTYPE_RIP_INTERFACE
, sizeof (struct rip_interface
));
122 memset (ri
, 0, sizeof (struct rip_interface
));
124 /* Default authentication type is simple password for Cisco
126 /* ri->auth_type = RIP_NO_AUTH; */
127 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
128 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
130 /* Set default split-horizon behavior. If the interface is Frame
131 Relay or SMDS is enabled, the default value for split-horizon is
132 off. But currently Zebra does detect Frame Relay or SMDS
133 interface. So all interface is set to split horizon. */
134 ri
->split_horizon_default
= RIP_SPLIT_HORIZON
;
135 ri
->split_horizon
= ri
->split_horizon_default
;
141 rip_interface_multicast_set (int sock
, struct connected
*connected
)
145 struct sockaddr_in from
;
147 struct prefix_ipv4
*p
;
149 if (connected
!= NULL
)
151 if (if_is_pointopoint(connected
->ifp
))
152 p
= (struct prefix_ipv4
*) connected
->destination
;
154 p
= (struct prefix_ipv4
*) connected
->address
;
159 addr
.s_addr
= INADDR_ANY
;
162 if (setsockopt_multicast_ipv4 (sock
, IP_MULTICAST_IF
, addr
, 0,
163 connected
->ifp
->ifindex
) < 0)
165 zlog_warn ("Can't setsockopt IP_MULTICAST_IF to fd %d, ifindex %d",
166 sock
, connected
->ifp
->ifindex
);
171 memset (&from
, 0, sizeof (struct sockaddr_in
));
174 sp
= getservbyname ("router", "udp");
176 from
.sin_port
= sp
->s_port
;
178 from
.sin_port
= htons (RIP_PORT_DEFAULT
);
180 /* Address should be any address. */
181 from
.sin_family
= AF_INET
;
183 addr
= ((struct prefix_ipv4
*) connected
->address
)->prefix
;
184 from
.sin_addr
= addr
;
186 from
.sin_len
= sizeof (struct sockaddr_in
);
187 #endif /* HAVE_SIN_LEN */
189 if (ripd_privs
.change (ZPRIVS_RAISE
))
190 zlog_err ("rip_interface_multicast_set: could not raise privs");
192 ret
= bind (sock
, (struct sockaddr
*) & from
, sizeof (struct sockaddr_in
));
195 zlog_warn ("Can't bind socket: %s", strerror (errno
));
198 if (ripd_privs
.change (ZPRIVS_LOWER
))
199 zlog_err ("rip_interface_multicast_set: could not lower privs");
205 /* Send RIP request packet to specified interface. */
207 rip_request_interface_send (struct interface
*ifp
, u_char version
)
209 struct sockaddr_in to
;
211 /* RIPv2 support multicast. */
212 if (version
== RIPv2
&& if_is_multicast (ifp
))
215 if (IS_RIP_DEBUG_EVENT
)
216 zlog_info ("multicast request on %s", ifp
->name
);
218 rip_request_send (NULL
, ifp
, version
, NULL
);
222 /* RIPv1 and non multicast interface. */
223 if (if_is_pointopoint (ifp
) || if_is_broadcast (ifp
))
225 struct listnode
*cnode
;
227 if (IS_RIP_DEBUG_EVENT
)
228 zlog_info ("broadcast request to %s", ifp
->name
);
230 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
232 struct prefix_ipv4
*p
;
233 struct connected
*connected
;
235 connected
= getdata (cnode
);
236 p
= (struct prefix_ipv4
*) connected
->destination
;
238 if (p
->family
== AF_INET
)
240 memset (&to
, 0, sizeof (struct sockaddr_in
));
241 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
242 to
.sin_addr
= p
->prefix
;
244 if (IS_RIP_DEBUG_EVENT
)
245 zlog_info ("SEND request to %s", inet_ntoa (to
.sin_addr
));
247 rip_request_send (&to
, ifp
, version
, connected
);
253 /* This will be executed when interface goes up. */
255 rip_request_interface (struct interface
*ifp
)
257 struct rip_interface
*ri
;
259 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
260 if (if_is_loopback (ifp
))
263 /* If interface is down, don't send RIP packet. */
264 if (! if_is_operative (ifp
))
267 /* Fetch RIP interface information. */
271 /* If there is no version configuration in the interface,
272 use rip's version setting. */
274 int vsend
= ((ri
->ri_send
== RI_RIP_UNSPEC
) ?
275 rip
->version_send
: ri
->ri_send
);
277 rip_request_interface_send (ifp
, RIPv1
);
279 rip_request_interface_send (ifp
, RIPv2
);
283 /* Send RIP request to the neighbor. */
285 rip_request_neighbor (struct in_addr addr
)
287 struct sockaddr_in to
;
289 memset (&to
, 0, sizeof (struct sockaddr_in
));
290 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
293 rip_request_send (&to
, NULL
, rip
->version_send
, NULL
);
296 /* Request routes at all interfaces. */
298 rip_request_neighbor_all ()
300 struct route_node
*rp
;
305 if (IS_RIP_DEBUG_EVENT
)
306 zlog_info ("request to the all neighbor");
308 /* Send request to all neighbor. */
309 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
311 rip_request_neighbor (rp
->p
.u
.prefix4
);
314 /* Multicast packet receive socket. */
316 rip_multicast_join (struct interface
*ifp
, int sock
)
318 struct listnode
*cnode
;
320 if (if_is_operative (ifp
) && if_is_multicast (ifp
))
322 if (IS_RIP_DEBUG_EVENT
)
323 zlog_info ("multicast join at %s", ifp
->name
);
325 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
327 struct prefix_ipv4
*p
;
328 struct connected
*connected
;
329 struct in_addr group
;
331 connected
= getdata (cnode
);
332 p
= (struct prefix_ipv4
*) connected
->address
;
334 if (p
->family
!= AF_INET
)
337 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
338 if (ipv4_multicast_join (sock
, group
, p
->prefix
, ifp
->ifindex
) < 0)
347 /* Leave from multicast group. */
349 rip_multicast_leave (struct interface
*ifp
, int sock
)
351 struct listnode
*cnode
;
353 if (if_is_up (ifp
) && if_is_multicast (ifp
))
355 if (IS_RIP_DEBUG_EVENT
)
356 zlog_info ("multicast leave from %s", ifp
->name
);
358 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
360 struct prefix_ipv4
*p
;
361 struct connected
*connected
;
362 struct in_addr group
;
364 connected
= getdata (cnode
);
365 p
= (struct prefix_ipv4
*) connected
->address
;
367 if (p
->family
!= AF_INET
)
370 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
371 if (ipv4_multicast_leave (sock
, group
, p
->prefix
, ifp
->ifindex
) == 0)
377 /* Is there and address on interface that I could use ? */
379 rip_if_ipv4_address_check (struct interface
*ifp
)
382 struct connected
*connected
;
385 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
386 if ((connected
= getdata (nn
)) != NULL
)
390 p
= connected
->address
;
392 if (p
->family
== AF_INET
)
404 /* Does this address belongs to me ? */
406 if_check_address (struct in_addr addr
)
408 struct listnode
*node
;
410 for (node
= listhead (iflist
); node
; nextnode (node
))
412 struct listnode
*cnode
;
413 struct interface
*ifp
;
415 ifp
= getdata (node
);
417 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
419 struct connected
*connected
;
420 struct prefix_ipv4
*p
;
422 connected
= getdata (cnode
);
423 p
= (struct prefix_ipv4
*) connected
->address
;
425 if (p
->family
!= AF_INET
)
428 if (IPV4_ADDR_CMP (&p
->prefix
, &addr
) == 0)
435 /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */
437 if_valid_neighbor (struct in_addr addr
)
439 struct listnode
*node
;
440 struct connected
*connected
= NULL
;
441 struct prefix_ipv4
*p
;
443 for (node
= listhead (iflist
); node
; nextnode (node
))
445 struct listnode
*cnode
;
446 struct interface
*ifp
;
448 ifp
= getdata (node
);
450 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
452 struct prefix
*pxn
= NULL
; /* Prefix of the neighbor */
453 struct prefix
*pxc
= NULL
; /* Prefix of the connected network */
455 connected
= getdata (cnode
);
457 if (if_is_pointopoint (ifp
))
459 p
= (struct prefix_ipv4
*) connected
->address
;
461 if (p
&& p
->family
== AF_INET
)
463 if (IPV4_ADDR_SAME (&p
->prefix
, &addr
))
466 p
= (struct prefix_ipv4
*) connected
->destination
;
467 if (p
&& IPV4_ADDR_SAME (&p
->prefix
, &addr
))
473 p
= (struct prefix_ipv4
*) connected
->address
;
475 if (p
->family
!= AF_INET
)
479 pxn
->family
= AF_INET
;
481 pxn
->u
.prefix4
= addr
;
484 prefix_copy(pxc
, (struct prefix
*) p
);
487 if (prefix_match (pxc
, pxn
))
501 /* Inteface link down message processing. */
503 rip_interface_down (int command
, struct zclient
*zclient
, zebra_size_t length
)
505 struct interface
*ifp
;
510 /* zebra_interface_state_read() updates interface structure in
512 ifp
= zebra_interface_state_read(s
);
519 if (IS_RIP_DEBUG_ZEBRA
)
520 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is down",
521 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
526 /* Inteface link up message processing */
528 rip_interface_up (int command
, struct zclient
*zclient
, zebra_size_t length
)
530 struct interface
*ifp
;
532 /* zebra_interface_state_read () updates interface structure in
534 ifp
= zebra_interface_state_read (zclient
->ibuf
);
539 if (IS_RIP_DEBUG_ZEBRA
)
540 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is up",
541 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
543 /* Check if this interface is RIP enabled or not.*/
544 rip_enable_apply (ifp
);
546 /* Check for a passive interface */
547 rip_passive_interface_apply (ifp
);
549 /* Apply distribute list to the all interface. */
550 rip_distribute_update_interface (ifp
);
555 /* Inteface addition message from zebra. */
557 rip_interface_add (int command
, struct zclient
*zclient
, zebra_size_t length
)
559 struct interface
*ifp
;
561 ifp
= zebra_interface_add_read (zclient
->ibuf
);
563 if (IS_RIP_DEBUG_ZEBRA
)
564 zlog_info ("interface add %s index %d flags %ld metric %d mtu %d",
565 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
567 /* Check if this interface is RIP enabled or not.*/
568 rip_enable_apply (ifp
);
570 /* Apply distribute list to the all interface. */
571 rip_distribute_update_interface (ifp
);
573 /* rip_request_neighbor_all (); */
575 /* Check interface routemap. */
576 rip_if_rmap_update_interface (ifp
);
582 rip_interface_delete (int command
, struct zclient
*zclient
,
585 struct interface
*ifp
;
590 /* zebra_interface_state_read() updates interface structure in iflist */
591 ifp
= zebra_interface_state_read(s
);
596 if (if_is_up (ifp
)) {
600 zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
601 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
603 /* To support pseudo interface do not free interface structure. */
604 /* if_delete(ifp); */
610 rip_interface_clean ()
612 struct listnode
*node
;
613 struct interface
*ifp
;
614 struct rip_interface
*ri
;
616 for (node
= listhead (iflist
); node
; nextnode (node
))
618 ifp
= getdata (node
);
621 ri
->enable_network
= 0;
622 ri
->enable_interface
= 0;
627 thread_cancel (ri
->t_wakeup
);
634 rip_interface_reset ()
636 struct listnode
*node
;
637 struct interface
*ifp
;
638 struct rip_interface
*ri
;
640 for (node
= listhead (iflist
); node
; nextnode (node
))
642 ifp
= getdata (node
);
645 ri
->enable_network
= 0;
646 ri
->enable_interface
= 0;
649 ri
->ri_send
= RI_RIP_UNSPEC
;
650 ri
->ri_receive
= RI_RIP_UNSPEC
;
652 /* ri->auth_type = RIP_NO_AUTH; */
653 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
662 free (ri
->key_chain
);
663 ri
->key_chain
= NULL
;
666 ri
->split_horizon
= RIP_NO_SPLIT_HORIZON
;
667 ri
->split_horizon_default
= RIP_NO_SPLIT_HORIZON
;
669 ri
->list
[RIP_FILTER_IN
] = NULL
;
670 ri
->list
[RIP_FILTER_OUT
] = NULL
;
672 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
673 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
677 thread_cancel (ri
->t_wakeup
);
681 ri
->recv_badpackets
= 0;
682 ri
->recv_badroutes
= 0;
683 ri
->sent_updates
= 0;
690 rip_if_down(struct interface
*ifp
)
692 struct route_node
*rp
;
693 struct rip_info
*rinfo
;
694 struct rip_interface
*ri
= NULL
;
697 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
698 if ((rinfo
= rp
->info
) != NULL
)
700 /* Routes got through this interface. */
701 if (rinfo
->ifindex
== ifp
->ifindex
&&
702 rinfo
->type
== ZEBRA_ROUTE_RIP
&&
703 rinfo
->sub_type
== RIP_ROUTE_RTE
)
705 rip_zebra_ipv4_delete ((struct prefix_ipv4
*) &rp
->p
,
709 rip_redistribute_delete (rinfo
->type
,rinfo
->sub_type
,
710 (struct prefix_ipv4
*)&rp
->p
,
715 /* All redistributed routes but static and system */
716 if ((rinfo
->ifindex
== ifp
->ifindex
) &&
717 /* (rinfo->type != ZEBRA_ROUTE_STATIC) && */
718 (rinfo
->type
!= ZEBRA_ROUTE_SYSTEM
))
719 rip_redistribute_delete (rinfo
->type
,rinfo
->sub_type
,
720 (struct prefix_ipv4
*)&rp
->p
,
730 if (IS_RIP_DEBUG_EVENT
)
731 zlog_info ("turn off %s", ifp
->name
);
733 /* Leave from multicast group. */
734 rip_multicast_leave (ifp
, rip
->sock
);
742 /* Needed for stop RIP process. */
746 struct interface
*ifp
;
747 struct listnode
*node
;
749 for (node
= listhead (iflist
); node
; nextnode (node
))
751 ifp
= getdata (node
);
757 rip_apply_address_add (struct connected
*ifc
) {
758 struct prefix_ipv4 address
;
764 if (! if_is_up(ifc
->ifp
))
769 memset (&address
, 0, sizeof (address
));
770 address
.family
= p
->family
;
771 address
.prefix
= p
->u
.prefix4
;
772 address
.prefixlen
= p
->prefixlen
;
773 apply_mask_ipv4(&address
);
775 /* Check if this interface is RIP enabled or not
776 or Check if this address's prefix is RIP enabled */
777 if ((rip_enable_if_lookup(ifc
->ifp
->name
) >= 0) ||
778 (rip_enable_network_lookup2(ifc
) >= 0))
779 rip_redistribute_add(ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
780 &address
, ifc
->ifp
->ifindex
, NULL
);
785 rip_interface_address_add (int command
, struct zclient
*zclient
,
788 struct connected
*ifc
;
791 ifc
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD
,
799 if (p
->family
== AF_INET
)
801 if (IS_RIP_DEBUG_ZEBRA
)
802 zlog_info ("connected address %s/%d is added",
803 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
805 rip_enable_apply(ifc
->ifp
);
806 /* Check if this prefix needs to be redistributed */
807 rip_apply_address_add(ifc
);
810 rip_ifaddr_add (ifc
->ifp
, ifc
);
811 #endif /* HAVE_SNMP */
818 rip_apply_address_del (struct connected
*ifc
) {
819 struct prefix_ipv4 address
;
825 if (! if_is_up(ifc
->ifp
))
830 memset (&address
, 0, sizeof (address
));
831 address
.family
= p
->family
;
832 address
.prefix
= p
->u
.prefix4
;
833 address
.prefixlen
= p
->prefixlen
;
834 apply_mask_ipv4(&address
);
836 rip_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
837 &address
, ifc
->ifp
->ifindex
);
841 rip_interface_address_delete (int command
, struct zclient
*zclient
,
844 struct connected
*ifc
;
847 ifc
= zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE
,
853 if (p
->family
== AF_INET
)
855 if (IS_RIP_DEBUG_ZEBRA
)
857 zlog_info ("connected address %s/%d is deleted",
858 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
861 rip_ifaddr_delete (ifc
->ifp
, ifc
);
862 #endif /* HAVE_SNMP */
864 /* Chech wether this prefix needs to be removed */
865 rip_apply_address_del(ifc
);
869 connected_free (ifc
);
876 /* Check interface is enabled by network statement. */
877 /* Check wether the interface has at least a connected prefix that
878 * is within the ripng_enable_network table. */
880 rip_enable_network_lookup_if (struct interface
*ifp
)
883 struct connected
*connected
;
884 struct prefix_ipv4 address
;
886 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
887 if ((connected
= getdata (nn
)) != NULL
)
890 struct route_node
*node
;
892 p
= connected
->address
;
894 if (p
->family
== AF_INET
)
896 address
.family
= AF_INET
;
897 address
.prefix
= p
->u
.prefix4
;
898 address
.prefixlen
= IPV4_MAX_BITLEN
;
900 node
= route_node_match (rip_enable_network
,
901 (struct prefix
*)&address
);
904 route_unlock_node (node
);
912 /* Check wether connected is within the ripng_enable_network table. */
914 rip_enable_network_lookup2 (struct connected
*connected
)
916 struct prefix_ipv4 address
;
919 p
= connected
->address
;
921 if (p
->family
== AF_INET
) {
922 struct route_node
*node
;
924 address
.family
= p
->family
;
925 address
.prefix
= p
->u
.prefix4
;
926 address
.prefixlen
= IPV4_MAX_BITLEN
;
928 /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within rip_enable_network */
929 node
= route_node_match (rip_enable_network
,
930 (struct prefix
*)&address
);
933 route_unlock_node (node
);
940 /* Add RIP enable network. */
942 rip_enable_network_add (struct prefix
*p
)
944 struct route_node
*node
;
946 node
= route_node_get (rip_enable_network
, p
);
950 route_unlock_node (node
);
954 node
->info
= (char *) "enabled";
956 /* XXX: One should find a better solution than a generic one */
957 rip_enable_apply_all();
962 /* Delete RIP enable network. */
964 rip_enable_network_delete (struct prefix
*p
)
966 struct route_node
*node
;
968 node
= route_node_lookup (rip_enable_network
, p
);
973 /* Unlock info lock. */
974 route_unlock_node (node
);
976 /* Unlock lookup lock. */
977 route_unlock_node (node
);
979 /* XXX: One should find a better solution than a generic one */
980 rip_enable_apply_all ();
987 /* Check interface is enabled by ifname statement. */
989 rip_enable_if_lookup (const char *ifname
)
994 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
995 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
996 if (strcmp (str
, ifname
) == 0)
1001 /* Add interface to rip_enable_if. */
1003 rip_enable_if_add (const char *ifname
)
1007 ret
= rip_enable_if_lookup (ifname
);
1011 vector_set (rip_enable_interface
, strdup (ifname
));
1013 rip_enable_apply_all(); /* TODOVJ */
1018 /* Delete interface from rip_enable_if. */
1020 rip_enable_if_delete (const char *ifname
)
1025 index
= rip_enable_if_lookup (ifname
);
1029 str
= vector_slot (rip_enable_interface
, index
);
1031 vector_unset (rip_enable_interface
, index
);
1033 rip_enable_apply_all(); /* TODOVJ */
1038 /* Join to multicast group and send request to the interface. */
1040 rip_interface_wakeup (struct thread
*t
)
1042 struct interface
*ifp
;
1043 struct rip_interface
*ri
;
1045 /* Get interface. */
1046 ifp
= THREAD_ARG (t
);
1049 ri
->t_wakeup
= NULL
;
1051 /* Join to multicast group. */
1052 if (rip_multicast_join (ifp
, rip
->sock
) < 0)
1054 zlog_err ("multicast join failed, interface %s not running", ifp
->name
);
1058 /* Set running flag. */
1061 /* Send RIP request to the interface. */
1062 rip_request_interface (ifp
);
1067 int rip_redistribute_check (int);
1070 rip_connect_set (struct interface
*ifp
, int set
)
1072 struct listnode
*nn
;
1073 struct connected
*connected
;
1074 struct prefix_ipv4 address
;
1076 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
1077 if ((connected
= getdata (nn
)) != NULL
)
1080 p
= connected
->address
;
1082 if (p
->family
!= AF_INET
)
1085 address
.family
= AF_INET
;
1086 address
.prefix
= p
->u
.prefix4
;
1087 address
.prefixlen
= p
->prefixlen
;
1088 apply_mask_ipv4 (&address
);
1091 /* Check once more wether this prefix is within a "network IF_OR_PREF" one */
1092 if ((rip_enable_if_lookup(connected
->ifp
->name
) >= 0) ||
1093 (rip_enable_network_lookup2(connected
) >= 0))
1094 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
1095 &address
, connected
->ifp
->ifindex
, NULL
);
1098 rip_redistribute_delete (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
1099 &address
, connected
->ifp
->ifindex
);
1100 if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT
))
1101 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_REDISTRIBUTE
,
1102 &address
, connected
->ifp
->ifindex
, NULL
);
1107 /* Update interface status. */
1109 rip_enable_apply (struct interface
*ifp
)
1112 struct rip_interface
*ri
= NULL
;
1114 /* Check interface. */
1115 if (! if_is_operative (ifp
))
1120 /* Check network configuration. */
1121 ret
= rip_enable_network_lookup_if (ifp
);
1123 /* If the interface is matched. */
1125 ri
->enable_network
= 1;
1127 ri
->enable_network
= 0;
1129 /* Check interface name configuration. */
1130 ret
= rip_enable_if_lookup (ifp
->name
);
1132 ri
->enable_interface
= 1;
1134 ri
->enable_interface
= 0;
1136 /* any interface MUST have an IPv4 address */
1137 if ( ! rip_if_ipv4_address_check (ifp
) )
1139 ri
->enable_network
= 0;
1140 ri
->enable_interface
= 0;
1143 /* Update running status of the interface. */
1144 if (ri
->enable_network
|| ri
->enable_interface
)
1147 if (IS_RIP_DEBUG_EVENT
)
1148 zlog_info ("turn on %s", ifp
->name
);
1150 /* Add interface wake up thread. */
1152 ri
->t_wakeup
= thread_add_timer (master
, rip_interface_wakeup
,
1154 rip_connect_set (ifp
, 1);
1161 /* Might as well clean up the route table as well
1162 * rip_if_down sets to 0 ri->running, and displays "turn off %s"
1166 rip_connect_set (ifp
, 0);
1171 /* Apply network configuration to all interface. */
1173 rip_enable_apply_all ()
1175 struct interface
*ifp
;
1176 struct listnode
*node
;
1178 /* Check each interface. */
1179 for (node
= listhead (iflist
); node
; nextnode (node
))
1181 ifp
= getdata (node
);
1182 rip_enable_apply (ifp
);
1187 rip_neighbor_lookup (struct sockaddr_in
*from
)
1189 struct prefix_ipv4 p
;
1190 struct route_node
*node
;
1192 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1194 p
.prefix
= from
->sin_addr
;
1195 p
.prefixlen
= IPV4_MAX_BITLEN
;
1197 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) &p
);
1200 route_unlock_node (node
);
1206 /* Add new RIP neighbor to the neighbor tree. */
1208 rip_neighbor_add (struct prefix_ipv4
*p
)
1210 struct route_node
*node
;
1212 node
= route_node_get (rip
->neighbor
, (struct prefix
*) p
);
1217 node
->info
= rip
->neighbor
;
1222 /* Delete RIP neighbor from the neighbor tree. */
1224 rip_neighbor_delete (struct prefix_ipv4
*p
)
1226 struct route_node
*node
;
1228 /* Lock for look up. */
1229 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) p
);
1235 /* Unlock lookup lock. */
1236 route_unlock_node (node
);
1238 /* Unlock real neighbor information lock. */
1239 route_unlock_node (node
);
1244 /* Clear all network and neighbor configuration. */
1246 rip_clean_network ()
1250 struct route_node
*rn
;
1252 /* rip_enable_network. */
1253 for (rn
= route_top (rip_enable_network
); rn
; rn
= route_next (rn
))
1257 route_unlock_node (rn
);
1260 /* rip_enable_interface. */
1261 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
1262 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
1265 vector_slot (rip_enable_interface
, i
) = NULL
;
1269 /* Utility function for looking up passive interface settings. */
1271 rip_passive_nondefault_lookup (const char *ifname
)
1276 for (i
= 0; i
< vector_max (Vrip_passive_nondefault
); i
++)
1277 if ((str
= vector_slot (Vrip_passive_nondefault
, i
)) != NULL
)
1278 if (strcmp (str
, ifname
) == 0)
1284 rip_passive_interface_apply (struct interface
*ifp
)
1286 struct rip_interface
*ri
;
1290 ri
->passive
= ((rip_passive_nondefault_lookup (ifp
->name
) < 0) ?
1291 passive_default
: !passive_default
);
1293 if (IS_RIP_DEBUG_ZEBRA
)
1294 zlog_info ("interface %s: passive = %d",ifp
->name
,ri
->passive
);
1298 rip_passive_interface_apply_all ()
1300 struct interface
*ifp
;
1301 struct listnode
*node
;
1303 for (node
= listhead (iflist
); node
; nextnode (node
))
1305 ifp
= getdata (node
);
1306 rip_passive_interface_apply (ifp
);
1310 /* Passive interface. */
1312 rip_passive_nondefault_set (struct vty
*vty
, const char *ifname
)
1314 if (rip_passive_nondefault_lookup (ifname
) >= 0)
1317 vector_set (Vrip_passive_nondefault
, strdup (ifname
));
1319 rip_passive_interface_apply_all ();
1325 rip_passive_nondefault_unset (struct vty
*vty
, const char *ifname
)
1330 i
= rip_passive_nondefault_lookup (ifname
);
1334 str
= vector_slot (Vrip_passive_nondefault
, i
);
1336 vector_unset (Vrip_passive_nondefault
, i
);
1338 rip_passive_interface_apply_all ();
1343 /* Free all configured RIP passive-interface settings. */
1345 rip_passive_nondefault_clean ()
1350 for (i
= 0; i
< vector_max (Vrip_passive_nondefault
); i
++)
1351 if ((str
= vector_slot (Vrip_passive_nondefault
, i
)) != NULL
)
1354 vector_slot (Vrip_passive_nondefault
, i
) = NULL
;
1356 rip_passive_interface_apply_all ();
1359 /* RIP enable network or interface configuration. */
1362 "network (A.B.C.D/M|WORD)",
1363 "Enable routing on an IP network\n"
1364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1368 struct prefix_ipv4 p
;
1370 ret
= str2prefix_ipv4 (argv
[0], &p
);
1373 ret
= rip_enable_network_add ((struct prefix
*) &p
);
1375 ret
= rip_enable_if_add (argv
[0]);
1379 vty_out (vty
, "There is a same network configuration %s%s", argv
[0],
1387 /* RIP enable network or interface configuration. */
1388 DEFUN (no_rip_network
,
1390 "no network (A.B.C.D/M|WORD)",
1392 "Enable routing on an IP network\n"
1393 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1397 struct prefix_ipv4 p
;
1399 ret
= str2prefix_ipv4 (argv
[0], &p
);
1402 ret
= rip_enable_network_delete ((struct prefix
*) &p
);
1404 ret
= rip_enable_if_delete (argv
[0]);
1408 vty_out (vty
, "Can't find network configuration %s%s", argv
[0],
1416 /* RIP neighbor configuration set. */
1417 DEFUN (rip_neighbor
,
1420 "Specify a neighbor router\n"
1421 "Neighbor address\n")
1424 struct prefix_ipv4 p
;
1426 ret
= str2prefix_ipv4 (argv
[0], &p
);
1430 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1434 rip_neighbor_add (&p
);
1439 /* RIP neighbor configuration unset. */
1440 DEFUN (no_rip_neighbor
,
1441 no_rip_neighbor_cmd
,
1442 "no neighbor A.B.C.D",
1444 "Specify a neighbor router\n"
1445 "Neighbor address\n")
1448 struct prefix_ipv4 p
;
1450 ret
= str2prefix_ipv4 (argv
[0], &p
);
1454 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1458 rip_neighbor_delete (&p
);
1463 DEFUN (ip_rip_receive_version
,
1464 ip_rip_receive_version_cmd
,
1465 "ip rip receive version (1|2)",
1467 "Routing Information Protocol\n"
1468 "Advertisement reception\n"
1473 struct interface
*ifp
;
1474 struct rip_interface
*ri
;
1476 ifp
= (struct interface
*)vty
->index
;
1480 if (atoi (argv
[0]) == 1)
1482 ri
->ri_receive
= RI_RIP_VERSION_1
;
1485 if (atoi (argv
[0]) == 2)
1487 ri
->ri_receive
= RI_RIP_VERSION_2
;
1493 DEFUN (ip_rip_receive_version_1
,
1494 ip_rip_receive_version_1_cmd
,
1495 "ip rip receive version 1 2",
1497 "Routing Information Protocol\n"
1498 "Advertisement reception\n"
1503 struct interface
*ifp
;
1504 struct rip_interface
*ri
;
1506 ifp
= (struct interface
*)vty
->index
;
1509 /* Version 1 and 2. */
1510 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1514 DEFUN (ip_rip_receive_version_2
,
1515 ip_rip_receive_version_2_cmd
,
1516 "ip rip receive version 2 1",
1518 "Routing Information Protocol\n"
1519 "Advertisement reception\n"
1524 struct interface
*ifp
;
1525 struct rip_interface
*ri
;
1527 ifp
= (struct interface
*)vty
->index
;
1530 /* Version 1 and 2. */
1531 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1535 DEFUN (no_ip_rip_receive_version
,
1536 no_ip_rip_receive_version_cmd
,
1537 "no ip rip receive version",
1540 "Routing Information Protocol\n"
1541 "Advertisement reception\n"
1542 "Version control\n")
1544 struct interface
*ifp
;
1545 struct rip_interface
*ri
;
1547 ifp
= (struct interface
*)vty
->index
;
1550 ri
->ri_receive
= RI_RIP_UNSPEC
;
1554 ALIAS (no_ip_rip_receive_version
,
1555 no_ip_rip_receive_version_num_cmd
,
1556 "no ip rip receive version (1|2)",
1559 "Routing Information Protocol\n"
1560 "Advertisement reception\n"
1565 DEFUN (ip_rip_send_version
,
1566 ip_rip_send_version_cmd
,
1567 "ip rip send version (1|2)",
1569 "Routing Information Protocol\n"
1570 "Advertisement transmission\n"
1575 struct interface
*ifp
;
1576 struct rip_interface
*ri
;
1578 ifp
= (struct interface
*)vty
->index
;
1582 if (atoi (argv
[0]) == 1)
1584 ri
->ri_send
= RI_RIP_VERSION_1
;
1587 if (atoi (argv
[0]) == 2)
1589 ri
->ri_send
= RI_RIP_VERSION_2
;
1595 DEFUN (ip_rip_send_version_1
,
1596 ip_rip_send_version_1_cmd
,
1597 "ip rip send version 1 2",
1599 "Routing Information Protocol\n"
1600 "Advertisement transmission\n"
1605 struct interface
*ifp
;
1606 struct rip_interface
*ri
;
1608 ifp
= (struct interface
*)vty
->index
;
1611 /* Version 1 and 2. */
1612 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1616 DEFUN (ip_rip_send_version_2
,
1617 ip_rip_send_version_2_cmd
,
1618 "ip rip send version 2 1",
1620 "Routing Information Protocol\n"
1621 "Advertisement transmission\n"
1626 struct interface
*ifp
;
1627 struct rip_interface
*ri
;
1629 ifp
= (struct interface
*)vty
->index
;
1632 /* Version 1 and 2. */
1633 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1637 DEFUN (no_ip_rip_send_version
,
1638 no_ip_rip_send_version_cmd
,
1639 "no ip rip send version",
1642 "Routing Information Protocol\n"
1643 "Advertisement transmission\n"
1644 "Version control\n")
1646 struct interface
*ifp
;
1647 struct rip_interface
*ri
;
1649 ifp
= (struct interface
*)vty
->index
;
1652 ri
->ri_send
= RI_RIP_UNSPEC
;
1656 ALIAS (no_ip_rip_send_version
,
1657 no_ip_rip_send_version_num_cmd
,
1658 "no ip rip send version (1|2)",
1661 "Routing Information Protocol\n"
1662 "Advertisement transmission\n"
1667 DEFUN (ip_rip_authentication_mode
,
1668 ip_rip_authentication_mode_cmd
,
1669 "ip rip authentication mode (md5|text)",
1671 "Routing Information Protocol\n"
1672 "Authentication control\n"
1673 "Authentication mode\n"
1674 "Keyed message digest\n"
1675 "Clear text authentication\n")
1677 struct interface
*ifp
;
1678 struct rip_interface
*ri
;
1680 ifp
= (struct interface
*)vty
->index
;
1683 if ( (argc
< 1) || (argc
> 2) )
1685 vty_out (vty
, "incorrect argument count%s", VTY_NEWLINE
);
1689 if (strncmp ("md5", argv
[0], strlen (argv
[0])) == 0)
1690 ri
->auth_type
= RIP_AUTH_MD5
;
1691 else if (strncmp ("text", argv
[0], strlen (argv
[0])) == 0)
1692 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1695 vty_out (vty
, "mode should be md5 or text%s", VTY_NEWLINE
);
1702 if ( (argc
== 2) && (ri
->auth_type
!= RIP_AUTH_MD5
) )
1704 vty_out (vty
, "auth length argument only valid for md5%s", VTY_NEWLINE
);
1708 if (strncmp ("r", argv
[1], 1) == 0)
1709 ri
->md5_auth_len
= RIP_AUTH_MD5_SIZE
;
1710 else if (strncmp ("o", argv
[1], 1) == 0)
1711 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
1718 ALIAS (ip_rip_authentication_mode
,
1719 ip_rip_authentication_mode_authlen_cmd
,
1720 "ip rip authentication mode (md5|text) auth-length (rfc|old-ripd)",
1722 "Routing Information Protocol\n"
1723 "Authentication control\n"
1724 "Authentication mode\n"
1725 "Keyed message digest\n"
1726 "Clear text authentication\n"
1727 "MD5 authentication data length\n"
1729 "Old ripd compatible\n")
1731 DEFUN (no_ip_rip_authentication_mode
,
1732 no_ip_rip_authentication_mode_cmd
,
1733 "no ip rip authentication mode",
1736 "Routing Information Protocol\n"
1737 "Authentication control\n"
1738 "Authentication mode\n")
1740 struct interface
*ifp
;
1741 struct rip_interface
*ri
;
1743 ifp
= (struct interface
*)vty
->index
;
1746 /* ri->auth_type = RIP_NO_AUTH; */
1747 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1748 ri
->md5_auth_len
= RIP_AUTH_MD5_COMPAT_SIZE
;
1753 ALIAS (no_ip_rip_authentication_mode
,
1754 no_ip_rip_authentication_mode_type_cmd
,
1755 "no ip rip authentication mode (md5|text)",
1758 "Routing Information Protocol\n"
1759 "Authentication control\n"
1760 "Authentication mode\n"
1761 "Keyed message digest\n"
1762 "Clear text authentication\n")
1764 ALIAS (no_ip_rip_authentication_mode
,
1765 no_ip_rip_authentication_mode_type_authlen_cmd
,
1766 "no ip rip authentication mode (md5|text) auth-length (rfc|old-ripd)",
1769 "Routing Information Protocol\n"
1770 "Authentication control\n"
1771 "Authentication mode\n"
1772 "Keyed message digest\n"
1773 "Clear text authentication\n"
1774 "MD5 authentication data length\n"
1776 "Old ripd compatible\n")
1778 DEFUN (ip_rip_authentication_string
,
1779 ip_rip_authentication_string_cmd
,
1780 "ip rip authentication string LINE",
1782 "Routing Information Protocol\n"
1783 "Authentication control\n"
1784 "Authentication string\n"
1785 "Authentication string\n")
1787 struct interface
*ifp
;
1788 struct rip_interface
*ri
;
1790 ifp
= (struct interface
*)vty
->index
;
1793 if (strlen (argv
[0]) > 16)
1795 vty_out (vty
, "%% RIPv2 authentication string must be shorter than 16%s",
1802 vty_out (vty
, "%% key-chain configuration exists%s", VTY_NEWLINE
);
1807 free (ri
->auth_str
);
1809 ri
->auth_str
= strdup (argv
[0]);
1814 DEFUN (no_ip_rip_authentication_string
,
1815 no_ip_rip_authentication_string_cmd
,
1816 "no ip rip authentication string",
1819 "Routing Information Protocol\n"
1820 "Authentication control\n"
1821 "Authentication string\n")
1823 struct interface
*ifp
;
1824 struct rip_interface
*ri
;
1826 ifp
= (struct interface
*)vty
->index
;
1830 free (ri
->auth_str
);
1832 ri
->auth_str
= NULL
;
1837 ALIAS (no_ip_rip_authentication_string
,
1838 no_ip_rip_authentication_string2_cmd
,
1839 "no ip rip authentication string LINE",
1842 "Routing Information Protocol\n"
1843 "Authentication control\n"
1844 "Authentication string\n"
1845 "Authentication string\n")
1847 DEFUN (ip_rip_authentication_key_chain
,
1848 ip_rip_authentication_key_chain_cmd
,
1849 "ip rip authentication key-chain LINE",
1851 "Routing Information Protocol\n"
1852 "Authentication control\n"
1853 "Authentication key-chain\n"
1854 "name of key-chain\n")
1856 struct interface
*ifp
;
1857 struct rip_interface
*ri
;
1859 ifp
= (struct interface
*) vty
->index
;
1864 vty_out (vty
, "%% authentication string configuration exists%s",
1870 free (ri
->key_chain
);
1872 ri
->key_chain
= strdup (argv
[0]);
1877 DEFUN (no_ip_rip_authentication_key_chain
,
1878 no_ip_rip_authentication_key_chain_cmd
,
1879 "no ip rip authentication key-chain",
1882 "Routing Information Protocol\n"
1883 "Authentication control\n"
1884 "Authentication key-chain\n")
1886 struct interface
*ifp
;
1887 struct rip_interface
*ri
;
1889 ifp
= (struct interface
*) vty
->index
;
1893 free (ri
->key_chain
);
1895 ri
->key_chain
= NULL
;
1900 ALIAS (no_ip_rip_authentication_key_chain
,
1901 no_ip_rip_authentication_key_chain2_cmd
,
1902 "no ip rip authentication key-chain LINE",
1905 "Routing Information Protocol\n"
1906 "Authentication control\n"
1907 "Authentication key-chain\n"
1908 "name of key-chain\n")
1910 /* CHANGED: ip rip split-horizon
1911 Cisco and Zebra's command is
1914 DEFUN (ip_rip_split_horizon
,
1915 ip_rip_split_horizon_cmd
,
1916 "ip rip split-horizon",
1918 "Routing Information Protocol\n"
1919 "Perform split horizon\n")
1921 struct interface
*ifp
;
1922 struct rip_interface
*ri
;
1927 ri
->split_horizon
= RIP_SPLIT_HORIZON
;
1931 DEFUN (ip_rip_split_horizon_poisoned_reverse
,
1932 ip_rip_split_horizon_poisoned_reverse_cmd
,
1933 "ip rip split-horizon poisoned-reverse",
1935 "Routing Information Protocol\n"
1936 "Perform split horizon\n"
1937 "With poisoned-reverse\n")
1939 struct interface
*ifp
;
1940 struct rip_interface
*ri
;
1945 ri
->split_horizon
= RIP_SPLIT_HORIZON_POISONED_REVERSE
;
1949 /* CHANGED: no ip rip split-horizon
1950 Cisco and Zebra's command is
1953 DEFUN (no_ip_rip_split_horizon
,
1954 no_ip_rip_split_horizon_cmd
,
1955 "no ip rip split-horizon",
1958 "Routing Information Protocol\n"
1959 "Perform split horizon\n")
1961 struct interface
*ifp
;
1962 struct rip_interface
*ri
;
1967 ri
->split_horizon
= RIP_NO_SPLIT_HORIZON
;
1971 ALIAS (no_ip_rip_split_horizon
,
1972 no_ip_rip_split_horizon_poisoned_reverse_cmd
,
1973 "no ip rip split-horizon poisoned-reverse",
1976 "Routing Information Protocol\n"
1977 "Perform split horizon\n"
1978 "With poisoned-reverse\n")
1980 DEFUN (rip_passive_interface
,
1981 rip_passive_interface_cmd
,
1982 "passive-interface (IFNAME|default)",
1983 "Suppress routing updates on an interface\n"
1985 "default for all interfaces\n")
1987 const char *ifname
= argv
[0];
1989 if (!strcmp(ifname
,"default")) {
1990 passive_default
= 1;
1991 rip_passive_nondefault_clean();
1994 if (passive_default
)
1995 return rip_passive_nondefault_unset (vty
, ifname
);
1997 return rip_passive_nondefault_set (vty
, ifname
);
2000 DEFUN (no_rip_passive_interface
,
2001 no_rip_passive_interface_cmd
,
2002 "no passive-interface (IFNAME|default)",
2004 "Suppress routing updates on an interface\n"
2006 "default for all interfaces\n")
2008 const char *ifname
= argv
[0];
2010 if (!strcmp(ifname
,"default")) {
2011 passive_default
= 0;
2012 rip_passive_nondefault_clean();
2015 if (passive_default
)
2016 return rip_passive_nondefault_set (vty
, ifname
);
2018 return rip_passive_nondefault_unset (vty
, ifname
);
2021 /* Write rip configuration of each interface. */
2023 rip_interface_config_write (struct vty
*vty
)
2025 struct listnode
*node
;
2026 struct interface
*ifp
;
2028 for (node
= listhead (iflist
); node
; nextnode (node
))
2030 struct rip_interface
*ri
;
2032 ifp
= getdata (node
);
2035 /* Do not display the interface if there is no
2036 * configuration about it.
2039 (ri
->split_horizon
== ri
->split_horizon_default
) &&
2040 (ri
->ri_send
== RI_RIP_UNSPEC
) &&
2041 (ri
->ri_receive
== RI_RIP_UNSPEC
) &&
2042 (ri
->auth_type
!= RIP_AUTH_MD5
) &&
2043 (ri
->md5_auth_len
!= RIP_AUTH_MD5_SIZE
) &&
2048 vty_out (vty
, "interface %s%s", ifp
->name
,
2052 vty_out (vty
, " description %s%s", ifp
->desc
,
2055 /* Split horizon. */
2056 if (ri
->split_horizon
!= ri
->split_horizon_default
)
2058 switch (ri
->split_horizon
) {
2059 case RIP_SPLIT_HORIZON
:
2060 vty_out (vty
, " ip rip split-horizon%s", VTY_NEWLINE
);
2062 case RIP_SPLIT_HORIZON_POISONED_REVERSE
:
2063 vty_out (vty
, " ip rip split-horizon poisoned-reverse%s",
2066 case RIP_NO_SPLIT_HORIZON
:
2068 vty_out (vty
, " no ip rip split-horizon%s", VTY_NEWLINE
);
2073 /* RIP version setting. */
2074 if (ri
->ri_send
!= RI_RIP_UNSPEC
)
2075 vty_out (vty
, " ip rip send version %s%s",
2076 lookup (ri_version_msg
, ri
->ri_send
),
2079 if (ri
->ri_receive
!= RI_RIP_UNSPEC
)
2080 vty_out (vty
, " ip rip receive version %s%s",
2081 lookup (ri_version_msg
, ri
->ri_receive
),
2084 /* RIP authentication. */
2086 /* RIP_AUTH_SIMPLE_PASSWORD becomes default mode. */
2087 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
2088 vty_out (vty
, " ip rip authentication mode text%s", VTY_NEWLINE
);
2091 if (ri
->auth_type
== RIP_AUTH_MD5
)
2093 vty_out (vty
, " ip rip authentication mode md5");
2094 if (ri
->md5_auth_len
== RIP_AUTH_MD5_COMPAT_SIZE
)
2095 vty_out (vty
, " auth-length old-ripd");
2097 vty_out (vty
, " auth-length rfc");
2098 vty_out (vty
, "%s", VTY_NEWLINE
);
2102 vty_out (vty
, " ip rip authentication string %s%s",
2103 ri
->auth_str
, VTY_NEWLINE
);
2106 vty_out (vty
, " ip rip authentication key-chain %s%s",
2107 ri
->key_chain
, VTY_NEWLINE
);
2109 vty_out (vty
, "!%s", VTY_NEWLINE
);
2115 config_write_rip_network (struct vty
*vty
, int config_mode
)
2119 struct route_node
*node
;
2121 /* Network type RIP enable interface statement. */
2122 for (node
= route_top (rip_enable_network
); node
; node
= route_next (node
))
2124 vty_out (vty
, "%s%s/%d%s",
2125 config_mode
? " network " : " ",
2126 inet_ntoa (node
->p
.u
.prefix4
),
2130 /* Interface name RIP enable statement. */
2131 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
2132 if ((ifname
= vector_slot (rip_enable_interface
, i
)) != NULL
)
2133 vty_out (vty
, "%s%s%s",
2134 config_mode
? " network " : " ",
2138 /* RIP neighbors listing. */
2139 for (node
= route_top (rip
->neighbor
); node
; node
= route_next (node
))
2141 vty_out (vty
, "%s%s%s",
2142 config_mode
? " neighbor " : " ",
2143 inet_ntoa (node
->p
.u
.prefix4
),
2146 /* RIP passive interface listing. */
2148 if (passive_default
)
2149 vty_out (vty
, " passive-interface default%s", VTY_NEWLINE
);
2150 for (i
= 0; i
< vector_max (Vrip_passive_nondefault
); i
++)
2151 if ((ifname
= vector_slot (Vrip_passive_nondefault
, i
)) != NULL
)
2152 vty_out (vty
, " %spassive-interface %s%s",
2153 (passive_default
? "no " : ""), ifname
, VTY_NEWLINE
);
2159 struct cmd_node interface_node
=
2166 /* Called when interface structure allocated. */
2168 rip_interface_new_hook (struct interface
*ifp
)
2170 ifp
->info
= rip_interface_new ();
2174 /* Called when interface structure deleted. */
2176 rip_interface_delete_hook (struct interface
*ifp
)
2178 XFREE (MTYPE_RIP_INTERFACE
, ifp
->info
);
2183 /* Allocate and initialize interface vector. */
2187 /* Default initial size of interface vector. */
2189 if_add_hook (IF_NEW_HOOK
, rip_interface_new_hook
);
2190 if_add_hook (IF_DELETE_HOOK
, rip_interface_delete_hook
);
2192 /* RIP network init. */
2193 rip_enable_interface
= vector_init (1);
2194 rip_enable_network
= route_table_init ();
2196 /* RIP passive interface. */
2197 Vrip_passive_nondefault
= vector_init (1);
2199 /* Install interface node. */
2200 install_node (&interface_node
, rip_interface_config_write
);
2202 /* Install commands. */
2203 install_element (CONFIG_NODE
, &interface_cmd
);
2204 install_element (CONFIG_NODE
, &no_interface_cmd
);
2205 install_default (INTERFACE_NODE
);
2206 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
2207 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
2208 install_element (RIP_NODE
, &rip_network_cmd
);
2209 install_element (RIP_NODE
, &no_rip_network_cmd
);
2210 install_element (RIP_NODE
, &rip_neighbor_cmd
);
2211 install_element (RIP_NODE
, &no_rip_neighbor_cmd
);
2213 install_element (RIP_NODE
, &rip_passive_interface_cmd
);
2214 install_element (RIP_NODE
, &no_rip_passive_interface_cmd
);
2216 install_element (INTERFACE_NODE
, &ip_rip_send_version_cmd
);
2217 install_element (INTERFACE_NODE
, &ip_rip_send_version_1_cmd
);
2218 install_element (INTERFACE_NODE
, &ip_rip_send_version_2_cmd
);
2219 install_element (INTERFACE_NODE
, &no_ip_rip_send_version_cmd
);
2220 install_element (INTERFACE_NODE
, &no_ip_rip_send_version_num_cmd
);
2222 install_element (INTERFACE_NODE
, &ip_rip_receive_version_cmd
);
2223 install_element (INTERFACE_NODE
, &ip_rip_receive_version_1_cmd
);
2224 install_element (INTERFACE_NODE
, &ip_rip_receive_version_2_cmd
);
2225 install_element (INTERFACE_NODE
, &no_ip_rip_receive_version_cmd
);
2226 install_element (INTERFACE_NODE
, &no_ip_rip_receive_version_num_cmd
);
2228 install_element (INTERFACE_NODE
, &ip_rip_authentication_mode_cmd
);
2229 install_element (INTERFACE_NODE
, &ip_rip_authentication_mode_authlen_cmd
);
2230 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_cmd
);
2231 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_type_cmd
);
2232 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_type_authlen_cmd
);
2234 install_element (INTERFACE_NODE
, &ip_rip_authentication_key_chain_cmd
);
2235 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_key_chain_cmd
);
2236 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_key_chain2_cmd
);
2238 install_element (INTERFACE_NODE
, &ip_rip_authentication_string_cmd
);
2239 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_string_cmd
);
2240 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_string2_cmd
);
2242 install_element (INTERFACE_NODE
, &ip_rip_split_horizon_cmd
);
2243 install_element (INTERFACE_NODE
, &ip_rip_split_horizon_poisoned_reverse_cmd
);
2244 install_element (INTERFACE_NODE
, &no_ip_rip_split_horizon_cmd
);
2245 install_element (INTERFACE_NODE
, &no_ip_rip_split_horizon_poisoned_reverse_cmd
);