Implement ARP mechanism as well as a mechanism for the local port. (Rev 428)
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 12:26:22 +0000 (12:26 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 12:26:22 +0000 (12:26 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@177 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/sdp/include/SdpShared.h
ulp/sdp/kernel/Precompile.h
ulp/sdp/kernel/SdpArp.cpp
ulp/sdp/kernel/SdpArp.h
ulp/sdp/kernel/SdpDriver.cpp
ulp/sdp/kernel/SdpDriver.h
ulp/sdp/kernel/SdpSocket.cpp

index 6638927..36215b5 100644 (file)
@@ -31,10 +31,15 @@ struct WspSocketOut {
     VOID *pSocket;\r
 };\r
 \r
+const int MAC_ADDR_SIZE = 6;\r
+typedef char MAC_ADDR[MAC_ADDR_SIZE] ;\r
+\r
 struct WspConnectIn {\r
-    VOID *pSocket;\r
-    ULONG IP;\r
-    USHORT Port;\r
+    VOID  *pSocket;\r
+    ULONG  SrcIP;\r
+    MAC_ADDR DestMac;\r
+    ULONG  DestIP;\r
+    USHORT DestPort;\r
 };\r
 \r
 struct WspConnectOut {\r
index 55ac814..0fca28d 100644 (file)
@@ -14,6 +14,7 @@ class SdpSocket;
 class SdpArp;\r
 \r
 #include "ib_al.h"\r
+#include "..\..\ipoib\ip_addresses_shared.h"\r
 \r
 #include "sdpMsgs.h"\r
 #include "SdpGenUtils.h"\r
index 3eb115a..43bced9 100644 (file)
 \r
 #pragma warning(disable: 4244 ) \r
 \r
+NTSTATUS \r
+SdpArp::Init() \r
+{ \r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET,("Entering"));\r
+\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
+    UNICODE_STRING  DevName;\r
+    IO_STATUS_BLOCK ioStatus;\r
+    m_DeviceObject = NULL;\r
+\r
+    OBJECT_ATTRIBUTES objectAttributes;\r
+\r
+    RtlInitUnicodeString( &DevName, IPOIB_DEV_NAME );\r
+\r
+    InitializeObjectAttributes( &objectAttributes,\r
+                                &DevName,\r
+                                OBJ_KERNEL_HANDLE,\r
+                                (HANDLE) NULL,\r
+                                (PSECURITY_DESCRIPTOR) NULL );\r
+\r
+    // Try to open the IPOIB device object\r
+    //\r
+    // The reason for using ZwOpenFile instead of IoGetDeviceObjectPointer\r
+    // is to keep the handle around because the NDISPROT makes an assumption\r
+    // that there is no I/O requests between Cleanup and Close requests.\r
+    //\r
+    rc = ZwOpenFile( &m_FileHandle,\r
+                         STANDARD_RIGHTS_ALL,\r
+                         &objectAttributes,\r
+                         &ioStatus,\r
+                         0,\r
+                         FILE_NON_DIRECTORY_FILE );\r
+    if (!NT_SUCCESS( rc )) {\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("ZwOpenFile failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+\r
+    //\r
+    // obtain a pointer to the device object for the handle.\r
+    //\r
+    rc = ObReferenceObjectByHandle(m_FileHandle,\r
+                                        THREAD_ALL_ACCESS,\r
+                                        *IoFileObjectType,\r
+                                        KernelMode,\r
+                                        (PVOID *) &m_FileObject,\r
+                                        NULL );\r
+    if (!NT_SUCCESS( rc )) {\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("ObReferenceObjectByHandle failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+\r
+    // This is what we are looking for\r
+    m_DeviceObject = IoGetRelatedDeviceObject(m_FileObject);\r
+\r
+Cleanup:\r
+    if (!NT_SUCCESS( rc )) {\r
+        if (m_FileHandle) {\r
+            ZwClose(m_FileHandle);\r
+            m_FileHandle = NULL;\r
+        }\r
+        if (m_FileObject) {\r
+            ObDereferenceObject(m_FileObject);\r
+            m_FileObject = NULL;\r
+        }\r
+    }    \r
+    return rc;\r
+\r
+}\r
+\r
+VOID \r
+SdpArp::Shutdown()\r
+{\r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET,("this = %p\n", this));\r
+    if (m_FileHandle) {\r
+        ZwClose(m_FileHandle);\r
+        m_FileHandle = NULL;\r
+    }\r
+    if (m_FileObject) {\r
+        ObDereferenceObject(m_FileObject);\r
+        m_FileObject = NULL;\r
+    }\r
+    m_DeviceObject = NULL; // Not valid any more\r
+}\r
+\r
+\r
+NTSTATUS \r
+SdpArp::SourcePortGidFromIP(\r
+    IN  ULONG  SourceAddr, \r
+    OUT ib_net64_t *SrcPortGuid,\r
+    OUT ib_net64_t *SrcCaGuid\r
+    )\r
+{\r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET,("IP = %d.%d.%d.%d\n", \r
+        (SourceAddr & 0xff000000) >> 24,\r
+        (SourceAddr & 0xff0000) >> 16,\r
+        (SourceAddr & 0xff00) >> 8 ,        \r
+        SourceAddr & 0xff\r
+        ));\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
+    KEVENT             event;\r
+    PIRP               irp;\r
+    IO_STATUS_BLOCK    ioStatus;\r
+    char temp [1000]; // BUGBUG: Handle the case of more IPs\r
+    \r
+    IOCTL_IPOIB_PORTS_IN ipoib_ports_in;\r
+    IOCTL_IPOIB_PORTS_OUT *pipoib_ports_out;\r
+    IPOIB_AT_PORT_RECORD *ports_records;\r
+\r
+    ipoib_ports_in.Version = IPOIB_IOCTL_VERSION;\r
+    ipoib_ports_in.Size = sizeof temp;\r
+\r
+    pipoib_ports_out = (IOCTL_IPOIB_PORTS_OUT *)temp;\r
+\r
+    ASSERT(m_DeviceObject != NULL);\r
+\r
+    KeInitializeEvent(&event, NotificationEvent, FALSE);\r
+    irp = IoBuildDeviceIoControlRequest(\r
+                IOCTL_IPOIB_PORTS ,\r
+                m_DeviceObject,\r
+                &ipoib_ports_in,\r
+                sizeof ipoib_ports_in,\r
+                pipoib_ports_out,\r
+                sizeof temp,\r
+                TRUE,\r
+                &event,\r
+                &ioStatus\r
+                );\r
+\r
+    if(NULL == irp) {\r
+        rc = STATUS_INSUFFICIENT_RESOURCES;\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("IoBuildDeviceIoControlRequest failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+\r
+    rc = IoCallDriver(m_DeviceObject, irp);\r
+    if(STATUS_PENDING == rc) {\r
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);\r
+    }\r
+    else {\r
+        ioStatus.Status = rc;\r
+    }\r
+\r
+    if(!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("IoCallDriver failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+    if (pipoib_ports_out->Size != 0) {\r
+        // The number of bytes that we have allocated wasn't enough\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("pipoib_ports_out.Size = %d\n", pipoib_ports_out->Size ));\r
+        rc = STATUS_INSUFFICIENT_RESOURCES;\r
+        goto Cleanup;\r
+        // BUGBUG: We should try again, with a bigger buffer\r
+    }\r
+\r
+    rc = SourcePortGidFromPorts(SourceAddr, pipoib_ports_out, SrcPortGuid, SrcCaGuid);\r
+    if(!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("SourcePortGidFromPorts failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+\r
+Cleanup:\r
+    return rc;\r
+}\r
+\r
+NTSTATUS\r
+SdpArp::SourcePortGidFromPorts(\r
+    IN  ULONG  SourceAddr, \r
+    IN  IOCTL_IPOIB_PORTS_OUT *pPorts, \r
+    OUT ib_net64_t *SrcPortGuid,\r
+    OUT ib_net64_t *SrcCaGuid\r
+    )\r
+{\r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET,("Entered\n"));\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
+    KEVENT             event;\r
+    PIRP               irp;\r
+    IO_STATUS_BLOCK    ioStatus;\r
+    \r
+    unsigned int i = 0, j = 0;\r
+\r
+    struct IOCTL_IPOIB_IP_ADDRESSES_IN addresses_in;\r
+    struct IOCTL_IPOIB_IP_ADDRESSES_OUT *addresses_out;\r
+    char temp[1000];\r
+    addresses_out = (struct IOCTL_IPOIB_IP_ADDRESSES_OUT *)temp;\r
+\r
+    addresses_in.Version = IPOIB_IOCTL_VERSION;\r
+\r
+    for (i = 0 ; i < pPorts->NumPorts; i++) {\r
+        SDP_PRINT(SDP_TRACE, SDP_SOCKET, (\r
+            "%d: ca guid = 0x%I64x port guid=0x%I64x\n",\r
+            i, CL_NTOH64(pPorts->Ports[i].CaGuid), CL_NTOH64(pPorts->Ports[i].PortGuid)));\r
+\r
+        // Do a quary to find out if this is the correct port\r
+        ASSERT(m_DeviceObject != NULL);\r
+\r
+        addresses_in.PortGuid = pPorts->Ports[i].PortGuid;\r
+\r
+        KeInitializeEvent(&event, NotificationEvent, FALSE);\r
+        irp = IoBuildDeviceIoControlRequest(\r
+                    IOCTL_IPOIB_IP_ADDRESSES ,\r
+                    m_DeviceObject,\r
+                    &addresses_in,\r
+                    sizeof addresses_in,\r
+                    addresses_out,\r
+                    sizeof temp,\r
+                    TRUE,\r
+                    &event,\r
+                    &ioStatus\r
+                    );\r
+\r
+        if(NULL == irp) {\r
+            rc = STATUS_INSUFFICIENT_RESOURCES;\r
+            SDP_PRINT(SDP_ERR, SDP_ARP, ("IoBuildDeviceIoControlRequest failed rc = 0x%x\n", rc ));        \r
+            goto Cleanup;\r
+        }\r
+\r
+        rc = IoCallDriver(m_DeviceObject, irp);\r
+        if(STATUS_PENDING == rc) {\r
+            KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);\r
+        }\r
+        else {\r
+            ioStatus.Status = rc;\r
+        }\r
+\r
+        if(!NT_SUCCESS(rc)) {\r
+            SDP_PRINT(SDP_ERR, SDP_ARP, ("IoCallDriver failed rc = 0x%x\n", rc ));        \r
+            goto Cleanup;\r
+        }\r
+        if (addresses_out->Size != 0) {\r
+        // The number of bytes that we have allocated wasn't enough\r
+            SDP_PRINT(SDP_ERR, SDP_ARP, ("addresses_out.Size = %d\n", addresses_out->Size ));\r
+            rc = STATUS_INSUFFICIENT_RESOURCES;\r
+            goto Cleanup;\r
+            // BUGBUG: We should try again, with a bigger buffer\r
+        }\r
+\r
+\r
+        // We now have the addreses, we can check if this is what we need\r
+        for (j = 0 ; j < addresses_out->NumIps; j++) {\r
+            ULONG *pIp;\r
+            ASSERT(addresses_out->Addreses[j].IpVersion == 4);\r
+            pIp = (ULONG *) (&addresses_out->Addreses[j].Data[12]);\r
+            if (*pIp == CL_NTOH32(SourceAddr)) {\r
+                SDP_PRINT(SDP_TRACE, SDP_ARP, \r
+                    ("Found the IP: ca guid = 0x%I64x port guid=0x%I64x\n", \r
+                    CL_NTOH64(pPorts->Ports[i].CaGuid), CL_NTOH64(pPorts->Ports[i].PortGuid)));\r
+                ASSERT(rc == STATUS_SUCCESS);\r
+                *SrcPortGuid = pPorts->Ports[i].PortGuid;\r
+                *SrcCaGuid = pPorts->Ports[i].CaGuid;\r
+                goto Cleanup;\r
+            }\r
+\r
+        }\r
+\r
+    }\r
+    // If we have reached here the data was not found\r
+    rc = STATUS_NOT_FOUND;\r
+\r
+Cleanup:\r
+    return rc;\r
+\r
+}\r
+\r
+\r
+NTSTATUS \r
+SdpArp::DestPortGidFromMac(\r
+    IN  MAC_ADDR  DestMac, \r
+    OUT ib_gid_t   *pDestPortGid)\r
+{\r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET,("MAC = ????"));\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
+\r
+    KEVENT             event;\r
+    PIRP               irp;\r
+    IO_STATUS_BLOCK    ioStatus;\r
+\r
+    IOCTL_IPOIB_MAC_2_GID_IN ipoib_mac2gid_in;\r
+    IOCTL_IPOIB_MAC_2_GID_OUT ipoib_mac2gid_out;\r
+\r
+    C_ASSERT(MAC_ADDR_SIZE == sizeof (ipoib_mac2gid_in.DestMac));\r
+    memcpy(ipoib_mac2gid_in.DestMac, DestMac, MAC_ADDR_SIZE);\r
+\r
+    ASSERT(m_DeviceObject != NULL);\r
+\r
+    KeInitializeEvent(&event, NotificationEvent, FALSE);\r
+    irp = IoBuildDeviceIoControlRequest(\r
+                IOCTL_IPOIB_MAC_2_GID ,\r
+                m_DeviceObject,\r
+                &ipoib_mac2gid_in,\r
+                sizeof ipoib_mac2gid_in,\r
+                &ipoib_mac2gid_out,\r
+                sizeof ipoib_mac2gid_out,\r
+                TRUE,\r
+                &event,\r
+                &ioStatus\r
+                );\r
+\r
+    if(NULL == irp) {\r
+        rc = STATUS_INSUFFICIENT_RESOURCES;\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("IoBuildDeviceIoControlRequest failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+\r
+    rc = IoCallDriver(m_DeviceObject, irp);\r
+    if(STATUS_PENDING == rc) {\r
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);\r
+    }\r
+    else {\r
+        ioStatus.Status = rc;\r
+    }\r
+\r
+    if(!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_ARP, ("IoCallDriver failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+\r
+    *pDestPortGid = ipoib_mac2gid_out.DestGid;\r
+Cleanup:\r
+    return rc;\r
+}\r
 \r
 NTSTATUS\r
 SdpArp::QueryPathRecord(\r
     IN  ib_net64_t      SrcPortGuid,\r
-    IN  ib_net64_t      DestPortGuid,\r
+    IN  ib_gid_t        DestPortGid,\r
     OUT ib_path_rec_t   *path_rec )\r
 {\r
     NTSTATUS rc = STATUS_SUCCESS;\r
@@ -28,13 +348,13 @@ SdpArp::QueryPathRecord(
     query_req.pfn_query_cb = SdpArp::query_pr_callback;\r
 \r
     ib_gid_set_default( &user_query.src_gid, SrcPortGuid );\r
-    ib_gid_set_default( &user_query.dest_gid, DestPortGuid );\r
+    \r
+    user_query.dest_gid = DestPortGid;\r
 \r
     query_context.path_rec = path_rec;\r
 \r
-    SDP_PRINT( SDP_TRACE, SDP_ARP,\r
-    ("Query for path from %I64x to %I64x\n",\r
-    SrcPortGuid, DestPortGuid) );\r
+    SDP_PRINT( SDP_TRACE, SDP_ARP, ("Query for path from %I64x to %I64x\n",\r
+        SrcPortGuid, DestPortGid.unicast.interface_id) );\r
 \r
     ib_status = ib_query( g_pSdpDriver->m_al_handle, &query_req, &query_handle );\r
 \r
index 2b433b1..e8eb202 100644 (file)
@@ -11,70 +11,22 @@ class SdpArp {
 \r
 public:\r
 \r
+    SdpArp() {\r
+        m_DeviceObject = NULL;\r
+        m_FileObject = NULL;\r
+        m_FileHandle = NULL;\r
+        \r
+    }\r
+\r
   struct query_pr_context\r
     {\r
            ib_api_status_t status;\r
            ib_path_rec_t *path_rec;\r
     };\r
 \r
-    NTSTATUS Init() { return STATUS_SUCCESS;}\r
-\r
-    NTSTATUS SourceAddrFromDestAddr(\r
-        IN  ULONG  DestIp, \r
-        OUT ULONG  *SrcIp\r
-        )\r
-    {\r
-        NTSTATUS rc = STATUS_SUCCESS;\r
-        if (DestIp == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 57) {\r
-            *SrcIp = 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 159;\r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (DestIp == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 63) {\r
-            *SrcIp = 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 159;\r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (DestIp == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 157) {\r
-            *SrcIp = 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 154;\r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (DestIp == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 152) {\r
-            *SrcIp = 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 151;\r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        \r
-        ASSERT(FALSE);\r
-        *SrcIp = 0;\r
-        return STATUS_UNEXPECTED_IO_ERROR;\r
+    NTSTATUS Init();\r
 \r
-    }\r
+    VOID Shutdown();\r
 \r
     NTSTATUS GetPort(\r
         IN  ULONG  SourceAddr, \r
@@ -93,134 +45,11 @@ public:
         IN  ULONG  SourceAddr, \r
         OUT ib_net64_t *SrcPortGuid,\r
         OUT ib_net64_t *SrcCaGuid\r
-        )\r
-    {\r
-        if (SourceAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 159) {\r
-//            *SrcPortGuid = CL_NTOH64(0x2c90200002001);//????? swlab120\r
-//            *SrcCaGuid = CL_NTOH64(0x2c90200002000);\r
-\r
-            *SrcPortGuid = CL_NTOH64(0x2c9010b7c4361);//????? swlab159\r
-            *SrcCaGuid = CL_NTOH64(0x2c9010b7c4360);\r
-            return STATUS_SUCCESS;\r
-        }\r
-        if (SourceAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 63) {\r
-\r
-            *SrcPortGuid = CL_NTOH64(0x2c901093d8432);//????? swlab63\r
-            *SrcCaGuid = CL_NTOH64(0x2c901093d8430);\r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (SourceAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 154) {\r
-\r
-            *SrcPortGuid = CL_NTOH64(0x2c9000100d151);//????? swlab63\r
-            *SrcCaGuid = CL_NTOH64(0x2c9000100d150);\r
-            return STATUS_SUCCESS;\r
-        }\r
-        \r
-        if (SourceAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 157) {\r
-\r
-            *SrcPortGuid = CL_NTOH64(0x2c9000100d051);//????? swlab63\r
-            *SrcCaGuid = CL_NTOH64(0x2c9000100d050);\r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (SourceAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 151) {\r
-\r
-            *SrcPortGuid = CL_NTOH64(0x2c9010a66d25a);//????? swlab63\r
-            *SrcCaGuid = CL_NTOH64(0x2c9010a66d259);\r
-            return STATUS_SUCCESS;\r
-        }\r
-        \r
-        if (SourceAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 152) {\r
-\r
-            *SrcPortGuid = CL_NTOH64(0x2c9010b29b661);//????? swlab63\r
-            *SrcCaGuid = CL_NTOH64(0x2c9010b29b660);\r
-            return STATUS_SUCCESS;\r
-        }\r
-        \r
-        ASSERT(FALSE);\r
-        *SrcPortGuid = 0;\r
-        *SrcCaGuid = 0;\r
-        return STATUS_UNEXPECTED_IO_ERROR;\r
-\r
-    }\r
+        );\r
+    NTSTATUS DestPortGidFromMac(\r
+        IN  MAC_ADDR  DestMac, \r
+        OUT ib_gid_t   *pDestPortGid);\r
 \r
-\r
-    // Get the remote GID based on it's IP addresses\r
-    NTSTATUS DestPortGidFromIP(\r
-        IN  ULONG  DestAddr, \r
-        OUT ib_net64_t *DestPortGuid)\r
-    {\r
-        if (DestAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 170) {\r
-            //*DestPortGuid = CL_NTOH64(0x0000c900012a3a41);//????? swlab124\r
-            //*DestPortGuid = CL_NTOH64(0x0002c90200400301);//????? swlab170\r
-            *DestPortGuid =   CL_NTOH64(0x0002c902004002fe);//????? swlab170\r
-            \r
-            return STATUS_SUCCESS;\r
-        }\r
-        if (DestAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 63) {\r
-            *DestPortGuid =   CL_NTOH64(0x2c901093d8432);//????? swlab63\r
-            \r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (DestAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 57) {\r
-            *DestPortGuid =   CL_NTOH64(0x2c90108a03611);//????? swlab57\r
-            \r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (DestAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 157) {\r
-            *DestPortGuid =   CL_NTOH64(0x2c9000100d051);//????? swlab57\r
-            \r
-            return STATUS_SUCCESS;\r
-        }\r
-\r
-        if (DestAddr == 11 * 256*256*256 + \r
-                      4 * 256*256 +\r
-                      8 * 256 +\r
-                      + 152) {\r
-            *DestPortGuid =   CL_NTOH64(0x2c9010b29b661);//????? swlab57\r
-            \r
-            return STATUS_SUCCESS;\r
-        }\r
-        \r
-        \r
-        ASSERT(FALSE);\r
-        *DestPortGuid = 0;\r
-        return STATUS_UNEXPECTED_IO_ERROR;\r
-\r
-    }\r
 /* \r
 Synchronously query the SA for a GUID. (started from wsd - query_pr)\r
 */\r
@@ -231,12 +60,29 @@ Synchronously query the SA for a GUID. (started from wsd - query_pr)
     NTSTATUS\r
     QueryPathRecord(\r
        IN                              ib_net64_t                              SrcPortGuid,\r
-       IN                              ib_net64_t                                      DestPortGuid,\r
+        IN              ib_gid_t                    DestPortGid,\r
        OUT                         ib_path_rec_t                               *path_rec \r
        );\r
 \r
     static void AL_API\r
         query_pr_callback(\r
         IN                             ib_query_rec_t                          *p_query_rec);\r
+\r
+    private :\r
+        PDEVICE_OBJECT  m_DeviceObject;\r
+        PFILE_OBJECT    m_FileObject;\r
+        HANDLE          m_FileHandle;\r
+\r
+        \r
+\r
+    NTSTATUS\r
+    SourcePortGidFromPorts(\r
+        IN  ULONG  SourceAddr, \r
+        IN  IOCTL_IPOIB_PORTS_OUT *pPorts, \r
+        OUT ib_net64_t *SrcPortGuid,\r
+        OUT ib_net64_t *SrcCaGuid\r
+        );\r
+        \r
+\r
 };\r
 \r
index cff0f6d..1ad412f 100644 (file)
@@ -12,7 +12,7 @@ VOID DriverUnload (
     SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("called pDriverObject = 0x%x\n", pDriverObject ));\r
     ib_api_status_t ib_status;\r
 \r
-    g_pSdpDriver->WaitForAllThreadsToDie();\r
+    g_pSdpDriver->Shutdown();\r
 \r
 \r
     ib_status = ib_close_al(g_pSdpDriver->m_al_handle);\r
@@ -53,8 +53,6 @@ extern "C" NTSTATUS DriverEntry (
         pDriverObject->MajorFunction[i] = SdpDriver::Dispatch;\r
     }\r
 \r
-\r
-\r
     // Create the device that will be used for comunication with the user mode\r
     // Now create the device\r
 \r
@@ -332,6 +330,13 @@ Cleanup:
     return rc;\r
 }\r
 \r
+VOID \r
+SdpDriver::Shutdown()\r
+{\r
+    m_pSdpArp->Shutdown();\r
+    WaitForAllThreadsToDie();\r
+\r
+}\r
 \r
 NTSTATUS \r
 SdpDriver::DispatchDeviceIoControl(\r
index 057e292..41d5224 100644 (file)
@@ -23,6 +23,8 @@ public:
     }\r
     \r
        NTSTATUS Init(PDEVICE_OBJECT pDevObj);\r
+\r
+    VOID Shutdown();\r
     \r
        PDEVICE_OBJECT GetDeviceObject() {\r
                return m_pDevObj;\r
index bd3b1e5..59a31b1 100644 (file)
@@ -439,19 +439,22 @@ NTSTATUS SdpSocket::WSPConnect(
 {\r
     NTSTATUS rc = STATUS_SUCCESS;\r
     ib_api_status_t ib_status;\r
-    ib_net64_t DestPortGuid;\r
+    ib_gid_t   DestPortGid;\r
+    \r
     ib_path_rec_t path_rec;\r
         \r
     SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p remote addresses ip=%d.%d.%d.%d:%d\n",\r
         this,\r
-        (pWspConnectIn->IP & 0XFF000000) >> 24,\r
-        (pWspConnectIn->IP & 0XFF0000) >> 16,\r
-        (pWspConnectIn->IP & 0XFF00) >> 8,\r
-        (pWspConnectIn->IP & 0XFF),\r
-        pWspConnectIn->Port\r
+        (pWspConnectIn->DestIP & 0XFF000000) >> 24,\r
+        (pWspConnectIn->DestIP & 0XFF0000) >> 16,\r
+        (pWspConnectIn->DestIP & 0XFF00) >> 8,\r
+        (pWspConnectIn->DestIP & 0XFF),\r
+        pWspConnectIn->DestPort\r
         ));\r
 \r
-    if((pWspConnectIn->IP == 0) || (pWspConnectIn->Port == 0)) {\r
+    if((pWspConnectIn->DestIP == 0) || \r
+        (pWspConnectIn->DestPort == 0) ||\r
+        (pWspConnectIn->SrcIP == 0)) {\r
         SDP_PRINT(SDP_ERR, SDP_SOCKET, ("Invalid Addresses"));\r
         pWspConnectOut->Errno = WSAEADDRNOTAVAIL;\r
         goto Cleanup;\r
@@ -477,15 +480,8 @@ NTSTATUS SdpSocket::WSPConnect(
     // IP address into gid.\r
     //\r
     if (m_SrcIp == 0) {\r
-        // This means that we need to do an implicit bind to get the source\r
-        // address\r
-        rc = g_pSdpDriver->m_pSdpArp->SourceAddrFromDestAddr(pWspConnectIn->IP , &m_SrcIp);\r
-        if (!NT_SUCCESS(rc)) {\r
-            SDP_PRINT(SDP_ERR, SDP_SOCKET, ("m_pSdpArp->SourceAddrFromDestAddr failed rc = 0x%x\n", rc ));\r
-            pWspConnectOut->Errno = WSAENETUNREACH;\r
-            m_Lock.Unlock(); // Error ignored as this is already an error pass\r
-            goto Cleanup;\r
-        }        \r
+        // No explicit bind was done, we use the default addresses\r
+        m_SrcIp = pWspConnectIn->SrcIP;\r
     }\r
 \r
     // Now that we know the source IP we can decide about the src port\r
@@ -511,7 +507,7 @@ NTSTATUS SdpSocket::WSPConnect(
         goto Cleanup;\r
     }        \r
 \r
-    rc = g_pSdpDriver->m_pSdpArp->DestPortGidFromIP(pWspConnectIn->IP, &DestPortGuid);\r
+    rc = g_pSdpDriver->m_pSdpArp->DestPortGidFromMac(pWspConnectIn->DestMac, &DestPortGid);\r
     if (!NT_SUCCESS(rc)) {\r
         SDP_PRINT(SDP_ERR, SDP_SOCKET, ("m_pSdpArp->DestPortGidFromIP failed rc = 0x%x\n", rc ));\r
         pWspConnectOut->Errno = WSAENETUNREACH; // BUGBUG: verify this error\r
@@ -527,7 +523,7 @@ NTSTATUS SdpSocket::WSPConnect(
     m_state = SS_CONNECTING_QPR_SENT;\r
     m_Lock.Unlock(); //?????\r
 \r
-    rc = g_pSdpDriver->m_pSdpArp->QueryPathRecord( m_SrcPortGuid, DestPortGuid, &path_rec );\r
+    rc = g_pSdpDriver->m_pSdpArp->QueryPathRecord( m_SrcPortGuid, DestPortGid, &path_rec );\r
     if (!NT_SUCCESS(rc)) {\r
         SDP_PRINT(SDP_ERR, SDP_SOCKET, ("m_pSdpArp->QueryPathRecord failed rc = 0x%x\n", rc ));\r
         pWspConnectOut->Errno = WSAENETUNREACH; // BUGBUG: verify this error\r
@@ -551,13 +547,13 @@ NTSTATUS SdpSocket::WSPConnect(
 \r
     // We need to prepare the hello mesage for the CM\r
     sdp_msg_hello hello_msg;\r
-    CreateHelloHeader(&hello_msg, pWspConnectIn->IP);\r
+    CreateHelloHeader(&hello_msg, pWspConnectIn->DestIP);\r
     // We can now update the number of buffers that we have\r
     m_RecvBufferPool.SetLocaleAdvertisedBuffers(CL_NTOH16(hello_msg.bsdh.recv_bufs));\r
 \r
     // Create the CM request\r
     ib_cm_req_t cm_req;\r
-    CreateCmRequest(&cm_req, &hello_msg, &path_rec, pWspConnectIn->Port);\r
+    CreateCmRequest(&cm_req, &hello_msg, &path_rec, pWspConnectIn->DestPort);\r
 \r
     // Create the event to wait on to the connection request to end:\r
     KeInitializeEvent(&m_ConnectCmCompleteEvent, NotificationEvent , FALSE );\r