blob: 2956e541d57e61abbbb67101e549f515a6254f9a [file] [log] [blame]
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
Neale Ranns4c7c8e52017-10-21 09:37:55 -070016#include <vnet/ip/ip4_input.h>
17#include <vnet/ip/ip6_input.h>
Neale Ranns0f26c5a2017-03-01 15:12:11 -080018#include <vnet/dpo/mpls_disposition.h>
19#include <vnet/mpls/mpls.h>
20
21/*
22 * pool of all MPLS Label DPOs
23 */
24mpls_disp_dpo_t *mpls_disp_dpo_pool;
25
26static mpls_disp_dpo_t *
27mpls_disp_dpo_alloc (void)
28{
29 mpls_disp_dpo_t *mdd;
30
31 pool_get_aligned(mpls_disp_dpo_pool, mdd, CLIB_CACHE_LINE_BYTES);
32 memset(mdd, 0, sizeof(*mdd));
33
34 dpo_reset(&mdd->mdd_dpo);
35
36 return (mdd);
37}
38
39static index_t
40mpls_disp_dpo_get_index (mpls_disp_dpo_t *mdd)
41{
42 return (mdd - mpls_disp_dpo_pool);
43}
44
Neale Ranns31ed7442018-02-23 05:29:09 -080045void
Neale Ranns0f26c5a2017-03-01 15:12:11 -080046mpls_disp_dpo_create (dpo_proto_t payload_proto,
47 fib_rpf_id_t rpf_id,
Neale Ranns31ed7442018-02-23 05:29:09 -080048 fib_mpls_lsp_mode_t mode,
49 const dpo_id_t *parent,
50 dpo_id_t *dpo)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080051{
52 mpls_disp_dpo_t *mdd;
Neale Ranns31ed7442018-02-23 05:29:09 -080053 dpo_type_t dtype;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080054
55 mdd = mpls_disp_dpo_alloc();
56
57 mdd->mdd_payload_proto = payload_proto;
58 mdd->mdd_rpf_id = rpf_id;
Neale Ranns31ed7442018-02-23 05:29:09 -080059 mdd->mdd_mode = mode;
60 dtype = (FIB_MPLS_LSP_MODE_PIPE == mode ?
61 DPO_MPLS_DISPOSITION_PIPE :
62 DPO_MPLS_DISPOSITION_UNIFORM);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080063
Neale Ranns31ed7442018-02-23 05:29:09 -080064 /*
65 * stack this disposition object on the parent given
66 */
67 dpo_stack(dtype,
Neale Ranns0f26c5a2017-03-01 15:12:11 -080068 mdd->mdd_payload_proto,
69 &mdd->mdd_dpo,
Neale Ranns31ed7442018-02-23 05:29:09 -080070 parent);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080071
Neale Ranns31ed7442018-02-23 05:29:09 -080072 /*
73 * set up the return DPO to refer to this object
74 */
75 dpo_set(dpo,
76 dtype,
77 payload_proto,
78 mpls_disp_dpo_get_index(mdd));
Neale Ranns0f26c5a2017-03-01 15:12:11 -080079}
80
81u8*
82format_mpls_disp_dpo (u8 *s, va_list *args)
83{
Neale Ranns31ed7442018-02-23 05:29:09 -080084 index_t index = va_arg(*args, index_t);
85 u32 indent = va_arg(*args, u32);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080086 mpls_disp_dpo_t *mdd;
87
88 mdd = mpls_disp_dpo_get(index);
89
Neale Ranns31ed7442018-02-23 05:29:09 -080090 s = format(s, "mpls-disposition:[%d]:[%U, %U]",
Neale Ranns0f26c5a2017-03-01 15:12:11 -080091 index,
Neale Ranns31ed7442018-02-23 05:29:09 -080092 format_dpo_proto, mdd->mdd_payload_proto,
93 format_fib_mpls_lsp_mode, mdd->mdd_mode);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080094
95 s = format(s, "\n%U", format_white_space, indent);
96 s = format(s, "%U", format_dpo_id, &mdd->mdd_dpo, indent+2);
97
98 return (s);
99}
100
101static void
102mpls_disp_dpo_lock (dpo_id_t *dpo)
103{
104 mpls_disp_dpo_t *mdd;
105
106 mdd = mpls_disp_dpo_get(dpo->dpoi_index);
107
108 mdd->mdd_locks++;
109}
110
111static void
112mpls_disp_dpo_unlock (dpo_id_t *dpo)
113{
114 mpls_disp_dpo_t *mdd;
115
116 mdd = mpls_disp_dpo_get(dpo->dpoi_index);
117
118 mdd->mdd_locks--;
119
120 if (0 == mdd->mdd_locks)
121 {
122 dpo_reset(&mdd->mdd_dpo);
123 pool_put(mpls_disp_dpo_pool, mdd);
124 }
125}
126
127/**
128 * @brief A struct to hold tracing information for the MPLS label disposition
129 * node.
130 */
131typedef struct mpls_label_disposition_trace_t_
132{
133 index_t mdd;
134} mpls_label_disposition_trace_t;
135
Neale Ranns31ed7442018-02-23 05:29:09 -0800136extern vlib_node_registration_t ip4_mpls_label_disposition_pipe_node;
137extern vlib_node_registration_t ip6_mpls_label_disposition_pipe_node;
138extern vlib_node_registration_t ip4_mpls_label_disposition_uniform_node;
139extern vlib_node_registration_t ip6_mpls_label_disposition_uniform_node;
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700140
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800141always_inline uword
142mpls_label_disposition_inline (vlib_main_t * vm,
Neale Ranns31ed7442018-02-23 05:29:09 -0800143 vlib_node_runtime_t * node,
144 vlib_frame_t * from_frame,
145 u8 payload_is_ip4,
146 u8 payload_is_ip6,
147 fib_mpls_lsp_mode_t mode)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800148{
149 u32 n_left_from, next_index, * from, * to_next;
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700150 vlib_node_runtime_t *error_node;
151
152 if (payload_is_ip4)
Neale Ranns31ed7442018-02-23 05:29:09 -0800153 {
154 if (FIB_MPLS_LSP_MODE_PIPE == mode)
155 error_node =
156 vlib_node_get_runtime(vm, ip4_mpls_label_disposition_pipe_node.index);
157 else
158 error_node =
159 vlib_node_get_runtime(vm, ip4_mpls_label_disposition_uniform_node.index);
160 }
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700161 else
Neale Ranns31ed7442018-02-23 05:29:09 -0800162 {
163 if (FIB_MPLS_LSP_MODE_PIPE == mode)
164 error_node =
165 vlib_node_get_runtime(vm, ip6_mpls_label_disposition_uniform_node.index);
166 else
167 error_node =
168 vlib_node_get_runtime(vm, ip6_mpls_label_disposition_uniform_node.index);
169 }
170 from = vlib_frame_vector_args(from_frame);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800171 n_left_from = from_frame->n_vectors;
172
173 next_index = node->cached_next_index;
174
175 while (n_left_from > 0)
176 {
177 u32 n_left_to_next;
178
179 vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
180
181 while (n_left_from >= 4 && n_left_to_next >= 2)
182 {
183 mpls_disp_dpo_t *mdd0, *mdd1;
184 u32 bi0, mddi0, bi1, mddi1;
185 vlib_buffer_t * b0, *b1;
186 u32 next0, next1;
187
188 bi0 = to_next[0] = from[0];
189 bi1 = to_next[1] = from[1];
190
191 /* Prefetch next iteration. */
192 {
193 vlib_buffer_t * p2, * p3;
194
Neale Ranns31ed7442018-02-23 05:29:09 -0800195 p2 = vlib_get_buffer(vm, from[2]);
196 p3 = vlib_get_buffer(vm, from[3]);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800197
Neale Ranns31ed7442018-02-23 05:29:09 -0800198 vlib_prefetch_buffer_header(p2, STORE);
199 vlib_prefetch_buffer_header(p3, STORE);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800200
Neale Ranns31ed7442018-02-23 05:29:09 -0800201 CLIB_PREFETCH(p2->data, sizeof(ip6_header_t), STORE);
202 CLIB_PREFETCH(p3->data, sizeof(ip6_header_t), STORE);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800203 }
204
205 from += 2;
206 to_next += 2;
207 n_left_from -= 2;
208 n_left_to_next -= 2;
209
Neale Ranns31ed7442018-02-23 05:29:09 -0800210 b0 = vlib_get_buffer(vm, bi0);
211 b1 = vlib_get_buffer(vm, bi1);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800212
213 /* dst lookup was done by ip4 lookup */
214 mddi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
215 mddi1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX];
216 mdd0 = mpls_disp_dpo_get(mddi0);
217 mdd1 = mpls_disp_dpo_get(mddi1);
218
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700219 next0 = mdd0->mdd_dpo.dpoi_next_node;
220 next1 = mdd1->mdd_dpo.dpoi_next_node;
221
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800222 if (payload_is_ip4)
223 {
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700224 ip4_header_t *ip0, *ip1;
225
Neale Ranns31ed7442018-02-23 05:29:09 -0800226 ip0 = vlib_buffer_get_current(b0);
227 ip1 = vlib_buffer_get_current(b1);
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700228
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800229 /*
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700230 * IPv4 input checks on the exposed IP header
231 * including checksum
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800232 */
Neale Ranns31ed7442018-02-23 05:29:09 -0800233 ip4_input_check_x2(vm, error_node,
234 b0, b1, ip0, ip1,
235 &next0, &next1, 1);
236
237 if (FIB_MPLS_LSP_MODE_UNIFORM == mode)
238 {
239 /*
240 * Copy the TTL from the MPLS packet into the
241 * exposed IP. recalc the chksum
242 */
243 ip0->ttl = vnet_buffer(b0)->mpls.ttl;
244 ip1->ttl = vnet_buffer(b1)->mpls.ttl;
245 ip0->tos = mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp);
246 ip1->tos = mpls_exp_to_ip_dscp(vnet_buffer(b1)->mpls.exp);
247
248 ip0->checksum = ip4_header_checksum(ip0);
249 ip1->checksum = ip4_header_checksum(ip1);
250 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800251 }
252 else if (payload_is_ip6)
253 {
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700254 ip6_header_t *ip0, *ip1;
255
Neale Ranns31ed7442018-02-23 05:29:09 -0800256 ip0 = vlib_buffer_get_current(b0);
257 ip1 = vlib_buffer_get_current(b1);
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700258
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800259 /*
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700260 * IPv6 input checks on the exposed IP header
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800261 */
Neale Ranns31ed7442018-02-23 05:29:09 -0800262 ip6_input_check_x2(vm, error_node,
263 b0, b1, ip0, ip1,
264 &next0, &next1);
265
266 if (FIB_MPLS_LSP_MODE_UNIFORM == mode)
267 {
268 /*
269 * Copy the TTL from the MPLS packet into the
270 * exposed IP
271 */
272 ip0->hop_limit = vnet_buffer(b0)->mpls.ttl;
273 ip1->hop_limit = vnet_buffer(b1)->mpls.ttl;
274
275 ip6_set_traffic_class_network_order(
276 ip0,
277 mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp));
278 ip6_set_traffic_class_network_order(
279 ip1,
280 mpls_exp_to_ip_dscp(vnet_buffer(b1)->mpls.exp));
281 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800282 }
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700283
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800284 vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mdd0->mdd_dpo.dpoi_index;
285 vnet_buffer(b1)->ip.adj_index[VLIB_TX] = mdd1->mdd_dpo.dpoi_index;
286 vnet_buffer(b0)->ip.rpf_id = mdd0->mdd_rpf_id;
287 vnet_buffer(b1)->ip.rpf_id = mdd1->mdd_rpf_id;
288
289 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
290 {
291 mpls_label_disposition_trace_t *tr =
Neale Ranns31ed7442018-02-23 05:29:09 -0800292 vlib_add_trace(vm, node, b0, sizeof(*tr));
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800293
294 tr->mdd = mddi0;
295 }
296 if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
297 {
298 mpls_label_disposition_trace_t *tr =
Neale Ranns31ed7442018-02-23 05:29:09 -0800299 vlib_add_trace(vm, node, b1, sizeof(*tr));
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800300 tr->mdd = mddi1;
301 }
302
303 vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next,
304 n_left_to_next,
305 bi0, bi1, next0, next1);
306 }
307
308 while (n_left_from > 0 && n_left_to_next > 0)
309 {
310 mpls_disp_dpo_t *mdd0;
311 vlib_buffer_t * b0;
312 u32 bi0, mddi0;
313 u32 next0;
314
315 bi0 = from[0];
316 to_next[0] = bi0;
317 from += 1;
318 to_next += 1;
319 n_left_from -= 1;
320 n_left_to_next -= 1;
321
Neale Ranns31ed7442018-02-23 05:29:09 -0800322 b0 = vlib_get_buffer(vm, bi0);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800323
324 /* dst lookup was done by ip4 lookup */
325 mddi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
326 mdd0 = mpls_disp_dpo_get(mddi0);
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700327 next0 = mdd0->mdd_dpo.dpoi_next_node;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800328
329 if (payload_is_ip4)
330 {
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700331 ip4_header_t *ip0;
332
Neale Ranns31ed7442018-02-23 05:29:09 -0800333 ip0 = vlib_buffer_get_current(b0);
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700334
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800335 /*
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700336 * IPv4 input checks on the exposed IP header
337 * including checksum
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800338 */
Neale Ranns31ed7442018-02-23 05:29:09 -0800339 ip4_input_check_x1(vm, error_node, b0, ip0, &next0, 1);
340
341 if (FIB_MPLS_LSP_MODE_UNIFORM == mode)
342 {
343 /*
344 * Copy the TTL from the MPLS packet into the
345 * exposed IP. recalc the chksum
346 */
347 ip0->ttl = vnet_buffer(b0)->mpls.ttl;
348 ip0->tos = mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp);
349 ip0->checksum = ip4_header_checksum(ip0);
350 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800351 }
352 else if (payload_is_ip6)
353 {
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700354 ip6_header_t *ip0;
355
Neale Ranns31ed7442018-02-23 05:29:09 -0800356 ip0 = vlib_buffer_get_current(b0);
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700357
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800358 /*
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700359 * IPv6 input checks on the exposed IP header
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800360 */
Neale Ranns31ed7442018-02-23 05:29:09 -0800361 ip6_input_check_x1(vm, error_node, b0, ip0, &next0);
362
363 if (FIB_MPLS_LSP_MODE_UNIFORM == mode)
364 {
365 /*
366 * Copy the TTL from the MPLS packet into the
367 * exposed IP
368 */
369 ip0->hop_limit = vnet_buffer(b0)->mpls.ttl;
370
371 ip6_set_traffic_class_network_order(
372 ip0,
373 mpls_exp_to_ip_dscp(vnet_buffer(b0)->mpls.exp));
374 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800375 }
376
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800377 vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mdd0->mdd_dpo.dpoi_index;
378 vnet_buffer(b0)->ip.rpf_id = mdd0->mdd_rpf_id;
379
380 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
381 {
382 mpls_label_disposition_trace_t *tr =
Neale Ranns31ed7442018-02-23 05:29:09 -0800383 vlib_add_trace(vm, node, b0, sizeof(*tr));
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800384 tr->mdd = mddi0;
385 }
386
387 vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
388 n_left_to_next, bi0, next0);
389 }
Neale Ranns31ed7442018-02-23 05:29:09 -0800390 vlib_put_next_frame(vm, node, next_index, n_left_to_next);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800391 }
392 return from_frame->n_vectors;
393}
394
395static u8 *
396format_mpls_label_disposition_trace (u8 * s, va_list * args)
397{
Neale Ranns31ed7442018-02-23 05:29:09 -0800398 CLIB_UNUSED(vlib_main_t * vm) = va_arg(*args, vlib_main_t *);
399 CLIB_UNUSED(vlib_node_t * node) = va_arg(*args, vlib_node_t *);
400 CLIB_UNUSED(mpls_label_disposition_trace_t * t);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800401
Neale Ranns31ed7442018-02-23 05:29:09 -0800402 t = va_arg(*args, mpls_label_disposition_trace_t *);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800403
404 s = format(s, "disp:%d", t->mdd);
405 return (s);
406}
407
408static uword
Neale Ranns31ed7442018-02-23 05:29:09 -0800409ip4_mpls_label_disposition_pipe (vlib_main_t * vm,
410 vlib_node_runtime_t * node,
411 vlib_frame_t * frame)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800412{
Neale Ranns31ed7442018-02-23 05:29:09 -0800413 return (mpls_label_disposition_inline(vm, node, frame, 1, 0,
414 FIB_MPLS_LSP_MODE_PIPE));
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800415}
416
Neale Ranns31ed7442018-02-23 05:29:09 -0800417VLIB_REGISTER_NODE(ip4_mpls_label_disposition_pipe_node) = {
418 .function = ip4_mpls_label_disposition_pipe,
419 .name = "ip4-mpls-label-disposition-pipe",
420 .vector_size = sizeof(u32),
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800421
422 .format_trace = format_mpls_label_disposition_trace,
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700423 .sibling_of = "ip4-input",
424 .n_errors = IP4_N_ERROR,
425 .error_strings = ip4_error_strings,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800426};
Neale Ranns31ed7442018-02-23 05:29:09 -0800427VLIB_NODE_FUNCTION_MULTIARCH(ip4_mpls_label_disposition_pipe_node,
428 ip4_mpls_label_disposition_pipe)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800429
430static uword
Neale Ranns31ed7442018-02-23 05:29:09 -0800431ip6_mpls_label_disposition_pipe (vlib_main_t * vm,
432 vlib_node_runtime_t * node,
433 vlib_frame_t * frame)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800434{
Neale Ranns31ed7442018-02-23 05:29:09 -0800435 return (mpls_label_disposition_inline(vm, node, frame, 0, 1,
436 FIB_MPLS_LSP_MODE_PIPE));
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800437}
438
Neale Ranns31ed7442018-02-23 05:29:09 -0800439VLIB_REGISTER_NODE(ip6_mpls_label_disposition_pipe_node) = {
440 .function = ip6_mpls_label_disposition_pipe,
441 .name = "ip6-mpls-label-disposition-pipe",
442 .vector_size = sizeof(u32),
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800443
444 .format_trace = format_mpls_label_disposition_trace,
Neale Ranns4c7c8e52017-10-21 09:37:55 -0700445 .sibling_of = "ip6-input",
446 .n_errors = IP6_N_ERROR,
447 .error_strings = ip6_error_strings,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800448};
Neale Ranns31ed7442018-02-23 05:29:09 -0800449VLIB_NODE_FUNCTION_MULTIARCH(ip6_mpls_label_disposition_pipe_node,
450 ip6_mpls_label_disposition_pipe)
451
452static uword
453ip4_mpls_label_disposition_uniform (vlib_main_t * vm,
454 vlib_node_runtime_t * node,
455 vlib_frame_t * frame)
456{
457 return (mpls_label_disposition_inline(vm, node, frame, 1, 0,
458 FIB_MPLS_LSP_MODE_UNIFORM));
459}
460
461VLIB_REGISTER_NODE(ip4_mpls_label_disposition_uniform_node) = {
462 .function = ip4_mpls_label_disposition_uniform,
463 .name = "ip4-mpls-label-disposition-uniform",
464 .vector_size = sizeof(u32),
465
466 .format_trace = format_mpls_label_disposition_trace,
467 .sibling_of = "ip4-input",
468 .n_errors = IP4_N_ERROR,
469 .error_strings = ip4_error_strings,
470};
471VLIB_NODE_FUNCTION_MULTIARCH(ip4_mpls_label_disposition_uniform_node,
472 ip4_mpls_label_disposition_uniform)
473
474static uword
475ip6_mpls_label_disposition_uniform (vlib_main_t * vm,
476 vlib_node_runtime_t * node,
477 vlib_frame_t * frame)
478{
479 return (mpls_label_disposition_inline(vm, node, frame, 0, 1,
480 FIB_MPLS_LSP_MODE_UNIFORM));
481}
482
483VLIB_REGISTER_NODE(ip6_mpls_label_disposition_uniform_node) = {
484 .function = ip6_mpls_label_disposition_uniform,
485 .name = "ip6-mpls-label-disposition-uniform",
486 .vector_size = sizeof(u32),
487
488 .format_trace = format_mpls_label_disposition_trace,
489 .sibling_of = "ip6-input",
490 .n_errors = IP6_N_ERROR,
491 .error_strings = ip6_error_strings,
492};
493VLIB_NODE_FUNCTION_MULTIARCH(ip6_mpls_label_disposition_uniform_node,
494 ip6_mpls_label_disposition_uniform)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800495
496static void
497mpls_disp_dpo_mem_show (void)
498{
499 fib_show_memory_usage("MPLS label",
500 pool_elts(mpls_disp_dpo_pool),
501 pool_len(mpls_disp_dpo_pool),
502 sizeof(mpls_disp_dpo_t));
503}
504
505const static dpo_vft_t mdd_vft = {
506 .dv_lock = mpls_disp_dpo_lock,
507 .dv_unlock = mpls_disp_dpo_unlock,
508 .dv_format = format_mpls_disp_dpo,
509 .dv_mem_show = mpls_disp_dpo_mem_show,
510};
511
Neale Ranns31ed7442018-02-23 05:29:09 -0800512const static char* const mpls_label_disp_pipe_ip4_nodes[] =
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800513{
Neale Ranns31ed7442018-02-23 05:29:09 -0800514 "ip4-mpls-label-disposition-pipe",
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800515 NULL,
516};
Neale Ranns31ed7442018-02-23 05:29:09 -0800517const static char* const mpls_label_disp_pipe_ip6_nodes[] =
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800518{
Neale Ranns31ed7442018-02-23 05:29:09 -0800519 "ip6-mpls-label-disposition-pipe",
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800520 NULL,
521};
Neale Ranns31ed7442018-02-23 05:29:09 -0800522const static char* const * const mpls_label_disp_pipe_nodes[DPO_PROTO_NUM] =
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800523{
Neale Ranns31ed7442018-02-23 05:29:09 -0800524 [DPO_PROTO_IP4] = mpls_label_disp_pipe_ip4_nodes,
525 [DPO_PROTO_IP6] = mpls_label_disp_pipe_ip6_nodes,
526};
527
528const static char* const mpls_label_disp_uniform_ip4_nodes[] =
529{
530 "ip4-mpls-label-disposition-uniform",
531 NULL,
532};
533const static char* const mpls_label_disp_uniform_ip6_nodes[] =
534{
535 "ip6-mpls-label-disposition-uniform",
536 NULL,
537};
538const static char* const * const mpls_label_disp_uniform_nodes[DPO_PROTO_NUM] =
539{
540 [DPO_PROTO_IP4] = mpls_label_disp_uniform_ip4_nodes,
541 [DPO_PROTO_IP6] = mpls_label_disp_uniform_ip6_nodes,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800542};
543
544
545void
Neale Ranns31ed7442018-02-23 05:29:09 -0800546mpls_disp_dpo_module_init(void)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800547{
Neale Ranns31ed7442018-02-23 05:29:09 -0800548 dpo_register(DPO_MPLS_DISPOSITION_PIPE, &mdd_vft,
549 mpls_label_disp_pipe_nodes);
550 dpo_register(DPO_MPLS_DISPOSITION_UNIFORM, &mdd_vft,
551 mpls_label_disp_uniform_nodes);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800552}