]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
Scrubbed some code for Udp4
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Udp4Dxe / Udp4Impl.c
index ab50830b680281d7281502ad4caa2b0f899ad743..d9372ba1b8316b58d1e7b38d0d199ddedc2273ea 100644 (file)
@@ -128,13 +128,14 @@ Udp4SendPortUnreach (
   @retval EFI_SUCCESS            The udp4 service context data is created and\r
                                  initialized.\r
   @retval EFI_OUT_OF_RESOURCES   Cannot allocate memory.\r
+  @retval other                  Other error occurs.\r
 \r
 **/\r
 EFI_STATUS\r
 Udp4CreateService (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service,\r
-  IN EFI_HANDLE         ImageHandle,\r
-  IN EFI_HANDLE         ControllerHandle\r
+  IN OUT UDP4_SERVICE_DATA  *Udp4Service,\r
+  IN     EFI_HANDLE         ImageHandle,\r
+  IN     EFI_HANDLE         ControllerHandle\r
   )\r
 {\r
   EFI_STATUS       Status;\r
@@ -251,7 +252,7 @@ Udp4CleanService (
   service context.\r
 \r
   @param  Event                  The event this function registered to.\r
-  @param  Conext                 The context data registered during the creation of\r
+  @param  Context                The context data registered during the creation of\r
                                  the Event.\r
 \r
   @return None.\r
@@ -318,8 +319,8 @@ Udp4CheckTimeout (
 **/\r
 VOID\r
 Udp4InitInstance (\r
-  IN UDP4_SERVICE_DATA   *Udp4Service,\r
-  IN UDP4_INSTANCE_DATA  *Instance\r
+  IN     UDP4_SERVICE_DATA   *Udp4Service,\r
+  IN OUT UDP4_INSTANCE_DATA  *Instance\r
   )\r
 {\r
   //\r
@@ -380,7 +381,8 @@ Udp4CleanInstance (
   @param  Address                Pointer to the specified IPv4 address.\r
   @param  Port                   The udp port number.\r
 \r
-  @return Is the specified <Address, Port> pair found or not.\r
+  @retval TRUE     The specified <Address, Port> pair is found.\r
+  @retval FALSE    Otherwise.\r
 \r
 **/\r
 BOOLEAN\r
@@ -427,12 +429,13 @@ Udp4FindInstanceByPort (
 \r
 /**\r
   This function tries to bind the udp instance according to the configured port\r
-  allocation stragety.\r
+  allocation strategy.\r
 \r
   @param  InstanceList           Pointer to the head of the list linking the udp\r
                                  instances.\r
   @param  ConfigData             Pointer to the ConfigData of the instance to be\r
-                                 bound.\r
+                                 bound. ConfigData->StationPort will be assigned\r
+                                 with an available port value on success.\r
 \r
   @retval EFI_SUCCESS            The bound operation is completed successfully.\r
   @retval EFI_ACCESS_DENIED      The <Address, Port> specified by the ConfigData is\r
@@ -442,8 +445,8 @@ Udp4FindInstanceByPort (
 **/\r
 EFI_STATUS\r
 Udp4Bind (\r
-  IN LIST_ENTRY            *InstanceList,\r
-  IN EFI_UDP4_CONFIG_DATA  *ConfigData\r
+  IN     LIST_ENTRY            *InstanceList,\r
+  IN OUT EFI_UDP4_CONFIG_DATA  *ConfigData\r
   )\r
 {\r
   EFI_IPv4_ADDRESS  *StationAddress;\r
@@ -514,7 +517,8 @@ Udp4Bind (
                                  uses.\r
   @param  NewConfigData          Pointer to the new ConfigData.\r
 \r
-  @return The instance is reconfigurable or not according to the NewConfigData.\r
+  @retval TRUE     The instance is reconfigurable.\r
+  @retval FALSE    Otherwise.\r
 \r
 **/\r
 BOOLEAN\r
@@ -523,10 +527,11 @@ Udp4IsReconfigurable (
   IN EFI_UDP4_CONFIG_DATA  *NewConfigData\r
   )\r
 {\r
-  if ((NewConfigData->AcceptAnyPort != OldConfigData->AcceptAnyPort) ||\r
-    (NewConfigData->AcceptBroadcast != OldConfigData->AcceptBroadcast) ||\r
-    (NewConfigData->AcceptPromiscuous != OldConfigData->AcceptPromiscuous) ||\r
-    (NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort)) {\r
+  if ((NewConfigData->AcceptAnyPort      != OldConfigData->AcceptAnyPort)     ||\r
+      (NewConfigData->AcceptBroadcast    != OldConfigData->AcceptBroadcast)   ||\r
+      (NewConfigData->AcceptPromiscuous  != OldConfigData->AcceptPromiscuous) ||\r
+      (NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort)\r
+      ) {\r
     //\r
     // The receiving filter parameters cannot be changed.\r
     //\r
@@ -534,7 +539,8 @@ Udp4IsReconfigurable (
   }\r
 \r
   if ((!NewConfigData->AcceptAnyPort) &&\r
-    (NewConfigData->StationPort != OldConfigData->StationPort)) {\r
+      (NewConfigData->StationPort != OldConfigData->StationPort)\r
+      ) {\r
     //\r
     // The port is not changeable.\r
     //\r
@@ -551,8 +557,9 @@ Udp4IsReconfigurable (
     }\r
 \r
     if (!NewConfigData->UseDefaultAddress &&\r
-      (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) ||\r
-      !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))) {\r
+        (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) ||\r
+         !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))\r
+        ) {\r
       //\r
       // If the instance doesn't use the default address, and the new address or\r
       // new subnet mask is different from the old values.\r
@@ -568,7 +575,9 @@ Udp4IsReconfigurable (
     return FALSE;\r
   }\r
 \r
-  if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) && (NewConfigData->RemotePort != OldConfigData->RemotePort)) {\r
+  if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
+      NewConfigData->RemotePort != OldConfigData->RemotePort\r
+      ) {\r
     //\r
     // The RemotePort differs if it's designated in the configdata.\r
     //\r
@@ -593,8 +602,8 @@ Udp4IsReconfigurable (
 **/\r
 VOID\r
 Udp4BuildIp4ConfigData (\r
-  IN EFI_UDP4_CONFIG_DATA  *Udp4ConfigData,\r
-  IN EFI_IP4_CONFIG_DATA   *Ip4ConfigData\r
+  IN     EFI_UDP4_CONFIG_DATA  *Udp4ConfigData,\r
+  IN OUT EFI_IP4_CONFIG_DATA   *Ip4ConfigData\r
   )\r
 {\r
   CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
@@ -818,8 +827,8 @@ Udp4Checksum (
 **/\r
 EFI_STATUS\r
 Udp4RemoveToken (\r
-  IN NET_MAP                    *TokenMap,\r
-  IN EFI_UDP4_COMPLETION_TOKEN  *Token\r
+  IN OUT NET_MAP                    *TokenMap,\r
+  IN     EFI_UDP4_COMPLETION_TOKEN  *Token\r
   )\r
 {\r
   NET_MAP_ITEM  *Item;\r
@@ -943,9 +952,9 @@ Udp4DgramRcvd (
 **/\r
 EFI_STATUS\r
 Udp4LeaveGroup (\r
-  IN NET_MAP       *Map,\r
-  IN NET_MAP_ITEM  *Item,\r
-  IN VOID          *Arg OPTIONAL\r
+  IN OUT NET_MAP       *Map,\r
+  IN     NET_MAP_ITEM  *Item,\r
+  IN     VOID          *Arg OPTIONAL\r
   )\r
 {\r
   EFI_IPv4_ADDRESS  *McastIp;\r
@@ -977,12 +986,13 @@ Udp4LeaveGroup (
 \r
 \r
 /**\r
-  This function cancle the token specified by Arg in the Map.\r
+  This function cancels the token specified by Arg in the Map. This is a callback\r
+  used by Udp4InstanceCancelToken().\r
 \r
   @param  Map                    Pointer to the NET_MAP.\r
   @param  Item                   Pointer to the NET_MAP_ITEM.\r
-  @param  Arg                    Pointer to the token to be cancelled, if NULL, all\r
-                                 the tokens in this Map will be cancelled.\r
+  @param  Arg                    Pointer to the token to be cancelled, if NULL,\r
+                                 the token specified by Item is cancelled.\r
 \r
   @retval EFI_SUCCESS            The token is cancelled if Arg is NULL or the token\r
                                  is not the same as that in the Item if Arg is not\r
@@ -1039,7 +1049,7 @@ Udp4CancelTokens (
 /**\r
   This function removes all the Wrap datas in the RcvdDgramQue.\r
 \r
-  @param  RcvdDgramQue           Pointer to the list containing all the Wrap datas.\r
+  @param  Instance           Pointer to the udp instance context data.\r
 \r
   @return None.\r
 \r
@@ -1067,6 +1077,7 @@ Udp4FlushRcvdDgram (
 \r
 \r
 /**\r
+  Cancel Udp4 tokens from the Udp4 instance.\r
 \r
   @param  Instance               Pointer to the udp instance context data.\r
   @param  Token                  Pointer to the token to be canceled, if NULL, all\r
@@ -1085,7 +1096,7 @@ Udp4InstanceCancelToken (
   EFI_STATUS  Status;\r
 \r
   //\r
-  // Cancle this token from the TxTokens map.\r
+  // Cancel this token from the TxTokens map.\r
   //\r
   Status = NetMapIterate (&Instance->TxTokens, Udp4CancelTokens, Token);\r
 \r
@@ -1125,7 +1136,9 @@ Udp4InstanceCancelToken (
   @param  Udp4Session            Pointer to the EFI_UDP4_SESSION_DATA abstracted\r
                                  from the received udp datagram.\r
 \r
-  @return The udp datagram matches the receiving requirments of the Instance or not.\r
+  @retval TRUE       The udp datagram matches the receiving requirments of the\r
+                     udp Instance.\r
+  @retval FALSE      Otherwise.\r
 \r
 **/\r
 BOOLEAN\r
@@ -1147,7 +1160,8 @@ Udp4MatchDgram (
   }\r
 \r
   if ((!ConfigData->AcceptAnyPort && (Udp4Session->DestinationPort != ConfigData->StationPort)) ||\r
-    ((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort))) {\r
+      ((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort))\r
+      ) {\r
     //\r
     // The local port or the remote port doesn't match.\r
     //\r
@@ -1155,7 +1169,8 @@ Udp4MatchDgram (
   }\r
 \r
   if (!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
-    !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)) {\r
+      !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)\r
+      ) {\r
     //\r
     // This datagram doesn't come from the instance's specified sender.\r
     //\r
@@ -1163,9 +1178,10 @@ Udp4MatchDgram (
   }\r
 \r
   if (EFI_IP4_EQUAL (&ConfigData->StationAddress, &mZeroIp4Addr) ||\r
-    EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)) {\r
+      EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)\r
+      ) {\r
     //\r
-    // The instance is configured to receive datagrams destinated to any station IP or\r
+    // The instance is configured to receive datagrams destined to any station IP or\r
     // the destination address of this datagram matches the configured station IP.\r
     //\r
     return TRUE;\r
@@ -1181,7 +1197,8 @@ Udp4MatchDgram (
   }\r
 \r
   if (IP4_IS_MULTICAST (NTOHL (Destination)) &&\r
-    (NULL != NetMapFindKey (&Instance->McastIps, (VOID *) (UINTN) Destination))) {\r
+      NetMapFindKey (&Instance->McastIps, (VOID *) (UINTN) Destination) != NULL\r
+      ) {\r
     //\r
     // It's a multicast packet and the multicast address is accepted by this instance.\r
     //\r
@@ -1365,7 +1382,7 @@ Udp4InstanceDeliverDgram (
   EFI_TPL                    OldTpl;\r
 \r
   if (!IsListEmpty (&Instance->RcvdDgramQue) &&\r
-    !NetMapIsEmpty (&Instance->RxTokens)) {\r
+      !NetMapIsEmpty (&Instance->RxTokens)) {\r
 \r
     Wrap = NET_LIST_HEAD (&Instance->RcvdDgramQue, UDP4_RXDATA_WRAP, Link);\r
 \r
@@ -1381,7 +1398,7 @@ Udp4InstanceDeliverDgram (
       NetbufFree (Wrap->Packet);\r
 \r
       Wrap->Packet = Dup;\r
-    } \r
+    }\r
 \r
     NetListRemoveHead (&Instance->RcvdDgramQue);\r
 \r
@@ -1678,9 +1695,10 @@ Udp4IcmpHandler (
     Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
 \r
     if (!Instance->Configured ||\r
-      Instance->ConfigData.AcceptPromiscuous ||\r
-      Instance->ConfigData.AcceptAnyPort ||\r
-      EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr)) {\r
+        Instance->ConfigData.AcceptPromiscuous ||\r
+        Instance->ConfigData.AcceptAnyPort ||\r
+        EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr)\r
+        ) {\r
       //\r
       // Don't try to deliver the ICMP error to this instance if it is not configured,\r
       // or it's configured to be promiscuous or accept any port or accept all the\r
@@ -1780,6 +1798,7 @@ Udp4NetVectorExtFree (
 \r
   @retval EFI_OUT_OF_RESOURCES   There are not enough resources to set the\r
                                  variable.\r
+  @retval EFI_SUCCESS            Set variable successfully.\r
   @retval other                  Set variable failed.\r
 \r
 **/\r