ln.dhcp/IPPool.cs

50 lines
1.0 KiB
C#
Raw Normal View History

2019-04-23 09:22:14 +02:00
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;
2019-04-24 12:53:43 +02:00
public IPv4 NextIP
2019-04-23 09:22:14 +02:00
{
2019-04-24 12:53:43 +02:00
get => nextIP;
set => nextIP = value;
}
public TimeSpan DefaultLeaseTime { get; set; }
public IPv4 GetNextIP()
{
lock (this)
2019-04-23 09:22:14 +02:00
{
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;
}
}
}