OUR SITES NetworkRADIUS FreeRADIUS

The if Statement

Syntax
if <condition> {
    [ statements ]
}
Description

The if statement evaluates a condition. When the <condition> evaluates to true, the statements within the subsection are executed. When the <condition> evaluates to false, those statements are skipped.

An if statement can optionally be followed by an else or an elsif statement.

Example
if (&User-Name == "bob") {
    reject
}

Practical Suggestions

There are a number of practical suggestions which make it easier to work with conditions.

Brackets are usually optional.

There is no need to put brackets around a <condition>. The following two examples work identically:

Example With Brackets
if (&User-Name == "bob") {
    reject
}

And without:

Example Without Brackes
if &User-Name == "bob" {
    reject
}

The same behavior applies to conditions with complex statements using && and ||. So long as the text between the if and the { is a valid condition, it will be parsed correctly.

Multi-line conditions

A <condition> can span multiple lines. There is no need to use \\ at the end of a line. The following condition is valid:

Example With Brackets
if (&User-Name ==
     "bob") {
    reject
}

Actions

The last entry in an if section can also be an actions subsection.