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

Error generating code from Starent dictionary #102

Closed eugennicoara closed 2 years ago

eugennicoara commented 2 years ago

I'm trying to generate code from Starent vendor-specific dictionary stored on the local fs as dictionary.starent and I'm getting the following error:

radius-dict-gen -output starent_generated.go -package dictionary dictionary.starent radius-dict-gen: dictionarygen: cannot generate code for Starent

However, the same operation from Starent VSA1 vendor specific dictionary as well as 3GPP vendor-specific dictionary works perfectly fine.

I tried adding that format=2,2 to the 3GPP dictionary and I got a similar error.

radius-dict-gen -output tgpp_generated.go -package dictionary dictionary.3gpp radius-dict-gen: dictionarygen: cannot generate code for 3GPP

Can you please confirm that is what's breaking radius-dict-gen? If yes, is there any workaround I can use to generate my code and maybe manually change it after that to still generate the proper Starent VSA encoding?

Thanks

eugennicoara commented 2 years ago

Here's what I did to solve this problem:

  1. Updated dictionary.starent from "format=2,2" to "format=1,1".
  2. Generated the helper code using radius-dict-gen.
  3. Reverted the changes introduced in step 1 above.
  4. Manually edited starent_generated.go and adjusted the indexes in _Starent_AddVendor, _Starent_GetsVendor, _Starent_LookupVendor, _Starent_SetVendor, and _Starent_DelVendor.

Sample code:

// Encode creates a 2 bytes slice encoding an uint16 value. func Encode(i uint16) []byte { v := make([]byte, 2) binary.BigEndian.PutUint16(v, i) return v } // Decode creates a uint16 value from a 2 bytes slice. func Decode(v []byte)uint16 { return binary.BigEndian.Uint16(v) } func _Starent_AddVendor(p *radius.Packet, typ uint16, attr radius.Attribute) (err error) {// typ is unit16 now instead of byte var vsa radius.Attribute vendor := make(radius.Attribute, 2+2+len(attr)) // this is 2+2+attribute length bytes now copy(vendor[0:], Encode(typ)) // this is 2 bytes now copy(vendor[2:], Encode(uint16(len(vendor)))) // this is 2 bytes now copy(vendor[4:], attr) vsa, err = radius.NewVendorSpecific(_Starent_VendorID, vendor) if err != nil { return } p.Add(rfc2865.VendorSpecific_Type, vsa) return }