Updates autoroute to enforce sensible netmasks. This is serious business.
git-svn-id: file:///home/svn/framework3/trunk@9664 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
01139ed655
commit
fb273e83a9
|
@ -201,6 +201,18 @@ module Socket
|
|||
addr_ntoi(resolv_nbo(host))
|
||||
end
|
||||
|
||||
def self.resolv_to_cidr(mask)
|
||||
mask_i = resolv_nbo_i(mask)
|
||||
cidr = nil
|
||||
0.upto(32) do |i|
|
||||
if ((1 << i)-1) << (32-i) == mask_i
|
||||
cidr = i
|
||||
break
|
||||
end
|
||||
end
|
||||
return cidr
|
||||
end
|
||||
|
||||
#
|
||||
# Resolves a host to a dotted address.
|
||||
#
|
||||
|
|
|
@ -124,7 +124,13 @@ def validate_cmd(subnet=nil,netmask=nil)
|
|||
end
|
||||
|
||||
unless(check_ip(subnet))
|
||||
print_error "Subnet invalid"
|
||||
print_error "Subnet invalid (must be IPv4)"
|
||||
usage
|
||||
return false
|
||||
end
|
||||
|
||||
if(netmask and !(Rex::Socket.resolv_to_cidr(netmask)))
|
||||
print_error "Netmask invalid (must define contiguous IP addressing)"
|
||||
usage
|
||||
return false
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue