During fcoe start, fcoemon creates a PF_PACKET,ETH_P_FIP raw socket for
vlan discovery.  After the socket() call and before binding to the
desired device interface, the socket receives FIP packets from all
interfaces. This can interfere with VLAN discovery if a discovery packet
on one interface is received on the wrong socket. This patch drains the
socket after binding it to an interface and before adding the fd to
select monitoring.

Signed-off-by: Nithin Nayak Sujir <[email protected]>
---
 lib/fip.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/lib/fip.c b/lib/fip.c
index f8c8014..20c1082 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -136,6 +136,28 @@ static void fip_ethhdr(int ifindex, unsigned char *mac, 
struct ethhdr *eh)
 }
 
 /**
+ * drain_socket - Discard receive packets on a socket
+ */
+static void drain_socket(int s)
+{
+       char buf[4096];
+       struct sockaddr_ll sa;
+       struct iovec iov[] = {
+               { .iov_base = buf, .iov_len = sizeof(buf), },
+       };
+       struct msghdr msg = {
+               .msg_name = &sa,
+               .msg_namelen = sizeof(sa),
+               .msg_iov = iov,
+               .msg_iovlen = ARRAY_SIZE(iov),
+       };
+
+       while (recvmsg(s, &msg, MSG_DONTWAIT) > 0) {
+               /* Drop the packet */
+       }
+}
+
+/**
  * fip_socket - create and bind a packet socket for FIP
  */
 int fip_socket(int ifindex)
@@ -160,6 +182,13 @@ int fip_socket(int ifindex)
                return rc;
        }
 
+       /*
+        * Drain the packets that were received between socket and bind. We
+        * could've received packets not meant for our interface. This can
+        * interfere with vlan discovery
+        */
+       drain_socket(s);
+
        return s;
 }
 
-- 
1.7.1


_______________________________________________
devel mailing list
[email protected]
https://lists.open-fcoe.org/mailman/listinfo/devel

Reply via email to