Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sub-VSA support #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions lib/radiustar/packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,35 +158,53 @@ def unpack
attribute_type = attribute_type.to_i

if attribute_type == 26 # Vendor Specific Attribute
vid, attribute_type, attribute_value = attribute_data.unpack("xxNCxa#{length-6}")
vid, vsa_data = attribute_data.unpack("xxNa#{length-6}")
vendor = @dict.vendors.find_by_id(vid)
attribute = vendor.find_attribute_by_id(attribute_type) if vendor

if vendor
while vsa_data.length > 0 do
attribute_type, attribute_length = vsa_data.unpack("CC")
attribute = vendor.find_attribute_by_id(attribute_type)

vsa_value = vsa_data.unpack("xxa#{attribute_length-2}").first

if attribute
vsa_value = case attribute.type
when 'string'
vsa_value
when 'integer'
attribute.has_values? ? attribute.find_values_by_id(vsa_value.unpack("N")[0]).name : vsa_value.unpack("N")[0]
when 'ipaddr'
vsa_value.unpack("N")[0].to_ip.to_s
when 'time'
vsa_value.unpack("N")[0]
when 'date'
vsa_value.unpack("N")[0]
end
set_attribute(vendor.name+"/"+attribute.name, vsa_value)
end
vsa_data[0, attribute_length] = ""
end
end
else
vendor = nil
attribute = @dict.find_attribute_by_id(attribute_type)
end

if attribute
attribute_value = case attribute.type
when 'string'
attribute_value
when 'integer'
attribute.has_values? ? attribute.find_values_by_id(attribute_value.unpack("N")[0]).name : attribute_value.unpack("N")[0]
when 'ipaddr'
attribute_value.unpack("N")[0].to_ip.to_s
when 'time'
attribute_value.unpack("N")[0]
when 'date'
attribute_value.unpack("N")[0]
end

if vendor
set_attribute(vendor.name+"/"+attribute.name, attribute_value) if attribute
else
set_attribute(attribute.name, attribute_value) if attribute
if attribute
attribute_value = case attribute.type
when 'string'
attribute_value
when 'integer'
attribute.has_values? ? attribute.find_values_by_id(attribute_value.unpack("N")[0]).name : attribute_value.unpack("N")[0]
when 'ipaddr'
attribute_value.unpack("N")[0].to_ip.to_s
when 'time'
attribute_value.unpack("N")[0]
when 'date'
attribute_value.unpack("N")[0]
end

set_attribute(attribute.name, attribute_value)
end
end

end
attribute_data[0, length] = ""
end
end
Expand Down