Augment Vxlan to support NSH-Proxy
[vpp.git] / vnet / vnet / pg / output.c
index cc098da..3d1f266 100644 (file)
  */
 
 #include <vlib/vlib.h>
+#include <vnet/vnet.h>
 #include <vnet/pg/pg.h>
+#include <vnet/ethernet/ethernet.h>
 
 uword
-pg_output (vlib_main_t * vm,
-          vlib_node_runtime_t * node,
-          vlib_frame_t * frame)
+pg_output (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
 {
-  u32 * buffers = vlib_frame_args (frame);
+  pg_main_t *pg = &pg_main;
+  u32 *buffers = vlib_frame_args (frame);
   uword n_buffers = frame->n_vectors;
-  vlib_buffer_free_no_next (vm, buffers, n_buffers);
+  uword n_left = n_buffers;
+  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
+  pg_interface_t *pif = pool_elt_at_index (pg->interfaces, rd->dev_instance);
+
+  if (PREDICT_FALSE (pif->lockp != 0))
+    while (__sync_lock_test_and_set (pif->lockp, 1))
+      ;
+
+  if (pif->pcap_file_name != 0)
+    {
+      while (n_left > 0)
+       {
+         n_left--;
+         u32 bi0 = buffers[0];
+         buffers++;
+
+         pcap_add_buffer (&pif->pcap_main, vm, bi0,
+                          ETHERNET_MAX_PACKET_BYTES);
+       }
+      pcap_write (&pif->pcap_main);
+    }
+
+  vlib_buffer_free (vm, vlib_frame_args (frame), n_buffers);
+  if (PREDICT_FALSE (pif->lockp != 0))
+    *pif->lockp = 0;
   return n_buffers;
 }
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */