diff --git a/appliances/VRouter/DHCP4v2/dhcpcore-onelease/client/main.go b/appliances/VRouter/DHCP4v2/dhcpcore-onelease/client/main.go index abeb5f3c..83e5594f 100644 --- a/appliances/VRouter/DHCP4v2/dhcpcore-onelease/client/main.go +++ b/appliances/VRouter/DHCP4v2/dhcpcore-onelease/client/main.go @@ -44,7 +44,6 @@ func main() { } conv, err := c.Exchange("lo", - dhcpv4.WithClientIP(net.ParseIP("127.0.0.1")), dhcpv4.WithHwAddr(mac)) for _, p := range conv { log.Print(p.Summary()) diff --git a/appliances/VRouter/DHCP4v2/dhcpcore-onelease/plugins/onerange/plugin.go b/appliances/VRouter/DHCP4v2/dhcpcore-onelease/plugins/onerange/plugin.go index 4d52013e..e0e91e24 100644 --- a/appliances/VRouter/DHCP4v2/dhcpcore-onelease/plugins/onerange/plugin.go +++ b/appliances/VRouter/DHCP4v2/dhcpcore-onelease/plugins/onerange/plugin.go @@ -77,8 +77,6 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) ipFromMAC, ok, err := p.checkMACPrefix(macAddress) if err != nil { log.Errorf("MAC2IP lease failed for mac %v: %v", macAddress.String(), err) - // return nack to the client - resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak)) return resp, true } if ok { @@ -94,9 +92,6 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) ip, err := p.allocator.Allocate(ipToAllocate) if err != nil { log.Errorf("Could not allocate IP for MAC %s: %v", req.ClientHWAddr.String(), err) - resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak)) - // return nack to the client - resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak)) return resp, true } @@ -105,8 +100,6 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) log.Warnf("Allocated IP %s for MAC %s does not match the requested IP %s", ip.IP.String(), req.ClientHWAddr.String(), ipToAllocate.IP.String()) //revert the allocation of the undesired IP p.allocator.Free(ip) - // return nack to the client - resp.Options.Update(dhcpv4.OptMessageType(dhcpv4.MessageTypeNak)) return resp, true } @@ -208,11 +201,13 @@ func setupRange(args ...string) (handler.Handler4, error) { var excludedIPs string var macPrefix string - pflag.StringVar(&excludedIPs, "excluded-ips", "", "Comma-separated list of excluded IP addresses") - pflag.BoolVar(&p.enableMAC2IP, "mac2ip", false, "Enables MAC to IP address mapping") - pflag.StringVar(&macPrefix, "mac-prefix", "02:00", "2-byte MAC prefix for MAC to IP address mapping. Defaults to [02:00]") + pluginFlags := pflag.NewFlagSet("onerange", pflag.ExitOnError) - pflag.CommandLine.Parse(optionalArgs) + pluginFlags.StringVar(&excludedIPs, "excluded-ips", "", "Comma-separated list of excluded IP addresses") + pluginFlags.BoolVar(&p.enableMAC2IP, "mac2ip", false, "Enables MAC to IP address mapping") + pluginFlags.StringVar(&macPrefix, "mac2ip-prefix", "02:00", "2-byte MAC prefix for MAC to IP address mapping") + + pluginFlags.Parse(optionalArgs) if p.enableMAC2IP && macPrefix != "" { p.MACPrefix, err = parseMACPrefix(macPrefix) diff --git a/appliances/VRouter/DHCP4v2/main.rb b/appliances/VRouter/DHCP4v2/main.rb index c8814125..89ad9dd8 100644 --- a/appliances/VRouter/DHCP4v2/main.rb +++ b/appliances/VRouter/DHCP4v2/main.rb @@ -109,9 +109,13 @@ def generate_config(basedir, vars) end def generate_range_config(nic, nic_data) - lease_range = nic_data[:range].gsub('-', ' ') + lease_range = nic_data[:range]&.gsub('-', ' ') excluded_ips_str = ([nic_data[:address]] + nic_data[:vips]).join(',') - return "leases-#{nic}.sqlite3 #{lease_range} #{ONEAPP_VNF_DHCP4_LEASE_TIME}s #{excluded_ips_str}" + range_config = "leases-#{nic}.sqlite3 #{lease_range} #{ONEAPP_VNF_DHCP4_LEASE_TIME}s" + range_config += " --excluded-ips #{excluded_ips_str}" unless excluded_ips_str.empty? + range_config += " --mac2ip" if ONEAPP_VNF_DHCP4_MAC2IP_ENABLED + range_config += " --mac2ip-prefix #{ONEAPP_VNF_DHCP4_MAC2IP_MACPREFIX}" if ONEAPP_VNF_DHCP4_MAC2IP_ENABLED + return range_config end def install(initdir: '/etc/init.d') diff --git a/appliances/VRouter/DHCP4v2/tests.rb b/appliances/VRouter/DHCP4v2/tests.rb index 632e2ecb..15d292f6 100644 --- a/appliances/VRouter/DHCP4v2/tests.rb +++ b/appliances/VRouter/DHCP4v2/tests.rb @@ -103,7 +103,8 @@ def clear_vars(object) - mtu: 1111 - router: 1.2.3.4 - netmask: 255.255.0.0 - - range: leases-eth1.sqlite3 20.30.0.2 20.30.255.254 3600s 20.30.40.50,20.30.40.55 + - range: leases-eth1.sqlite3 20.30.0.2 20.30.255.254 3600s --excluded-ips 20.30.40.50,20.30.40.55 + --mac2ip --mac2ip-prefix 02:00 - onelease: eth2: server4: @@ -116,7 +117,8 @@ def clear_vars(object) - mtu: 2222 - router: 30.40.50.1 - netmask: 255.0.0.0 - - range: leases-eth2.sqlite3 30.40.50.64 30.40.50.68 3600s 30.40.50.60 + - range: leases-eth2.sqlite3 30.40.50.64 30.40.50.68 3600s --excluded-ips 30.40.50.60 + --mac2ip --mac2ip-prefix 02:00 - onelease: eth3: server4: @@ -129,7 +131,8 @@ def clear_vars(object) - mtu: 3333 - router: 40.50.60.1 - netmask: 255.255.255.0 - - range: leases-eth3.sqlite3 40.50.60.2 40.50.60.254 3600s 40.50.60.70 + - range: leases-eth3.sqlite3 40.50.60.2 40.50.60.254 3600s --excluded-ips 40.50.60.70 + --mac2ip --mac2ip-prefix 02:00 - onelease: ONELEASE_CONF