layeh / radius

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

how to use rfc2866 #103

Open mohamadpk opened 2 years ago

mohamadpk commented 2 years ago

how i can to send Service-Type ,Framed-Protocol ,NAS-Port,NAS-Port-Type,User-Name,Calling-Station-Id,Called-Station-Id,Acct-Session-Id,Framed-IP-Address,Acct-Authentic,Event-Timestamp,Acct-Status-Type,NAS-Identifier,Acct-Delay-Time,NAS-IP-Address , in CodeAccountingRequest? User-Name is important to my. i can add sessionid to packet with this code

    rfc2866.AcctSessionID_Add(packet, []byte("sssssssssssssssssss"))
    rfc2866.AcctStatusType_Add(packet, rfc2866.AcctStatusType_Value_Start)

how i can add User-Name?

DiniFarb commented 2 years ago

Hi @mohamadpk

Your listed attributes are from both rfc's, since rfc2866(accounting) extends rfc2865 you can use them togheter. Here the client example from the readme alterd to mixed attributs:

package main

import (
    "context"
    "log"

    "layeh.com/radius"
    "layeh.com/radius/rfc2865"
    "layeh.com/radius/rfc2866"
)

func main() {
    packet := radius.New(radius.CodeAccountingRequest, []byte(`secret`))
    rfc2865.UserName_SetString(packet, "tim")
    rfc2865.CallingStationID_AddString(packet, "1.1.1.1")
    rfc2866.AcctSessionID_Add(packet, []byte("sssssssssssssssssss"))
    rfc2866.AcctStatusType_Add(packet, rfc2866.AcctStatusType_Value_Start)
    response, err := radius.Exchange(context.Background(), packet, "localhost:1812")
    if err != nil {
        log.Fatal(err)
    }

    log.Println("Code:", response.Code)
}

Which results in a clean radius request here shown in wireshark:

image