layeh / radius

a Go (golang) RADIUS client and server implementation
https://pkg.go.dev/layeh.com/radius
Mozilla Public License 2.0
571 stars 181 forks source link

Add freeradius vendor specific dictionary #88

Open stamp opened 3 years ago

stamp commented 3 years ago

FreeRADIUS has this builtin feature where you are able to query some statistics from the server. I added the FreeRADIUS vendor dictionary to be able to both read and write those attributes.

There are a already existing monitoring tools that support the FreeRADIUS statistics query. I wanted to be able to re-use those very tools instead of building something custom of my own.

Here are an example of a test query using radclient that is a part of the FreeRADIUS toolbox.

echo "Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 1, Response-Packet-Type = Access-Accept" | radclient -x localhost:18121 status secret
Sent Status-Server Id 32 from 0.0.0.0:36075 to 127.0.0.1:18121 length 50
    Message-Authenticator = 0x00
    FreeRADIUS-Statistics-Type = Authentication
    Response-Packet-Type = Access-Accept
Received Access-Accept Id 32 from 127.0.0.1:18121 to 0.0.0.0:0 length 140
    FreeRADIUS-Total-Access-Requests = 123
    FreeRADIUS-Total-Access-Accepts = 321
    FreeRADIUS-Total-Access-Rejects = 321
    FreeRADIUS-Total-Access-Challenges = 321
    FreeRADIUS-Total-Auth-Responses = 321
    FreeRADIUS-Total-Auth-Duplicate-Requests = 321
    FreeRADIUS-Total-Auth-Malformed-Requests = 321
    FreeRADIUS-Total-Auth-Invalid-Requests = 321
    FreeRADIUS-Total-Auth-Dropped-Requests = 321
    FreeRADIUS-Total-Auth-Unknown-Types = 321

And some source code for my test query:

          switch freeradius.StatisticsType_Get(r.Packet) {
          case freeradius.StatisticsType_Value_Authentication:
              resp = r.Response(radius.CodeAccessAccept)
              freeradius.TotalAccessRequests_Add(resp, 123)
              freeradius.TotalAccessAccepts_Add(resp, 321)
              freeradius.TotalAccessRejects_Add(resp, 321)
              freeradius.TotalAccessChallenges_Add(resp, 321)
              freeradius.TotalAuthResponses_Add(resp, 321)
              freeradius.TotalAuthDuplicateRequests_Add(resp, 321)
              freeradius.TotalAuthMalformedRequests_Add(resp, 321)
              freeradius.TotalAuthInvalidRequests_Add(resp, 321)
              freeradius.TotalAuthDroppedRequests_Add(resp, 321)
              freeradius.TotalAuthUnknownTypes_Add(resp, 321)
          default:
              resp = r.Response(radius.CodeAccessReject)
          }

I was not able to generate code for the FreeRADIUS v4 version of the statistics attributes. They have the type TLV and the generator fails at dictionarygen/generator.go:193. I'm to much of a novice on the radius mechanics so I commented out the V4 part in the dictionary file for now.