master
Harald Wolff 2019-04-24 12:53:43 +02:00
parent a002c4b0a1
commit 50899f7f3c
17 changed files with 79 additions and 10 deletions

View File

@ -1,8 +1,11 @@
using System; using System;
using ln.types.net; using ln.types.net;
using ln.types.odb.attributes; using ln.types.odb.attributes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ln.dhcp namespace ln.dhcp
{ {
[JsonConverter(typeof(StringEnumConverter))]
public enum DHCPLeaseState public enum DHCPLeaseState
{ {
RELEASED, RELEASED,

View File

@ -288,6 +288,7 @@ namespace ln.dhcp
lease.ValidThrough = validThrough; lease.ValidThrough = validThrough;
} }
lease.LeaseState = DHCPLeaseState.BOUND; lease.LeaseState = DHCPLeaseState.BOUND;
lease.LastUpdate = DateTimeOffset.Now;
Commit(lease); Commit(lease);
logLease.Log(LogLevel.INFO, "[ACK ] {0} {1} {2}", lease.ClientMAC, lease.ClientIP, lease.ClientName); logLease.Log(LogLevel.INFO, "[ACK ] {0} {1} {2}", lease.ClientMAC, lease.ClientIP, lease.ClientName);
@ -328,10 +329,11 @@ namespace ln.dhcp
IPv4 test = start; IPv4 test = start;
while (leasesAPI.FindLease(test) != null) while (leasesAPI.FindLease(test) != null)
{ {
test = ippool.NextIP; test = ippool.GetNextIP();
if (test.Equals(start)) if (test.Equals(start))
return null; return null;
} }
Commit(ippool);
return test; return test;
} }
} }

View File

