class DHCP::OptStaticRoutes
Class for DHCP option 33 (static routes) - Use option 121 instead if possible WARNING: Option 33 can only handle class A, B, or C networks, not classless networks with an arbitrary netmask.
Public Instance Methods
bin_to_data(data)
click to toggle source
# File lib/dhcp/options.rb, line 349 def bin_to_data(data) [IPAddress::IPv4::parse_classful_data(data[0,4]).net.to_string, IPAddress::IPv4::parse_data(data[4,4]).to_s] end
data_to_bin(data)
click to toggle source
# File lib/dhcp/options.rb, line 334 def data_to_bin(data) raise "Invalid static route" unless data.is_a?(Array) && data.size == 2 net, gateway = *data net = IPAddress::IPv4.new(net) raise "Invalid classful static route network" unless net.network? raise "Invalid classful static route network" unless ( (net.a? && net.prefix == 8 ) || (net.b? && net.prefix == 16) || (net.c? && net.prefix == 24) ) gateway = IPAddress::IPv4.new("#{gateway}/#{net.prefix}") raise "Invalid classful static route gateway" unless gateway.member?(net) net.data + gateway.data end
is_list?(list)
click to toggle source
# File lib/dhcp/options.rb, line 321 def is_list?(list) raise "Invalid route list/entry" unless list.is_a?(Array) if list.size == 2 return false if list[0].is_a?(String) && list[1].is_a?(String) return true if list[0].is_a?(Array) && list[1].is_a?(Array) raise "Invalid route list/entry" end list.each do |item| raise "Invalid route list" unless item.is_a?(Array) && item[0].is_a?(String) && item[1].is_a?(String) end return true end
to_s()
click to toggle source
# File lib/dhcp/options.rb, line 353 def to_s opt_header + '=[' + map{|i| i[0] + '=>' + i[1]}.join(',') + ']' end