tap_v2: include host-side parameters in the dump binary API

Change-Id: I097a738b96a304621520f1842dcac7dbf61a8e3f
Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c
index 4f76321..ff7bd91 100644
--- a/src/vnet/devices/tap/tap.c
+++ b/src/vnet/devices/tap/tap.c
@@ -335,10 +335,22 @@
       args->mac_addr[0] = 2;
       args->mac_addr[1] = 0xfe;
     }
+  vif->rx_ring_sz = args->rx_ring_sz != 0 ? args->rx_ring_sz : 256;
+  vif->tx_ring_sz = args->tx_ring_sz != 0 ? args->tx_ring_sz : 256;
   vif->host_if_name = args->host_if_name;
   args->host_if_name = 0;
   vif->net_ns = args->host_namespace;
   args->host_namespace = 0;
+  vif->host_bridge = args->host_bridge;
+  args->host_bridge = 0;
+  clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6);
+  vif->host_ip4_prefix_len = args->host_ip4_prefix_len;
+  vif->host_ip6_prefix_len = args->host_ip6_prefix_len;
+  if (args->host_ip4_prefix_len)
+    clib_memcpy (&vif->host_ip4_addr, &args->host_ip4_addr, 4);
+  if (args->host_ip6_prefix_len)
+    clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16);
+
   args->error = ethernet_register_interface (vnm, virtio_device_class.index,
 					     vif->dev_instance,
 					     args->mac_addr,
@@ -441,11 +453,39 @@
   pool_foreach (vif, mm->interfaces,
     vec_add2(r_tapids, tapid, 1);
     memset (tapid, 0, sizeof (*tapid));
+    tapid->id = vif->id;
     tapid->sw_if_index = vif->sw_if_index;
     hi = vnet_get_hw_interface (vnm, vif->hw_if_index);
     clib_memcpy(tapid->dev_name, hi->name,
-		MIN (ARRAY_LEN (tapid->dev_name) - 1,
-		     strlen ((const char *) hi->name)));
+                MIN (ARRAY_LEN (tapid->dev_name) - 1,
+                     strlen ((const char *) hi->name)));
+    tapid->rx_ring_sz = vif->rx_ring_sz;
+    tapid->tx_ring_sz = vif->tx_ring_sz;
+    clib_memcpy(tapid->host_mac_addr, vif->host_mac_addr, 6);
+    if (vif->host_if_name)
+      {
+        clib_memcpy(tapid->host_if_name, vif->host_if_name,
+                    MIN (ARRAY_LEN (tapid->host_if_name) - 1,
+                    strlen ((const char *) vif->host_if_name)));
+      }
+    if (vif->net_ns)
+      {
+        clib_memcpy(tapid->host_namespace, vif->net_ns,
+                    MIN (ARRAY_LEN (tapid->host_namespace) - 1,
+                    strlen ((const char *) vif->net_ns)));
+      }
+    if (vif->host_bridge)
+      {
+        clib_memcpy(tapid->host_bridge, vif->host_bridge,
+                    MIN (ARRAY_LEN (tapid->host_bridge) - 1,
+                    strlen ((const char *) vif->host_bridge)));
+      }
+    if (vif->host_ip4_prefix_len)
+      clib_memcpy(tapid->host_ip4_addr, &vif->host_ip4_addr, 4);
+    tapid->host_ip4_prefix_len = vif->host_ip4_prefix_len;
+    if (vif->host_ip6_prefix_len)
+      clib_memcpy(tapid->host_ip6_addr, &vif->host_ip6_addr, 16);
+    tapid->host_ip6_prefix_len = vif->host_ip6_prefix_len;
   );
   /* *INDENT-ON* */
 
diff --git a/src/vnet/devices/tap/tap.h b/src/vnet/devices/tap/tap.h
index 7d07ffb..35f7a01 100644
--- a/src/vnet/devices/tap/tap.h
+++ b/src/vnet/devices/tap/tap.h
@@ -34,9 +34,9 @@
   u8 host_mac_addr[6];
   u8 *host_bridge;
   ip4_address_t host_ip4_addr;
-  u32 host_ip4_prefix_len;
+  u8 host_ip4_prefix_len;
   ip6_address_t host_ip6_addr;
-  u32 host_ip6_prefix_len;
+  u8 host_ip6_prefix_len;
   /* return */
   u32 sw_if_index;
   int rv;
@@ -46,8 +46,19 @@
 /** TAP interface details struct */
 typedef struct
 {
+  u32 id;
   u32 sw_if_index;
   u8 dev_name[64];
+  u16 tx_ring_sz;
+  u16 rx_ring_sz;
+  u8 host_mac_addr[6];
+  u8 host_if_name[64];
+  u8 host_namespace[64];
+  u8 host_bridge[64];
+  u8 host_ip4_addr[4];
+  u8 host_ip4_prefix_len;
+  u8 host_ip6_addr[16];
+  u8 host_ip6_prefix_len;
 } tap_interface_details_t;
 
 typedef struct
