ln.dhcp/IPPool.cs

50 lines
1.0 KiB
C#

using System;
using ln.types.net;
using System.Collections.Generic;
using ln.types.odb.attributes;
namespace ln.dhcp
{
public class IPPool
{
[DocumentID]
public String Name { get; set; }
public IPv4 FirstIP { get; set; }
public IPv4 LastIP { get; set; }
IPv4 nextIP;
public IPv4 NextIP
{
get => nextIP;
set => nextIP = value;
}
public TimeSpan DefaultLeaseTime { get; set; }
public IPv4 GetNextIP()
{
lock (this)
{
IPv4 next = nextIP++;
if (nextIP > LastIP)
nextIP = FirstIP;
return next;
}
}
private IPPool()
{
DefaultLeaseTime = TimeSpan.FromHours(1);
}
public IPPool(String name, IPv4 first, IPv4 last)
: this()
{
Name = name;
FirstIP = first;
LastIP = last;
NextIP = FirstIP;
}
}
}