Forum Discussion
Scott_Larson
Nimbostratus
Jul 03, 2007Block until NAME::lookup returns?
For my iRule, I need to perform a reverse DNS lookup, and determine if a client IP is from a domain ending in .mil or .gov. This determines whether or not they need to authenticate. The authentication works fine; even the NAME::lookup works fine (thru much trial and tribulation due to lacking documentation!!!) The problem is that since NAME::lookup is an asynchronous function, I need to block (wait) all HTTP requests until the lookup returns and I can determine whether the client is or isn't from .mil/.gov. The lookup is quick - nearly immediate - but it's not synchronous.
How does one block until the NAME_RESOLVED event fires?
Or, is there a synchronous version of the NAME::lookup function? or a TCL version of the function that might work?
Or does anyone have any other ideas?
11 Replies
- Deb_Allen_18Historic F5 AccountYou'll want to run HTTP::collect before calling the NAME::lookup command, then call HTTP::release inside of the NAME_RESOLVED event.
- Scott_Larson
Nimbostratus
Unfortunately, that doesn't seem to do the trick. After my call to HTTP::collect, execution of the event handler continues on, and it "slips" into the rest of the iRule, which forces the user to authenticate if they're not from a .gov or .mil address. However, if it worked as planned, it'd block until the name resolved to blah.mil, then it'd know it should skip authentication. - Deb_Allen_18Historic F5 AccountNice job logging and debugging. This is exactly the way you should be approaching it.
- Scott_Larson
Nimbostratus
Ah yes, I thought of that too, and I tried that, but unfortunately that doesn't do it either, as the subsequent logic contains directives (HTTP and AUTH) which are not valid within the context of the NAME_RESOLVED event. Ghar!!!!! - Scott_Larson
Nimbostratus
btw I forgot to add, thanks for your help, all your ideas are good...I'm hopeful we can keep thinking of other innovative ways to solve this problem. - Deb_Allen_18Historic F5 AccountWell, there are ways to implement a wait loop, but don't -- it will lock up the thread and cause a watchdog reboot and failover if the name lookup takes too long.
- Deb_Allen_18Historic F5 AccountI like Spark's idea re: lookup in CLIENT_ACCEPTED better than mine re: using TCP::notify -- it's simpler, and more efficient, then you can use the result anywhere in the iRule at your leisure.
- spark_86682Historic F5 AccountActually, this version works better:
when CLIENT_ACCEPTED { set clientIP [IP::client_addr] set resolved 0 TCP::collect NAME::lookup $clientIP } when NAME_RESOLVED { set client_name "[NAME::response]" set resolved 1 TCP::release } when CLIENT_DATA { if { $resolved == 0 } { TCP::collect } else { TCP::release } }
- Scott_Larson
Nimbostratus
Spark & Deb, thanks so much for your dilligent assistance and innovative thinking. I have tried Spark's idea and it does seem to be working at first blush. THANKS SPARK! I will continue testing this tomorrow and will post again when I have some results to share. - Scott_Larson
Nimbostratus
Our testing confirms that this solution works like a champ. Thanks again, Deb and Spark!!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects