public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jiaxin Wu <jiaxin.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>, Fu Siyuan <siyuan.fu@intel.com>,
	Wang Fan <fan.wang@intel.com>, Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch 2/4] NetworkPkg/DnsDxe: Update RetryCount/RetryInterval to comply with UEFI spec.
Date: Tue,  5 Dec 2017 14:59:20 +0800	[thread overview]
Message-ID: <1512457162-9296-3-git-send-email-jiaxin.wu@intel.com> (raw)
In-Reply-To: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com>

According to UEFI spec:
"Retry number if no response received after RetryInterval. If zero, use
the parameter configured through Dns.Configure() interface."
"Minimum interval of retry is 2 second. If the retry interval is less
than 2 second, then use the 2 second. If zero, use the parameter configured
through Dns.Configure() interface."

For both DNS.HostNameToIp and DNS.GeneralLookUp, the value of RetryCount /
RetryInterval need to be updated to comply with UEFI spec.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wang Fan <fan.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/DnsDxe/DnsDriver.h   |   4 +-
 NetworkPkg/DnsDxe/DnsImpl.c     |   4 +-
 NetworkPkg/DnsDxe/DnsImpl.h     |   5 +-
 NetworkPkg/DnsDxe/DnsProtocol.c | 102 ++++++++++++++++++++++++----------------
 4 files changed, 67 insertions(+), 48 deletions(-)

