]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/redistribute.c
zebra: reorganize zserv, batch i/o
[mirror_frr.git] / zebra / redistribute.c
index ce86b6c1e34b15e5782d2289db4822086227fb8c..5a239306fbfae0fbd2ec6e19e04d111fe8d8a026 100644 (file)
@@ -84,11 +84,13 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id)
                if (!rn)
                        continue;
 
-               RNODE_FOREACH_RE(rn, newre)
-               if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)
-                   && newre->distance != DISTANCE_INFINITY)
-                       zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
-                                                client, &rn->p, NULL, newre);
+               RNODE_FOREACH_RE (rn, newre) {
+                       if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)
+                           && newre->distance != DISTANCE_INFINITY)
+                               zsend_redistribute_route(
+                                       ZEBRA_REDISTRIBUTE_ROUTE_ADD, client,
+                                       &rn->p, NULL, newre);
+               }
 
                route_unlock_node(rn);
        }
@@ -107,8 +109,7 @@ static void zebra_redistribute(struct zserv *client, int type, u_short instance,
                return;
 
        for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
-               RNODE_FOREACH_RE(rn, newre)
-               {
+               RNODE_FOREACH_RE (rn, newre) {
                        struct prefix *dst_p, *src_p;
                        srcdest_rnode_prefixes(rn, &dst_p, &src_p);
 
@@ -242,19 +243,27 @@ void redistribute_delete(struct prefix *p, struct prefix *src_p,
        }
 }
 
-void zebra_redistribute_add(int command, struct zserv *client, int length,
-                           struct zebra_vrf *zvrf)
+void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
 {
-       afi_t afi;
-       int type;
+       afi_t afi = 0;
+       int type = 0;
        u_short instance;
 
-       afi = stream_getc(client->ibuf);
-       type = stream_getc(client->ibuf);
-       instance = stream_getw(client->ibuf);
+       STREAM_GETC(msg, afi);
+       STREAM_GETC(msg, type);
+       STREAM_GETW(msg, instance);
+
+       if (afi == 0 || afi > AFI_MAX) {
+               zlog_warn("%s: Specified afi %d does not exist",
+                         __PRETTY_FUNCTION__, afi);
+               return;
+       }
 
-       if (type == 0 || type >= ZEBRA_ROUTE_MAX)
+       if (type == 0 || type >= ZEBRA_ROUTE_MAX) {
+               zlog_warn("%s: Specified Route Type %d does not exist",
+                         __PRETTY_FUNCTION__, type);
                return;
+       }
 
        if (instance) {
                if (!redist_check_instance(&client->mi_redist[afi][type],
@@ -272,21 +281,32 @@ void zebra_redistribute_add(int command, struct zserv *client, int length,
                        zebra_redistribute(client, type, 0, zvrf_id(zvrf), afi);
                }
        }
+
+stream_failure:
+       return;
 }
 
-void zebra_redistribute_delete(int command, struct zserv *client, int length,
-                              struct zebra_vrf *zvrf)
+void zebra_redistribute_delete(ZAPI_HANDLER_ARGS)
 {
-       afi_t afi;
-       int type;
+       afi_t afi = 0;
+       int type = 0;
        u_short instance;
 
-       afi = stream_getc(client->ibuf);
-       type = stream_getc(client->ibuf);
-       instance = stream_getw(client->ibuf);
+       STREAM_GETC(msg, afi);
+       STREAM_GETC(msg, type);
+       STREAM_GETW(msg, instance);
 
-       if (type == 0 || type >= ZEBRA_ROUTE_MAX)
+       if (afi == 0 || afi > AFI_MAX) {
+               zlog_warn("%s: Specified afi %d does not exist",
+                         __PRETTY_FUNCTION__, afi);
                return;
+       }
+
+       if (type == 0 || type >= ZEBRA_ROUTE_MAX) {
+               zlog_warn("%s: Specified Route Type %d does not exist",
+                         __PRETTY_FUNCTION__, type);
+               return;
+       }
 
        /*
         * NOTE: no need to withdraw the previously advertised routes. The
@@ -298,17 +318,18 @@ void zebra_redistribute_delete(int command, struct zserv *client, int length,
                redist_del_instance(&client->mi_redist[afi][type], instance);
        else
                vrf_bitmap_unset(client->redist[afi][type], zvrf_id(zvrf));
+
+stream_failure:
+       return;
 }
 
-void zebra_redistribute_default_add(int command, struct zserv *client,
-                                   int length, struct zebra_vrf *zvrf)
+void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS)
 {
        vrf_bitmap_set(client->redist_default, zvrf_id(zvrf));
        zebra_redistribute_default(client, zvrf_id(zvrf));
 }
 
-void zebra_redistribute_default_delete(int command, struct zserv *client,
-                                      int length, struct zebra_vrf *zvrf)
+void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS)
 {
        vrf_bitmap_unset(client->redist_default, zvrf_id(zvrf));
 }
@@ -494,7 +515,7 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re,
        afi = family2afi(rn->p.family);
        if (rmap_name)
                ret = zebra_import_table_route_map_check(
-                       afi, re->type, &rn->p, re->nexthop, re->vrf_id,
+                       afi, re->type, &rn->p, re->ng.nexthop, re->vrf_id,
                        re->tag, rmap_name);
 
        if (ret != RMAP_MATCH) {
@@ -504,14 +525,11 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re,
 
        prefix_copy(&p, &rn->p);
 
-       RNODE_FOREACH_RE(rn, same)
-       {
-               if (CHECK_FLAG(same->status,
-                              ROUTE_ENTRY_REMOVED))
+       RNODE_FOREACH_RE (rn, same) {
+               if (CHECK_FLAG(same->status, ROUTE_ENTRY_REMOVED))
                        continue;
 
-               if (same->type == re->type
-                   && same->instance == re->instance
+               if (same->type == re->type && same->instance == re->instance
                    && same->table == re->table
                    && same->type != ZEBRA_ROUTE_CONNECT)
                        break;
@@ -520,32 +538,20 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re,
        if (same)
                zebra_del_import_table_entry(rn, same);
 
-       if (re->nexthop_num == 1) {
-               rib_add(afi, SAFI_UNICAST, re->vrf_id,
-                       ZEBRA_ROUTE_TABLE, re->table, 0, &p,
-                       NULL, re->nexthop,
-                       zebrad.rtm_table_default, re->metric,
-                       re->mtu,
-                       zebra_import_table_distance[afi]
-                       [re->table]);
-       } else if (re->nexthop_num > 1) {
-               newre = XCALLOC(MTYPE_RE,
-                               sizeof(struct route_entry));
-               newre->type = ZEBRA_ROUTE_TABLE;
-               newre->distance =
-                       zebra_import_table_distance[afi][re->table];
-               newre->flags = re->flags;
-               newre->metric = re->metric;
-               newre->mtu = re->mtu;
-               newre->table = zebrad.rtm_table_default;
-               newre->nexthop_num = 0;
-               newre->uptime = time(NULL);
-               newre->instance = re->table;
-               route_entry_copy_nexthops(newre, re->nexthop);
-
-               rib_add_multipath(afi, SAFI_UNICAST, &p,
-                                 NULL, newre);
-       }
+       newre = XCALLOC(MTYPE_RE, sizeof(struct route_entry));
+       newre->type = ZEBRA_ROUTE_TABLE;
+       newre->distance = zebra_import_table_distance[afi][re->table];
+       newre->flags = re->flags;
+       newre->metric = re->metric;
+       newre->mtu = re->mtu;
+       newre->table = zebrad.rtm_table_default;
+       newre->nexthop_num = 0;
+       newre->uptime = time(NULL);
+       newre->instance = re->table;
+       route_entry_copy_nexthops(newre, re->ng.nexthop);
+
+       rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, newre);
+
        return 0;
 }
 
@@ -557,9 +563,9 @@ int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re)
        afi = family2afi(rn->p.family);
        prefix_copy(&p, &rn->p);
 
-       rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE,
-                  re->table, re->flags, &p, NULL, NULL,
-                  zebrad.rtm_table_default, re->metric);
+       rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE, re->table,
+                  re->flags, &p, NULL, re->ng.nexthop,
+                  zebrad.rtm_table_default, re->metric, false, NULL);
 
        return 0;
 }
@@ -618,8 +624,7 @@ int zebra_import_table(afi_t afi, u_int32_t table_id, u_int32_t distance,
                if (!rn->info)
                        continue;
 
-               RNODE_FOREACH_RE(rn, re)
-               {
+               RNODE_FOREACH_RE (rn, re) {
                        if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
                                continue;
                        break;
@@ -654,19 +659,17 @@ int zebra_import_table_config(struct vty *vty)
 
                        if (zebra_import_table_distance[afi][i]
                            != ZEBRA_TABLE_DISTANCE_DEFAULT) {
-                               vty_out(vty,
-                                       "%s import-table %d distance %d",
+                               vty_out(vty, "%s import-table %d distance %d",
                                        afi_str[afi], i,
                                        zebra_import_table_distance[afi][i]);
                        } else {
-                               vty_out(vty, "%s import-table %d",
-                                       afi_str[afi], i);
+                               vty_out(vty, "%s import-table %d", afi_str[afi],
+                                       i);
                        }
 
                        rmap_name = zebra_get_import_table_route_map(afi, i);
                        if (rmap_name)
-                               vty_out(vty, " route-map %s",
-                                       rmap_name);
+                               vty_out(vty, " route-map %s", rmap_name);
 
                        vty_out(vty, "\n");
                        write = 1;
@@ -694,11 +697,9 @@ void zebra_import_table_rm_update()
                        if (!rmap_name)
                                return;
 
-                       table = zebra_vrf_other_route_table(afi,
-                                                           i,
+                       table = zebra_vrf_other_route_table(afi, i,
                                                            VRF_DEFAULT);
-                       for (rn = route_top(table); rn;
-                            rn = route_next(rn)) {
+                       for (rn = route_top(table); rn; rn = route_next(rn)) {
                                /* For each entry in the non-default
                                 * routing table,
                                 * add the entry in the main table
@@ -706,11 +707,9 @@ void zebra_import_table_rm_update()
                                if (!rn->info)
                                        continue;
 
-                               RNODE_FOREACH_RE(rn, re)
-                               {
-                                       if (CHECK_FLAG(
-                                                   re->status,
-                                                   ROUTE_ENTRY_REMOVED))
+                               RNODE_FOREACH_RE (rn, re) {
+                                       if (CHECK_FLAG(re->status,
+                                                      ROUTE_ENTRY_REMOVED))
                                                continue;
                                        break;
                                }
@@ -722,8 +721,8 @@ void zebra_import_table_rm_update()
                                     && (rn->p.family == AF_INET))
                                    || ((afi == AFI_IP6)
                                        && (rn->p.family == AF_INET6)))
-                                       zebra_add_import_table_entry(
-                                               rn, re, rmap_name);
+                                       zebra_add_import_table_entry(rn, re,
+                                                                    rmap_name);
                        }
                }
        }