| 1 |
= The update Statement |
| 2 |
|
| 3 |
.Syntax |
| 4 |
[source,unlang] |
| 5 |
---- |
| 6 |
update [ <list> ] { |
| 7 |
<server-attribute> <op> <value> |
| 8 |
... |
| 9 |
} |
| 10 |
---- |
| 11 |
|
| 12 |
The `update` statement adds attributes to, or edits the attributes in, |
| 13 |
the named _<list>_. |
| 14 |
|
| 15 |
The `update` statement consists of the following syntax elements: |
| 16 |
|
| 17 |
<list>:: The attribute list which will be updated. The list is |
| 18 |
usually `request`, `reply`, or `control`. |
| 19 |
+ |
| 20 |
If the _<list>_ qualifier is omitted, then each entry inside of the |
| 21 |
`update` section *must* be prefixed with a list name. For example, |
| 22 |
`&request.User-Name ...` |
| 23 |
|
| 24 |
<server-attribute>:: The server attribute which is assigned the |
| 25 |
_<value>_. |
| 26 |
|
| 27 |
<op>:: The operator such as `=`, `:=`, etc. |
| 28 |
|
| 29 |
<value>:: The value which is assigned to the attribute. If the field |
| 30 |
is a double-quoted string, it undergoes xref:xlat/index.adoc[string |
| 31 |
expansion], and the resulting value is assigned to the attribute. |
| 32 |
|
| 33 |
The update process is atomic, in that either all of the attributes are |
| 34 |
modified, or none of them are modified. If the `update` fails for any |
| 35 |
reason, then all of the results are discarded, and the `update` does |
| 36 |
not affect any server attributes. |
| 37 |
|
| 38 |
.Example |
| 39 |
[source,unlang] |
| 40 |
---- |
| 41 |
update reply { |
| 42 |
&Reply-Message := "Hello!" |
| 43 |
&Framed-IP-Address := 192.0.2.4 |
| 44 |
} |
| 45 |
---- |
| 46 |
|
| 47 |
== Lists |
| 48 |
|
| 49 |
The _<list>_ field sets the attribute list that will be updated. If |
| 50 |
the _<list>_ qualifier is omitted, then each entry inside of the |
| 51 |
`update` section *must* be prefixed with a list name. For example, |
| 52 |
`&request.User-Name ...` |
| 53 |
|
| 54 |
Please see the xref:list.adoc[list] page for valid list names. |
| 55 |
|
| 56 |
== Server Attributes |
| 57 |
|
| 58 |
The _<server-attribute>_ field is an attribute name, such as |
| 59 |
`&Reply-Message`. The attribute name may also be prefixed with a |
| 60 |
_<list>_ qualifier, which overrides the _<list>_ given at the start |
| 61 |
of the `update` section. |
| 62 |
|
| 63 |
NOTE: In version 3, the leading `&` is optional but recommended. |
| 64 |
|
| 65 |
== Editing Operators |
| 66 |
|
| 67 |
The `<op>` field is used to define how the attribute is processed. |
| 68 |
Different operators allow attributes to be added, deleted, or |
| 69 |
replaced, as defined below. |
| 70 |
|
| 71 |
.Editing Operators |
| 72 |
[options="header"] |
| 73 |
[cols="10%,90%"] |
| 74 |
|===== |
| 75 |
| Operator | Description |
| 76 |
| = | Add the attribute to the list, if and only if an attribute of |
| 77 |
the same name is not already present in that list. |
| 78 |
| := | Add the attribute to the list. If any attribute of the same |
| 79 |
name is already present in that list, its value is replaced with the |
| 80 |
value of the current attribute. |
| 81 |
| += | Add the attribute to the tail of the list, even if attributes |
| 82 |
of the same name are already present in the list. |
| 83 |
| ^= | Add the attribute to the head of the list, even if attributes |
| 84 |
of the same name are already present in the list. |
| 85 |
| -= | Remove all attributes from the list that match _<value>_. |
| 86 |
| !* | Delete all occurances of the attribute, no matter what the value. |
| 87 |
|===== |
| 88 |
|
| 89 |
== Filtering Operators |
| 90 |
|
| 91 |
The following operators may also be used in addition to the ones |
| 92 |
listed above. These operators use the _<server-attribute>_ and |
| 93 |
_<value>_ fields to enforce limits on all attributes in the given |
| 94 |
_<list>_, and to edit attributes which have a matching |
| 95 |
_<server-attribute>_ name. All other attributes are ignored. |
| 96 |
|
| 97 |
.Filtering Operators |
| 98 |
[options="header] |
| 99 |
[cols="10%,90%"] |
| 100 |
|===== |
| 101 |
| Operator | Description |
| 102 |
| == | Keep only the attributes in the list that match _<value>_ |
| 103 |
| < | Keep only the attributes in the list that have values less than _<value>_. |
| 104 |
| \<= | Keep only the attributes in the list that have values less than or equal to _<value>_. |
| 105 |
| > | Keep only the attributes in the list that have values greater than _<value>_. |
| 106 |
| >= | Keep only the attributes in the list that have values greater than or equal to _<value>_. |
| 107 |
| =~ | Keep only the attributes in the list which match the regular expression given in _<value>_. |
| 108 |
| !~ | Keep only the attributes in the list which do not match the regular expression given in _<value>_. |
| 109 |
|===== |
| 110 |
|
| 111 |
The `==` operator is very different from the `=` operator listed |
| 112 |
above. The `=` operator is used to add new attributes to the list, |
| 113 |
while the `==` operator removes all attributes that do not match the |
| 114 |
given value. |
| 115 |
|
| 116 |
The comparison operators `<`, `<=`, `>`, and `>=` have some additional |
| 117 |
side effects. Any non-matching value is replaced by the _<value>_ |
| 118 |
given here. If no attribute exists, it is created with the given |
| 119 |
_<value>_. |
| 120 |
|
| 121 |
For IP addresses, the operators `>`, `>=`, `<`, and `\<=` check for |
| 122 |
membership in a network. The _<value>_ field should then be a IP |
| 123 |
network, given in `address/mask` format. |
| 124 |
|
| 125 |
.Example |
| 126 |
[source,unlang] |
| 127 |
---- |
| 128 |
update reply { |
| 129 |
&Session-timeout := 86400 |
| 130 |
} |
| 131 |
---- |
| 132 |
|
| 133 |
.Example |
| 134 |
[source,unlang] |
| 135 |
---- |
| 136 |
update reply { |
| 137 |
&Reply-Message += "Rejected: Also, realm does not end with ac.uk" |
| 138 |
} |
| 139 |
---- |
| 140 |
|
| 141 |
== Values |
| 142 |
|
| 143 |
The _<value>_ field is the value which is assigned to the |
| 144 |
_<server-attribute>_. The interpretation of the _<value>_ field |
| 145 |
depends on the data type of the contents. For example, if the string |
| 146 |
`"192.0.2.1"` is assigned to an attribute of the `string` data type, |
| 147 |
then the result is an ASCII string containing that value. However, if |
| 148 |
the same string is assigned to an attribute of the `ipaddr` data type, |
| 149 |
then the result is a 32-bit IPv4 address, with binary value `0xc0000201`. |
| 150 |
|
| 151 |
.Example |
| 152 |
[source,unlang] |
| 153 |
---- |
| 154 |
update reply { |
| 155 |
&Session-Timeout <= 3600 |
| 156 |
} |
| 157 |
---- |
| 158 |
|
| 159 |
// Copyright (C) 2020 Network RADIUS SAS. Licenced under CC-by-NC 4.0. |
| 160 |
// Development of this documentation was sponsored by Network RADIUS SAS. |