Re: Module Statistics in freeradius

Himanshu Pandey pandey_himanshu80 at
Sat Sep 27 15:41:10 CEST 2014

Dear Alan,

I have completed my coding to achieve my task. I tried my best not to disturb much of the server code. Here is my code snippet. I request you to suggest me If my  added code is correct or wrong. Also, suggest me if there is any other best way to achieve this or you think my added can be optimized more.

/* Structure */

/**     Return codes indicating the result of the module call
 *  *
 *   *  All module functions must return one of the codes listed below (apart from
 *    * RLM_MODULE_NUMCODES, which is used to check for validity).
 *     */
typedef enum rlm_rcodes {
        RLM_MODULE_REJECT = 0,  //!< Immediately reject the request.
        RLM_MODULE_FAIL,             //!< Module failed, don't reply.
        RLM_MODULE_OK,              //!< The module is OK, continue.
        RLM_MODULE_HANDLED,    //!< The module handled the request, so stop.
        RLM_MODULE_INVALID,       //!< The module considers the request invalid.
        RLM_MODULE_USERLOCK,  //!< Reject the request (user is locked out).
        RLM_MODULE_NOTFOUND,    //!< User not found.
        RLM_MODULE_NOOP,           //!< Module succeeded without doing anything.
        RLM_MODULE_UPDATED,     //!< OK (pairs modified).
        RLM_MODULE_NUMCODES,  //!< How many valid return codes there are.
        RLM_MODULE_UNKNOWN      //!< Error resolving rcode (should not be
                                                      //!< returned by modules).
} rlm_rcode_t;

typedef struct module_t {
        uint64_t                magic;               //!< Used to validate module struct.
        char const              *name;             //!< The name of the module (without rlm_ prefix).
        int                     type;                     //!< One or more of the RLM_TYPE_* constants.
        size_t                  inst_size;            //!< Size of the instance data
        CONF_PARSER const       *config;                        //!< Configuration information
        instantiate_t           instantiate;                    //!< Function to use for instantiation.
        detach_t                detach;                         //!< Function to use to free module instance.
        packetmethod            methods[RLM_COMPONENT_COUNT];   //!< Pointers to the various section                                                                                                                  //functions, ordering
                                                                //!< determines which function is mapped                                                                                                         //to           &n!
                                                                 //!< which section                                                                                                                      &nbsp!
 ;                                                                                                                                                                    &nb!
 sp;           &
        uint64_t                rtcode[RLM_MODULE_NUMCODES];    //Used for module return codes                  
} module_t;

Now in function: modcall_recurse() I added

modcall_recurse() {

rlm_rcode_t result;
module_t const *module;

result = call_modsingle(c->method, sp, request);
module->rtcode[result] = module->rtcode[result] + 1;

Also, in radius.c in function main I will use memset to initialize my rtcode array to zero.
will add this statement:



From: Alan DeKok <aland at>
Sent: Fri, 26 Sep 2014 23:43:18 
To: FreeRadius users mailing list <freeradius-users at>
Subject: Re: Module Statistics in freeradius
Himanshu Pandey wrote:

> But as we discussed, the server does NOT keep track of statistics for

> each module return codes.

  Yes... I've said that repeatedly.  Perhaps you could repeat it some

more, to be sure that I understand how the server works?

> The very first thing that I did was finding out the basic module

> structure in freeradius, if I am not wrong this is the basic module

> structure used:


> Now I added an unsigned long array in this structure in which module

> return code act as an index. Please see the snippet below:

  That's not a good idea.  For one, the module return codes are already

in a typedef.  Just use that one.  There's no reason to create a new one.

  And "unsigned long" isn't used anywhere else in the server.  Just use


> Please advice me that how should I update this my unsigned long

> rtcode[RLM_RETCODE_COUNT] array with each module return code.

  Use C code to increment the array entry.  See modcall.c, call_modsingle().

  Alan DeKok.


List info/subscribe/unsubscribe? See

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Freeradius-Users mailing list