]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/EfiSocketLib/Udp4.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / EfiSocketLib / Udp4.c
index e1500d3f9f92b3fd308dc05d36cb979bcceb9af7..11b7db761448353e47cf1a6f4a0bf9241f6c2799 100644 (file)
@@ -131,9 +131,9 @@ EslUdp4LocalAddressSet (
     }\r
     else {\r
       pConfig->SubnetMask.Addr[0] = 0xff;\r
-      pConfig->SubnetMask.Addr[1] = 0xff;\r
-      pConfig->SubnetMask.Addr[2] = 0xff;\r
-      pConfig->SubnetMask.Addr[3] = 0xff;\r
+      pConfig->SubnetMask.Addr[1] = ( 128 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;\r
+      pConfig->SubnetMask.Addr[2] = ( 192 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;\r
+      pConfig->SubnetMask.Addr[3] = ( 224 <= pConfig->StationAddress.Addr[0]) ? 0xff : 0;\r
     }\r
 \r
     //\r
@@ -253,6 +253,7 @@ EslUdp4PortAllocate (
   //\r
   pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.UDPv4->Configure;\r
   pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Cancel;\r
+  pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.UDPv4->Poll;\r
   pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Receive;\r
   pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Transmit;\r
 \r
@@ -265,7 +266,7 @@ EslUdp4PortAllocate (
   pConfig->AcceptBroadcast = FALSE;\r
   pConfig->AcceptPromiscuous = FALSE;\r
   pConfig->AllowDuplicatePort = TRUE;\r
-  pConfig->DoNotFragment = TRUE;\r
+  pConfig->DoNotFragment = FALSE;\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
@@ -462,6 +463,7 @@ EslUdp4RemoteAddressSet (
   pUdp4->ConfigData.RemoteAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );\r
   pUdp4->ConfigData.RemoteAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );\r
   pUdp4->ConfigData.RemotePort = SwapBytes16 ( pRemoteAddress->sin_port );\r
+  pPort->pSocket->bAddressSet = TRUE;\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
@@ -589,6 +591,7 @@ EslUdp4RxComplete (
     //\r
     //  Fill in the port list if necessary\r
     //\r
+    pSocket->errno = ENETDOWN;\r
     if ( NULL == pSocket->pPortList ) {\r
       LocalAddress.sin_len = sizeof ( LocalAddress );\r
       LocalAddress.sin_family = AF_INET;\r
@@ -638,34 +641,36 @@ EslUdp4RxComplete (
                                               NULL );\r
       }\r
       if ( EFI_ERROR ( Status )) {\r
-        DEBUG (( DEBUG_LISTEN,\r
-                  "ERROR - Failed to configure the Udp4 port, Status: %r\r\n",\r
-                  Status ));\r
-        switch ( Status ) {\r
-        case EFI_ACCESS_DENIED:\r
-          pSocket->errno = EACCES;\r
-          break;\r
+        if ( !pSocket->bConfigured ) {\r
+          DEBUG (( DEBUG_LISTEN,\r
+                    "ERROR - Failed to configure the Udp4 port, Status: %r\r\n",\r
+                    Status ));\r
+          switch ( Status ) {\r
+          case EFI_ACCESS_DENIED:\r
+            pSocket->errno = EACCES;\r
+            break;\r
+\r
+          default:\r
+          case EFI_DEVICE_ERROR:\r
+            pSocket->errno = EIO;\r
+            break;\r
 \r
-        default:\r
-        case EFI_DEVICE_ERROR:\r
-          pSocket->errno = EIO;\r
-          break;\r
+          case EFI_INVALID_PARAMETER:\r
+            pSocket->errno = EADDRNOTAVAIL;\r
+            break;\r
 \r
-        case EFI_INVALID_PARAMETER:\r
-          pSocket->errno = EADDRNOTAVAIL;\r
-          break;\r
+          case EFI_NO_MAPPING:\r
+            pSocket->errno = EAFNOSUPPORT;\r
+            break;\r
 \r
-        case EFI_NO_MAPPING:\r
-          pSocket->errno = EAFNOSUPPORT;\r
-          break;\r
-\r
-        case EFI_OUT_OF_RESOURCES:\r
-          pSocket->errno = ENOBUFS;\r
-          break;\r
+          case EFI_OUT_OF_RESOURCES:\r
+            pSocket->errno = ENOBUFS;\r
+            break;\r
 \r
-        case EFI_UNSUPPORTED:\r
-          pSocket->errno = EOPNOTSUPP;\r
-          break;\r
+          case EFI_UNSUPPORTED:\r
+            pSocket->errno = EOPNOTSUPP;\r
+            break;\r
+          }\r
         }\r
       }\r
       else {\r
@@ -683,6 +688,7 @@ EslUdp4RxComplete (
                   pConfigData->RemoteAddress.Addr[3],\r
                   pConfigData->RemotePort ));\r
         pPort->bConfigured = TRUE;\r
+        pSocket->bConfigured = TRUE;\r
 \r
         //\r
         //  Start the first read on the port\r
@@ -693,6 +699,7 @@ EslUdp4RxComplete (
         //  The socket is connected\r
         //\r
         pSocket->State = SOCKET_STATE_CONNECTED;\r
+        pSocket->errno = 0;\r
       }\r
 \r
       //\r
@@ -700,21 +707,12 @@ EslUdp4RxComplete (
       //\r
       pPort = pNextPort;\r
     }\r
-\r
-    //\r
-    //  Determine the configuration status\r
-    //\r
-    if ( NULL != pSocket->pPortList ) {\r
-      pSocket->bConfigured = TRUE;\r
-    }\r
   }\r
 \r
   //\r
   //  Determine the socket configuration status\r
   //\r
-  if ( !EFI_ERROR ( Status )) {\r
-    Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;\r
-  }\r
+  Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;\r
   \r
   //\r
   //  Return the port connected state.\r
@@ -796,21 +794,21 @@ EslUdp4TxBuffer (
   //\r
   if ( SOCKET_STATE_CONNECTED == pSocket->State ) {\r
     //\r
-    //  Locate the port\r
+    //  Verify that there is enough room to buffer another\r
+    //  transmit operation\r
     //\r
-    pPort = pSocket->pPortList;\r
-    if ( NULL != pPort ) {\r
+    pTxBytes = &pSocket->TxBytes;\r
+    if ( pSocket->MaxTxBuf > *pTxBytes ) {\r
       //\r
-      //  Determine the queue head\r
+      //  Locate the port\r
       //\r
-      pUdp4 = &pPort->Context.Udp4;\r
-      pTxBytes = &pSocket->TxBytes;\r
+      pPort = pSocket->pPortList;\r
+      while ( NULL != pPort ) {\r
+        //\r
+        //  Determine the queue head\r
+        //\r
+        pUdp4 = &pPort->Context.Udp4;\r
 \r
-      //\r
-      //  Verify that there is enough room to buffer another\r
-      //  transmit operation\r
-      //\r
-      if ( pSocket->MaxTxBuf > *pTxBytes ) {\r
         //\r
         //  Attempt to allocate the packet\r
         //\r
@@ -925,6 +923,7 @@ EslUdp4TxBuffer (
             //  Free the packet\r
             //\r
             EslSocketPacketFree ( pPacket, DEBUG_TX );\r
+            break;\r
           }\r
 \r
           //\r
@@ -937,16 +936,22 @@ EslUdp4TxBuffer (
           //  Packet allocation failed\r
           //\r
           pSocket->errno = ENOMEM;\r
+          break;\r
         }\r
-      }\r
-      else {\r
+\r
         //\r
-        //  Not enough buffer space available\r
+        //  Set the next port\r
         //\r
-        pSocket->errno = EAGAIN;\r
-        Status = EFI_NOT_READY;\r
+        pPort = pPort->pLinkSocket;\r
       }\r
     }\r
+    else {\r
+      //\r
+      //  Not enough buffer space available\r
+      //\r
+      pSocket->errno = EAGAIN;\r
+      Status = EFI_NOT_READY;\r
+    }\r
   }\r
 \r
   //\r