If we don't receive a SAN MAC address it's pointless to try
to create a socket, as FCoE itself cannot continue. So we
should be handling errors from socket creation and abort
VLAN discovery early.

Signed-off-by: Hannes Reinecke <[email protected]>
---
 fipvlan.c | 19 ++++++++++++-------
 lib/fip.c | 20 ++++++++++++++------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/fipvlan.c b/fipvlan.c
index 198f0ee..5bedea1 100644
--- a/fipvlan.c
+++ b/fipvlan.c
@@ -790,7 +790,7 @@ static void find_interfaces(int ns)
 
 static int probe_fip_interface(struct iff *iff)
 {
-       int origdev = 1;
+       int origdev = 1, rc;
 
        if (iff->resp_recv)
                return 0;
@@ -812,6 +812,10 @@ static int probe_fip_interface(struct iff *iff)
 
        if (!iff->fip_ready) {
                iff->ps = fip_socket(iff->ifindex, FIP_NONE);
+               if (iff->ps < 0) {
+                       FIP_LOG_DBG("if %d not ready\n", iff->ifindex);
+                       return 0;
+               }
                setsockopt(iff->ps, SOL_PACKET, PACKET_ORIGDEV,
                           &origdev, sizeof(origdev));
                pfd_add(iff->ps);
@@ -819,13 +823,14 @@ static int probe_fip_interface(struct iff *iff)
        }
 
        if (config.vn2vn)
-               fip_send_vlan_request(iff->ps, iff->ifindex, iff->mac_addr,
-                                     FIP_ALL_VN2VN);
+               rc = fip_send_vlan_request(iff->ps, iff->ifindex,
+                                          iff->mac_addr, FIP_ALL_VN2VN);
        else
-               fip_send_vlan_request(iff->ps, iff->ifindex, iff->mac_addr,
-                                     FIP_ALL_FCF);
-       iff->req_sent = true;
-       return 0;
+               rc = fip_send_vlan_request(iff->ps, iff->ifindex,
+                                          iff->mac_addr, FIP_ALL_FCF);
+       if (rc == 0)
+               iff->req_sent = true;
+       return rc == 0 ? 0 : 1;
 }
 
 static int send_vlan_requests(void)
diff --git a/lib/fip.c b/lib/fip.c
index 73bf03e..6657b61 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -95,10 +95,11 @@ static int fip_get_sanmac(int ifindex, unsigned char *addr)
  * @mac: MAC address to add or delete
  * @multi: false if unicast, true if multicast address
  */
-static void
+static int
 fip_socket_add_addr(int s, int ifindex, bool add, const __u8 *mac, bool multi)
 {
        struct packet_mreq mr;
+       int rc = 0;
 
        memset(&mr, 0, sizeof(mr));
        mr.mr_ifindex = ifindex;
@@ -107,9 +108,12 @@ fip_socket_add_addr(int s, int ifindex, bool add, const 
__u8 *mac, bool multi)
        memcpy(mr.mr_address, mac, ETHER_ADDR_LEN);
        if (setsockopt(s, SOL_PACKET,
                       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
-                      &mr, sizeof(mr)) < 0)
+                      &mr, sizeof(mr)) < 0) {
                FIP_LOG_DBG("PACKET_%s_MEMBERSHIP:failed\n",
                            add ? "ADD" : "DROP");
+               rc = -errno;
+       }
+       return rc;
 }
 
 /**
@@ -118,16 +122,16 @@ fip_socket_add_addr(int s, int ifindex, bool add, const 
__u8 *mac, bool multi)
  * @ifindex: network interface index to send on
  * @add: 1 to add 0 to del
  */
-static void fip_socket_sanmac(int s, int ifindex, int add)
+static int fip_socket_sanmac(int s, int ifindex, int add)
 {
        unsigned char smac[ETHER_ADDR_LEN];
 
        if (fip_get_sanmac(ifindex, smac)) {
                FIP_LOG_DBG("%s: no sanmac, ifindex %d\n", __func__, ifindex);
-               return;
+               return -ENXIO;
        }
 
-       fip_socket_add_addr(s, ifindex, add, smac, false);
+       return fip_socket_add_addr(s, ifindex, add, smac, false);
 }
 
 /**
@@ -210,7 +214,11 @@ int fip_socket(int ifindex, enum fip_multi multi)
        if (s < 0)
                return s;
 
-       fip_socket_sanmac(s, ifindex, 1);
+       rc = fip_socket_sanmac(s, ifindex, 1);
+       if (rc < 0) {
+               close(s);
+               return rc;
+       }
        if (multi != FIP_NONE)
                fip_socket_multi(s, ifindex, true, multi);
 
-- 
1.8.1.4

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

Reply via email to