Forum Discussion

Michael_Benzing's avatar
Michael_Benzing
Icon for Nimbostratus rankNimbostratus
Jan 26, 2014

Syntax of "switch" statement

I have seen some switch statements in our F5 rules that seem to be using "else" instead of the "default" keyword to catch all unmatched searches. Based on documentation, it would seem to me that the interpreter would merely attempt to match the string to "else" and fail instead of performing default action. My question is, is this an undocumented feature that works as the default keyword in F5? In other words, how does the interpreter treat the "else" statement in the example below?

 

when HTTP_REQUEST { switch -glob [HTTP::uri] { somesvc { drop } /mysvc* {pool my_pool_10010} / {redirect to https://somewhere.else.com/their_service} else { drop } } }

 

5 Replies

  • is this an undocumented feature that works as the default keyword in F5? In other words, how does the interpreter treat the "else" statement in the example below?

     

    isn't else interpreted as literal?

     

  • e.g.

    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule quux
    ltm rule quux {
        when HTTP_REQUEST {
      switch -glob [HTTP::uri] {
        somesvc { log local0. "[HTTP::uri] - somesvc"; return }
        /mysvc* { log local0. "[HTTP::uri] - /mysvc*"; return }
        / { log local0. "[HTTP::uri] - /"; return }
        else { log local0. "[HTTP::uri] - else"; return }
      }
      log local0. "[HTTP::uri] - not match"
    }
    }
    
    [root@ve11a:Active:In Sync] config  tail -f /var/log/ltm
    Jan 26 09:17:16 ve11a info tmm1[11129]: Rule /Common/quux : /mysvc/something - /mysvc*
    Jan 26 09:17:18 ve11a info tmm[11129]: Rule /Common/quux : /somethingelse - not match
    
    • Michael_Benzing's avatar
      Michael_Benzing
      Icon for Nimbostratus rankNimbostratus
      Thanks for the test results! My initial thoughts were that this was being treated as a literal and not a keyword.
  • e.g.

    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule quux
    ltm rule quux {
        when HTTP_REQUEST {
      switch -glob [HTTP::uri] {
        somesvc { log local0. "[HTTP::uri] - somesvc"; return }
        /mysvc* { log local0. "[HTTP::uri] - /mysvc*"; return }
        / { log local0. "[HTTP::uri] - /"; return }
        else { log local0. "[HTTP::uri] - else"; return }
      }
      log local0. "[HTTP::uri] - not match"
    }
    }
    
    [root@ve11a:Active:In Sync] config  tail -f /var/log/ltm
    Jan 26 09:17:16 ve11a info tmm1[11129]: Rule /Common/quux : /mysvc/something - /mysvc*
    Jan 26 09:17:18 ve11a info tmm[11129]: Rule /Common/quux : /somethingelse - not match
    
    • Michael_Benzing's avatar
      Michael_Benzing
      Icon for Nimbostratus rankNimbostratus
      Thanks for the test results! My initial thoughts were that this was being treated as a literal and not a keyword.