Forum Discussion
Shay_Ben-David1
Nimbostratus
Oct 18, 2006how to log source ip connections?
i have used the irule for limit connection from one source ip vip in the bigip, this irule also logs each source ip that opend more than X connections, that the irule set.
i would like to log the source ip that pass the X connections and will also includes how many connections this source opend.
when RULE_INIT {
array set ::active_clients { }
array set white_client {
x.x.x.x
y.y.y.y
}
}
when CLIENT_ACCEPTED {
set client_ip [IP::remote_addr]
if { [info exists ::active_clients($client_ip)] && ![info exist ::white_client($client_ip)] } {
if {$::active_clients($client_ip) > 50 } {
reject
log "Alert! Multiple connections to mysite.com$client_ip ($::active_clients($client_ip))"
return
} else {
incr ::active_clients($client_ip)
}
} else {
set ::active_clients($client_ip) 1
}
}
when CLIENT_CLOSED {
set client_ip [IP::remote_addr]
if { [info exists ::active_clients($client_ip)] && ![info exist ::white_client($client_ip)] } {
incr ::active_clients($client_ip) -1
if { $::active_clients($client_ip) <= 0 } {
unset ::active_clients($client_ip)
}
}
}
- Shay_Ben-David1
Nimbostratus
Hi, actually i am asking for help, what happen now with this irule, is that it logs the source ip and the connections, but it logs only the " >50" meaning that it show on the log only the 51 connections, what i would like is that it will log the amount of real connections that this source try to open. let say if a source ip is trying to open 2000 simultaneous connections, i want it to be in the log and show how many connection this source is trying to open. - Shane_Benting_5
Nimbostratus
I don't think there is a way to tell how many connections they are trying and block the excess connections, since the it will decrement the counter when the connection is rejected (i.e. CLIENT_CLOSED). However, the script below (modified from yours) will generate a warning if the connections exceed the threshold.when RULE_INIT { array set ::active_clients { } array set white_client { x.x.x.x y.y.y.y } } when CLIENT_ACCEPTED { set client_ip [IP::remote_addr] if { [info exists ::active_clients($client_ip)] && ![info exist ::white_client($client_ip)] } { if {$::active_clients($client_ip) > 50 } { incr ::active_clients($client_ip) reject log "Alert! $::active_clients($client_ip) connections to mysite.com from $client_ip" return } else { incr ::active_clients($client_ip) } } else { set ::active_clients($client_ip) 1 } } when CLIENT_CLOSED { set client_ip [IP::remote_addr] if { [info exists ::active_clients($client_ip)] && ![info exist ::white_client($client_ip)] } { incr ::active_clients($client_ip) -1 if { $::active_clients($client_ip) <= 0 } { unset ::active_clients($client_ip) } } }
- Shay_Ben-David1
Nimbostratus
Thanks you very much, it works fine. - Deb_Allen_18Historic F5 AccountSeems that your iRule would work applied to a forwarding virtual server -- what happens?
- Shay_Ben-David1
Nimbostratus
i try using it on the forwarding vip, and all nodes went down, couldn't investigate it because its a production system, do u have any idea why ? - Deb_Allen_18Historic F5 AccountNo clue. That's pretty odd.
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