Forum Discussion

Kim_Scarborough's avatar
Kim_Scarborough
Icon for Nimbostratus rankNimbostratus
Dec 01, 2005

iRule "domain" truncating

I've been using the iRule "domain" command in a variety of iRules. I've been having problems with it, and I finally figured out that it is truncating the last letter, for some reason. I created a special, simplified iRule to illustrate the problem:

when HTTP_REQUEST {
    if { [HTTP::host] ends_with "example.com" } {
        HTTP::respond 403 X-Domain [ domain [HTTP::host] 2 ]
    }
}

Here's an HTTP session transcript for the VIP with that iRule:

GET /poop HTTP/1.1
Host: www.example.com
HTTP/1.0 403 Forbidden
X-Domain: example.co
Server: BIG-IP
Connection: Keep-Alive
Content-Type: text/html
Content-Length: 0

Shouldn't "X-Domain" be returning "example.com", not "example.co"? Or is there something I've missed here?

4 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    I'm pretty sure the domain command should just return the domain parts that you specify. There shouldn't be any truncation that I know of.

     

     

    Is there a reason you're using "domain" in the example rather than just the HTTP::host variable, if you're looking for the full hostname anyway?

     

     

    Thanks,

     

    -Colin
  • I'm not looking for the full hostname. I only want the domain name to be returned. In this example, I want it to take "www.example.com" or "foo.bar.example.com" and have it return "example.com".

     

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    That's interesting. It certainly appears as though you're using the command properly. I'll have to take a look and see if I'm seeing the same behavior. What version are you running?

    In any event, I'd try this as a different solution for the time being:

    
    when HTTP_REQUEST {
        if { [HTTP::host] ends_with "example.com" } {
            HTTP::respond 403 X-Domain [join [lrange [split [HTTP::host] "."] end-1 end] "."]
        }
    }

    HTH,

    -Colin