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
38 #include "lib_errors.h"
40 #include "ripngd/ripngd.h"
41 #include "ripngd/ripng_debug.h"
43 /* If RFC2133 definition is used. */
44 #ifndef IPV6_JOIN_GROUP
45 #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
47 #ifndef IPV6_LEAVE_GROUP
48 #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
51 /* Static utility function. */
52 static void ripng_enable_apply(struct interface
*);
53 static void ripng_passive_interface_apply(struct interface
*);
54 static int ripng_enable_if_lookup(const char *);
55 static int ripng_enable_network_lookup2(struct connected
*);
56 static void ripng_enable_apply_all(void);
58 /* Join to the all rip routers multicast group. */
59 static int ripng_multicast_join(struct interface
*ifp
)
62 struct ipv6_mreq mreq
;
65 if (if_is_multicast(ifp
)) {
66 memset(&mreq
, 0, sizeof(mreq
));
67 inet_pton(AF_INET6
, RIPNG_GROUP
, &mreq
.ipv6mr_multiaddr
);
68 mreq
.ipv6mr_interface
= ifp
->ifindex
;
71 * NetBSD 1.6.2 requires root to join groups on gif(4).
72 * While this is bogus, privs are available and easy to use
73 * for this call as a workaround.
75 frr_elevate_privs(&ripngd_privs
) {
77 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
,
79 (char *)&mreq
, sizeof(mreq
));
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 flog_err_sys(LIB_ERR_SOCKET
,
646 "multicast join failed, interface %s not running",
651 /* Set running flag. */
654 /* Send RIP request to the interface. */
660 static void ripng_connect_set(struct interface
*ifp
, int set
)
662 struct listnode
*node
, *nnode
;
663 struct connected
*connected
;
664 struct prefix_ipv6 address
;
666 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
668 p
= connected
->address
;
670 if (p
->family
!= AF_INET6
)
673 address
.family
= AF_INET6
;
674 address
.prefix
= p
->u
.prefix6
;
675 address
.prefixlen
= p
->prefixlen
;
676 apply_mask_ipv6(&address
);
679 /* Check once more wether this prefix is within a
680 * "network IF_OR_PREF" one */
681 if ((ripng_enable_if_lookup(connected
->ifp
->name
) >= 0)
682 || (ripng_enable_network_lookup2(connected
) >= 0))
683 ripng_redistribute_add(
685 RIPNG_ROUTE_INTERFACE
, &address
,
686 connected
->ifp
->ifindex
, NULL
, 0);
688 ripng_redistribute_delete(
689 ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
690 &address
, connected
->ifp
->ifindex
);
691 if (ripng_redistribute_check(ZEBRA_ROUTE_CONNECT
))
692 ripng_redistribute_add(
694 RIPNG_ROUTE_REDISTRIBUTE
, &address
,
695 connected
->ifp
->ifindex
, NULL
, 0);
700 /* Check RIPng is enabed on this interface. */
701 void ripng_enable_apply(struct interface
*ifp
)
704 struct ripng_interface
*ri
= NULL
;
706 /* Check interface. */
712 /* Is this interface a candidate for RIPng ? */
713 ret
= ripng_enable_network_lookup_if(ifp
);
715 /* If the interface is matched. */
717 ri
->enable_network
= 1;
719 ri
->enable_network
= 0;
721 /* Check interface name configuration. */
722 ret
= ripng_enable_if_lookup(ifp
->name
);
724 ri
->enable_interface
= 1;
726 ri
->enable_interface
= 0;
728 /* any candidate interface MUST have a link-local IPv6 address */
729 if ((!ripng_if_ipv6_lladdress_check(ifp
))
730 && (ri
->enable_network
|| ri
->enable_interface
)) {
731 ri
->enable_network
= 0;
732 ri
->enable_interface
= 0;
733 zlog_warn("Interface %s does not have any link-local address",
737 /* Update running status of the interface. */
738 if (ri
->enable_network
|| ri
->enable_interface
) {
739 zlog_info("RIPng INTERFACE ON %s", ifp
->name
);
741 /* Add interface wake up thread. */
742 thread_add_timer(master
, ripng_interface_wakeup
, ifp
, 1,
745 ripng_connect_set(ifp
, 1);
748 /* Might as well clean up the route table as well
749 * ripng_if_down sets to 0 ri->running, and displays
754 ripng_connect_set(ifp
, 0);
759 /* Set distribute list to all interfaces. */
760 static void ripng_enable_apply_all(void)
762 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
763 struct interface
*ifp
;
765 FOR_ALL_INTERFACES (vrf
, ifp
)
766 ripng_enable_apply(ifp
);
769 /* Clear all network and neighbor configuration */
770 void ripng_clean_network()
774 struct route_node
*rn
;
776 /* ripng_enable_network */
777 for (rn
= route_top(ripng_enable_network
); rn
; rn
= route_next(rn
))
780 route_unlock_node(rn
);
783 /* ripng_enable_if */
784 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
785 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
) {
787 vector_slot(ripng_enable_if
, i
) = NULL
;
791 /* Vector to store passive-interface name. */
792 vector Vripng_passive_interface
;
794 /* Utility function for looking up passive interface settings. */
795 static int ripng_passive_interface_lookup(const char *ifname
)
800 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
801 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
)
802 if (strcmp(str
, ifname
) == 0)
807 void ripng_passive_interface_apply(struct interface
*ifp
)
810 struct ripng_interface
*ri
;
814 ret
= ripng_passive_interface_lookup(ifp
->name
);
821 static void ripng_passive_interface_apply_all(void)
823 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
824 struct interface
*ifp
;
826 FOR_ALL_INTERFACES (vrf
, ifp
)
827 ripng_passive_interface_apply(ifp
);
830 /* Passive interface. */
831 static int ripng_passive_interface_set(struct vty
*vty
, const char *ifname
)
833 if (ripng_passive_interface_lookup(ifname
) >= 0)
834 return CMD_WARNING_CONFIG_FAILED
;
836 vector_set(Vripng_passive_interface
, strdup(ifname
));
838 ripng_passive_interface_apply_all();
843 static int ripng_passive_interface_unset(struct vty
*vty
, const char *ifname
)
848 i
= ripng_passive_interface_lookup(ifname
);
850 return CMD_WARNING_CONFIG_FAILED
;
852 str
= vector_slot(Vripng_passive_interface
, i
);
854 vector_unset(Vripng_passive_interface
, i
);
856 ripng_passive_interface_apply_all();
861 /* Free all configured RIP passive-interface settings. */
862 void ripng_passive_interface_clean(void)
867 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
868 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
) {
870 vector_slot(Vripng_passive_interface
, i
) = NULL
;
872 ripng_passive_interface_apply_all();
875 /* Write RIPng enable network and interface to the vty. */
876 int ripng_network_write(struct vty
*vty
, int config_mode
)
880 struct route_node
*node
;
883 /* Write enable network. */
884 for (node
= route_top(ripng_enable_network
); node
;
885 node
= route_next(node
))
887 struct prefix
*p
= &node
->p
;
888 vty_out(vty
, "%s%s/%d\n",
889 config_mode
? " network " : " ",
890 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
894 /* Write enable interface. */
895 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
896 if ((ifname
= vector_slot(ripng_enable_if
, i
)) != NULL
)
897 vty_out(vty
, "%s%s\n",
898 config_mode
? " network " : " ", ifname
);
900 /* Write passive interface. */
902 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
903 if ((ifname
= vector_slot(Vripng_passive_interface
, i
))
905 vty_out(vty
, " passive-interface %s\n", ifname
);
910 /* RIPng enable on specified interface or matched network. */
911 DEFUN (ripng_network
,
913 "network IF_OR_ADDR",
914 "RIPng enable on specified interface or network.\n"
915 "Interface or address\n")
917 int idx_if_or_addr
= 1;
921 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
923 /* Given string is IPv6 network or interface name. */
925 ret
= ripng_enable_network_add(&p
);
927 ret
= ripng_enable_if_add(argv
[idx_if_or_addr
]->arg
);
930 vty_out(vty
, "There is same network configuration %s\n",
931 argv
[idx_if_or_addr
]->arg
);
932 return CMD_WARNING_CONFIG_FAILED
;
938 /* RIPng enable on specified interface or matched network. */
939 DEFUN (no_ripng_network
,
940 no_ripng_network_cmd
,
941 "no network IF_OR_ADDR",
943 "RIPng enable on specified interface or network.\n"
944 "Interface or address\n")
946 int idx_if_or_addr
= 2;
950 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
952 /* Given string is interface name. */
954 ret
= ripng_enable_network_delete(&p
);
956 ret
= ripng_enable_if_delete(argv
[idx_if_or_addr
]->arg
);
959 vty_out(vty
, "can't find network %s\n",
960 argv
[idx_if_or_addr
]->arg
);
961 return CMD_WARNING_CONFIG_FAILED
;
967 DEFUN (ipv6_ripng_split_horizon
,
968 ipv6_ripng_split_horizon_cmd
,
969 "ipv6 ripng split-horizon",
971 "Routing Information Protocol\n"
972 "Perform split horizon\n")
974 VTY_DECLVAR_CONTEXT(interface
, ifp
);
975 struct ripng_interface
*ri
;
979 ri
->split_horizon
= RIPNG_SPLIT_HORIZON
;
983 DEFUN (ipv6_ripng_split_horizon_poisoned_reverse
,
984 ipv6_ripng_split_horizon_poisoned_reverse_cmd
,
985 "ipv6 ripng split-horizon poisoned-reverse",
987 "Routing Information Protocol\n"
988 "Perform split horizon\n"
989 "With poisoned-reverse\n")
991 VTY_DECLVAR_CONTEXT(interface
, ifp
);
992 struct ripng_interface
*ri
;
996 ri
->split_horizon
= RIPNG_SPLIT_HORIZON_POISONED_REVERSE
;
1000 DEFUN (no_ipv6_ripng_split_horizon
,
1001 no_ipv6_ripng_split_horizon_cmd
,
1002 "no ipv6 ripng split-horizon [poisoned-reverse]",
1005 "Routing Information Protocol\n"
1006 "Perform split horizon\n"
1007 "With poisoned-reverse\n")
1009 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1010 struct ripng_interface
*ri
;
1014 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
1018 DEFUN (ripng_passive_interface
,
1019 ripng_passive_interface_cmd
,
1020 "passive-interface IFNAME",
1021 "Suppress routing updates on an interface\n"
1025 return ripng_passive_interface_set(vty
, argv
[idx_ifname
]->arg
);
1028 DEFUN (no_ripng_passive_interface
,
1029 no_ripng_passive_interface_cmd
,
1030 "no passive-interface IFNAME",
1032 "Suppress routing updates on an interface\n"
1036 return ripng_passive_interface_unset(vty
, argv
[idx_ifname
]->arg
);
1039 static struct ripng_interface
*ri_new(void)
1041 struct ripng_interface
*ri
;
1042 ri
= XCALLOC(MTYPE_IF
, sizeof(struct ripng_interface
));
1044 /* Set default split-horizon behavior. If the interface is Frame
1045 Relay or SMDS is enabled, the default value for split-horizon is
1046 off. But currently Zebra does detect Frame Relay or SMDS
1047 interface. So all interface is set to split horizon. */
1048 ri
->split_horizon_default
= RIPNG_SPLIT_HORIZON
;
1049 ri
->split_horizon
= ri
->split_horizon_default
;
1054 static int ripng_if_new_hook(struct interface
*ifp
)
1056 ifp
->info
= ri_new();
1060 /* Called when interface structure deleted. */
1061 static int ripng_if_delete_hook(struct interface
*ifp
)
1063 XFREE(MTYPE_IF
, ifp
->info
);
1068 /* Configuration write function for ripngd. */
1069 static int interface_config_write(struct vty
*vty
)
1071 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1072 struct interface
*ifp
;
1073 struct ripng_interface
*ri
;
1076 FOR_ALL_INTERFACES (vrf
, ifp
) {
1079 /* Do not display the interface if there is no
1080 * configuration about it.
1083 && (ri
->split_horizon
== ri
->split_horizon_default
))
1086 vty_frame(vty
, "interface %s\n", ifp
->name
);
1088 vty_out(vty
, " description %s\n", ifp
->desc
);
1090 /* Split horizon. */
1091 if (ri
->split_horizon
!= ri
->split_horizon_default
) {
1092 switch (ri
->split_horizon
) {
1093 case RIPNG_SPLIT_HORIZON
:
1094 vty_out(vty
, " ipv6 ripng split-horizon\n");
1096 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE
:
1098 " ipv6 ripng split-horizon poisoned-reverse\n");
1100 case RIPNG_NO_SPLIT_HORIZON
:
1102 vty_out(vty
, " no ipv6 ripng split-horizon\n");
1107 vty_endframe(vty
, "!\n");
1114 /* ripngd's interface node. */
1115 static struct cmd_node interface_node
= {
1116 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1119 /* Initialization of interface. */
1120 void ripng_if_init()
1122 /* Interface initialize. */
1123 hook_register_prio(if_add
, 0, ripng_if_new_hook
);
1124 hook_register_prio(if_del
, 0, ripng_if_delete_hook
);
1126 /* RIPng enable network init. */
1127 ripng_enable_network
= route_table_init();
1129 /* RIPng enable interface init. */
1130 ripng_enable_if
= vector_init(1);
1132 /* RIPng passive interface. */
1133 Vripng_passive_interface
= vector_init(1);
1135 /* Install interface node. */
1136 install_node(&interface_node
, interface_config_write
);
1139 install_element(RIPNG_NODE
, &ripng_network_cmd
);
1140 install_element(RIPNG_NODE
, &no_ripng_network_cmd
);
1141 install_element(RIPNG_NODE
, &ripng_passive_interface_cmd
);
1142 install_element(RIPNG_NODE
, &no_ripng_passive_interface_cmd
);
1144 install_element(INTERFACE_NODE
, &ipv6_ripng_split_horizon_cmd
);
1145 install_element(INTERFACE_NODE
,
1146 &ipv6_ripng_split_horizon_poisoned_reverse_cmd
);
1147 install_element(INTERFACE_NODE
, &no_ipv6_ripng_split_horizon_cmd
);