Forum Discussion

Aforester_2020's avatar
Aforester_2020
Icon for Nimbostratus rankNimbostratus
Feb 03, 2012

redirect to pool member based on Subnet

I am very new to iRule creation. I have a group of subnets that need to be directed to a specific pool member when any traffic from them comes into the VIP.

 

 

Any help is appreciated!

 

 

 

 

 

  • e.g.

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when CLIENT_ACCEPTED {
            set vs "[IP::local_addr]:[TCP::local_port]"
    
            if {[IP::addr [IP::client_addr] equals 172.28.19.0/24]}{
                    pool foo1
            } else {
                    pool foo2
            }
    }
    
    when SERVER_CONNECTED {
            log local0. "[IP::client_addr]:[TCP::client_port] -> $vs -> [IP::server_addr]:[TCP::server_port]"
    }
    }
    [root@ve1023:Active] config  b pool foo1 list
    pool foo1 {
       members 200.200.200.101:80 {}
    }
    [root@ve1023:Active] config  b pool foo2 list
    pool foo2 {
       members 200.200.200.102:80 {}
    }
    
    [root@ve1023:Active] config  cat /var/log/ltm
    Feb  3 08:39:57 local/tmm info tmm[4369]: Rule myrule SERVER_CONNECTED: 172.28.19.80:50344 -> 172.28.19.79:80 -> 200.200.200.101:80
    Feb  3 08:40:11 local/tmm info tmm[4369]: Rule myrule SERVER_CONNECTED: 192.168.204.8:53455 -> 172.28.19.79:80 -> 200.200.200.102:80
    
  • Thank you. What does the set vs do? Do i edit that at all or do I just leave it as is? And if I need to do multiple subnets do I just repeat the line or would it be better to do a data group?

     

     

    Thanks again!

     

  • vs variable and SERVER_CONNECTED event are used for logging. please feel free to remove it.

    this is data group version.

    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when CLIENT_ACCEPTED {
            set vs "[IP::local_addr]:[TCP::local_port]"
    
            if {[class match -- [IP::client_addr] equals subnet_list]}{
                    pool foo1
            } else {
                    pool foo2
            }
    }
    
    when SERVER_CONNECTED {
            log local0. "[IP::client_addr]:[TCP::client_port] -> $vs -> [IP::server_addr]:[TCP::server_port]"
    }
    }
    [root@ve1023:Active] config  b class subnet_list list
    class subnet_list {
       network 172.28.19.0/24
    }
    
    [root@ve1023:Active] config  cat /var/log/ltm
    Feb  3 08:51:04 local/tmm info tmm[4369]: Rule myrule SERVER_CONNECTED: 172.28.19.80:59652 -> 172.28.19.79:80 -> 200.200.200.101:80
    Feb  3 08:51:07 local/tmm info tmm[4369]: Rule myrule SERVER_CONNECTED: 192.168.204.8:53813 -> 172.28.19.79:80 -> 200.200.200.102:80