@ -13,20 +13,24 @@ namespace ln.dhcp
public IPv4 LastIP { get; set; } public IPv4 LastIP { get; set; }
IPv4 nextIP; IPv4 nextIP;
public IPv4 NextIP public IPv4 NextIP
{ {
get get => nextIP;
set => nextIP = value;
}
public TimeSpan DefaultLeaseTime { get; set; }
public IPv4 GetNextIP()
{
lock (this)
{ {
IPv4 next = nextIP++; IPv4 next = nextIP++;
if (nextIP > LastIP) if (nextIP > LastIP)
nextIP = FirstIP; nextIP = FirstIP;
return next; return next;
} }
set => nextIP = value;
} }
public TimeSpan DefaultLeaseTime { get; set; }
private IPPool() private IPPool()
{ {
DefaultLeaseTime = TimeSpan.FromHours(1); DefaultLeaseTime = TimeSpan.FromHours(1);

Binary file not shown.

Binary file not shown.

View File

@ -1514,7 +1514,7 @@
Converts the <see cref="T:System.Decimal"/> to its JSON string representation. Converts the <see cref="T:System.Decimal"/> to its JSON string representation.
</summary> </summary>
<param name="value">The value to convert.</param> <param name="value">The value to convert.</param>
<returns>A JSON string representation of the <see cref="T:System.SByte"/>.</returns> <returns>A JSON string representation of the <see cref="T:System.Decimal"/>.</returns>
</member> </member>
<member name="M:Newtonsoft.Json.JsonConvert.ToString(System.Guid)"> <member name="M:Newtonsoft.Json.JsonConvert.ToString(System.Guid)">
<summary> <summary>
@ -2162,6 +2162,12 @@
</summary> </summary>
<value>The member serialization.</value> <value>The member serialization.</value>
</member> </member>
<member name="P:Newtonsoft.Json.JsonObjectAttribute.MissingMemberHandling">
<summary>
Gets or sets the missing member handling used when deserializing this object.
</summary>
<value>The missing member handling.</value>
</member>
<member name="P:Newtonsoft.Json.JsonObjectAttribute.ItemNullValueHandling"> <member name="P:Newtonsoft.Json.JsonObjectAttribute.ItemNullValueHandling">
<summary> <summary>
Gets or sets how the object's properties with null values are handled during serialization and deserialization. Gets or sets how the object's properties with null values are handled during serialization and deserialization.
@ -8103,6 +8109,13 @@
</summary> </summary>
<param name="token">The token to read from.</param> <param name="token">The token to read from.</param>
</member> </member>
<member name="M:Newtonsoft.Json.Linq.JTokenReader.#ctor(Newtonsoft.Json.Linq.JToken,System.String)">
<summary>
Initializes a new instance of the <see cref="T:Newtonsoft.Json.Linq.JTokenReader"/> class.
</summary>
<param name="token">The token to read from.</param>
<param name="initialPath">The initial path of the token. It is prepended to the returned <see cref="P:Newtonsoft.Json.Linq.JTokenReader.Path"/>.</param>
</member>
<member name="M:Newtonsoft.Json.Linq.JTokenReader.Read"> <member name="M:Newtonsoft.Json.Linq.JTokenReader.Read">
<summary> <summary>
Reads the next JSON token from the underlying <see cref="T:Newtonsoft.Json.Linq.JToken"/>. Reads the next JSON token from the underlying <see cref="T:Newtonsoft.Json.Linq.JToken"/>.
@ -10199,6 +10212,13 @@
</summary> </summary>
<value>The converter.</value> <value>The converter.</value>
</member> </member>
<member name="P:Newtonsoft.Json.Serialization.JsonContract.InternalConverter">
<summary>
Gets the internally resolved <see cref="T:Newtonsoft.Json.JsonConverter"/> for the contract's type.
This converter is used as a fallback converter when no other converter is resolved.
Setting <see cref="P:Newtonsoft.Json.Serialization.JsonContract.Converter"/> will always override this converter.
</summary>
</member>
<member name="P:Newtonsoft.Json.Serialization.JsonContract.OnDeserializedCallbacks"> <member name="P:Newtonsoft.Json.Serialization.JsonContract.OnDeserializedCallbacks">
<summary> <summary>
Gets or sets all methods called immediately after deserialization of the object. Gets or sets all methods called immediately after deserialization of the object.
@ -10344,6 +10364,12 @@
</summary> </summary>
<value>The member object serialization.</value> <value>The member object serialization.</value>
</member> </member>
<member name="P:Newtonsoft.Json.Serialization.JsonObjectContract.MissingMemberHandling">
<summary>
Gets or sets the missing member handling used when deserializing this object.
</summary>
<value>The missing member handling.</value>
</member>
<member name="P:Newtonsoft.Json.Serialization.JsonObjectContract.ItemRequired"> <member name="P:Newtonsoft.Json.Serialization.JsonObjectContract.ItemRequired">
<summary> <summary>
Gets or sets a value that indicates whether the object's properties are required. Gets or sets a value that indicates whether the object's properties are required.
@ -10510,6 +10536,11 @@
</summary> </summary>
<value>A value indicating whether this <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> is required.</value> <value>A value indicating whether this <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> is required.</value>
</member> </member>
<member name="P:Newtonsoft.Json.Serialization.JsonProperty.IsRequiredSpecified">
<summary>
Gets a value indicating whether <see cref="P:Newtonsoft.Json.Serialization.JsonProperty.Required"/> has a value specified.
</summary>
</member>
<member name="P:Newtonsoft.Json.Serialization.JsonProperty.IsReference"> <member name="P:Newtonsoft.Json.Serialization.JsonProperty.IsReference">
<summary> <summary>
Gets or sets a value indicating whether this property preserves object references. Gets or sets a value indicating whether this property preserves object references.
@ -10760,6 +10791,26 @@
<param name="name">The property name to resolve.</param> <param name="name">The property name to resolve.</param>
<returns>The resolved property name.</returns> <returns>The resolved property name.</returns>
</member> </member>
<member name="M:Newtonsoft.Json.Serialization.NamingStrategy.GetHashCode">
<summary>
Hash code calculation
</summary>
<returns></returns>
</member>
<member name="M:Newtonsoft.Json.Serialization.NamingStrategy.Equals(System.Object)">
<summary>
Object equality implementation
</summary>
<param name="obj"></param>
<returns></returns>
</member>
<member name="M:Newtonsoft.Json.Serialization.NamingStrategy.Equals(Newtonsoft.Json.Serialization.NamingStrategy)">
<summary>
Compare to another NamingStrategy
</summary>
<param name="other"></param>
<returns></returns>
</member>
<member name="T:Newtonsoft.Json.Serialization.ObjectConstructor`1"> <member name="T:Newtonsoft.Json.Serialization.ObjectConstructor`1">
<summary> <summary>
Represents a method that constructs an object. Represents a method that constructs an object.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,6 +29,9 @@
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="Mono.Posix" /> <Reference Include="Mono.Posix" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DHCPServer.cs" /> <Compile Include="DHCPServer.cs" />
@ -51,5 +54,8 @@
<Name>ln.logging</Name> <Name>ln.logging</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -1 +1 @@
62f8061fbf7e671ceaa150fc217748d6af510370 52f74c261979b87de87fda0ff386127bee4e9aa4

View File

@ -25,4 +25,3 @@
/home/haraldwolff/src/ln.skyspot/ln.dhcp/bin/Debug/sharp.logging.pdb /home/haraldwolff/src/ln.skyspot/ln.dhcp/bin/Debug/sharp.logging.pdb
/home/haraldwolff/src/ln.skyspot/ln.dhcp/bin/Debug/Newtonsoft.Json.xml /home/haraldwolff/src/ln.skyspot/ln.dhcp/bin/Debug/Newtonsoft.Json.xml
/home/haraldwolff/src/ln.skyspot/ln.dhcp/obj/Debug/ln.dhcp.csproj.CopyComplete /home/haraldwolff/src/ln.skyspot/ln.dhcp/obj/Debug/ln.dhcp.csproj.CopyComplete
/home/haraldwolff/src/ln.skyspot/ln.dhcp/bin/Debug/Newtonsoft.Json.pdb

Binary file not shown.

Binary file not shown.

4
packages.config 100644
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net47" />
</packages>