OUR SITES NetworkRADIUS FreeRADIUS

The switch Statement

Syntax
switch <expansion> {
    case <match-1> {
        [ statements-1 ]
    }
    case <match-2> {
        [ statements-2 ]
    }
    case {
        [ statements-3 ]
    }
}

A switch statement causes the server to evaluate expansion, which can be an &Attribute-Name or data. The result is compared against match-1 and match-2 to find a match. If no string matches, then the server looks for the default case statement, which has no associated match.

The matching is done via equality. The switch statement is mostly syntactic sugar and is used to simplify the visual form of the configuration. It is mostly equivalent to the following use of if statements:

Nearly equivalent syntax
if (<expansion> == <match-1>) {
    [ statements-1 ]
}
elsif (<expansion> == <match-2>) {
    [ statements-2 ]
}
else {
    [ statements-3 ]
}

The only difference between the two forms is that for a switch statement, the expansion is evaluated only once. For the equivalent if statement, the expansion is evaluated again for every if.

If a matching case is found, the statements within that case are evaluated. If no matching case is found, the case section with no "match" is evaluated. If there is no such case { …​} subsection, then the switch statement behaves as if the case {…​} section was empty.

The match text for the case statement can be an &Attribute-Name or data.

No statement other than case can appear in a switch statement, and the case statement cannot appear outside of a switch statement.

Example
switch &User-Name {
    case "bob" {
        reject
    }

    case {
        ok
    }
}