Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 495bbe94e5126512132d69685e96e0d7 > files > 8

fcoe-utils-1.0.18-2.fc15.src.rpm

From d880216b9882eb601e60d2111a97ac1405f3529f Mon Sep 17 00:00:00 2001
From: Nithin Sujir <nsujir@broadcom.com>
Date: Tue, 12 Apr 2011 05:33:05 +0000
Subject: [PATCH 09/16] fcoe-utils: Drain fip socket during creation to
 discard unintended rx packets.

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 <nsujir@broadcom.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: Petr Sabata <psabata@redhat.com>
---
 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.4.4