]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripngd/ripng_interface.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / ripngd / ripng_interface.c
index 02fab6825483b48a77449e905063ec0e7c9ee78a..4d14fbab649290301604d853d2173e7782560426 100644 (file)
 #include "stream.h"
 #include "zclient.h"
 #include "command.h"
-#include "table.h"
+#include "agg_table.h"
 #include "thread.h"
 #include "privs.h"
 #include "vrf.h"
+#include "lib_errors.h"
+#include "northbound_cli.h"
 
 #include "ripngd/ripngd.h"
 #include "ripngd/ripng_debug.h"
@@ -47,8 +49,6 @@
 #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP 
 #endif
 
-extern struct zebra_privs_t ripngd_privs;
-
 /* Static utility function. */
 static void ripng_enable_apply(struct interface *);
 static void ripng_passive_interface_apply(struct interface *);
@@ -73,15 +73,14 @@ static int ripng_multicast_join(struct interface *ifp)
                 * While this is bogus, privs are available and easy to use
                 * for this call as a workaround.
                 */
-               if (ripngd_privs.change(ZPRIVS_RAISE))
-                       zlog_err("ripng_multicast_join: could not raise privs");
+               frr_elevate_privs(&ripngd_privs) {
 
-               ret = setsockopt(ripng->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
-                                (char *)&mreq, sizeof(mreq));
-               save_errno = errno;
+                       ret = setsockopt(ripng->sock, IPPROTO_IPV6,
+                                        IPV6_JOIN_GROUP,
+                                        (char *)&mreq, sizeof(mreq));
+                       save_errno = errno;
 
-               if (ripngd_privs.change(ZPRIVS_LOWER))
-                       zlog_err("ripng_multicast_join: could not lower privs");
+               }
 
                if (ret < 0 && save_errno == EADDRINUSE) {
                        /*
@@ -161,14 +160,15 @@ static int ripng_if_ipv6_lladdress_check(struct interface *ifp)
 
 static int ripng_if_down(struct interface *ifp)
 {
-       struct route_node *rp;
+       struct agg_node *rp;
        struct ripng_info *rinfo;
        struct ripng_interface *ri;
        struct list *list = NULL;
        struct listnode *listnode = NULL, *nextnode = NULL;
 
        if (ripng)
-               for (rp = route_top(ripng->table); rp; rp = route_next(rp))
+               for (rp = agg_route_top(ripng->table); rp;
+                    rp = agg_route_next(rp))
                        if ((list = rp->info) != NULL)
                                for (ALL_LIST_ELEMENTS(list, listnode, nextnode,
                                                       rinfo))
@@ -299,18 +299,18 @@ int ripng_interface_delete(int command, struct zclient *zclient,
 
        /* To support pseudo interface do not free interface structure.  */
        /* if_delete(ifp); */
-       ifp->ifindex = IFINDEX_DELETED;
+       if_set_index(ifp, IFINDEX_INTERNAL);
 
        return 0;
 }
 
 void ripng_interface_clean(void)
 {
-       struct listnode *node, *nnode;
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
        struct ripng_interface *ri;
 
-       for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) {
+       FOR_ALL_INTERFACES (vrf, ifp) {
                ri = ifp->info;
 
                ri->enable_network = 0;
@@ -324,37 +324,6 @@ void ripng_interface_clean(void)
        }
 }
 
