Proxy ND (RFC4389 - or a sub-set thereof). This allows the 'emulation' of bridging...
[vpp.git] / src / vnet / ip / ping.c
index 8888262..e4f2ee7 100644 (file)
@@ -13,6 +13,7 @@
  * limitations under the License.
  */
 
+#include <stddef.h>
 #include <vnet/ip/ping.h>
 #include <vnet/fib/ip6_fib.h>
 #include <vnet/fib/ip4_fib.h>
@@ -213,27 +214,6 @@ VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node, static) =
 char *ip6_lookup_next_nodes[] = IP6_LOOKUP_NEXT_NODES;
 char *ip4_lookup_next_nodes[] = IP4_LOOKUP_NEXT_NODES;
 
-/* get first interface address */
-static ip6_address_t *
-ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
-{
-  ip_lookup_main_t *lm = &im->lookup_main;
-  ip_interface_address_t *ia = 0;
-  ip6_address_t *result = 0;
-
-  /* *INDENT-OFF* */
-  foreach_ip_interface_address (lm, ia, sw_if_index,
-                                1 /* honor unnumbered */ ,
-  ({
-    ip6_address_t * a =
-      ip_interface_address_get_address (lm, ia);
-    result = a;
-    break;
-  }));
-  /* *INDENT-ON* */
-  return result;
-}
-
 /* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
 static u16
 init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
@@ -243,15 +223,10 @@ init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
   icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
   icmp46_echo->id = clib_host_to_net_u16 (id_host);
 
-  for (i = 0; i < sizeof (icmp46_echo->data); i++)
-    {
-      icmp46_echo->data[i] = i % 256;
-    }
-
-  if (data_len > sizeof (icmp46_echo_request_t))
-    {
-      data_len = sizeof (icmp46_echo_request_t);
-    }
+  if (data_len > PING_MAXIMUM_DATA_SIZE)
+    data_len = PING_MAXIMUM_DATA_SIZE;
+  for (i = 0; i < data_len; i++)
+    icmp46_echo->data[i] = i % 256;
   return data_len;
 }
 
@@ -267,11 +242,15 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
   vlib_buffer_t *p0;
   vlib_frame_t *f;
   u32 *to_next;
+  vlib_buffer_free_list_t *fl;
 
   if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
     return SEND_PING_ALLOC_FAIL;
 
   p0 = vlib_get_buffer (vm, bi0);
+  fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+  vlib_buffer_init_for_free_list (p0, fl);
+  VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
 
   /*
    * if the user did not provide a source interface, use the any interface
@@ -376,11 +355,15 @@ send_ip4_ping (vlib_main_t * vm,
   vlib_frame_t *f;
   u32 *to_next;
   u32 if_add_index0;
+  vlib_buffer_free_list_t *fl;
 
   if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
     return SEND_PING_ALLOC_FAIL;
 
   p0 = vlib_get_buffer (vm, bi0);
+  fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+  vlib_buffer_init_for_free_list (p0, fl);
+  VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
 
   /*
    * if the user did not provide a source interface, use the any interface
@@ -759,6 +742,14 @@ ping_ip_address (vlib_main_t * vm,
                                   format_unformat_error, input);
              goto done;
            }
+         if (data_len > PING_MAXIMUM_DATA_SIZE)
+           {
+             error =
+               clib_error_return (0,
+                                  "%d is bigger than maximum allowed payload size %d",
+                                  data_len, PING_MAXIMUM_DATA_SIZE);
+             goto done;
+           }
        }
       else if (unformat (input, "table-id"))
        {