# Compare a variable to a list

**URL:** <https://community.f5.com/t/compare-a-variable-to-a-list/28464>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [June 25, 2009, 2:03pm UTC](https://community.f5.com/t/compare-a-variable-to-a-list/28464 "2009-06-25T14:03:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathew\_58739](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mathew\_58739](https://community.f5.com/u/Mathew_58739)\
**Post date:** [June 25, 2009, 2:03pm UTC](https://community.f5.com/t/compare-a-variable-to-a-list/28464/1 "2009-06-25T14:03:00Z")

</div>

I have an issue with my iRule. I am attepmting to compare a variable value to a white list of values. I have written the following iRule. However, if I place more than one value in my DataGroup, the iRule fails. Is there another way to compare a variable to a DataGroup list?

when RULE\_INIT {

set appidresponse {

Application Code Error 551

Your SSL MA negotiation used an unauthorized Client Application ID.

Please validate your client certificate. (Error Code:551)

}

}

when CLIENTSSL\_CLIENTCERT {

set client\_cert [SSL::cert 0]

set appidcode [findstr [X509::subject $client\_cert] “OU=” 10 “,”]

session add ssl [SSL::sessionid] $appidcode

log local0. “Application Code = $appidcode”

}

when HTTP\_REQUEST {

set appid [session lookup ssl [SSL::sessionid]]

if {$appid != [lindex $::app\_id 0]}{

log local0. “Failed App ID 551: [IP::client\_addr] & [X509::subject $client\_cert]”

HTTP::respond 551 content [subst $::appidresponse]

}

elseif {$appid == [lindex $::app\_id 0]}{

HTTP::header insert APPCERTID: “$appid”

}

}

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [June 25, 2009, 3:37pm UTC](https://community.f5.com/t/compare-a-variable-to-a-list/28464/2 "2009-06-25T15:37:40Z")

</div>

Hi,

You can use matchclass ([Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/matchclass)) for a datagroup or list.

Aaron

---

<div class="post-metadata">

**Author:** ![Mathew\_58739](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mathew\_58739](https://community.f5.com/u/Mathew_58739)\
**Post date:** [June 25, 2009, 3:48pm UTC](https://community.f5.com/t/compare-a-variable-to-a-list/28464/3 "2009-06-25T15:48:13Z")

</div>

I tried to use the matchclass command initially. However, it doesn’t appear that the matchclass command will allow me to compare a variable to alist. One of the values used must be a fixed or specified value. The iRule engine keeps giving me the error that all variables must be proceeded by a $. But my syntax is correct according to examples. Here is my sample line…

set appid [session lookup ssl [SSL::sessionid]]

if {matchclass “$appid” != $::app\_id}{

I have tried both removing and including quotes, brackets and braces to isolate the different components. It seems that the matchclass command must have one variable and one known value.

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [June 25, 2009, 8:06pm UTC](https://community.f5.com/t/compare-a-variable-to-a-list/28464/4 "2009-06-25T20:06:06Z")

</div>

How about:

if {not ([matchclass $appid equals $::app\_id])}{

Aaron
