Skip to content

Commit

Permalink
Merge pull request #2507 from cloudfoundry/user-safer-netaddr-methods
Browse files Browse the repository at this point in the history
Use `NetAddr::CIDR.create` instead of `CIDRv{4,6}.new`
  • Loading branch information
beyhan committed Mar 28, 2024
2 parents 4e9d023 + a99aebb commit 570bfe6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def try_to_allocate_dynamic_ip(reservation, subnet)
addresses_we_cant_allocate.merge(subnet.static_ips.to_a) unless subnet.static_ips.empty?
addr = find_first_available_address(addresses_we_cant_allocate, first_range_address)
if subnet.range.version == 6
ip_address = NetAddr::CIDRv6.new(addr)
ip_address = NetAddr::CIDR.create(addr, Version: 6)
else
ip_address = NetAddr::CIDRv4.new(addr)
ip_address = NetAddr::CIDR.create(addr, Version: 4)
end

unless subnet.range == ip_address || subnet.range.contains?(ip_address)
Expand Down Expand Up @@ -115,7 +115,7 @@ def try_to_allocate_vip_ip(reservation, subnet)

raise NoMoreIPsAvailableAndStopRetrying if available_ips.empty?

ip_address = NetAddr::CIDRv4.new(available_ips.first)
ip_address = NetAddr::CIDR.create(available_ips.first, Version: 4)

save_ip(ip_address, reservation, false)

Expand Down
2 changes: 1 addition & 1 deletion src/bosh-director/lib/cloud/dummy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create_vm(agent_id, stemcell_id, cloud_properties, networks, disk_cids, env)
elsif cloud_properties['az_name']
ip_address = cmd.ip_address_for_az(cloud_properties['az_name'])
else
ip_address = NetAddr::CIDRv4.new(rand(0..4294967295)).ip #collisions?
ip_address = NetAddr::CIDR.create(rand(0..4294967295), Version: 4).ip #collisions?
end

if ip_address
Expand Down

0 comments on commit 570bfe6

Please sign in to comment.