summaryrefslogtreecommitdiffstats
path: root/src/vnet/dns
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-10-17 10:38:51 -0400
committerDamjan Marion <dmarion@me.com>2018-10-23 13:06:46 +0000
commitb7b929931a07fbb27b43d5cd105f366c3e29807e (patch)
tree438681c89738802dbb5d339715b96ea2c31bafb4 /src/vnet/dns
parentb9a4c445c1d4e9cdab476a8e1fb8a46ff0fc6080 (diff)
c11 safe string handling support
Change-Id: Ied34720ca5a6e6e717eea4e86003e854031b6eab Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vnet/dns')
-rw-r--r--src/vnet/dns/dns.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/vnet/dns/dns.c b/src/vnet/dns/dns.c
index eff854933c4..54b75aa1708 100644
--- a/src/vnet/dns/dns.c
+++ b/src/vnet/dns/dns.c
@@ -278,9 +278,9 @@ found_src_address:
vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; /* default VRF for now */
ip = vlib_buffer_get_current (b);
- memset (ip, 0, sizeof (*ip));
+ clib_memset (ip, 0, sizeof (*ip));
udp = (udp_header_t *) (ip + 1);
- memset (udp, 0, sizeof (*udp));
+ clib_memset (udp, 0, sizeof (*udp));
dns_request = (u8 *) (udp + 1);
@@ -384,9 +384,9 @@ found_src_address:
VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_LOCALLY_ORIGINATED;
ip = vlib_buffer_get_current (b);
- memset (ip, 0, sizeof (*ip));
+ clib_memset (ip, 0, sizeof (*ip));
udp = (udp_header_t *) (ip + 1);
- memset (udp, 0, sizeof (*udp));
+ clib_memset (udp, 0, sizeof (*udp));
dns_request = (u8 *) (udp + 1);
@@ -768,7 +768,7 @@ dns_add_static_entry (dns_main_t * dm, u8 * name, u8 * dns_reply_data)
}
pool_get (dm->entries, ep);
- memset (ep, 0, sizeof (*ep));
+ clib_memset (ep, 0, sizeof (*ep));
/* Note: consumes the name vector */
ep->name = name;
@@ -887,7 +887,7 @@ re_resolve:
/* add new hash table entry */
pool_get (dm->entries, ep);
- memset (ep, 0, sizeof (*ep));
+ clib_memset (ep, 0, sizeof (*ep));
ep->name = format (0, "%s%c", name, 0);
_vec_len (ep->name) = vec_len (ep->name) - 1;
@@ -1063,7 +1063,7 @@ found_last_request:
/* Need to recompute ep post pool-get */
ep = pool_elt_at_index (dm->entries, ep_index);
- memset (next_ep, 0, sizeof (*next_ep));
+ clib_memset (next_ep, 0, sizeof (*next_ep));
next_ep->name = vec_dup (cname);
vec_add1 (next_ep->name, 0);
_vec_len (next_ep->name) -= 1;
@@ -2592,7 +2592,7 @@ test_dns_fmt_command_fn (vlib_main_t * vm,
vlib_cli_output (vm, "%U", format_dns_reply, dns_reply_data, verbose);
- memset (rmp, 0, sizeof (*rmp));
+ clib_memset (rmp, 0, sizeof (*rmp));
rv = vnet_dns_response_to_reply (dns_reply_data, rmp, 0 /* ttl-ptr */ );
@@ -2758,7 +2758,7 @@ vnet_send_dns4_reply (dns_main_t * dm, dns_pending_request_t * pr,
if (pr->request_type == DNS_PEER_PENDING_NAME_TO_IP)
{
/* Quick and dirty way to dig up the A-record address. $$ FIXME */
- memset (rnr, 0, sizeof (*rnr));
+ clib_memset (rnr, 0, sizeof (*rnr));
if (vnet_dns_response_to_reply (ep->dns_response, rnr, &ttl))
{
/* clib_warning ("response_to_reply failed..."); */
@@ -2772,7 +2772,7 @@ vnet_send_dns4_reply (dns_main_t * dm, dns_pending_request_t * pr,
}
else if (pr->request_type == DNS_PEER_PENDING_IP_TO_NAME)
{
- memset (rir, 0, sizeof (*rir));
+ clib_memset (rir, 0, sizeof (*rir));
if (vnet_dns_response_to_name (ep->dns_response, rir, &ttl))
{
/* clib_warning ("response_to_name failed..."); */
@@ -2859,7 +2859,7 @@ found_src_address:
ip = vlib_buffer_get_current (b0);
udp = (udp_header_t *) (ip + 1);
dns_response = (u8 *) (udp + 1);
- memset (ip, 0, sizeof (*ip) + sizeof (*udp));
+ clib_memset (ip, 0, sizeof (*ip) + sizeof (*udp));
/*
* Start with the variadic portion of the exercise.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vnet/bier/bier_entry.h>
#include <vnet/bier/bier_update.h>

#include <vnet/fib/fib_path_list.h>

#include <vnet/bier/bier_fmask_db.h>
#include <vnet/bier/bier_fmask.h>
#include <vnet/bier/bier_table.h>

bier_entry_t *bier_entry_pool;

static index_t
bier_entry_get_index (const bier_entry_t *be)
{
    return (be - bier_entry_pool);
}

static fib_path_list_walk_rc_t
bier_entry_link_walk (fib_node_index_t pl_index,
                      fib_node_index_t path_index,
                      void *arg)
{
    bier_entry_t *be = arg;
    index_t bfmi;

    bfmi = fib_path_get_resolving_index(path_index);
    bier_fmask_link(bfmi, be->be_bp);

    return (FIB_PATH_LIST_WALK_CONTINUE);
}

static fib_path_list_walk_rc_t
bier_entry_unlink_walk (fib_node_index_t pl_index,
                        fib_node_index_t path_index,
                        void *arg)
{
    bier_entry_t *be = arg;
    index_t bfmi;

    bfmi = fib_path_get_resolving_index(path_index);
    bier_fmask_unlink(bfmi, be->be_bp);

    return (FIB_PATH_LIST_WALK_CONTINUE);
}

index_t
bier_entry_create (index_t bti,
                   bier_bp_t bp)
{
    bier_entry_t *be;

    pool_get(bier_entry_pool, be);

    be->be_bp = bp;
    be->be_bti = bti;
    be->be_path_list = FIB_NODE_INDEX_INVALID;

    return (bier_entry_get_index(be));
}

void
bier_entry_delete (index_t bei)
{
    bier_entry_t *be;

    be = bier_entry_get(bei);

    /*
     * if we still ahve a path-list, unlink from it
     */
    if (FIB_NODE_INDEX_INVALID != be->be_path_list)
    {
        fib_path_list_walk(be->be_path_list,
                           bier_entry_unlink_walk,
                           be);
        fib_path_list_child_remove(be->be_path_list,
                                   be->be_sibling_index);
    }

    pool_put(bier_entry_pool, be);
}

static void
bier_entry_table_ecmp_walk_add_fmask (index_t btei,
                                      void *arg)
{
    bier_entry_t *be = arg;;

    /*
     * choose a fmask from the entry's resolved set to add
     * to ECMP table's lookup table
     */
    if (FIB_NODE_INDEX_INVALID != be->be_path_list)
    {
        const bier_table_id_t *btid;
        dpo_id_t dpo = DPO_INVALID;
        const dpo_id_t *choice;
        load_balance_t *lb;

        btid = bier_table_get_id(btei);

        fib_path_list_contribute_forwarding(be->be_path_list,
                                            FIB_FORW_CHAIN_TYPE_BIER,
                                            FIB_PATH_LIST_FWD_FLAG_COLLAPSE,
                                            &dpo);

        /*
         * select the appropriate bucket from the LB
         */
        if (dpo.dpoi_type == DPO_LOAD_BALANCE)
        {
            lb = load_balance_get(dpo.dpoi_index);
            choice = load_balance_get_bucket_i(lb,
                                               btid->bti_ecmp &
                                               (lb->lb_n_buckets_minus_1));
        }
        else
        {
            choice = &dpo;
        }

        if (choice->dpoi_type == DPO_BIER_FMASK)
        {
            bier_table_ecmp_set_fmask(btei, be->be_bp,
                                      choice->dpoi_index);
        }
        else
        {
            /*
             * any other type results in a drop, which we represent
             * with an empty bucket
             */
            bier_table_ecmp_set_fmask(btei, be->be_bp,
                                      INDEX_INVALID);
        }

        dpo_reset(&dpo);
    }
    else
    {
        /*
         * no fmasks left. insert a drop
         */
        bier_table_ecmp_set_fmask(btei, be->be_bp, INDEX_INVALID);
    }
}

void
bier_entry_path_add (index_t bei,
                     const fib_route_path_t *rpaths)
{
    fib_node_index_t old_pl_index;
    bier_entry_t *be;

    be = bier_entry_get(bei);
    old_pl_index = be->be_path_list;

    /*
     * lock the path-list so it does not go away before we unlink
     * from its resolved fmasks
     */
    fib_path_list_lock(old_pl_index);

    if (FIB_NODE_INDEX_INVALID == be->be_path_list)
    {
        old_pl_index = FIB_NODE_INDEX_INVALID;
        be->be_path_list = fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED |
                                                 FIB_PATH_LIST_FLAG_NO_URPF),
                                                rpaths);
        be->be_sibling_index = fib_path_list_child_add(be->be_path_list,
                                                       FIB_NODE_TYPE_BIER_ENTRY,
                                                       bier_entry_get_index(be));
    }
    else
    {

        old_pl_index = be->be_path_list;

        be->be_path_list =
            fib_path_list_copy_and_path_add(old_pl_index,
                                            (FIB_PATH_LIST_FLAG_SHARED |
                                             FIB_PATH_LIST_FLAG_NO_URPF),
                                            rpaths);

        fib_path_list_child_remove(old_pl_index,
                                   be->be_sibling_index);
        be->be_sibling_index = fib_path_list_child_add(be->be_path_list,
                                                       FIB_NODE_TYPE_BIER_ENTRY,
                                                       bier_entry_get_index(be));
    }
    /*
     * link the entry's bit-position to each fmask in the new path-list
     * then unlink from the old.
     */
    fib_path_list_walk(be->be_path_list,
                       bier_entry_link_walk,
                       be);
    if (FIB_NODE_INDEX_INVALID != old_pl_index)
    {
        fib_path_list_walk(old_pl_index,
                           bier_entry_unlink_walk,
                           be);
    }

    /*
     * update the ECNP tables with the new choice
     */
    bier_table_ecmp_walk(be->be_bti,
                         bier_entry_table_ecmp_walk_add_fmask,
                         be);

    /*
     * symmetric unlock. The old path-list may not exist hereinafter
     */
    fib_path_list_unlock(old_pl_index);
}

int
bier_entry_path_remove (index_t bei,
                        const fib_route_path_t *rpaths)
{
    fib_node_index_t old_pl_index;
    bier_entry_t *be;

    be = bier_entry_get(bei);
    old_pl_index = be->be_path_list;

    fib_path_list_lock(old_pl_index);

    ASSERT (FIB_NODE_INDEX_INVALID != be->be_path_list);

    be->be_path_list =
        fib_path_list_copy_and_path_remove(old_pl_index,
                                           (FIB_PATH_LIST_FLAG_SHARED |
                                            FIB_PATH_LIST_FLAG_NO_URPF),
                                           rpaths);

    if (be->be_path_list != old_pl_index)
    {
        /*
         * a path was removed
         */
        fib_path_list_child_remove(old_pl_index,
                                   be->be_sibling_index);

        if (FIB_NODE_INDEX_INVALID != be->be_path_list)
        {
            /*
             * link the entry's bit-position to each fmask in the new path-list
             * then unlink from the old.
             */
            fib_path_list_walk(be->be_path_list,
                               bier_entry_link_walk,
                               be);
            be->be_sibling_index =
                fib_path_list_child_add(be->be_path_list,
                                        FIB_NODE_TYPE_BIER_ENTRY,
                                        bier_entry_get_index(be));
        }

        fib_path_list_walk(old_pl_index,
                           bier_entry_unlink_walk,
                           be);
    }
    fib_path_list_unlock(old_pl_index);


    /*
     * update the ECNP tables with the new choice
     */
    bier_table_ecmp_walk(be->be_bti,
                         bier_entry_table_ecmp_walk_add_fmask,
                         be);

    return (fib_path_list_get_n_paths(be->be_path_list));
}

void
bier_entry_contribute_forwarding(index_t bei,
                                 dpo_id_t *dpo)
{
    bier_entry_t *be = bier_entry_get(bei);

    fib_path_list_contribute_forwarding(be->be_path_list,
                                        FIB_FORW_CHAIN_TYPE_BIER,
                                        FIB_PATH_LIST_FWD_FLAG_COLLAPSE,
                                        dpo);
}

u8*
format_bier_entry (u8* s, va_list *ap)
{
    index_t bei = va_arg(*ap, index_t);
    bier_show_flags_t flags = va_arg(*ap, bier_show_flags_t);

    bier_entry_t *be = bier_entry_get(bei);

    s = format(s, " bp:%d\n", be->be_bp);
    s = fib_path_list_format(be->be_path_list, s);

    if (flags & BIER_SHOW_DETAIL)
    {
        dpo_id_t dpo = DPO_INVALID;

        bier_entry_contribute_forwarding(bei, &dpo);

        s = format(s, " forwarding:\n");
        s = format(s, "  %U",
                   format_dpo_id, &dpo, 2);
        s = format(s, "\n");
    }

    return (s);
}

static fib_node_t *
bier_entry_get_node (fib_node_index_t index)
{
    bier_entry_t *be = bier_entry_get(index);
    return (&(be->be_node));
}

static bier_entry_t*
bier_entry_get_from_node (fib_node_t *node)
{
    return ((bier_entry_t*)(((char*)node) -
                            STRUCT_OFFSET_OF(bier_entry_t,
                                             be_node)));
}

static void
bier_entry_last_lock_gone (fib_node_t *node)
{
    /*
     * the lifetime of the entry is managed by the table.
     */
    ASSERT(0);
}

/*
 * A back walk has reached this BIER entry
 */
static fib_node_back_walk_rc_t
bier_entry_back_walk_notify (fib_node_t *node,
                             fib_node_back_walk_ctx_t *ctx)
{
    /*
     * re-populate the ECMP tables with new choices
     */
    bier_entry_t *be = bier_entry_get_from_node(node);

    bier_table_ecmp_walk(be->be_bti,
                         bier_entry_table_ecmp_walk_add_fmask,
                         be);

    /*
     * no need to propagate further up the graph.
     */
    return (FIB_NODE_BACK_WALK_CONTINUE);
}

/*
 * The BIER fmask's graph node virtual function table
 */
static const fib_node_vft_t bier_entry_vft = {
    .fnv_get = bier_entry_get_node,
    .fnv_last_lock = bier_entry_last_lock_gone,
    .fnv_back_walk = bier_entry_back_walk_notify,
};

clib_error_t *
bier_entry_module_init (vlib_main_t * vm)
{
    fib_node_register_type (FIB_NODE_TYPE_BIER_ENTRY, &bier_entry_vft);

    return (NULL);
}

VLIB_INIT_FUNCTION (bier_entry_module_init);