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
;
229 rip_request_send (&to
, ifp
, version
);
235 /* This will be executed when interface goes up. */
237 rip_request_interface (struct interface
*ifp
)
239 struct rip_interface
*ri
;
241 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
242 if (if_is_loopback (ifp
))
245 /* If interface is down, don't send RIP packet. */
246 if (! if_is_up (ifp
))
249 /* Fetch RIP interface information. */
253 /* If there is no version configuration in the interface,
254 use rip's version setting. */
255 if (ri
->ri_send
== RI_RIP_UNSPEC
)
257 if (rip
->version
== RIPv1
)
258 rip_request_interface_send (ifp
, RIPv1
);
260 rip_request_interface_send (ifp
, RIPv2
);
262 /* If interface has RIP version configuration use it. */
265 if (ri
->ri_send
& RIPv1
)
266 rip_request_interface_send (ifp
, RIPv1
);
267 if (ri
->ri_send
& RIPv2
)
268 rip_request_interface_send (ifp
, RIPv2
);
272 /* Send RIP request to the neighbor. */
274 rip_request_neighbor (struct in_addr addr
)
276 struct sockaddr_in to
;
278 memset (&to
, 0, sizeof (struct sockaddr_in
));
279 to
.sin_port
= htons (RIP_PORT_DEFAULT
);
282 rip_request_send (&to
, NULL
, rip
->version
);
285 /* Request routes at all interfaces. */
287 rip_request_neighbor_all ()
289 struct route_node
*rp
;
294 if (IS_RIP_DEBUG_EVENT
)
295 zlog_info ("request to the all neighbor");
297 /* Send request to all neighbor. */
298 for (rp
= route_top (rip
->neighbor
); rp
; rp
= route_next (rp
))
300 rip_request_neighbor (rp
->p
.u
.prefix4
);
303 /* Multicast packet receive socket. */
305 rip_multicast_join (struct interface
*ifp
, int sock
)
307 struct rip_interface
*ri
;
312 if (if_is_up (ifp
) && if_is_multicast (ifp
))
314 if (IS_RIP_DEBUG_EVENT
)
315 zlog_info ("multicast join at %s", ifp
->name
);
317 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
319 struct prefix_ipv4
*p
;
320 struct connected
*connected
;
321 struct in_addr group
;
323 connected
= getdata (cnode
);
324 p
= (struct prefix_ipv4
*) connected
->address
;
326 if (p
->family
!= AF_INET
)
329 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
330 if (ipv4_multicast_join (sock
, group
, p
->prefix
, ifp
->ifindex
) < 0)
334 ri
->joined_multicast
= 1;
342 /* Leave from multicast group. */
344 rip_multicast_leave (struct interface
*ifp
, int sock
)
346 struct rip_interface
*ri
;
351 if (ri
->joined_multicast
)
353 ri
->joined_multicast
= 0;
354 if (IS_RIP_DEBUG_EVENT
)
355 zlog_info ("multicast leave from %s", ifp
->name
);
357 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
359 struct prefix_ipv4
*p
;
360 struct connected
*connected
;
361 struct in_addr group
;
363 connected
= getdata (cnode
);
364 p
= (struct prefix_ipv4
*) connected
->address
;
366 if (p
->family
!= AF_INET
)
369 group
.s_addr
= htonl (INADDR_RIP_GROUP
);
370 if (ipv4_multicast_leave (sock
, group
, p
->prefix
, ifp
->ifindex
) == 0)
376 /* Is there and address on interface that I could use ? */
378 rip_if_ipv4_address_check (struct interface
*ifp
)
381 struct connected
*connected
;
384 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
385 if ((connected
= getdata (nn
)) != NULL
)
389 p
= connected
->address
;
391 if (p
->family
== AF_INET
)
403 /* Does this address belongs to me ? */
405 if_check_address (struct in_addr addr
)
409 for (node
= listhead (iflist
); node
; nextnode (node
))
412 struct interface
*ifp
;
414 ifp
= getdata (node
);
416 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
418 struct connected
*connected
;
419 struct prefix_ipv4
*p
;
421 connected
= getdata (cnode
);
422 p
= (struct prefix_ipv4
*) connected
->address
;
424 if (p
->family
!= AF_INET
)
427 if (IPV4_ADDR_CMP (&p
->prefix
, &addr
) == 0)
434 /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */
436 if_valid_neighbor (struct in_addr addr
)
439 struct connected
*connected
= NULL
;
440 struct prefix_ipv4
*p
;
442 for (node
= listhead (iflist
); node
; nextnode (node
))
445 struct interface
*ifp
;
447 ifp
= getdata (node
);
449 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
451 struct prefix
*pxn
= NULL
; /* Prefix of the neighbor */
452 struct prefix
*pxc
= NULL
; /* Prefix of the connected network */
454 connected
= getdata (cnode
);
456 if (if_is_pointopoint (ifp
))
458 p
= (struct prefix_ipv4
*) connected
->address
;
460 if (p
&& p
->family
== AF_INET
)
462 if (IPV4_ADDR_SAME (&p
->prefix
, &addr
))
465 p
= (struct prefix_ipv4
*) connected
->destination
;
466 if (p
&& IPV4_ADDR_SAME (&p
->prefix
, &addr
))
472 p
= (struct prefix_ipv4
*) connected
->address
;
474 if (p
->family
!= AF_INET
)
478 pxn
->family
= AF_INET
;
480 pxn
->u
.prefix4
= addr
;
483 prefix_copy(pxc
, (struct prefix
*) p
);
486 if (prefix_match (pxc
, pxn
))
500 /* Inteface link down message processing. */
502 rip_interface_down (int command
, struct zclient
*zclient
, zebra_size_t length
)
504 struct interface
*ifp
;
509 /* zebra_interface_state_read() updates interface structure in
511 ifp
= zebra_interface_state_read(s
);
518 if (IS_RIP_DEBUG_ZEBRA
)
519 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is down",
520 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
525 /* Inteface link up message processing */
527 rip_interface_up (int command
, struct zclient
*zclient
, zebra_size_t length
)
529 struct interface
*ifp
;
531 /* zebra_interface_state_read () updates interface structure in
533 ifp
= zebra_interface_state_read (zclient
->ibuf
);
538 if (IS_RIP_DEBUG_ZEBRA
)
539 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is up",
540 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
542 /* Check if this interface is RIP enabled or not.*/
543 rip_enable_apply (ifp
);
545 /* Check for a passive interface */
546 rip_passive_interface_apply (ifp
);
548 /* Apply distribute list to the all interface. */
549 rip_distribute_update_interface (ifp
);
554 /* Inteface addition message from zebra. */
556 rip_interface_add (int command
, struct zclient
*zclient
, zebra_size_t length
)
558 struct interface
*ifp
;
560 ifp
= zebra_interface_add_read (zclient
->ibuf
);
562 if (IS_RIP_DEBUG_ZEBRA
)
563 zlog_info ("interface add %s index %d flags %ld metric %d mtu %d",
564 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
566 /* Check if this interface is RIP enabled or not.*/
567 rip_enable_apply (ifp
);
569 /* Apply distribute list to the all interface. */
570 rip_distribute_update_interface (ifp
);
572 /* rip_request_neighbor_all (); */
578 rip_interface_delete (int command
, struct zclient
*zclient
,
581 struct interface
*ifp
;
586 /* zebra_interface_state_read() updates interface structure in iflist */
587 ifp
= zebra_interface_state_read(s
);
592 if (if_is_up (ifp
)) {
596 zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
597 ifp
->name
, ifp
->ifindex
, ifp
->flags
, ifp
->metric
, ifp
->mtu
);
599 /* To support pseudo interface do not free interface structure. */
600 /* if_delete(ifp); */
606 rip_interface_clean ()
609 struct interface
*ifp
;
610 struct rip_interface
*ri
;
612 for (node
= listhead (iflist
); node
; nextnode (node
))
614 ifp
= getdata (node
);
617 ri
->enable_network
= 0;
618 ri
->enable_interface
= 0;
623 thread_cancel (ri
->t_wakeup
);
630 rip_interface_reset ()
633 struct interface
*ifp
;
634 struct rip_interface
*ri
;
636 for (node
= listhead (iflist
); node
; nextnode (node
))
638 ifp
= getdata (node
);
641 ri
->enable_network
= 0;
642 ri
->enable_interface
= 0;
645 ri
->ri_send
= RI_RIP_UNSPEC
;
646 ri
->ri_receive
= RI_RIP_UNSPEC
;
648 /* ri->auth_type = RIP_NO_AUTH; */
649 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
658 free (ri
->key_chain
);
659 ri
->key_chain
= NULL
;
662 ri
->split_horizon
= 0;
663 ri
->split_horizon_default
= 0;
665 ri
->list
[RIP_FILTER_IN
] = NULL
;
666 ri
->list
[RIP_FILTER_OUT
] = NULL
;
668 ri
->prefix
[RIP_FILTER_IN
] = NULL
;
669 ri
->prefix
[RIP_FILTER_OUT
] = NULL
;
673 thread_cancel (ri
->t_wakeup
);
677 ri
->recv_badpackets
= 0;
678 ri
->recv_badroutes
= 0;
679 ri
->sent_updates
= 0;
686 rip_if_down(struct interface
*ifp
)
688 struct route_node
*rp
;
689 struct rip_info
*rinfo
;
690 struct rip_interface
*ri
= NULL
;
693 for (rp
= route_top (rip
->table
); rp
; rp
= route_next (rp
))
694 if ((rinfo
= rp
->info
) != NULL
)
696 /* Routes got through this interface. */
697 if (rinfo
->ifindex
== ifp
->ifindex
&&
698 rinfo
->type
== ZEBRA_ROUTE_RIP
&&
699 rinfo
->sub_type
== RIP_ROUTE_RTE
)
701 rip_zebra_ipv4_delete ((struct prefix_ipv4
*) &rp
->p
,
705 rip_redistribute_delete (rinfo
->type
,rinfo
->sub_type
,
706 (struct prefix_ipv4
*)&rp
->p
,
711 /* All redistributed routes but static and system */
712 if ((rinfo
->ifindex
== ifp
->ifindex
) &&
713 (rinfo
->type
!= ZEBRA_ROUTE_STATIC
) &&
714 (rinfo
->type
!= ZEBRA_ROUTE_SYSTEM
))
715 rip_redistribute_delete (rinfo
->type
,rinfo
->sub_type
,
716 (struct prefix_ipv4
*)&rp
->p
,
726 if (IS_RIP_DEBUG_EVENT
)
727 zlog_info ("turn off %s", ifp
->name
);
729 /* Leave from multicast group. */
730 rip_multicast_leave (ifp
, rip
->sock
);
738 /* Needed for stop RIP process. */
742 struct interface
*ifp
;
745 for (node
= listhead (iflist
); node
; nextnode (node
))
747 ifp
= getdata (node
);
753 rip_interface_address_add (int command
, struct zclient
*zclient
,
756 struct connected
*ifc
;
759 ifc
= zebra_interface_address_add_read (zclient
->ibuf
);
766 if (p
->family
== AF_INET
)
768 if (IS_RIP_DEBUG_ZEBRA
)
769 zlog_info ("connected address %s/%d is added",
770 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
772 /* Check is this interface is RIP enabled or not.*/
773 rip_enable_apply (ifc
->ifp
);
776 rip_ifaddr_add (ifc
->ifp
, ifc
);
777 #endif /* HAVE_SNMP */
784 rip_interface_address_delete (int command
, struct zclient
*zclient
,
787 struct connected
*ifc
;
790 ifc
= zebra_interface_address_delete_read (zclient
->ibuf
);
795 if (p
->family
== AF_INET
)
797 if (IS_RIP_DEBUG_ZEBRA
)
799 zlog_info ("connected address %s/%d is deleted",
800 inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
803 rip_ifaddr_delete (ifc
->ifp
, ifc
);
804 #endif /* HAVE_SNMP */
806 /* Check if this interface is RIP enabled or not.*/
807 rip_enable_apply (ifc
->ifp
);
810 connected_free (ifc
);
817 /* Check interface is enabled by network statement. */
819 rip_enable_network_lookup (struct interface
*ifp
)
822 struct connected
*connected
;
823 struct prefix_ipv4 address
;
825 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
826 if ((connected
= getdata (nn
)) != NULL
)
829 struct route_node
*node
;
831 p
= connected
->address
;
833 if (p
->family
== AF_INET
)
835 address
.family
= AF_INET
;
836 address
.prefix
= p
->u
.prefix4
;
837 address
.prefixlen
= IPV4_MAX_BITLEN
;
839 node
= route_node_match (rip_enable_network
,
840 (struct prefix
*)&address
);
843 route_unlock_node (node
);
851 /* Add RIP enable network. */
853 rip_enable_network_add (struct prefix
*p
)
855 struct route_node
*node
;
857 node
= route_node_get (rip_enable_network
, p
);
861 route_unlock_node (node
);
865 node
->info
= "enabled";
870 /* Delete RIP enable network. */
872 rip_enable_network_delete (struct prefix
*p
)
874 struct route_node
*node
;
876 node
= route_node_lookup (rip_enable_network
, p
);
881 /* Unlock info lock. */
882 route_unlock_node (node
);
884 /* Unlock lookup lock. */
885 route_unlock_node (node
);
892 /* Check interface is enabled by ifname statement. */
894 rip_enable_if_lookup (char *ifname
)
899 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
900 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
901 if (strcmp (str
, ifname
) == 0)
906 /* Add interface to rip_enable_if. */
908 rip_enable_if_add (char *ifname
)
912 ret
= rip_enable_if_lookup (ifname
);
916 vector_set (rip_enable_interface
, strdup (ifname
));
921 /* Delete interface from rip_enable_if. */
923 rip_enable_if_delete (char *ifname
)
928 index
= rip_enable_if_lookup (ifname
);
932 str
= vector_slot (rip_enable_interface
, index
);
934 vector_unset (rip_enable_interface
, index
);
939 /* Join to multicast group and send request to the interface. */
941 rip_interface_wakeup (struct thread
*t
)
943 struct interface
*ifp
;
944 struct rip_interface
*ri
;
947 ifp
= THREAD_ARG (t
);
952 /* Join to multicast group. */
953 if (rip_multicast_join (ifp
, rip
->sock
) < 0)
955 zlog_err ("multicast join failed, interface %s not running", ifp
->name
);
959 /* Set running flag. */
962 /* Send RIP request to the interface. */
963 rip_request_interface (ifp
);
968 int rip_redistribute_check (int);
971 rip_connect_set (struct interface
*ifp
, int set
)
974 struct connected
*connected
;
975 struct prefix_ipv4 address
;
977 for (nn
= listhead (ifp
->connected
); nn
; nextnode (nn
))
978 if ((connected
= getdata (nn
)) != NULL
)
981 p
= connected
->address
;
983 if (p
->family
!= AF_INET
)
986 address
.family
= AF_INET
;
987 address
.prefix
= p
->u
.prefix4
;
988 address
.prefixlen
= p
->prefixlen
;
989 apply_mask_ipv4 (&address
);
992 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
993 &address
, connected
->ifp
->ifindex
, NULL
);
996 rip_redistribute_delete (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_INTERFACE
,
997 &address
, connected
->ifp
->ifindex
);
998 if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT
))
999 rip_redistribute_add (ZEBRA_ROUTE_CONNECT
, RIP_ROUTE_REDISTRIBUTE
,
1000 &address
, connected
->ifp
->ifindex
, NULL
);
1005 /* Update interface status. */
1007 rip_enable_apply (struct interface
*ifp
)
1010 struct rip_interface
*ri
= NULL
;
1012 /* Check interface. */
1013 if (if_is_loopback (ifp
))
1016 if (! if_is_up (ifp
))
1021 /* Check network configuration. */
1022 ret
= rip_enable_network_lookup (ifp
);
1024 /* If the interface is matched. */
1026 ri
->enable_network
= 1;
1028 ri
->enable_network
= 0;
1030 /* Check interface name configuration. */
1031 ret
= rip_enable_if_lookup (ifp
->name
);
1033 ri
->enable_interface
= 1;
1035 ri
->enable_interface
= 0;
1037 /* any interface MUST have an IPv4 address */
1038 if ( ! rip_if_ipv4_address_check (ifp
) )
1040 ri
->enable_network
= 0;
1041 ri
->enable_interface
= 0;
1044 /* Update running status of the interface. */
1045 if (ri
->enable_network
|| ri
->enable_interface
)
1049 if (IS_RIP_DEBUG_EVENT
)
1050 zlog_info ("turn on %s", ifp
->name
);
1052 /* Add interface wake up thread. */
1054 ri
->t_wakeup
= thread_add_timer (master
, rip_interface_wakeup
,
1056 rip_connect_set (ifp
, 1);
1063 if (IS_RIP_DEBUG_EVENT
)
1064 zlog_info ("turn off %s", ifp
->name
);
1066 /* Might as well clean up the route table as well */
1070 rip_connect_set (ifp
, 0);
1075 /* Apply network configuration to all interface. */
1077 rip_enable_apply_all ()
1079 struct interface
*ifp
;
1082 /* Check each interface. */
1083 for (node
= listhead (iflist
); node
; nextnode (node
))
1085 ifp
= getdata (node
);
1086 rip_enable_apply (ifp
);
1091 rip_neighbor_lookup (struct sockaddr_in
*from
)
1093 struct prefix_ipv4 p
;
1094 struct route_node
*node
;
1096 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1098 p
.prefix
= from
->sin_addr
;
1099 p
.prefixlen
= IPV4_MAX_BITLEN
;
1101 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) &p
);
1104 route_unlock_node (node
);
1110 /* Add new RIP neighbor to the neighbor tree. */
1112 rip_neighbor_add (struct prefix_ipv4
*p
)
1114 struct route_node
*node
;
1116 node
= route_node_get (rip
->neighbor
, (struct prefix
*) p
);
1121 node
->info
= rip
->neighbor
;
1126 /* Delete RIP neighbor from the neighbor tree. */
1128 rip_neighbor_delete (struct prefix_ipv4
*p
)
1130 struct route_node
*node
;
1132 /* Lock for look up. */
1133 node
= route_node_lookup (rip
->neighbor
, (struct prefix
*) p
);
1139 /* Unlock lookup lock. */
1140 route_unlock_node (node
);
1142 /* Unlock real neighbor information lock. */
1143 route_unlock_node (node
);
1148 /* Clear all network and neighbor configuration. */
1150 rip_clean_network ()
1154 struct route_node
*rn
;
1156 /* rip_enable_network. */
1157 for (rn
= route_top (rip_enable_network
); rn
; rn
= route_next (rn
))
1161 route_unlock_node (rn
);
1164 /* rip_enable_interface. */
1165 for (i
= 0; i
< vector_max (rip_enable_interface
); i
++)
1166 if ((str
= vector_slot (rip_enable_interface
, i
)) != NULL
)
1169 vector_slot (rip_enable_interface
, i
) = NULL
;
1173 /* Utility function for looking up passive interface settings. */
1175 rip_passive_interface_lookup (char *ifname
)
1180 for (i
= 0; i
< vector_max (Vrip_passive_interface
); i
++)
1181 if ((str
= vector_slot (Vrip_passive_interface
, i
)) != NULL
)
1182 if (strcmp (str
, ifname
) == 0)
1188 rip_passive_interface_apply (struct interface
*ifp
)
1191 struct rip_interface
*ri
;
1195 ret
= rip_passive_interface_lookup (ifp
->name
);
1203 rip_passive_interface_apply_all ()
1205 struct interface
*ifp
;
1208 for (node
= listhead (iflist
); node
; nextnode (node
))
1210 ifp
= getdata (node
);
1211 rip_passive_interface_apply (ifp
);
1215 /* Passive interface. */
1217 rip_passive_interface_set (struct vty
*vty
, char *ifname
)
1219 if (rip_passive_interface_lookup (ifname
) >= 0)
1222 vector_set (Vrip_passive_interface
, strdup (ifname
));
1224 rip_passive_interface_apply_all ();
1230 rip_passive_interface_unset (struct vty
*vty
, char *ifname
)
1235 i
= rip_passive_interface_lookup (ifname
);
1239 str
= vector_slot (Vrip_passive_interface
, i
);
1241 vector_unset (Vrip_passive_interface
, i
);
1243 rip_passive_interface_apply_all ();
1248 /* Free all configured RIP passive-interface settings. */
1250 rip_passive_interface_clean ()
1255 for (i
= 0; i
< vector_max (Vrip_passive_interface
); i
++)
1256 if ((str
= vector_slot (Vrip_passive_interface
, i
)) != NULL
)
1259 vector_slot (Vrip_passive_interface
, i
) = NULL
;
1261 rip_passive_interface_apply_all ();
1264 /* RIP enable network or interface configuration. */
1267 "network (A.B.C.D/M|WORD)",
1268 "Enable routing on an IP network\n"
1269 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1273 struct prefix_ipv4 p
;
1275 ret
= str2prefix_ipv4 (argv
[0], &p
);
1278 ret
= rip_enable_network_add ((struct prefix
*) &p
);
1280 ret
= rip_enable_if_add (argv
[0]);
1284 vty_out (vty
, "There is a same network configuration %s%s", argv
[0],
1289 rip_enable_apply_all ();
1294 /* RIP enable network or interface configuration. */
1295 DEFUN (no_rip_network
,
1297 "no network (A.B.C.D/M|WORD)",
1299 "Enable routing on an IP network\n"
1300 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1304 struct prefix_ipv4 p
;
1306 ret
= str2prefix_ipv4 (argv
[0], &p
);
1309 ret
= rip_enable_network_delete ((struct prefix
*) &p
);
1311 ret
= rip_enable_if_delete (argv
[0]);
1315 vty_out (vty
, "Can't find network configuration %s%s", argv
[0],
1320 rip_enable_apply_all ();
1325 /* RIP neighbor configuration set. */
1326 DEFUN (rip_neighbor
,
1329 "Specify a neighbor router\n"
1330 "Neighbor address\n")
1333 struct prefix_ipv4 p
;
1335 ret
= str2prefix_ipv4 (argv
[0], &p
);
1339 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1343 rip_neighbor_add (&p
);
1348 /* RIP neighbor configuration unset. */
1349 DEFUN (no_rip_neighbor
,
1350 no_rip_neighbor_cmd
,
1351 "no neighbor A.B.C.D",
1353 "Specify a neighbor router\n"
1354 "Neighbor address\n")
1357 struct prefix_ipv4 p
;
1359 ret
= str2prefix_ipv4 (argv
[0], &p
);
1363 vty_out (vty
, "Please specify address by A.B.C.D%s", VTY_NEWLINE
);
1367 rip_neighbor_delete (&p
);
1372 DEFUN (ip_rip_receive_version
,
1373 ip_rip_receive_version_cmd
,
1374 "ip rip receive version (1|2)",
1376 "Routing Information Protocol\n"
1377 "Advertisement reception\n"
1382 struct interface
*ifp
;
1383 struct rip_interface
*ri
;
1385 ifp
= (struct interface
*)vty
->index
;
1389 if (atoi (argv
[0]) == 1)
1391 ri
->ri_receive
= RI_RIP_VERSION_1
;
1394 if (atoi (argv
[0]) == 2)
1396 ri
->ri_receive
= RI_RIP_VERSION_2
;
1402 DEFUN (ip_rip_receive_version_1
,
1403 ip_rip_receive_version_1_cmd
,
1404 "ip rip receive version 1 2",
1406 "Routing Information Protocol\n"
1407 "Advertisement reception\n"
1412 struct interface
*ifp
;
1413 struct rip_interface
*ri
;
1415 ifp
= (struct interface
*)vty
->index
;
1418 /* Version 1 and 2. */
1419 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1423 DEFUN (ip_rip_receive_version_2
,
1424 ip_rip_receive_version_2_cmd
,
1425 "ip rip receive version 2 1",
1427 "Routing Information Protocol\n"
1428 "Advertisement reception\n"
1433 struct interface
*ifp
;
1434 struct rip_interface
*ri
;
1436 ifp
= (struct interface
*)vty
->index
;
1439 /* Version 1 and 2. */
1440 ri
->ri_receive
= RI_RIP_VERSION_1_AND_2
;
1444 DEFUN (no_ip_rip_receive_version
,
1445 no_ip_rip_receive_version_cmd
,
1446 "no ip rip receive version",
1449 "Routing Information Protocol\n"
1450 "Advertisement reception\n"
1451 "Version control\n")
1453 struct interface
*ifp
;
1454 struct rip_interface
*ri
;
1456 ifp
= (struct interface
*)vty
->index
;
1459 ri
->ri_receive
= RI_RIP_UNSPEC
;
1463 ALIAS (no_ip_rip_receive_version
,
1464 no_ip_rip_receive_version_num_cmd
,
1465 "no ip rip receive version (1|2)",
1468 "Routing Information Protocol\n"
1469 "Advertisement reception\n"
1474 DEFUN (ip_rip_send_version
,
1475 ip_rip_send_version_cmd
,
1476 "ip rip send version (1|2)",
1478 "Routing Information Protocol\n"
1479 "Advertisement transmission\n"
1484 struct interface
*ifp
;
1485 struct rip_interface
*ri
;
1487 ifp
= (struct interface
*)vty
->index
;
1491 if (atoi (argv
[0]) == 1)
1493 ri
->ri_send
= RI_RIP_VERSION_1
;
1496 if (atoi (argv
[0]) == 2)
1498 ri
->ri_send
= RI_RIP_VERSION_2
;
1504 DEFUN (ip_rip_send_version_1
,
1505 ip_rip_send_version_1_cmd
,
1506 "ip rip send version 1 2",
1508 "Routing Information Protocol\n"
1509 "Advertisement transmission\n"
1514 struct interface
*ifp
;
1515 struct rip_interface
*ri
;
1517 ifp
= (struct interface
*)vty
->index
;
1520 /* Version 1 and 2. */
1521 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1525 DEFUN (ip_rip_send_version_2
,
1526 ip_rip_send_version_2_cmd
,
1527 "ip rip send version 2 1",
1529 "Routing Information Protocol\n"
1530 "Advertisement transmission\n"
1535 struct interface
*ifp
;
1536 struct rip_interface
*ri
;
1538 ifp
= (struct interface
*)vty
->index
;
1541 /* Version 1 and 2. */
1542 ri
->ri_send
= RI_RIP_VERSION_1_AND_2
;
1546 DEFUN (no_ip_rip_send_version
,
1547 no_ip_rip_send_version_cmd
,
1548 "no ip rip send version",
1551 "Routing Information Protocol\n"
1552 "Advertisement transmission\n"
1553 "Version control\n")
1555 struct interface
*ifp
;
1556 struct rip_interface
*ri
;
1558 ifp
= (struct interface
*)vty
->index
;
1561 ri
->ri_send
= RI_RIP_UNSPEC
;
1565 ALIAS (no_ip_rip_send_version
,
1566 no_ip_rip_send_version_num_cmd
,
1567 "no ip rip send version (1|2)",
1570 "Routing Information Protocol\n"
1571 "Advertisement transmission\n"
1576 DEFUN (ip_rip_authentication_mode
,
1577 ip_rip_authentication_mode_cmd
,
1578 "ip rip authentication mode (md5|text)",
1580 "Routing Information Protocol\n"
1581 "Authentication control\n"
1582 "Authentication mode\n"
1583 "Keyed message digest\n"
1584 "Clear text authentication\n")
1586 struct interface
*ifp
;
1587 struct rip_interface
*ri
;
1589 ifp
= (struct interface
*)vty
->index
;
1592 if (strncmp ("md5", argv
[0], strlen (argv
[0])) == 0)
1593 ri
->auth_type
= RIP_AUTH_MD5
;
1594 else if (strncmp ("text", argv
[0], strlen (argv
[0])) == 0)
1595 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1598 vty_out (vty
, "mode should be md5 or text%s", VTY_NEWLINE
);
1605 DEFUN (no_ip_rip_authentication_mode
,
1606 no_ip_rip_authentication_mode_cmd
,
1607 "no ip rip authentication mode",
1610 "Routing Information Protocol\n"
1611 "Authentication control\n"
1612 "Authentication mode\n")
1614 struct interface
*ifp
;
1615 struct rip_interface
*ri
;
1617 ifp
= (struct interface
*)vty
->index
;
1620 /* ri->auth_type = RIP_NO_AUTH; */
1621 ri
->auth_type
= RIP_AUTH_SIMPLE_PASSWORD
;
1626 ALIAS (no_ip_rip_authentication_mode
,
1627 no_ip_rip_authentication_mode_type_cmd
,
1628 "no ip rip authentication mode (md5|text)",
1631 "Routing Information Protocol\n"
1632 "Authentication control\n"
1633 "Authentication mode\n"
1634 "Keyed message digest\n"
1635 "Clear text authentication\n");
1637 DEFUN (ip_rip_authentication_string
,
1638 ip_rip_authentication_string_cmd
,
1639 "ip rip authentication string LINE",
1641 "Routing Information Protocol\n"
1642 "Authentication control\n"
1643 "Authentication string\n"
1644 "Authentication string\n")
1646 struct interface
*ifp
;
1647 struct rip_interface
*ri
;
1649 ifp
= (struct interface
*)vty
->index
;
1652 if (strlen (argv
[0]) > 16)
1654 vty_out (vty
, "%% RIPv2 authentication string must be shorter than 16%s",
1661 vty_out (vty
, "%% key-chain configuration exists%s", VTY_NEWLINE
);
1666 free (ri
->auth_str
);
1668 ri
->auth_str
= strdup (argv
[0]);
1673 DEFUN (no_ip_rip_authentication_string
,
1674 no_ip_rip_authentication_string_cmd
,
1675 "no ip rip authentication string",
1678 "Routing Information Protocol\n"
1679 "Authentication control\n"
1680 "Authentication string\n")
1682 struct interface
*ifp
;
1683 struct rip_interface
*ri
;
1685 ifp
= (struct interface
*)vty
->index
;
1689 free (ri
->auth_str
);
1691 ri
->auth_str
= NULL
;
1696 ALIAS (no_ip_rip_authentication_string
,
1697 no_ip_rip_authentication_string2_cmd
,
1698 "no ip rip authentication string LINE",
1701 "Routing Information Protocol\n"
1702 "Authentication control\n"
1703 "Authentication string\n"
1704 "Authentication string\n");
1706 DEFUN (ip_rip_authentication_key_chain
,
1707 ip_rip_authentication_key_chain_cmd
,
1708 "ip rip authentication key-chain LINE",
1710 "Routing Information Protocol\n"
1711 "Authentication control\n"
1712 "Authentication key-chain\n"
1713 "name of key-chain\n")
1715 struct interface
*ifp
;
1716 struct rip_interface
*ri
;
1718 ifp
= (struct interface
*) vty
->index
;
1723 vty_out (vty
, "%% authentication string configuration exists%s",
1729 free (ri
->key_chain
);
1731 ri
->key_chain
= strdup (argv
[0]);
1736 DEFUN (no_ip_rip_authentication_key_chain
,
1737 no_ip_rip_authentication_key_chain_cmd
,
1738 "no ip rip authentication key-chain",
1741 "Routing Information Protocol\n"
1742 "Authentication control\n"
1743 "Authentication key-chain\n")
1745 struct interface
*ifp
;
1746 struct rip_interface
*ri
;
1748 ifp
= (struct interface
*) vty
->index
;
1752 free (ri
->key_chain
);
1754 ri
->key_chain
= NULL
;
1759 ALIAS (no_ip_rip_authentication_key_chain
,
1760 no_ip_rip_authentication_key_chain2_cmd
,
1761 "no ip rip authentication key-chain LINE",
1764 "Routing Information Protocol\n"
1765 "Authentication control\n"
1766 "Authentication key-chain\n"
1767 "name of key-chain\n");
1769 DEFUN (rip_split_horizon
,
1770 rip_split_horizon_cmd
,
1773 "Perform split horizon\n")
1775 struct interface
*ifp
;
1776 struct rip_interface
*ri
;
1781 ri
->split_horizon
= 1;
1785 DEFUN (no_rip_split_horizon
,
1786 no_rip_split_horizon_cmd
,
1787 "no ip split-horizon",
1790 "Perform split horizon\n")
1792 struct interface
*ifp
;
1793 struct rip_interface
*ri
;
1798 ri
->split_horizon
= 0;
1802 DEFUN (rip_passive_interface
,
1803 rip_passive_interface_cmd
,
1804 "passive-interface IFNAME",
1805 "Suppress routing updates on an interface\n"
1808 return rip_passive_interface_set (vty
, argv
[0]);
1811 DEFUN (no_rip_passive_interface
,
1812 no_rip_passive_interface_cmd
,
1813 "no passive-interface IFNAME",
1815 "Suppress routing updates on an interface\n"
1818 return rip_passive_interface_unset (vty
, argv
[0]);
1821 /* Write rip configuration of each interface. */
1823 rip_interface_config_write (struct vty
*vty
)
1826 struct interface
*ifp
;
1828 for (node
= listhead (iflist
); node
; nextnode (node
))
1830 struct rip_interface
*ri
;
1832 ifp
= getdata (node
);
1835 vty_out (vty
, "interface %s%s", ifp
->name
,
1839 vty_out (vty
, " description %s%s", ifp
->desc
,
1842 /* Split horizon. */
1843 if (ri
->split_horizon
!= ri
->split_horizon_default
)
1845 if (ri
->split_horizon
)
1846 vty_out (vty
, " ip split-horizon%s", VTY_NEWLINE
);
1848 vty_out (vty
, " no ip split-horizon%s", VTY_NEWLINE
);
1851 /* RIP version setting. */
1852 if (ri
->ri_send
!= RI_RIP_UNSPEC
)
1853 vty_out (vty
, " ip rip send version %s%s",
1854 lookup (ri_version_msg
, ri
->ri_send
),
1857 if (ri
->ri_receive
!= RI_RIP_UNSPEC
)
1858 vty_out (vty
, " ip rip receive version %s%s",
1859 lookup (ri_version_msg
, ri
->ri_receive
),
1862 /* RIP authentication. */
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
);