Forum Discussion

Chris_Phillips's avatar
Chris_Phillips
Icon for Nimbostratus rankNimbostratus
Dec 19, 2012

does class match always find the BEST match?

Hi folks,

 

 

This seems like an odd thing to not find in the wiki already, but if i'm doing a "class match starts_with" operation, will the BEST match always be found in the ist, i.e. the longest matchign string? I can't see any discussion in the wiki about what happens if there are multiple potential results.

 

 

So if I'm matching a url of "/one/two/three" against a class list containing "/one" and "/one/two", will "/one/two" ALWAYS be returned?

 

 

Thanks

 

Chris

 

6 Replies

  • I'm pretty sure it's the first match so if you were looking for starts_with /one and /one/two was first in the list it would match that. If you want it to be more exact you should make your match statement more exact (i.e make the search string more specific and/or use equals).
  • well I'm matching a uri stem, I can't make it any more specific by definition. The data is what it is.

     

     

    Actually though, I just noticed that there's a bit on the wiki class page in tmsh speak (which I still can't get my head around... what was wrong with lovely bigpipe?) which explicitly does cover this, proving a longest match criteria is used. v11 at least. Can this be confirmed also on v10?
  • I believe that only applies to IP classes but I'm still looking, standby...

     

    OK, can't find anything that confirms this for v10 or v11. Can anyone else help here?

     

  • Yes, the class command should return the longest match for starts_with or ends_with. I don't know about matchclass or findclass, but you could test this fairly easily.

     

     

     

    https://devcentral.f5.com/wiki/iRules.class.ashx

     

    Note: When using the equals operator on IP classes, or when using the starts_with or ends_with operators, if multiple possible matches are found in the class, then the longest match is always chosen. This is not true when using the contains operator. See the example below for more details.

     

     

     

    You also have the -all flag to return all matching keys, values or elements:

     

     

     

    -all If used with -index, -name, -value, -element, changes the return value to all of the matching class elements. (added in v11.0)

     

     

     

    Aaron
  • How on earth did I not see that???? I guess I was searching for "best match" not "longest match"... I impress myself sometimes!