summaryrefslogtreecommitdiffstats
path: root/src/vnet/dpo/l3_proxy_dpo.c
blob: ea3db7151d070bda1778ed34da5a2c537af7265c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * 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 l3_proxying the packet, i.e. it's for-us
 */
#include <vlib/vlib.h>
#include <vnet/ip/ip.h>
#include <vnet/dpo/l3_proxy_dpo.h>

/**
 * @brief pool of all l3_proxy DPOs
 */
l3_proxy_dpo_t *l3_proxy_dpo_pool;

static l3_proxy_dpo_t *
l3_proxy_dpo_alloc (void)
{
    l3_proxy_dpo_t *l3p;

    pool_get_aligned(l3_proxy_dpo_pool, l3p, CLIB_CACHE_LINE_BYTES);
    memset(l3p, 0, sizeof(*l3p));

    return (l3p);
}

static l3_proxy_dpo_t *
l3_proxy_dpo_get_from_dpo (const dpo_id_t *dpo)
{
    ASSERT(DPO_L3_PROXY == dpo->dpoi_type);

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


/*
 * l3_proxy_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 l3_proxy prefix, the next-hop
 * passed here is the local prefix on the same interface.
 */
void
l3_proxy_dpo_add_or_lock (dpo_proto_t proto,
                          u32 sw_if_index,
                          dpo_id_t *dpo)
{
    l3_proxy_dpo_t *l3p;

    l3p = l3_proxy_dpo_alloc();

    l3p->l3p_sw_if_index = sw_if_index;

    dpo_set(dpo, DPO_L3_PROXY, proto, (l3p - l3_proxy_dpo_pool));
}

static void
l3_proxy_dpo_lock (dpo_id_t *dpo)
{
    l3_proxy_dpo_t *l3p;

    l3p = l3_proxy_dpo_get_from_dpo(dpo);
    l3p->l3p_locks++;
}

static void
l3_proxy_dpo_unlock (dpo_id_t *dpo)
{
    l3_proxy_dpo_t *l3p;

    l3p = l3_proxy_dpo_get_from_dpo(dpo);
    l3p->l3p_locks--;

    if (0 == l3p->l3p_locks)
    {
        pool_put(l3_proxy_dpo_pool, l3p);
    }
}

static u32
l3_proxy_dpo_get_urpf (const dpo_id_t *dpo)
{
    l3_proxy_dpo_t *l3p;

    l3p = l3_proxy_dpo_get_from_dpo(dpo);

    return (l3p->l3p_sw_if_index);
}

static u8*
format_l3_proxy_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();
    l3_proxy_dpo_t *l3p;

    if (pool_is_free_index(l3_proxy_dpo_pool, index))
    {
        return (format(s, "dpo-l3_proxy DELETED"));
    }

    l3p = l3_proxy_dpo_get(index);

    if (~0 != l3p->l3p_sw_if_index)
    {
        return (format(s, "dpo-l3_proxy: %U",
                       format_vnet_sw_interface_name, vnm,
                       vnet_get_sw_interface(vnm, l3p->l3p_sw_if_index)));
    }
    else
    {
        return (format(s, "dpo-l3-proxy"));
    }
}

static void
l3_proxy_dpo_mem_show (void)
{
    fib_show_memory_usage("L3 Proxy",
			  pool_elts(l3_proxy_dpo_pool),
			  pool_len(l3_proxy_dpo_pool),
			  sizeof(l3_proxy_dpo_t));
}

const static dpo_vft_t l3_proxy_vft = {
    .dv_lock = l3_proxy_dpo_lock,
    .dv_unlock = l3_proxy_dpo_unlock,
    .dv_format = format_l3_proxy_dpo,
    .dv_get_urpf = l3_proxy_dpo_get_urpf,
    .dv_mem_show = l3_proxy_dpo_mem_show,
};

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

const static char* const * const l3_proxy_nodes[DPO_PROTO_NUM] =
{
    [DPO_PROTO_IP4]  = l3_proxy_ip4_nodes,
    [DPO_PROTO_IP6]  = l3_proxy_ip6_nodes,
    [DPO_PROTO_MPLS] = NULL,
};

