]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_interface.c
Initial revision
[mirror_frr.git] / ripd / rip_interface.c
1 /* 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
43 void rip_enable_apply (struct interface *);
44 void rip_passive_interface_apply (struct interface *);
45 int rip_if_down(struct interface *ifp);
46
47 struct 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. */
56 vector rip_enable_interface;
57
58 /* RIP enabled interface table. */
59 struct route_table *rip_enable_network;
60
61 /* Vector to store passive-interface name. */
62 vector Vrip_passive_interface;
63 \f
64 /* Join to the RIP version 2 multicast group. */
65 int
66 ipv4_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. */
87 int
88 ipv4_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 \f
107 /* Allocate new RIP's interface configuration. */
108 struct rip_interface *
109 rip_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
131 void
132 rip_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. */
191 void
192 rip_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. */
241 void
242 rip_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. */
251 if (! if_is_up (ifp))
252 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. */
278 void
279 rip_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. */
291 void
292 rip_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. */
309 int
310 rip_multicast_join (struct interface *ifp, int sock)
311 {
312 listnode cnode;
313
314 if (if_is_up (ifp) && if_is_multicast (ifp))
315 {
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. */
342 void
343 rip_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 ? */
372 int
373 rip_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 }
394
395
396
397
398 /* Does this address belongs to me ? */
399 int
400 if_check_address (struct in_addr addr)
401 {
402 listnode node;
403
404 for (node = listhead (iflist); node; nextnode (node))
405 {
406 listnode cnode;
407 struct interface *ifp;
408
409 ifp = getdata (node);
410
411 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
412 {
413 struct connected *connected;
414 struct prefix_ipv4 *p;
415
416 connected = getdata (cnode);
417 p = (struct prefix_ipv4 *) connected->address;
418
419 if (p->family != AF_INET)
420 continue;
421
422 if (IPV4_ADDR_CMP (&p->prefix, &addr) == 0)
423 return 1;
424 }
425 }
426 return 0;
427 }
428
429 /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */
430 int
431 if_valid_neighbor (struct in_addr addr)
432 {
433 listnode node;
434 struct connected *connected = NULL;
435 struct prefix_ipv4 *p;
436
437 for (node = listhead (iflist); node; nextnode (node))
438 {
439 listnode cnode;
440 struct interface *ifp;
441
442 ifp = getdata (node);
443
444 for (cnode = listhead (ifp->connected); cnode; nextnode (cnode))
445 {
446 struct prefix *pxn = NULL; /* Prefix of the neighbor */
447 struct prefix *pxc = NULL; /* Prefix of the connected network */
448
449 connected = getdata (cnode);
450
451 if (if_is_pointopoint (ifp))
452 {
453 p = (struct prefix_ipv4 *) connected->address;
454
455 if (p && p->family == AF_INET)
456 {
457 if (IPV4_ADDR_SAME (&p->prefix, &addr))
458 return 1;
459
460 p = (struct prefix_ipv4 *) connected->destination;
461 if (p && IPV4_ADDR_SAME (&p->prefix, &addr))
462 return 1;
463 }
464 }
465 else
466 {
467 p = (struct prefix_ipv4 *) connected->address;
468
469 if (p->family != AF_INET)
470 continue;
471
472 pxn = prefix_new();
473 pxn->family = AF_INET;
474 pxn->prefixlen = 32;
475 pxn->u.prefix4 = addr;
476
477 pxc = prefix_new();
478 prefix_copy(pxc, (struct prefix *) p);
479 apply_mask(pxc);
480
481 if (prefix_match (pxc, pxn))
482 {
483 prefix_free (pxn);
484 prefix_free (pxc);
485 return 1;
486 }
487 prefix_free(pxc);
488 prefix_free(pxn);
489 }
490 }
491 }
492 return 0;
493 }
494
495 /* Inteface link down message processing. */
496 int
497 rip_interface_down (int command, struct zclient *zclient, zebra_size_t length)
498 {
499 struct interface *ifp;
500 struct stream *s;
501
502 s = zclient->ibuf;
503
504 /* zebra_interface_state_read() updates interface structure in
505 iflist. */
506 ifp = zebra_interface_state_read(s);
507
508 if (ifp == NULL)
509 return 0;
510
511 rip_if_down(ifp);
512
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);
516
517 return 0;
518 }
519
520 /* Inteface link up message processing */
521 int
522 rip_interface_up (int command, struct zclient *zclient, zebra_size_t length)
523 {
524 struct interface *ifp;
525
526 /* zebra_interface_state_read () updates interface structure in
527 iflist. */
528 ifp = zebra_interface_state_read (zclient->ibuf);
529
530 if (ifp == NULL)
531 return 0;
532
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);
536
537 /* Check if this interface is RIP enabled or not.*/
538 rip_enable_apply (ifp);
539
540 /* Check for a passive interface */
541 rip_passive_interface_apply (ifp);
542
543 /* Apply distribute list to the all interface. */
544 rip_distribute_update_interface (ifp);
545
546 return 0;
547 }
548
549 /* Inteface addition message from zebra. */
550 int
551 rip_interface_add (int command, struct zclient *zclient, zebra_size_t length)
552 {
553 struct interface *ifp;
554
555 ifp = zebra_interface_add_read (zclient->ibuf);
556
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);
560
561 /* Check if this interface is RIP enabled or not.*/
562 rip_enable_apply (ifp);
563
564 /* Apply distribute list to the all interface. */
565 rip_distribute_update_interface (ifp);
566
567 /* rip_request_neighbor_all (); */
568
569 return 0;
570 }
571
572 int
573 rip_interface_delete (int command, struct zclient *zclient,
574 zebra_size_t length)
575 {
576 struct interface *ifp;
577 struct stream *s;
578
579
580 s = zclient->ibuf;
581 /* zebra_interface_state_read() updates interface structure in iflist */
582 ifp = zebra_interface_state_read(s);
583
584 if (ifp == NULL)
585 return 0;
586
587 if (if_is_up (ifp)) {
588 rip_if_down(ifp);
589 }
590
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);
593
594 /* To support pseudo interface do not free interface structure. */
595 /* if_delete(ifp); */
596
597 return 0;
598 }
599
600 void
601 rip_interface_clean ()
602 {
603 listnode node;
604 struct interface *ifp;
605 struct rip_interface *ri;
606
607 for (node = listhead (iflist); node; nextnode (node))
608 {
609 ifp = getdata (node);
610 ri = ifp->info;
611
612 ri->enable_network = 0;
613 ri->enable_interface = 0;
614 ri->running = 0;
615
616 if (ri->t_wakeup)
617 {
618 thread_cancel (ri->t_wakeup);
619 ri->t_wakeup = NULL;
620 }
621 }
622 }
623
624 void
625 rip_interface_reset ()
626 {
627 listnode node;
628 struct interface *ifp;
629 struct rip_interface *ri;
630
631 for (node = listhead (iflist); node; nextnode (node))
632 {
633 ifp = getdata (node);
634 ri = ifp->info;
635
636 ri->enable_network = 0;
637 ri->enable_interface = 0;
638 ri->running = 0;
639
640 ri->ri_send = RI_RIP_UNSPEC;
641 ri->ri_receive = RI_RIP_UNSPEC;
642
643 /* ri->auth_type = RIP_NO_AUTH; */
644 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
645
646 if (ri->auth_str)
647 {
648 free (ri->auth_str);
649 ri->auth_str = NULL;
650 }
651 if (ri->key_chain)
652 {
653 free (ri->key_chain);
654 ri->key_chain = NULL;
655 }
656
657 ri->split_horizon = 0;
658 ri->split_horizon_default = 0;
659
660 ri->list[RIP_FILTER_IN] = NULL;
661 ri->list[RIP_FILTER_OUT] = NULL;
662
663 ri->prefix[RIP_FILTER_IN] = NULL;
664 ri->prefix[RIP_FILTER_OUT] = NULL;
665
666 if (ri->t_wakeup)
667 {
668 thread_cancel (ri->t_wakeup);
669 ri->t_wakeup = NULL;
670 }
671
672 ri->recv_badpackets = 0;
673 ri->recv_badroutes = 0;
674 ri->sent_updates = 0;
675
676 ri->passive = 0;
677 }
678 }
679
680 int
681 rip_if_down(struct interface *ifp)
682 {
683 struct route_node *rp;
684 struct rip_info *rinfo;
685 struct rip_interface *ri = NULL;
686 if (rip)
687 {
688 for (rp = route_top (rip->table); rp; rp = route_next (rp))
689 if ((rinfo = rp->info) != NULL)
690 {
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)
695 {
696 rip_zebra_ipv4_delete ((struct prefix_ipv4 *) &rp->p,
697 &rinfo->nexthop,
698 rinfo->ifindex);
699
700 rip_redistribute_delete (rinfo->type,rinfo->sub_type,
701 (struct prefix_ipv4 *)&rp->p,
702 rinfo->ifindex);
703 }
704 else
705 {
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,
712 rinfo->ifindex);
713 }
714 }
715 }
716
717 ri = ifp->info;
718
719 if (ri->running)
720 {
721 if (IS_RIP_DEBUG_EVENT)
722 zlog_info ("turn off %s", ifp->name);
723
724 /* Leave from multicast group. */
725 rip_multicast_leave (ifp, rip->sock);
726
727 ri->running = 0;
728 }
729
730 return 0;
731 }
732
733 /* Needed for stop RIP process. */
734 void
735 rip_if_down_all ()
736 {
737 struct interface *ifp;
738 listnode node;
739
740 for (node = listhead (iflist); node; nextnode (node))
741 {
742 ifp = getdata (node);
743 rip_if_down (ifp);
744 }
745 }
746
747 int
748 rip_interface_address_add (int command, struct zclient *zclient,
749 zebra_size_t length)
750 {
751 struct connected *ifc;
752 struct prefix *p;
753
754 ifc = zebra_interface_address_add_read (zclient->ibuf);
755
756 if (ifc == NULL)
757 return 0;
758
759 p = ifc->address;
760
761 if (p->family == AF_INET)
762 {
763 if (IS_RIP_DEBUG_ZEBRA)
764 zlog_info ("connected address %s/%d is added",
765 inet_ntoa (p->u.prefix4), p->prefixlen);
766
767 /* Check is this interface is RIP enabled or not.*/
768 rip_enable_apply (ifc->ifp);
769
770 #ifdef HAVE_SNMP
771 rip_ifaddr_add (ifc->ifp, ifc);
772 #endif /* HAVE_SNMP */
773 }
774
775 return 0;
776 }
777
778 int
779 rip_interface_address_delete (int command, struct zclient *zclient,
780 zebra_size_t length)
781 {
782 struct connected *ifc;
783 struct prefix *p;
784
785 ifc = zebra_interface_address_delete_read (zclient->ibuf);
786
787 if (ifc)
788 {
789 p = ifc->address;
790 if (p->family == AF_INET)
791 {
792 if (IS_RIP_DEBUG_ZEBRA)
793
794 zlog_info ("connected address %s/%d is deleted",
795 inet_ntoa (p->u.prefix4), p->prefixlen);
796
797 #ifdef HAVE_SNMP
798 rip_ifaddr_delete (ifc->ifp, ifc);
799 #endif /* HAVE_SNMP */
800
801 /* Check if this interface is RIP enabled or not.*/
802 rip_enable_apply (ifc->ifp);
803 }
804
805 connected_free (ifc);
806
807 }
808
809 return 0;
810 }
811 \f
812 /* Check interface is enabled by network statement. */
813 int
814 rip_enable_network_lookup (struct interface *ifp)
815 {
816 struct listnode *nn;
817 struct connected *connected;
818 struct prefix_ipv4 address;
819
820 for (nn = listhead (ifp->connected); nn; nextnode (nn))
821 if ((connected = getdata (nn)) != NULL)
822 {
823 struct prefix *p;
824 struct route_node *node;
825
826 p = connected->address;
827
828 if (p->family == AF_INET)
829 {
830 address.family = AF_INET;
831 address.prefix = p->u.prefix4;
832 address.prefixlen = IPV4_MAX_BITLEN;
833
834 node = route_node_match (rip_enable_network,
835 (struct prefix *)&address);
836 if (node)
837 {
838 route_unlock_node (node);
839 return 1;
840 }
841 }
842 }
843 return -1;
844 }
845
846 /* Add RIP enable network. */
847 int
848 rip_enable_network_add (struct prefix *p)
849 {
850 struct route_node *node;
851
852 node = route_node_get (rip_enable_network, p);
853
854 if (node->info)
855 {
856 route_unlock_node (node);
857 return -1;
858 }
859 else
860 node->info = "enabled";
861
862 return 1;
863 }
864
865 /* Delete RIP enable network. */
866 int
867 rip_enable_network_delete (struct prefix *p)
868 {
869 struct route_node *node;
870
871 node = route_node_lookup (rip_enable_network, p);
872 if (node)
873 {
874 node->info = NULL;
875
876 /* Unlock info lock. */
877 route_unlock_node (node);
878
879 /* Unlock lookup lock. */
880 route_unlock_node (node);
881
882 return 1;
883 }
884 return -1;
885 }
886
887 /* Check interface is enabled by ifname statement. */
888 int
889 rip_enable_if_lookup (char *ifname)
890 {
891 int i;
892 char *str;
893
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)
897 return i;
898 return -1;
899 }
900
901 /* Add interface to rip_enable_if. */
902 int
903 rip_enable_if_add (char *ifname)
904 {
905 int ret;
906
907 ret = rip_enable_if_lookup (ifname);
908 if (ret >= 0)
909 return -1;
910
911 vector_set (rip_enable_interface, strdup (ifname));
912
913 return 1;
914 }
915
916 /* Delete interface from rip_enable_if. */
917 int
918 rip_enable_if_delete (char *ifname)
919 {
920 int index;
921 char *str;
922
923 index = rip_enable_if_lookup (ifname);
924 if (index < 0)
925 return -1;
926
927 str = vector_slot (rip_enable_interface, index);
928 free (str);
929 vector_unset (rip_enable_interface, index);
930
931 return 1;
932 }
933
934 /* Join to multicast group and send request to the interface. */
935 int
936 rip_interface_wakeup (struct thread *t)
937 {
938 struct interface *ifp;
939 struct rip_interface *ri;
940
941 /* Get interface. */
942 ifp = THREAD_ARG (t);
943
944 ri = ifp->info;
945 ri->t_wakeup = NULL;
946
947 /* Join to multicast group. */
948 if (rip_multicast_join (ifp, rip->sock) < 0)
949 {
950 zlog_err ("multicast join failed, interface %s not running", ifp->name);
951 return 0;
952 }
953
954 /* Set running flag. */
955 ri->running = 1;
956
957 /* Send RIP request to the interface. */
958 rip_request_interface (ifp);
959
960 return 0;
961 }
962
963 int rip_redistribute_check (int);
964
965 void
966 rip_connect_set (struct interface *ifp, int set)
967 {
968 struct listnode *nn;
969 struct connected *connected;
970 struct prefix_ipv4 address;
971
972 for (nn = listhead (ifp->connected); nn; nextnode (nn))
973 if ((connected = getdata (nn)) != NULL)
974 {
975 struct prefix *p;
976 p = connected->address;
977
978 if (p->family != AF_INET)
979 continue;
980
981 address.family = AF_INET;
982 address.prefix = p->u.prefix4;
983 address.prefixlen = p->prefixlen;
984 apply_mask_ipv4 (&address);
985
986 if (set)
987 rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
988 &address, connected->ifp->ifindex, NULL);
989 else
990 {
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);
996 }
997 }
998 }
999
1000 /* Update interface status. */
1001 void
1002 rip_enable_apply (struct interface *ifp)
1003 {
1004 int ret;
1005 struct rip_interface *ri = NULL;
1006
1007 /* Check interface. */
1008 if (if_is_loopback (ifp))
1009 return;
1010
1011 if (! if_is_up (ifp))
1012 return;
1013
1014 ri = ifp->info;
1015
1016 /* Check network configuration. */
1017 ret = rip_enable_network_lookup (ifp);
1018
1019 /* If the interface is matched. */
1020 if (ret > 0)
1021 ri->enable_network = 1;
1022 else
1023 ri->enable_network = 0;
1024
1025 /* Check interface name configuration. */
1026 ret = rip_enable_if_lookup (ifp->name);
1027 if (ret >= 0)
1028 ri->enable_interface = 1;
1029 else
1030 ri->enable_interface = 0;
1031
1032 /* any interface MUST have an IPv4 address */
1033 if ( ! rip_if_ipv4_address_check (ifp) )
1034 {
1035 ri->enable_network = 0;
1036 ri->enable_interface = 0;
1037 }
1038
1039 /* Update running status of the interface. */
1040 if (ri->enable_network || ri->enable_interface)
1041 {
1042 if (! ri->running)
1043 {
1044 if (IS_RIP_DEBUG_EVENT)
1045 zlog_info ("turn on %s", ifp->name);
1046
1047 /* Add interface wake up thread. */
1048 if (! ri->t_wakeup)
1049 ri->t_wakeup = thread_add_timer (master, rip_interface_wakeup,
1050 ifp, 1);
1051 rip_connect_set (ifp, 1);
1052 }
1053 }
1054 else
1055 {
1056 if (ri->running)
1057 {
1058 if (IS_RIP_DEBUG_EVENT)
1059 zlog_info ("turn off %s", ifp->name);
1060
1061 /* Might as well clean up the route table as well */
1062 rip_if_down(ifp);
1063
1064 ri->running = 0;
1065 rip_connect_set (ifp, 0);
1066 }
1067 }
1068 }
1069
1070 /* Apply network configuration to all interface. */
1071 void
1072 rip_enable_apply_all ()
1073 {
1074 struct interface *ifp;
1075 listnode node;
1076
1077 /* Check each interface. */
1078 for (node = listhead (iflist); node; nextnode (node))
1079 {
1080 ifp = getdata (node);
1081 rip_enable_apply (ifp);
1082 }
1083 }
1084
1085 int
1086 rip_neighbor_lookup (struct sockaddr_in *from)
1087 {
1088 struct prefix_ipv4 p;
1089 struct route_node *node;
1090
1091 memset (&p, 0, sizeof (struct prefix_ipv4));
1092 p.family = AF_INET;
1093 p.prefix = from->sin_addr;
1094 p.prefixlen = IPV4_MAX_BITLEN;
1095
1096 node = route_node_lookup (rip->neighbor, (struct prefix *) &p);
1097 if (node)
1098 {
1099 route_unlock_node (node);
1100 return 1;
1101 }
1102 return 0;
1103 }
1104
1105 /* Add new RIP neighbor to the neighbor tree. */
1106 int
1107 rip_neighbor_add (struct prefix_ipv4 *p)
1108 {
1109 struct route_node *node;
1110
1111 node = route_node_get (rip->neighbor, (struct prefix *) p);
1112
1113 if (node->info)
1114 return -1;
1115
1116 node->info = rip->neighbor;
1117
1118 return 0;
1119 }
1120
1121 /* Delete RIP neighbor from the neighbor tree. */
1122 int
1123 rip_neighbor_delete (struct prefix_ipv4 *p)
1124 {
1125 struct route_node *node;
1126
1127 /* Lock for look up. */
1128 node = route_node_lookup (rip->neighbor, (struct prefix *) p);
1129 if (! node)
1130 return -1;
1131
1132 node->info = NULL;
1133
1134 /* Unlock lookup lock. */
1135 route_unlock_node (node);
1136
1137 /* Unlock real neighbor information lock. */
1138 route_unlock_node (node);
1139
1140 return 0;
1141 }
1142
1143 /* Clear all network and neighbor configuration. */
1144 void
1145 rip_clean_network ()
1146 {
1147 int i;
1148 char *str;
1149 struct route_node *rn;
1150
1151 /* rip_enable_network. */
1152 for (rn = route_top (rip_enable_network); rn; rn = route_next (rn))
1153 if (rn->info)
1154 {
1155 rn->info = NULL;
1156 route_unlock_node (rn);
1157 }
1158
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)
1162 {
1163 free (str);
1164 vector_slot (rip_enable_interface, i) = NULL;
1165 }
1166 }
1167 \f
1168 /* Utility function for looking up passive interface settings. */
1169 int
1170 rip_passive_interface_lookup (char *ifname)
1171 {
1172 int i;
1173 char *str;
1174
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)
1178 return i;
1179 return -1;
1180 }
1181
1182 void
1183 rip_passive_interface_apply (struct interface *ifp)
1184 {
1185 int ret;
1186 struct rip_interface *ri;
1187
1188 ri = ifp->info;
1189
1190 ret = rip_passive_interface_lookup (ifp->name);
1191 if (ret < 0)
1192 ri->passive = 0;
1193 else
1194 ri->passive = 1;
1195 }
1196
1197 void
1198 rip_passive_interface_apply_all ()
1199 {
1200 struct interface *ifp;
1201 listnode node;
1202
1203 for (node = listhead (iflist); node; nextnode (node))
1204 {
1205 ifp = getdata (node);
1206 rip_passive_interface_apply (ifp);
1207 }
1208 }
1209
1210 /* Passive interface. */
1211 int
1212 rip_passive_interface_set (struct vty *vty, char *ifname)
1213 {
1214 if (rip_passive_interface_lookup (ifname) >= 0)
1215 return CMD_WARNING;
1216
1217 vector_set (Vrip_passive_interface, strdup (ifname));
1218
1219 rip_passive_interface_apply_all ();
1220
1221 return CMD_SUCCESS;
1222 }
1223
1224 int
1225 rip_passive_interface_unset (struct vty *vty, char *ifname)
1226 {
1227 int i;
1228 char *str;
1229
1230 i = rip_passive_interface_lookup (ifname);
1231 if (i < 0)
1232 return CMD_WARNING;
1233
1234 str = vector_slot (Vrip_passive_interface, i);
1235 free (str);
1236 vector_unset (Vrip_passive_interface, i);
1237
1238 rip_passive_interface_apply_all ();
1239
1240 return CMD_SUCCESS;
1241 }
1242
1243 /* Free all configured RIP passive-interface settings. */
1244 void
1245 rip_passive_interface_clean ()
1246 {
1247 int i;
1248 char *str;
1249
1250 for (i = 0; i < vector_max (Vrip_passive_interface); i++)
1251 if ((str = vector_slot (Vrip_passive_interface, i)) != NULL)
1252 {
1253 free (str);
1254 vector_slot (Vrip_passive_interface, i) = NULL;
1255 }
1256 rip_passive_interface_apply_all ();
1257 }
1258 \f
1259 /* RIP enable network or interface configuration. */
1260 DEFUN (rip_network,
1261 rip_network_cmd,
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"
1265 "Interface name\n")
1266 {
1267 int ret;
1268 struct prefix_ipv4 p;
1269
1270 ret = str2prefix_ipv4 (argv[0], &p);
1271
1272 if (ret)
1273 ret = rip_enable_network_add ((struct prefix *) &p);
1274 else
1275 ret = rip_enable_if_add (argv[0]);
1276
1277 if (ret < 0)
1278 {
1279 vty_out (vty, "There is a same network configuration %s%s", argv[0],
1280 VTY_NEWLINE);
1281 return CMD_WARNING;
1282 }
1283
1284 rip_enable_apply_all ();
1285
1286 return CMD_SUCCESS;
1287 }
1288
1289 /* RIP enable network or interface configuration. */
1290 DEFUN (no_rip_network,
1291 no_rip_network_cmd,
1292 "no network (A.B.C.D/M|WORD)",
1293 NO_STR
1294 "Enable routing on an IP network\n"
1295 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1296 "Interface name\n")
1297 {
1298 int ret;
1299 struct prefix_ipv4 p;
1300
1301 ret = str2prefix_ipv4 (argv[0], &p);
1302
1303 if (ret)
1304 ret = rip_enable_network_delete ((struct prefix *) &p);
1305 else
1306 ret = rip_enable_if_delete (argv[0]);
1307
1308 if (ret < 0)
1309 {
1310 vty_out (vty, "Can't find network configuration %s%s", argv[0],
1311 VTY_NEWLINE);
1312 return CMD_WARNING;
1313 }
1314
1315 rip_enable_apply_all ();
1316
1317 return CMD_SUCCESS;
1318 }
1319
1320 /* RIP neighbor configuration set. */
1321 DEFUN (rip_neighbor,
1322 rip_neighbor_cmd,
1323 "neighbor A.B.C.D",
1324 "Specify a neighbor router\n"
1325 "Neighbor address\n")
1326 {
1327 int ret;
1328 struct prefix_ipv4 p;
1329
1330 ret = str2prefix_ipv4 (argv[0], &p);
1331
1332 if (ret <= 0)
1333 {
1334 vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
1335 return CMD_WARNING;
1336 }
1337
1338 rip_neighbor_add (&p);
1339
1340 return CMD_SUCCESS;
1341 }
1342
1343 /* RIP neighbor configuration unset. */
1344 DEFUN (no_rip_neighbor,
1345 no_rip_neighbor_cmd,
1346 "no neighbor A.B.C.D",
1347 NO_STR
1348 "Specify a neighbor router\n"
1349 "Neighbor address\n")
1350 {
1351 int ret;
1352 struct prefix_ipv4 p;
1353
1354 ret = str2prefix_ipv4 (argv[0], &p);
1355
1356 if (ret <= 0)
1357 {
1358 vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE);
1359 return CMD_WARNING;
1360 }
1361
1362 rip_neighbor_delete (&p);
1363
1364 return CMD_SUCCESS;
1365 }
1366
1367 DEFUN (ip_rip_receive_version,
1368 ip_rip_receive_version_cmd,
1369 "ip rip receive version (1|2)",
1370 IP_STR
1371 "Routing Information Protocol\n"
1372 "Advertisement reception\n"
1373 "Version control\n"
1374 "RIP version 1\n"
1375 "RIP version 2\n")
1376 {
1377 struct interface *ifp;
1378 struct rip_interface *ri;
1379
1380 ifp = (struct interface *)vty->index;
1381 ri = ifp->info;
1382
1383 /* Version 1. */
1384 if (atoi (argv[0]) == 1)
1385 {
1386 ri->ri_receive = RI_RIP_VERSION_1;
1387 return CMD_SUCCESS;
1388 }
1389 if (atoi (argv[0]) == 2)
1390 {
1391 ri->ri_receive = RI_RIP_VERSION_2;
1392 return CMD_SUCCESS;
1393 }
1394 return CMD_WARNING;
1395 }
1396
1397 DEFUN (ip_rip_receive_version_1,
1398 ip_rip_receive_version_1_cmd,
1399 "ip rip receive version 1 2",
1400 IP_STR
1401 "Routing Information Protocol\n"
1402 "Advertisement reception\n"
1403 "Version control\n"
1404 "RIP version 1\n"
1405 "RIP version 2\n")
1406 {
1407 struct interface *ifp;
1408 struct rip_interface *ri;
1409
1410 ifp = (struct interface *)vty->index;
1411 ri = ifp->info;
1412
1413 /* Version 1 and 2. */
1414 ri->ri_receive = RI_RIP_VERSION_1_AND_2;
1415 return CMD_SUCCESS;
1416 }
1417
1418 DEFUN (ip_rip_receive_version_2,
1419 ip_rip_receive_version_2_cmd,
1420 "ip rip receive version 2 1",
1421 IP_STR
1422 "Routing Information Protocol\n"
1423 "Advertisement reception\n"
1424 "Version control\n"
1425 "RIP version 2\n"
1426 "RIP version 1\n")
1427 {
1428 struct interface *ifp;
1429 struct rip_interface *ri;
1430
1431 ifp = (struct interface *)vty->index;
1432 ri = ifp->info;
1433
1434 /* Version 1 and 2. */
1435 ri->ri_receive = RI_RIP_VERSION_1_AND_2;
1436 return CMD_SUCCESS;
1437 }
1438
1439 DEFUN (no_ip_rip_receive_version,
1440 no_ip_rip_receive_version_cmd,
1441 "no ip rip receive version",
1442 NO_STR
1443 IP_STR
1444 "Routing Information Protocol\n"
1445 "Advertisement reception\n"
1446 "Version control\n")
1447 {
1448 struct interface *ifp;
1449 struct rip_interface *ri;
1450
1451 ifp = (struct interface *)vty->index;
1452 ri = ifp->info;
1453
1454 ri->ri_receive = RI_RIP_UNSPEC;
1455 return CMD_SUCCESS;
1456 }
1457
1458 ALIAS (no_ip_rip_receive_version,
1459 no_ip_rip_receive_version_num_cmd,
1460 "no ip rip receive version (1|2)",
1461 NO_STR
1462 IP_STR
1463 "Routing Information Protocol\n"
1464 "Advertisement reception\n"
1465 "Version control\n"
1466 "Version 1\n"
1467 "Version 2\n")
1468
1469 DEFUN (ip_rip_send_version,
1470 ip_rip_send_version_cmd,
1471 "ip rip send version (1|2)",
1472 IP_STR
1473 "Routing Information Protocol\n"
1474 "Advertisement transmission\n"
1475 "Version control\n"
1476 "RIP version 1\n"
1477 "RIP version 2\n")
1478 {
1479 struct interface *ifp;
1480 struct rip_interface *ri;
1481
1482 ifp = (struct interface *)vty->index;
1483 ri = ifp->info;
1484
1485 /* Version 1. */
1486 if (atoi (argv[0]) == 1)
1487 {
1488 ri->ri_send = RI_RIP_VERSION_1;
1489 return CMD_SUCCESS;
1490 }
1491 if (atoi (argv[0]) == 2)
1492 {
1493 ri->ri_send = RI_RIP_VERSION_2;
1494 return CMD_SUCCESS;
1495 }
1496 return CMD_WARNING;
1497 }
1498
1499 DEFUN (ip_rip_send_version_1,
1500 ip_rip_send_version_1_cmd,
1501 "ip rip send version 1 2",
1502 IP_STR
1503 "Routing Information Protocol\n"
1504 "Advertisement transmission\n"
1505 "Version control\n"
1506 "RIP version 1\n"
1507 "RIP version 2\n")
1508 {
1509 struct interface *ifp;
1510 struct rip_interface *ri;
1511
1512 ifp = (struct interface *)vty->index;
1513 ri = ifp->info;
1514
1515 /* Version 1 and 2. */
1516 ri->ri_send = RI_RIP_VERSION_1_AND_2;
1517 return CMD_SUCCESS;
1518 }
1519
1520 DEFUN (ip_rip_send_version_2,
1521 ip_rip_send_version_2_cmd,
1522 "ip rip send version 2 1",
1523 IP_STR
1524 "Routing Information Protocol\n"
1525 "Advertisement transmission\n"
1526 "Version control\n"
1527 "RIP version 2\n"
1528 "RIP version 1\n")
1529 {
1530 struct interface *ifp;
1531 struct rip_interface *ri;
1532
1533 ifp = (struct interface *)vty->index;
1534 ri = ifp->info;
1535
1536 /* Version 1 and 2. */
1537 ri->ri_send = RI_RIP_VERSION_1_AND_2;
1538 return CMD_SUCCESS;
1539 }
1540
1541 DEFUN (no_ip_rip_send_version,
1542 no_ip_rip_send_version_cmd,
1543 "no ip rip send version",
1544 NO_STR
1545 IP_STR
1546 "Routing Information Protocol\n"
1547 "Advertisement transmission\n"
1548 "Version control\n")
1549 {
1550 struct interface *ifp;
1551 struct rip_interface *ri;
1552
1553 ifp = (struct interface *)vty->index;
1554 ri = ifp->info;
1555
1556 ri->ri_send = RI_RIP_UNSPEC;
1557 return CMD_SUCCESS;
1558 }
1559
1560 ALIAS (no_ip_rip_send_version,
1561 no_ip_rip_send_version_num_cmd,
1562 "no ip rip send version (1|2)",
1563 NO_STR
1564 IP_STR
1565 "Routing Information Protocol\n"
1566 "Advertisement transmission\n"
1567 "Version control\n"
1568 "Version 1\n"
1569 "Version 2\n")
1570
1571 DEFUN (ip_rip_authentication_mode,
1572 ip_rip_authentication_mode_cmd,
1573 "ip rip authentication mode (md5|text)",
1574 IP_STR
1575 "Routing Information Protocol\n"
1576 "Authentication control\n"
1577 "Authentication mode\n"
1578 "Keyed message digest\n"
1579 "Clear text authentication\n")
1580 {
1581 struct interface *ifp;
1582 struct rip_interface *ri;
1583
1584 ifp = (struct interface *)vty->index;
1585 ri = ifp->info;
1586
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;
1591 else
1592 {
1593 vty_out (vty, "mode should be md5 or text%s", VTY_NEWLINE);
1594 return CMD_WARNING;
1595 }
1596
1597 return CMD_SUCCESS;
1598 }
1599
1600 DEFUN (no_ip_rip_authentication_mode,
1601 no_ip_rip_authentication_mode_cmd,
1602 "no ip rip authentication mode",
1603 NO_STR
1604 IP_STR
1605 "Routing Information Protocol\n"
1606 "Authentication control\n"
1607 "Authentication mode\n")
1608 {
1609 struct interface *ifp;
1610 struct rip_interface *ri;
1611
1612 ifp = (struct interface *)vty->index;
1613 ri = ifp->info;
1614
1615 /* ri->auth_type = RIP_NO_AUTH; */
1616 ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD;
1617
1618 return CMD_SUCCESS;
1619 }
1620
1621 ALIAS (no_ip_rip_authentication_mode,
1622 no_ip_rip_authentication_mode_type_cmd,
1623 "no ip rip authentication mode (md5|text)",
1624 NO_STR
1625 IP_STR
1626 "Routing Information Protocol\n"
1627 "Authentication control\n"
1628 "Authentication mode\n"
1629 "Keyed message digest\n"
1630 "Clear text authentication\n")
1631
1632 DEFUN (ip_rip_authentication_string,
1633 ip_rip_authentication_string_cmd,
1634 "ip rip authentication string LINE",
1635 IP_STR
1636 "Routing Information Protocol\n"
1637 "Authentication control\n"
1638 "Authentication string\n"
1639 "Authentication string\n")
1640 {
1641 struct interface *ifp;
1642 struct rip_interface *ri;
1643
1644 ifp = (struct interface *)vty->index;
1645 ri = ifp->info;
1646
1647 if (strlen (argv[0]) > 16)
1648 {
1649 vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s",
1650 VTY_NEWLINE);
1651 return CMD_WARNING;
1652 }
1653
1654 if (ri->key_chain)
1655 {
1656 vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE);
1657 return CMD_WARNING;
1658 }
1659
1660 if (ri->auth_str)
1661 free (ri->auth_str);
1662
1663 ri->auth_str = strdup (argv[0]);
1664
1665 return CMD_SUCCESS;
1666 }
1667
1668 DEFUN (no_ip_rip_authentication_string,
1669 no_ip_rip_authentication_string_cmd,
1670 "no ip rip authentication string",
1671 NO_STR
1672 IP_STR
1673 "Routing Information Protocol\n"
1674 "Authentication control\n"
1675 "Authentication string\n")
1676 {
1677 struct interface *ifp;
1678 struct rip_interface *ri;
1679
1680 ifp = (struct interface *)vty->index;
1681 ri = ifp->info;
1682
1683 if (ri->auth_str)
1684 free (ri->auth_str);
1685
1686 ri->auth_str = NULL;
1687
1688 return CMD_SUCCESS;
1689 }
1690
1691 ALIAS (no_ip_rip_authentication_string,
1692 no_ip_rip_authentication_string2_cmd,
1693 "no ip rip authentication string LINE",
1694 NO_STR
1695 IP_STR
1696 "Routing Information Protocol\n"
1697 "Authentication control\n"
1698 "Authentication string\n"
1699 "Authentication string\n")
1700
1701 DEFUN (ip_rip_authentication_key_chain,
1702 ip_rip_authentication_key_chain_cmd,
1703 "ip rip authentication key-chain LINE",
1704 IP_STR
1705 "Routing Information Protocol\n"
1706 "Authentication control\n"
1707 "Authentication key-chain\n"
1708 "name of key-chain\n")
1709 {
1710 struct interface *ifp;
1711 struct rip_interface *ri;
1712
1713 ifp = (struct interface *) vty->index;
1714 ri = ifp->info;
1715
1716 if (ri->auth_str)
1717 {
1718 vty_out (vty, "%% authentication string configuration exists%s",
1719 VTY_NEWLINE);
1720 return CMD_WARNING;
1721 }
1722
1723 if (ri->key_chain)
1724 free (ri->key_chain);
1725
1726 ri->key_chain = strdup (argv[0]);
1727
1728 return CMD_SUCCESS;
1729 }
1730
1731 DEFUN (no_ip_rip_authentication_key_chain,
1732 no_ip_rip_authentication_key_chain_cmd,
1733 "no ip rip authentication key-chain",
1734 NO_STR
1735 IP_STR
1736 "Routing Information Protocol\n"
1737 "Authentication control\n"
1738 "Authentication key-chain\n")
1739 {
1740 struct interface *ifp;
1741 struct rip_interface *ri;
1742
1743 ifp = (struct interface *) vty->index;
1744 ri = ifp->info;
1745
1746 if (ri->key_chain)
1747 free (ri->key_chain);
1748
1749 ri->key_chain = NULL;
1750
1751 return CMD_SUCCESS;
1752 }
1753
1754 ALIAS (no_ip_rip_authentication_key_chain,
1755 no_ip_rip_authentication_key_chain2_cmd,
1756 "no ip rip authentication key-chain LINE",
1757 NO_STR
1758 IP_STR
1759 "Routing Information Protocol\n"
1760 "Authentication control\n"
1761 "Authentication key-chain\n"
1762 "name of key-chain\n")
1763
1764 DEFUN (rip_split_horizon,
1765 rip_split_horizon_cmd,
1766 "ip split-horizon",
1767 IP_STR
1768 "Perform split horizon\n")
1769 {
1770 struct interface *ifp;
1771 struct rip_interface *ri;
1772
1773 ifp = vty->index;
1774 ri = ifp->info;
1775
1776 ri->split_horizon = 1;
1777 return CMD_SUCCESS;
1778 }
1779
1780 DEFUN (no_rip_split_horizon,
1781 no_rip_split_horizon_cmd,
1782 "no ip split-horizon",
1783 NO_STR
1784 IP_STR
1785 "Perform split horizon\n")
1786 {
1787 struct interface *ifp;
1788 struct rip_interface *ri;
1789
1790 ifp = vty->index;
1791 ri = ifp->info;
1792
1793 ri->split_horizon = 0;
1794 return CMD_SUCCESS;
1795 }
1796
1797 DEFUN (rip_passive_interface,
1798 rip_passive_interface_cmd,
1799 "passive-interface IFNAME",
1800 "Suppress routing updates on an interface\n"
1801 "Interface name\n")
1802 {
1803 return rip_passive_interface_set (vty, argv[0]);
1804 }
1805
1806 DEFUN (no_rip_passive_interface,
1807 no_rip_passive_interface_cmd,
1808 "no passive-interface IFNAME",
1809 NO_STR
1810 "Suppress routing updates on an interface\n"
1811 "Interface name\n")
1812 {
1813 return rip_passive_interface_unset (vty, argv[0]);
1814 }
1815 \f
1816 /* Write rip configuration of each interface. */
1817 int
1818 rip_interface_config_write (struct vty *vty)
1819 {
1820 listnode node;
1821 struct interface *ifp;
1822
1823 for (node = listhead (iflist); node; nextnode (node))
1824 {
1825 struct rip_interface *ri;
1826
1827 ifp = getdata (node);
1828 ri = ifp->info;
1829
1830 vty_out (vty, "interface %s%s", ifp->name,
1831 VTY_NEWLINE);
1832
1833 if (ifp->desc)
1834 vty_out (vty, " description %s%s", ifp->desc,
1835 VTY_NEWLINE);
1836
1837 /* Split horizon. */
1838 if (ri->split_horizon != ri->split_horizon_default)
1839 {
1840 if (ri->split_horizon)
1841 vty_out (vty, " ip split-horizon%s", VTY_NEWLINE);
1842 else
1843 vty_out (vty, " no ip split-horizon%s", VTY_NEWLINE);
1844 }
1845
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),
1850 VTY_NEWLINE);
1851
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),
1855 VTY_NEWLINE);
1856
1857 /* RIP authentication. */
1858 #if 0
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);
1862 #endif /* 0 */
1863 if (ri->auth_type == RIP_AUTH_MD5)
1864 vty_out (vty, " ip rip authentication mode md5%s", VTY_NEWLINE);
1865
1866 if (ri->auth_str)
1867 vty_out (vty, " ip rip authentication string %s%s",
1868 ri->auth_str, VTY_NEWLINE);
1869
1870 if (ri->key_chain)
1871 vty_out (vty, " ip rip authentication key-chain %s%s",
1872 ri->key_chain, VTY_NEWLINE);
1873
1874 vty_out (vty, "!%s", VTY_NEWLINE);
1875 }
1876 return 0;
1877 }
1878
1879 int
1880 config_write_rip_network (struct vty *vty, int config_mode)
1881 {
1882 int i;
1883 char *ifname;
1884 struct route_node *node;
1885
1886 /* Network type RIP enable interface statement. */
1887 for (node = route_top (rip_enable_network); node; node = route_next (node))
1888 if (node->info)
1889 vty_out (vty, "%s%s/%d%s",
1890 config_mode ? " network " : " ",
1891 inet_ntoa (node->p.u.prefix4),
1892 node->p.prefixlen,
1893 VTY_NEWLINE);
1894
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 " : " ",
1900 ifname,
1901 VTY_NEWLINE);
1902
1903 /* RIP neighbors listing. */
1904 for (node = route_top (rip->neighbor); node; node = route_next (node))
1905 if (node->info)
1906 vty_out (vty, "%s%s%s",
1907 config_mode ? " neighbor " : " ",
1908 inet_ntoa (node->p.u.prefix4),
1909 VTY_NEWLINE);
1910
1911 /* RIP passive interface listing. */
1912 if (config_mode)
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);
1916
1917 return 0;
1918 }
1919
1920 struct cmd_node interface_node =
1921 {
1922 INTERFACE_NODE,
1923 "%s(config-if)# ",
1924 1,
1925 };
1926
1927 /* Called when interface structure allocated. */
1928 int
1929 rip_interface_new_hook (struct interface *ifp)
1930 {
1931 ifp->info = rip_interface_new ();
1932 return 0;
1933 }
1934
1935 /* Called when interface structure deleted. */
1936 int
1937 rip_interface_delete_hook (struct interface *ifp)
1938 {
1939 XFREE (MTYPE_RIP_INTERFACE, ifp->info);
1940 return 0;
1941 }
1942
1943 /* Allocate and initialize interface vector. */
1944 void
1945 rip_if_init ()
1946 {
1947 /* Default initial size of interface vector. */
1948 if_init();
1949 if_add_hook (IF_NEW_HOOK, rip_interface_new_hook);
1950 if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook);
1951
1952 /* RIP network init. */
1953 rip_enable_interface = vector_init (1);
1954 rip_enable_network = route_table_init ();
1955
1956 /* RIP passive interface. */
1957 Vrip_passive_interface = vector_init (1);
1958
1959 /* Install interface node. */
1960 install_node (&interface_node, rip_interface_config_write);
1961
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);
1971
1972 install_element (RIP_NODE, &rip_passive_interface_cmd);
1973 install_element (RIP_NODE, &no_rip_passive_interface_cmd);
1974
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);
1980
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);
1986
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);
1990
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);
1994
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);
1998
1999 install_element (INTERFACE_NODE, &rip_split_horizon_cmd);
2000 install_element (INTERFACE_NODE, &no_rip_split_horizon_cmd);
2001 }