Debian Codegraph @

doc/antora/modules/unlang/pages/attr.adoc

raw
1 = &Attribute References
2
3 Attributes may be referenced via the following syntax:
4
5 .Syntax
6 [source,unlang]
7 ----
8 &Attribute-Name
9 &Attribute-Name:TAG
10 &Attribute-Name[NUM]
11 &<list>:Attribute-Name
12 &<list>:Attribute-Name:TAG[NUM]
13 ----
14
15 The `&Attribute-Name` operator returns a reference to the named
16 attribute.
17
18 When used as an existence check in a condition, the condition
19 evaluates to `true` if the attribute exists. Otherwise, the condition
20 evaluates to `false`.
21
22 When used elsewhere, such as in xref:switch.adoc[switch], it returns
23 the value of the named attribute.
24
25 .Examples
26 [source,unlang]
27 ----
28 &User-Name
29 &NAS-IP-Address
30 ----
31
32 == Lists
33
34 The attribute reference can also be qualified with a
35 xref:list.adoc[list] reference. When no list is given, the server
36 looks in the input packet list for the named attribute.
37
38 .Examples
39
40 [source,unlang]
41 ----
42 &request:User-Name
43 &reply:NAS-IP-Address
44 ----
45
46 == Array References
47
48 Finding a particular attribute from multiple instances can be done via
49 an array reference.
50
51 .Syntax
52 [source,unlang]
53 ----
54 &Attribute-Name[<integer>]
55 ----
56
57 When an attribute appears multiple times in a list, this syntax allows
58 you to address the attributes as if they were array entries. The
59 `<integer>` value defines which attribute to address. The `[0]` value
60 refers to the first attributes, `[1]` refers to the second attribute,
61 etc.
62
63 .Examples
64 [source,unlang]
65 ----
66 &EAP-Message[1]
67 &reply:NAS-IP-Address[2]
68 ----
69
70 == Other Array indexes
71
72 The array syntax can be used for a few special cases, too.
73
74 .Syntax
75 [source,unlang]
76 ----
77 &Attribute-Name[#]
78 &Attribute-Name[*]
79 &Attribute-Name[n]
80 ----
81
82 These extra fields have the following definitions:
83
84 `#`::
85 Returns an integer which is the number of instances of this attribute.
86
87 `*`::
88 Returns all of the instances of the given attribute. This syntax can only be used in a xref:xlat/index.adoc[string expansion]. It will return all of the values of the attribute, separated by commas.
89
90 `n`::
91 Returns the last instance of the given attribute.
92
93 == Removing ambuguity from the configuration files
94
95 In most cases, the server uses the `&` character to distinguish
96 attribute names from other strings.
97
98 Without the `&`, it is more difficult to parse the configuration file
99 clearly. You could interpret a string as `hello-there`
100 either as a literal string "hello-there", or as a reference to an
101 attribute named `hello-there`.
102
103 Adding the leading `&` character means that attribute references are
104 now easily distinguishable from literal strings. The use of the leading
105 `&` character is highly recommended.
106
107
108 // Copyright (C) 2025 Network RADIUS SAS. Licenced under CC-by-NC 4.0.
109 // Development of this documentation was sponsored by Network RADIUS SAS.