Repair vlib API socket server
[vpp.git] / src / plugins / ioam / udp-ping / udp_ping_node.c
1 /*
2  * Copyright (c) 2017 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 #include <vnet/vnet.h>
17 #include <vlib/vlib.h>
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20
21 #include <vnet/ip/ip.h>
22 #include <vnet/ip/ip6_hop_by_hop.h>
23 #include <ioam/encap/ip6_ioam_trace.h>
24 #include <ioam/encap/ip6_ioam_e2e.h>
25 #include <ioam/udp-ping/udp_ping_packet.h>
26 #include <ioam/udp-ping/udp_ping.h>
27 #include <ioam/udp-ping/udp_ping_util.h>
28 #include <vnet/srv6/sr_packet.h>
29
30 typedef enum
31 {
32   UDP_PING_NEXT_DROP,
33   UDP_PING_NEXT_PUNT,
34   UDP_PING_NEXT_UDP_LOOKUP,
35   UDP_PING_NEXT_ICMP,
36   UDP_PING_NEXT_IP6_LOOKUP,
37   UDP_PING_NEXT_IP6_DROP,
38   UDP_PING_N_NEXT,
39 } udp_ping_next_t;
40
41 udp_ping_main_t udp_ping_main;
42
43 uword
44 udp_ping_process (vlib_main_t * vm,
45                   vlib_node_runtime_t * rt, vlib_frame_t * f);
46
47 extern int
48 ip6_hbh_ioam_trace_data_list_handler (vlib_buffer_t * b, ip6_header_t * ip,
49                                       ip6_hop_by_hop_option_t * opt);
50
51 typedef struct
52 {
53   ip6_address_t src;
54   ip6_address_t dst;
55   u16 src_port;
56   u16 dst_port;
57   u16 handle;
58   u16 next_index;
59   u8 msg_type;
60 } udp_ping_trace_t;
61
62 /* packet trace format function */
63 static u8 *
64 format_udp_ping_trace (u8 * s, va_list * args)
65 {
66   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
67   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
68   udp_ping_trace_t *t = va_arg (*args, udp_ping_trace_t *);
69
70   s = format (s, "udp-ping-local: src %U, dst %U, src_port %u, dst_port %u "
71               "handle %u, next_index %u, msg_type %u",
72               format_ip6_address, &t->src,
73               format_ip6_address, &t->dst,
74               t->src_port, t->dst_port,
75               t->handle, t->next_index, t->msg_type);
76   return s;
77 }
78
79 /* *INDENT-OFF* */
80 VLIB_REGISTER_NODE (udp_ping_node, static) =
81 {
82   .function = udp_ping_process,
83   .type = VLIB_NODE_TYPE_PROCESS,
84   .name = "udp-ping-process",
85 };
86 /* *INDENT-ON* */
87
88 void
89 udp_ping_calculate_timer_interval (void)
90 {
91   int i;
92   ip46_udp_ping_flow *flow = NULL;
93   u16 min_interval = 0x1e9;
94
95   for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
96     {
97       if (pool_is_free_index (udp_ping_main.ip46_flow, i))
98         continue;
99
100       flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
101
102       if (min_interval > flow->udp_data.interval)
103         min_interval = flow->udp_data.interval;
104     }
105
106   if (udp_ping_main.timer_interval != min_interval)
107     {
108       udp_ping_main.timer_interval = min_interval;
109       vlib_process_signal_event (udp_ping_main.vlib_main,
110                                  udp_ping_node.index, EVENT_SIG_RECHECK, 0);
111     }
112 }
113
114 void
115 ip46_udp_ping_set_flow (ip46_address_t src, ip46_address_t dst,
116                         u16 start_src_port, u16 end_src_port,
117                         u16 start_dst_port, u16 end_dst_port,
118                         u16 interval, u8 fault_det, u8 is_disable)
119 {
120   u8 found = 0;
121   ip46_udp_ping_flow *flow = NULL;
122   int i;
123
124   for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
125     {
126       if (pool_is_free_index (udp_ping_main.ip46_flow, i))
127         continue;
128
129       flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
130       if ((0 == udp_ping_compare_flow (src, dst,
131                                        start_src_port, end_src_port,
132                                        start_dst_port, end_dst_port, flow)))
133         {
134           found = 1;
135           break;
136         }
137     }
138
139   if (found)
140     {
141       u16 cur_interval;
142       if (is_disable)
143         {
144           cur_interval = flow->udp_data.interval;
145           udp_ping_free_flow_data (flow);
146           pool_put_index (udp_ping_main.ip46_flow, i);
147           if (udp_ping_main.timer_interval == interval)
148             udp_ping_calculate_timer_interval ();
149           return;
150         }
151
152       cur_interval = flow->udp_data.interval;
153       flow->udp_data.interval = interval;
154       if (udp_ping_main.timer_interval > interval)
155         {
156           udp_ping_main.timer_interval = interval;
157           vlib_process_signal_event (udp_ping_main.vlib_main,
158                                      udp_ping_node.index,
159                                      EVENT_SIG_RECHECK, 0);
160         }
161       else if (udp_ping_main.timer_interval == cur_interval)
162         udp_ping_calculate_timer_interval ();
163
164       return;
165     }
166
167   /* Delete operation and item not found */
168   if (is_disable)
169     return;
170
171   /* Alloc new session */
172   pool_get_aligned (udp_ping_main.ip46_flow, flow, CLIB_CACHE_LINE_BYTES);
173   udp_ping_populate_flow (src, dst,
174                           start_src_port, end_src_port,
175                           start_dst_port, end_dst_port,
176                           interval, fault_det, flow);
177
178   udp_ping_create_rewrite (flow, (flow - udp_ping_main.ip46_flow));
179
180   if (udp_ping_main.timer_interval > interval)
181     {
182       udp_ping_main.timer_interval = interval;
183       vlib_process_signal_event (udp_ping_main.vlib_main,
184                                  udp_ping_node.index, EVENT_SIG_RECHECK, 0);
185     }
186   return;
187 }
188
189 uword
190 unformat_port_range (unformat_input_t * input, va_list * args)
191 {
192   u16 *start_port, *end_port;
193   uword c;
194   u8 colon_present = 0;
195
196   start_port = va_arg (*args, u16 *);
197   end_port = va_arg (*args, u16 *);
198
199   *start_port = *end_port = 0;
200   /* Get start port */
201   while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
202     {
203       switch (c)
204         {
205         case '0' ... '9':
206           *start_port = ((*start_port) * 10) + (c - '0');
207           break;
208
209         case ':':
210           colon_present = 1;
211           break;
212
213         default:
214           return 0;
215         }
216
217       if (colon_present)
218         break;
219     }
220
221   if (!colon_present)
222     return 0;
223
224   /* Get end port */
225   while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
226     {
227       switch (c)
228         {
229         case '0' ... '9':
230           *end_port = ((*end_port) * 10) + (c - '0');
231           break;
232
233         default:
234           return 1;
235         }
236     }
237
238   if (end_port < start_port)
239     return 0;
240
241   return 1;
242 }
243
244 static clib_error_t *
245 set_udp_ping_command_fn (vlib_main_t * vm,
246                          unformat_input_t * input, vlib_cli_command_t * cmd)
247 {
248   ip46_address_t dst, src;
249   u16 start_src_port, end_src_port;
250   u16 start_dst_port, end_dst_port;
251   u32 interval;
252   u8 is_disable = 0;
253   u8 fault_det = 0;
254
255   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
256     {
257       if (unformat
258           (input, "src %U", unformat_ip46_address, &src, IP46_TYPE_ANY))
259         ;
260       else if (unformat (input, "src-port-range %U",
261                          unformat_port_range, &start_src_port, &end_src_port))
262         ;
263       else
264         if (unformat
265             (input, "dst %U", unformat_ip46_address, &dst, IP46_TYPE_ANY))
266         ;
267       else if (unformat (input, "dst-port-range %U",
268                          unformat_port_range, &start_dst_port, &end_dst_port))
269         ;
270       else if (unformat (input, "interval %d", &interval))
271         ;
272       else if (unformat (input, "fault-detect"))
273         fault_det = 1;
274       else if (unformat (input, "disable"))
275         is_disable = 1;
276       else
277         break;
278     }
279
280   ip46_udp_ping_set_flow (src, dst, start_src_port, end_src_port,
281                           start_dst_port, end_dst_port, (u16) interval,
282                           fault_det, is_disable);
283
284   return 0;
285 }
286
287 /* *INDENT-OFF* */
288 VLIB_CLI_COMMAND (set_udp_ping_command, static) =
289 {
290   .path = "set udp-ping",
291   .short_help =
292       "set udp-ping src <local IPv6 address>  src-port-range <local port range> \
293       dst <remote IPv6 address> dst-port-range <destination port range> \
294       interval <time interval in sec for which ping packet will be sent> \
295       [disable]",
296   .function = set_udp_ping_command_fn,
297 };
298 /* *INDENT-ON* */
299
300 static clib_error_t *
301 show_udp_ping_summary_cmd_fn (vlib_main_t * vm,
302                               unformat_input_t * input,
303                               vlib_cli_command_t * cmd)
304 {
305   u8 *s = 0;
306   int i, j;
307   ip46_udp_ping_flow *ip46_flow;
308   u16 src_port, dst_port;
309   udp_ping_flow_data *stats;
310
311   s = format (s, "UDP-Ping data:\n");
312
313   for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
314     {
315       if (pool_is_free_index (udp_ping_main.ip46_flow, i))
316         continue;
317
318       ip46_flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
319       s = format (s, "Src: %U, Dst: %U\n",
320                   format_ip46_address, &ip46_flow->src, IP46_TYPE_ANY,
321                   format_ip46_address, &ip46_flow->dst, IP46_TYPE_ANY);
322
323       s = format (s, "Start src port: %u, End src port: %u\n",
324                   ip46_flow->udp_data.start_src_port,
325                   ip46_flow->udp_data.end_src_port);
326       s = format (s, "Start dst port: %u, End dst port: %u\n",
327                   ip46_flow->udp_data.start_dst_port,
328                   ip46_flow->udp_data.end_dst_port);
329       s = format (s, "Interval: %u\n", ip46_flow->udp_data.interval);
330
331       j = 0;
332       for (src_port = ip46_flow->udp_data.start_src_port;
333            src_port <= ip46_flow->udp_data.end_src_port; src_port++)
334         {
335           for (dst_port = ip46_flow->udp_data.start_dst_port;
336                dst_port <= ip46_flow->udp_data.end_dst_port; dst_port++)
337             {
338               stats = ip46_flow->udp_data.stats + j;
339               s =
340                 format (s, "\nSrc Port - %u, Dst Port - %u, Flow CTX - %u\n",
341                         src_port, dst_port, stats->flow_ctx);
342               s =
343                 format (s, "Path State - %s\n",
344                         (stats->retry > MAX_PING_RETRIES) ? "Down" : "Up");
345               s = format (s, "Path Data:\n");
346               s = print_analyse_flow (s,
347                                       &ip46_flow->udp_data.
348                                       stats[j].analyse_data);
349               j++;
350             }
351         }
352       s = format (s, "\n\n");
353     }
354
355   vlib_cli_output (vm, "%v", s);
356   vec_free (s);
357   return 0;
358 }
359
360 /* *INDENT-OFF* */
361 VLIB_CLI_COMMAND (show_udp_ping_cmd, static) =
362 {
363   .path = "show udp-ping summary",
364   .short_help = "Summary of udp-ping",
365   .function = show_udp_ping_summary_cmd_fn,
366 };
367 /* *INDENT-ON* */
368
369 /**
370  * @brief UDP-Ping Process node.
371  * @node udp-ping-process
372  *
373  * This is process node which wakes up when periodically to send
374  * out udp probe packets for all configured sessions.
375  *
376  * @param vm    vlib_main_t corresponding to the current thread.
377  * @param node  vlib_node_runtime_t data for this node.
378  * @param frame vlib_frame_t whose contents should be dispatched.
379  *
380  */
381 uword
382 udp_ping_process (vlib_main_t * vm,
383                   vlib_node_runtime_t * rt, vlib_frame_t * f)
384 {
385   f64 now;
386   uword *event_data = 0;
387   int i;
388   ip46_udp_ping_flow *ip46_flow;
389
390   while (1)
391     {
392       vec_reset_length (event_data);
393       vlib_process_wait_for_event_or_clock (vm, udp_ping_main.timer_interval);
394       (void) vlib_process_get_events (vm, &event_data);
395       now = vlib_time_now (vm);
396
397       for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
398         {
399           if (pool_is_free_index (udp_ping_main.ip46_flow, i))
400             continue;
401
402           ip46_flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
403           if (ip46_flow->udp_data.next_send_time < now)
404             udp_ping_send_ip6_pak (udp_ping_main.vlib_main, ip46_flow);
405         }
406     }
407   return 0;
408 }
409
410 /**
411  * @brief HopByHop analyse function for udp-ping response.
412  *
413  * Walks through all hbh options present in udp-ping response
414  * and uses analyser library for the analysis.
415  *
416  */
417 void
418 udp_ping_analyse_hbh (vlib_buffer_t * b0,
419                       u32 flow_id,
420                       u16 src_port,
421                       u16 dst_port,
422                       ip6_hop_by_hop_option_t * opt0,
423                       ip6_hop_by_hop_option_t * limit0, u16 len)
424 {
425   u8 type0;
426   ip46_udp_ping_flow *ip46_flow;
427   u16 flow_index;
428   ioam_analyser_data_t *data;
429   ioam_e2e_option_t *e2e;
430   ioam_trace_option_t *trace;
431
432   /* If the packet doesnt match UDP session then return */
433   if (PREDICT_FALSE (pool_is_free_index (udp_ping_main.ip46_flow, flow_id)))
434     return;
435
436   ip46_flow = udp_ping_main.ip46_flow + flow_id;
437   /* Check port is within range */
438   if (PREDICT_FALSE ((src_port < ip46_flow->udp_data.start_src_port) ||
439                      (src_port > ip46_flow->udp_data.end_src_port) ||
440                      (dst_port < ip46_flow->udp_data.start_dst_port) ||
441                      (dst_port > ip46_flow->udp_data.end_dst_port)))
442     return;
443
444   flow_index = (src_port - ip46_flow->udp_data.start_src_port) *
445     (ip46_flow->udp_data.end_dst_port - ip46_flow->udp_data.start_dst_port +
446      1);
447   flow_index += (dst_port - ip46_flow->udp_data.start_dst_port);
448   data = &(ip46_flow->udp_data.stats[flow_index].analyse_data);
449
450   data->pkt_counter++;
451   data->bytes_counter += len;
452
453   vnet_buffer (b0)->l2_classify.opaque_index =
454     ip46_flow->udp_data.stats[flow_index].flow_ctx;
455
456   while (opt0 < limit0)
457     {
458       type0 = opt0->type;
459       switch (type0)
460         {
461         case HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST:
462           /* Add trace for here as it hasnt been done yet */
463           vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
464           trace = (ioam_trace_option_t *) opt0;
465           if (PREDICT_FALSE
466               (trace->trace_hdr.ioam_trace_type & BIT_LOOPBACK_REPLY))
467             {
468               ip6_ioam_analyse_hbh_trace_loopback (data, &trace->trace_hdr,
469                                                    (trace->hdr.length - 2));
470               return;
471             }
472           ip6_hbh_ioam_trace_data_list_handler (b0,
473                                                 vlib_buffer_get_current (b0),
474                                                 opt0);
475           (void) ip6_ioam_analyse_hbh_trace (data, &trace->trace_hdr, len,
476                                              (trace->hdr.length - 2));
477           break;
478         case HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE:
479           e2e = (ioam_e2e_option_t *) opt0;
480           (void) ip6_ioam_analyse_hbh_e2e (data, &e2e->e2e_hdr, len);
481           break;
482         case 0:         /* Pad1 */
483           opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
484           continue;
485         case 1:         /* PadN */
486           break;
487         default:
488           break;
489         }
490       opt0 = (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
491                                           sizeof (ip6_hop_by_hop_option_t));
492     }
493   ip46_flow->udp_data.stats[flow_index].retry = 0;
494 }
495
496 /**
497  * @brief UDP-Ping request/response handler function.
498  *
499  * Checks udp-ping packet type - request/response and handles them.
500  * If not udp-ping packet then, strips off hbh options and enques
501  * packet to protocol registered node to enable next protocol processing.
502  *
503  */
504 void
505 udp_ping_local_analyse (vlib_buffer_t * b0,
506                         ip6_header_t * ip0,
507                         ip6_hop_by_hop_header_t * hbh0, u16 * next0)
508 {
509   ip6_main_t *im = &ip6_main;
510   ip_lookup_main_t *lm = &im->lookup_main;
511
512   *next0 = UDP_PING_NEXT_IP6_DROP;
513
514   if (PREDICT_TRUE (hbh0->protocol == IP_PROTOCOL_UDP))
515     {
516       ip6_hop_by_hop_option_t *opt0;
517       ip6_hop_by_hop_option_t *limit0;
518       u16 p_len0;
519       udp_ping_t *udp0;
520
521       /* Check for udp ping packet */
522       udp0 = (udp_ping_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
523       opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
524       if ((udp0->ping_data.probe_marker1 ==
525            clib_host_to_net_u32 (UDP_PING_PROBE_MARKER1)) &&
526           (udp0->ping_data.probe_marker2 ==
527            clib_host_to_net_u32 (UDP_PING_PROBE_MARKER2)))
528         {
529           if (udp0->ping_data.msg_type == UDP_PING_PROBE)
530             {
531               udp_ping_create_reply_from_probe_ip6 (ip0, hbh0, udp0);
532               /* Skip e2e processing */
533               vnet_buffer (b0)->l2_classify.opaque_index = 0x7FFFFFFF;
534               *next0 = UDP_PING_NEXT_IP6_LOOKUP;
535               return;
536             }
537
538           /* Reply */
539           opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
540           limit0 = (ip6_hop_by_hop_option_t *)
541             ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
542           p_len0 = clib_net_to_host_u16 (ip0->payload_length);
543           udp_ping_analyse_hbh (b0,
544                                 clib_net_to_host_u16 (udp0->
545                                                       ping_data.sender_handle),
546                                 clib_net_to_host_u16 (udp0->udp.dst_port),
547                                 clib_net_to_host_u16 (udp0->udp.src_port),
548                                 opt0, limit0, p_len0);
549
550           /* UDP Ping packet, so return */
551           return;
552         }
553     }
554
555   /* If next header is SR, then destination may get overwritten to
556    * remote address. So pass it to SR processing as it may be local packet
557    * afterall
558    */
559   if (PREDICT_FALSE (hbh0->protocol == IPPROTO_IPV6_ROUTE))
560     goto end;
561
562   /* Other case remove hbh-ioam headers */
563   u64 *copy_dst0, *copy_src0;
564   u16 new_l0;
565
566   vlib_buffer_advance (b0, (hbh0->length + 1) << 3);
567
568   new_l0 = clib_net_to_host_u16 (ip0->payload_length) -
569     ((hbh0->length + 1) << 3);
570
571   ip0->payload_length = clib_host_to_net_u16 (new_l0);
572
573   ip0->protocol = hbh0->protocol;
574
575   copy_src0 = (u64 *) ip0;
576   copy_dst0 = copy_src0 + (hbh0->length + 1);
577   copy_dst0[4] = copy_src0[4];
578   copy_dst0[3] = copy_src0[3];
579   copy_dst0[2] = copy_src0[2];
580   copy_dst0[1] = copy_src0[1];
581   copy_dst0[0] = copy_src0[0];
582
583 end:
584   *next0 = lm->local_next_by_ip_protocol[hbh0->protocol];
585   return;
586 }
587
588 /**
589  * @brief udp ping request/response packet receive node.
590  * @node udp-ping-local
591  *
592  * This function receives udp ping request/response packets and process them.
593  * For request packets, response is created and sent.
594  * For response packets, they are analysed and results stored.
595  *
596  * @param vm    vlib_main_t corresponding to the current thread.
597  * @param node  vlib_node_runtime_t data for this node.
598  * @param frame vlib_frame_t whose contents should be dispatched.
599  *
600  * @par Graph mechanics: buffer, next index usage
601  *
602  * <em>Uses:</em>
603  * - <code>udp_ping_local_analyse(p0, ip0, hbh0, &next0)</code>
604  *     - Checks packet type - request/respnse and process them.
605  *
606  * <em>Next Index:</em>
607  * - Dispatches the packet to ip6-lookup/ip6-drop depending on type of packet.
608  */
609 static uword
610 udp_ping_local_node_fn (vlib_main_t * vm,
611                         vlib_node_runtime_t * node, vlib_frame_t * frame)
612 {
613   udp_ping_next_t next_index;
614   u32 *from, *to_next, n_left_from, n_left_to_next;
615
616   from = vlib_frame_vector_args (frame);
617   n_left_from = frame->n_vectors;
618   next_index = node->cached_next_index;
619
620   while (n_left_from > 0)
621     {
622       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
623
624       while (n_left_from >= 4 && n_left_to_next >= 2)
625         {
626           vlib_buffer_t *p0, *p1;
627           ip6_header_t *ip0, *ip1;
628           ip6_hop_by_hop_header_t *hbh0, *hbh1;
629           u16 next0, next1;
630           u32 pi0, pi1;
631
632           /* Prefetch next iteration. */
633           {
634             vlib_buffer_t *p2, *p3;
635
636             p2 = vlib_get_buffer (vm, from[2]);
637             p3 = vlib_get_buffer (vm, from[3]);
638
639             vlib_prefetch_buffer_header (p2, LOAD);
640             vlib_prefetch_buffer_header (p3, LOAD);
641
642             /* Prefetch 3 cache lines as we need to look deep into packet */
643             CLIB_PREFETCH (p2->data, 3 * CLIB_CACHE_LINE_BYTES, STORE);
644             CLIB_PREFETCH (p3->data, 3 * CLIB_CACHE_LINE_BYTES, STORE);
645           }
646
647           pi0 = to_next[0] = from[0];
648           pi1 = to_next[1] = from[1];
649           from += 2;
650           n_left_from -= 2;
651           to_next += 2;
652           n_left_to_next -= 2;
653
654           p0 = vlib_get_buffer (vm, pi0);
655           p1 = vlib_get_buffer (vm, pi1);
656
657           ip0 = vlib_buffer_get_current (p0);
658           ip1 = vlib_buffer_get_current (p1);
659
660           hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
661           hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
662
663           udp_ping_local_analyse (p0, ip0, hbh0, &next0);
664           udp_ping_local_analyse (p1, ip1, hbh1, &next1);
665
666           if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
667             {
668               if (p0->flags & VLIB_BUFFER_IS_TRACED)
669                 {
670                   udp_ping_trace_t *t0 =
671                     vlib_add_trace (vm, node, p0, sizeof (*t0));
672                   udp_ping_t *udp0;
673
674                   /* Check for udp ping packet */
675                   udp0 =
676                     (udp_ping_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
677                   t0->src = ip0->src_address;
678                   t0->dst = ip0->dst_address;
679                   t0->src_port = clib_net_to_host_u16 (udp0->udp.src_port);
680                   t0->dst_port = clib_net_to_host_u16 (udp0->udp.dst_port);
681                   t0->handle =
682                     clib_net_to_host_u16 (udp0->ping_data.sender_handle);
683                   t0->msg_type = udp0->ping_data.msg_type;
684                   t0->next_index = next0;
685                 }
686               if (p1->flags & VLIB_BUFFER_IS_TRACED)
687                 {
688                   udp_ping_trace_t *t1 =
689                     vlib_add_trace (vm, node, p1, sizeof (*t1));
690                   udp_ping_t *udp1;
691
692                   /* Check for udp ping packet */
693                   udp1 =
694                     (udp_ping_t *) ((u8 *) hbh1 + ((hbh1->length + 1) << 3));
695                   t1->src = ip1->src_address;
696                   t1->dst = ip1->dst_address;
697                   t1->src_port = clib_net_to_host_u16 (udp1->udp.src_port);
698                   t1->dst_port = clib_net_to_host_u16 (udp1->udp.dst_port);
699                   t1->handle =
700                     clib_net_to_host_u16 (udp1->ping_data.sender_handle);
701                   t1->msg_type = udp1->ping_data.msg_type;
702                   t1->next_index = next1;
703                 }
704             }
705
706           vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
707                                            to_next, n_left_to_next,
708                                            pi0, pi1, next0, next1);
709         }
710
711       while (n_left_from > 0 && n_left_to_next > 0)
712         {
713           vlib_buffer_t *p0;
714           ip6_header_t *ip0;
715           ip6_hop_by_hop_header_t *hbh0;
716           u16 next0;
717           u32 pi0;
718
719           pi0 = from[0];
720           to_next[0] = pi0;
721           from += 1;
722           to_next += 1;
723           n_left_from -= 1;
724           n_left_to_next -= 1;
725
726           p0 = vlib_get_buffer (vm, pi0);
727           ip0 = vlib_buffer_get_current (p0);
728           hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
729
730           udp_ping_local_analyse (p0, ip0, hbh0, &next0);
731
732           if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
733             {
734               if (p0->flags & VLIB_BUFFER_IS_TRACED)
735                 {
736                   udp_ping_trace_t *t0 =
737                     vlib_add_trace (vm, node, p0, sizeof (*t0));
738                   udp_ping_t *udp0;
739
740                   /* Check for udp ping packet */
741                   udp0 =
742                     (udp_ping_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
743                   t0->src = ip0->src_address;
744                   t0->dst = ip0->dst_address;
745                   t0->src_port = clib_net_to_host_u16 (udp0->udp.src_port);
746                   t0->dst_port = clib_net_to_host_u16 (udp0->udp.dst_port);
747                   t0->handle =
748                     clib_net_to_host_u16 (udp0->ping_data.sender_handle);
749                   t0->msg_type = udp0->ping_data.msg_type;
750                   t0->next_index = next0;
751                 }
752             }
753
754           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
755                                            to_next, n_left_to_next,
756                                            pi0, next0);
757         }
758
759       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
760     }
761
762   return frame->n_vectors;
763 }
764
765 /* *INDENT-OFF* */
766 /*
767  * Node for udp-ping-local
768  */
769 VLIB_REGISTER_NODE (udp_ping_local, static) =
770 {
771   .function = udp_ping_local_node_fn,
772   .name = "udp-ping-local",
773   .vector_size = sizeof (u32),
774   .format_trace = format_udp_ping_trace,
775   .type = VLIB_NODE_TYPE_INTERNAL,
776   .n_next_nodes = UDP_PING_N_NEXT,
777   .next_nodes =
778     {
779       [UDP_PING_NEXT_DROP] = "error-drop",
780       [UDP_PING_NEXT_PUNT] = "error-punt",
781       [UDP_PING_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
782       [UDP_PING_NEXT_ICMP] = "ip6-icmp-input",
783       [UDP_PING_NEXT_IP6_LOOKUP] = "ip6-lookup",
784       [UDP_PING_NEXT_IP6_DROP] = "ip6-drop",
785     },
786 };
787 /* *INDENT-ON* */
788
789 static clib_error_t *
790 udp_ping_init (vlib_main_t * vm)
791 {
792   clib_error_t *error = 0;
793
794   udp_ping_main.vlib_main = vm;
795   udp_ping_main.vnet_main = vnet_get_main ();
796   udp_ping_main.timer_interval = 1e9;
797
798   if ((error = vlib_call_init_function (vm, ip_main_init)))
799     return (error);
800
801   ip6_register_protocol (IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS,
802                          udp_ping_local.index);
803   return 0;
804 }
805
806 VLIB_INIT_FUNCTION (udp_ping_init);
807
808 /*
809  * fd.io coding-style-patch-verification: ON
810  *
811  * Local Variables:
812  * eval: (c-set-style "gnu")
813  * End:
814  */