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"
38 #include "zebra/connected.h"
40 #include "ripd/ripd.h"
41 #include "ripd/rip_debug.h"
43 void rip_enable_apply (struct interface
*);
44 void rip_passive_interface_apply (struct interface
*);
45 int rip_if_down(struct interface
*ifp
);
47 struct message ri_version_msg
[] =
49 {RI_RIP_VERSION_1
, "1"},
50 {RI_RIP_VERSION_2
, "2"},
51 {RI_RIP_VERSION_1_AND_2
, "1 2"},
55 /* RIP enabled network vector. */
56 vector rip_enable_interface
;
58 /* RIP enabled interface table. */
59 struct route_table
*rip_enable_network
;
61 /* Vector to store passive-interface name. */
62 vector Vrip_passive_interface
;
64 /* Join to the RIP version 2 multicast group. */
66 ipv4_multicast_join (int sock
,
73 ret
= setsockopt_multicast_ipv4 (sock
,
80 zlog (NULL
, LOG_INFO
, "can't setsockopt IP_ADD_MEMBERSHIP %s",
86 /* Leave from the RIP version 2 multicast group. */
88 ipv4_multicast_leave (int sock
,
95 ret
= setsockopt_multicast_ipv4 (sock
,
102 zlog (NULL
, LOG_INFO
, "can't setsockopt IP_DROP_MEMBERSHIP");
107 /* Allocate new RIP's interface configuration. */
108 struct rip_interface
*
111 struct rip_interface
*ri
;
113 ri
= XMALLOC (MTYPE_RIP_INTERFACE
, sizeof (struct rip_interface
));
114 memset (ri
, 0, sizeof (struct rip_interface
));
116 /* Default authentication type is simple password for Cisco
118 /* ri->auth_type = RIP_NO_AUTH; */
119 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
121 /* Set default split-horizon behavior. If the interface is Frame
122 Relay or SMDS is enabled, the default value for split-horizon is
123 off. But currently Zebra does detect Frame Relay or SMDS
124 interface. So all interface is set to split horizon. */
125 ri
->split_horizon_default
= 1;
126 ri
->split_horizon
= ri
->split_horizon_default
;
132 rip_interface_multicast_set (int sock
, struct interface
*ifp
)
137 struct sockaddr_in from
;
139 for (node
= listhead (ifp
->connected
); node
; nextnode (node
))
141 struct prefix_ipv4
*p
;
142 struct connected
*connected
;
145 connected
= getdata (node
);
146 p
= (struct prefix_ipv4
*) connected
->address
;
148 if (p
->family
== AF_INET
)
152 if (setsockopt_multicast_ipv4 (sock
, IP_MULTICAST_IF
,
153 addr
, 0, ifp
->ifindex
) < 0)
155 zlog_warn ("Can't setsockopt IP_MULTICAST_IF to fd %d", sock
);
160 memset (&from
, 0, sizeof (struct sockaddr_in
));
163 sp
= getservbyname ("router", "udp");
165 from
.sin_port
= sp
->s_port
;
167 from
.sin_port
= htons (RIP_PORT_DEFAULT
);
169 /* Address shoud be any address. */
170 from
.sin_family
= AF_INET
;
171 from
.sin_addr
= addr
;
173 from
.sin_len
= sizeof (struct sockaddr_in
);
174 #endif /* HAVE_SIN_LEN */
176 ret
= bind (sock
, (struct sockaddr
*) & from
,
177 sizeof (struct sockaddr_in
));
180 zlog_warn ("Can't bind socket: %s", strerror (errno
));
190 /* Send RIP request packet to specified interface. */
192 rip_request_interface_send (struct interface
*ifp
, u_char version
)
194 struct sockaddr_in to
;
196 /* RIPv2 support multicast. */
197 if (version
== RIPv2
&& if_is_multicast (ifp
))
200 if (IS_RIP_DEBUG_EVENT
)
201 zlog_info ("multicast request on %s", ifp
->name
);
203 rip_request_send (NULL
, ifp
, version
);
207 /* RIPv1 and non multicast interface. */
208 if (if_is_pointopoint (ifp
) || if_is_broadcast (ifp
))
212 if (IS_RIP_DEBUG_EVENT
)
213 zlog_info ("broadcast request to %s", ifp
->name
);
215 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
217 struct prefix_ipv4
*p
;
218 struct connected
*connected
;
220 connected
= getdata (cnode
);
221 p
= (struct prefix_ipv4
*) connected
->destination
;
223 if (p
->family
== AF_INET
)
225 memset (&to
, 0, sizeof (struct sockaddr_in
));
226 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
227 to
.sin_addr
= p
->prefix
;
230 if (IS_RIP_DEBUG_EVENT
)
231 zlog_info ("SEND request to %s", inet_ntoa (to
.sin_addr
));
234 rip_request_send (&to
, ifp
, version
);
240 /* This will be executed when interface goes up. */
242 rip_request_interface (struct interface
*ifp
)
244 struct rip_interface
*ri
;
246 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
247 if (if_is_loopback (ifp
))
250 /* If interface is down, don't send RIP packet. */
251 if (! if_is_up (ifp
))
254 /* Fetch RIP interface information. */
258 /* If there is no version configuration in the interface,
259 use rip's version setting. */
260 if (ri
->ri_send
== RI_RIP_UNSPEC
)
262 if (rip
->version
== RIPv1
)
263 rip_request_interface_send (ifp
, RIPv1
);
265 rip_request_interface_send (ifp
, RIPv2
);
267 /* If interface has RIP version configuration use it. */
270 if (ri
->ri_send
& RIPv1
)
271 rip_request_interface_send (ifp
, RIPv1
);
272 if (ri
->ri_send
& RIPv2
)
273 rip_request_interface_send (ifp
, RIPv2
);
277 /* Send RIP request to the neighbor. */
279 rip_request_neighbor (struct in_addr addr
)
281 struct sockaddr_in to
;
283 memset (&to
, 0, sizeof (struct sockaddr_in
));
284 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
287 rip_request_send (&to
, NULL
, rip
->version
);
290 /* Request routes at all interfaces. */
292 rip_request_neighbor_all ()
294 struct route_node
*rp
;
299 if (IS_RIP_DEBUG_EVENT
)
300 zlog_info ("request to the all neighbor");
302 /* Send request to all neighbor. */
303 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
305 rip_request_neighbor (rp
->p
.u
.prefix4
);
308 /* Multicast packet receive socket. */
310 rip_multicast_join (struct interface
*ifp
, int sock
)
314 if (if_is_up (ifp
) && if_is_multicast (ifp
))
316 if (IS_RIP_DEBUG_EVENT
)
317 zlog_info ("multicast join at %s", ifp
->name
);
319 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
321 struct prefix_ipv4
*p
;
322 struct connected
*connected
;
323 struct in_addr group
;
325 connected
= getdata (cnode
);
326 p
= (struct prefix_ipv4
*) connected
->address
;
328 if (p
->family
!= AF_INET
)
331 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
332 if (ipv4_multicast_join (sock
, group
, p
->prefix
, ifp
->ifindex
) < 0)
341 /* Leave from multicast group. */
343 rip_multicast_leave (struct interface
*ifp
, int sock
)
347 if (if_is_up (ifp
) && if_is_multicast (ifp
))
349 if (IS_RIP_DEBUG_EVENT
)
350 zlog_info ("multicast leave from %s", ifp
->name
);
352 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
354 struct prefix_ipv4
*p
;
355 struct connected
*connected
;
356 struct in_addr group
;
358 connected
= getdata (cnode
);
359 p
= (struct prefix_ipv4
*) connected
->address
;
361 if (p
->family
!= AF_INET
)
364 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
365 if (ipv4_multicast_leave (sock
, group
, p
->prefix
, ifp
->ifindex
) == 0)
371 /* Is there and address on interface that I could use ? */
373 rip_if_ipv4_address_check (struct interface
*ifp
)
376 struct connected
*connected
;
379 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
380 if ((connected
= getdata (nn
)) != NULL
)
384 p
= connected
->address
;
386 if (p
->family
== AF_INET
)
398 /* Does this address belongs to me ? */
400 if_check_address (struct in_addr addr
)
404 for (node
= listhead (iflist
); node
; nextnode (node
))
407 struct interface
*ifp
;
409 ifp
= getdata (node
);
411 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
413 struct connected
*connected
;
414 struct prefix_ipv4
*p
;
416 connected
= getdata (cnode
);
417 p
= (struct prefix_ipv4
*) connected
->address
;
419 if (p
->family
!= AF_INET
)
422 if (IPV4_ADDR_CMP (&p
->prefix
, &addr
) == 0)
429 /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */
431 if_valid_neighbor (struct in_addr addr
)
434 struct connected
*connected
= NULL
;
435 struct prefix_ipv4
*p
;
437 for (node
= listhead (iflist
); node
; nextnode (node
))
440 struct interface
*ifp
;
442 ifp
= getdata (node
);
444 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
446 struct prefix
*pxn
= NULL
; /* Prefix of the neighbor */
447 struct prefix
*pxc
= NULL
; /* Prefix of the connected network */
449 connected
= getdata (cnode
);
451 if (if_is_pointopoint (ifp
))
453 p
= (struct prefix_ipv4
*) connected
->address
;
455 if (p
&& p
->family
== AF_INET
)
457 if (IPV4_ADDR_SAME (&p
->prefix
, &addr
))
460 p
= (struct prefix_ipv4
*) connected
->destination
;
461 if (p
&& IPV4_ADDR_SAME (&p
->prefix
, &addr
))
467 p
= (struct prefix_ipv4
*) connected
->address
;
469 if (p
->family
!= AF_INET
)
473 pxn
->family
= AF_INET
;
475 pxn
->u
.prefix4
= addr
;
478 prefix_copy(pxc
, (struct prefix
*) p
);
481 if (prefix_match (pxc
, pxn
))
495 /* Inteface link down message processing. */
497 rip_interface_down (int command
, struct zclient
*zclient
, zebra_size_t length
)
499 struct interface
*ifp
;
504 /* zebra_interface_state_read() updates interface structure in
506 ifp
= zebra_interface_state_read(s
);
513 if (IS_RIP_DEBUG_ZEBRA
)
514 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is down",
515 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
520 /* Inteface link up message processing */
522 rip_interface_up (int command
, struct zclient
*zclient
, zebra_size_t length
)
524 struct interface
*ifp
;
526 /* zebra_interface_state_read () updates interface structure in
528 ifp
= zebra_interface_state_read (zclient
->ibuf
);
533 if (IS_RIP_DEBUG_ZEBRA
)
534 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is up",
535 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
537 /* Check if this interface is RIP enabled or not.*/
538 rip_enable_apply (ifp
);
540 /* Check for a passive interface */
541 rip_passive_interface_apply (ifp
);
543 /* Apply distribute list to the all interface. */
544 rip_distribute_update_interface (ifp
);
549 /* Inteface addition message from zebra. */
551 rip_interface_add (int command
, struct zclient
*zclient
, zebra_size_t length
)
553 struct interface
*ifp
;
555 ifp
= zebra_interface_add_read (zclient
->ibuf
);
557 if (IS_RIP_DEBUG_ZEBRA
)
558 zlog_info ("interface add %s index %d flags %ld metric %d mtu %d",
559 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
561 /* Check if this interface is RIP enabled or not.*/
562 rip_enable_apply (ifp
);
564 /* Apply distribute list to the all interface. */
565 rip_distribute_update_interface (ifp
);
567 /* rip_request_neighbor_all (); */
573 rip_interface_delete (int command
, struct zclient
*zclient
,
576 struct interface
*ifp
;
581 /* zebra_interface_state_read() updates interface structure in iflist */
582 ifp
= zebra_interface_state_read(s
);
587 if (if_is_up (ifp
)) {
591 zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
592 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
594 /* To support pseudo interface do not free interface structure. */
595 /* if_delete(ifp); */
601 rip_interface_clean ()
604 struct interface
*ifp
;
605 struct rip_interface
*ri
;
607 for (node
= listhead (iflist
); node
; nextnode (node
))
609 ifp
= getdata (node
);
612 ri
->enable_network
= 0;
613 ri
->enable_interface
= 0;
618 thread_cancel (ri
->t_wakeup
);
625 rip_interface_reset ()
628 struct interface
*ifp
;
629 struct rip_interface
*ri
;
631 for (node
= listhead (iflist
); node
; nextnode (node
))
633 ifp
= getdata (node
);
636 ri
->enable_network
= 0;
637 ri
->enable_interface
= 0;
640 ri
->ri_send
= RI_RIP_UNSPEC
;
641 ri
->ri_receive
= RI_RIP_UNSPEC
;
643 /* ri->auth_type = RIP_NO_AUTH; */
644 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
653 free (ri
->key_chain
);
654 ri
->key_chain
= NULL
;
657 ri
->split_horizon
= 0;
658 ri
->split_horizon_default
= 0;
660 ri
->list
[RIP_FILTER_IN
] = NULL
;
661 ri
->list
[RIP_FILTER_OUT
] = NULL
;
663 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
664 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
668 thread_cancel (ri
->t_wakeup
);
672 ri
->recv_badpackets
= 0;
673 ri
->recv_badroutes
= 0;
674 ri
->sent_updates
= 0;
681 rip_if_down(struct interface
*ifp
)
683 struct route_node
*rp
;
684 struct rip_info
*rinfo
;
685 struct rip_interface
*ri
= NULL
;
688 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
689 if ((rinfo
= rp
->info
) != NULL
)
691 /* Routes got through this interface. */
692 if (rinfo
->ifindex
== ifp
->ifindex
&&
693 rinfo
->type
== ZEBRA_ROUTE_RIP
&&
694 rinfo
->sub_type
== RIP_ROUTE_RTE
)
696 rip_zebra_ipv4_delete ((struct prefix_ipv4
*) &rp
->p
,
700 rip_redistribute_delete (rinfo
->type
,rinfo
->sub_type
,
701 (struct prefix_ipv4
*)&rp
->p
,
706 /* All redistributed routes but static and system */
707 if ((rinfo
->ifindex
== ifp
->ifindex
) &&
708 (rinfo
->type
!= ZEBRA_ROUTE_STATIC
) &&
709 (rinfo
->type
!= ZEBRA_ROUTE_SYSTEM
))
710 rip_redistribute_delete (rinfo
->type
,rinfo
->sub_type
,
711 (struct prefix_ipv4
*)&rp
->p
,
721 if (IS_RIP_DEBUG_EVENT
)
722 zlog_info ("turn off %s", ifp
->name
);
724 /* Leave from multicast group. */
725 rip_multicast_leave (ifp
, rip
->sock
);
733 /* Needed for stop RIP process. */
737 struct interface
*ifp
;
740 for (node
= listhead (iflist
); node
; nextnode (node
))
742 ifp
= getdata (node
);
748 rip_interface_address_add (int command
, struct zclient
*zclient
,
751 struct connected
*ifc
;
754 ifc
= zebra_interface_address_add_read (zclient
->ibuf
);
761 if (p
->family
== AF_INET
)
763 if (IS_RIP_DEBUG_ZEBRA
)
764 zlog_info ("connected address %s/%d is added",
765 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
767 /* Check is this interface is RIP enabled or not.*/
768 rip_enable_apply (ifc
->ifp
);
771 rip_ifaddr_add (ifc
->ifp
, ifc
);
772 #endif /* HAVE_SNMP */
779 rip_interface_address_delete (int command
, struct zclient
*zclient
,
782 struct connected
*ifc
;
785 ifc
= zebra_interface_address_delete_read (zclient
->ibuf
);
790 if (p
->family
== AF_INET
)
792 if (IS_RIP_DEBUG_ZEBRA
)
794 zlog_info ("connected address %s/%d is deleted",
795 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
798 rip_ifaddr_delete (ifc
->ifp
, ifc
);
799 #endif /* HAVE_SNMP */
801 /* Check if this interface is RIP enabled or not.*/
802 rip_enable_apply (ifc
->ifp
);
805 connected_free (ifc
);
812 /* Check interface is enabled by network statement. */
814 rip_enable_network_lookup (struct interface
*ifp
)
817 struct connected
*connected
;
818 struct prefix_ipv4 address
;
820 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
821 if ((connected
= getdata (nn
)) != NULL
)
824 struct route_node
*node
;
826 p
= connected
->address
;
828 if (p
->family
== AF_INET
)
830 address
.family
= AF_INET
;
831 address
.prefix
= p
->u
.prefix4
;
832 address
.prefixlen
= IPV4_MAX_BITLEN
;
834 node
= route_node_match (rip_enable_network
,
835 (struct prefix
*)&address
);
838 route_unlock_node (node
);
846 /* Add RIP enable network. */
848 rip_enable_network_add (struct prefix
*p
)
850 struct route_node
*node
;
852 node
= route_node_get (rip_enable_network
, p
);
856 route_unlock_node (node
);
860 node
->info
= "enabled";
865 /* Delete RIP enable network. */
867 rip_enable_network_delete (struct prefix
*p
)
869 struct route_node
*node
;
871 node
= route_node_lookup (rip_enable_network
, p
);
876 /* Unlock info lock. */
877 route_unlock_node (node
);
879 /* Unlock lookup lock. */
880 route_unlock_node (node
);
887 /* Check interface is enabled by ifname statement. */
889 rip_enable_if_lookup (char *ifname
)
894 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
895 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
896 if (strcmp (str
, ifname
) == 0)
901 /* Add interface to rip_enable_if. */
903 rip_enable_if_add (char *ifname
)
907 ret
= rip_enable_if_lookup (ifname
);
911 vector_set (rip_enable_interface
, strdup (ifname
));
916 /* Delete interface from rip_enable_if. */
918 rip_enable_if_delete (char *ifname
)
923 index
= rip_enable_if_lookup (ifname
);
927 str
= vector_slot (rip_enable_interface
, index
);
929 vector_unset (rip_enable_interface
, index
);
934 /* Join to multicast group and send request to the interface. */
936 rip_interface_wakeup (struct thread
*t
)
938 struct interface
*ifp
;
939 struct rip_interface
*ri
;
942 ifp
= THREAD_ARG (t
);
947 /* Join to multicast group. */
948 if (rip_multicast_join (ifp
, rip
->sock
) < 0)
950 zlog_err ("multicast join failed, interface %s not running", ifp
->name
);
954 /* Set running flag. */
957 /* Send RIP request to the interface. */
958 rip_request_interface (ifp
);
963 int rip_redistribute_check (int);
966 rip_connect_set (struct interface
*ifp
, int set
)
969 struct connected
*connected
;
970 struct prefix_ipv4 address
;
972 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
973 if ((connected
= getdata (nn
)) != NULL
)
976 p
= connected
->address
;
978 if (p
->family
!= AF_INET
)
981 address
.family
= AF_INET
;
982 address
.prefix
= p
->u
.prefix4
;
983 address
.prefixlen
= p
->prefixlen
;
984 apply_mask_ipv4 (&address
);
987 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
988 &address
, connected
->ifp
->ifindex
, NULL
);
991 rip_redistribute_delete (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
992 &address
, connected
->ifp
->ifindex
);
993 if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT
))
994 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_REDISTRIBUTE
,
995 &address
, connected
->ifp
->ifindex
, NULL
);
1000 /* Update interface status. */
1002 rip_enable_apply (struct interface
*ifp
)
1005 struct rip_interface
*ri
= NULL
;
1007 /* Check interface. */
1008 if (if_is_loopback (ifp
))
1011 if (! if_is_up (ifp
))
1016 /* Check network configuration. */
1017 ret
= rip_enable_network_lookup (ifp
);
1019 /* If the interface is matched. */
1021 ri
->enable_network
= 1;
1023 ri
->enable_network
= 0;
1025 /* Check interface name configuration. */
1026 ret
= rip_enable_if_lookup (ifp
->name
);
1028 ri
->enable_interface
= 1;
1030 ri
->enable_interface
= 0;
1032 /* any interface MUST have an IPv4 address */
1033 if ( ! rip_if_ipv4_address_check (ifp
) )
1035 ri
->enable_network
= 0;
1036 ri
->enable_interface
= 0;
1039 /* Update running status of the interface. */
1040 if (ri
->enable_network
|| ri
->enable_interface
)
1044 if (IS_RIP_DEBUG_EVENT
)
1045 zlog_info ("turn on %s", ifp
->name
);
1047 /* Add interface wake up thread. */
1049 ri
->t_wakeup
= thread_add_timer (master
, rip_interface_wakeup
,
1051 rip_connect_set (ifp
, 1);
1058 if (IS_RIP_DEBUG_EVENT
)
1059 zlog_info ("turn off %s", ifp
->name
);
1061 /* Might as well clean up the route table as well */
1065 rip_connect_set (ifp
, 0);
1070 /* Apply network configuration to all interface. */
1072 rip_enable_apply_all ()
1074 struct interface
*ifp
;
1077 /* Check each interface. */
1078 for (node
= listhead (iflist
); node
; nextnode (node
))
1080 ifp
= getdata (node
);
1081 rip_enable_apply (ifp
);
1086 rip_neighbor_lookup (struct sockaddr_in
*from
)
1088 struct prefix_ipv4 p
;
1089 struct route_node
*node
;
1091 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1093 p
.prefix
= from
->sin_addr
;
1094 p
.prefixlen
= IPV4_MAX_BITLEN
;
1096 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) &p
);
1099 route_unlock_node (node
);
1105 /* Add new RIP neighbor to the neighbor tree. */
1107 rip_neighbor_add (struct prefix_ipv4
*p
)
1109 struct route_node
*node
;
1111 node
= route_node_get (rip
->neighbor
, (struct prefix
*) p
);
1116 node
->info
= rip
->neighbor
;
1121 /* Delete RIP neighbor from the neighbor tree. */
1123 rip_neighbor_delete (struct prefix_ipv4
*p
)
1125 struct route_node
*node
;
1127 /* Lock for look up. */
1128 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) p
);
1134 /* Unlock lookup lock. */
1135 route_unlock_node (node
);
1137 /* Unlock real neighbor information lock. */
1138 route_unlock_node (node
);
1143 /* Clear all network and neighbor configuration. */
1145 rip_clean_network ()
1149 struct route_node
*rn
;
1151 /* rip_enable_network. */
1152 for (rn
= route_top (rip_enable_network
); rn
; rn
= route_next (rn
))
1156 route_unlock_node (rn
);
1159 /* rip_enable_interface. */
1160 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
1161 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
1164 vector_slot (rip_enable_interface
, i
) = NULL
;
1168 /* Utility function for looking up passive interface settings. */
1170 rip_passive_interface_lookup (char *ifname
)
1175 for (i
= 0; i
< vector_max (Vrip_passive_interface
); i
++)
1176 if ((str
= vector_slot (Vrip_passive_interface
, i
)) != NULL
)
1177 if (strcmp (str
, ifname
) == 0)
1183 rip_passive_interface_apply (struct interface
*ifp
)
1186 struct rip_interface
*ri
;
1190 ret
= rip_passive_interface_lookup (ifp
->name
);
1198 rip_passive_interface_apply_all ()
1200 struct interface
*ifp
;
1203 for (node
= listhead (iflist
); node
; nextnode (node
))
1205 ifp
= getdata (node
);
1206 rip_passive_interface_apply (ifp
);
1210 /* Passive interface. */
1212 rip_passive_interface_set (struct vty
*vty
, char *ifname
)
1214 if (rip_passive_interface_lookup (ifname
) >= 0)
1217 vector_set (Vrip_passive_interface
, strdup (ifname
));
1219 rip_passive_interface_apply_all ();
1225 rip_passive_interface_unset (struct vty
*vty
, char *ifname
)
1230 i
= rip_passive_interface_lookup (ifname
);
1234 str
= vector_slot (Vrip_passive_interface
, i
);
1236 vector_unset (Vrip_passive_interface
, i
);
1238 rip_passive_interface_apply_all ();
1243 /* Free all configured RIP passive-interface settings. */
1245 rip_passive_interface_clean ()
1250 for (i
= 0; i
< vector_max (Vrip_passive_interface
); i
++)
1251 if ((str
= vector_slot (Vrip_passive_interface
, i
)) != NULL
)
1254 vector_slot (Vrip_passive_interface
, i
) = NULL
;
1256 rip_passive_interface_apply_all ();
1259 /* RIP enable network or interface configuration. */
1262 "network (A.B.C.D/M|WORD)",
1263 "Enable routing on an IP network\n"
1264 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1268 struct prefix_ipv4 p
;
1270 ret
= str2prefix_ipv4 (argv
[0], &p
);
1273 ret
= rip_enable_network_add ((struct prefix
*) &p
);
1275 ret
= rip_enable_if_add (argv
[0]);
1279 vty_out (vty
, "There is a same network configuration %s%s", argv
[0],
1284 rip_enable_apply_all ();
1289 /* RIP enable network or interface configuration. */
1290 DEFUN (no_rip_network
,
1292 "no network (A.B.C.D/M|WORD)",
1294 "Enable routing on an IP network\n"
1295 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1299 struct prefix_ipv4 p
;
1301 ret
= str2prefix_ipv4 (argv
[0], &p
);
1304 ret
= rip_enable_network_delete ((struct prefix
*) &p
);
1306 ret
= rip_enable_if_delete (argv
[0]);
1310 vty_out (vty
, "Can't find network configuration %s%s", argv
[0],
1315 rip_enable_apply_all ();
1320 /* RIP neighbor configuration set. */
1321 DEFUN (rip_neighbor
,
1324 "Specify a neighbor router\n"
1325 "Neighbor address\n")
1328 struct prefix_ipv4 p
;
1330 ret
= str2prefix_ipv4 (argv
[0], &p
);
1334 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1338 rip_neighbor_add (&p
);
1343 /* RIP neighbor configuration unset. */
1344 DEFUN (no_rip_neighbor
,
1345 no_rip_neighbor_cmd
,
1346 "no neighbor A.B.C.D",
1348 "Specify a neighbor router\n"
1349 "Neighbor address\n")
1352 struct prefix_ipv4 p
;
1354 ret
= str2prefix_ipv4 (argv
[0], &p
);
1358 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1362 rip_neighbor_delete (&p
);
1367 DEFUN (ip_rip_receive_version
,
1368 ip_rip_receive_version_cmd
,
1369 "ip rip receive version (1|2)",
1371 "Routing Information Protocol\n"
1372 "Advertisement reception\n"
1377 struct interface
*ifp
;
1378 struct rip_interface
*ri
;
1380 ifp
= (struct interface
*)vty
->index
;
1384 if (atoi (argv
[0]) == 1)
1386 ri
->ri_receive
= RI_RIP_VERSION_1
;
1389 if (atoi (argv
[0]) == 2)
1391 ri
->ri_receive
= RI_RIP_VERSION_2
;
1397 DEFUN (ip_rip_receive_version_1
,
1398 ip_rip_receive_version_1_cmd
,
1399 "ip rip receive version 1 2",
1401 "Routing Information Protocol\n"
1402 "Advertisement reception\n"
1407 struct interface
*ifp
;
1408 struct rip_interface
*ri
;
1410 ifp
= (struct interface
*)vty
->index
;
1413 /* Version 1 and 2. */
1414 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1418 DEFUN (ip_rip_receive_version_2
,
1419 ip_rip_receive_version_2_cmd
,
1420 "ip rip receive version 2 1",
1422 "Routing Information Protocol\n"
1423 "Advertisement reception\n"
1428 struct interface
*ifp
;
1429 struct rip_interface
*ri
;
1431 ifp
= (struct interface
*)vty
->index
;
1434 /* Version 1 and 2. */
1435 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1439 DEFUN (no_ip_rip_receive_version
,
1440 no_ip_rip_receive_version_cmd
,
1441 "no ip rip receive version",
1444 "Routing Information Protocol\n"
1445 "Advertisement reception\n"
1446 "Version control\n")
1448 struct interface
*ifp
;
1449 struct rip_interface
*ri
;
1451 ifp
= (struct interface
*)vty
->index
;
1454 ri
->ri_receive
= RI_RIP_UNSPEC
;
1458 ALIAS (no_ip_rip_receive_version
,
1459 no_ip_rip_receive_version_num_cmd
,
1460 "no ip rip receive version (1|2)",
1463 "Routing Information Protocol\n"
1464 "Advertisement reception\n"
1469 DEFUN (ip_rip_send_version
,
1470 ip_rip_send_version_cmd
,
1471 "ip rip send version (1|2)",
1473 "Routing Information Protocol\n"
1474 "Advertisement transmission\n"
1479 struct interface
*ifp
;
1480 struct rip_interface
*ri
;
1482 ifp
= (struct interface
*)vty
->index
;
1486 if (atoi (argv
[0]) == 1)
1488 ri
->ri_send
= RI_RIP_VERSION_1
;
1491 if (atoi (argv
[0]) == 2)
1493 ri
->ri_send
= RI_RIP_VERSION_2
;
1499 DEFUN (ip_rip_send_version_1
,
1500 ip_rip_send_version_1_cmd
,
1501 "ip rip send version 1 2",
1503 "Routing Information Protocol\n"
1504 "Advertisement transmission\n"
1509 struct interface
*ifp
;
1510 struct rip_interface
*ri
;
1512 ifp
= (struct interface
*)vty
->index
;
1515 /* Version 1 and 2. */
1516 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1520 DEFUN (ip_rip_send_version_2
,
1521 ip_rip_send_version_2_cmd
,
1522 "ip rip send version 2 1",
1524 "Routing Information Protocol\n"
1525 "Advertisement transmission\n"
1530 struct interface
*ifp
;
1531 struct rip_interface
*ri
;
1533 ifp
= (struct interface
*)vty
->index
;
1536 /* Version 1 and 2. */
1537 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1541 DEFUN (no_ip_rip_send_version
,
1542 no_ip_rip_send_version_cmd
,
1543 "no ip rip send version",
1546 "Routing Information Protocol\n"
1547 "Advertisement transmission\n"
1548 "Version control\n")
1550 struct interface
*ifp
;
1551 struct rip_interface
*ri
;
1553 ifp
= (struct interface
*)vty
->index
;
1556 ri
->ri_send
= RI_RIP_UNSPEC
;
1560 ALIAS (no_ip_rip_send_version
,
1561 no_ip_rip_send_version_num_cmd
,
1562 "no ip rip send version (1|2)",
1565 "Routing Information Protocol\n"
1566 "Advertisement transmission\n"
1571 DEFUN (ip_rip_authentication_mode
,
1572 ip_rip_authentication_mode_cmd
,
1573 "ip rip authentication mode (md5|text)",
1575 "Routing Information Protocol\n"
1576 "Authentication control\n"
1577 "Authentication mode\n"
1578 "Keyed message digest\n"
1579 "Clear text authentication\n")
1581 struct interface
*ifp
;
1582 struct rip_interface
*ri
;
1584 ifp
= (struct interface
*)vty
->index
;
1587 if (strncmp ("md5", argv
[0], strlen (argv
[0])) == 0)
1588 ri
->auth_type
= RIP_AUTH_MD5
;
1589 else if (strncmp ("text", argv
[0], strlen (argv
[0])) == 0)
1590 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1593 vty_out (vty
, "mode should be md5 or text%s", VTY_NEWLINE
);
1600 DEFUN (no_ip_rip_authentication_mode
,
1601 no_ip_rip_authentication_mode_cmd
,
1602 "no ip rip authentication mode",
1605 "Routing Information Protocol\n"
1606 "Authentication control\n"
1607 "Authentication mode\n")
1609 struct interface
*ifp
;
1610 struct rip_interface
*ri
;
1612 ifp
= (struct interface
*)vty
->index
;
1615 /* ri->auth_type = RIP_NO_AUTH; */
1616 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1621 ALIAS (no_ip_rip_authentication_mode
,
1622 no_ip_rip_authentication_mode_type_cmd
,
1623 "no ip rip authentication mode (md5|text)",
1626 "Routing Information Protocol\n"
1627 "Authentication control\n"
1628 "Authentication mode\n"
1629 "Keyed message digest\n"
1630 "Clear text authentication\n")
1632 DEFUN (ip_rip_authentication_string
,
1633 ip_rip_authentication_string_cmd
,
1634 "ip rip authentication string LINE",
1636 "Routing Information Protocol\n"
1637 "Authentication control\n"
1638 "Authentication string\n"
1639 "Authentication string\n")
1641 struct interface
*ifp
;
1642 struct rip_interface
*ri
;
1644 ifp
= (struct interface
*)vty
->index
;
1647 if (strlen (argv
[0]) > 16)
1649 vty_out (vty
, "%% RIPv2 authentication string must be shorter than 16%s",
1656 vty_out (vty
, "%% key-chain configuration exists%s", VTY_NEWLINE
);
1661 free (ri
->auth_str
);
1663 ri
->auth_str
= strdup (argv
[0]);
1668 DEFUN (no_ip_rip_authentication_string
,
1669 no_ip_rip_authentication_string_cmd
,
1670 "no ip rip authentication string",
1673 "Routing Information Protocol\n"
1674 "Authentication control\n"
1675 "Authentication string\n")
1677 struct interface
*ifp
;
1678 struct rip_interface
*ri
;
1680 ifp
= (struct interface
*)vty
->index
;
1684 free (ri
->auth_str
);
1686 ri
->auth_str
= NULL
;
1691 ALIAS (no_ip_rip_authentication_string
,
1692 no_ip_rip_authentication_string2_cmd
,
1693 "no ip rip authentication string LINE",
1696 "Routing Information Protocol\n"
1697 "Authentication control\n"
1698 "Authentication string\n"
1699 "Authentication string\n")
1701 DEFUN (ip_rip_authentication_key_chain
,
1702 ip_rip_authentication_key_chain_cmd
,
1703 "ip rip authentication key-chain LINE",
1705 "Routing Information Protocol\n"
1706 "Authentication control\n"
1707 "Authentication key-chain\n"
1708 "name of key-chain\n")
1710 struct interface
*ifp
;
1711 struct rip_interface
*ri
;
1713 ifp
= (struct interface
*) vty
->index
;
1718 vty_out (vty
, "%% authentication string configuration exists%s",
1724 free (ri
->key_chain
);
1726 ri
->key_chain
= strdup (argv
[0]);
1731 DEFUN (no_ip_rip_authentication_key_chain
,
1732 no_ip_rip_authentication_key_chain_cmd
,
1733 "no ip rip authentication key-chain",
1736 "Routing Information Protocol\n"
1737 "Authentication control\n"
1738 "Authentication key-chain\n")
1740 struct interface
*ifp
;
1741 struct rip_interface
*ri
;
1743 ifp
= (struct interface
*) vty
->index
;
1747 free (ri
->key_chain
);
1749 ri
->key_chain
= NULL
;
1754 ALIAS (no_ip_rip_authentication_key_chain
,
1755 no_ip_rip_authentication_key_chain2_cmd
,
1756 "no ip rip authentication key-chain LINE",
1759 "Routing Information Protocol\n"
1760 "Authentication control\n"
1761 "Authentication key-chain\n"
1762 "name of key-chain\n")
1764 DEFUN (rip_split_horizon
,
1765 rip_split_horizon_cmd
,
1768 "Perform split horizon\n")
1770 struct interface
*ifp
;
1771 struct rip_interface
*ri
;
1776 ri
->split_horizon
= 1;
1780 DEFUN (no_rip_split_horizon
,
1781 no_rip_split_horizon_cmd
,
1782 "no ip split-horizon",
1785 "Perform split horizon\n")
1787 struct interface
*ifp
;
1788 struct rip_interface
*ri
;
1793 ri
->split_horizon
= 0;
1797 DEFUN (rip_passive_interface
,
1798 rip_passive_interface_cmd
,
1799 "passive-interface IFNAME",
1800 "Suppress routing updates on an interface\n"
1803 return rip_passive_interface_set (vty
, argv
[0]);
1806 DEFUN (no_rip_passive_interface
,
1807 no_rip_passive_interface_cmd
,
1808 "no passive-interface IFNAME",
1810 "Suppress routing updates on an interface\n"
1813 return rip_passive_interface_unset (vty
, argv
[0]);
1816 /* Write rip configuration of each interface. */
1818 rip_interface_config_write (struct vty
*vty
)
1821 struct interface
*ifp
;
1823 for (node
= listhead (iflist
); node
; nextnode (node
))
1825 struct rip_interface
*ri
;
1827 ifp
= getdata (node
);
1830 vty_out (vty
, "interface %s%s", ifp
->name
,
1834 vty_out (vty
, " description %s%s", ifp
->desc
,
1837 /* Split horizon. */
1838 if (ri
->split_horizon
!= ri
->split_horizon_default
)
1840 if (ri
->split_horizon
)
1841 vty_out (vty
, " ip split-horizon%s", VTY_NEWLINE
);
1843 vty_out (vty
, " no ip split-horizon%s", VTY_NEWLINE
);
1846 /* RIP version setting. */
1847 if (ri
->ri_send
!= RI_RIP_UNSPEC
)
1848 vty_out (vty
, " ip rip send version %s%s",
1849 lookup (ri_version_msg
, ri
->ri_send
),
1852 if (ri
->ri_receive
!= RI_RIP_UNSPEC
)
1853 vty_out (vty
, " ip rip receive version %s%s",
1854 lookup (ri_version_msg
, ri
->ri_receive
),
1857 /* RIP authentication. */
1859 /* RIP_AUTH_SIMPLE_PASSWORD becomes default mode. */
1860 if (ri
->auth_type
== RIP_AUTH_SIMPLE_PASSWORD
)
1861 vty_out (vty
, " ip rip authentication mode text%s", VTY_NEWLINE
);
1863 if (ri
->auth_type
== RIP_AUTH_MD5
)
1864 vty_out (vty
, " ip rip authentication mode md5%s", VTY_NEWLINE
);
1867 vty_out (vty
, " ip rip authentication string %s%s",
1868 ri
->auth_str
, VTY_NEWLINE
);
1871 vty_out (vty
, " ip rip authentication key-chain %s%s",
1872 ri
->key_chain
, VTY_NEWLINE
);
1874 vty_out (vty
, "!%s", VTY_NEWLINE
);
1880 config_write_rip_network (struct vty
*vty
, int config_mode
)
1884 struct route_node
*node
;
1886 /* Network type RIP enable interface statement. */
1887 for (node
= route_top (rip_enable_network
); node
; node
= route_next (node
))
1889 vty_out (vty
, "%s%s/%d%s",
1890 config_mode
? " network " : " ",
1891 inet_ntoa (node
->p
.u
.prefix4
),
1895 /* Interface name RIP enable statement. */
1896 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
1897 if ((ifname
= vector_slot (rip_enable_interface
, i
)) != NULL
)
1898 vty_out (vty
, "%s%s%s",
1899 config_mode
? " network " : " ",
1903 /* RIP neighbors listing. */
1904 for (node
= route_top (rip
->neighbor
); node
; node
= route_next (node
))
1906 vty_out (vty
, "%s%s%s",
1907 config_mode
? " neighbor " : " ",
1908 inet_ntoa (node
->p
.u
.prefix4
),
1911 /* RIP passive interface listing. */
1913 for (i
= 0; i
< vector_max (Vrip_passive_interface
); i
++)
1914 if ((ifname
= vector_slot (Vrip_passive_interface
, i
)) != NULL
)
1915 vty_out (vty
, " passive-interface %s%s", ifname
, VTY_NEWLINE
);
1920 struct cmd_node interface_node
=
1927 /* Called when interface structure allocated. */
1929 rip_interface_new_hook (struct interface
*ifp
)
1931 ifp
->info
= rip_interface_new ();
1935 /* Called when interface structure deleted. */
1937 rip_interface_delete_hook (struct interface
*ifp
)
1939 XFREE (MTYPE_RIP_INTERFACE
, ifp
->info
);
1943 /* Allocate and initialize interface vector. */
1947 /* Default initial size of interface vector. */
1949 if_add_hook (IF_NEW_HOOK
, rip_interface_new_hook
);
1950 if_add_hook (IF_DELETE_HOOK
, rip_interface_delete_hook
);
1952 /* RIP network init. */
1953 rip_enable_interface
= vector_init (1);
1954 rip_enable_network
= route_table_init ();
1956 /* RIP passive interface. */
1957 Vrip_passive_interface
= vector_init (1);
1959 /* Install interface node. */
1960 install_node (&interface_node
, rip_interface_config_write
);
1962 /* Install commands. */
1963 install_element (CONFIG_NODE
, &interface_cmd
);
1964 install_default (INTERFACE_NODE
);
1965 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
1966 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
1967 install_element (RIP_NODE
, &rip_network_cmd
);
1968 install_element (RIP_NODE
, &no_rip_network_cmd
);
1969 install_element (RIP_NODE
, &rip_neighbor_cmd
);
1970 install_element (RIP_NODE
, &no_rip_neighbor_cmd
);
1972 install_element (RIP_NODE
, &rip_passive_interface_cmd
);
1973 install_element (RIP_NODE
, &no_rip_passive_interface_cmd
);
1975 install_element (INTERFACE_NODE
, &ip_rip_send_version_cmd
);
1976 install_element (INTERFACE_NODE
, &ip_rip_send_version_1_cmd
);
1977 install_element (INTERFACE_NODE
, &ip_rip_send_version_2_cmd
);
1978 install_element (INTERFACE_NODE
, &no_ip_rip_send_version_cmd
);
1979 install_element (INTERFACE_NODE
, &no_ip_rip_send_version_num_cmd
);
1981 install_element (INTERFACE_NODE
, &ip_rip_receive_version_cmd
);
1982 install_element (INTERFACE_NODE
, &ip_rip_receive_version_1_cmd
);
1983 install_element (INTERFACE_NODE
, &ip_rip_receive_version_2_cmd
);
1984 install_element (INTERFACE_NODE
, &no_ip_rip_receive_version_cmd
);
1985 install_element (INTERFACE_NODE
, &no_ip_rip_receive_version_num_cmd
);
1987 install_element (INTERFACE_NODE
, &ip_rip_authentication_mode_cmd
);
1988 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_cmd
);
1989 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_mode_type_cmd
);
1991 install_element (INTERFACE_NODE
, &ip_rip_authentication_key_chain_cmd
);
1992 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_key_chain_cmd
);
1993 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_key_chain2_cmd
);
1995 install_element (INTERFACE_NODE
, &ip_rip_authentication_string_cmd
);
1996 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_string_cmd
);
1997 install_element (INTERFACE_NODE
, &no_ip_rip_authentication_string2_cmd
);
1999 install_element (INTERFACE_NODE
, &rip_split_horizon_cmd
);
2000 install_element (INTERFACE_NODE
, &no_rip_split_horizon_cmd
);