Permalink
Browse files

api: IpAddress.Free: check for networks routed via the removed address

It was possible to remove routed networks whose host addresses were used
for routing of other networks.
  • Loading branch information...
aither64 committed Dec 25, 2018
1 parent f15b574 commit 8fc54c126005b69356f50bec805191347fe1ff00
Showing with 11 additions and 0 deletions.
  1. +3 −0 api/lib/vpsadmin/api/resources/ip_address.rb
  2. +8 −0 api/models/network_interface.rb
@@ -390,6 +390,9 @@ def exec

@chain, _ = netif.remove_route(ip)
ip

rescue VpsAdmin::API::Exceptions::IpAddressInUse => e
error(e.message)
end

def state_id
@@ -92,6 +92,14 @@ def remove_route(ip, safe: false)
raise VpsAdmin::API::Exceptions::IpAddressNotAssigned
end

routed_addrs = ::IpAddress.where(route_via: ip.host_ip_addresses)

if routed_addrs.any?
raise VpsAdmin::API::Exceptions::IpAddressInUse,
"The following addresses are routed via host addresses from #{ip}:\n"+
(routed_addrs.map { |v| "#{v} via #{v.route_via.ip_addr}" }.join(", \n"))
end

TransactionChains::NetworkInterface::DelRoute.fire(self, [ip])
end
end

0 comments on commit 8fc54c1

Please sign in to comment.