Forum Discussion

Roy_Jee's avatar
Roy_Jee
Icon for Nimbostratus rankNimbostratus
Sep 19, 2019

Irule to differentiate source traffic

i have an issue regarding source traffic please assist.

 

Scenario:

 

VIP:10.10.50.100

 

Pool members :10.10.70.100 , 10.10.70.101

 

when traffic from user having last octet of ip in even number e.g 192.168.150.100 come it will go to 10.10.70.100 and when traffic from user having last octet of ip address in odd number e.g 192.168.150.101 come it will routed to 10.10.70.101.is it possible ?

 

Many Thanks .

IRULE :

 when CLIENT_ACCEPTED {

       set lastOctet [getfield [IP::client_addr] "." 4]

       if {($lastOctet % 2) == 0} {

           log local0. "$lastOctet is even"

           node 10.10.70.100

       } else {

           log local0. "$lastOctet is odd"

           node 10.10.70.101

       }

   }

 

Error in LTM logs :

TCL error: /Common/even-odd-x2go-irule <CLIENT_ACCEPTED> - can't use non-numeric string as operand of "%"    while executing "if {($lastOctet % 2) == 0} {            log local0. "$lastOctet is even"            node 10.10.70.100        }

3 Replies

  • Hi RoyMalik,

    Can you try this?

    when CLIENT_ACCEPTED {
    	set lastOctet [getfield [IP::client_addr] "." 4]
    	if {[expr $lastOctet % 2] == 0} {
    		log local0. "$lastOctet is even"
    		node 10.10.70.100
    	} else {
    		log local0. "$lastOctet is odd"
    		node 10.10.70.101
    	}
    }

    or you can use this iRule.

    when HTTP_REQUEST {
    	switch -glob [IP::client_addr] {
    		"*1" -
    		"*3" -
    		"*5" -
    		"*7" -
    		"*9" { node "nodeName_10.10.70.101" }
    		default { node "nodeName_10.10.70.100" }
    	}
    }
    • Roy_Jee's avatar
      Roy_Jee
      Icon for Nimbostratus rankNimbostratus

      Great .It worked with expr my bad .Really appreciate it.Thanks

       

    • Roy_Jee's avatar
      Roy_Jee
      Icon for Nimbostratus rankNimbostratus

      1 more thing what if 1 pool member is down and then LB route it o available member.

      what condition can be used ?

      like

      when LB_FAILED {

       pool my_pool

        LB::reselect

      }