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
34 #include "agg_table.h"
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
)
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
= agg_route_top(ripng
->table
); rp
;
170 rp
= agg_route_next(rp
))
171 if ((list
= rp
->info
) != NULL
)
172 for (ALL_LIST_ELEMENTS(list
, listnode
, nextnode
,
174 if (rinfo
->ifindex
== ifp
->ifindex
)
175 ripng_ecmp_delete(rinfo
);
180 if (IS_RIPNG_DEBUG_EVENT
)
181 zlog_debug("turn off %s", ifp
->name
);
183 /* Leave from multicast group. */
184 ripng_multicast_leave(ifp
);
192 /* Inteface link up message processing. */
193 int ripng_interface_up(int command
, struct zclient
*zclient
,
194 zebra_size_t length
, vrf_id_t vrf_id
)
197 struct interface
*ifp
;
199 /* zebra_interface_state_read() updates interface structure in iflist.
202 ifp
= zebra_interface_state_read(s
, vrf_id
);
207 if (IS_RIPNG_DEBUG_ZEBRA
)
209 "interface up %s index %d flags %llx metric %d mtu %d",
210 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
211 ifp
->metric
, ifp
->mtu6
);
213 /* Check if this interface is RIPng enabled or not. */
214 ripng_enable_apply(ifp
);
216 /* Check for a passive interface. */
217 ripng_passive_interface_apply(ifp
);
219 /* Apply distribute list to the all interface. */
220 ripng_distribute_update_interface(ifp
);
225 /* Inteface link down message processing. */
226 int ripng_interface_down(int command
, struct zclient
*zclient
,
227 zebra_size_t length
, vrf_id_t vrf_id
)
230 struct interface
*ifp
;
232 /* zebra_interface_state_read() updates interface structure in iflist.
235 ifp
= zebra_interface_state_read(s
, vrf_id
);
242 if (IS_RIPNG_DEBUG_ZEBRA
)
244 "interface down %s index %d flags %#llx metric %d mtu %d",
245 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
246 ifp
->metric
, ifp
->mtu6
);
251 /* Inteface addition message from zebra. */
252 int ripng_interface_add(int command
, struct zclient
*zclient
,
253 zebra_size_t length
, vrf_id_t vrf_id
)
255 struct interface
*ifp
;
257 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
259 if (IS_RIPNG_DEBUG_ZEBRA
)
261 "RIPng interface add %s index %d flags %#llx metric %d mtu %d",
262 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
263 ifp
->metric
, ifp
->mtu6
);
265 /* Check is this interface is RIP enabled or not.*/
266 ripng_enable_apply(ifp
);
268 /* Apply distribute list to the interface. */
269 ripng_distribute_update_interface(ifp
);
271 /* Check interface routemap. */
272 ripng_if_rmap_update_interface(ifp
);
277 int ripng_interface_delete(int command
, struct zclient
*zclient
,
278 zebra_size_t length
, vrf_id_t vrf_id
)
280 struct interface
*ifp
;
284 /* zebra_interface_state_read() updates interface structure in iflist
286 ifp
= zebra_interface_state_read(s
, vrf_id
);
295 zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d",
296 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
297 ifp
->metric
, ifp
->mtu6
);
299 /* To support pseudo interface do not free interface structure. */
300 /* if_delete(ifp); */
301 if_set_index(ifp
, IFINDEX_INTERNAL
);
306 void ripng_interface_clean(void)
308 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
309 struct interface
*ifp
;
310 struct ripng_interface
*ri
;
312 FOR_ALL_INTERFACES (vrf
, ifp
) {
315 ri
->enable_network
= 0;
316 ri
->enable_interface
= 0;
320 thread_cancel(ri
->t_wakeup
);
326 void ripng_interface_reset(void)
328 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
329 struct interface
*ifp
;
330 struct ripng_interface
*ri
;
332 FOR_ALL_INTERFACES (vrf
, ifp
) {
335 ri
->enable_network
= 0;
336 ri
->enable_interface
= 0;
339 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
340 ri
->split_horizon_default
= RIPNG_NO_SPLIT_HORIZON
;
342 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
343 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
345 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
346 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
349 thread_cancel(ri
->t_wakeup
);
357 static void ripng_apply_address_add(struct connected
*ifc
)
359 struct prefix_ipv6 address
;
365 if (!if_is_up(ifc
->ifp
))
370 memset(&address
, 0, sizeof(address
));
371 address
.family
= p
->family
;
372 address
.prefix
= p
->u
.prefix6
;
373 address
.prefixlen
= p
->prefixlen
;
374 apply_mask_ipv6(&address
);
376 /* Check if this interface is RIP enabled or not
377 or Check if this address's prefix is RIP enabled */
378 if ((ripng_enable_if_lookup(ifc
->ifp
->name
) >= 0)
379 || (ripng_enable_network_lookup2(ifc
) >= 0))
380 ripng_redistribute_add(ZEBRA_ROUTE_CONNECT
,
381 RIPNG_ROUTE_INTERFACE
, &address
,
382 ifc
->ifp
->ifindex
, NULL
, 0);
385 int ripng_interface_address_add(int command
, struct zclient
*zclient
,
386 zebra_size_t length
, vrf_id_t vrf_id
)
391 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
392 zclient
->ibuf
, vrf_id
);
399 if (p
->family
== AF_INET6
) {
400 struct ripng_interface
*ri
= c
->ifp
->info
;
402 if (IS_RIPNG_DEBUG_ZEBRA
)
403 zlog_debug("RIPng connected address %s/%d add",
404 inet6_ntoa(p
->u
.prefix6
), p
->prefixlen
);
406 /* Check is this prefix needs to be redistributed. */
407 ripng_apply_address_add(c
);
409 /* Let's try once again whether the interface could be activated
412 /* Check if this interface is RIP enabled or not.*/
413 ripng_enable_apply(c
->ifp
);
415 /* Apply distribute list to the interface. */
416 ripng_distribute_update_interface(c
->ifp
);
418 /* Check interface routemap. */
419 ripng_if_rmap_update_interface(c
->ifp
);
426 static void ripng_apply_address_del(struct connected
*ifc
)
428 struct prefix_ipv6 address
;
434 if (!if_is_up(ifc
->ifp
))
439 memset(&address
, 0, sizeof(address
));
440 address
.family
= p
->family
;
441 address
.prefix
= p
->u
.prefix6
;
442 address
.prefixlen
= p
->prefixlen
;
443 apply_mask_ipv6(&address
);
445 ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
446 &address
, ifc
->ifp
->ifindex
);
449 int ripng_interface_address_delete(int command
, struct zclient
*zclient
,
450 zebra_size_t length
, vrf_id_t vrf_id
)
452 struct connected
*ifc
;
454 char buf
[INET6_ADDRSTRLEN
];
456 ifc
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
457 zclient
->ibuf
, vrf_id
);
462 if (p
->family
== AF_INET6
) {
463 if (IS_RIPNG_DEBUG_ZEBRA
)
465 "RIPng connected address %s/%d delete",
466 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
,
470 /* Check wether this prefix needs to be removed. */
471 ripng_apply_address_del(ifc
);
479 /* RIPng enable interface vector. */
480 vector ripng_enable_if
;
482 /* RIPng enable network table. */
483 struct agg_table
*ripng_enable_network
;
485 /* Lookup RIPng enable network. */
486 /* Check wether the interface has at least a connected prefix that
487 * is within the ripng_enable_network table. */
488 static int ripng_enable_network_lookup_if(struct interface
*ifp
)
490 struct listnode
*node
;
491 struct connected
*connected
;
492 struct prefix_ipv6 address
;
494 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
498 p
= connected
->address
;
500 if (p
->family
== AF_INET6
) {
501 address
.family
= AF_INET6
;
502 address
.prefix
= p
->u
.prefix6
;
503 address
.prefixlen
= IPV6_MAX_BITLEN
;
505 n
= agg_node_match(ripng_enable_network
,
506 (struct prefix
*)&address
);
516 /* Check wether connected is within the ripng_enable_network table. */
517 static int ripng_enable_network_lookup2(struct connected
*connected
)
519 struct prefix_ipv6 address
;
522 p
= connected
->address
;
524 if (p
->family
== AF_INET6
) {
525 struct agg_node
*node
;
527 address
.family
= p
->family
;
528 address
.prefix
= p
->u
.prefix6
;
529 address
.prefixlen
= IPV6_MAX_BITLEN
;
531 /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within
532 * ripng_enable_network */
533 node
= agg_node_match(ripng_enable_network
,
534 (struct prefix
*)&address
);
537 agg_unlock_node(node
);
545 /* Add RIPng enable network. */
546 int ripng_enable_network_add(struct prefix
*p
)
548 struct agg_node
*node
;
550 node
= agg_node_get(ripng_enable_network
, p
);
553 agg_unlock_node(node
);
554 return NB_ERR_INCONSISTENCY
;
556 node
->info
= (void *)1;
558 /* XXX: One should find a better solution than a generic one */
559 ripng_enable_apply_all();
564 /* Delete RIPng enable network. */
565 int ripng_enable_network_delete(struct prefix
*p
)
567 struct agg_node
*node
;
569 node
= agg_node_lookup(ripng_enable_network
, p
);
573 /* Unlock info lock. */
574 agg_unlock_node(node
);
576 /* Unlock lookup lock. */
577 agg_unlock_node(node
);
582 return NB_ERR_INCONSISTENCY
;
585 /* Lookup function. */
586 static int ripng_enable_if_lookup(const char *ifname
)
591 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
592 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
)
593 if (strcmp(str
, ifname
) == 0)
598 /* Add interface to ripng_enable_if. */
599 int ripng_enable_if_add(const char *ifname
)
603 ret
= ripng_enable_if_lookup(ifname
);
605 return NB_ERR_INCONSISTENCY
;
607 vector_set(ripng_enable_if
, strdup(ifname
));
609 ripng_enable_apply_all();
614 /* Delete interface from ripng_enable_if. */
615 int ripng_enable_if_delete(const char *ifname
)
620 index
= ripng_enable_if_lookup(ifname
);
622 return NB_ERR_INCONSISTENCY
;
624 str
= vector_slot(ripng_enable_if
, index
);
626 vector_unset(ripng_enable_if
, index
);
628 ripng_enable_apply_all();
633 /* Wake up interface. */
634 static int ripng_interface_wakeup(struct thread
*t
)
636 struct interface
*ifp
;
637 struct ripng_interface
*ri
;
645 /* Join to multicast group. */
646 if (ripng_multicast_join(ifp
) < 0) {
647 flog_err_sys(EC_LIB_SOCKET
,
648 "multicast join failed, interface %s not running",
653 /* Set running flag. */
656 /* Send RIP request to the interface. */
662 static void ripng_connect_set(struct interface
*ifp
, int set
)
664 struct listnode
*node
, *nnode
;
665 struct connected
*connected
;
666 struct prefix_ipv6 address
;
668 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
670 p
= connected
->address
;
672 if (p
->family
!= AF_INET6
)
675 address
.family
= AF_INET6
;
676 address
.prefix
= p
->u
.prefix6
;
677 address
.prefixlen
= p
->prefixlen
;
678 apply_mask_ipv6(&address
);
681 /* Check once more wether this prefix is within a
682 * "network IF_OR_PREF" one */
683 if ((ripng_enable_if_lookup(connected
->ifp
->name
) >= 0)
684 || (ripng_enable_network_lookup2(connected
) >= 0))
685 ripng_redistribute_add(
687 RIPNG_ROUTE_INTERFACE
, &address
,
688 connected
->ifp
->ifindex
, NULL
, 0);
690 ripng_redistribute_delete(
691 ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
692 &address
, connected
->ifp
->ifindex
);
693 if (ripng_redistribute_check(ZEBRA_ROUTE_CONNECT
))
694 ripng_redistribute_add(
696 RIPNG_ROUTE_REDISTRIBUTE
, &address
,
697 connected
->ifp
->ifindex
, NULL
, 0);
702 /* Check RIPng is enabed on this interface. */
703 void ripng_enable_apply(struct interface
*ifp
)
706 struct ripng_interface
*ri
= NULL
;
708 /* Check interface. */
714 /* Is this interface a candidate for RIPng ? */
715 ret
= ripng_enable_network_lookup_if(ifp
);
717 /* If the interface is matched. */
719 ri
->enable_network
= 1;
721 ri
->enable_network
= 0;
723 /* Check interface name configuration. */
724 ret
= ripng_enable_if_lookup(ifp
->name
);
726 ri
->enable_interface
= 1;
728 ri
->enable_interface
= 0;
730 /* any candidate interface MUST have a link-local IPv6 address */
731 if ((!ripng_if_ipv6_lladdress_check(ifp
))
732 && (ri
->enable_network
|| ri
->enable_interface
)) {
733 ri
->enable_network
= 0;
734 ri
->enable_interface
= 0;
735 zlog_warn("Interface %s does not have any link-local address",
739 /* Update running status of the interface. */
740 if (ri
->enable_network
|| ri
->enable_interface
) {
741 zlog_info("RIPng INTERFACE ON %s", ifp
->name
);
743 /* Add interface wake up thread. */
744 thread_add_timer(master
, ripng_interface_wakeup
, ifp
, 1,
747 ripng_connect_set(ifp
, 1);
750 /* Might as well clean up the route table as well
751 * ripng_if_down sets to 0 ri->running, and displays
756 ripng_connect_set(ifp
, 0);
761 /* Set distribute list to all interfaces. */
762 static void ripng_enable_apply_all(void)
764 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
765 struct interface
*ifp
;
767 FOR_ALL_INTERFACES (vrf
, ifp
)
768 ripng_enable_apply(ifp
);
771 /* Clear all network and neighbor configuration */
772 void ripng_clean_network()
778 /* ripng_enable_network */
779 for (rn
= agg_route_top(ripng_enable_network
); rn
;
780 rn
= agg_route_next(rn
))
786 /* ripng_enable_if */
787 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
788 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
) {
790 vector_slot(ripng_enable_if
, i
) = NULL
;
794 /* Vector to store passive-interface name. */
795 vector Vripng_passive_interface
;
797 /* Utility function for looking up passive interface settings. */
798 static int ripng_passive_interface_lookup(const char *ifname
)
803 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
804 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
)
805 if (strcmp(str
, ifname
) == 0)
810 void ripng_passive_interface_apply(struct interface
*ifp
)
813 struct ripng_interface
*ri
;
817 ret
= ripng_passive_interface_lookup(ifp
->name
);
824 static void ripng_passive_interface_apply_all(void)
826 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
827 struct interface
*ifp
;
829 FOR_ALL_INTERFACES (vrf
, ifp
)
830 ripng_passive_interface_apply(ifp
);
833 /* Passive interface. */
834 static int ripng_passive_interface_set(struct vty
*vty
, const char *ifname
)
836 if (ripng_passive_interface_lookup(ifname
) >= 0)
837 return CMD_WARNING_CONFIG_FAILED
;
839 vector_set(Vripng_passive_interface
, strdup(ifname
));
841 ripng_passive_interface_apply_all();
846 static int ripng_passive_interface_unset(struct vty
*vty
, const char *ifname
)
851 i
= ripng_passive_interface_lookup(ifname
);
853 return CMD_WARNING_CONFIG_FAILED
;
855 str
= vector_slot(Vripng_passive_interface
, i
);
857 vector_unset(Vripng_passive_interface
, i
);
859 ripng_passive_interface_apply_all();
864 /* Free all configured RIP passive-interface settings. */
865 void ripng_passive_interface_clean(void)
870 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
871 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
) {
873 vector_slot(Vripng_passive_interface
, i
) = NULL
;
875 ripng_passive_interface_apply_all();
878 /* Write RIPng enable network and interface to the vty. */
879 int ripng_network_write(struct vty
*vty
, int config_mode
)
883 struct agg_node
*node
;
886 /* Write enable network. */
887 for (node
= agg_route_top(ripng_enable_network
); node
;
888 node
= agg_route_next(node
))
890 struct prefix
*p
= &node
->p
;
891 vty_out(vty
, "%s%s/%d\n",
892 config_mode
? " network " : " ",
893 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
897 /* Write enable interface. */
898 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
899 if ((ifname
= vector_slot(ripng_enable_if
, i
)) != NULL
)
900 vty_out(vty
, "%s%s\n",
901 config_mode
? " network " : " ", ifname
);
903 /* Write passive interface. */
905 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
906 if ((ifname
= vector_slot(Vripng_passive_interface
, i
))
908 vty_out(vty
, " passive-interface %s\n", ifname
);
913 DEFUN (ipv6_ripng_split_horizon
,
914 ipv6_ripng_split_horizon_cmd
,
915 "ipv6 ripng split-horizon",
917 "Routing Information Protocol\n"
918 "Perform split horizon\n")
920 VTY_DECLVAR_CONTEXT(interface
, ifp
);
921 struct ripng_interface
*ri
;
925 ri
->split_horizon
= RIPNG_SPLIT_HORIZON
;
929 DEFUN (ipv6_ripng_split_horizon_poisoned_reverse
,
930 ipv6_ripng_split_horizon_poisoned_reverse_cmd
,
931 "ipv6 ripng split-horizon poisoned-reverse",
933 "Routing Information Protocol\n"
934 "Perform split horizon\n"
935 "With poisoned-reverse\n")
937 VTY_DECLVAR_CONTEXT(interface
, ifp
);
938 struct ripng_interface
*ri
;
942 ri
->split_horizon
= RIPNG_SPLIT_HORIZON_POISONED_REVERSE
;
946 DEFUN (no_ipv6_ripng_split_horizon
,
947 no_ipv6_ripng_split_horizon_cmd
,
948 "no ipv6 ripng split-horizon [poisoned-reverse]",
951 "Routing Information Protocol\n"
952 "Perform split horizon\n"
953 "With poisoned-reverse\n")
955 VTY_DECLVAR_CONTEXT(interface
, ifp
);
956 struct ripng_interface
*ri
;
960 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
964 DEFUN (ripng_passive_interface
,
965 ripng_passive_interface_cmd
,
966 "passive-interface IFNAME",
967 "Suppress routing updates on an interface\n"
971 return ripng_passive_interface_set(vty
, argv
[idx_ifname
]->arg
);
974 DEFUN (no_ripng_passive_interface
,
975 no_ripng_passive_interface_cmd
,
976 "no passive-interface IFNAME",
978 "Suppress routing updates on an interface\n"
982 return ripng_passive_interface_unset(vty
, argv
[idx_ifname
]->arg
);
985 static struct ripng_interface
*ri_new(void)
987 struct ripng_interface
*ri
;
988 ri
= XCALLOC(MTYPE_IF
, sizeof(struct ripng_interface
));
990 /* Set default split-horizon behavior. If the interface is Frame
991 Relay or SMDS is enabled, the default value for split-horizon is
992 off. But currently Zebra does detect Frame Relay or SMDS
993 interface. So all interface is set to split horizon. */
994 ri
->split_horizon_default
= RIPNG_SPLIT_HORIZON
;
995 ri
->split_horizon
= ri
->split_horizon_default
;
1000 static int ripng_if_new_hook(struct interface
*ifp
)
1002 ifp
->info
= ri_new();
1006 /* Called when interface structure deleted. */
1007 static int ripng_if_delete_hook(struct interface
*ifp
)
1009 XFREE(MTYPE_IF
, ifp
->info
);
1014 /* Configuration write function for ripngd. */
1015 static int interface_config_write(struct vty
*vty
)
1017 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1018 struct interface
*ifp
;
1019 struct ripng_interface
*ri
;
1022 FOR_ALL_INTERFACES (vrf
, ifp
) {
1025 /* Do not display the interface if there is no
1026 * configuration about it.
1029 && (ri
->split_horizon
== ri
->split_horizon_default
))
1032 vty_frame(vty
, "interface %s\n", ifp
->name
);
1034 vty_out(vty
, " description %s\n", ifp
->desc
);
1036 /* Split horizon. */
1037 if (ri
->split_horizon
!= ri
->split_horizon_default
) {
1038 switch (ri
->split_horizon
) {
1039 case RIPNG_SPLIT_HORIZON
:
1040 vty_out(vty
, " ipv6 ripng split-horizon\n");
1042 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE
:
1044 " ipv6 ripng split-horizon poisoned-reverse\n");
1046 case RIPNG_NO_SPLIT_HORIZON
:
1048 vty_out(vty
, " no ipv6 ripng split-horizon\n");
1053 vty_endframe(vty
, "!\n");
1060 /* ripngd's interface node. */
1061 static struct cmd_node interface_node
= {
1062 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1065 /* Initialization of interface. */
1066 void ripng_if_init()
1068 /* Interface initialize. */
1069 hook_register_prio(if_add
, 0, ripng_if_new_hook
);
1070 hook_register_prio(if_del
, 0, ripng_if_delete_hook
);
1072 /* RIPng enable network init. */
1073 ripng_enable_network
= agg_table_init();
1075 /* RIPng enable interface init. */
1076 ripng_enable_if
= vector_init(1);
1078 /* RIPng passive interface. */
1079 Vripng_passive_interface
= vector_init(1);
1081 /* Install interface node. */
1082 install_node(&interface_node
, interface_config_write
);
1085 install_element(RIPNG_NODE
, &ripng_passive_interface_cmd
);
1086 install_element(RIPNG_NODE
, &no_ripng_passive_interface_cmd
);
1088 install_element(INTERFACE_NODE
, &ipv6_ripng_split_horizon_cmd
);
1089 install_element(INTERFACE_NODE
,
1090 &ipv6_ripng_split_horizon_poisoned_reverse_cmd
);
1091 install_element(INTERFACE_NODE
, &no_ipv6_ripng_split_horizon_cmd
);