blob: 9432717e9e2f261d9788abebf26babd0abf77871 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Interface related function for RIP.
2 * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#include "command.h"
25#include "if.h"
26#include "sockunion.h"
27#include "prefix.h"
28#include "memory.h"
29#include "network.h"
30#include "table.h"
31#include "log.h"
32#include "stream.h"
33#include "thread.h"
34#include "zclient.h"
35#include "filter.h"
36#include "sockopt.h"
37
38#include "zebra/connected.h"
39
40#include "ripd/ripd.h"
41#include "ripd/rip_debug.h"
42
43void rip_enable_apply (struct interface *);
44void rip_passive_interface_apply (struct interface *);
45int rip_if_down(struct interface *ifp);
46
47struct message ri_version_msg[] =
48{
49 {RI_RIP_VERSION_1, "1"},
50 {RI_RIP_VERSION_2, "2"},
51 {RI_RIP_VERSION_1_AND_2, "1 2"},
52 {0, NULL}
53};
54
55/* RIP enabled network vector. */
56vector rip_enable_interface;
57
58/* RIP enabled interface table. */
59struct route_table *rip_enable_network;
60
61/* Vector to store passive-interface name. */
62vector Vrip_passive_interface;
63
64/* Join to the RIP version 2 multicast group. */
65int
66ipv4_multicast_join (int sock,
67 struct in_addr group,
68 struct in_addr ifa,
69 unsigned int ifindex)
70{
71 int ret;
72
73 ret = setsockopt_multicast_ipv4 (sock,
74 IP_ADD_MEMBERSHIP,
75 ifa,
76 group.s_addr,
77 ifindex);
78
79 if (ret < 0)
80 zlog (NULL, LOG_INFO, "can't setsockopt IP_ADD_MEMBERSHIP %s",
81 strerror (errno));
82
83 return ret;
84}
85
86/* Leave from the RIP version 2 multicast group. */
87int
88ipv4_multicast_leave (int sock,
89 struct in_addr group,
90 struct in_addr ifa,
91 unsigned int ifindex)
92{
93 int ret;
94
95 ret = setsockopt_multicast_ipv4 (sock,
96 IP_DROP_MEMBERSHIP,
97 ifa,
98 group.s_addr,
99 ifindex);
100
101 if (ret < 0)
102 zlog (NULL, LOG_INFO, "can't setsockopt IP_DROP_MEMBERSHIP");
103
104 return ret;
105}
106
107/* Allocate new RIP's interface configuration. */
108struct rip_interface *
109rip_interface_new ()
110{
111 struct rip_interface *ri;
112
113 ri = XMALLOC (MTYPE_RIP_INTERFACE, sizeof (struct rip_interface));
114 memset (ri, 0, sizeof (struct rip_interface));
115
116 /* Default authentication type is simple password for Cisco
117 compatibility. */
118 /* ri->auth_type = RIP_NO_AUTH; */
119 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
120
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;
127
128 return ri;
129}
130
131void
132rip_interface_multicast_set (int sock, struct interface *ifp)
133{
134 int ret;
135 listnode node;
136 struct servent *sp;
137 struct sockaddr_in from;
138
139 for (node = listhead (ifp->connected); node; nextnode (node))
140 {
141 struct prefix_ipv4 *p;
142 struct connected *connected;
143 struct in_addr addr;
144
145 connected = getdata (node);
146 p = (struct prefix_ipv4 *) connected->address;
147
148 if (p->family == AF_INET)
149 {
150 addr = p->prefix;
151
152 if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF,
153 addr, 0, ifp->ifindex) < 0)
154 {
155 zlog_warn ("Can't setsockopt IP_MULTICAST_IF to fd %d", sock);
156 return;
157 }
158
159 /* Bind myself. */
160 memset (&from, 0, sizeof (struct sockaddr_in));
161
162 /* Set RIP port. */
163 sp = getservbyname ("router", "udp");
164 if (sp)
165 from.sin_port = sp->s_port;
166 else
167 from.sin_port = htons (RIP_PORT_DEFAULT);
168
169 /* Address shoud be any address. */
170 from.sin_family = AF_INET;
171 from.sin_addr = addr;
172#ifdef HAVE_SIN_LEN
173 from.sin_len = sizeof (struct sockaddr_in);
174#endif /* HAVE_SIN_LEN */
175
176 ret = bind (sock, (struct sockaddr *) & from,
177 sizeof (struct sockaddr_in));
178 if (ret < 0)
179 {
180 zlog_warn ("Can't bind socket: %s", strerror (errno));
181 return;
182 }
183
184 return;
185
186 }
187 }
188}
189
190/* Send RIP request packet to specified interface. */
191void
192rip_request_interface_send (struct interface *ifp, u_char version)
193{
194 struct sockaddr_in to;
195
196 /* RIPv2 support multicast. */
197 if (version == RIPv2 && if_is_multicast (ifp))
198 {
199
200 if (IS_RIP_DEBUG_EVENT)
201 zlog_info ("multicast request on %s", ifp->name);
202
203 rip_request_send (NULL, ifp, version);
204 return;
205 }
206
207 /* RIPv1 and non multicast interface. */
208 if (if_is_pointopoint (ifp) || if_is_broadcast (ifp))
209 {
210 listnode cnode;
211
212 if (IS_RIP_DEBUG_EVENT)
213 zlog_info ("broadcast request to %s", ifp->name);
214
215 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
216 {
217 struct prefix_ipv4 *p;
218 struct connected *connected;
219
220 connected = getdata (cnode);
221 p = (struct prefix_ipv4 *) connected->destination;
222
223 if (p->family == AF_INET)
224 {
225 memset (&to, 0, sizeof (struct sockaddr_in));
226 to.sin_port = htons (RIP_PORT_DEFAULT);
227 to.sin_addr = p->prefix;
228
229#if 0
230 if (IS_RIP_DEBUG_EVENT)
231 zlog_info ("SEND request to %s", inet_ntoa (to.sin_addr));
232#endif /* 0 */
233
234 rip_request_send (&to, ifp, version);
235 }
236 }
237 }
238}
239
240/* This will be executed when interface goes up. */
241void
242rip_request_interface (struct interface *ifp)
243{
244 struct rip_interface *ri;
245
246 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
247 if (if_is_loopback (ifp))
248 return;
249
250 /* If interface is down, don't send RIP packet. */
paul2e3b2e42002-12-13 21:03:13 +0000251 if (! if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000252 return;
253
254 /* Fetch RIP interface information. */
255 ri = ifp->info;
256
257
258 /* If there is no version configuration in the interface,
259 use rip's version setting. */
260 if (ri->ri_send == RI_RIP_UNSPEC)
261 {
262 if (rip->version == RIPv1)
263 rip_request_interface_send (ifp, RIPv1);
264 else
265 rip_request_interface_send (ifp, RIPv2);
266 }
267 /* If interface has RIP version configuration use it. */
268 else
269 {
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);
274 }
275}
276
277/* Send RIP request to the neighbor. */
278void
279rip_request_neighbor (struct in_addr addr)
280{
281 struct sockaddr_in to;
282
283 memset (&to, 0, sizeof (struct sockaddr_in));
284 to.sin_port = htons (RIP_PORT_DEFAULT);
285 to.sin_addr = addr;
286
287 rip_request_send (&to, NULL, rip->version);
288}
289
290/* Request routes at all interfaces. */
291void
292rip_request_neighbor_all ()
293{
294 struct route_node *rp;
295
296 if (! rip)
297 return;
298
299 if (IS_RIP_DEBUG_EVENT)
300 zlog_info ("request to the all neighbor");
301
302 /* Send request to all neighbor. */
303 for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
304 if (rp->info)
305 rip_request_neighbor (rp->p.u.prefix4);
306}
307
308/* Multicast packet receive socket. */
309int
310rip_multicast_join (struct interface *ifp, int sock)
311{
312 listnode cnode;
313
paul2e3b2e42002-12-13 21:03:13 +0000314 if (if_is_operative (ifp) && if_is_multicast (ifp))
paul718e3742002-12-13 20:15:29 +0000315 {
316 if (IS_RIP_DEBUG_EVENT)
317 zlog_info ("multicast join at %s", ifp->name);
318
319 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
320 {
321 struct prefix_ipv4 *p;
322 struct connected *connected;
323 struct in_addr group;
324
325 connected = getdata (cnode);
326 p = (struct prefix_ipv4 *) connected->address;
327
328 if (p->family != AF_INET)
329 continue;
330
331 group.s_addr = htonl (INADDR_RIP_GROUP);
332 if (ipv4_multicast_join (sock, group, p->prefix, ifp->ifindex) < 0)
333 return -1;
334 else
335 return 0;
336 }
337 }
338 return 0;
339}
340
341/* Leave from multicast group. */
342void
343rip_multicast_leave (struct interface *ifp, int sock)
344{
345 listnode cnode;
346
347 if (if_is_up (ifp) && if_is_multicast (ifp))
348 {
349 if (IS_RIP_DEBUG_EVENT)
350 zlog_info ("multicast leave from %s", ifp->name);
351
352 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
353 {
354 struct prefix_ipv4 *p;
355 struct connected *connected;
356 struct in_addr group;
357
358 connected = getdata (cnode);
359 p = (struct prefix_ipv4 *) connected->address;
360
361 if (p->family != AF_INET)
362 continue;
363
364 group.s_addr = htonl (INADDR_RIP_GROUP);
365 if (ipv4_multicast_leave (sock, group, p->prefix, ifp->ifindex) == 0)
366 return;
367 }
368 }
369}
370
371/* Is there and address on interface that I could use ? */
372int
373rip_if_ipv4_address_check (struct interface *ifp)
374{
375 struct listnode *nn;
376 struct connected *connected;
377 int count = 0;
378
379 for (nn = listhead (ifp->connected); nn; nextnode (nn))
380 if ((connected = getdata (nn)) != NULL)
381 {
382 struct prefix *p;
383
384 p = connected->address;
385
386 if (p->family == AF_INET)
387 {
388 count++;
389 }
390 }
391
392 return count;
393}
paul718e3742002-12-13 20:15:29 +0000394
395/* Inteface link down message processing. */
396int
397rip_interface_down (int command, struct zclient *zclient, zebra_size_t length)
398{
399 struct interface *ifp;
400 struct stream *s;
401
402 s = zclient->ibuf;
403
404 /* zebra_interface_state_read() updates interface structure in
405 iflist. */
406 ifp = zebra_interface_state_read(s);
407
408 if (ifp == NULL)
409 return 0;
410
411 rip_if_down(ifp);
412
413 if (IS_RIP_DEBUG_ZEBRA)
414 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is down",
415 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
416
417 return 0;
418}
419
420/* Inteface link up message processing */
421int
422rip_interface_up (int command, struct zclient *zclient, zebra_size_t length)
423{
424 struct interface *ifp;
425
426 /* zebra_interface_state_read () updates interface structure in
427 iflist. */
428 ifp = zebra_interface_state_read (zclient->ibuf);
429
430 if (ifp == NULL)
431 return 0;
432
433 if (IS_RIP_DEBUG_ZEBRA)
434 zlog_info ("interface %s index %d flags %ld metric %d mtu %d is up",
435 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
436
437 /* Check if this interface is RIP enabled or not.*/
438 rip_enable_apply (ifp);
439
440 /* Check for a passive interface */
441 rip_passive_interface_apply (ifp);
442
443 /* Apply distribute list to the all interface. */
444 rip_distribute_update_interface (ifp);
445
446 return 0;
447}
448
449/* Inteface addition message from zebra. */
450int
451rip_interface_add (int command, struct zclient *zclient, zebra_size_t length)
452{
453 struct interface *ifp;
454
455 ifp = zebra_interface_add_read (zclient->ibuf);
456
457 if (IS_RIP_DEBUG_ZEBRA)
458 zlog_info ("interface add %s index %d flags %ld metric %d mtu %d",
459 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
460
461 /* Check if this interface is RIP enabled or not.*/
462 rip_enable_apply (ifp);
463
464 /* Apply distribute list to the all interface. */
465 rip_distribute_update_interface (ifp);
466
467 /* rip_request_neighbor_all (); */
468
469 return 0;
470}
471
472int
473rip_interface_delete (int command, struct zclient *zclient,
474 zebra_size_t length)
475{
476 struct interface *ifp;
477 struct stream *s;
478
479
480 s = zclient->ibuf;
481 /* zebra_interface_state_read() updates interface structure in iflist */
482 ifp = zebra_interface_state_read(s);
483
484 if (ifp == NULL)
485 return 0;
486
487 if (if_is_up (ifp)) {
488 rip_if_down(ifp);
489 }
490
491 zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
492 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
493
494 /* To support pseudo interface do not free interface structure. */
495 /* if_delete(ifp); */
496
497 return 0;
498}
499
500void
501rip_interface_clean ()
502{
503 listnode node;
504 struct interface *ifp;
505 struct rip_interface *ri;
506
507 for (node = listhead (iflist); node; nextnode (node))
508 {
509 ifp = getdata (node);
510 ri = ifp->info;
511
512 ri->enable_network = 0;
513 ri->enable_interface = 0;
514 ri->running = 0;
515
516 if (ri->t_wakeup)
517 {
518 thread_cancel (ri->t_wakeup);
519 ri->t_wakeup = NULL;
520 }
521 }
522}
523
524void
525rip_interface_reset ()
526{
527 listnode node;
528 struct interface *ifp;
529 struct rip_interface *ri;
530
531 for (node = listhead (iflist); node; nextnode (node))
532 {
533 ifp = getdata (node);
534 ri = ifp->info;
535
536 ri->enable_network = 0;
537 ri->enable_interface = 0;
538 ri->running = 0;
539
540 ri->ri_send = RI_RIP_UNSPEC;
541 ri->ri_receive = RI_RIP_UNSPEC;
542
543 /* ri->auth_type = RIP_NO_AUTH; */
544 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
545
546 if (ri->auth_str)
547 {
548 free (ri->auth_str);
549 ri->auth_str = NULL;
550 }
551 if (ri->key_chain)
552 {
553 free (ri->key_chain);
554 ri->key_chain = NULL;
555 }
556
557 ri->split_horizon = 0;
558 ri->split_horizon_default = 0;
559
560 ri->list[RIP_FILTER_IN] = NULL;
561 ri->list[RIP_FILTER_OUT] = NULL;
562
563 ri->prefix[RIP_FILTER_IN] = NULL;
564 ri->prefix[RIP_FILTER_OUT] = NULL;
565
566 if (ri->t_wakeup)
567 {
568 thread_cancel (ri->t_wakeup);
569 ri->t_wakeup = NULL;
570 }
571
572 ri->recv_badpackets = 0;
573 ri->recv_badroutes = 0;
574 ri->sent_updates = 0;
575
576 ri->passive = 0;
577 }
578}
579
580int
581rip_if_down(struct interface *ifp)
582{
583 struct route_node *rp;
584 struct rip_info *rinfo;
585 struct rip_interface *ri = NULL;
586 if (rip)
587 {
588 for (rp = route_top (rip->table); rp; rp = route_next (rp))
589 if ((rinfo = rp->info) != NULL)
590 {
591 /* Routes got through this interface. */
592 if (rinfo->ifindex == ifp->ifindex &&
593 rinfo->type == ZEBRA_ROUTE_RIP &&
594 rinfo->sub_type == RIP_ROUTE_RTE)
595 {
596 rip_zebra_ipv4_delete ((struct prefix_ipv4 *) &rp->p,
597 &rinfo->nexthop,
598 rinfo->ifindex);
599
600 rip_redistribute_delete (rinfo->type,rinfo->sub_type,
601 (struct prefix_ipv4 *)&rp->p,
602 rinfo->ifindex);
603 }
604 else
605 {
606 /* All redistributed routes but static and system */
607 if ((rinfo->ifindex == ifp->ifindex) &&
paul2e3b2e42002-12-13 21:03:13 +0000608 /* (rinfo->type != ZEBRA_ROUTE_STATIC) && */
paul718e3742002-12-13 20:15:29 +0000609 (rinfo->type != ZEBRA_ROUTE_SYSTEM))
610 rip_redistribute_delete (rinfo->type,rinfo->sub_type,
611 (struct prefix_ipv4 *)&rp->p,
612 rinfo->ifindex);
613 }
614 }
615 }
616
617 ri = ifp->info;
618
619 if (ri->running)
620 {
621 if (IS_RIP_DEBUG_EVENT)
622 zlog_info ("turn off %s", ifp->name);
623
624 /* Leave from multicast group. */
625 rip_multicast_leave (ifp, rip->sock);
626
627 ri->running = 0;
628 }
629
630 return 0;
631}
632
633/* Needed for stop RIP process. */
634void
635rip_if_down_all ()
636{
637 struct interface *ifp;
638 listnode node;
639
640 for (node = listhead (iflist); node; nextnode (node))
641 {
642 ifp = getdata (node);
643 rip_if_down (ifp);
644 }
645}
646
647int
648rip_interface_address_add (int command, struct zclient *zclient,
649 zebra_size_t length)
650{
651 struct connected *ifc;
652 struct prefix *p;
653
654 ifc = zebra_interface_address_add_read (zclient->ibuf);
655
656 if (ifc == NULL)
657 return 0;
658
659 p = ifc->address;
660
661 if (p->family == AF_INET)
662 {
663 if (IS_RIP_DEBUG_ZEBRA)
664 zlog_info ("connected address %s/%d is added",
665 inet_ntoa (p->u.prefix4), p->prefixlen);
666
667 /* Check is this interface is RIP enabled or not.*/
668 rip_enable_apply (ifc->ifp);
669
670#ifdef HAVE_SNMP
671 rip_ifaddr_add (ifc->ifp, ifc);
672#endif /* HAVE_SNMP */
673 }
674
675 return 0;
676}
677
678int
679rip_interface_address_delete (int command, struct zclient *zclient,
680 zebra_size_t length)
681{
682 struct connected *ifc;
683 struct prefix *p;
684
685 ifc = zebra_interface_address_delete_read (zclient->ibuf);
686
687 if (ifc)
688 {
689 p = ifc->address;
690 if (p->family == AF_INET)
691 {
692 if (IS_RIP_DEBUG_ZEBRA)
693
694 zlog_info ("connected address %s/%d is deleted",
695 inet_ntoa (p->u.prefix4), p->prefixlen);
696
697#ifdef HAVE_SNMP
698 rip_ifaddr_delete (ifc->ifp, ifc);
699#endif /* HAVE_SNMP */
700
701 /* Check if this interface is RIP enabled or not.*/
702 rip_enable_apply (ifc->ifp);
703 }
704
705 connected_free (ifc);
706
707 }
708
709 return 0;
710}
711
712/* Check interface is enabled by network statement. */
713int
714rip_enable_network_lookup (struct interface *ifp)
715{
716 struct listnode *nn;
717 struct connected *connected;
718 struct prefix_ipv4 address;
719
720 for (nn = listhead (ifp->connected); nn; nextnode (nn))
721 if ((connected = getdata (nn)) != NULL)
722 {
723 struct prefix *p;
724 struct route_node *node;
725
726 p = connected->address;
727
728 if (p->family == AF_INET)
729 {
730 address.family = AF_INET;
731 address.prefix = p->u.prefix4;
732 address.prefixlen = IPV4_MAX_BITLEN;
733
734 node = route_node_match (rip_enable_network,
735 (struct prefix *)&address);
736 if (node)
737 {
738 route_unlock_node (node);
739 return 1;
740 }
741 }
742 }
743 return -1;
744}
745
746/* Add RIP enable network. */
747int
748rip_enable_network_add (struct prefix *p)
749{
750 struct route_node *node;
751
752 node = route_node_get (rip_enable_network, p);
753
754 if (node->info)
755 {
756 route_unlock_node (node);
757 return -1;
758 }
759 else
760 node->info = "enabled";
761
762 return 1;
763}
764
765/* Delete RIP enable network. */
766int
767rip_enable_network_delete (struct prefix *p)
768{
769 struct route_node *node;
770
771 node = route_node_lookup (rip_enable_network, p);
772 if (node)
773 {
774 node->info = NULL;
775
776 /* Unlock info lock. */
777 route_unlock_node (node);
778
779 /* Unlock lookup lock. */
780 route_unlock_node (node);
781
782 return 1;
783 }
784 return -1;
785}
786
787/* Check interface is enabled by ifname statement. */
788int
789rip_enable_if_lookup (char *ifname)
790{
791 int i;
792 char *str;
793
794 for (i = 0; i < vector_max (rip_enable_interface); i++)
795 if ((str = vector_slot (rip_enable_interface, i)) != NULL)
796 if (strcmp (str, ifname) == 0)
797 return i;
798 return -1;
799}
800
801/* Add interface to rip_enable_if. */
802int
803rip_enable_if_add (char *ifname)
804{
805 int ret;
806
807 ret = rip_enable_if_lookup (ifname);
808 if (ret >= 0)
809 return -1;
810
811 vector_set (rip_enable_interface, strdup (ifname));
812
813 return 1;
814}
815
816/* Delete interface from rip_enable_if. */
817int
818rip_enable_if_delete (char *ifname)
819{
820 int index;
821 char *str;
822
823 index = rip_enable_if_lookup (ifname);
824 if (index < 0)
825 return -1;
826
827 str = vector_slot (rip_enable_interface, index);
828 free (str);
829 vector_unset (rip_enable_interface, index);
830
831 return 1;
832}
833
834/* Join to multicast group and send request to the interface. */
835int
836rip_interface_wakeup (struct thread *t)
837{
838 struct interface *ifp;
839 struct rip_interface *ri;
840
841 /* Get interface. */
842 ifp = THREAD_ARG (t);
843
844 ri = ifp->info;
845 ri->t_wakeup = NULL;
846
847 /* Join to multicast group. */
848 if (rip_multicast_join (ifp, rip->sock) < 0)
849 {
850 zlog_err ("multicast join failed, interface %s not running", ifp->name);
851 return 0;
852 }
853
854 /* Set running flag. */
855 ri->running = 1;
856
857 /* Send RIP request to the interface. */
858 rip_request_interface (ifp);
859
860 return 0;
861}
862
863int rip_redistribute_check (int);
864
865void
866rip_connect_set (struct interface *ifp, int set)
867{
868 struct listnode *nn;
869 struct connected *connected;
870 struct prefix_ipv4 address;
871
872 for (nn = listhead (ifp->connected); nn; nextnode (nn))
873 if ((connected = getdata (nn)) != NULL)
874 {
875 struct prefix *p;
876 p = connected->address;
877
878 if (p->family != AF_INET)
879 continue;
880
881 address.family = AF_INET;
882 address.prefix = p->u.prefix4;
883 address.prefixlen = p->prefixlen;
884 apply_mask_ipv4 (&address);
885
886 if (set)
887 rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
888 &address, connected->ifp->ifindex, NULL);
889 else
890 {
891 rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
892 &address, connected->ifp->ifindex);
893 if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT))
894 rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE,
895 &address, connected->ifp->ifindex, NULL);
896 }
897 }
898}
899
900/* Update interface status. */
901void
902rip_enable_apply (struct interface *ifp)
903{
904 int ret;
905 struct rip_interface *ri = NULL;
906
907 /* Check interface. */
908 if (if_is_loopback (ifp))
909 return;
910
paul2e3b2e42002-12-13 21:03:13 +0000911 if (! if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000912 return;
913
914 ri = ifp->info;
915
916 /* Check network configuration. */
917 ret = rip_enable_network_lookup (ifp);
918
919 /* If the interface is matched. */
920 if (ret > 0)
921 ri->enable_network = 1;
922 else
923 ri->enable_network = 0;
924
925 /* Check interface name configuration. */
926 ret = rip_enable_if_lookup (ifp->name);
927 if (ret >= 0)
928 ri->enable_interface = 1;
929 else
930 ri->enable_interface = 0;
931
932 /* any interface MUST have an IPv4 address */
933 if ( ! rip_if_ipv4_address_check (ifp) )
934 {
935 ri->enable_network = 0;
936 ri->enable_interface = 0;
937 }
938
939 /* Update running status of the interface. */
940 if (ri->enable_network || ri->enable_interface)
941 {
942 if (! ri->running)
943 {
944 if (IS_RIP_DEBUG_EVENT)
945 zlog_info ("turn on %s", ifp->name);
946
947 /* Add interface wake up thread. */
948 if (! ri->t_wakeup)
949 ri->t_wakeup = thread_add_timer (master, rip_interface_wakeup,
950 ifp, 1);
951 rip_connect_set (ifp, 1);
952 }
953 }
954 else
955 {
956 if (ri->running)
957 {
958 if (IS_RIP_DEBUG_EVENT)
959 zlog_info ("turn off %s", ifp->name);
960
961 /* Might as well clean up the route table as well */
962 rip_if_down(ifp);
963
964 ri->running = 0;
965 rip_connect_set (ifp, 0);
966 }
967 }
968}
969
970/* Apply network configuration to all interface. */
971void
972rip_enable_apply_all ()
973{
974 struct interface *ifp;
975 listnode node;
976
977 /* Check each interface. */
978 for (node = listhead (iflist); node; nextnode (node))
979 {
980 ifp = getdata (node);
981 rip_enable_apply (ifp);
982 }
983}
984
985int
986rip_neighbor_lookup (struct sockaddr_in *from)
987{
988 struct prefix_ipv4 p;
989 struct route_node *node;
990
991 memset (&p, 0, sizeof (struct prefix_ipv4));
992 p.family = AF_INET;
993 p.prefix = from->sin_addr;
994 p.prefixlen = IPV4_MAX_BITLEN;
995
996 node = route_node_lookup (rip->neighbor, (struct prefix *) &p);
997 if (node)
998 {
999 route_unlock_node (node);
1000 return 1;
1001 }
1002 return 0;
1003}
1004
1005/* Add new RIP neighbor to the neighbor tree. */
1006int
1007rip_neighbor_add (struct prefix_ipv4 *p)
1008{
1009 struct route_node *node;
1010
1011 node = route_node_get (rip->neighbor, (struct prefix *) p);
1012
1013 if (node->info)
1014 return -1;
1015
1016 node->info = rip->neighbor;
1017
1018 return 0;
1019}
1020
1021/* Delete RIP neighbor from the neighbor tree. */
1022int
1023rip_neighbor_delete (struct prefix_ipv4 *p)
1024{
1025 struct route_node *node;
1026
1027 /* Lock for look up. */
1028 node = route_node_lookup (rip->neighbor, (struct prefix *) p);
1029 if (! node)
1030 return -1;
1031
1032 node->info = NULL;
1033
1034 /* Unlock lookup lock. */
1035 route_unlock_node (node);
1036
1037 /* Unlock real neighbor information lock. */
1038 route_unlock_node (node);
1039
1040 return 0;
1041}
1042
1043/* Clear all network and neighbor configuration. */
1044void
1045rip_clean_network ()
1046{
1047 int i;
1048 char *str;
1049 struct route_node *rn;
1050
1051 /* rip_enable_network. */
1052 for (rn = route_top (rip_enable_network); rn; rn = route_next (rn))
1053 if (rn->info)
1054 {
1055 rn->info = NULL;
1056 route_unlock_node (rn);
1057 }
1058
1059 /* rip_enable_interface. */
1060 for (i = 0; i < vector_max (rip_enable_interface); i++)
1061 if ((str = vector_slot (rip_enable_interface, i)) != NULL)
1062 {
1063 free (str);
1064 vector_slot (rip_enable_interface, i) = NULL;
1065 }
1066}
1067
1068/* Utility function for looking up passive interface settings. */
1069int
1070rip_passive_interface_lookup (char *ifname)
1071{
1072 int i;
1073 char *str;
1074
1075 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1076 if ((str = vector_slot (Vrip_passive_interface, i)) != NULL)
1077 if (strcmp (str, ifname) == 0)
1078 return i;
1079 return -1;
1080}
1081
1082void
1083rip_passive_interface_apply (struct interface *ifp)
1084{
1085 int ret;
1086 struct rip_interface *ri;
1087
1088 ri = ifp->info;
1089
1090 ret = rip_passive_interface_lookup (ifp->name);
1091 if (ret < 0)
1092 ri->passive = 0;
1093 else
1094 ri->passive = 1;
1095}
1096
1097void
1098rip_passive_interface_apply_all ()
1099{
1100 struct interface *ifp;
1101 listnode node;
1102
1103 for (node = listhead (iflist); node; nextnode (node))
1104 {
1105 ifp = getdata (node);
1106 rip_passive_interface_apply (ifp);
1107 }
1108}
1109
1110/* Passive interface. */
1111int
1112rip_passive_interface_set (struct vty *vty, char *ifname)
1113{
1114 if (rip_passive_interface_lookup (ifname) >= 0)
1115 return CMD_WARNING;
1116
1117 vector_set (Vrip_passive_interface, strdup (ifname));
1118
1119 rip_passive_interface_apply_all ();
1120
1121 return CMD_SUCCESS;
1122}
1123
1124int
1125rip_passive_interface_unset (struct vty *vty, char *ifname)
1126{
1127 int i;
1128 char *str;
1129
1130 i = rip_passive_interface_lookup (ifname);
1131 if (i < 0)
1132 return CMD_WARNING;
1133
1134 str = vector_slot (Vrip_passive_interface, i);
1135 free (str);
1136 vector_unset (Vrip_passive_interface, i);
1137
1138 rip_passive_interface_apply_all ();
1139
1140 return CMD_SUCCESS;
1141}
1142
1143/* Free all configured RIP passive-interface settings. */
1144void
1145rip_passive_interface_clean ()
1146{
1147 int i;
1148 char *str;
1149
1150 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1151 if ((str = vector_slot (Vrip_passive_interface, i)) != NULL)
1152 {
1153 free (str);
1154 vector_slot (Vrip_passive_interface, i) = NULL;
1155 }
1156 rip_passive_interface_apply_all ();
1157}
1158
1159/* RIP enable network or interface configuration. */
1160DEFUN (rip_network,
1161 rip_network_cmd,
1162 "network (A.B.C.D/M|WORD)",
1163 "Enable routing on an IP network\n"
1164 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1165 "Interface name\n")
1166{
1167 int ret;
1168 struct prefix_ipv4 p;
1169
1170 ret = str2prefix_ipv4 (argv[0], &p);
1171
1172 if (ret)
1173 ret = rip_enable_network_add ((struct prefix *) &p);
1174 else
1175 ret = rip_enable_if_add (argv[0]);
1176
1177 if (ret < 0)
1178 {
1179 vty_out (vty, "There is a same network configuration %s%s", argv[0],
1180 VTY_NEWLINE);
1181 return CMD_WARNING;
1182 }
1183
1184 rip_enable_apply_all ();
1185
1186 return CMD_SUCCESS;
1187}
1188
1189/* RIP enable network or interface configuration. */
1190DEFUN (no_rip_network,
1191 no_rip_network_cmd,
1192 "no network (A.B.C.D/M|WORD)",
1193 NO_STR
1194 "Enable routing on an IP network\n"
1195 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1196 "Interface name\n")
1197{
1198 int ret;
1199 struct prefix_ipv4 p;
1200
1201 ret = str2prefix_ipv4 (argv[0], &p);
1202
1203 if (ret)
1204 ret = rip_enable_network_delete ((struct prefix *) &p);
1205 else
1206 ret = rip_enable_if_delete (argv[0]);
1207
1208 if (ret < 0)
1209 {
1210 vty_out (vty, "Can't find network configuration %s%s", argv[0],
1211 VTY_NEWLINE);
1212 return CMD_WARNING;
1213 }
1214
1215 rip_enable_apply_all ();
1216
1217 return CMD_SUCCESS;
1218}
1219
1220/* RIP neighbor configuration set. */
1221DEFUN (rip_neighbor,
1222 rip_neighbor_cmd,
1223 "neighbor A.B.C.D",
1224 "Specify a neighbor router\n"
1225 "Neighbor address\n")
1226{
1227 int ret;
1228 struct prefix_ipv4 p;
1229
1230 ret = str2prefix_ipv4 (argv[0], &p);
1231
1232 if (ret <= 0)
1233 {
1234 vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
1235 return CMD_WARNING;
1236 }
1237
1238 rip_neighbor_add (&p);
1239
1240 return CMD_SUCCESS;
1241}
1242
1243/* RIP neighbor configuration unset. */
1244DEFUN (no_rip_neighbor,
1245 no_rip_neighbor_cmd,
1246 "no neighbor A.B.C.D",
1247 NO_STR
1248 "Specify a neighbor router\n"
1249 "Neighbor address\n")
1250{
1251 int ret;
1252 struct prefix_ipv4 p;
1253
1254 ret = str2prefix_ipv4 (argv[0], &p);
1255
1256 if (ret <= 0)
1257 {
1258 vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
1259 return CMD_WARNING;
1260 }
1261
1262 rip_neighbor_delete (&p);
1263
1264 return CMD_SUCCESS;
1265}
1266
1267DEFUN (ip_rip_receive_version,
1268 ip_rip_receive_version_cmd,
1269 "ip rip receive version (1|2)",
1270 IP_STR
1271 "Routing Information Protocol\n"
1272 "Advertisement reception\n"
1273 "Version control\n"
1274 "RIP version 1\n"
1275 "RIP version 2\n")
1276{
1277 struct interface *ifp;
1278 struct rip_interface *ri;
1279
1280 ifp = (struct interface *)vty->index;
1281 ri = ifp->info;
1282
1283 /* Version 1. */
1284 if (atoi (argv[0]) == 1)
1285 {
1286 ri->ri_receive = RI_RIP_VERSION_1;
1287 return CMD_SUCCESS;
1288 }
1289 if (atoi (argv[0]) == 2)
1290 {
1291 ri->ri_receive = RI_RIP_VERSION_2;
1292 return CMD_SUCCESS;
1293 }
1294 return CMD_WARNING;
1295}
1296
1297DEFUN (ip_rip_receive_version_1,
1298 ip_rip_receive_version_1_cmd,
1299 "ip rip receive version 1 2",
1300 IP_STR
1301 "Routing Information Protocol\n"
1302 "Advertisement reception\n"
1303 "Version control\n"
1304 "RIP version 1\n"
1305 "RIP version 2\n")
1306{
1307 struct interface *ifp;
1308 struct rip_interface *ri;
1309
1310 ifp = (struct interface *)vty->index;
1311 ri = ifp->info;
1312
1313 /* Version 1 and 2. */
1314 ri->ri_receive = RI_RIP_VERSION_1_AND_2;
1315 return CMD_SUCCESS;
1316}
1317
1318DEFUN (ip_rip_receive_version_2,
1319 ip_rip_receive_version_2_cmd,
1320 "ip rip receive version 2 1",
1321 IP_STR
1322 "Routing Information Protocol\n"
1323 "Advertisement reception\n"
1324 "Version control\n"
1325 "RIP version 2\n"
1326 "RIP version 1\n")
1327{
1328 struct interface *ifp;
1329 struct rip_interface *ri;
1330
1331 ifp = (struct interface *)vty->index;
1332 ri = ifp->info;
1333
1334 /* Version 1 and 2. */
1335 ri->ri_receive = RI_RIP_VERSION_1_AND_2;
1336 return CMD_SUCCESS;
1337}
1338
1339DEFUN (no_ip_rip_receive_version,
1340 no_ip_rip_receive_version_cmd,
1341 "no ip rip receive version",
1342 NO_STR
1343 IP_STR
1344 "Routing Information Protocol\n"
1345 "Advertisement reception\n"
1346 "Version control\n")
1347{
1348 struct interface *ifp;
1349 struct rip_interface *ri;
1350
1351 ifp = (struct interface *)vty->index;
1352 ri = ifp->info;
1353
1354 ri->ri_receive = RI_RIP_UNSPEC;
1355 return CMD_SUCCESS;
1356}
1357
1358ALIAS (no_ip_rip_receive_version,
1359 no_ip_rip_receive_version_num_cmd,
1360 "no ip rip receive version (1|2)",
1361 NO_STR
1362 IP_STR
1363 "Routing Information Protocol\n"
1364 "Advertisement reception\n"
1365 "Version control\n"
1366 "Version 1\n"
1367 "Version 2\n")
1368
1369DEFUN (ip_rip_send_version,
1370 ip_rip_send_version_cmd,
1371 "ip rip send version (1|2)",
1372 IP_STR
1373 "Routing Information Protocol\n"
1374 "Advertisement transmission\n"
1375 "Version control\n"
1376 "RIP version 1\n"
1377 "RIP version 2\n")
1378{
1379 struct interface *ifp;
1380 struct rip_interface *ri;
1381
1382 ifp = (struct interface *)vty->index;
1383 ri = ifp->info;
1384
1385 /* Version 1. */
1386 if (atoi (argv[0]) == 1)
1387 {
1388 ri->ri_send = RI_RIP_VERSION_1;
1389 return CMD_SUCCESS;
1390 }
1391 if (atoi (argv[0]) == 2)
1392 {
1393 ri->ri_send = RI_RIP_VERSION_2;
1394 return CMD_SUCCESS;
1395 }
1396 return CMD_WARNING;
1397}
1398
1399DEFUN (ip_rip_send_version_1,
1400 ip_rip_send_version_1_cmd,
1401 "ip rip send version 1 2",
1402 IP_STR
1403 "Routing Information Protocol\n"
1404 "Advertisement transmission\n"
1405 "Version control\n"
1406 "RIP version 1\n"
1407 "RIP version 2\n")
1408{
1409 struct interface *ifp;
1410 struct rip_interface *ri;
1411
1412 ifp = (struct interface *)vty->index;
1413 ri = ifp->info;
1414
1415 /* Version 1 and 2. */
1416 ri->ri_send = RI_RIP_VERSION_1_AND_2;
1417 return CMD_SUCCESS;
1418}
1419
1420DEFUN (ip_rip_send_version_2,
1421 ip_rip_send_version_2_cmd,
1422 "ip rip send version 2 1",
1423 IP_STR
1424 "Routing Information Protocol\n"
1425 "Advertisement transmission\n"
1426 "Version control\n"
1427 "RIP version 2\n"
1428 "RIP version 1\n")
1429{
1430 struct interface *ifp;
1431 struct rip_interface *ri;
1432
1433 ifp = (struct interface *)vty->index;
1434 ri = ifp->info;
1435
1436 /* Version 1 and 2. */
1437 ri->ri_send = RI_RIP_VERSION_1_AND_2;
1438 return CMD_SUCCESS;
1439}
1440
1441DEFUN (no_ip_rip_send_version,
1442 no_ip_rip_send_version_cmd,
1443 "no ip rip send version",
1444 NO_STR
1445 IP_STR
1446 "Routing Information Protocol\n"
1447 "Advertisement transmission\n"
1448 "Version control\n")
1449{
1450 struct interface *ifp;
1451 struct rip_interface *ri;
1452
1453 ifp = (struct interface *)vty->index;
1454 ri = ifp->info;
1455
1456 ri->ri_send = RI_RIP_UNSPEC;
1457 return CMD_SUCCESS;
1458}
1459
1460ALIAS (no_ip_rip_send_version,
1461 no_ip_rip_send_version_num_cmd,
1462 "no ip rip send version (1|2)",
1463 NO_STR
1464 IP_STR
1465 "Routing Information Protocol\n"
1466 "Advertisement transmission\n"
1467 "Version control\n"
1468 "Version 1\n"
1469 "Version 2\n")
1470
1471DEFUN (ip_rip_authentication_mode,
1472 ip_rip_authentication_mode_cmd,
1473 "ip rip authentication mode (md5|text)",
1474 IP_STR
1475 "Routing Information Protocol\n"
1476 "Authentication control\n"
1477 "Authentication mode\n"
1478 "Keyed message digest\n"
1479 "Clear text authentication\n")
1480{
1481 struct interface *ifp;
1482 struct rip_interface *ri;
1483
1484 ifp = (struct interface *)vty->index;
1485 ri = ifp->info;
1486
1487 if (strncmp ("md5", argv[0], strlen (argv[0])) == 0)
1488 ri->auth_type = RIP_AUTH_MD5;
1489 else if (strncmp ("text", argv[0], strlen (argv[0])) == 0)
1490 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
1491 else
1492 {
1493 vty_out (vty, "mode should be md5 or text%s", VTY_NEWLINE);
1494 return CMD_WARNING;
1495 }
1496
1497 return CMD_SUCCESS;
1498}
1499
1500DEFUN (no_ip_rip_authentication_mode,
1501 no_ip_rip_authentication_mode_cmd,
1502 "no ip rip authentication mode",
1503 NO_STR
1504 IP_STR
1505 "Routing Information Protocol\n"
1506 "Authentication control\n"
1507 "Authentication mode\n")
1508{
1509 struct interface *ifp;
1510 struct rip_interface *ri;
1511
1512 ifp = (struct interface *)vty->index;
1513 ri = ifp->info;
1514
1515 /* ri->auth_type = RIP_NO_AUTH; */
1516 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
1517
1518 return CMD_SUCCESS;
1519}
1520
1521ALIAS (no_ip_rip_authentication_mode,
1522 no_ip_rip_authentication_mode_type_cmd,
1523 "no ip rip authentication mode (md5|text)",
1524 NO_STR
1525 IP_STR
1526 "Routing Information Protocol\n"
1527 "Authentication control\n"
1528 "Authentication mode\n"
1529 "Keyed message digest\n"
1530 "Clear text authentication\n")
1531
1532DEFUN (ip_rip_authentication_string,
1533 ip_rip_authentication_string_cmd,
1534 "ip rip authentication string LINE",
1535 IP_STR
1536 "Routing Information Protocol\n"
1537 "Authentication control\n"
1538 "Authentication string\n"
1539 "Authentication string\n")
1540{
1541 struct interface *ifp;
1542 struct rip_interface *ri;
1543
1544 ifp = (struct interface *)vty->index;
1545 ri = ifp->info;
1546
1547 if (strlen (argv[0]) > 16)
1548 {
1549 vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s",
1550 VTY_NEWLINE);
1551 return CMD_WARNING;
1552 }
1553
1554 if (ri->key_chain)
1555 {
1556 vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE);
1557 return CMD_WARNING;
1558 }
1559
1560 if (ri->auth_str)
1561 free (ri->auth_str);
1562
1563 ri->auth_str = strdup (argv[0]);
1564
1565 return CMD_SUCCESS;
1566}
1567
1568DEFUN (no_ip_rip_authentication_string,
1569 no_ip_rip_authentication_string_cmd,
1570 "no ip rip authentication string",
1571 NO_STR
1572 IP_STR
1573 "Routing Information Protocol\n"
1574 "Authentication control\n"
1575 "Authentication string\n")
1576{
1577 struct interface *ifp;
1578 struct rip_interface *ri;
1579
1580 ifp = (struct interface *)vty->index;
1581 ri = ifp->info;
1582
1583 if (ri->auth_str)
1584 free (ri->auth_str);
1585
1586 ri->auth_str = NULL;
1587
1588 return CMD_SUCCESS;
1589}
1590
1591ALIAS (no_ip_rip_authentication_string,
1592 no_ip_rip_authentication_string2_cmd,
1593 "no ip rip authentication string LINE",
1594 NO_STR
1595 IP_STR
1596 "Routing Information Protocol\n"
1597 "Authentication control\n"
1598 "Authentication string\n"
1599 "Authentication string\n")
1600
1601DEFUN (ip_rip_authentication_key_chain,
1602 ip_rip_authentication_key_chain_cmd,
1603 "ip rip authentication key-chain LINE",
1604 IP_STR
1605 "Routing Information Protocol\n"
1606 "Authentication control\n"
1607 "Authentication key-chain\n"
1608 "name of key-chain\n")
1609{
1610 struct interface *ifp;
1611 struct rip_interface *ri;
1612
1613 ifp = (struct interface *) vty->index;
1614 ri = ifp->info;
1615
1616 if (ri->auth_str)
1617 {
1618 vty_out (vty, "%% authentication string configuration exists%s",
1619 VTY_NEWLINE);
1620 return CMD_WARNING;
1621 }
1622
1623 if (ri->key_chain)
1624 free (ri->key_chain);
1625
1626 ri->key_chain = strdup (argv[0]);
1627
1628 return CMD_SUCCESS;
1629}
1630
1631DEFUN (no_ip_rip_authentication_key_chain,
1632 no_ip_rip_authentication_key_chain_cmd,
1633 "no ip rip authentication key-chain",
1634 NO_STR
1635 IP_STR
1636 "Routing Information Protocol\n"
1637 "Authentication control\n"
1638 "Authentication key-chain\n")
1639{
1640 struct interface *ifp;
1641 struct rip_interface *ri;
1642
1643 ifp = (struct interface *) vty->index;
1644 ri = ifp->info;
1645
1646 if (ri->key_chain)
1647 free (ri->key_chain);
1648
1649 ri->key_chain = NULL;
1650
1651 return CMD_SUCCESS;
1652}
1653
1654ALIAS (no_ip_rip_authentication_key_chain,
1655 no_ip_rip_authentication_key_chain2_cmd,
1656 "no ip rip authentication key-chain LINE",
1657 NO_STR
1658 IP_STR
1659 "Routing Information Protocol\n"
1660 "Authentication control\n"
1661 "Authentication key-chain\n"
1662 "name of key-chain\n")
1663
1664DEFUN (rip_split_horizon,
1665 rip_split_horizon_cmd,
1666 "ip split-horizon",
1667 IP_STR
1668 "Perform split horizon\n")
1669{
1670 struct interface *ifp;
1671 struct rip_interface *ri;
1672
1673 ifp = vty->index;
1674 ri = ifp->info;
1675
1676 ri->split_horizon = 1;
1677 return CMD_SUCCESS;
1678}
1679
1680DEFUN (no_rip_split_horizon,
1681 no_rip_split_horizon_cmd,
1682 "no ip split-horizon",
1683 NO_STR
1684 IP_STR
1685 "Perform split horizon\n")
1686{
1687 struct interface *ifp;
1688 struct rip_interface *ri;
1689
1690 ifp = vty->index;
1691 ri = ifp->info;
1692
1693 ri->split_horizon = 0;
1694 return CMD_SUCCESS;
1695}
1696
1697DEFUN (rip_passive_interface,
1698 rip_passive_interface_cmd,
1699 "passive-interface IFNAME",
1700 "Suppress routing updates on an interface\n"
1701 "Interface name\n")
1702{
1703 return rip_passive_interface_set (vty, argv[0]);
1704}
1705
1706DEFUN (no_rip_passive_interface,
1707 no_rip_passive_interface_cmd,
1708 "no passive-interface IFNAME",
1709 NO_STR
1710 "Suppress routing updates on an interface\n"
1711 "Interface name\n")
1712{
1713 return rip_passive_interface_unset (vty, argv[0]);
1714}
1715
1716/* Write rip configuration of each interface. */
1717int
1718rip_interface_config_write (struct vty *vty)
1719{
1720 listnode node;
1721 struct interface *ifp;
1722
1723 for (node = listhead (iflist); node; nextnode (node))
1724 {
1725 struct rip_interface *ri;
1726
1727 ifp = getdata (node);
1728 ri = ifp->info;
1729
1730 vty_out (vty, "interface %s%s", ifp->name,
1731 VTY_NEWLINE);
1732
1733 if (ifp->desc)
1734 vty_out (vty, " description %s%s", ifp->desc,
1735 VTY_NEWLINE);
1736
1737 /* Split horizon. */
1738 if (ri->split_horizon != ri->split_horizon_default)
1739 {
1740 if (ri->split_horizon)
1741 vty_out (vty, " ip split-horizon%s", VTY_NEWLINE);
1742 else
1743 vty_out (vty, " no ip split-horizon%s", VTY_NEWLINE);
1744 }
1745
1746 /* RIP version setting. */
1747 if (ri->ri_send != RI_RIP_UNSPEC)
1748 vty_out (vty, " ip rip send version %s%s",
1749 lookup (ri_version_msg, ri->ri_send),
1750 VTY_NEWLINE);
1751
1752 if (ri->ri_receive != RI_RIP_UNSPEC)
1753 vty_out (vty, " ip rip receive version %s%s",
1754 lookup (ri_version_msg, ri->ri_receive),
1755 VTY_NEWLINE);
1756
1757 /* RIP authentication. */
1758#if 0
1759 /* RIP_AUTH_SIMPLE_PASSWORD becomes default mode. */
1760 if (ri->auth_type == RIP_AUTH_SIMPLE_PASSWORD)
1761 vty_out (vty, " ip rip authentication mode text%s", VTY_NEWLINE);
1762#endif /* 0 */
1763 if (ri->auth_type == RIP_AUTH_MD5)
1764 vty_out (vty, " ip rip authentication mode md5%s", VTY_NEWLINE);
1765
1766 if (ri->auth_str)
1767 vty_out (vty, " ip rip authentication string %s%s",
1768 ri->auth_str, VTY_NEWLINE);
1769
1770 if (ri->key_chain)
1771 vty_out (vty, " ip rip authentication key-chain %s%s",
1772 ri->key_chain, VTY_NEWLINE);
1773
1774 vty_out (vty, "!%s", VTY_NEWLINE);
1775 }
1776 return 0;
1777}
1778
1779int
1780config_write_rip_network (struct vty *vty, int config_mode)
1781{
1782 int i;
1783 char *ifname;
1784 struct route_node *node;
1785
1786 /* Network type RIP enable interface statement. */
1787 for (node = route_top (rip_enable_network); node; node = route_next (node))
1788 if (node->info)
1789 vty_out (vty, "%s%s/%d%s",
1790 config_mode ? " network " : " ",
1791 inet_ntoa (node->p.u.prefix4),
1792 node->p.prefixlen,
1793 VTY_NEWLINE);
1794
1795 /* Interface name RIP enable statement. */
1796 for (i = 0; i < vector_max (rip_enable_interface); i++)
1797 if ((ifname = vector_slot (rip_enable_interface, i)) != NULL)
1798 vty_out (vty, "%s%s%s",
1799 config_mode ? " network " : " ",
1800 ifname,
1801 VTY_NEWLINE);
1802
1803 /* RIP neighbors listing. */
1804 for (node = route_top (rip->neighbor); node; node = route_next (node))
1805 if (node->info)
1806 vty_out (vty, "%s%s%s",
1807 config_mode ? " neighbor " : " ",
1808 inet_ntoa (node->p.u.prefix4),
1809 VTY_NEWLINE);
1810
1811 /* RIP passive interface listing. */
1812 if (config_mode)
1813 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1814 if ((ifname = vector_slot (Vrip_passive_interface, i)) != NULL)
1815 vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE);
1816
1817 return 0;
1818}
1819
1820struct cmd_node interface_node =
1821{
1822 INTERFACE_NODE,
1823 "%s(config-if)# ",
1824 1,
1825};
1826
1827/* Called when interface structure allocated. */
1828int
1829rip_interface_new_hook (struct interface *ifp)
1830{
1831 ifp->info = rip_interface_new ();
1832 return 0;
1833}
1834
1835/* Called when interface structure deleted. */
1836int
1837rip_interface_delete_hook (struct interface *ifp)
1838{
1839 XFREE (MTYPE_RIP_INTERFACE, ifp->info);
1840 return 0;
1841}
1842
1843/* Allocate and initialize interface vector. */
1844void
1845rip_if_init ()
1846{
1847 /* Default initial size of interface vector. */
1848 if_init();
1849 if_add_hook (IF_NEW_HOOK, rip_interface_new_hook);
1850 if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook);
1851
1852 /* RIP network init. */
1853 rip_enable_interface = vector_init (1);
1854 rip_enable_network = route_table_init ();
1855
1856 /* RIP passive interface. */
1857 Vrip_passive_interface = vector_init (1);
1858
1859 /* Install interface node. */
1860 install_node (&interface_node, rip_interface_config_write);
1861
1862 /* Install commands. */
1863 install_element (CONFIG_NODE, &interface_cmd);
1864 install_default (INTERFACE_NODE);
1865 install_element (INTERFACE_NODE, &interface_desc_cmd);
1866 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1867 install_element (RIP_NODE, &rip_network_cmd);
1868 install_element (RIP_NODE, &no_rip_network_cmd);
1869 install_element (RIP_NODE, &rip_neighbor_cmd);
1870 install_element (RIP_NODE, &no_rip_neighbor_cmd);
1871
1872 install_element (RIP_NODE, &rip_passive_interface_cmd);
1873 install_element (RIP_NODE, &no_rip_passive_interface_cmd);
1874
1875 install_element (INTERFACE_NODE, &ip_rip_send_version_cmd);
1876 install_element (INTERFACE_NODE, &ip_rip_send_version_1_cmd);
1877 install_element (INTERFACE_NODE, &ip_rip_send_version_2_cmd);
1878 install_element (INTERFACE_NODE, &no_ip_rip_send_version_cmd);
1879 install_element (INTERFACE_NODE, &no_ip_rip_send_version_num_cmd);
1880
1881 install_element (INTERFACE_NODE, &ip_rip_receive_version_cmd);
1882 install_element (INTERFACE_NODE, &ip_rip_receive_version_1_cmd);
1883 install_element (INTERFACE_NODE, &ip_rip_receive_version_2_cmd);
1884 install_element (INTERFACE_NODE, &no_ip_rip_receive_version_cmd);
1885 install_element (INTERFACE_NODE, &no_ip_rip_receive_version_num_cmd);
1886
1887 install_element (INTERFACE_NODE, &ip_rip_authentication_mode_cmd);
1888 install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd);
1889 install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_type_cmd);
1890
1891 install_element (INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd);
1892 install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain_cmd);
1893 install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain2_cmd);
1894
1895 install_element (INTERFACE_NODE, &ip_rip_authentication_string_cmd);
1896 install_element (INTERFACE_NODE, &no_ip_rip_authentication_string_cmd);
1897 install_element (INTERFACE_NODE, &no_ip_rip_authentication_string2_cmd);
1898
1899 install_element (INTERFACE_NODE, &rip_split_horizon_cmd);
1900 install_element (INTERFACE_NODE, &no_rip_split_horizon_cmd);
1901}