Large multiple "if" optimisation

Phil Mayers p.mayers at imperial.ac.uk
Wed Nov 20 18:33:13 CET 2013


On 20/11/13 16:57, Jonathan Gazeley wrote:

> It's getting a bit unwieldy to manage this block, so I'm looking for a
> better way of writing it. However it must be fast, as every eduroam user
> hits this, i.e. database lookups are unsatisfactory. Flat files might be

Shrug. We do a database lookup on source MAC, cached in an rlm_cache 
instance. It works fine. Get a faster database!

> ok depending on how they cached.

A "files" module is loaded into RAM and keyed into a hash table. It'll 
be lightning fast. Something like this:

modules {
   files uobmac {
     key = "%{UOB-Stripped-MAC}"
     filename = "..."
   }
}

...and in the file:

20:10:7a:1a:89:1d
	Fall-Through := Non

...the in unlang:

authorize {
   ...
   uobmac
   if (ok) {
     update control {
       UOB-Debug = "%{debug:9}"
     }
   }
   ...
}

However a "files" module is only reloaded on hup. If you want proper 
dynamism, use an SQL lookup and wrap it in rlm_cache e.g.

modules {
   cache uobdebug {
     ...
     key = "%{UOB-Stripped-MAC}"
     update {
       request {
         Tmp-String-0 := "%{sql:select 'y' from debugmacs where 
mac='%{UOB-Stripped-Mac}'}"
       }
    }
}

authorize {
   ...
   uobdebug
   if (Tmp-String-0 == "y") {
     update control {
       UOB-Debug = "%{debug:9}"
     }
   }
   ...
}


More information about the Freeradius-Users mailing list