]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripngd/ripng_interface.c
ripngd: retrofit the 'router ripng' command to the new northbound model
[mirror_frr.git] / ripngd / ripng_interface.c
index 02fab6825483b48a77449e905063ec0e7c9ee78a..a1d25f29619574383cf75503d3a6d85ac12fcaa3 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 "ripngd/ripngd.h"
 #include "ripngd/ripng_debug.h"
@@ -47,8 +48,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 +72,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 +159,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 +298,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;
@@ -326,11 +325,11 @@ void ripng_interface_clean(void)
 
 void ripng_interface_reset(void)
 {
-       struct listnode *node;
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
        struct ripng_interface *ri;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
+       FOR_ALL_INTERFACES (vrf, ifp) {
                ri = ifp->info;
 
                ri->enable_network = 0;
@@ -481,7 +480,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 +493,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 +502,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 +522,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 +530,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;
                }
        }
@@ -546,12 +545,12 @@ static int ripng_enable_network_lookup2(struct connected *connected)
 /* Add RIPng enable network. */
 static 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);
+               agg_unlock_node(node);
                return -1;
        } else
                node->info = (void *)1;
@@ -565,17 +564,17 @@ static int ripng_enable_network_add(struct prefix *p)
 /* Delete RIPng enable network. */
 static 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;
        }
@@ -644,8 +643,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 +760,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 +772,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,10 +822,10 @@ 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);
 }
 
@@ -878,12 +879,12 @@ int ripng_network_write(struct vty *vty, int config_mode)
 {
        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",
@@ -1069,12 +1070,12 @@ 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)) {
+       FOR_ALL_INTERFACES (vrf, ifp) {
                ri = ifp->info;
 
                /* Do not display the interface if there is no
@@ -1084,7 +1085,7 @@ static int interface_config_write(struct vty *vty)
                    && (ri->split_horizon == ri->split_horizon_default))
                        continue;
 
-               vty_out(vty, "interface %s\n", ifp->name);
+               vty_frame(vty, "interface %s\n", ifp->name);
                if (ifp->desc)
                        vty_out(vty, " description %s\n", ifp->desc);
 
@@ -1105,7 +1106,7 @@ static int interface_config_write(struct vty *vty)
                        }
                }
 
-               vty_out(vty, "!\n");
+               vty_endframe(vty, "!\n");
 
                write++;
        }
@@ -1125,7 +1126,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);