void
l3_proxy_dpo_module_init (void)
{
    dpo_register(DPO_L3_PROXY, &l3_proxy_vft, l3_proxy_nodes);
}
ip4_0 = (vlib_buffer_get_current (b0) + vnet_buffer (b0)->ip.save_rewrite_length); if (PREDICT_FALSE (qos0 != ip4_0->tos)) { ip4_0->tos = qos0; ip4_0->checksum = ip4_header_checksum (ip4_0); } } } else if (QOS_SOURCE_MPLS == output_source) { mpls_bytes_0 = (vlib_buffer_get_current (b0) + vnet_buffer (b0)->mpls.save_rewrite_length); /* apply to all the labels in the stack */ do { /* clear out the old COS bts */ mpls_bytes_0[2] &= 0xf1; /* OR in 3 bits of the mapped value */ mpls_bytes_0[2] |= (qos0 & 0x7) << 1; eos0 = mpls_bytes_0[2] & 0x1; mpls_bytes_0 += 4; } while (!eos0); } else if (QOS_SOURCE_VLAN == output_source) { vlan0 = (vlib_buffer_get_current (b0) + sizeof (ethernet_header_t)); ethernet_vlan_header_set_priority_net_order (vlan0, qos0); } } vnet_feature_next (&next0, b0); if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) { qos_mark_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t)); t->bits = qos0; t->input = input_source0; t->used = (b0->flags & VNET_BUFFER_F_QOS_DATA_VALID); } /* verify speculative enqueue, maybe switch current next frame */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, bi0, next0); } vlib_put_next_frame (vm, node, next_index, n_left_to_next); } return frame->n_vectors; } /* packet trace format function */ static u8 * format_qos_mark_trace (u8 * s, va_list * args) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); qos_mark_trace_t *t = va_arg (*args, qos_mark_trace_t *); s = format (s, "source:%U qos:%d used:%s", format_qos_source, t->input, t->bits, (t->used ? "yes" : "no")); return s; } VLIB_NODE_FN (ip4_qos_mark_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (qos_mark_inline (vm, node, frame, QOS_SOURCE_IP, 0)); } VLIB_NODE_FN (ip6_qos_mark_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (qos_mark_inline (vm, node, frame, QOS_SOURCE_IP, 1)); } VLIB_NODE_FN (mpls_qos_mark_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (qos_mark_inline (vm, node, frame, QOS_SOURCE_MPLS, 0)); } VLIB_NODE_FN (vlan_mpls_qos_mark_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (qos_mark_inline (vm, node, frame, QOS_SOURCE_VLAN, 0)); } VLIB_NODE_FN (vlan_ip4_qos_mark_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (qos_mark_inline (vm, node, frame, QOS_SOURCE_VLAN, 0)); } VLIB_NODE_FN (vlan_ip6_qos_mark_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (qos_mark_inline (vm, node, frame, QOS_SOURCE_VLAN, 0)); } /* *INDENT-OFF* */ VLIB_REGISTER_NODE (ip4_qos_mark_node) = { .name = "ip4-qos-mark", .vector_size = sizeof (u32), .format_trace = format_qos_mark_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = 0, .n_next_nodes = 1, .next_nodes = { [0] = "ip4-drop", }, }; VNET_FEATURE_INIT (ip4_qos_mark_node, static) = { .arc_name = "ip4-output", .node_name = "ip4-qos-mark", }; VLIB_REGISTER_NODE (ip6_qos_mark_node) = { .name = "ip6-qos-mark", .vector_size = sizeof (u32), .format_trace = format_qos_mark_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = 0, .n_next_nodes = 1, .next_nodes = { [0] = "ip6-drop", }, }; VNET_FEATURE_INIT (ip6_qos_mark_node, static) = { .arc_name = "ip6-output", .node_name = "ip6-qos-mark", }; VLIB_REGISTER_NODE (mpls_qos_mark_node) = { .name = "mpls-qos-mark", .vector_size = sizeof (u32), .format_trace = format_qos_mark_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = 0, .n_next_nodes = 1, .next_nodes = { [0] = "mpls-drop", }, }; VNET_FEATURE_INIT (mpls_qos_mark_node, static) = { .arc_name = "mpls-output", .node_name = "mpls-qos-mark", }; VLIB_REGISTER_NODE (vlan_ip4_qos_mark_node) = { .name = "vlan-ip4-qos-mark", .vector_size = sizeof (u32), .format_trace = format_qos_mark_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = 0, .n_next_nodes = 1, .next_nodes = { [0] = "error-drop", }, }; VNET_FEATURE_INIT (vlan_ip4_qos_mark_node, static) = { .arc_name = "ip4-output", .node_name = "vlan-ip4-qos-mark", .runs_after = VNET_FEATURES ("ip4-qos-mark"), }; VLIB_REGISTER_NODE (vlan_ip6_qos_mark_node) = { .name = "vlan-ip6-qos-mark", .vector_size = sizeof (u32), .format_trace = format_qos_mark_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = 0, .n_next_nodes = 1, .next_nodes = { [0] = "error-drop", }, }; VNET_FEATURE_INIT (vlan_ip6_qos_mark_node, static) = { .arc_name = "ip6-output", .node_name = "vlan-ip6-qos-mark", .runs_after = VNET_FEATURES ("ip6-qos-mark"), }; VLIB_REGISTER_NODE (vlan_mpls_qos_mark_node) = { .name = "vlan-mpls-qos-mark", .vector_size = sizeof (u32), .format_trace = format_qos_mark_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = 0, .n_next_nodes = 1, .next_nodes = { [0] = "error-drop", }, }; VNET_FEATURE_INIT (vlan_mpls_qos_mark_node, static) = { .arc_name = "mpls-output", .node_name = "vlan-mpls-qos-mark", .runs_after = VNET_FEATURES ("mpls-qos-mark"), }; /* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */