Forum Discussion

mr_evil_116524's avatar
mr_evil_116524
Icon for Nimbostratus rankNimbostratus
Jan 10, 2014

Source destination irule

Hello All,

I am trying to do source to destination iRULe not sure what I am doing below is my iRULE:

when CLIENT_ACCEPTED {
            if { [IP::addr [IP::client_addr] equals vm1 ] ||  [IP::addr [IP::client_addr] equals vm2 ] && [IP::addr [IP::local_addr] equals remote ip] } {
            if { [matchclass [TCP::local_port] equals tcp_DG ] || [matchclass [UDP::local_port] equals udp_DG] } {
         snat using this source address
            snatpool Public_internet_pool
                log local0. "SNATed, [IP::client_addr]:[TCP::client_port] --> [IP::local_addr]:[TCP::local_port]"
        Exit this event to avoid disabling SNAT below
            return
        }
        }
   Default action is to not SNAT
  snat none
log local0. "Not Allowed to SNATed , [IP::client_addr]:[TCP::client_port] --> [IP::local_addr]:[TCP::local_port]"
}

Any help will be great.

Thanks

5 Replies

  • You need brackets in your if statement, as the && takes precedence over the ||. Could that be your problem?

    if { ([IP::addr [IP::client_addr] equals vm1 ] || [IP::addr [IP::client_addr] equals vm2 ] )
         && [IP::addr [IP::local_addr] equals remote ip] } { 
    
    • uni_87886's avatar
      uni_87886
      Icon for Cirrostratus rankCirrostratus
      PS, if you're posting code, highlight it and click the Preformatted Code button. It makes it much easier to read
  • uni's avatar
    uni
    Icon for Altocumulus rankAltocumulus

    You need brackets in your if statement, as the && takes precedence over the ||. Could that be your problem?

    if { ([IP::addr [IP::client_addr] equals vm1 ] || [IP::addr [IP::client_addr] equals vm2 ] )
         && [IP::addr [IP::local_addr] equals remote ip] } { 
    
    • uni's avatar
      uni
      Icon for Altocumulus rankAltocumulus
      PS, if you're posting code, highlight it and click the Preformatted Code button. It makes it much easier to read
  • Thanks UNI, that seemed to work BTW I try to format earlier but didnt work. I have fixed that.