aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChaoyu Jin <chjin@cisco.com>2018-03-13 07:37:41 -0700
committerDamjan Marion <dmarion.lists@gmail.com>2018-03-14 07:49:39 +0000
commitafb193019192a296e96c1008fdb788f70f5150d6 (patch)
treee2bd7ed650feb7f4496694164629f4f1f6777847
parent49c13c71939fafa2d7d113a6a6d2062df5825a89 (diff)
At AF_PACKET socket create, do intf bind before rx ring cfg to avoid receiving pkts from other interfaces
Change-Id: Ie40ee9129edaac717e716b469f4d10f3c29a4932 Signed-off-by: Chaoyu Jin <chjin@cisco.com>
-rw-r--r--src/vnet/devices/af_packet/af_packet.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index 2a135105721..e286ae9a980 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -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)
{
@@ -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)