diff --git a/src/vnet/devices/tap/tapv2.api b/src/vnet/devices/tap/tapv2.api
index a206269..1f0051e 100644
--- a/src/vnet/devices/tap/tapv2.api
+++ b/src/vnet/devices/tap/tapv2.api
@@ -102,13 +102,35 @@
 
 /** \brief Reply for tap dump request
     @param sw_if_index - software index of tap interface
+    @param id - interface id
     @param dev_name - Linux tap device name
+    @param tx_ring_sz - the number of entries of TX ring
+    @param rx_ring_sz - the number of entries of RX ring
+    @param host_mac_addr - mac address assigned to the host side of the interface
+    @param host_if_name - host side interface name
+    @param host_namespace - host namespace the interface is attached into
+    @param host_bridge - host bridge the interface is attached into
+    @param host_ip4_addr - host IPv4 ip address
+    @param host_ip4_prefix_len - host IPv4 ip address prefix length; 0 if unset
+    @param host_ip6_addr - host IPv6 ip address
+    @param host_ip6_prefix_len - host IPv6 ip address prefix length; 0 if unset
 */
 define sw_interface_tap_v2_details
 {
   u32 context;
   u32 sw_if_index;
+  u32 id;
   u8 dev_name[64];
+  u16 tx_ring_sz;
+  u16 rx_ring_sz;
+  u8 host_mac_addr[6];
+  u8 host_if_name[64];
+  u8 host_namespace[64];
+  u8 host_bridge[64];
+  u8 host_ip4_addr[4];
+  u8 host_ip4_prefix_len;
+  u8 host_ip6_addr[16];
+  u8 host_ip6_prefix_len;
 };
 
 /*
diff --git a/src/vnet/devices/tap/tapv2_api.c b/src/vnet/devices/tap/tapv2_api.c
index 3cededb..841d21e 100644
--- a/src/vnet/devices/tap/tapv2_api.c
+++ b/src/vnet/devices/tap/tapv2_api.c
@@ -164,13 +164,32 @@
   vl_api_sw_interface_tap_v2_details_t *mp;
   mp = vl_msg_api_alloc (sizeof (*mp));
   memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_V2_DETAILS);
-  mp->sw_if_index = ntohl (tap_if->sw_if_index);
+  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_TAP_V2_DETAILS);
+  mp->id = htonl (tap_if->id);
+  mp->sw_if_index = htonl (tap_if->sw_if_index);
   clib_memcpy (mp->dev_name, tap_if->dev_name,
 	       MIN (ARRAY_LEN (mp->dev_name) - 1,
 		    strlen ((const char *) tap_if->dev_name)));
-  mp->context = context;
+  mp->rx_ring_sz = htons (tap_if->rx_ring_sz);
+  mp->tx_ring_sz = htons (tap_if->tx_ring_sz);
+  clib_memcpy (mp->host_mac_addr, tap_if->host_mac_addr, 6);
+  clib_memcpy (mp->host_if_name, tap_if->host_if_name,
+	       MIN (ARRAY_LEN (mp->host_if_name) - 1,
+		    strlen ((const char *) tap_if->host_if_name)));
+  clib_memcpy (mp->host_namespace, tap_if->host_namespace,
+	       MIN (ARRAY_LEN (mp->host_namespace) - 1,
+		    strlen ((const char *) tap_if->host_namespace)));
+  clib_memcpy (mp->host_bridge, tap_if->host_bridge,
+	       MIN (ARRAY_LEN (mp->host_bridge) - 1,
+		    strlen ((const char *) tap_if->host_bridge)));
+  if (tap_if->host_ip4_prefix_len)
+    clib_memcpy (&mp->host_ip4_addr, &tap_if->host_ip4_addr, 4);
+  mp->host_ip4_prefix_len = tap_if->host_ip4_prefix_len;
+  if (tap_if->host_ip6_prefix_len)
+    clib_memcpy (&mp->host_ip6_addr, &tap_if->host_ip6_addr, 16);
+  mp->host_ip6_prefix_len = tap_if->host_ip6_prefix_len;
 
+  mp->context = context;
   vl_msg_api_send_shmem (q, (u8 *) & mp);
 }
 
diff --git a/src/vnet/devices/virtio/device.c b/src/vnet/devices/virtio/device.c
index d4ef6d8..df5fcf5 100644
--- a/src/vnet/devices/virtio/device.c
+++ b/src/vnet/devices/virtio/device.c
@@ -24,6 +24,8 @@
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
 #include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
 #include <vnet/devices/virtio/virtio.h>
 
 #define foreach_virtio_tx_func_error	       \
diff --git a/src/vnet/devices/virtio/node.c b/src/vnet/devices/virtio/node.c
index f746ada..5ca0636 100644
--- a/src/vnet/devices/virtio/node.c
+++ b/src/vnet/devices/virtio/node.c
@@ -30,6 +30,8 @@
 #include <vnet/ethernet/ethernet.h>
 #include <vnet/devices/devices.h>
 #include <vnet/feature/feature.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
 #include <vnet/devices/virtio/virtio.h>
 
 
diff --git a/src/vnet/devices/virtio/virtio.c b/src/vnet/devices/virtio/virtio.c
index 7418673..7829da6 100644
--- a/src/vnet/devices/virtio/virtio.c
+++ b/src/vnet/devices/virtio/virtio.c
@@ -28,6 +28,8 @@
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
 #include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
 #include <vnet/devices/virtio/virtio.h>
 
 virtio_main_t virtio_main;
diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h
index cb97df8..079223d 100644
--- a/src/vnet/devices/virtio/virtio.h
+++ b/src/vnet/devices/virtio/virtio.h
@@ -103,8 +103,17 @@
   u64 features, remote_features;
 
   virtio_if_type_t type;
+  u16 tx_ring_sz;
+  u16 rx_ring_sz;
   u8 *host_if_name;
   u8 *net_ns;
+  u8 *host_bridge;
+  u8 host_mac_addr[6];
+  ip4_address_t host_ip4_addr;
+  u8 host_ip4_prefix_len;
+  ip6_address_t host_ip6_addr;
+  u8 host_ip6_prefix_len;
+
   int ifindex;
 } virtio_if_t;