]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add class columns / fields to queries
authorAlan T. DeKok <aland@freeradius.org>
Mon, 24 May 2021 14:27:56 +0000 (10:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 24 May 2021 14:27:56 +0000 (10:27 -0400)
for both accounting and postauth

raddb/mods-config/sql/main/sqlite/queries.conf
raddb/mods-config/sql/main/sqlite/schema.sql

index ef4131387813ef961e39f8f002ab6a322990152d..20e87a928a80f35888a7c2c5eac0332323b0ddbf 100644 (file)
 #
 sql_user_name = "%{User-Name}"
 
+#
+#  3.0.22 and later have a "class" column in the accounting table.
+#
+#  However, we do NOT want to break existing configurations by adding
+#  the Class attribute to the default queries.  If we did that, then
+#  systems using newer versions of the server would fail, because
+#  there is no "class" column in their accounting tables.
+#
+#  The solution to that is the following "class" subsection.  If your
+#  database has a "class" column for the various tables, then you can
+#  uncomment the configuration items here.  The queries below will
+#  then automatically insert the Class attribute into radacct,
+#  radpostauth, etc.
+#
+class {
+       #
+       #  Delete the '#' from all of the next 3 lines in order to
+       #  put the Class attribute into the various tables.
+       #
+       #  See also policy.d/accounting, and the "insert_acct_class"
+       #  policy.  You will need to list (or uncomment)
+       #  "insert_acct_class" in the "post-auth" section in order to
+       #  create a Class attribute.
+       #
+       column_name =  # ", class"
+       packet_xlat =  # ", '%{Class}'"
+       reply_xlat =   # ", '%{Reply:Class}'"
+}
+
 #######################################################################
 #  Query config:  Event-Timestamp
 #######################################################################
@@ -236,7 +265,8 @@ accounting {
                framedipv6address, \
                framedipv6prefix, \
                framedinterfaceid, \
-               delegatedipv6prefix"
+               delegatedipv6prefix \
+               ${..class.column_name}"
 
        type {
                accounting-on {
@@ -345,7 +375,8 @@ accounting {
                                        '%{Framed-IPv6-Address}', \
                                        '%{Framed-IPv6-Prefix}', \
                                        '%{Framed-Interface-Id}', \
-                                       '%{Delegated-IPv6-Prefix}')"
+                                       '%{Delegated-IPv6-Prefix}' \
+                                       ${....class.packet_xlat})"
 
                        #
                        #  When using "sql_session_start", you should comment out
@@ -448,7 +479,8 @@ accounting {
                                        '%{Framed-IPv6-Address}', \
                                        '%{Framed-IPv6-Prefix}', \
                                        '%{Framed-Interface-Id}', \
-                                       '%{Delegated-IPv6-Prefix}')"
+                                       '%{Delegated-IPv6-Prefix}' \
+                                       ${....class.packet_xlat})"
 
                        #
                        #  When using "sql_session_start", you should comment out
@@ -538,7 +570,8 @@ accounting {
                                        '%{Framed-IPv6-Address}', \
                                        '%{Framed-IPv6-Prefix}', \
                                        '%{Framed-Interface-Id}', \
-                                       '%{Delegated-IPv6-Prefix}')"
+                                       '%{Delegated-IPv6-Prefix}' \
+                                       ${....class.packet_xlat})"
 
                        #
                        #  When using "sql_session_start", you should comment out
@@ -603,10 +636,11 @@ post-auth {
 
        query = "\
                INSERT INTO ${..postauth_table} \
-                       (username, pass, reply, authdate) \
+                       (username, pass, reply, authdate ${..class.column_name}) \
                VALUES ( \
                        '%{SQL-User-Name}', \
                        '%{%{User-Password}:-%{Chap-Password}}', \
                        '%{reply:Packet-Type}', \
-                       '%S.%M')"
+                       '%S.%M' \
+                       ${..class.reply_xlat})"
 }
index bdbbfec27bbf8108539fe00c75dc41f04a88c298..d6277531a9a032976ce4c853f16a4198d314070a 100644 (file)
@@ -42,6 +42,15 @@ CREATE TABLE IF NOT EXISTS radacct (
        class varchar(64) default NULL
 );
 
+--
+--  You might not need all of these indexes.  It should be safe to
+--  delete indexes you do not use.  For example, if you're not using
+--  IPv6, you can delete the indexes on IPv6 attributes.
+--
+--  You MUST however leave the indexes needed by the server, which
+--  include username, acctstoptime, nasipaddress, acctstarttime, and
+--  acctuniqueid.
+--
 CREATE UNIQUE INDEX acctuniqueid ON radacct(acctuniqueid);
 CREATE INDEX username ON radacct(username);
 CREATE INDEX framedipaddress ON radacct (framedipaddress);
@@ -55,6 +64,7 @@ CREATE INDEX acctstarttime ON radacct(acctstarttime);
 CREATE INDEX acctinterval ON radacct(acctinterval);
 CREATE INDEX acctstoptime ON radacct(acctstoptime);
 CREATE INDEX nasipaddress ON radacct(nasipaddress);
+CREATE INDEX class ON radacct(class);
 
 --
 -- Table structure for table 'radcheck'
@@ -123,8 +133,11 @@ CREATE TABLE IF NOT EXISTS radpostauth (
        username varchar(64) NOT NULL default '',
        pass varchar(64) NOT NULL default '',
        reply varchar(32) NOT NULL default '',
-       authdate timestamp NOT NULL
+       authdate timestamp NOT NULL,
+       class varchar(64) default NULL
 );
+CREATE INDEX username ON radpostauth(username);
+CREATE INDEX class ON radpostauth(class);
 
 --
 -- Table structure for table 'nas'