public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/4] Http Fixes
@ 2022-03-04 13:34 Oliver Steffen
  2022-03-04 13:34 ` [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring Oliver Steffen
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Oliver Steffen @ 2022-03-04 13:34 UTC (permalink / raw)
  To: devel; +Cc: Oliver Steffen

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720

This set of patches fixes booting from HTTP/1.0 servers.
It also improves the interaction with HTTP/1.1 servers by recognizing
the 'Connection: close' header field, which fixes a problem with
servers that close the connection after a 404-error is encountered.

It also prevents triggering the TCP issue described in
https://bugzilla.tianocore.org/show_bug.cgi?id=3735
when booting from HTTP/1.0 servers.

PR: https://github.com/tianocore/edk2/pull/2564

Oliver Steffen (4):
  NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring
  NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL
  NetworkPkg/HttpDxe: Detect 'Connection: close' header
  NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers

 NetworkPkg/HttpDxe/HttpImpl.c  | 25 ++++++++++++++++++++++++-
 NetworkPkg/HttpDxe/HttpProto.c | 12 ++++++++++++
 NetworkPkg/HttpDxe/HttpProto.h |  2 ++
 3 files changed, 38 insertions(+), 1 deletion(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring
  2022-03-04 13:34 [PATCH 0/4] Http Fixes Oliver Steffen
@ 2022-03-04 13:34 ` Oliver Steffen
  2022-03-07 11:52   ` [edk2-devel] " Gerd Hoffmann
  2022-03-04 13:34 ` [PATCH 2/4] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL Oliver Steffen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Oliver Steffen @ 2022-03-04 13:34 UTC (permalink / raw)
  To: devel; +Cc: Oliver Steffen

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720

