2 * Interface related function for RIPng.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 #include "ripngd/ripngd.h"
40 #include "ripngd/ripng_debug.h"
42 /* If RFC2133 definition is used. */
43 #ifndef IPV6_JOIN_GROUP
44 #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
46 #ifndef IPV6_LEAVE_GROUP
47 #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
50 /* Static utility function. */
51 static void ripng_enable_apply(struct interface
*);
52 static void ripng_passive_interface_apply(struct interface
*);
53 static int ripng_enable_if_lookup(const char *);
54 static int ripng_enable_network_lookup2(struct connected
*);
55 static void ripng_enable_apply_all(void);
57 /* Join to the all rip routers multicast group. */
58 static int ripng_multicast_join(struct interface
*ifp
)
61 struct ipv6_mreq mreq
;
64 if (if_is_multicast(ifp
)) {
65 memset(&mreq
, 0, sizeof(mreq
));
66 inet_pton(AF_INET6
, RIPNG_GROUP
, &mreq
.ipv6mr_multiaddr
);
67 mreq
.ipv6mr_interface
= ifp
->ifindex
;
70 * NetBSD 1.6.2 requires root to join groups on gif(4).
71 * While this is bogus, privs are available and easy to use
72 * for this call as a workaround.
74 if (ripngd_privs
.change(ZPRIVS_RAISE
))
75 zlog_err("ripng_multicast_join: could not raise privs");
77 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
,
78 (char *)&mreq
, sizeof(mreq
));
81 if (ripngd_privs
.change(ZPRIVS_LOWER
))
82 zlog_err("ripng_multicast_join: could not lower privs");
84 if (ret
< 0 && save_errno
== EADDRINUSE
) {
86 * Group is already joined. This occurs due to sloppy
88 * management, in particular declining to leave the
90 * an interface that has just gone down.
92 zlog_warn("ripng join on %s EADDRINUSE (ignoring)\n",
94 return 0; /* not an error */
98 zlog_warn("can't setsockopt IPV6_JOIN_GROUP: %s",
99 safe_strerror(save_errno
));
101 if (IS_RIPNG_DEBUG_EVENT
)
103 "RIPng %s join to all-rip-routers multicast group",
112 /* Leave from the all rip routers multicast group. */
113 static int ripng_multicast_leave(struct interface
*ifp
)
116 struct ipv6_mreq mreq
;
118 if (if_is_multicast(ifp
)) {
119 memset(&mreq
, 0, sizeof(mreq
));
120 inet_pton(AF_INET6
, RIPNG_GROUP
, &mreq
.ipv6mr_multiaddr
);
121 mreq
.ipv6mr_interface
= ifp
->ifindex
;
123 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
, IPV6_LEAVE_GROUP
,
124 (char *)&mreq
, sizeof(mreq
));
126 zlog_warn("can't setsockopt IPV6_LEAVE_GROUP: %s\n",
127 safe_strerror(errno
));
129 if (IS_RIPNG_DEBUG_EVENT
)
131 "RIPng %s leave from all-rip-routers multicast group",
141 /* How many link local IPv6 address could be used on the interface ? */
142 static int ripng_if_ipv6_lladdress_check(struct interface
*ifp
)
145 struct connected
*connected
;
148 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, nn
, connected
)) {
150 p
= connected
->address
;
152 if ((p
->family
== AF_INET6
)
153 && IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
160 static int ripng_if_down(struct interface
*ifp
)
162 struct route_node
*rp
;
163 struct ripng_info
*rinfo
;
164 struct ripng_interface
*ri
;
165 struct list
*list
= NULL
;
166 struct listnode
*listnode
= NULL
, *nextnode
= NULL
;
169 for (rp
= route_top(ripng
->table
); rp
; rp
= route_next(rp
))
170 if ((list
= rp
->info
) != NULL
)
171 for (ALL_LIST_ELEMENTS(list
, listnode
, nextnode
,
173 if (rinfo
->ifindex
== ifp
->ifindex
)
174 ripng_ecmp_delete(rinfo
);
179 if (IS_RIPNG_DEBUG_EVENT
)
180 zlog_debug("turn off %s", ifp
->name
);
182 /* Leave from multicast group. */
183 ripng_multicast_leave(ifp
);
191 /* Inteface link up message processing. */
192 int ripng_interface_up(int command
, struct zclient
*zclient
,
193 zebra_size_t length
, vrf_id_t vrf_id
)
196 struct interface
*ifp
;
198 /* zebra_interface_state_read() updates interface structure in iflist.
201 ifp
= zebra_interface_state_read(s
, vrf_id
);
206 if (IS_RIPNG_DEBUG_ZEBRA
)
208 "interface up %s index %d flags %llx metric %d mtu %d",
209 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
210 ifp
->metric
, ifp
->mtu6
);
212 /* Check if this interface is RIPng enabled or not. */
213 ripng_enable_apply(ifp
);
215 /* Check for a passive interface. */
216 ripng_passive_interface_apply(ifp
);
218 /* Apply distribute list to the all interface. */
219 ripng_distribute_update_interface(ifp
);
224 /* Inteface link down message processing. */
225 int ripng_interface_down(int command
, struct zclient
*zclient
,
226 zebra_size_t length
, vrf_id_t vrf_id
)
229 struct interface
*ifp
;
231 /* zebra_interface_state_read() updates interface structure in iflist.
234 ifp
= zebra_interface_state_read(s
, vrf_id
);
241 if (IS_RIPNG_DEBUG_ZEBRA
)
243 "interface down %s index %d flags %#llx metric %d mtu %d",
244 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
245 ifp
->metric
, ifp
->mtu6
);
250 /* Inteface addition message from zebra. */
251 int ripng_interface_add(int command
, struct zclient
*zclient
,
252 zebra_size_t length
, vrf_id_t vrf_id
)
254 struct interface
*ifp
;
256 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
258 if (IS_RIPNG_DEBUG_ZEBRA
)
260 "RIPng interface add %s index %d flags %#llx metric %d mtu %d",
261 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
262 ifp
->metric
, ifp
->mtu6
);
264 /* Check is this interface is RIP enabled or not.*/
265 ripng_enable_apply(ifp
);
267 /* Apply distribute list to the interface. */
268 ripng_distribute_update_interface(ifp
);
270 /* Check interface routemap. */
271 ripng_if_rmap_update_interface(ifp
);
276 int ripng_interface_delete(int command
, struct zclient
*zclient
,
277 zebra_size_t length
, vrf_id_t vrf_id
)
279 struct interface
*ifp
;
283 /* zebra_interface_state_read() updates interface structure in iflist
285 ifp
= zebra_interface_state_read(s
, vrf_id
);
294 zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d",
295 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
296 ifp
->metric
, ifp
->mtu6
);
298 /* To support pseudo interface do not free interface structure. */
299 /* if_delete(ifp); */
300 if_set_index(ifp
, IFINDEX_INTERNAL
);
305 void ripng_interface_clean(void)
307 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
308 struct interface
*ifp
;
309 struct ripng_interface
*ri
;
311 FOR_ALL_INTERFACES (vrf
, ifp
) {
314 ri
->enable_network
= 0;
315 ri
->enable_interface
= 0;
319 thread_cancel(ri
->t_wakeup
);
325 void ripng_interface_reset(void)
327 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
328 struct interface
*ifp
;
329 struct ripng_interface
*ri
;
331 FOR_ALL_INTERFACES (vrf
, ifp
) {
334 ri
->enable_network
= 0;
335 ri
->enable_interface
= 0;
338 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
339 ri
->split_horizon_default
= RIPNG_NO_SPLIT_HORIZON
;
341 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
342 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
344 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
345 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
348 thread_cancel(ri
->t_wakeup
);
356 static void ripng_apply_address_add(struct connected
*ifc
)
358 struct prefix_ipv6 address
;
364 if (!if_is_up(ifc
->ifp
))
369 memset(&address
, 0, sizeof(address
));
370 address
.family
= p
->family
;
371 address
.prefix
= p
->u
.prefix6
;
372 address
.prefixlen
= p
->prefixlen
;
373 apply_mask_ipv6(&address
);
375 /* Check if this interface is RIP enabled or not
376 or Check if this address's prefix is RIP enabled */
377 if ((ripng_enable_if_lookup(ifc
->ifp
->name
) >= 0)
378 || (ripng_enable_network_lookup2(ifc
) >= 0))
379 ripng_redistribute_add(ZEBRA_ROUTE_CONNECT
,
380 RIPNG_ROUTE_INTERFACE
, &address
,
381 ifc
->ifp
->ifindex
, NULL
, 0);
384 int ripng_interface_address_add(int command
, struct zclient
*zclient
,
385 zebra_size_t length
, vrf_id_t vrf_id
)
390 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
391 zclient
->ibuf
, vrf_id
);
398 if (p
->family
== AF_INET6
) {
399 struct ripng_interface
*ri
= c
->ifp
->info
;
401 if (IS_RIPNG_DEBUG_ZEBRA
)
402 zlog_debug("RIPng connected address %s/%d add",
403 inet6_ntoa(p
->u
.prefix6
), p
->prefixlen
);
405 /* Check is this prefix needs to be redistributed. */
406 ripng_apply_address_add(c
);
408 /* Let's try once again whether the interface could be activated
411 /* Check if this interface is RIP enabled or not.*/
412 ripng_enable_apply(c
->ifp
);
414 /* Apply distribute list to the interface. */
415 ripng_distribute_update_interface(c
->ifp
);
417 /* Check interface routemap. */
418 ripng_if_rmap_update_interface(c
->ifp
);
425 static void ripng_apply_address_del(struct connected
*ifc
)
427 struct prefix_ipv6 address
;
433 if (!if_is_up(ifc
->ifp
))
438 memset(&address
, 0, sizeof(address
));
439 address
.family
= p
->family
;
440 address
.prefix
= p
->u
.prefix6
;
441 address
.prefixlen
= p
->prefixlen
;
442 apply_mask_ipv6(&address
);
444 ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
445 &address
, ifc
->ifp
->ifindex
);
448 int ripng_interface_address_delete(int command
, struct zclient
*zclient
,
449 zebra_size_t length
, vrf_id_t vrf_id
)
451 struct connected
*ifc
;
453 char buf
[INET6_ADDRSTRLEN
];
455 ifc
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
456 zclient
->ibuf
, vrf_id
);
461 if (p
->family
== AF_INET6
) {
462 if (IS_RIPNG_DEBUG_ZEBRA
)
464 "RIPng connected address %s/%d delete",
465 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
,
469 /* Check wether this prefix needs to be removed. */
470 ripng_apply_address_del(ifc
);
478 /* RIPng enable interface vector. */
479 vector ripng_enable_if
;
481 /* RIPng enable network table. */
482 struct route_table
*ripng_enable_network
;
484 /* Lookup RIPng enable network. */
485 /* Check wether the interface has at least a connected prefix that
486 * is within the ripng_enable_network table. */
487 static int ripng_enable_network_lookup_if(struct interface
*ifp
)
489 struct listnode
*node
;
490 struct connected
*connected
;
491 struct prefix_ipv6 address
;
493 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
495 struct route_node
*n
;
497 p
= connected
->address
;
499 if (p
->family
== AF_INET6
) {
500 address
.family
= AF_INET6
;
501 address
.prefix
= p
->u
.prefix6
;
502 address
.prefixlen
= IPV6_MAX_BITLEN
;
504 n
= route_node_match(ripng_enable_network
,
505 (struct prefix
*)&address
);
507 route_unlock_node(n
);
515 /* Check wether connected is within the ripng_enable_network table. */
516 static int ripng_enable_network_lookup2(struct connected
*connected
)
518 struct prefix_ipv6 address
;
521 p
= connected
->address
;
523 if (p
->family
== AF_INET6
) {
524 struct route_node
*node
;
526 address
.family
= p
->family
;
527 address
.prefix
= p
->u
.prefix6
;
528 address
.prefixlen
= IPV6_MAX_BITLEN
;
530 /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within
531 * ripng_enable_network */
532 node
= route_node_match(ripng_enable_network
,
533 (struct prefix
*)&address
);
536 route_unlock_node(node
);
544 /* Add RIPng enable network. */
545 static int ripng_enable_network_add(struct prefix
*p
)
547 struct route_node
*node
;
549 node
= route_node_get(ripng_enable_network
, p
);
552 route_unlock_node(node
);
555 node
->info
= (void *)1;
557 /* XXX: One should find a better solution than a generic one */
558 ripng_enable_apply_all();
563 /* Delete RIPng enable network. */
564 static int ripng_enable_network_delete(struct prefix
*p
)
566 struct route_node
*node
;
568 node
= route_node_lookup(ripng_enable_network
, p
);
572 /* Unlock info lock. */
573 route_unlock_node(node
);
575 /* Unlock lookup lock. */
576 route_unlock_node(node
);
583 /* Lookup function. */
584 static int ripng_enable_if_lookup(const char *ifname
)
589 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
590 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
)
591 if (strcmp(str
, ifname
) == 0)
596 /* Add interface to ripng_enable_if. */
597 static int ripng_enable_if_add(const char *ifname
)
601 ret
= ripng_enable_if_lookup(ifname
);
605 vector_set(ripng_enable_if
, strdup(ifname
));
607 ripng_enable_apply_all();
612 /* Delete interface from ripng_enable_if. */
613 static int ripng_enable_if_delete(const char *ifname
)
618 index
= ripng_enable_if_lookup(ifname
);
622 str
= vector_slot(ripng_enable_if
, index
);
624 vector_unset(ripng_enable_if
, index
);
626 ripng_enable_apply_all();
631 /* Wake up interface. */
632 static int ripng_interface_wakeup(struct thread
*t
)
634 struct interface
*ifp
;
635 struct ripng_interface
*ri
;
643 /* Join to multicast group. */
644 if (ripng_multicast_join(ifp
) < 0) {
645 zlog_err("multicast join failed, interface %s not running",
650 /* Set running flag. */
653 /* Send RIP request to the interface. */
659 static void ripng_connect_set(struct interface
*ifp
, int set
)
661 struct listnode
*node
, *nnode
;
662 struct connected
*connected
;
663 struct prefix_ipv6 address
;
665 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
667 p
= connected
->address
;
669 if (p
->family
!= AF_INET6
)
672 address
.family
= AF_INET6
;
673 address
.prefix
= p
->u
.prefix6
;
674 address
.prefixlen
= p
->prefixlen
;
675 apply_mask_ipv6(&address
);
678 /* Check once more wether this prefix is within a
679 * "network IF_OR_PREF" one */
680 if ((ripng_enable_if_lookup(connected
->ifp
->name
) >= 0)
681 || (ripng_enable_network_lookup2(connected
) >= 0))
682 ripng_redistribute_add(
684 RIPNG_ROUTE_INTERFACE
, &address
,
685 connected
->ifp
->ifindex
, NULL
, 0);
687 ripng_redistribute_delete(
688 ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
689 &address
, connected
->ifp
->ifindex
);
690 if (ripng_redistribute_check(ZEBRA_ROUTE_CONNECT
))
691 ripng_redistribute_add(
693 RIPNG_ROUTE_REDISTRIBUTE
, &address
,
694 connected
->ifp
->ifindex
, NULL
, 0);
699 /* Check RIPng is enabed on this interface. */
700 void ripng_enable_apply(struct interface
*ifp
)
703 struct ripng_interface
*ri
= NULL
;
705 /* Check interface. */
711 /* Is this interface a candidate for RIPng ? */
712 ret
= ripng_enable_network_lookup_if(ifp
);
714 /* If the interface is matched. */
716 ri
->enable_network
= 1;
718 ri
->enable_network
= 0;
720 /* Check interface name configuration. */
721 ret
= ripng_enable_if_lookup(ifp
->name
);
723 ri
->enable_interface
= 1;
725 ri
->enable_interface
= 0;
727 /* any candidate interface MUST have a link-local IPv6 address */
728 if ((!ripng_if_ipv6_lladdress_check(ifp
))
729 && (ri
->enable_network
|| ri
->enable_interface
)) {
730 ri
->enable_network
= 0;
731 ri
->enable_interface
= 0;
732 zlog_warn("Interface %s does not have any link-local address",
736 /* Update running status of the interface. */
737 if (ri
->enable_network
|| ri
->enable_interface
) {
738 zlog_info("RIPng INTERFACE ON %s", ifp
->name
);
740 /* Add interface wake up thread. */
741 thread_add_timer(master
, ripng_interface_wakeup
, ifp
, 1,
744 ripng_connect_set(ifp
, 1);
747 /* Might as well clean up the route table as well
748 * ripng_if_down sets to 0 ri->running, and displays
753 ripng_connect_set(ifp
, 0);
758 /* Set distribute list to all interfaces. */
759 static void ripng_enable_apply_all(void)
761 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
762 struct interface
*ifp
;
764 FOR_ALL_INTERFACES (vrf
, ifp
)
765 ripng_enable_apply(ifp
);
768 /* Clear all network and neighbor configuration */
769 void ripng_clean_network()
773 struct route_node
*rn
;
775 /* ripng_enable_network */
776 for (rn
= route_top(ripng_enable_network
); rn
; rn
= route_next(rn
))
779 route_unlock_node(rn
);
782 /* ripng_enable_if */
783 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
784 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
) {
786 vector_slot(ripng_enable_if
, i
) = NULL
;
790 /* Vector to store passive-interface name. */
791 vector Vripng_passive_interface
;
793 /* Utility function for looking up passive interface settings. */
794 static int ripng_passive_interface_lookup(const char *ifname
)
799 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
800 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
)
801 if (strcmp(str
, ifname
) == 0)
806 void ripng_passive_interface_apply(struct interface
*ifp
)
809 struct ripng_interface
*ri
;
813 ret
= ripng_passive_interface_lookup(ifp
->name
);
820 static void ripng_passive_interface_apply_all(void)
822 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
823 struct interface
*ifp
;
825 FOR_ALL_INTERFACES (vrf
, ifp
)
826 ripng_passive_interface_apply(ifp
);
829 /* Passive interface. */
830 static int ripng_passive_interface_set(struct vty
*vty
, const char *ifname
)
832 if (ripng_passive_interface_lookup(ifname
) >= 0)
833 return CMD_WARNING_CONFIG_FAILED
;
835 vector_set(Vripng_passive_interface
, strdup(ifname
));
837 ripng_passive_interface_apply_all();
842 static int ripng_passive_interface_unset(struct vty
*vty
, const char *ifname
)
847 i
= ripng_passive_interface_lookup(ifname
);
849 return CMD_WARNING_CONFIG_FAILED
;
851 str
= vector_slot(Vripng_passive_interface
, i
);
853 vector_unset(Vripng_passive_interface
, i
);
855 ripng_passive_interface_apply_all();
860 /* Free all configured RIP passive-interface settings. */
861 void ripng_passive_interface_clean(void)
866 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
867 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
) {
869 vector_slot(Vripng_passive_interface
, i
) = NULL
;
871 ripng_passive_interface_apply_all();
874 /* Write RIPng enable network and interface to the vty. */
875 int ripng_network_write(struct vty
*vty
, int config_mode
)
879 struct route_node
*node
;
882 /* Write enable network. */
883 for (node
= route_top(ripng_enable_network
); node
;
884 node
= route_next(node
))
886 struct prefix
*p
= &node
->p
;
887 vty_out(vty
, "%s%s/%d\n",
888 config_mode
? " network " : " ",
889 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
893 /* Write enable interface. */
894 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
895 if ((ifname
= vector_slot(ripng_enable_if
, i
)) != NULL
)
896 vty_out(vty
, "%s%s\n",
897 config_mode
? " network " : " ", ifname
);
899 /* Write passive interface. */
901 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
902 if ((ifname
= vector_slot(Vripng_passive_interface
, i
))
904 vty_out(vty
, " passive-interface %s\n", ifname
);
909 /* RIPng enable on specified interface or matched network. */
910 DEFUN (ripng_network
,
912 "network IF_OR_ADDR",
913 "RIPng enable on specified interface or network.\n"
914 "Interface or address\n")
916 int idx_if_or_addr
= 1;
920 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
922 /* Given string is IPv6 network or interface name. */
924 ret
= ripng_enable_network_add(&p
);
926 ret
= ripng_enable_if_add(argv
[idx_if_or_addr
]->arg
);
929 vty_out(vty
, "There is same network configuration %s\n",
930 argv
[idx_if_or_addr
]->arg
);
931 return CMD_WARNING_CONFIG_FAILED
;
937 /* RIPng enable on specified interface or matched network. */
938 DEFUN (no_ripng_network
,
939 no_ripng_network_cmd
,
940 "no network IF_OR_ADDR",
942 "RIPng enable on specified interface or network.\n"
943 "Interface or address\n")
945 int idx_if_or_addr
= 2;
949 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
951 /* Given string is interface name. */
953 ret
= ripng_enable_network_delete(&p
);
955 ret
= ripng_enable_if_delete(argv
[idx_if_or_addr
]->arg
);
958 vty_out(vty
, "can't find network %s\n",
959 argv
[idx_if_or_addr
]->arg
);
960 return CMD_WARNING_CONFIG_FAILED
;
966 DEFUN (ipv6_ripng_split_horizon
,
967 ipv6_ripng_split_horizon_cmd
,
968 "ipv6 ripng split-horizon",
970 "Routing Information Protocol\n"
971 "Perform split horizon\n")
973 VTY_DECLVAR_CONTEXT(interface
, ifp
);
974 struct ripng_interface
*ri
;
978 ri
->split_horizon
= RIPNG_SPLIT_HORIZON
;
982 DEFUN (ipv6_ripng_split_horizon_poisoned_reverse
,
983 ipv6_ripng_split_horizon_poisoned_reverse_cmd
,
984 "ipv6 ripng split-horizon poisoned-reverse",
986 "Routing Information Protocol\n"
987 "Perform split horizon\n"
988 "With poisoned-reverse\n")
990 VTY_DECLVAR_CONTEXT(interface
, ifp
);
991 struct ripng_interface
*ri
;
995 ri
->split_horizon
= RIPNG_SPLIT_HORIZON_POISONED_REVERSE
;
999 DEFUN (no_ipv6_ripng_split_horizon
,
1000 no_ipv6_ripng_split_horizon_cmd
,
1001 "no ipv6 ripng split-horizon [poisoned-reverse]",
1004 "Routing Information Protocol\n"
1005 "Perform split horizon\n"
1006 "With poisoned-reverse\n")
1008 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1009 struct ripng_interface
*ri
;
1013 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
1017 DEFUN (ripng_passive_interface
,
1018 ripng_passive_interface_cmd
,
1019 "passive-interface IFNAME",
1020 "Suppress routing updates on an interface\n"
1024 return ripng_passive_interface_set(vty
, argv
[idx_ifname
]->arg
);
1027 DEFUN (no_ripng_passive_interface
,
1028 no_ripng_passive_interface_cmd
,
1029 "no passive-interface IFNAME",
1031 "Suppress routing updates on an interface\n"
1035 return ripng_passive_interface_unset(vty
, argv
[idx_ifname
]->arg
);
1038 static struct ripng_interface
*ri_new(void)
1040 struct ripng_interface
*ri
;
1041 ri
= XCALLOC(MTYPE_IF
, sizeof(struct ripng_interface
));
1043 /* Set default split-horizon behavior. If the interface is Frame
1044 Relay or SMDS is enabled, the default value for split-horizon is
1045 off. But currently Zebra does detect Frame Relay or SMDS
1046 interface. So all interface is set to split horizon. */
1047 ri
->split_horizon_default
= RIPNG_SPLIT_HORIZON
;
1048 ri
->split_horizon
= ri
->split_horizon_default
;
1053 static int ripng_if_new_hook(struct interface
*ifp
)
1055 ifp
->info
= ri_new();
1059 /* Called when interface structure deleted. */
1060 static int ripng_if_delete_hook(struct interface
*ifp
)
1062 XFREE(MTYPE_IF
, ifp
->info
);
1067 /* Configuration write function for ripngd. */
1068 static int interface_config_write(struct vty
*vty
)
1070 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1071 struct interface
*ifp
;
1072 struct ripng_interface
*ri
;
1075 FOR_ALL_INTERFACES (vrf
, ifp
) {
1078 /* Do not display the interface if there is no
1079 * configuration about it.
1082 && (ri
->split_horizon
== ri
->split_horizon_default
))
1085 vty_frame(vty
, "interface %s\n", ifp
->name
);
1087 vty_out(vty
, " description %s\n", ifp
->desc
);
1089 /* Split horizon. */
1090 if (ri
->split_horizon
!= ri
->split_horizon_default
) {
1091 switch (ri
->split_horizon
) {
1092 case RIPNG_SPLIT_HORIZON
:
1093 vty_out(vty
, " ipv6 ripng split-horizon\n");
1095 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE
:
1097 " ipv6 ripng split-horizon poisoned-reverse\n");
1099 case RIPNG_NO_SPLIT_HORIZON
:
1101 vty_out(vty
, " no ipv6 ripng split-horizon\n");
1106 vty_endframe(vty
, "!\n");
1113 /* ripngd's interface node. */
1114 static struct cmd_node interface_node
= {
1115 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1118 /* Initialization of interface. */
1119 void ripng_if_init()
1121 /* Interface initialize. */
1122 hook_register_prio(if_add
, 0, ripng_if_new_hook
);
1123 hook_register_prio(if_del
, 0, ripng_if_delete_hook
);
1125 /* RIPng enable network init. */
1126 ripng_enable_network
= route_table_init();
1128 /* RIPng enable interface init. */
1129 ripng_enable_if
= vector_init(1);
1131 /* RIPng passive interface. */
1132 Vripng_passive_interface
= vector_init(1);
1134 /* Install interface node. */
1135 install_node(&interface_node
, interface_config_write
);
1138 install_element(RIPNG_NODE
, &ripng_network_cmd
);
1139 install_element(RIPNG_NODE
, &no_ripng_network_cmd
);
1140 install_element(RIPNG_NODE
, &ripng_passive_interface_cmd
);
1141 install_element(RIPNG_NODE
, &no_ripng_passive_interface_cmd
);
1143 install_element(INTERFACE_NODE
, &ipv6_ripng_split_horizon_cmd
);
1144 install_element(INTERFACE_NODE
,
1145 &ipv6_ripng_split_horizon_poisoned_reverse_cmd
);
1146 install_element(INTERFACE_NODE
, &no_ipv6_ripng_split_horizon_cmd
);