101 connection reset

Hi all.

Firstly, i have to thank to all contributors in this forum, because they’ve saved my life a lot of times.

Today i have a problem with one irule.

I am writing an irule that concern this concepts:

First. If the destiny does not contain an explicit domain and uri is empty, you have to redirect the request to some place, whit the source host as uri,

Second: If it has an uri, i have to replace the host with an especific host leave the original uri without modification.

As i’m spanish and i’m not sure if i’m explained me correctly there it go an example.

1.- I the domain it is not www.ejemplo.com and the uri have not content.

Example:

http://www.noejemplo.com/ --> http://www.ejemplo.com/noejemplo.com

2.- If the request content and uri:

Example:

http://www.noejemplo.com/xyz --> http://www.ejemplo.com/xyz

In my irule, the second part run perfectly but the first option give me an error “101 error connection reset”.

As you’ll see below i’ve put the response in a log to trace it.

I do not know if you had found some error like this.

This is my Irule:

when HTTP_REQUEST {

set host_debug 1

set newhost “www.ejemplo.com”

set hostname [getfield [HTTP::host] “:” 1]

set suri [getfield [HTTP::host] “:” 1]

set ouri [HTTP::uri]

if { (not ([HTTP::host] equals $newhost)) and (not ([HTTP::uri] equals “/”))

}

{

HTTP::header replace Host $newhost

if {$host_debug}{log local0. “[HTTP::host]: First Case: Replaced Host header with $newhost$ouri”}

}

elseif { (not ([HTTP::host] equals $newhost))

}

{

HTTP::header replace Host $newhost/$suri

if {$host_debug}{log local0. “[HTTP::host]: Second case: Replaced Host header with $newhost/$suri.”}

}

}

Sorry i’ve forgot something, Thanks in advance. :slight_smile:

Can you please clarify which part of the iRule is the first part (the problem) and which is the second?

Note that in this line, you are adding the URI to the HTTP Host header which you shouldn’t be doing;

HTTP::header replace Host $newhost/$suri

not sure if you want redirection or rewriting.

this is an example of redirection.

[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   set newhost "www.ejemplo.com"
   if { not ([HTTP::host] equals $newhost ) } {
      if { [HTTP::uri] equals "/" } {
         HTTP::redirect "http://$newhost/[string map {www. ""} [HTTP::host]]"
      } else {
         HTTP::redirect "http://$newhost[HTTP::uri]"
      }
   }
}
}

[root@ve10:Active] config  curl -I http://www.noejemplo.com/
HTTP/1.0 302 Found
Location: http://www.ejemplo.com/noejemplo.com
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve10:Active] config  curl -I http://www.noejemplo.com/xyz
HTTP/1.0 302 Found
Location: http://www.ejemplo.com/xyz
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

this is rewriting.

