Implement ip_probe_neighbor API
[vpp.git] / src / vnet / devices / af_packet / af_packet.c
index d0a241e..46bb42a 100644 (file)
@@ -144,6 +144,18 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req,
       goto error;
     }
 
+  /* bind before rx ring is cfged so we don't receive packets from other interfaces */
+  memset (&sll, 0, sizeof (sll));
+  sll.sll_family = PF_PACKET;
+  sll.sll_protocol = htons (ETH_P_ALL);
+  sll.sll_ifindex = host_if_index;
+  if ((err = bind (*fd, (struct sockaddr *) &sll, sizeof (sll))) < 0)
+    {
+      DBG_SOCK ("Failed to bind rx packet socket (error %d)", err);
+      ret = VNET_API_ERROR_SYSCALL_ERROR_1;
+      goto error;
+    }
+
   if ((err =
        setsockopt (*fd, SOL_PACKET, PACKET_VERSION, &ver, sizeof (ver))) < 0)
     {
@@ -172,7 +184,7 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req,
   if ((err =
        setsockopt (*fd, SOL_PACKET, PACKET_TX_RING, tx_req, req_sz)) < 0)
     {
-      DBG_SOCK ("Failed to set packet rx ring options");
+      DBG_SOCK ("Failed to set packet tx ring options");
       ret = VNET_API_ERROR_SYSCALL_ERROR_1;
       goto error;
     }
@@ -187,18 +199,6 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req,
       goto error;
     }
 
-  memset (&sll, 0, sizeof (sll));
-  sll.sll_family = PF_PACKET;
-  sll.sll_protocol = htons (ETH_P_ALL);
-  sll.sll_ifindex = host_if_index;
-
-  if ((err = bind (*fd, (struct sockaddr *) &sll, sizeof (sll))) < 0)
-    {
-      DBG_SOCK ("Failed to bind rx packet socket (error %d)", err);
-      ret = VNET_API_ERROR_SYSCALL_ERROR_1;
-      goto error;
-    }
-
   return 0;
 error:
   if (*fd >= 0)
@@ -231,7 +231,9 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
   p = mhash_get (&apm->if_index_by_host_if_name, host_if_name);
   if (p)
     {
-      return VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
+      apif = vec_elt_at_index (apm->interfaces, p[0]);
+      *sw_if_index = apif->sw_if_index;
+      return VNET_API_ERROR_IF_ALREADY_EXISTS;
     }
 
   vec_validate (rx_req, 0);
@@ -288,6 +290,8 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
     template.file_descriptor = fd;
     template.private_data = if_index;
     template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED;
+    template.description = format (0, "%U", format_af_packet_device_name,
+                                  if_index);
     apif->clib_file_index = clib_file_add (&file_main, &template);
   }
 
@@ -416,6 +420,9 @@ af_packet_set_l4_cksum_offload (vlib_main_t * vm, u32 sw_if_index, u8 set)
 
   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->flags &= ~VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
   else