diff --git a/NetworkPkg/DnsDxe/DnsDriver.h b/NetworkPkg/DnsDxe/DnsDriver.h
index 6632bb2..49f6a1d 100644
--- a/NetworkPkg/DnsDxe/DnsDriver.h
+++ b/NetworkPkg/DnsDxe/DnsDriver.h
@@ -1,9 +1,9 @@
 /** @file
 The header files of the driver binding and service binding protocol for DnsDxe driver.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -87,12 +87,10 @@ struct _DNS_INSTANCE {
   EFI_IP_ADDRESS                SessionDnsServer;
 
   NET_MAP                       Dns4TxTokens;
   NET_MAP                       Dns6TxTokens;
 
-  UINT32                        MaxRetry;
-
   UDP_IO                        *UdpIo;
 };
 
 typedef struct {
   EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;
diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c
index ea3d27d..7c236a0 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.c
+++ b/NetworkPkg/DnsDxe/DnsImpl.c
@@ -1946,11 +1946,11 @@ DnsOnTimerRetransmit (
 
         //
         // Retransmit the packet if haven't reach the maxmium retry count,
         // otherwise exit the transfer.
         //
-        if (++Dns4TokenEntry->Token->RetryCount < Instance->MaxRetry) {
+        if (++Dns4TokenEntry->RetryCounting <= Dns4TokenEntry->Token->RetryCount) {
           DnsRetransmit (Instance, (NET_BUF *)ItemNetMap->Value);
           EntryNetMap = EntryNetMap->ForwardLink;
         } else {
           //
           // Maximum retries reached, clean the Token up.
@@ -1990,11 +1990,11 @@ DnsOnTimerRetransmit (
 
         //
         // Retransmit the packet if haven't reach the maxmium retry count,
         // otherwise exit the transfer.
         //
-        if (++Dns6TokenEntry->Token->RetryCount < Instance->MaxRetry) {
+        if (++Dns6TokenEntry->RetryCounting <= Dns6TokenEntry->Token->RetryCount) {
           DnsRetransmit (Instance, (NET_BUF *) ItemNetMap->Value);
           EntryNetMap = EntryNetMap->ForwardLink;
         } else {
           //
           // Maximum retries reached, clean the Token up.
diff --git a/NetworkPkg/DnsDxe/DnsImpl.h b/NetworkPkg/DnsDxe/DnsImpl.h
index 5fa7f24..3c6296c 100644
--- a/NetworkPkg/DnsDxe/DnsImpl.h
+++ b/NetworkPkg/DnsDxe/DnsImpl.h
@@ -1,9 +1,9 @@
 /** @file
 DnsDxe support functions implementation.
    
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -84,11 +84,10 @@ extern EFI_DNS6_PROTOCOL             mDns6Protocol;
 #define DNS_STATE_UNCONFIGED     0
 #define DNS_STATE_CONFIGED       1
 #define DNS_STATE_DESTROY        2
 
 #define DNS_DEFAULT_TIMEOUT      2
-#define DNS_DEFAULT_RETRY        3
 
 #define DNS_TIME_TO_GETMAP       5
 
 #pragma pack(1)
 
@@ -113,18 +112,20 @@ typedef struct {
   LIST_ENTRY             AllServerLink;
   EFI_IPv6_ADDRESS       Dns6ServerIp;       
 } DNS6_SERVER_IP;
 
 typedef struct {
+  UINT32                     RetryCounting;
   UINT32                     PacketToLive;
   CHAR16                     *QueryHostName;
   EFI_IPv4_ADDRESS           QueryIpAddress;
   BOOLEAN                    GeneralLookUp;
   EFI_DNS4_COMPLETION_TOKEN  *Token;
 } DNS4_TOKEN_ENTRY;
 
 typedef struct {
+  UINT32                     RetryCounting;
   UINT32                     PacketToLive;
   CHAR16                     *QueryHostName;
   EFI_IPv6_ADDRESS           QueryIpAddress;
   BOOLEAN                    GeneralLookUp;
   EFI_DNS6_COMPLETION_TOKEN  *Token;
diff --git a/NetworkPkg/DnsDxe/DnsProtocol.c b/NetworkPkg/DnsDxe/DnsProtocol.c
index 7435607..df737dc 100644
--- a/NetworkPkg/DnsDxe/DnsProtocol.c
+++ b/NetworkPkg/DnsDxe/DnsProtocol.c
@@ -221,12 +221,10 @@ Dns4Configure (
     //
     if (!NetMapIsEmpty(&Instance->Dns4TxTokens)) {
       Dns4InstanceCancelToken(Instance, NULL);
     }
 
-    Instance->MaxRetry = 0;
-
     if (Instance->UdpIo != NULL){
       UdpIoCleanIo (Instance->UdpIo);
     }
     
     if (Instance->Dns4CfgData.DnsServerList != NULL) {
@@ -375,28 +373,34 @@ Dns4HostNameToIp (
   
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);
   
   ConfigData = &(Instance->Dns4CfgData);
   
-  Instance->MaxRetry = ConfigData->RetryCount;
-  
-  Token->Status = EFI_NOT_READY;
-  Token->RetryCount = 0;
-  Token->RetryInterval = ConfigData->RetryInterval;
-
   if (Instance->State != DNS_STATE_CONFIGED) {
     Status = EFI_NOT_STARTED;
     goto ON_EXIT;
   }
 
+  Token->Status = EFI_NOT_READY;
+
   //
-  // Check the MaxRetry and RetryInterval values.
+  // If zero, use the parameter configured through Dns.Configure() interface.
   //
-  if (Instance->MaxRetry == 0) {
-    Instance->MaxRetry = DNS_DEFAULT_RETRY;
+  if (Token->RetryCount == 0) {
+    Token->RetryCount = ConfigData->RetryCount;
   }
 
+  //
+  // If zero, use the parameter configured through Dns.Configure() interface.
+  //
+  if (Token->RetryInterval == 0) {
+    Token->RetryInterval = ConfigData->RetryInterval;
+  }
+  
+  //
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second. 
+  //
   if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {
     Token->RetryInterval = DNS_DEFAULT_TIMEOUT;
   }
 
   //
@@ -618,29 +622,35 @@ Dns4GeneralLookUp (
   OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);
   
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This);
   
   ConfigData = &(Instance->Dns4CfgData);
-  
-  Instance->MaxRetry = ConfigData->RetryCount;
-  
-  Token->Status = EFI_NOT_READY;
-  Token->RetryCount = 0;
-  Token->RetryInterval = ConfigData->RetryInterval;
 
   if (Instance->State != DNS_STATE_CONFIGED) {
     Status = EFI_NOT_STARTED;
     goto ON_EXIT;
   }
 
+  Token->Status = EFI_NOT_READY;
+  
+  //
+  // If zero, use the parameter configured through Dns.Configure() interface.
   //
-  // Check the MaxRetry and RetryInterval values.
+  if (Token->RetryCount == 0) {
+    Token->RetryCount = ConfigData->RetryCount;
+  }
+  
+  //
+  // If zero, use the parameter configured through Dns.Configure() interface.
   //
-  if (Instance->MaxRetry == 0) {
-    Instance->MaxRetry = DNS_DEFAULT_RETRY;
+  if (Token->RetryInterval == 0) {
+    Token->RetryInterval = ConfigData->RetryInterval;
   }
 
+  //
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second. 
+  //
   if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {
     Token->RetryInterval = DNS_DEFAULT_TIMEOUT;
   }
 
   //
@@ -1050,12 +1060,10 @@ Dns6Configure (
     //
     if (!NetMapIsEmpty(&Instance->Dns6TxTokens)) {
       Dns6InstanceCancelToken(Instance, NULL);
     }
 
-    Instance->MaxRetry = 0;
-
     if (Instance->UdpIo != NULL){
       UdpIoCleanIo (Instance->UdpIo);
     }
 
     if (Instance->Dns6CfgData.DnsServerList != NULL) {
@@ -1201,32 +1209,38 @@ Dns6HostNameToIp (
   OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);
   
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);
   
   ConfigData = &(Instance->Dns6CfgData);
-  
-  Instance->MaxRetry = ConfigData->RetryCount;
-
-  Token->Status = EFI_NOT_READY;
-  Token->RetryCount = 0;
-  Token->RetryInterval = ConfigData->RetryInterval;
 
   if (Instance->State != DNS_STATE_CONFIGED) {
     Status = EFI_NOT_STARTED;
     goto ON_EXIT;
   }
 
+  Token->Status = EFI_NOT_READY;
+
   //
-  // Check the MaxRetry and RetryInterval values.
+  // If zero, use the parameter configured through Dns.Configure() interface.
   //
-  if (Instance->MaxRetry == 0) {
-    Instance->MaxRetry = DNS_DEFAULT_RETRY;
+  if (Token->RetryCount == 0) {
+    Token->RetryCount = ConfigData->RetryCount;
   }
 
+  //
+  // If zero, use the parameter configured through Dns.Configure() interface.
+  //
+  if (Token->RetryInterval == 0) {
+    Token->RetryInterval = ConfigData->RetryInterval;
+  }
+  
+  //
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second. 
+  //
   if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {
     Token->RetryInterval = DNS_DEFAULT_TIMEOUT;
-  } 
+  }
 
   //
   // Check cache
   //
   if (ConfigData->EnableDnsCache) {
@@ -1449,29 +1463,35 @@ Dns6GeneralLookUp (
   OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);
   
   Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This);
   
   ConfigData = &(Instance->Dns6CfgData);
-  
-  Instance->MaxRetry = ConfigData->RetryCount;
-  
-  Token->Status = EFI_NOT_READY;
-  Token->RetryCount = 0;
-  Token->RetryInterval = ConfigData->RetryInterval;
 
   if (Instance->State != DNS_STATE_CONFIGED) {
     Status = EFI_NOT_STARTED;
     goto ON_EXIT;
   }
 
+  Token->Status = EFI_NOT_READY;
+  
   //
-  // Check the MaxRetry and RetryInterval values.
+  // If zero, use the parameter configured through Dns.Configure() interface.
   //
-  if (Instance->MaxRetry == 0) {
-    Instance->MaxRetry = DNS_DEFAULT_RETRY;
+  if (Token->RetryCount == 0) {
+    Token->RetryCount = ConfigData->RetryCount;
+  }
+  
+  //
+  // If zero, use the parameter configured through Dns.Configure() interface.
+  //
+  if (Token->RetryInterval == 0) {
+    Token->RetryInterval = ConfigData->RetryInterval;
   }
 
+  //
+  // Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second. 
+  //
   if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) {
     Token->RetryInterval = DNS_DEFAULT_TIMEOUT;
   }
 
   //
-- 
1.9.5.msysgit.1



  parent reply	other threads:[~2017-12-05  6:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05  6:59 [Patch 0/4] NetworkPkg/DnsDxe: Fix several issues in DnsDxe driver Jiaxin Wu
2017-12-05  6:59 ` [Patch 1/4] NetworkPkg/DnsDxe: Remove the unnecessary if condition check in DNS.Config Jiaxin Wu
2017-12-05  6:59 ` Jiaxin Wu [this message]
2017-12-05  6:59 ` [Patch 3/4] NetworkPkg/DnsDxe: Fix the potential memory leak issue Jiaxin Wu
2017-12-05  6:59 ` [Patch 4/4] NetworkPkg/DnsDxe: Avoid to access the freed memory buffer Jiaxin Wu
2017-12-05  8:09 ` [Patch 0/4] NetworkPkg/DnsDxe: Fix several issues in DnsDxe driver Fu, Siyuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512457162-9296-3-git-send-email-jiaxin.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox