Permalink
Browse files

Fixes #781 - DHCP create attempted when mac already used

includes fixes for both ISC and MS implementations.
Signed-off-by: Paul kelly <paul.ian.kelly@googlemail.com>
  • Loading branch information...
1 parent a57ca5d commit 4a5b83c0a84a7ebdac1caf59e922db7c6533bed4 @ohadlevy ohadlevy committed Mar 24, 2011
Showing with 17 additions and 13 deletions.
  1. +15 −1 lib/proxy/dhcp/server.rb
  2. +1 −6 lib/proxy/dhcp/server/isc.rb
  3. +1 −6 lib/proxy/dhcp/server/native_ms.rb
View
@@ -76,18 +76,32 @@ def find_subnet value
def find_record record
subnets.each do |s|
s.records.each do |v|
- return v if record.is_a?(String) and v.ip == record
+ return v if record.is_a?(String) and (v.ip == record or v.mac == record)
return v if record.is_a?(Proxy::DHCP::Record) and v == record
return v if record.is_a?(IPAddr) and v.ip == record.to_s
end
end
return nil
end
+ def ensure_ip_and_mac_unused ip, mac
+ entry = nil
+ raise Proxy::DHCP::Error, "Address #{ip} is used by this reservation: #{entry.ip} - #{entry.mac}" if (entry = find_record(ip))
+ raise Proxy::DHCP::Error, "MAC #{mac} is used by this reservation: #{entry.mac} - #{entry.ip}" if (entry = find_record(mac))
+ end
+
def inspect
self
end
+ def addRecord options = {}
+ ip = validate_ip options[:ip]
+ mac = validate_mac options[:mac]
+ ensure_ip_and_mac_unused ip, mac
+ name = options[:hostname] || raise(Proxy::DHCP::Error, "Must provide hostname")
+ raise Proxy::DHCP::Error, "Unknown subnet for #{ip}" unless subnet = find_subnet(IPAddr.new(ip))
+ end
+
def delRecord subnet, record
subnet.delete record
end
@@ -23,12 +23,7 @@ def delRecord subnet, record
end
def addRecord options = {}
- ip = validate_ip options[:ip]
- mac = validate_mac options[:mac]
- raise Proxy::DHCP::Error, "Must provide host-name" unless options[:name]
- name = options[:name]
- raise Proxy::DHCP::Error, "Already exists" if find_record(ip)
- raise Proxy::DHCP::Error, "Unknown subnet for #{ip}" unless subnet = find_subnet(IPAddr.new(ip))
+ super(options)
msg = "Added DHCP reservation for #{options[:name]}"
omcmd "connect"
@@ -25,11 +25,7 @@ def delRecord subnet, record
end
def addRecord options={}
- ip = validate_ip options[:ip]
- mac = validate_mac options[:mac]
- name = options[:hostname] || raise(Proxy::DHCP::Error, "Must provide hostname")
- raise Proxy::DHCP::Error, "Already exists" if find_record(ip)
- raise Proxy::DHCP::Error, "Unknown subnet for #{ip}" unless subnet = find_subnet(IPAddr.new(ip))
+ super(options)
msg = "Added DHCP reservation for #{name} => #{ip} - #{mac}"
cmd = "scope #{subnet.network} add reservedip #{ip} #{mac.gsub(/:/,"")} #{name}"
@@ -48,7 +44,6 @@ def addRecord options={}
execute(cmd, msg, true)
record = Proxy::DHCP::Reservation.new subnet, ip, mac, options
- true
end
def loadSubnetData subnet

0 comments on commit 4a5b83c

Please sign in to comment.