Check if the state of the HTTP instance is HTTP_STATE_TCP_CONNECTED, or
HTTP_STATE_TCP_CLOSED and de-configure the Tcp4 instance before
configuring it again.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index 9457dd2623..cd54c57404 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -1086,6 +1086,18 @@ HttpConfigureTcp4 (
   Tcp4Option->EnableNagle       = TRUE;
   Tcp4CfgData->ControlOption    = Tcp4Option;
 
+  if ((HttpInstance->State == HTTP_STATE_TCP_CONNECTED) ||
+      (HttpInstance->State == HTTP_STATE_TCP_CLOSED))
+  {
+    Status = HttpInstance->Tcp4->Configure (HttpInstance->Tcp4, NULL);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "HttpConfigureTcp4(NULL) - %r\n", Status));
+      return Status;
+    }
+
+    HttpInstance->State = HTTP_STATE_TCP_UNCONFIGED;
+  }
+
   Status = HttpInstance->Tcp4->Configure (HttpInstance->Tcp4, Tcp4CfgData);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "HttpConfigureTcp4 - %r\n", Status));
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL
  2022-03-04 13:34 [PATCH 0/4] Http Fixes Oliver Steffen
  2022-03-04 13:34 ` [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring Oliver Steffen
@ 2022-03-04 13:34 ` Oliver Steffen
  2022-03-07 11:55   ` [edk2-devel] " Gerd Hoffmann
  2022-03-04 13:34 ` [PATCH 3/4] NetworkPkg/HttpDxe: Detect 'Connection: close' header Oliver Steffen
  2022-03-04 13:34 ` [PATCH 4/4] NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers Oliver Steffen
  3 siblings, 1 reply; 9+ messages in thread
From: Oliver Steffen @ 2022-03-04 13:34 UTC (permalink / raw)
  To: devel; +Cc: Oliver Steffen

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720

Add ConnectionClose flag fo HTTP_PROTOCOL.
This boolean is FALSE by default. If set to TRUE, a reconfigure
of the Http instance is forced on the next request. The flag
is then reset.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
 NetworkPkg/HttpDxe/HttpImpl.c  | 6 +++++-
 NetworkPkg/HttpDxe/HttpProto.h | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index d64cd9e965..d8b014c94f 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -161,6 +161,7 @@ EfiHttpConfigure (
     HttpInstance->HttpVersion        = HttpConfigData->HttpVersion;
     HttpInstance->TimeOutMillisec    = HttpConfigData->TimeOutMillisec;
     HttpInstance->LocalAddressIsIPv6 = HttpConfigData->LocalAddressIsIPv6;
+    HttpInstance->ConnectionClose    = FALSE;
 
     if (HttpConfigData->LocalAddressIsIPv6) {
       CopyMem (
@@ -440,7 +441,8 @@ EfiHttpRequest (
       //
       ReConfigure = FALSE;
     } else {
-      if ((HttpInstance->RemotePort == RemotePort) &&
+      if ((HttpInstance->ConnectionClose == FALSE) &&
+          (HttpInstance->RemotePort == RemotePort) &&
           (AsciiStrCmp (HttpInstance->RemoteHost, HostName) == 0) &&
           (!HttpInstance->UseHttps || (HttpInstance->UseHttps &&
                                        !TlsConfigure &&
@@ -649,6 +651,8 @@ EfiHttpRequest (
     }
   }
 
+  HttpInstance->ConnectionClose = FALSE;
+
   //
   // Transmit the request message.
   //
diff --git a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h
index 8ed99c7a02..620eb39158 100644
--- a/NetworkPkg/HttpDxe/HttpProto.h
+++ b/NetworkPkg/HttpDxe/HttpProto.h
@@ -194,6 +194,8 @@ typedef struct _HTTP_PROTOCOL {
   EFI_TCP6_IO_TOKEN                 Tcp6TlsRxToken;
   EFI_TCP6_RECEIVE_DATA             Tcp6TlsRxData;
   BOOLEAN                           TlsIsRxDone;
+
+  BOOLEAN                           ConnectionClose;
 } HTTP_PROTOCOL;
 
 typedef struct {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] NetworkPkg/HttpDxe: Detect 'Connection: close' header
  2022-03-04 13:34 [PATCH 0/4] Http Fixes Oliver Steffen
  2022-03-04 13:34 ` [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring Oliver Steffen
  2022-03-04 13:34 ` [PATCH 2/4] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL Oliver Steffen
@ 2022-03-04 13:34 ` Oliver Steffen
  2022-03-07 11:59   ` [edk2-devel] " Gerd Hoffmann
  2022-03-04 13:34 ` [PATCH 4/4] NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers Oliver Steffen
  3 siblings, 1 reply; 9+ messages in thread
From: Oliver Steffen @ 2022-03-04 13:34 UTC (permalink / raw)
  To: devel; +Cc: Oliver Steffen

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720

Force connecton close before the next request if
the server sends the 'Connection: close' header.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
 NetworkPkg/HttpDxe/HttpImpl.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index d8b014c94f..a1a3eea585 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -994,6 +994,7 @@ HttpResponseWorker (
   UINTN             HdrLen;
   NET_FRAGMENT      Fragment;
   UINT32            TimeoutValue;
+  UINTN             index;
 
   if ((Wrap == NULL) || (Wrap->HttpInstance == NULL)) {
     return EFI_INVALID_PARAMETER;
@@ -1200,6 +1201,16 @@ HttpResponseWorker (
       FreePool (HttpHeaders);
       HttpHeaders = NULL;
 
+      for (index = 0; index < HttpMsg->HeaderCount; ++index) {
+        if ((AsciiStriCmp ("Connection", HttpMsg->Headers[index].FieldName) == 0) &&
+            (AsciiStriCmp ("close", HttpMsg->Headers[index].FieldValue) == 0))
+        {
+          DEBUG ((DEBUG_WARN, "Http: 'Connection: close' header received.\n"));
+          HttpInstance->ConnectionClose = TRUE;
+          break;
+        }
+      }
+
       //
       // Init message-body parser by header information.
       //
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers
  2022-03-04 13:34 [PATCH 0/4] Http Fixes Oliver Steffen
                   ` (2 preceding siblings ...)
  2022-03-04 13:34 ` [PATCH 3/4] NetworkPkg/HttpDxe: Detect 'Connection: close' header Oliver Steffen
@ 2022-03-04 13:34 ` Oliver Steffen
  2022-03-07 12:07   ` [edk2-devel] " Gerd Hoffmann
  3 siblings, 1 reply; 9+ messages in thread
From: Oliver Steffen @ 2022-03-04 13:34 UTC (permalink / raw)
  To: devel; +Cc: Oliver Steffen

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720

Force connecton close before the next request if
the server does not identify as version 1.1.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
 NetworkPkg/HttpDxe/HttpImpl.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index a1a3eea585..ea1ab60517 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -1105,6 +1105,14 @@ HttpResponseWorker (
       HttpInstance->CacheLen = BodyLen;
     }
 
+    //
+    // Check server's HTTP version.
+    //
+    if (AsciiStrnCmp (HttpHeaders, HTTP_VERSION, AsciiStrLen (HTTP_VERSION)) != 0) {
+      DEBUG ((DEBUG_WARN, "HTTP: Server version is not 1.1. Setting Connection close.\n"));
+      HttpInstance->ConnectionClose = TRUE;
+    }
+
     //
     // Search for Status Code.
     //
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring
  2022-03-04 13:34 ` [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring Oliver Steffen
@ 2022-03-07 11:52   ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2022-03-07 11:52 UTC (permalink / raw)
  To: devel, osteffen

On Fri, Mar 04, 2022 at 02:34:28PM +0100, Oliver Steffen wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
> 
> Check if the state of the HTTP instance is HTTP_STATE_TCP_CONNECTED, or
> HTTP_STATE_TCP_CLOSED and de-configure the Tcp4 instance before
> configuring it again.
> 
> Signed-off-by: Oliver Steffen <osteffen@redhat.com>
> ---
>  NetworkPkg/HttpDxe/HttpProto.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
> index 9457dd2623..cd54c57404 100644
> --- a/NetworkPkg/HttpDxe/HttpProto.c
> +++ b/NetworkPkg/HttpDxe/HttpProto.c
> @@ -1086,6 +1086,18 @@ HttpConfigureTcp4 (
>    Tcp4Option->EnableNagle       = TRUE;
> 
>    Tcp4CfgData->ControlOption    = Tcp4Option;
> 
>  
> 
> +  if ((HttpInstance->State == HTTP_STATE_TCP_CONNECTED) ||
> 
> +      (HttpInstance->State == HTTP_STATE_TCP_CLOSED))

Line breaks are mangled, probably due to edk2 using dos/windows
style linebreaks.

Running BaseTools/Scripts/SetupGit.py once should update the git
configuration according.

Otherwise the patch looks good to me.

take care,
  Gerd


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] [PATCH 2/4] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL
  2022-03-04 13:34 ` [PATCH 2/4] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL Oliver Steffen
@ 2022-03-07 11:55   ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2022-03-07 11:55 UTC (permalink / raw)
  To: devel, osteffen

  Hi,

> -      if ((HttpInstance->RemotePort == RemotePort) &&
> 
> +      if ((HttpInstance->ConnectionClose == FALSE) &&
> 
> +          (HttpInstance->RemotePort == RemotePort) &&

Adding a check for the port makes sense, but that change should also be
mentioned in the commit message (or splitted into a separate patch, but
that's probably overkill for a one-liner).

take care,
  Gerd


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] [PATCH 3/4] NetworkPkg/HttpDxe: Detect 'Connection: close' header
  2022-03-04 13:34 ` [PATCH 3/4] NetworkPkg/HttpDxe: Detect 'Connection: close' header Oliver Steffen
@ 2022-03-07 11:59   ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2022-03-07 11:59 UTC (permalink / raw)
  To: devel, osteffen

On Fri, Mar 04, 2022 at 02:34:30PM +0100, Oliver Steffen wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
> 
> Force connecton close before the next request if
> the server sends the 'Connection: close' header.
> 
> Signed-off-by: Oliver Steffen <osteffen@redhat.com>
> ---
>  NetworkPkg/HttpDxe/HttpImpl.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
> index d8b014c94f..a1a3eea585 100644
> --- a/NetworkPkg/HttpDxe/HttpImpl.c
> +++ b/NetworkPkg/HttpDxe/HttpImpl.c
> @@ -994,6 +994,7 @@ HttpResponseWorker (
>    UINTN             HdrLen;
> 
>    NET_FRAGMENT      Fragment;
> 
>    UINT32            TimeoutValue;
> 
> +  UINTN             index;

Should be "Index" (edk2 codestyle).

> +        if ((AsciiStriCmp ("Connection", HttpMsg->Headers[index].FieldName) == 0) &&
> 
> +            (AsciiStriCmp ("close", HttpMsg->Headers[index].FieldValue) == 0))
> 
> +        {
> 
> +          DEBUG ((DEBUG_WARN, "Http: 'Connection: close' header received.\n"));

I'd suggest to use DEBUG_VERBOSE here.

Otherwise the patch looks good to me.

take care,
  Gerd


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] [PATCH 4/4] NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers
  2022-03-04 13:34 ` [PATCH 4/4] NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers Oliver Steffen
@ 2022-03-07 12:07   ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2022-03-07 12:07 UTC (permalink / raw)
  To: devel, osteffen

On Fri, Mar 04, 2022 at 02:34:31PM +0100, Oliver Steffen wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
> 
> Force connecton close before the next request if
> the server does not identify as version 1.1.
> 
> Signed-off-by: Oliver Steffen <osteffen@redhat.com>
> ---
>  NetworkPkg/HttpDxe/HttpImpl.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
> index a1a3eea585..ea1ab60517 100644
> --- a/NetworkPkg/HttpDxe/HttpImpl.c
> +++ b/NetworkPkg/HttpDxe/HttpImpl.c
> @@ -1105,6 +1105,14 @@ HttpResponseWorker (
>        HttpInstance->CacheLen = BodyLen;
> 
>      }
> 
>  
> 
> +    //
> 
> +    // Check server's HTTP version.
> 
> +    //
> 
> +    if (AsciiStrnCmp (HttpHeaders, HTTP_VERSION, AsciiStrLen (HTTP_VERSION)) != 0) {

Better explicitly check for 1.0 here?  That is the special case we are
looking for here: http/1.0 has no pipelining, so we close the connection
in that case.

As long as edk2 has no support for http/2.0 it doesn't make a difference
in practice though.

> +      DEBUG ((DEBUG_WARN, "HTTP: Server version is not 1.1. Setting Connection close.\n"));

Same here, should better use DEBUG_VERBOSE.

take care,
  Gerd


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-03-07 12:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-04 13:34 [PATCH 0/4] Http Fixes Oliver Steffen
2022-03-04 13:34 ` [PATCH 1/4] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring Oliver Steffen
2022-03-07 11:52   ` [edk2-devel] " Gerd Hoffmann
2022-03-04 13:34 ` [PATCH 2/4] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL Oliver Steffen
2022-03-07 11:55   ` [edk2-devel] " Gerd Hoffmann
2022-03-04 13:34 ` [PATCH 3/4] NetworkPkg/HttpDxe: Detect 'Connection: close' header Oliver Steffen
2022-03-07 11:59   ` [edk2-devel] " Gerd Hoffmann
2022-03-04 13:34 ` [PATCH 4/4] NetworkPkg/HttpDxe: Detect non-HTTP/1.1 servers Oliver Steffen
2022-03-07 12:07   ` [edk2-devel] " Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox