Comparison Operators

Reference guide for comparison operators used in policy and handler conditions and condition clauses.

Comparison operators are used in condition rules (for policies and handlers) and if clauses. A condition rule consists of a namespace attribute, comparison operator, and one or more values to compare.

If you are looking for the assignment operators used in modify blocks, see the modify action documentation.

Supported Operators

Equality Operators

OperatorAliasDescription
==eqEqual
!=neNot equal

Relational Operators

OperatorAliasDescription
>gtGreater than
>=geGreater than or equal
<ltLess than
<=leLess than or equal

String Matching Operators

OperatorDescription
startsText representation starts with
!startsText representation does not start with
containsText representation contains
!containsText representation does not contain
endsText representation ends with
!endsText representation does not end with

Regular Expression Matching

Regular expressions are specified using /pattern/ literal syntax with the == or != operators:

SyntaxDescription
== /pattern/Value matches the regular expression pattern
== /pattern/iCase-insensitive regular expression match
!= /pattern/Value does not match the regular expression

Operator Details

Equal (== or eq)

Matches values that are exactly equal. Works with all data types including strings, numbers, booleans, and IP addresses.

Examples:

if all {
    aaa.accounting == false;
    radius.request.attr.User-Name == "admin";
    radius.request.attr.NAS-Port == 1234;
} then {
    # Actions when conditions match
}

Not Equal (!= or ne)

Matches values that are not equal. The inverse of the equal operator.

Examples:

conditions any {
    aaa.method != "eap";
    radius.request.attr.NAS-IP-Address != "10.0.0.1";
    radius.request.attr.Service-Type != 1;
}

Greater Than (> or gt)

Matches values that are numerically or lexicographically greater than the specified value. Works with numbers and strings.

Examples:

if all {
    radius.request.attr.Session-Timeout > 3600;
    vars.priority > 5;
} then {
    # Actions when conditions match
}

Greater Than or Equal (>= or ge)

Matches values that are greater than or equal to the specified value.

Examples:

conditions any {
    radius.request.attr.Acct-Session-Time >= 300;
    vars.user_level >= 10;
}

Less Than (< or lt)

Matches values that are numerically or lexicographically less than the specified value.

Examples:

if all {
    radius.request.attr.Idle-Timeout < 600;
    vars.retry_count < 3;
} then {
    # Actions when conditions match
}

Less Than or Equal (<= or le)

Matches values that are less than or equal to the specified value.

Examples:

conditions any {
    radius.request.attr.Acct-Input-Octets <= 1000000;
    vars.connection_limit <= 100;
}

Starts With (starts)

Matches string values where the text representation starts with the specified substring. Case-sensitive.

Examples:

if all {
    radius.request.attr.User-Name starts "admin";
    radius.request.attr.Called-Station-Id starts "00:11:22";
} then {
    # Actions when conditions match
}

Contains (contains)

Matches string values where the text representation contains the specified substring. Case-sensitive.

Examples:

if all {
    radius.request.attr.User-Name contains "@example.com";
    radius.request.attr.NAS-Identifier contains "switch";
} then {
    # Actions when conditions match
}

Ends With (ends)

Matches string values where the text representation ends with the specified substring. Case-sensitive.

Examples:

if all {
    radius.request.attr.User-Name ends "@domain.com";
    radius.request.attr.Called-Station-Id ends ":SSID";
} then {
    # Actions when conditions match
}

Does Not Start With (!starts)

Matches string values where the text representation does not start with the specified substring. Case-sensitive.

Examples:

if all {
    # Reject test accounts
    radius.request.attr.User-Name !starts "test_";
    # Skip devices with specific OUI
    radius.request.attr.Called-Station-Id !starts "00:11:22";
} then {
    # Actions when conditions match
}

Does Not Contain (!contains)

Matches string values where the text representation does not contain the specified substring. Case-sensitive.

Examples:

if all {
    # Exclude guest accounts
    radius.request.attr.User-Name !contains "guest";
    # Skip certain NAS identifiers
    radius.request.attr.NAS-Identifier !contains "legacy";
} then {
    # Actions when conditions match
}

Does Not End With (!ends)

Matches string values where the text representation does not end with the specified substring. Case-sensitive.

Examples:

if all {
    # Exclude external domains
    radius.request.attr.User-Name !ends "@external.com";
    # Skip certain SSID types
    radius.request.attr.Called-Station-Id !ends ":GUEST";
} then {
    # Actions when conditions match
}

Regular Expression Match (== /pattern/)

Matches string values against a regular expression pattern using /pattern/ literal syntax. Uses Rust regex syntax.

Examples:

if all {
    # Match usernames starting with lowercase letters followed by @
    radius.request.attr.User-Name == /^[a-z]+@/;
    # Match MAC address format
    radius.request.attr.Called-Station-Id == /^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/;
} then {
    # Actions when conditions match
}

Case-Insensitive Match (== /pattern/i)

Add the i flag after the closing slash for case-insensitive matching:

if all {
    # Case-insensitive match
    radius.request.attr.User-Name == /admin.*/i;
} then {
    # Matches "admin", "ADMIN", "Admin", etc.
}

Does Not Match (!= /pattern/)

Use != with a regex literal to reject values that match the pattern:

conditions any {
    # Reject usernames that look like test accounts
    radius.request.attr.User-Name != /^test[0-9]*@/;
}

Special Values

In addition to literal values, conditions support special keyword values:

ValueDescription
anyMatches any existing value (variable/attribute is set)
noneMatches only when the value does not exist (not set)
trueBoolean true
falseBoolean false
nowCurrent timestamp (for time-based comparisons)

Presence Checks with any and none

Use any and none to check whether a variable or attribute exists, regardless of its value:

Examples:

# Check if variable is set (has any value)
if all {
    vars.load_limit_reason == any;
} then {
    discard;
}

# Check if variable is NOT set
if all {
    vars.session_key == none;
} then {
    reject;
}

# Check if optional RADIUS attribute exists
if all {
    radius.request.attr.Framed-IP-Address == any;
} then {
    # Attribute is present
}

These are especially useful when:

  • A Lua script conditionally sets a variable
  • A backend query may or may not return a value
  • Checking for optional RADIUS attributes

Note: Comparing with empty string (vars.foo != "") only works when the variable is set. Use == any or == none for reliable presence checks.

Multiple Values

Operators can compare against multiple values using array syntax. The condition matches if the comparison is true for any of the provided values.

Example:

conditions any {
    # Match if NAS-Port-Type is any of these values
    radius.request.attr.NAS-Port-Type == [15, 19, 20];

    # Match if User-Name starts with any of these prefixes
    radius.request.attr.User-Name starts ["admin", "root", "system"];
}

Usage in Conditions

Comparison operators are used in condition blocks with matching strategies:

  • all: All condition rules must match
  • any: Any condition rule must match
  • none: None of the condition rules must match

Example:

policy "example" {
    handler "wireless" {
        conditions all {
            aaa.authentication == true;
            radius.request.attr.NAS-Port-Type == 19;  # Wireless-802.11
            radius.request.attr.User-Name !starts "guest-";
        }

        authentication {
            backend "ldap";
            pap;
        }
    }
}