-void ripng_interface_reset(void)
-{
-       struct listnode *node;
-       struct interface *ifp;
-       struct ripng_interface *ri;
-
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
-               ri = ifp->info;
-
-               ri->enable_network = 0;
-               ri->enable_interface = 0;
-               ri->running = 0;
-
-               ri->split_horizon = RIPNG_NO_SPLIT_HORIZON;
-               ri->split_horizon_default = RIPNG_NO_SPLIT_HORIZON;
-
-               ri->list[RIPNG_FILTER_IN] = NULL;
-               ri->list[RIPNG_FILTER_OUT] = NULL;
-
-               ri->prefix[RIPNG_FILTER_IN] = NULL;
-               ri->prefix[RIPNG_FILTER_OUT] = NULL;
-
-               if (ri->t_wakeup) {
-                       thread_cancel(ri->t_wakeup);
-                       ri->t_wakeup = NULL;
-               }
-
-               ri->passive = 0;
-       }
-}
-
 static void ripng_apply_address_add(struct connected *ifc)
 {
        struct prefix_ipv6 address;
@@ -481,7 +450,7 @@ int ripng_interface_address_delete(int command, struct zclient *zclient,
 vector ripng_enable_if;
 
 /* RIPng enable network table. */
-struct route_table *ripng_enable_network;
+struct agg_table *ripng_enable_network;
 
 /* Lookup RIPng enable network. */
 /* Check wether the interface has at least a connected prefix that
@@ -494,7 +463,7 @@ static int ripng_enable_network_lookup_if(struct interface *ifp)
 
        for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
                struct prefix *p;
-               struct route_node *node;
+               struct agg_node *n;
 
                p = connected->address;
 
@@ -503,10 +472,10 @@ static int ripng_enable_network_lookup_if(struct interface *ifp)
                        address.prefix = p->u.prefix6;
                        address.prefixlen = IPV6_MAX_BITLEN;
 
-                       node = route_node_match(ripng_enable_network,
-                                               (struct prefix *)&address);
-                       if (node) {
-                               route_unlock_node(node);
+                       n = agg_node_match(ripng_enable_network,
+                                          (struct prefix *)&address);
+                       if (n) {
+                               agg_unlock_node(n);
                                return 1;
                        }
                }
@@ -523,7 +492,7 @@ static int ripng_enable_network_lookup2(struct connected *connected)
        p = connected->address;
 
        if (p->family == AF_INET6) {
-               struct route_node *node;
+               struct agg_node *node;
 
                address.family = p->family;
                address.prefix = p->u.prefix6;
@@ -531,11 +500,11 @@ static int ripng_enable_network_lookup2(struct connected *connected)
 
                /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within
                 * ripng_enable_network */
-               node = route_node_match(ripng_enable_network,
-                                       (struct prefix *)&address);
+               node = agg_node_match(ripng_enable_network,
+                                     (struct prefix *)&address);
 
                if (node) {
-                       route_unlock_node(node);
+                       agg_unlock_node(node);
                        return 1;
                }
        }
@@ -544,42 +513,43 @@ static int ripng_enable_network_lookup2(struct connected *connected)
 }
 
 /* Add RIPng enable network. */
-static int ripng_enable_network_add(struct prefix *p)
+int ripng_enable_network_add(struct prefix *p)
 {
-       struct route_node *node;
+       struct agg_node *node;
 
-       node = route_node_get(ripng_enable_network, p);
+       node = agg_node_get(ripng_enable_network, p);
 
        if (node->info) {
-               route_unlock_node(node);
-               return -1;
+               agg_unlock_node(node);
+               return NB_ERR_INCONSISTENCY;
        } else
                node->info = (void *)1;
 
        /* XXX: One should find a better solution than a generic one */
        ripng_enable_apply_all();
 
-       return 1;
+       return NB_OK;
 }
 
 /* Delete RIPng enable network. */
-static int ripng_enable_network_delete(struct prefix *p)
+int ripng_enable_network_delete(struct prefix *p)
 {
-       struct route_node *node;
+       struct agg_node *node;
 
-       node = route_node_lookup(ripng_enable_network, p);
+       node = agg_node_lookup(ripng_enable_network, p);
        if (node) {
                node->info = NULL;
 
                /* Unlock info lock. */
-               route_unlock_node(node);
+               agg_unlock_node(node);
 
                /* Unlock lookup lock. */
-               route_unlock_node(node);
+               agg_unlock_node(node);
 
-               return 1;
+               return NB_OK;
        }
-       return -1;
+
+       return NB_ERR_INCONSISTENCY;
 }
 
 /* Lookup function. */
@@ -596,30 +566,30 @@ static int ripng_enable_if_lookup(const char *ifname)
 }
 
 /* Add interface to ripng_enable_if. */
-static int ripng_enable_if_add(const char *ifname)
+int ripng_enable_if_add(const char *ifname)
 {
        int ret;
 
        ret = ripng_enable_if_lookup(ifname);
        if (ret >= 0)
-               return -1;
+               return NB_ERR_INCONSISTENCY;
 
        vector_set(ripng_enable_if, strdup(ifname));
 
        ripng_enable_apply_all();
 
-       return 1;
+       return NB_OK;
 }
 
 /* Delete interface from ripng_enable_if. */
