summaryrefslogtreecommitdiffstats
path: root/src/vnet/dpo/receive_dpo.c
blob: 2b2571c6c831b792d9e27e08a6917c096ee5928f (plain)
1
2
3
4

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Gene
/*
 * 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.
 */
/**
 * @brief
 * The data-path object representing receiveing the packet, i.e. it's for-us
 */
#include <vlib/vlib.h>
#include <vnet/ip/ip.h>
#include <vnet/dpo/receive_dpo.h>

/**
 * @brief pool of all receive DPOs
 */
receive_dpo_t *receive_dpo_pool;

static receive_dpo_t *
receive_dpo_alloc (void)
{
    receive_dpo_t *rd;

    pool_get_aligned(receive_dpo_pool, rd, CLIB_CACHE_LINE_BYTES);
    memset(rd, 0, sizeof(*rd));

    return (rd);
}

static receive_dpo_t *
receive_dpo_get_from_dpo (const dpo_id_t *dpo)
{
    ASSERT(DPO_RECEIVE == dpo->dpoi_type);

    return (receive_dpo_get(dpo->dpoi_index));
}


/*
 * receive_dpo_add_or_lock
 *
 * The next_hop address here is used for source address selection in the DP.
 * The local adj is added to an interface's receive prefix, the next-hop
 * passed here is the local prefix on the same interface.
 */
void
receive_dpo_add_or_lock (dpo_proto_t proto,
                         u32 sw_if_index,
                         const ip46_address_t *nh_addr,
                         dpo_id_t *dpo)
{
    receive_dpo_t *rd;

    rd = receive_dpo_alloc();

    rd->rd_sw_if_index = sw_if_index;
    if (NULL != nh_addr)
    {
	rd->rd_addr = *nh_addr;
    }

    dpo_set(dpo, DPO_RECEIVE, proto, (rd - receive_dpo_pool));
}

static void
receive_dpo_lock (dpo_id_t *dpo)
{
    receive_dpo_t *rd;

    rd = receive_dpo_get_from_dpo(dpo);
    rd->rd_locks++;
}

static void
receive_dpo_unlock (dpo_id_t *dpo)
{
    receive_dpo_t *rd;

    rd = receive_dpo_get_from_dpo(dpo);
    rd->rd_locks--;

    if (0 == rd->rd_locks)
    {
        pool_put(receive_dpo_pool, rd);
    }
}

static u8*
format_receive_dpo (u8 *s, va_list *ap)
{
    CLIB_UNUSED(index_t index) = va_arg(*ap, index_t);
    CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
    vnet_main_t * vnm = vnet_get_main();
    receive_dpo_t *rd;

    rd = receive_dpo_get(index);

    if (~0 != rd->rd_sw_if_index)
    {
        return (format(s, "dpo-receive: %U on %U",
                       format_ip46_address, &rd->rd_addr, IP46_TYPE_ANY,
                       format_vnet_sw_interface_name, vnm,
                       vnet_get_sw_interface(vnm, rd->rd_sw_if_index)));
    }
    else
    {
        return (format(s, "dpo-receive"));
    }
}

static void
receive_dpo_mem_show (void)
{
    fib_show_memory_usage("Receive",
			  pool_elts(receive_dpo_pool),
			  pool_len(receive_dpo_pool),
			  sizeof(receive_dpo_t));
}

const static dpo_vft_t receive_vft = {
    .dv_lock = receive_dpo_lock,
    .dv_unlock = receive_dpo_unlock,
    .dv_format = format_receive_dpo,
    .dv_mem_show = receive_dpo_mem_show,
};

/**
 * @brief The per-protocol VLIB graph nodes that are assigned to a receive
 *        object.
 *
 * this means that these graph nodes are ones from which a receive is the
 * parent object in the DPO-graph.
 */
const static char* const receive_ip4_nodes[] =
{
    "ip4-local",
    NULL,
};
const static char* const receive_ip6_nodes[] =
{
    "ip6-local",
    NULL,
};

const static char* const * const receive_nodes[DPO_PROTO_NUM] =
{
    [DPO_PROTO_IP4]  = receive_ip4_nodes,
    [DPO_PROTO_IP6]  = receive_ip6_nodes,
    [DPO_PROTO_MPLS] = NULL,
};

void
receive_dpo_module_init (void)
{
    dpo_register(DPO_RECEIVE, &receive_vft, receive_nodes);
}