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 if (ripngd_privs
.change(ZPRIVS_RAISE
))
78 "ripng_multicast_join: could not raise privs");
80 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
,
81 (char *)&mreq
, sizeof(mreq
));
84 if (ripngd_privs
.change(ZPRIVS_LOWER
))
87 "ripng_multicast_join: could not lower privs");
89 if (ret
< 0 && save_errno
== EADDRINUSE
) {
91 * Group is already joined. This occurs due to sloppy
93 * management, in particular declining to leave the
95 * an interface that has just gone down.
97 zlog_warn("ripng join on %s EADDRINUSE (ignoring)\n",
99 return 0; /* not an error */
103 zlog_warn("can't setsockopt IPV6_JOIN_GROUP: %s",
104 safe_strerror(save_errno
));
106 if (IS_RIPNG_DEBUG_EVENT
)
108 "RIPng %s join to all-rip-routers multicast group",
117 /* Leave from the all rip routers multicast group. */
118 static int ripng_multicast_leave(struct interface
*ifp
)
121 struct ipv6_mreq mreq
;
123 if (if_is_multicast(ifp
)) {
124 memset(&mreq
, 0, sizeof(mreq
));
125 inet_pton(AF_INET6
, RIPNG_GROUP
, &mreq
.ipv6mr_multiaddr
);
126 mreq
.ipv6mr_interface
= ifp
->ifindex
;
128 ret
= setsockopt(ripng
->sock
, IPPROTO_IPV6
, IPV6_LEAVE_GROUP
,
129 (char *)&mreq
, sizeof(mreq
));
131 zlog_warn("can't setsockopt IPV6_LEAVE_GROUP: %s\n",
132 safe_strerror(errno
));
134 if (IS_RIPNG_DEBUG_EVENT
)
136 "RIPng %s leave from all-rip-routers multicast group",
146 /* How many link local IPv6 address could be used on the interface ? */
147 static int ripng_if_ipv6_lladdress_check(struct interface
*ifp
)
150 struct connected
*connected
;
153 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, nn
, connected
)) {
155 p
= connected
->address
;
157 if ((p
->family
== AF_INET6
)
158 && IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
165 static int ripng_if_down(struct interface
*ifp
)
167 struct route_node
*rp
;
168 struct ripng_info
*rinfo
;
169 struct ripng_interface
*ri
;
170 struct list
*list
= NULL
;
171 struct listnode
*listnode
= NULL
, *nextnode
= NULL
;
174 for (rp
= route_top(ripng
->table
); rp
; rp
= route_next(rp
))
175 if ((list
= rp
->info
) != NULL
)
176 for (ALL_LIST_ELEMENTS(list
, listnode
, nextnode
,
178 if (rinfo
->ifindex
== ifp
->ifindex
)
179 ripng_ecmp_delete(rinfo
);
184 if (IS_RIPNG_DEBUG_EVENT
)
185 zlog_debug("turn off %s", ifp
->name
);
187 /* Leave from multicast group. */
188 ripng_multicast_leave(ifp
);
196 /* Inteface link up message processing. */
197 int ripng_interface_up(int command
, struct zclient
*zclient
,
198 zebra_size_t length
, vrf_id_t vrf_id
)
201 struct interface
*ifp
;
203 /* zebra_interface_state_read() updates interface structure in iflist.
206 ifp
= zebra_interface_state_read(s
, vrf_id
);
211 if (IS_RIPNG_DEBUG_ZEBRA
)
213 "interface up %s index %d flags %llx metric %d mtu %d",
214 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
215 ifp
->metric
, ifp
->mtu6
);
217 /* Check if this interface is RIPng enabled or not. */
218 ripng_enable_apply(ifp
);
220 /* Check for a passive interface. */
221 ripng_passive_interface_apply(ifp
);
223 /* Apply distribute list to the all interface. */
224 ripng_distribute_update_interface(ifp
);
229 /* Inteface link down message processing. */
230 int ripng_interface_down(int command
, struct zclient
*zclient
,
231 zebra_size_t length
, vrf_id_t vrf_id
)
234 struct interface
*ifp
;
236 /* zebra_interface_state_read() updates interface structure in iflist.
239 ifp
= zebra_interface_state_read(s
, vrf_id
);
246 if (IS_RIPNG_DEBUG_ZEBRA
)
248 "interface down %s index %d flags %#llx metric %d mtu %d",
249 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
250 ifp
->metric
, ifp
->mtu6
);
255 /* Inteface addition message from zebra. */
256 int ripng_interface_add(int command
, struct zclient
*zclient
,
257 zebra_size_t length
, vrf_id_t vrf_id
)
259 struct interface
*ifp
;
261 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
263 if (IS_RIPNG_DEBUG_ZEBRA
)
265 "RIPng interface add %s index %d flags %#llx metric %d mtu %d",
266 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
267 ifp
->metric
, ifp
->mtu6
);
269 /* Check is this interface is RIP enabled or not.*/
270 ripng_enable_apply(ifp
);
272 /* Apply distribute list to the interface. */
273 ripng_distribute_update_interface(ifp
);
275 /* Check interface routemap. */
276 ripng_if_rmap_update_interface(ifp
);
281 int ripng_interface_delete(int command
, struct zclient
*zclient
,
282 zebra_size_t length
, vrf_id_t vrf_id
)
284 struct interface
*ifp
;
288 /* zebra_interface_state_read() updates interface structure in iflist
290 ifp
= zebra_interface_state_read(s
, vrf_id
);
299 zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d",
300 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
301 ifp
->metric
, ifp
->mtu6
);
303 /* To support pseudo interface do not free interface structure. */
304 /* if_delete(ifp); */
305 if_set_index(ifp
, IFINDEX_INTERNAL
);
310 void ripng_interface_clean(void)
312 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
313 struct interface
*ifp
;
314 struct ripng_interface
*ri
;
316 FOR_ALL_INTERFACES (vrf
, ifp
) {
319 ri
->enable_network
= 0;
320 ri
->enable_interface
= 0;
324 thread_cancel(ri
->t_wakeup
);
330 void ripng_interface_reset(void)
332 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
333 struct interface
*ifp
;
334 struct ripng_interface
*ri
;
336 FOR_ALL_INTERFACES (vrf
, ifp
) {
339 ri
->enable_network
= 0;
340 ri
->enable_interface
= 0;
343 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
344 ri
->split_horizon_default
= RIPNG_NO_SPLIT_HORIZON
;
346 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
347 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
349 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
350 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
353 thread_cancel(ri
->t_wakeup
);
361 static void ripng_apply_address_add(struct connected
*ifc
)
363 struct prefix_ipv6 address
;
369 if (!if_is_up(ifc
->ifp
))
374 memset(&address
, 0, sizeof(address
));
375 address
.family
= p
->family
;
376 address
.prefix
= p
->u
.prefix6
;
377 address
.prefixlen
= p
->prefixlen
;
378 apply_mask_ipv6(&address
);
380 /* Check if this interface is RIP enabled or not
381 or Check if this address's prefix is RIP enabled */
382 if ((ripng_enable_if_lookup(ifc
->ifp
->name
) >= 0)
383 || (ripng_enable_network_lookup2(ifc
) >= 0))
384 ripng_redistribute_add(ZEBRA_ROUTE_CONNECT
,
385 RIPNG_ROUTE_INTERFACE
, &address
,
386 ifc
->ifp
->ifindex
, NULL
, 0);
389 int ripng_interface_address_add(int command
, struct zclient
*zclient
,
390 zebra_size_t length
, vrf_id_t vrf_id
)
395 c
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD
,
396 zclient
->ibuf
, vrf_id
);
403 if (p
->family
== AF_INET6
) {
404 struct ripng_interface
*ri
= c
->ifp
->info
;
406 if (IS_RIPNG_DEBUG_ZEBRA
)
407 zlog_debug("RIPng connected address %s/%d add",
408 inet6_ntoa(p
->u
.prefix6
), p
->prefixlen
);
410 /* Check is this prefix needs to be redistributed. */
411 ripng_apply_address_add(c
);
413 /* Let's try once again whether the interface could be activated
416 /* Check if this interface is RIP enabled or not.*/
417 ripng_enable_apply(c
->ifp
);
419 /* Apply distribute list to the interface. */
420 ripng_distribute_update_interface(c
->ifp
);
422 /* Check interface routemap. */
423 ripng_if_rmap_update_interface(c
->ifp
);
430 static void ripng_apply_address_del(struct connected
*ifc
)
432 struct prefix_ipv6 address
;
438 if (!if_is_up(ifc
->ifp
))
443 memset(&address
, 0, sizeof(address
));
444 address
.family
= p
->family
;
445 address
.prefix
= p
->u
.prefix6
;
446 address
.prefixlen
= p
->prefixlen
;
447 apply_mask_ipv6(&address
);
449 ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
450 &address
, ifc
->ifp
->ifindex
);
453 int ripng_interface_address_delete(int command
, struct zclient
*zclient
,
454 zebra_size_t length
, vrf_id_t vrf_id
)
456 struct connected
*ifc
;
458 char buf
[INET6_ADDRSTRLEN
];
460 ifc
= zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE
,
461 zclient
->ibuf
, vrf_id
);
466 if (p
->family
== AF_INET6
) {
467 if (IS_RIPNG_DEBUG_ZEBRA
)
469 "RIPng connected address %s/%d delete",
470 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
,
474 /* Check wether this prefix needs to be removed. */
475 ripng_apply_address_del(ifc
);
483 /* RIPng enable interface vector. */
484 vector ripng_enable_if
;
486 /* RIPng enable network table. */
487 struct route_table
*ripng_enable_network
;
489 /* Lookup RIPng enable network. */
490 /* Check wether the interface has at least a connected prefix that
491 * is within the ripng_enable_network table. */
492 static int ripng_enable_network_lookup_if(struct interface
*ifp
)
494 struct listnode
*node
;
495 struct connected
*connected
;
496 struct prefix_ipv6 address
;
498 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
500 struct route_node
*n
;
502 p
= connected
->address
;
504 if (p
->family
== AF_INET6
) {
505 address
.family
= AF_INET6
;
506 address
.prefix
= p
->u
.prefix6
;
507 address
.prefixlen
= IPV6_MAX_BITLEN
;
509 n
= route_node_match(ripng_enable_network
,
510 (struct prefix
*)&address
);
512 route_unlock_node(n
);
520 /* Check wether connected is within the ripng_enable_network table. */
521 static int ripng_enable_network_lookup2(struct connected
*connected
)
523 struct prefix_ipv6 address
;
526 p
= connected
->address
;
528 if (p
->family
== AF_INET6
) {
529 struct route_node
*node
;
531 address
.family
= p
->family
;
532 address
.prefix
= p
->u
.prefix6
;
533 address
.prefixlen
= IPV6_MAX_BITLEN
;
535 /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within
536 * ripng_enable_network */
537 node
= route_node_match(ripng_enable_network
,
538 (struct prefix
*)&address
);
541 route_unlock_node(node
);
549 /* Add RIPng enable network. */
550 static int ripng_enable_network_add(struct prefix
*p
)
552 struct route_node
*node
;
554 node
= route_node_get(ripng_enable_network
, p
);
557 route_unlock_node(node
);
560 node
->info
= (void *)1;
562 /* XXX: One should find a better solution than a generic one */
563 ripng_enable_apply_all();
568 /* Delete RIPng enable network. */
569 static int ripng_enable_network_delete(struct prefix
*p
)
571 struct route_node
*node
;
573 node
= route_node_lookup(ripng_enable_network
, p
);
577 /* Unlock info lock. */
578 route_unlock_node(node
);
580 /* Unlock lookup lock. */
581 route_unlock_node(node
);
588 /* Lookup function. */
589 static int ripng_enable_if_lookup(const char *ifname
)
594 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
595 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
)
596 if (strcmp(str
, ifname
) == 0)
601 /* Add interface to ripng_enable_if. */
602 static int ripng_enable_if_add(const char *ifname
)
606 ret
= ripng_enable_if_lookup(ifname
);
610 vector_set(ripng_enable_if
, strdup(ifname
));
612 ripng_enable_apply_all();
617 /* Delete interface from ripng_enable_if. */
618 static int ripng_enable_if_delete(const char *ifname
)
623 index
= ripng_enable_if_lookup(ifname
);
627 str
= vector_slot(ripng_enable_if
, index
);
629 vector_unset(ripng_enable_if
, index
);
631 ripng_enable_apply_all();
636 /* Wake up interface. */
637 static int ripng_interface_wakeup(struct thread
*t
)
639 struct interface
*ifp
;
640 struct ripng_interface
*ri
;
648 /* Join to multicast group. */
649 if (ripng_multicast_join(ifp
) < 0) {
650 flog_err(LIB_ERR_SOCKET
,
651 "multicast join failed, interface %s not running",
656 /* Set running flag. */
659 /* Send RIP request to the interface. */
665 static void ripng_connect_set(struct interface
*ifp
, int set
)
667 struct listnode
*node
, *nnode
;
668 struct connected
*connected
;
669 struct prefix_ipv6 address
;
671 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, connected
)) {
673 p
= connected
->address
;
675 if (p
->family
!= AF_INET6
)
678 address
.family
= AF_INET6
;
679 address
.prefix
= p
->u
.prefix6
;
680 address
.prefixlen
= p
->prefixlen
;
681 apply_mask_ipv6(&address
);
684 /* Check once more wether this prefix is within a
685 * "network IF_OR_PREF" one */
686 if ((ripng_enable_if_lookup(connected
->ifp
->name
) >= 0)
687 || (ripng_enable_network_lookup2(connected
) >= 0))
688 ripng_redistribute_add(
690 RIPNG_ROUTE_INTERFACE
, &address
,
691 connected
->ifp
->ifindex
, NULL
, 0);
693 ripng_redistribute_delete(
694 ZEBRA_ROUTE_CONNECT
, RIPNG_ROUTE_INTERFACE
,
695 &address
, connected
->ifp
->ifindex
);
696 if (ripng_redistribute_check(ZEBRA_ROUTE_CONNECT
))
697 ripng_redistribute_add(
699 RIPNG_ROUTE_REDISTRIBUTE
, &address
,
700 connected
->ifp
->ifindex
, NULL
, 0);
705 /* Check RIPng is enabed on this interface. */
706 void ripng_enable_apply(struct interface
*ifp
)
709 struct ripng_interface
*ri
= NULL
;
711 /* Check interface. */
717 /* Is this interface a candidate for RIPng ? */
718 ret
= ripng_enable_network_lookup_if(ifp
);
720 /* If the interface is matched. */
722 ri
->enable_network
= 1;
724 ri
->enable_network
= 0;
726 /* Check interface name configuration. */
727 ret
= ripng_enable_if_lookup(ifp
->name
);
729 ri
->enable_interface
= 1;
731 ri
->enable_interface
= 0;
733 /* any candidate interface MUST have a link-local IPv6 address */
734 if ((!ripng_if_ipv6_lladdress_check(ifp
))
735 && (ri
->enable_network
|| ri
->enable_interface
)) {
736 ri
->enable_network
= 0;
737 ri
->enable_interface
= 0;
738 zlog_warn("Interface %s does not have any link-local address",
742 /* Update running status of the interface. */
743 if (ri
->enable_network
|| ri
->enable_interface
) {
744 zlog_info("RIPng INTERFACE ON %s", ifp
->name
);
746 /* Add interface wake up thread. */
747 thread_add_timer(master
, ripng_interface_wakeup
, ifp
, 1,
750 ripng_connect_set(ifp
, 1);
753 /* Might as well clean up the route table as well
754 * ripng_if_down sets to 0 ri->running, and displays
759 ripng_connect_set(ifp
, 0);
764 /* Set distribute list to all interfaces. */
765 static void ripng_enable_apply_all(void)
767 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
768 struct interface
*ifp
;
770 FOR_ALL_INTERFACES (vrf
, ifp
)
771 ripng_enable_apply(ifp
);
774 /* Clear all network and neighbor configuration */
775 void ripng_clean_network()
779 struct route_node
*rn
;
781 /* ripng_enable_network */
782 for (rn
= route_top(ripng_enable_network
); rn
; rn
= route_next(rn
))
785 route_unlock_node(rn
);
788 /* ripng_enable_if */
789 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
790 if ((str
= vector_slot(ripng_enable_if
, i
)) != NULL
) {
792 vector_slot(ripng_enable_if
, i
) = NULL
;
796 /* Vector to store passive-interface name. */
797 vector Vripng_passive_interface
;
799 /* Utility function for looking up passive interface settings. */
800 static int ripng_passive_interface_lookup(const char *ifname
)
805 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
806 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
)
807 if (strcmp(str
, ifname
) == 0)
812 void ripng_passive_interface_apply(struct interface
*ifp
)
815 struct ripng_interface
*ri
;
819 ret
= ripng_passive_interface_lookup(ifp
->name
);
826 static void ripng_passive_interface_apply_all(void)
828 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
829 struct interface
*ifp
;
831 FOR_ALL_INTERFACES (vrf
, ifp
)
832 ripng_passive_interface_apply(ifp
);
835 /* Passive interface. */
836 static int ripng_passive_interface_set(struct vty
*vty
, const char *ifname
)
838 if (ripng_passive_interface_lookup(ifname
) >= 0)
839 return CMD_WARNING_CONFIG_FAILED
;
841 vector_set(Vripng_passive_interface
, strdup(ifname
));
843 ripng_passive_interface_apply_all();
848 static int ripng_passive_interface_unset(struct vty
*vty
, const char *ifname
)
853 i
= ripng_passive_interface_lookup(ifname
);
855 return CMD_WARNING_CONFIG_FAILED
;
857 str
= vector_slot(Vripng_passive_interface
, i
);
859 vector_unset(Vripng_passive_interface
, i
);
861 ripng_passive_interface_apply_all();
866 /* Free all configured RIP passive-interface settings. */
867 void ripng_passive_interface_clean(void)
872 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
873 if ((str
= vector_slot(Vripng_passive_interface
, i
)) != NULL
) {
875 vector_slot(Vripng_passive_interface
, i
) = NULL
;
877 ripng_passive_interface_apply_all();
880 /* Write RIPng enable network and interface to the vty. */
881 int ripng_network_write(struct vty
*vty
, int config_mode
)
885 struct route_node
*node
;
888 /* Write enable network. */
889 for (node
= route_top(ripng_enable_network
); node
;
890 node
= route_next(node
))
892 struct prefix
*p
= &node
->p
;
893 vty_out(vty
, "%s%s/%d\n",
894 config_mode
? " network " : " ",
895 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
899 /* Write enable interface. */
900 for (i
= 0; i
< vector_active(ripng_enable_if
); i
++)
901 if ((ifname
= vector_slot(ripng_enable_if
, i
)) != NULL
)
902 vty_out(vty
, "%s%s\n",
903 config_mode
? " network " : " ", ifname
);
905 /* Write passive interface. */
907 for (i
= 0; i
< vector_active(Vripng_passive_interface
); i
++)
908 if ((ifname
= vector_slot(Vripng_passive_interface
, i
))
910 vty_out(vty
, " passive-interface %s\n", ifname
);
915 /* RIPng enable on specified interface or matched network. */
916 DEFUN (ripng_network
,
918 "network IF_OR_ADDR",
919 "RIPng enable on specified interface or network.\n"
920 "Interface or address\n")
922 int idx_if_or_addr
= 1;
926 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
928 /* Given string is IPv6 network or interface name. */
930 ret
= ripng_enable_network_add(&p
);
932 ret
= ripng_enable_if_add(argv
[idx_if_or_addr
]->arg
);
935 vty_out(vty
, "There is same network configuration %s\n",
936 argv
[idx_if_or_addr
]->arg
);
937 return CMD_WARNING_CONFIG_FAILED
;
943 /* RIPng enable on specified interface or matched network. */
944 DEFUN (no_ripng_network
,
945 no_ripng_network_cmd
,
946 "no network IF_OR_ADDR",
948 "RIPng enable on specified interface or network.\n"
949 "Interface or address\n")
951 int idx_if_or_addr
= 2;
955 ret
= str2prefix(argv
[idx_if_or_addr
]->arg
, &p
);
957 /* Given string is interface name. */
959 ret
= ripng_enable_network_delete(&p
);
961 ret
= ripng_enable_if_delete(argv
[idx_if_or_addr
]->arg
);
964 vty_out(vty
, "can't find network %s\n",
965 argv
[idx_if_or_addr
]->arg
);
966 return CMD_WARNING_CONFIG_FAILED
;
972 DEFUN (ipv6_ripng_split_horizon
,
973 ipv6_ripng_split_horizon_cmd
,
974 "ipv6 ripng split-horizon",
976 "Routing Information Protocol\n"
977 "Perform split horizon\n")
979 VTY_DECLVAR_CONTEXT(interface
, ifp
);
980 struct ripng_interface
*ri
;
984 ri
->split_horizon
= RIPNG_SPLIT_HORIZON
;
988 DEFUN (ipv6_ripng_split_horizon_poisoned_reverse
,
989 ipv6_ripng_split_horizon_poisoned_reverse_cmd
,
990 "ipv6 ripng split-horizon poisoned-reverse",
992 "Routing Information Protocol\n"
993 "Perform split horizon\n"
994 "With poisoned-reverse\n")
996 VTY_DECLVAR_CONTEXT(interface
, ifp
);
997 struct ripng_interface
*ri
;
1001 ri
->split_horizon
= RIPNG_SPLIT_HORIZON_POISONED_REVERSE
;
1005 DEFUN (no_ipv6_ripng_split_horizon
,
1006 no_ipv6_ripng_split_horizon_cmd
,
1007 "no ipv6 ripng split-horizon [poisoned-reverse]",
1010 "Routing Information Protocol\n"
1011 "Perform split horizon\n"
1012 "With poisoned-reverse\n")
1014 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1015 struct ripng_interface
*ri
;
1019 ri
->split_horizon
= RIPNG_NO_SPLIT_HORIZON
;
1023 DEFUN (ripng_passive_interface
,
1024 ripng_passive_interface_cmd
,
1025 "passive-interface IFNAME",
1026 "Suppress routing updates on an interface\n"
1030 return ripng_passive_interface_set(vty
, argv
[idx_ifname
]->arg
);
1033 DEFUN (no_ripng_passive_interface
,
1034 no_ripng_passive_interface_cmd
,
1035 "no passive-interface IFNAME",
1037 "Suppress routing updates on an interface\n"
1041 return ripng_passive_interface_unset(vty
, argv
[idx_ifname
]->arg
);
1044 static struct ripng_interface
*ri_new(void)
1046 struct ripng_interface
*ri
;
1047 ri
= XCALLOC(MTYPE_IF
, sizeof(struct ripng_interface
));
1049 /* Set default split-horizon behavior. If the interface is Frame
1050 Relay or SMDS is enabled, the default value for split-horizon is
1051 off. But currently Zebra does detect Frame Relay or SMDS
1052 interface. So all interface is set to split horizon. */
1053 ri
->split_horizon_default
= RIPNG_SPLIT_HORIZON
;
1054 ri
->split_horizon
= ri
->split_horizon_default
;
1059 static int ripng_if_new_hook(struct interface
*ifp
)
1061 ifp
->info
= ri_new();
1065 /* Called when interface structure deleted. */
1066 static int ripng_if_delete_hook(struct interface
*ifp
)
1068 XFREE(MTYPE_IF
, ifp
->info
);
1073 /* Configuration write function for ripngd. */
1074 static int interface_config_write(struct vty
*vty
)
1076 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1077 struct interface
*ifp
;
1078 struct ripng_interface
*ri
;
1081 FOR_ALL_INTERFACES (vrf
, ifp
) {
1084 /* Do not display the interface if there is no
1085 * configuration about it.
1088 && (ri
->split_horizon
== ri
->split_horizon_default
))
1091 vty_frame(vty
, "interface %s\n", ifp
->name
);
1093 vty_out(vty
, " description %s\n", ifp
->desc
);
1095 /* Split horizon. */
1096 if (ri
->split_horizon
!= ri
->split_horizon_default
) {
1097 switch (ri
->split_horizon
) {
1098 case RIPNG_SPLIT_HORIZON
:
1099 vty_out(vty
, " ipv6 ripng split-horizon\n");
1101 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE
:
1103 " ipv6 ripng split-horizon poisoned-reverse\n");
1105 case RIPNG_NO_SPLIT_HORIZON
:
1107 vty_out(vty
, " no ipv6 ripng split-horizon\n");
1112 vty_endframe(vty
, "!\n");
1119 /* ripngd's interface node. */
1120 static struct cmd_node interface_node
= {
1121 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1124 /* Initialization of interface. */
1125 void ripng_if_init()
1127 /* Interface initialize. */
1128 hook_register_prio(if_add
, 0, ripng_if_new_hook
);
1129 hook_register_prio(if_del
, 0, ripng_if_delete_hook
);
1131 /* RIPng enable network init. */
1132 ripng_enable_network
= route_table_init();
1134 /* RIPng enable interface init. */
1135 ripng_enable_if
= vector_init(1);
1137 /* RIPng passive interface. */
1138 Vripng_passive_interface
= vector_init(1);
1140 /* Install interface node. */
1141 install_node(&interface_node
, interface_config_write
);
1144 install_element(RIPNG_NODE
, &ripng_network_cmd
);
1145 install_element(RIPNG_NODE
, &no_ripng_network_cmd
);
1146 install_element(RIPNG_NODE
, &ripng_passive_interface_cmd
);
1147 install_element(RIPNG_NODE
, &no_ripng_passive_interface_cmd
);
1149 install_element(INTERFACE_NODE
, &ipv6_ripng_split_horizon_cmd
);
1150 install_element(INTERFACE_NODE
,
1151 &ipv6_ripng_split_horizon_poisoned_reverse_cmd
);
1152 install_element(INTERFACE_NODE
, &no_ipv6_ripng_split_horizon_cmd
);