tap_v2: include host-side parameters in the dump binary API 39/9839/3
authorMilan Lenco <milan.lenco@pantheon.tech>
Thu, 14 Dec 2017 09:04:25 +0000 (10:04 +0100)
committerDamjan Marion <dmarion.lists@gmail.com>
Thu, 14 Dec 2017 11:08:49 +0000 (11:08 +0000)
Change-Id: I097a738b96a304621520f1842dcac7dbf61a8e3f
Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
src/vat/api_format.c
src/vnet/devices/tap/tap.c
src/vnet/devices/tap/tap.h
src/vnet/devices/tap/tapv2.api
src/vnet/devices/tap/tapv2_api.c
src/vnet/devices/virtio/device.c
src/vnet/devices/virtio/node.c
src/vnet/devices/virtio/virtio.c
src/vnet/devices/virtio/virtio.h

index e8d6bd5..445b496 100644 (file)
@@ -12439,8 +12439,20 @@ static void vl_api_sw_interface_tap_v2_details_t_handler
 {
   vat_main_t *vam = &vat_main;
 
-  print (vam->ofp, "%-16s %d",
-        mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
+  u8 *ip4 = format (0, "%U/%d", format_ip4_address, mp->host_ip4_addr,
+                   mp->host_ip4_prefix_len);
+  u8 *ip6 = format (0, "%U/%d", format_ip6_address, mp->host_ip6_addr,
+                   mp->host_ip6_prefix_len);
+
+  print (vam->ofp,
+        "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s",
+        mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
+        ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
+        format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
+        mp->host_bridge, ip4, ip6);
+
+  vec_free (ip4);
+  vec_free (ip6);
 }
 
 static void vl_api_sw_interface_tap_v2_details_t_handler_json
@@ -12457,8 +12469,26 @@ static void vl_api_sw_interface_tap_v2_details_t_handler_json
   node = vat_json_array_add (&vam->json_tree);
 
   vat_json_init_object (node);
+  vat_json_object_add_uint (node, "id", ntohl (mp->id));
   vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
   vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
+  vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
+  vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
+  vat_json_object_add_string_copy (node, "host_mac_addr",
+                                  format (0, "%U", format_ethernet_address,
+                                          &mp->host_mac_addr));
+  vat_json_object_add_string_copy (node, "host_namespace",
+                                  mp->host_namespace);
+  vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
+  vat_json_object_add_string_copy (node, "host_ip4_addr",
+                                  format (0, "%U/%d", format_ip4_address,
+                                          mp->host_ip4_addr,
+                                          mp->host_ip4_prefix_len));
+  vat_json_object_add_string_copy (node, "host_ip6_addr",
+                                  format (0, "%U/%d", format_ip6_address,
+                                          mp->host_ip6_addr,
+                                          mp->host_ip6_prefix_len));
+
 }
 
 static int
@@ -12468,7 +12498,12 @@ api_sw_interface_tap_v2_dump (vat_main_t * vam)
   vl_api_control_ping_t *mp_ping;
   int ret;
 
-  print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
+  print (vam->ofp,
+        "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
+        "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
+        "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
+        "host_ip6_addr");
+
   /* Get list of tap interfaces */
   M (SW_INTERFACE_TAP_V2_DUMP, mp);
   S (mp);
index 4f76321..ff7bd91 100644 (file)
@@ -335,10 +335,22 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
       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 @@ tap_dump_ifs (tap_interface_details_t ** out_tapids)
   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* */
 
index 7d07ffb..35f7a01 100644 (file)
@@ -34,9 +34,9 @@ typedef struct
   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 @@ typedef struct
 /** 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
index a206269..1f0051e 100644 (file)
@@ -102,13 +102,35 @@ define sw_interface_tap_v2_dump
 
 /** \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;
 };
 
 /*
index 3cededb..841d21e 100644 (file)
@@ -164,13 +164,32 @@ tap_send_sw_interface_details (vpe_api_main_t * am,
   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);
 }
 
index d4ef6d8..df5fcf5 100644 (file)
@@ -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          \
index f746ada..5ca0636 100644 (file)
@@ -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>
 
 
index 7418673..7829da6 100644 (file)
@@ -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;
index cb97df8..079223d 100644 (file)
@@ -103,8 +103,17 @@ typedef struct
   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;