[root@ve10:Active] config  b virtual bar list
virtual bar {
   snat automap
   pool foo
   destination 172.28.19.79:80
   ip protocol 6
   rules myrule
   profiles {
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b pool foo list
pool foo {
   members 200.200.200.101:80 {}
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_REQUEST {
   set newhost "www.ejemplo.com"
   if { not ([HTTP::host] equals $newhost ) } {
      if { [HTTP::uri] equals "/" } {
         HTTP::header replace Host $newhost
         HTTP::uri "/[string map {www. ""} [HTTP::host]]"
      } else {
         HTTP::header replace Host $newhost
      }
   }
}
}

[root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
New TCP connection 1: 172.28.20.11(59583) <-> 172.28.19.79(80)
1351506625.0959 (0.0011)  C>S
---------------------------------------------------------------
HEAD / HTTP/1.1
User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: www.noejemplo.com

---------------------------------------------------------------

New TCP connection 2: 200.200.200.10(59583) <-> 200.200.200.101(80)
1351506625.0986 (0.0008)  C>S
---------------------------------------------------------------
HEAD /noejemplo.com HTTP/1.1
User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: www.ejemplo.com

---------------------------------------------------------------

[root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
New TCP connection 1: 172.28.20.11(59584) <-> 172.28.19.79(80)
1351506657.3599 (0.0012)  C>S
---------------------------------------------------------------
HEAD /xyz HTTP/1.1
User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: www.noejemplo.com

---------------------------------------------------------------

New TCP connection 2: 200.200.200.10(59584) <-> 200.200.200.101(80)
1351506657.3607 (0.0007)  C>S
---------------------------------------------------------------
HEAD /xyz HTTP/1.1
User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: www.ejemplo.com

---------------------------------------------------------------

Hi all,

The part of the irule that is not run correctly is:

elseif { (not ([HTTP::host] equals $newhost))

}

{

HTTP::header replace Host $newhost/$suri

if {$host_debug}{log local0. “[HTTP::host]: Second case: Replaced Host header with $newhost/$suri.”}

}

Answering to nitas,

We want to be transparent to the users, in this case we must to use replace instead of redirect.

Anyway thank so much for all, with your examples i’ve had enough to fix the behaviour of my irule.

Would you be so kind to say me what i was doing wrong?, in order to understand the issue.

Thanks in advance and kind regards.

Hi all,

The part of the irule that is not run correctly is:

elseif { (not ([HTTP::host] equals $newhost))

}

{

HTTP::header replace Host $newhost/$suri

if {$host_debug}{log local0. “[HTTP::host]: Second case: Replaced Host header with $newhost/$suri.”}

}

Answering to nitas,

We want to be transparent to the users, in this case we must to use replace instead of redirect.

Anyway thank so much for all, with your examples i’ve had enough to fix the behaviour of my irule.

Would you be so kind to say me what i was doing wrong?, in order to understand the issue.

Thanks in advance and kind regards.

Can you show us what you changed pleased and then we’ll be able to comment.

Hi Steve,

Following your instructions, i’ve modified my irule like this ussing the code of nitass:

when HTTP_REQUEST {

set newhost “www.ejemplo.com”

if { not ([HTTP::host] equals $newhost ) } {

if { [HTTP::uri] equals “/” } {

HTTP::header replace Host $newhost

HTTP::uri “/[string map {www. “”} [HTTP::host]]”

if {$host_debug}{log local0. “[HTTP::host]: First Case: Replaced Host header with $newhost”/[string map {www. “”} [HTTP::host]]“.”}

} else {

HTTP::header replace Host $newhost

if {$host_debug}{log local0. “[HTTP::host]: Second Case: Replaced Host header with $newhost”}

}

}

}

}

Then, my question is oriented to the old version of my irule.

When i tried to replace the irule with:

when HTTP_REQUEST {

set newhost “www.ejemplo.com”

Se usa solo en el caso dos

set hostname [getfield [HTTP::host] “:” 1]

set suri [getfield [HTTP::host] “:” 1]

set ouri [HTTP::uri]

if{ (not ([HTTP::host] equals $newhost)) and (not ([HTTP::uri] equals “/”))

}

{

HTTP::header replace Host $newhost

if {$host_debug}{log local0. “[HTTP::host]: First Case: Replaced Host header with $newhost$ouri.”}

}

elseif { (not ([HTTP::host] equals $newhost))

}

{

HTTP::header replace Host $newhost/$suri

if {$host_debug}{log local0. “[HTTP::host]: Second case: Replaced Host header with $newhost/$suri.”}

}

}

What am i doing wrong?, why am i getting “101 connection reset” when i tried HTTP::header replace Host $newhost/$suri in the second case.

Kind Regards.

i do not know why you got 101 connection reset. if host header is wrong, i think we should receive http 400 status code.

e.g.

[root@ve10:Active] config  curl -I http://200.200.200.101/something -H "Host: www.ejemplo.com/noejemplo.com"
HTTP/1.1 400 Bad Request
Date: Mon, 29 Oct 2012 12:47:23 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Content-Type: text/html; charset=iso-8859-1

What am i doing wrong?, why am i getting “101 connection reset” when i tried HTTP::header replace Host $newhost/$suri in the second case.

Like mentioned above… are you sure you want the HOST HEADER to contain $newhost/$suri ???

set hostname [getfield [HTTP::host] “:” 1]

set suri [getfield [HTTP::host] “:” 1]

set ouri [HTTP::uri]

what does “suri” mean?