-static int ripng_enable_if_delete(const char *ifname)
+int ripng_enable_if_delete(const char *ifname)
 {
        int index;
        char *str;
 
        index = ripng_enable_if_lookup(ifname);
        if (index < 0)
-               return -1;
+               return NB_ERR_INCONSISTENCY;
 
        str = vector_slot(ripng_enable_if, index);
        free(str);
@@ -627,7 +597,7 @@ static int ripng_enable_if_delete(const char *ifname)
 
        ripng_enable_apply_all();
 
-       return 1;
+       return NB_OK;
 }
 
 /* Wake up interface. */
@@ -644,8 +614,9 @@ static int ripng_interface_wakeup(struct thread *t)
 
        /* Join to multicast group. */
        if (ripng_multicast_join(ifp) < 0) {
-               zlog_err("multicast join failed, interface %s not running",
-                        ifp->name);
+               flog_err_sys(EC_LIB_SOCKET,
+                            "multicast join failed, interface %s not running",
+                            ifp->name);
                return 0;
        }
 
@@ -760,10 +731,10 @@ void ripng_enable_apply(struct interface *ifp)
 /* Set distribute list to all interfaces. */
 static void ripng_enable_apply_all(void)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
-       struct listnode *node;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
+       FOR_ALL_INTERFACES (vrf, ifp)
                ripng_enable_apply(ifp);
 }
 
@@ -772,13 +743,14 @@ void ripng_clean_network()
 {
        unsigned int i;
        char *str;
-       struct route_node *rn;
+       struct agg_node *rn;
 
        /* ripng_enable_network */
-       for (rn = route_top(ripng_enable_network); rn; rn = route_next(rn))
+       for (rn = agg_route_top(ripng_enable_network); rn;
+            rn = agg_route_next(rn))
                if (rn->info) {
                        rn->info = NULL;
-                       route_unlock_node(rn);
+                       agg_unlock_node(rn);
                }
 
        /* ripng_enable_if */
@@ -821,34 +793,34 @@ void ripng_passive_interface_apply(struct interface *ifp)
 
 static void ripng_passive_interface_apply_all(void)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
-       struct listnode *node;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
+       FOR_ALL_INTERFACES (vrf, ifp)
                ripng_passive_interface_apply(ifp);
 }
 
 /* Passive interface. */
-static int ripng_passive_interface_set(struct vty *vty, const char *ifname)
+int ripng_passive_interface_set(const char *ifname)
 {
        if (ripng_passive_interface_lookup(ifname) >= 0)
-               return CMD_WARNING_CONFIG_FAILED;
+               return NB_ERR_INCONSISTENCY;
 
        vector_set(Vripng_passive_interface, strdup(ifname));
 
        ripng_passive_interface_apply_all();
 
-       return CMD_SUCCESS;
+       return NB_OK;
 }
 
-static int ripng_passive_interface_unset(struct vty *vty, const char *ifname)
+int ripng_passive_interface_unset(const char *ifname)
 {
        int i;
        char *str;
 
        i = ripng_passive_interface_lookup(ifname);
        if (i < 0)
-               return CMD_WARNING_CONFIG_FAILED;
+               return NB_ERR_INCONSISTENCY;
 
        str = vector_slot(Vripng_passive_interface, i);
        free(str);
@@ -856,7 +828,7 @@ static int ripng_passive_interface_unset(struct vty *vty, const char *ifname)
 
        ripng_passive_interface_apply_all();
 
-       return CMD_SUCCESS;
+       return NB_OK;
 }
 
 /* Free all configured RIP passive-interface settings. */
@@ -874,20 +846,19 @@ void ripng_passive_interface_clean(void)
 }
 
 /* Write RIPng enable network and interface to the vty. */
-int ripng_network_write(struct vty *vty, int config_mode)
+int ripng_network_write(struct vty *vty)
 {
        unsigned int i;
        const char *ifname;
-       struct route_node *node;
+       struct agg_node *node;
        char buf[BUFSIZ];
 
        /* Write enable network. */
-       for (node = route_top(ripng_enable_network); node;
-            node = route_next(node))
+       for (node = agg_route_top(ripng_enable_network); node;
+            node = agg_route_next(node))
                if (node->info) {
                        struct prefix *p = &node->p;
-                       vty_out(vty, "%s%s/%d\n",
-                               config_mode ? " network " : "    ",
+                       vty_out(vty, "    %s/%d\n",
                                inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
                                p->prefixlen);
                }
@@ -895,148 +866,11 @@ int ripng_network_write(struct vty *vty, int config_mode)
        /* Write enable interface. */
        for (i = 0; i < vector_active(ripng_enable_if); i++)
                if ((ifname = vector_slot(ripng_enable_if, i)) != NULL)
-                       vty_out(vty, "%s%s\n",
-                               config_mode ? " network " : "    ", ifname);
-
-       /* Write passive interface. */
-       if (config_mode)
-               for (i = 0; i < vector_active(Vripng_passive_interface); i++)
-                       if ((ifname = vector_slot(Vripng_passive_interface, i))
-                           != NULL)
-                               vty_out(vty, " passive-interface %s\n", ifname);
+                       vty_out(vty, "    %s\n", ifname);
 
        return 0;
 }
 
-/* RIPng enable on specified interface or matched network. */
-DEFUN (ripng_network,
-       ripng_network_cmd,
-       "network IF_OR_ADDR",
-       "RIPng enable on specified interface or network.\n"
-       "Interface or address\n")
-{
-       int idx_if_or_addr = 1;
-       int ret;
-       struct prefix p;
-
-       ret = str2prefix(argv[idx_if_or_addr]->arg, &p);
-
-       /* Given string is IPv6 network or interface name. */
-       if (ret)
-               ret = ripng_enable_network_add(&p);
-       else
-               ret = ripng_enable_if_add(argv[idx_if_or_addr]->arg);
-
-       if (ret < 0) {
-               vty_out(vty, "There is same network configuration %s\n",
-                       argv[idx_if_or_addr]->arg);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       return CMD_SUCCESS;
-}
-
-/* RIPng enable on specified interface or matched network. */
-DEFUN (no_ripng_network,
-       no_ripng_network_cmd,
-       "no network IF_OR_ADDR",
-       NO_STR
-       "RIPng enable on specified interface or network.\n"
-       "Interface or address\n")
-{
-       int idx_if_or_addr = 2;
-       int ret;
-       struct prefix p;
-
-       ret = str2prefix(argv[idx_if_or_addr]->arg, &p);
-
-       /* Given string is interface name. */
-       if (ret)
-               ret = ripng_enable_network_delete(&p);
-       else
-               ret = ripng_enable_if_delete(argv[idx_if_or_addr]->arg);
-
-       if (ret < 0) {
-               vty_out(vty, "can't find network %s\n",
-                       argv[idx_if_or_addr]->arg);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (ipv6_ripng_split_horizon,
-       ipv6_ripng_split_horizon_cmd,
-       "ipv6 ripng split-horizon",
-       IPV6_STR
-       "Routing Information Protocol\n"
-       "Perform split horizon\n")
-{
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       struct ripng_interface *ri;
-
-       ri = ifp->info;
-
-       ri->split_horizon = RIPNG_SPLIT_HORIZON;
-       return CMD_SUCCESS;
-}
-
-DEFUN (ipv6_ripng_split_horizon_poisoned_reverse,
-       ipv6_ripng_split_horizon_poisoned_reverse_cmd,
-       "ipv6 ripng split-horizon poisoned-reverse",
-       IPV6_STR
-       "Routing Information Protocol\n"
-       "Perform split horizon\n"
-       "With poisoned-reverse\n")
-{
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       struct ripng_interface *ri;
-
-       ri = ifp->info;
-
-       ri->split_horizon = RIPNG_SPLIT_HORIZON_POISONED_REVERSE;
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_ipv6_ripng_split_horizon,
-       no_ipv6_ripng_split_horizon_cmd,
-       "no ipv6 ripng split-horizon [poisoned-reverse]",
-       NO_STR
-       IPV6_STR
-       "Routing Information Protocol\n"
-       "Perform split horizon\n"
-       "With poisoned-reverse\n")
-{
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       struct ripng_interface *ri;
-
-       ri = ifp->info;
-
-       ri->split_horizon = RIPNG_NO_SPLIT_HORIZON;
-       return CMD_SUCCESS;
-}
-
-DEFUN (ripng_passive_interface,
-       ripng_passive_interface_cmd,
-       "passive-interface IFNAME",
-       "Suppress routing updates on an interface\n"
-       "Interface name\n")
-{
-       int idx_ifname = 1;
-       return ripng_passive_interface_set(vty, argv[idx_ifname]->arg);
-}
-
-DEFUN (no_ripng_passive_interface,
-       no_ripng_passive_interface_cmd,
-       "no passive-interface IFNAME",
-       NO_STR
-       "Suppress routing updates on an interface\n"
-       "Interface name\n")
-{
-       int idx_ifname = 2;
-       return ripng_passive_interface_unset(vty, argv[idx_ifname]->arg);
-}
-
 static struct ripng_interface *ri_new(void)
 {
        struct ripng_interface *ri;
@@ -1046,8 +880,8 @@ static struct ripng_interface *ri_new(void)
           Relay or SMDS is enabled, the default value for split-horizon is
           off.  But currently Zebra does detect Frame Relay or SMDS
           interface.  So all interface is set to split horizon.  */
-       ri->split_horizon_default = RIPNG_SPLIT_HORIZON;
-       ri->split_horizon = ri->split_horizon_default;
+       ri->split_horizon =
+               yang_get_default_enum("%s/split-horizon", RIPNG_IFACE);
 
        return ri;
 }
@@ -1069,46 +903,24 @@ static int ripng_if_delete_hook(struct interface *ifp)
 /* Configuration write function for ripngd. */
 static int interface_config_write(struct vty *vty)
 {
-       struct listnode *node;
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
-       struct ripng_interface *ri;
        int write = 0;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
-               ri = ifp->info;
+       FOR_ALL_INTERFACES (vrf, ifp) {
+               struct lyd_node *dnode;
 
-               /* Do not display the interface if there is no
-                * configuration about it.
-                **/
-               if ((!ifp->desc)
-                   && (ri->split_horizon == ri->split_horizon_default))
+               dnode = yang_dnode_get(
+                       running_config->dnode,
+                       "/frr-interface:lib/interface[name='%s'][vrf='%s']",
+                       ifp->name, vrf->name);
+               if (dnode == NULL)
                        continue;
 
-               vty_out(vty, "interface %s\n", ifp->name);
-               if (ifp->desc)
-                       vty_out(vty, " description %s\n", ifp->desc);
-
-               /* Split horizon. */
-               if (ri->split_horizon != ri->split_horizon_default) {
-                       switch (ri->split_horizon) {
-                       case RIPNG_SPLIT_HORIZON:
-                               vty_out(vty, " ipv6 ripng split-horizon\n");
-                               break;
-                       case RIPNG_SPLIT_HORIZON_POISONED_REVERSE:
-                               vty_out(vty,
-                                       " ipv6 ripng split-horizon poisoned-reverse\n");
-                               break;
-                       case RIPNG_NO_SPLIT_HORIZON:
-                       default:
-                               vty_out(vty, " no ipv6 ripng split-horizon\n");
-                               break;
-                       }
-               }
-
-               vty_out(vty, "!\n");
-
-               write++;
+               write = 1;
+               nb_cli_show_dnode_cmds(vty, dnode, false);
        }
+
        return write;
 }
 
@@ -1125,7 +937,7 @@ void ripng_if_init()
        hook_register_prio(if_del, 0, ripng_if_delete_hook);
 
        /* RIPng enable network init. */
-       ripng_enable_network = route_table_init();
+       ripng_enable_network = agg_table_init();
 
        /* RIPng enable interface init. */
        ripng_enable_if = vector_init(1);
@@ -1136,14 +948,4 @@ void ripng_if_init()
        /* Install interface node. */
        install_node(&interface_node, interface_config_write);
        if_cmd_init();
-
-       install_element(RIPNG_NODE, &ripng_network_cmd);
-       install_element(RIPNG_NODE, &no_ripng_network_cmd);
-       install_element(RIPNG_NODE, &ripng_passive_interface_cmd);
-       install_element(RIPNG_NODE, &no_ripng_passive_interface_cmd);
-
-       install_element(INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd);
-       install_element(INTERFACE_NODE,
-                       &ipv6_ripng_split_horizon_poisoned_reverse_cmd);
-       install_element(INTERFACE_NODE, &no_ipv6_ripng_split_horizon_cmd);
 }