Forum Discussion

sundogbrew's avatar
sundogbrew
Icon for Altocumulus rankAltocumulus
Jun 04, 2013

IP restriction irule

I found this old thread and am trying to make it work.

 

https://devcentral.f5.com/community/group/aft/18255/asg/50

 

here is what I have

 

 

when CLIENT_ACCEPTED {

 

if { not ([class match [IP::client_addr] equals $::ESB]) }{

 

Log dropped requests

 

log local0. "Invalid client IP: [IP::client_addr] - discarding"

 

 

drop the request

 

discard

 

}

 

}

 

 

Then in Data Group List I have

 

 

ESB

 

 

1.1.0.0/255.255.0.0 <-sanatized

 

 

When I put it in a virtual host and run it I get this error...

 

 

TCL error: /Common/esb-mgmt - can't read "ESB": no such variable while executing "class match [IP::client_addr] equals $ESB"

 

 

Its like it can't read the variable?

 

 

As always, any help is greatly appreciated!

 

Thanks

 

Joe

 

 

7 Replies

  • Hi Joe,

     

     

    Can you remove the $:: prefix from the data group name in the iRule?

     

     

     

    https://devcentral.f5.com/wiki/iRules.class.ashx

     

     

    Note that you should not use a $:: or :: prefix on the datagroup name when using the class command (or in any datagroup reference on 9.4.4 or later).

     

     

    In v9.4.4 - 10, using $::datagroup_name will work but demote the virtual server from running on all TMMs. For details, see the CMP compatibility page.

     

     

    In v11, using $::datagroup_name will result in a TCL runtime error and a reset being sent to the client!

     

  • Hey Hoolio,

     

    Thanks for the response. I did remove the $:: I am still not getting what I want? If I put an address in there that isn't mine and try to go to it I get a log message that it is blocked and tells me my IP. But if I put my IP in there I get nothing like it either drops it or doesn't do anything with it? I saw in the other post you said not to say forward? Do I need to say anything to get it to move the traffic on to the pool?

     

    Thanks

     

    Joe

     

  • I still can't get this to work, can anyone help? Looks like if it doesn't discard it then it doesn't work. Like the default doesn't do anything? Does that make sense?

     

    This is what I have, do I need an "else" or something else?

     

     

    when CLIENT_ACCEPTED {

     

    if {!( [class match [IP::client_addr] equals ESB]) }{

     

    Log dropped requests

     

    log local0. "Invalid client IP: [IP::client_addr] - discarding"

     

     

    drop the request

     

    discard

     

    }

     

    }

     

     

     

    Thanks

     

    Joe
  • Does it discard as required? Are you using an address-based data group?

    
    when CLIENT_ACCEPTED {
        if { not ( [class match [IP::client_addr] equals ESB] ) } {
             Log dropped requests
            log local0. "Invalid client IP: [IP::client_addr] - discarding"
            drop the request
            discard
        }
    } 
    
  • Hey Kevin,

     

    Yes I have an address-based data group. If I don't put my address in the list and try to go to it, it drops my request and logs it and tells me my IP, so that part works fine. But if I put my address in the list I get nothing in the logs and I also don't get the page? Like it drops it anyway but just doesn't log it? Do I need to say forward or include the pool?
  • You shouldn't have to do anything. What happens if you completely remove the iRule? Do you have a default pool assigned to the VIP?
  • SON OF A... I think I have been fighting the idiot in the chair here, no winning against him. I had my persistence messed up and once I changed it to cookie it works now.

     

    Thank you Kevin and Hoolio.

     

    Joe