Line data Source code
1 : /*
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 :
16 : /**
17 : * @file
18 : * @brief Local TCP/IP stack punt infrastructure.
19 : *
20 : * Provides a set of VPP nodes together with the relevant APIs and CLI
21 : * commands in order to adjust and dispatch packets from the VPP data plane
22 : * to the local TCP/IP stack
23 : */
24 :
25 : #include <vnet/ip/ip.h>
26 : #include <vnet/ethernet/ethernet.h>
27 : #include <vlib/vlib.h>
28 : #include <vnet/ip/punt.h>
29 : #include <vlib/unix/unix.h>
30 :
31 : #include <stdio.h>
32 : #include <unistd.h>
33 : #include <sys/socket.h>
34 : #include <sys/uio.h>
35 : #include <stdlib.h>
36 :
37 : typedef enum
38 : {
39 : #define punt_error(n,s) PUNT_ERROR_##n,
40 : #include <vnet/ip/punt_error.def>
41 : #undef punt_error
42 : PUNT_N_ERROR,
43 : } punt_error_t;
44 :
45 : #define foreach_punt_next \
46 : _ (PUNT4, "ip4-punt") \
47 : _ (PUNT6, "ip6-punt")
48 :
49 : typedef enum
50 : {
51 : #define _(s,n) PUNT_NEXT_##s,
52 : foreach_punt_next
53 : #undef _
54 : PUNT_N_NEXT,
55 : } punt_next_t;
56 :
57 : enum punt_socket_rx_next_e
58 : {
59 : PUNT_SOCKET_RX_NEXT_INTERFACE_OUTPUT,
60 : PUNT_SOCKET_RX_NEXT_IP4_LOOKUP,
61 : PUNT_SOCKET_RX_NEXT_IP6_LOOKUP,
62 : PUNT_SOCKET_RX_N_NEXT
63 : };
64 :
65 : #define punt_next_punt(is_ip4) (is_ip4 ? PUNT_NEXT_PUNT4 : PUNT_NEXT_PUNT6)
66 :
67 : /** @brief IPv4/IPv6 UDP punt node main loop.
68 :
69 : This is the main loop inline function for IPv4/IPv6 UDP punt
70 : transition node.
71 :
72 : @param vm vlib_main_t corresponding to the current thread
73 : @param node vlib_node_runtime_t
74 : @param frame vlib_frame_t whose contents should be dispatched
75 : @param is_ipv4 indicates if called for IPv4 or IPv6 node
76 : */
77 : always_inline uword
78 73 : udp46_punt_inline (vlib_main_t * vm,
79 : vlib_node_runtime_t * node,
80 : vlib_frame_t * from_frame, int is_ip4)
81 : {
82 : u32 n_left_from, *from, *to_next;
83 : word advance;
84 :
85 73 : from = vlib_frame_vector_args (from_frame);
86 73 : n_left_from = from_frame->n_vectors;
87 :
88 : /* udp[46]_lookup hands us the data payload, not the IP header */
89 73 : if (is_ip4)
90 41 : advance = -(sizeof (ip4_header_t) + sizeof (udp_header_t));
91 : else
92 32 : advance = -(sizeof (ip6_header_t) + sizeof (udp_header_t));
93 :
94 146 : while (n_left_from > 0)
95 : {
96 : u32 n_left_to_next;
97 :
98 73 : vlib_get_next_frame (vm, node, punt_next_punt (is_ip4), to_next,
99 : n_left_to_next);
100 :
101 10765 : while (n_left_from > 0 && n_left_to_next > 0)
102 : {
103 : u32 bi0;
104 : vlib_buffer_t *b0;
105 :
106 10692 : bi0 = from[0];
107 10692 : to_next[0] = bi0;
108 10692 : from += 1;
109 10692 : to_next += 1;
110 10692 : n_left_from -= 1;
111 10692 : n_left_to_next -= 1;
112 :
113 10692 : b0 = vlib_get_buffer (vm, bi0);
114 10692 : vlib_buffer_advance (b0, advance);
115 10692 : b0->error = node->errors[PUNT_ERROR_UDP_PORT];
116 : }
117 :
118 73 : vlib_put_next_frame (vm, node, punt_next_punt (is_ip4), n_left_to_next);
119 : }
120 :
121 73 : return from_frame->n_vectors;
122 : }
123 :
124 : static char *punt_error_strings[] = {
125 : #define punt_error(n,s) s,
126 : #include "punt_error.def"
127 : #undef punt_error
128 : };
129 :
130 : /** @brief IPv4 UDP punt node.
131 : @node ip4-udp-punt
132 :
133 : This is the IPv4 UDP punt transition node. It is registered as a next
134 : node for the "ip4-udp-lookup" handling UDP port(s) requested for punt.
135 : The buffer's current data pointer is adjusted to the original packet
136 : IPv4 header. All buffers are dispatched to "error-punt".
137 :
138 : @param vm vlib_main_t corresponding to the current thread
139 : @param node vlib_node_runtime_t
140 : @param frame vlib_frame_t whose contents should be dispatched
141 :
142 : @par Graph mechanics: next index usage
143 :
144 : @em Sets:
145 : - <code>vnet_buffer(b)->current_data</code>
146 : - <code>vnet_buffer(b)->current_len</code>
147 :
148 : <em>Next Index:</em>
149 : - Dispatches the packet to the "error-punt" node
150 : */
151 2341 : VLIB_NODE_FN (udp4_punt_node) (vlib_main_t * vm,
152 : vlib_node_runtime_t * node,
153 : vlib_frame_t * from_frame)
154 : {
155 41 : return udp46_punt_inline (vm, node, from_frame, 1 /* is_ip4 */ );
156 : }
157 :
158 : /** @brief IPv6 UDP punt node.
159 : @node ip6-udp-punt
160 :
161 : This is the IPv6 UDP punt transition node. It is registered as a next
162 : node for the "ip6-udp-lookup" handling UDP port(s) requested for punt.
163 : The buffer's current data pointer is adjusted to the original packet
164 : IPv6 header. All buffers are dispatched to "error-punt".
165 :
166 : @param vm vlib_main_t corresponding to the current thread
167 : @param node vlib_node_runtime_t
168 : @param frame vlib_frame_t whose contents should be dispatched
169 :
170 : @par Graph mechanics: next index usage
171 :
172 : @em Sets:
173 : - <code>vnet_buffer(b)->current_data</code>
174 : - <code>vnet_buffer(b)->current_len</code>
175 :
176 : <em>Next Index:</em>
177 : - Dispatches the packet to the "error-punt" node
178 : */
179 2332 : VLIB_NODE_FN (udp6_punt_node) (vlib_main_t * vm,
180 : vlib_node_runtime_t * node,
181 : vlib_frame_t * from_frame)
182 : {
183 32 : return udp46_punt_inline (vm, node, from_frame, 0 /* is_ip4 */ );
184 : }
185 :
186 : /* *INDENT-OFF* */
187 183788 : VLIB_REGISTER_NODE (udp4_punt_node) = {
188 : .name = "ip4-udp-punt",
189 : /* Takes a vector of packets. */
190 : .vector_size = sizeof (u32),
191 :
192 : .n_errors = PUNT_N_ERROR,
193 : .error_strings = punt_error_strings,
194 :
195 : .n_next_nodes = PUNT_N_NEXT,
196 : .next_nodes = {
197 : #define _(s,n) [PUNT_NEXT_##s] = n,
198 : foreach_punt_next
199 : #undef _
200 : },
201 : };
202 :
203 183788 : VLIB_REGISTER_NODE (udp6_punt_node) = {
204 : .name = "ip6-udp-punt",
205 : /* Takes a vector of packets. */
206 : .vector_size = sizeof (u32),
207 :
208 : .n_errors = PUNT_N_ERROR,
209 : .error_strings = punt_error_strings,
210 :
211 : .n_next_nodes = PUNT_N_NEXT,
212 : .next_nodes = {
213 : #define _(s,n) [PUNT_NEXT_##s] = n,
214 : foreach_punt_next
215 : #undef _
216 : },
217 : };
218 : /* *INDENT-ON* */
219 :
220 : typedef struct
221 : {
222 : punt_client_t client;
223 : u8 is_midchain;
224 : u8 packet_data[64];
225 : } udp_punt_trace_t;
226 :
227 : static u8 *
228 75 : format_udp_punt_trace (u8 * s, va_list * args)
229 : {
230 75 : CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
231 75 : CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
232 75 : udp_punt_trace_t *t = va_arg (*args, udp_punt_trace_t *);
233 75 : u32 indent = format_get_indent (s);
234 75 : s = format (s, "to: %s", t->client.caddr.sun_path);
235 75 : if (t->is_midchain)
236 : {
237 0 : s = format (s, "\n%U(buffer is part of chain)", format_white_space,
238 : indent);
239 : }
240 75 : s = format (s, "\n%U%U", format_white_space, indent,
241 75 : format_hex_bytes, t->packet_data, sizeof (t->packet_data));
242 :
243 75 : return s;
244 : }
245 :
246 : always_inline uword
247 16 : punt_socket_inline2 (vlib_main_t *vm, vlib_node_runtime_t *node,
248 : vlib_frame_t *frame, punt_type_t pt,
249 : ip_address_family_t af, ip_protocol_t protocol)
250 : {
251 16 : u32 *buffers = vlib_frame_vector_args (frame);
252 16 : u32 thread_index = vm->thread_index;
253 16 : uword n_packets = frame->n_vectors;
254 16 : punt_main_t *pm = &punt_main;
255 : int i;
256 :
257 16 : punt_thread_data_t *ptd = &pm->thread_data[thread_index];
258 16 : u32 node_index = (AF_IP4 == af ?
259 16 : udp4_punt_socket_node.index :
260 : udp6_punt_socket_node.index);
261 :
262 63 : for (i = 0; i < n_packets; i++)
263 : {
264 : struct iovec *iov;
265 : vlib_buffer_t *b;
266 : uword l;
267 : punt_packetdesc_t packetdesc;
268 : punt_client_t *c;
269 47 : u16 port = 0;
270 47 : b = vlib_get_buffer (vm, buffers[i]);
271 :
272 47 : if (PUNT_TYPE_L4 == pt)
273 : {
274 38 : if (protocol == IP_PROTOCOL_UDP)
275 : {
276 : /* Reverse UDP Punt advance */
277 : udp_header_t *udp;
278 38 : if (AF_IP4 == af)
279 : {
280 20 : vlib_buffer_advance (
281 : b, -(sizeof (ip4_header_t) + sizeof (udp_header_t)));
282 20 : ip4_header_t *ip = vlib_buffer_get_current (b);
283 20 : udp = (udp_header_t *) (ip + 1);
284 : }
285 : else
286 : {
287 18 : vlib_buffer_advance (
288 : b, -(sizeof (ip6_header_t) + sizeof (udp_header_t)));
289 18 : ip6_header_t *ip = vlib_buffer_get_current (b);
290 18 : udp = (udp_header_t *) (ip + 1);
291 : }
292 38 : port = clib_net_to_host_u16 (udp->dst_port);
293 : }
294 0 : else if (protocol == IP_PROTOCOL_ICMP6)
295 : {
296 0 : ip6_header_t *ip = vlib_buffer_get_current (b);
297 0 : icmp46_header_t *icmp = ip6_next_header (ip);
298 0 : port = icmp->type;
299 : }
300 : /*
301 : * Find registerered client
302 : * If no registered client, drop packet and count
303 : */
304 38 : c = punt_client_l4_get (af, port);
305 : }
306 9 : else if (PUNT_TYPE_IP_PROTO == pt)
307 : {
308 : /* Reverse UDP Punt advance */
309 : ip_protocol_t proto;
310 :
311 7 : if (AF_IP4 == af)
312 : {
313 7 : ip4_header_t *ip = vlib_buffer_get_current (b);
314 7 : proto = ip->protocol;
315 : }
316 : else
317 : {
318 0 : ip6_header_t *ip = vlib_buffer_get_current (b);
319 0 : proto = ip->protocol;
320 : }
321 :
322 7 : c = punt_client_ip_proto_get (af, proto);
323 : }
324 2 : else if (PUNT_TYPE_EXCEPTION == pt)
325 : {
326 2 : c = punt_client_exception_get (b->punt_reason);
327 : }
328 : else
329 0 : c = NULL;
330 :
331 47 : if (PREDICT_FALSE (NULL == c))
332 : {
333 0 : vlib_node_increment_counter (vm, node_index,
334 : PUNT_ERROR_SOCKET_TX_ERROR, 1);
335 0 : goto error;
336 : }
337 :
338 47 : struct sockaddr_un *caddr = &c->caddr;
339 :
340 : /* Re-set iovecs */
341 47 : vec_reset_length (ptd->iovecs);
342 :
343 : /* Add packet descriptor */
344 47 : packetdesc.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
345 47 : packetdesc.action = 0;
346 47 : vec_add2 (ptd->iovecs, iov, 1);
347 47 : iov->iov_base = &packetdesc;
348 47 : iov->iov_len = sizeof (packetdesc);
349 :
350 : /** VLIB buffer chain -> Unix iovec(s). */
351 47 : vlib_buffer_advance (b, -ethernet_buffer_header_size (b));
352 47 : vec_add2 (ptd->iovecs, iov, 1);
353 47 : iov->iov_base = b->data + b->current_data;
354 47 : iov->iov_len = l = b->current_length;
355 :
356 47 : if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
357 : {
358 : udp_punt_trace_t *t;
359 47 : t = vlib_add_trace (vm, node, b, sizeof (t[0]));
360 47 : clib_memcpy_fast (&t->client, c, sizeof (t->client));
361 47 : clib_memcpy_fast (t->packet_data,
362 47 : vlib_buffer_get_current (b),
363 : sizeof (t->packet_data));
364 : }
365 :
366 47 : if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NEXT_PRESENT))
367 : {
368 : do
369 : {
370 0 : b = vlib_get_buffer (vm, b->next_buffer);
371 0 : if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
372 : {
373 : udp_punt_trace_t *t;
374 0 : t = vlib_add_trace (vm, node, b, sizeof (t[0]));
375 0 : clib_memcpy_fast (&t->client, c, sizeof (t->client));
376 0 : t->is_midchain = 1;
377 : }
378 :
379 0 : vec_add2 (ptd->iovecs, iov, 1);
380 :
381 0 : iov->iov_base = b->data + b->current_data;
382 0 : iov->iov_len = b->current_length;
383 0 : l += b->current_length;
384 : }
385 0 : while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
386 : }
387 :
388 94 : struct msghdr msg = {
389 : .msg_name = caddr,
390 : .msg_namelen = sizeof (*caddr),
391 47 : .msg_iov = ptd->iovecs,
392 47 : .msg_iovlen = vec_len (ptd->iovecs),
393 : };
394 :
395 47 : if (sendmsg (pm->socket_fd, &msg, 0) < (ssize_t) l)
396 1 : vlib_node_increment_counter (vm, node_index,
397 : PUNT_ERROR_SOCKET_TX_ERROR, 1);
398 : else
399 46 : vlib_node_increment_counter (vm, node_index, PUNT_ERROR_SOCKET_TX, 1);
400 : }
401 :
402 16 : error:
403 16 : vlib_buffer_free (vm, buffers, n_packets);
404 :
405 16 : return n_packets;
406 : }
407 :
408 : always_inline uword
409 16 : punt_socket_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
410 : vlib_frame_t *frame, punt_type_t pt,
411 : ip_address_family_t af)
412 : {
413 16 : return punt_socket_inline2 (vm, node, frame, pt, af, IP_PROTOCOL_UDP);
414 : }
415 :
416 : static uword
417 7 : udp4_punt_socket (vlib_main_t * vm,
418 : vlib_node_runtime_t * node, vlib_frame_t * from_frame)
419 : {
420 7 : return punt_socket_inline (vm, node, from_frame, PUNT_TYPE_L4, AF_IP4);
421 : }
422 :
423 : static uword
424 6 : udp6_punt_socket (vlib_main_t * vm,
425 : vlib_node_runtime_t * node, vlib_frame_t * from_frame)
426 : {
427 6 : return punt_socket_inline (vm, node, from_frame, PUNT_TYPE_L4, AF_IP6);
428 : }
429 :
430 : static uword
431 1 : ip4_proto_punt_socket (vlib_main_t * vm,
432 : vlib_node_runtime_t * node, vlib_frame_t * from_frame)
433 : {
434 1 : return punt_socket_inline (vm, node, from_frame,
435 : PUNT_TYPE_IP_PROTO, AF_IP4);
436 : }
437 :
438 : static uword
439 0 : ip6_proto_punt_socket (vlib_main_t * vm,
440 : vlib_node_runtime_t * node, vlib_frame_t * from_frame)
441 : {
442 0 : return punt_socket_inline (vm, node, from_frame,
443 : PUNT_TYPE_IP_PROTO, AF_IP6);
444 : }
445 :
446 : static uword
447 0 : icmp6_punt_socket (vlib_main_t *vm, vlib_node_runtime_t *node,
448 : vlib_frame_t *from_frame)
449 : {
450 0 : return punt_socket_inline2 (vm, node, from_frame, PUNT_TYPE_L4, AF_IP6,
451 : IP_PROTOCOL_ICMP6);
452 : }
453 :
454 : static uword
455 2 : exception_punt_socket (vlib_main_t * vm,
456 : vlib_node_runtime_t * node, vlib_frame_t * from_frame)
457 : {
458 2 : return punt_socket_inline (vm, node, from_frame,
459 : PUNT_TYPE_EXCEPTION, AF_IP4);
460 : }
461 :
462 :
463 : /* *INDENT-OFF* */
464 183788 : VLIB_REGISTER_NODE (udp4_punt_socket_node) = {
465 : .function = udp4_punt_socket,
466 : .name = "ip4-udp-punt-socket",
467 : .format_trace = format_udp_punt_trace,
468 : .flags = VLIB_NODE_FLAG_IS_DROP,
469 : /* Takes a vector of packets. */
470 : .vector_size = sizeof (u32),
471 : .n_errors = PUNT_N_ERROR,
472 : .error_strings = punt_error_strings,
473 : };
474 183788 : VLIB_REGISTER_NODE (udp6_punt_socket_node) = {
475 : .function = udp6_punt_socket,
476 : .name = "ip6-udp-punt-socket",
477 : .format_trace = format_udp_punt_trace,
478 : .flags = VLIB_NODE_FLAG_IS_DROP,
479 : .vector_size = sizeof (u32),
480 : .n_errors = PUNT_N_ERROR,
481 : .error_strings = punt_error_strings,
482 : };
483 183788 : VLIB_REGISTER_NODE (ip4_proto_punt_socket_node) = {
484 : .function = ip4_proto_punt_socket,
485 : .name = "ip4-proto-punt-socket",
486 : .format_trace = format_udp_punt_trace,
487 : .flags = VLIB_NODE_FLAG_IS_DROP,
488 : /* Takes a vector of packets. */
489 : .vector_size = sizeof (u32),
490 : .n_errors = PUNT_N_ERROR,
491 : .error_strings = punt_error_strings,
492 : };
493 183788 : VLIB_REGISTER_NODE (ip6_proto_punt_socket_node) = {
494 : .function = ip6_proto_punt_socket,
495 : .name = "ip6-proto-punt-socket",
496 : .format_trace = format_udp_punt_trace,
497 : .flags = VLIB_NODE_FLAG_IS_DROP,
498 : .vector_size = sizeof (u32),
499 : .n_errors = PUNT_N_ERROR,
500 : .error_strings = punt_error_strings,
501 : };
502 183788 : VLIB_REGISTER_NODE (exception_punt_socket_node) = {
503 : .function = exception_punt_socket,
504 : .name = "exception-punt-socket",
505 : .format_trace = format_udp_punt_trace,
506 : .flags = VLIB_NODE_FLAG_IS_DROP,
507 : .vector_size = sizeof (u32),
508 : .n_errors = PUNT_N_ERROR,
509 : .error_strings = punt_error_strings,
510 : };
511 183788 : VLIB_REGISTER_NODE (icmp6_punt_socket_node) = {
512 : .function = icmp6_punt_socket,
513 : .name = "ip6-icmp-punt-socket",
514 : .format_trace = format_udp_punt_trace,
515 : .flags = VLIB_NODE_FLAG_IS_DROP,
516 : .vector_size = sizeof (u32),
517 : .n_errors = PUNT_N_ERROR,
518 : .error_strings = punt_error_strings,
519 : };
520 :
521 : /* *INDENT-ON* */
522 :
523 : typedef struct
524 : {
525 : enum punt_action_e action;
526 : u32 sw_if_index;
527 : } punt_trace_t;
528 :
529 : static u8 *
530 0 : format_punt_trace (u8 * s, va_list * va)
531 : {
532 0 : CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
533 0 : CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
534 0 : vnet_main_t *vnm = vnet_get_main ();
535 0 : punt_trace_t *t = va_arg (*va, punt_trace_t *);
536 0 : s = format (s, "%U Action: %d", format_vnet_sw_if_index_name,
537 0 : vnm, t->sw_if_index, t->action);
538 0 : return s;
539 : }
540 :
541 : static uword
542 0 : punt_socket_rx_fd (vlib_main_t * vm, vlib_node_runtime_t * node, u32 fd)
543 : {
544 0 : const uword buffer_size = vlib_buffer_get_default_data_size (vm);
545 0 : u32 n_trace = vlib_get_trace_count (vm, node);
546 0 : u32 next = node->cached_next_index;
547 : u32 n_left_to_next, next_index;
548 : u32 *to_next;
549 0 : u32 error = PUNT_ERROR_NONE;
550 0 : vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
551 :
552 : /* $$$$ Only dealing with one buffer at the time for now */
553 :
554 : u32 bi;
555 : vlib_buffer_t *b;
556 : punt_packetdesc_t packetdesc;
557 : ssize_t size;
558 : struct iovec io[2];
559 :
560 0 : if (vlib_buffer_alloc (vm, &bi, 1) != 1)
561 : {
562 0 : error = PUNT_ERROR_NOBUFFER;
563 0 : goto error;
564 : }
565 :
566 0 : b = vlib_get_buffer (vm, bi);
567 0 : io[0].iov_base = &packetdesc;
568 0 : io[0].iov_len = sizeof (packetdesc);
569 0 : io[1].iov_base = b->data;
570 0 : io[1].iov_len = buffer_size;
571 :
572 0 : size = readv (fd, io, 2);
573 : /* We need at least the packet descriptor plus a header */
574 0 : if (size <= (int) (sizeof (packetdesc) + sizeof (ip4_header_t)))
575 : {
576 0 : vlib_buffer_free (vm, &bi, 1);
577 0 : error = PUNT_ERROR_READV;
578 0 : goto error;
579 : }
580 :
581 0 : b->flags = VNET_BUFFER_F_LOCALLY_ORIGINATED;
582 0 : b->current_length = size - sizeof (packetdesc);
583 :
584 0 : switch (packetdesc.action)
585 : {
586 0 : case PUNT_L2:
587 0 : vnet_buffer (b)->sw_if_index[VLIB_TX] = packetdesc.sw_if_index;
588 0 : next_index = PUNT_SOCKET_RX_NEXT_INTERFACE_OUTPUT;
589 0 : break;
590 :
591 0 : case PUNT_IP4_ROUTED:
592 0 : vnet_buffer (b)->sw_if_index[VLIB_RX] = packetdesc.sw_if_index;
593 0 : vnet_buffer (b)->sw_if_index[VLIB_TX] = ~0;
594 0 : next_index = PUNT_SOCKET_RX_NEXT_IP4_LOOKUP;
595 0 : break;
596 :
597 0 : case PUNT_IP6_ROUTED:
598 0 : vnet_buffer (b)->sw_if_index[VLIB_RX] = packetdesc.sw_if_index;
599 0 : vnet_buffer (b)->sw_if_index[VLIB_TX] = ~0;
600 0 : next_index = PUNT_SOCKET_RX_NEXT_IP6_LOOKUP;
601 0 : break;
602 :
603 0 : default:
604 0 : error = PUNT_ERROR_ACTION;
605 0 : vlib_buffer_free (vm, &bi, 1);
606 0 : goto error;
607 : }
608 :
609 0 : if (PREDICT_FALSE
610 : (n_trace > 0
611 : && vlib_trace_buffer (vm, node, next_index, b, 1 /* follow_chain */ )))
612 : {
613 : punt_trace_t *t;
614 0 : vlib_set_trace_count (vm, node, --n_trace);
615 0 : t = vlib_add_trace (vm, node, b, sizeof (*t));
616 0 : t->sw_if_index = packetdesc.sw_if_index;
617 0 : t->action = packetdesc.action;
618 : }
619 :
620 0 : to_next[0] = bi;
621 0 : to_next++;
622 0 : n_left_to_next--;
623 :
624 0 : vlib_validate_buffer_enqueue_x1 (vm, node, next, to_next, n_left_to_next,
625 : bi, next_index);
626 0 : vlib_put_next_frame (vm, node, next, n_left_to_next);
627 :
628 0 : return 1;
629 :
630 0 : error:
631 0 : vlib_put_next_frame (vm, node, next, n_left_to_next);
632 0 : vlib_node_increment_counter (vm, punt_socket_rx_node.index, error, 1);
633 0 : return 0;
634 : }
635 :
636 : static uword
637 0 : punt_socket_rx (vlib_main_t * vm,
638 : vlib_node_runtime_t * node, vlib_frame_t * frame)
639 : {
640 0 : punt_main_t *pm = &punt_main;
641 0 : u32 total_count = 0;
642 : int i;
643 :
644 0 : for (i = 0; i < vec_len (pm->ready_fds); i++)
645 : {
646 0 : total_count += punt_socket_rx_fd (vm, node, pm->ready_fds[i]);
647 0 : vec_del1 (pm->ready_fds, i);
648 : }
649 0 : return total_count;
650 : }
651 :
652 : /* *INDENT-OFF* */
653 183788 : VLIB_REGISTER_NODE (punt_socket_rx_node) =
654 : {
655 : .function = punt_socket_rx,
656 : .name = "punt-socket-rx",
657 : .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED,
658 : .type = VLIB_NODE_TYPE_INPUT,
659 : .state = VLIB_NODE_STATE_INTERRUPT,
660 : .vector_size = 1,
661 : .n_errors = PUNT_N_ERROR,
662 : .error_strings = punt_error_strings,
663 : .n_next_nodes = PUNT_SOCKET_RX_N_NEXT,
664 : .next_nodes = {
665 : [PUNT_SOCKET_RX_NEXT_INTERFACE_OUTPUT] = "interface-output",
666 : [PUNT_SOCKET_RX_NEXT_IP4_LOOKUP] = "ip4-lookup",
667 : [PUNT_SOCKET_RX_NEXT_IP6_LOOKUP] = "ip6-lookup",
668 : },
669 : .format_trace = format_punt_trace,
670 : };
671 : /* *INDENT-ON* */
672 :
673 : /*
674 : * fd.io coding-style-patch-verification: ON
675 : *
676 : * Local Variables:
677 : * eval: (c-set-style "gnu")
678 : * End:
679 : */
|