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 extern struct zebra_privs_t ripngd_privs
;
52 /* Static utility function. */
53 static void ripng_enable_apply(struct interface
*);
54 static void ripng_passive_interface_apply(struct interface
*);
55 static int ripng_enable_if_lookup(const char *);
56 static int ripng_enable_network_lookup2(struct connected
*);
57 static void ripng_enable_apply_all(void);
59 /* Join to the all rip routers multicast group. */
60 static int ripng_multicast_join(struct interface
*ifp
)
63 struct ipv6_mreq mreq
;
66 if (if_is_multicast(ifp
)) {
67 memset(&mreq
, 0, sizeof(mreq
));
68 inet_pton(AF_INET6
, RIPNG_GROUP
, &mreq
.ipv6mr_multiaddr
);
69 mreq
.ipv6mr_interface
= ifp
->ifindex
;
72 * NetBSD 1.6.2 requires root to join groups on gif(4).
73 * While this is bogus, privs are available and easy to use
74 * for this call as a workaround.
76 if (ripngd_privs
.change(ZPRIVS_RAISE
))
77 zlog_err("ripng_multicast_join: could not raise privs");
79 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
,
80 (char *)&mreq
, sizeof(mreq
));
83 if (ripngd_privs
.change(ZPRIVS_LOWER
))
84 zlog_err("ripng_multicast_join: could not lower privs");
86 if (ret
< 0 && save_errno
== EADDRINUSE
) {
88 * Group is already joined. This occurs due to sloppy
90 * management, in particular declining to leave the
92 * an interface that has just gone down.
94 zlog_warn("ripng join on %s EADDRINUSE (ignoring)\n",
96 return 0; /* not an error */
100 zlog_warn("can't setsockopt IPV6_JOIN_GROUP: %s",
101 safe_strerror(save_errno
));
103 if (IS_RIPNG_DEBUG_EVENT
)
105 "RIPng %s join to all-rip-routers multicast group",
114 /* Leave from the all rip routers multicast group. */
115 static int ripng_multicast_leave(struct interface
*ifp
)
118 struct ipv6_mreq mreq
;
120 if (if_is_multicast(ifp
)) {
121 memset(&mreq
, 0, sizeof(mreq
));
122 inet_pton(AF_INET6
, RIPNG_GROUP
, &mreq
.ipv6mr_multiaddr
);
123 mreq
.ipv6mr_interface
= ifp
->ifindex
;
125 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
, IPV6_LEAVE_GROUP
,
126 (char *)&mreq
, sizeof(mreq
));
128 zlog_warn("can't setsockopt IPV6_LEAVE_GROUP: %s\n",
129 safe_strerror(errno
));
131 if (IS_RIPNG_DEBUG_EVENT
)
133 "RIPng %s leave from all-rip-routers multicast group",
143 /* How many link local IPv6 address could be used on the interface ? */
144 static int ripng_if_ipv6_lladdress_check(struct interface
*ifp
)
147 struct connected
*connected
;
150 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, nn
, connected
)) {
152 p
= connected
->address
;
154 if ((p
->family
== AF_INET6
)
155 && IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
162 static int ripng_if_down(struct interface
*ifp
)
164 struct route_node
*rp
;
165 struct ripng_info
*rinfo
;
166 struct ripng_interface
*ri
;
167 struct list
*list
= NULL
;
168 struct listnode
*listnode
= NULL
, *nextnode
= NULL
;
171 for (rp
= route_top(ripng
->table
); rp
; rp
= route_next(rp
))
172 if ((list
= rp
->info
) != NULL
)
173 for (ALL_LIST_ELEMENTS(list
, listnode
, nextnode
,
175 if (rinfo
->ifindex
== ifp
->ifindex
)
176 ripng_ecmp_delete(rinfo
);
181 if (IS_RIPNG_DEBUG_EVENT
)
182 zlog_debug("turn off %s", ifp
->name
);
184 /* Leave from multicast group. */
185 ripng_multicast_leave(ifp
);
193 /* Inteface link up message processing. */
194 int ripng_interface_up(int command
, struct zclient
*zclient
,
195 zebra_size_t length
, vrf_id_t vrf_id
)
198 struct interface
*ifp
;
200 /* zebra_interface_state_read() updates interface structure in iflist.
203 ifp
= zebra_interface_state_read(s
, vrf_id
);
208 if (IS_RIPNG_DEBUG_ZEBRA
)
210 "interface up %s index %d flags %llx metric %d mtu %d",
211 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
212 ifp
->metric
, ifp
->mtu6
);
214 /* Check if this interface is RIPng enabled or not. */
215 ripng_enable_apply(ifp
);
217 /* Check for a passive interface. */
218 ripng_passive_interface_apply(ifp
);
220 /* Apply distribute list to the all interface. */
221 ripng_distribute_update_interface(ifp
);
226 /* Inteface link down message processing. */
227 int ripng_interface_down(int command
, struct zclient
*zclient
,
228 zebra_size_t length
, vrf_id_t vrf_id
)
231 struct interface
*ifp
;
233 /* zebra_interface_state_read() updates interface structure in iflist.
236 ifp
= zebra_interface_state_read(s
, vrf_id
);
243 if (IS_RIPNG_DEBUG_ZEBRA
)
245 "interface down %s index %d flags %#llx metric %d mtu %d",
246 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
247 ifp
->metric
, ifp
->mtu6
);
252 /* Inteface addition message from zebra. */
253 int ripng_interface_add(int command
, struct zclient
*zclient
,
254 zebra_size_t length
, vrf_id_t vrf_id
)
256 struct interface
*ifp
;
258 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
260 if (IS_RIPNG_DEBUG_ZEBRA
)
262 "RIPng interface add %s index %d flags %#llx metric %d mtu %d",
263 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
264 ifp
->metric
, ifp
->mtu6
);
266 /* Check is this interface is RIP enabled or not.*/
267 ripng_enable_apply(ifp
);
269 /* Apply distribute list to the interface. */
270 ripng_distribute_update_interface(ifp
);
272 /* Check interface routemap. */
273 ripng_if_rmap_update_interface(ifp
);
278 int ripng_interface_delete(int command
, struct zclient
*zclient
,
279 zebra_size_t length
, vrf_id_t vrf_id
)
281 struct interface
*ifp
;
285 /* zebra_interface_state_read() updates interface structure in iflist
287 ifp
= zebra_interface_state_read(s
, vrf_id
);
296 zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d",
297 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
298 ifp
->metric
, ifp
->mtu6
);
300 /* To support pseudo interface do not free interface structure. */
301 /* if_delete(ifp); */
302 ifp
->ifindex
= IFINDEX_DELETED
;
307 void ripng_interface_clean(void)
309 struct listnode
*node
, *nnode
;
310 struct interface
*ifp
;
311 struct ripng_interface
*ri
;
313 for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT
), node
, nnode
, ifp
)) {
316 ri
->enable_network
= 0;
317 ri
->enable_interface
= 0;
321 thread_cancel(ri
->t_wakeup
);
327 void ripng_interface_reset(void)
329 struct listnode
*node
;
330 struct interface
*ifp
;
331 struct ripng_interface
*ri
;
333 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
)) {
336 ri
->enable_network
= 0;
337 ri
->enable_interface
= 0;
340 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
341 ri
->split_horizon_default
= RIPNG_NO_SPLIT_HORIZON
;
343 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
344 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
346 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
347 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
350 thread_cancel(ri
->t_wakeup
);
358 static void ripng_apply_address_add(struct connected
*ifc
)
360 struct prefix_ipv6 address
;
366 if (!if_is_up(ifc
->ifp
))
371 memset(&address
, 0, sizeof(address
));
372 address
.family
= p
->family
;
373 address
.prefix
= p
->u
.prefix6
;
374 address
.prefixlen
= p
->prefixlen
;
375 apply_mask_ipv6(&address
);
377 /* Check if this interface is RIP enabled or not
378 or Check if this address's prefix is RIP enabled */
379 if ((ripng_enable_if_lookup(ifc
->ifp
->name
) >= 0)
380 || (ripng_enable_network_lookup2(ifc
) >= 0))
381 ripng_redistribute_add(ZEBRA_ROUTE_CONNECT
,
382 RIPNG_ROUTE_INTERFACE
, &address
,
383 ifc
->ifp
->ifindex
, NULL
, 0);
386 int ripng_interface_address_add(int command
, struct zclient
*zclient
,
387 zebra_size_t length
, vrf_id_t vrf_id
)
392 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
393 zclient
->ibuf
, vrf_id
);
400 if (p
->family
== AF_INET6
) {
401 struct ripng_interface
*ri
= c
->ifp
->info
;
403 if (IS_RIPNG_DEBUG_ZEBRA
)
404 zlog_debug("RIPng connected address %s/%d add",
405 inet6_ntoa(p
->u
.prefix6
), p
->prefixlen
);
407 /* Check is this prefix needs to be redistributed. */
408 ripng_apply_address_add(c
);
410 /* Let's try once again whether the interface could be activated
413 /* Check if this interface is RIP enabled or not.*/
414 ripng_enable_apply(c
->ifp
);
416 /* Apply distribute list to the interface. */
417 ripng_distribute_update_interface(c
->ifp
);
419 /* Check interface routemap. */
420 ripng_if_rmap_update_interface(c
->ifp
);
427 static void ripng_apply_address_del(struct connected
*ifc
)
429 struct prefix_ipv6 address
;
435 if (!if_is_up(ifc
->ifp
))
440 memset(&address
, 0, sizeof(address
));
441 address
.family
= p
->family
;
442 address
.prefix
= p
->u
.prefix6
;
443 address
.prefixlen
= p
->prefixlen
;
444 apply_mask_ipv6(&address
);
446 ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
447 &address
, ifc
->ifp
->ifindex
);
450 int ripng_interface_address_delete(int command
, struct zclient
*zclient
,
451 zebra_size_t length
, vrf_id_t vrf_id
)
453 struct connected
*ifc
;
455 char buf
[INET6_ADDRSTRLEN
];
457 ifc
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
458 zclient
->ibuf
, vrf_id
);
463 if (p
->family
== AF_INET6
) {
464 if (IS_RIPNG_DEBUG_ZEBRA
)
466 "RIPng connected address %s/%d delete",
467 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
,
471 /* Check wether this prefix needs to be removed. */
472 ripng_apply_address_del(ifc
);
480 /* RIPng enable interface vector. */
481 vector ripng_enable_if
;
483 /* RIPng enable network table. */
484 struct route_table
*ripng_enable_network
;
486 /* Lookup RIPng enable network. */
487 /* Check wether the interface has at least a connected prefix that
488 * is within the ripng_enable_network table. */
489 static int ripng_enable_network_lookup_if(struct interface
*ifp
)
491 struct listnode
*node
;
492 struct connected
*connected
;
493 struct prefix_ipv6 address
;
495 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
497 struct route_node
*node
;
499 p
= connected
->address
;
501 if (p
->family
== AF_INET6
) {
502 address
.family
= AF_INET6
;
503 address
.prefix
= p
->u
.prefix6
;
504 address
.prefixlen
= IPV6_MAX_BITLEN
;
506 node
= route_node_match(ripng_enable_network
,
507 (struct prefix
*)&address
);
509 route_unlock_node(node
);
517 /* Check wether connected is within the ripng_enable_network table. */
518 static int ripng_enable_network_lookup2(struct connected
*connected
)
520 struct prefix_ipv6 address
;
523 p
= connected
->address
;
525 if (p
->family
== AF_INET6
) {
526 struct route_node
*node
;
528 address
.family
= p
->family
;
529 address
.prefix
= p
->u
.prefix6
;
530 address
.prefixlen
= IPV6_MAX_BITLEN
;
532 /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within
533 * ripng_enable_network */
534 node
= route_node_match(ripng_enable_network
,
535 (struct prefix
*)&address
);
538 route_unlock_node(node
);
546 /* Add RIPng enable network. */
547 static int ripng_enable_network_add(struct prefix
*p
)
549 struct route_node
*node
;
551 node
= route_node_get(ripng_enable_network
, p
);
554 route_unlock_node(node
);
557 node
->info
= (void *)1;
559 /* XXX: One should find a better solution than a generic one */
560 ripng_enable_apply_all();
565 /* Delete RIPng enable network. */
566 static int ripng_enable_network_delete(struct prefix
*p
)
568 struct route_node
*node
;
570 node
= route_node_lookup(ripng_enable_network
, p
);
574 /* Unlock info lock. */
575 route_unlock_node(node
);
577 /* Unlock lookup lock. */
578 route_unlock_node(node
);
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 static int ripng_enable_if_add(const char *ifname
)
603 ret
= ripng_enable_if_lookup(ifname
);
607 vector_set(ripng_enable_if
, strdup(ifname
));
609 ripng_enable_apply_all();
614 /* Delete interface from ripng_enable_if. */
615 static int ripng_enable_if_delete(const char *ifname
)
620 index
= ripng_enable_if_lookup(ifname
);
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 zlog_err("multicast join failed, interface %s not running",
652 /* Set running flag. */
655 /* Send RIP request to the interface. */
661 static void ripng_connect_set(struct interface
*ifp
, int set
)
663 struct listnode
*node
, *nnode
;
664 struct connected
*connected
;
665 struct prefix_ipv6 address
;
667 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
669 p
= connected
->address
;
671 if (p
->family
!= AF_INET6
)
674 address
.family
= AF_INET6
;
675 address
.prefix
= p
->u
.prefix6
;
676 address
.prefixlen
= p
->prefixlen
;
677 apply_mask_ipv6(&address
);
680 /* Check once more wether this prefix is within a
681 * "network IF_OR_PREF" one */
682 if ((ripng_enable_if_lookup(connected
->ifp
->name
) >= 0)
683 || (ripng_enable_network_lookup2(connected
) >= 0))
684 ripng_redistribute_add(
686 RIPNG_ROUTE_INTERFACE
, &address
,
687 connected
->ifp
->ifindex
, NULL
, 0);
689 ripng_redistribute_delete(
690 ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
691 &address
, connected
->ifp
->ifindex
);
692 if (ripng_redistribute_check(ZEBRA_ROUTE_CONNECT
))
693 ripng_redistribute_add(
695 RIPNG_ROUTE_REDISTRIBUTE
, &address
,
696 connected
->ifp
->ifindex
, NULL
, 0);
701 /* Check RIPng is enabed on this interface. */
702 void ripng_enable_apply(struct interface
*ifp
)
705 struct ripng_interface
*ri
= NULL
;
707 /* Check interface. */
713 /* Is this interface a candidate for RIPng ? */
714 ret
= ripng_enable_network_lookup_if(ifp
);
716 /* If the interface is matched. */
718 ri
->enable_network
= 1;
720 ri
->enable_network
= 0;
722 /* Check interface name configuration. */
723 ret
= ripng_enable_if_lookup(ifp
->name
);
725 ri
->enable_interface
= 1;
727 ri
->enable_interface
= 0;
729 /* any candidate interface MUST have a link-local IPv6 address */
730 if ((!ripng_if_ipv6_lladdress_check(ifp
))
731 && (ri
->enable_network
|| ri
->enable_interface
)) {
732 ri
->enable_network
= 0;
733 ri
->enable_interface
= 0;
734 zlog_warn("Interface %s does not have any link-local address",
738 /* Update running status of the interface. */
739 if (ri
->enable_network
|| ri
->enable_interface
) {
740 zlog_info("RIPng INTERFACE ON %s", ifp
->name
);
742 /* Add interface wake up thread. */
743 thread_add_timer(master
, ripng_interface_wakeup
, ifp
, 1,
746 ripng_connect_set(ifp
, 1);
749 /* Might as well clean up the route table as well
750 * ripng_if_down sets to 0 ri->running, and displays
755 ripng_connect_set(ifp
, 0);
760 /* Set distribute list to all interfaces. */
761 static void ripng_enable_apply_all(void)
763 struct interface
*ifp
;
764 struct listnode
*node
;
766 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
767 ripng_enable_apply(ifp
);
770 /* Clear all network and neighbor configuration */
771 void ripng_clean_network()
775 struct route_node
*rn
;
777 /* ripng_enable_network */
778 for (rn
= route_top(ripng_enable_network
); rn
; rn
= route_next(rn
))
781 route_unlock_node(rn
);
784 /* ripng_enable_if */
785 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
786 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
) {
788 vector_slot(ripng_enable_if
, i
) = NULL
;
792 /* Vector to store passive-interface name. */
793 vector Vripng_passive_interface
;
795 /* Utility function for looking up passive interface settings. */
796 static int ripng_passive_interface_lookup(const char *ifname
)
801 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
802 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
)
803 if (strcmp(str
, ifname
) == 0)
808 void ripng_passive_interface_apply(struct interface
*ifp
)
811 struct ripng_interface
*ri
;
815 ret
= ripng_passive_interface_lookup(ifp
->name
);
822 static void ripng_passive_interface_apply_all(void)
824 struct interface
*ifp
;
825 struct listnode
*node
;
827 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
828 ripng_passive_interface_apply(ifp
);
831 /* Passive interface. */
832 static int ripng_passive_interface_set(struct vty
*vty
, const char *ifname
)
834 if (ripng_passive_interface_lookup(ifname
) >= 0)
835 return CMD_WARNING_CONFIG_FAILED
;
837 vector_set(Vripng_passive_interface
, strdup(ifname
));
839 ripng_passive_interface_apply_all();
844 static int ripng_passive_interface_unset(struct vty
*vty
, const char *ifname
)
849 i
= ripng_passive_interface_lookup(ifname
);
851 return CMD_WARNING_CONFIG_FAILED
;
853 str
= vector_slot(Vripng_passive_interface
, i
);
855 vector_unset(Vripng_passive_interface
, i
);
857 ripng_passive_interface_apply_all();
862 /* Free all configured RIP passive-interface settings. */
863 void ripng_passive_interface_clean(void)
868 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
869 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
) {
871 vector_slot(Vripng_passive_interface
, i
) = NULL
;
873 ripng_passive_interface_apply_all();
876 /* Write RIPng enable network and interface to the vty. */
877 int ripng_network_write(struct vty
*vty
, int config_mode
)
881 struct route_node
*node
;
884 /* Write enable network. */
885 for (node
= route_top(ripng_enable_network
); node
;
886 node
= route_next(node
))
888 struct prefix
*p
= &node
->p
;
889 vty_out(vty
, "%s%s/%d\n",
890 config_mode
? " network " : " ",
891 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
895 /* Write enable interface. */
896 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
897 if ((ifname
= vector_slot(ripng_enable_if
, i
)) != NULL
)
898 vty_out(vty
, "%s%s\n",
899 config_mode
? " network " : " ", ifname
);
901 /* Write passive interface. */
903 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
904 if ((ifname
= vector_slot(Vripng_passive_interface
, i
))
906 vty_out(vty
, " passive-interface %s\n", ifname
);
911 /* RIPng enable on specified interface or matched network. */
912 DEFUN (ripng_network
,
914 "network IF_OR_ADDR",
915 "RIPng enable on specified interface or network.\n"
916 "Interface or address\n")
918 int idx_if_or_addr
= 1;
922 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
924 /* Given string is IPv6 network or interface name. */
926 ret
= ripng_enable_network_add(&p
);
928 ret
= ripng_enable_if_add(argv
[idx_if_or_addr
]->arg
);
931 vty_out(vty
, "There is same network configuration %s\n",
932 argv
[idx_if_or_addr
]->arg
);
933 return CMD_WARNING_CONFIG_FAILED
;
939 /* RIPng enable on specified interface or matched network. */
940 DEFUN (no_ripng_network
,
941 no_ripng_network_cmd
,
942 "no network IF_OR_ADDR",
944 "RIPng enable on specified interface or network.\n"
945 "Interface or address\n")
947 int idx_if_or_addr
= 2;
951 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
953 /* Given string is interface name. */
955 ret
= ripng_enable_network_delete(&p
);
957 ret
= ripng_enable_if_delete(argv
[idx_if_or_addr
]->arg
);
960 vty_out(vty
, "can't find network %s\n",
961 argv
[idx_if_or_addr
]->arg
);
962 return CMD_WARNING_CONFIG_FAILED
;
968 DEFUN (ipv6_ripng_split_horizon
,
969 ipv6_ripng_split_horizon_cmd
,
970 "ipv6 ripng split-horizon",
972 "Routing Information Protocol\n"
973 "Perform split horizon\n")
975 VTY_DECLVAR_CONTEXT(interface
, ifp
);
976 struct ripng_interface
*ri
;
980 ri
->split_horizon
= RIPNG_SPLIT_HORIZON
;
984 DEFUN (ipv6_ripng_split_horizon_poisoned_reverse
,
985 ipv6_ripng_split_horizon_poisoned_reverse_cmd
,
986 "ipv6 ripng split-horizon poisoned-reverse",
988 "Routing Information Protocol\n"
989 "Perform split horizon\n"
990 "With poisoned-reverse\n")
992 VTY_DECLVAR_CONTEXT(interface
, ifp
);
993 struct ripng_interface
*ri
;
997 ri
->split_horizon
= RIPNG_SPLIT_HORIZON_POISONED_REVERSE
;
1001 DEFUN (no_ipv6_ripng_split_horizon
,
1002 no_ipv6_ripng_split_horizon_cmd
,
1003 "no ipv6 ripng split-horizon [poisoned-reverse]",
1006 "Routing Information Protocol\n"
1007 "Perform split horizon\n"
1008 "With poisoned-reverse\n")
1010 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1011 struct ripng_interface
*ri
;
1015 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
1019 DEFUN (ripng_passive_interface
,
1020 ripng_passive_interface_cmd
,
1021 "passive-interface IFNAME",
1022 "Suppress routing updates on an interface\n"
1026 return ripng_passive_interface_set(vty
, argv
[idx_ifname
]->arg
);
1029 DEFUN (no_ripng_passive_interface
,
1030 no_ripng_passive_interface_cmd
,
1031 "no passive-interface IFNAME",
1033 "Suppress routing updates on an interface\n"
1037 return ripng_passive_interface_unset(vty
, argv
[idx_ifname
]->arg
);
1040 static struct ripng_interface
*ri_new(void)
1042 struct ripng_interface
*ri
;
1043 ri
= XCALLOC(MTYPE_IF
, sizeof(struct ripng_interface
));
1045 /* Set default split-horizon behavior. If the interface is Frame
1046 Relay or SMDS is enabled, the default value for split-horizon is
1047 off. But currently Zebra does detect Frame Relay or SMDS
1048 interface. So all interface is set to split horizon. */
1049 ri
->split_horizon_default
= RIPNG_SPLIT_HORIZON
;
1050 ri
->split_horizon
= ri
->split_horizon_default
;
1055 static int ripng_if_new_hook(struct interface
*ifp
)
1057 ifp
->info
= ri_new();
1061 /* Called when interface structure deleted. */
1062 static int ripng_if_delete_hook(struct interface
*ifp
)
1064 XFREE(MTYPE_IF
, ifp
->info
);
1069 /* Configuration write function for ripngd. */
1070 static int interface_config_write(struct vty
*vty
)
1072 struct listnode
*node
;
1073 struct interface
*ifp
;
1074 struct ripng_interface
*ri
;
1077 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
)) {
1080 /* Do not display the interface if there is no
1081 * configuration about it.
1084 && (ri
->split_horizon
== ri
->split_horizon_default
))
1087 vty_out(vty
, "interface %s\n", ifp
->name
);
1089 vty_out(vty
, " description %s\n", ifp
->desc
);
1091 /* Split horizon. */
1092 if (ri
->split_horizon
!= ri
->split_horizon_default
) {
1093 switch (ri
->split_horizon
) {
1094 case RIPNG_SPLIT_HORIZON
:
1095 vty_out(vty
, " ipv6 ripng split-horizon\n");
1097 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE
:
1099 " ipv6 ripng split-horizon poisoned-reverse\n");
1101 case RIPNG_NO_SPLIT_HORIZON
:
1103 vty_out(vty
, " no ipv6 ripng split-horizon\n");
1108 vty_out(vty
, "!\n");
1115 /* ripngd's interface node. */
1116 static struct cmd_node interface_node
= {
1117 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1120 /* Initialization of interface. */
1121 void ripng_if_init()
1123 /* Interface initialize. */
1124 hook_register_prio(if_add
, 0, ripng_if_new_hook
);
1125 hook_register_prio(if_del
, 0, ripng_if_delete_hook
);
1127 /* RIPng enable network init. */
1128 ripng_enable_network
= route_table_init();
1130 /* RIPng enable interface init. */
1131 ripng_enable_if
= vector_init(1);
1133 /* RIPng passive interface. */
1134 Vripng_passive_interface
= vector_init(1);
1136 /* Install interface node. */
1137 install_node(&interface_node
, interface_config_write
);
1140 install_element(RIPNG_NODE
, &ripng_network_cmd
);
1141 install_element(RIPNG_NODE
, &no_ripng_network_cmd
);
1142 install_element(RIPNG_NODE
, &ripng_passive_interface_cmd
);
1143 install_element(RIPNG_NODE
, &no_ripng_passive_interface_cmd
);
1145 install_element(INTERFACE_NODE
, &ipv6_ripng_split_horizon_cmd
);
1146 install_element(INTERFACE_NODE
,
1147 &ipv6_ripng_split_horizon_poisoned_reverse_cmd
);
1148 install_element(INTERFACE_NODE
, &no_ipv6_ripng_split_horizon_cmd
);