vnet: distinguish between max_frame_size and MTU
[vpp.git] / src / vnet / devices / af_packet / af_packet.c
index 4c52cf1..2085379 100644 (file)
@@ -56,31 +56,28 @@ unsigned int if_nametoindex (const char *ifname);
 
 typedef struct tpacket_req tpacket_req_t;
 
-static u32
-af_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
-                          u32 flags)
+static clib_error_t *
+af_packet_eth_set_max_frame_size (vnet_main_t *vnm, vnet_hw_interface_t *hi,
+                                 u32 frame_size)
 {
-  clib_error_t *error;
+  clib_error_t *error, *rv;
   af_packet_main_t *apm = &af_packet_main;
-  af_packet_if_t *apif =
-    pool_elt_at_index (apm->interfaces, hi->dev_instance);
+  af_packet_if_t *apif = pool_elt_at_index (apm->interfaces, hi->dev_instance);
 
-  if (flags == ETHERNET_INTERFACE_FLAG_MTU)
-    {
-      error =
-       vnet_netlink_set_link_mtu (apif->host_if_index, hi->max_packet_bytes);
+  error = vnet_netlink_set_link_mtu (apif->host_if_index,
+                                    frame_size + hi->frame_overhead);
 
-      if (error)
-       {
-         vlib_log_err (apm->log_class, "netlink failed to change MTU: %U",
-                       format_clib_error, error);
-         clib_error_free (error);
-         return VNET_API_ERROR_SYSCALL_ERROR_1;
-       }
-      else
-       apif->host_mtu = hi->max_packet_bytes;
+  if (error)
+    {
+      vlib_log_err (apm->log_class, "netlink failed to change MTU: %U",
+                   format_clib_error, error);
+      rv = vnet_error (VNET_ERR_SYSCALL_ERROR_1, "netlink error: %U",
+                      format_clib_error, error);
+      clib_error_free (error);
+      return rv;
     }
-
+  else
+    apif->host_mtu = frame_size + hi->frame_overhead;
   return 0;
 }
 
@@ -253,7 +250,6 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
   af_packet_if_t *apif = 0;
   u8 hw_addr[6];
   vnet_sw_interface_t *sw;
-  vnet_hw_interface_t *hw;
   vlib_thread_main_t *tm = vlib_get_thread_main ();
   vnet_main_t *vnm = vnet_get_main ();
   uword *p;
@@ -404,7 +400,7 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
       eir.dev_class_index = af_packet_device_class.index;
       eir.dev_instance = if_index;
       eir.address = hw_addr;
-      eir.cb.flag_change = af_packet_eth_flag_change;
+      eir.cb.set_max_frame_size = af_packet_eth_set_max_frame_size;
       apif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
     }
   else
@@ -414,14 +410,13 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
        af_packet_ip_device_hw_interface_class.index, if_index);
     }
   sw = vnet_get_hw_sw_interface (vnm, apif->hw_if_index);
-  hw = vnet_get_hw_interface (vnm, apif->hw_if_index);
   apif->sw_if_index = sw->sw_if_index;
   vnet_hw_if_set_input_node (vnm, apif->hw_if_index,
                             af_packet_input_node.index);
   apif->queue_index = vnet_hw_if_register_rx_queue (vnm, apif->hw_if_index, 0,
                                                    VNET_HW_IF_RXQ_THREAD_ANY);
 
-  hw->caps |= VNET_HW_IF_CAP_INT_MODE;
+  vnet_hw_if_set_caps (vnm, apif->hw_if_index, VNET_HW_IF_CAP_INT_MODE);
   vnet_hw_interface_set_flags (vnm, apif->hw_if_index,
                               VNET_HW_INTERFACE_FLAG_LINK_UP);
 
@@ -527,20 +522,18 @@ af_packet_set_l4_cksum_offload (u32 sw_if_index, u8 set)
 {
   vnet_main_t *vnm = vnet_get_main ();
   vnet_hw_interface_t *hw;
-
+  vnet_hw_if_caps_t caps =
+    VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM;
   hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
 
   if (hw->dev_class_index != af_packet_device_class.index)
     return VNET_API_ERROR_INVALID_INTERFACE;
 
   if (set)
-    {
-      hw->caps &= ~(VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM);
-    }
+    vnet_hw_if_set_caps (vnm, hw->hw_if_index, caps);
   else
-    {
-      hw->caps |= (VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM);
-    }
+    vnet_hw_if_unset_caps (vnm, hw->hw_if_index, caps);
+
   return 0;
 }