FreeRADIUS InkBridge

The transaction Statement

Syntax
transaction {
    [ statements ]
}

The transaction statement collects a series of statements into a single transaction. If the block returns an error such as fail, reject, invalid, or disallow, any attribute changes which have been made will be reverted.

[ statements ]

The unlang commands which will be executed.

A transaction section should only contain attribute editing which is done via the edit statements, or conditions (if / else / elsif). It can also contain rcodes such as fail or ok.

Caveats

An Unlang transaction cannot undo operations on external databases. For example, any data which was inserted into sql during a transaction statement will remain in sql even if the Unlang transaction fails. This is because Unlang transactions are independent of any database transactions.

The transaction keyword sets its own return codes for fail, invalid, and disallow to be set the the priority 1, instead of the default return. This behavior means that a failed transaction will cause the interpreter to proceed to the next instruction, instead of returning.

Example

In this example, if the SQL select statement fails, then the reply.Framed-IP-Address attribute is not updated, and the statements inside of the transaction section will return fail. The assignment to reply.Framed-IP-Address will then be reverted.

transaction {
    string tmp

    tmp := %sql("SELECT ...")
    reply.Framed-IP-Address := 192.0.2.1

    if !tmp {
        fail
    }

    reply.Filter-Id := tmp
}

Note that edit statements do not fail if the right hand side expression fails. Instead, you must manually check if the assignment failed. The example above does this with an intermediate variable.

The last entry in a transaction section can also be an actions subsection. If set, those actions over-ride any previously set defaults.

Grouping Edits

The transaction keyword can be used to group multiple edit instructions. When edit instructions are grouped, then the edits are done in an atomic transaction. That is, either all of the edits succeed, or none of them do.

For now, the main purpose of transaction is to group edits. None of the modules support transactions. If a module is used inside of a transaction, the server will return an error, and will not start.