Merge tag 'release_3_0_12' into branch moonshot-fr-3.0.12-upgrade.
[freeradius.git] / raddb / policy.d / accounting
1 # We check for this prefix to determine whether the class
2 # value was generated by this server.  It should be changed
3 # so that it is globally unique.
4 class_value_prefix = 'ai:'
5
6 #
7 #       Replacement for the old rlm_acct_unique module
8 #
9 acct_unique {
10         #
11         #  If we have a class attribute in the format
12         #  'auth_id:[0-9a-f]{32}' it'll have a local value
13         #  (defined by insert_acct_class), this ensures
14         #  uniqueness and suitability.
15         #
16         #  We could just use the Class attribute as
17         #  Acct-Unique-Session-Id, but this may cause problems
18         #  with NAS that carry Class values across between
19         #  multiple linked sessions.  So we rehash class with
20         #  Acct-Session-ID to provide a truely unique session
21         #  identifier.
22         #
23         #  Using a Class/Session-ID combination is more robust
24         #  than using elements in the Accounting-Request,
25         #  which may be subject to change, such as
26         #  NAS-IP-Address, Client-IP-Address and
27         #  NAS-Port-ID/NAS-Port.
28         #
29         #  This policy should ensure that session data is not
30         #  affected if NAS IP addresses change, or the client
31         #  roams to a different 'port' whilst maintaining its
32         #  initial authentication session (Common in a
33         #  wireless environment).
34         #
35         update request {
36                Tmp-String-9 := "${policy.class_value_prefix}"
37         }
38
39         if (("%{hex:&Class}" =~ /^%{hex:&Tmp-String-9}/) && \
40             ("%{string:&Class}" =~ /^${policy.class_value_prefix}([0-9a-f]{32})/i)) {
41                 update request {
42                         &Acct-Unique-Session-Id := "%{md5:%{1},%{Acct-Session-ID}}"
43                 }
44         }
45
46         #
47         #  Not All devices respect RFC 2865 when dealing with
48         #  the class attribute, so be prepared to use the
49         #  older style of hashing scheme if a class attribute
50         #  is not included
51         #
52         else {
53                 update request {
54                         &Acct-Unique-Session-Id := "%{md5:%{User-Name},%{Acct-Session-ID},%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}},%{NAS-Identifier},%{NAS-Port-ID},%{NAS-Port}}"
55                  }
56         }
57 }
58
59 #
60 #       Insert a (hopefully unique) value into class
61 #
62 insert_acct_class {
63         update reply {
64                 &Class = "${policy.class_value_prefix}%{md5:%t,%I,%{Packet-Src-Port},%{%{Packet-Src-IP-Address}:-%{Packet-Src-IPv6-Address}},%{NAS-IP-Address},%{Calling-Station-ID},%{User-Name}}"
65         }
66 }
67
68 #
69 #       Merges Acct-[Input|Output]-Octets and Acct-[Input|Output]-Gigawords into Acct-[Input|Output]-Octets64
70 #
71 #       If the &Attr-Foo doesn't exist, it's value is taken as zero.
72 #
73 acct_counters64.preacct {
74         update request {
75                 &Acct-Input-Octets64 = "%{expr:(&Acct-Input-Gigawords << 32) | &Acct-Input-Octets}"
76                 &Acct-Output-Octets64 = "%{expr:(&Acct-Output-Gigawords << 32) | &Acct-Output-Octets}"
77         }
78 }
79