Giter Site home page Giter Site logo

dhcpserverapi's People

Contributors

garysharp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dhcpserverapi's Issues

DhcpServerClientAddressStates - WRONG VALUES!!

Nearly all the "AddressState" information I receive from this API is wrong. The API infers that there is a simple enumeration of five states. This is not so....

Please see link:
https://social.technet.microsoft.com/Forums/en-US/4e6e1313-2743-462f-94a2-f95a6b312bbd/dhcp-lease-address-state-values?forum=winserverPN

Unfortunately, this API is masking the real "byte" value of the true Address State and returns bad values that cannot be correctly interpretted

As an immediate fix... please provide the Raw/native byte value as the Address State is really supplying multiple states/values in one field based on corresponding bit values within the byte (again see link for details).

Exception thrown enumerating ExcludedIpRanges in scope

An exception is thrown when iterating ExcludedIpRanges for a scope in the demo console application. This only happens when the scope does not have any ExcludedIpRanges. I'm actually not sure if the exception should be swallowed by the API and just return 0 objects to the caller or if it should bubble the exception. This seems like one of the rare cases where swallowing the exception might be the appropriate thing to do to avoid messy try/catches in calling code.

Design writable API for Reservations

Determine how writable reservation API should be implemented. Will likely depend on decisions made in #17 and #19.

Requirements:
Create/Update/Delete reservations
Add/Update/Remove reservation options

Blocked by #28

Implement writable subnet API

Blocked by #19

Implement the designed API and perform adhoc testing.

Involving creating/editing:

  • basic subnets (including range and subnet mask)
  • exclusions
  • response delay
  • lease duration
  • respond to DHCP/BOOTP/Both
  • options (Router/Default-Gateway, DNS Parent Domain & Servers
  • scope activation/deactivation

Make DNS settings writable

DNS Settings at the server level and at the individual scope level need to be writable (currently read-only).

  • Implement Native API
  • Update API

Write capability

Hi,
I need to modify the reservation option 67 (bootfile name) from my Web app.

Do you think it's possible to add this function to your .Net API?

BTW, great work, a little gem for DHCP managers, easy to use and program.

DNS Settings are not correctly set

Writing DNS settings does not always result in the desired configuration being made. The flag bits are not being set in the correct manner.

When setting a flag the configuration is as expected (or operation used to set the flag).

When unsetting a flag, the bitwise xor operation is used. This results in the flags value being toggled instead of unset! The nand operation should be used instead (to remove the flag).

Should be (nand):

flags &= ~Constants.DNS_FLAG_UPDATE_BOTH_ALWAYS;

dhcp authorization error 20070?

Hello, I am not an expert and I need to read a dhcp server, specifically from a hosted network, and I want to test your code, but I get this error:

"dhcp authorization error 20070"

I understand that I should request AD permissions, but how would I do it in C #?

I look forward to your help, thank you very much.

Design API for Scope Failover

Failover details are not currently included in the API.

This API change will involve reading, creating, editing and deleting:

  • Failover Relationships (between servers)
  • Failover settings per scope

Blocked by #25 (informs design decisions)

API Change: LeaseDuration should be nullable to represent 'Unlimited'

A scope's lease duration can be unlimited. The platform returns -1 seconds in this case. I propose at the next major release (which allows breaking API compatibility) the DhcpServerScope.LeaseDuration property be changed from TimeSpan to TimeSpan? (Nullable<TimeSpan>). If this value is null it would represent an unlimited lease duration.

Cannot retrieve vendor options

It appears DhcpEnumOptionsV5 must be implemented to retrieve custom vendor options. Interestingly, I can see the vendors options defined in the server classes, but was unable to find a way to access them.

Design writable API for Subnets (+Options)

Determine what the writable API should look like for creating, editing and deleting subnets.

Initial question: Should the API directly update edited properties, or should the properties be changed and a SaveChanges() method be used to commit the changes. A SaveChanges() method would likely be more complex but potentially more efficient - less roundtrips/config-changes for the server.

Filters

Is ist possible to read/write the Filters V4?

Implement writable reservation API

Blocked by #23

Implement the design in #23 and perform adhoc testing.

Involves:

  • Creating Reservations on a Subnet
  • Editing Reservation Name
  • MAC address
  • Description
  • DHCP/BOOTP/Both
  • Adding/Removing Reservation Options & Setting Values

Implement DHCP failover API

Implement the design in #26 and perform adhoc testing.

Involves:

  • Implementing statically-typed models to represent these concepts
  • Reading failover relationships & associations
  • Creating failover relationships
  • Editing failover relationships
  • Assigning failover relationships to subnets

Blocked by #26

can not add option value to reservation

Hello,

I am trying to add a Option Value to a new created reservation, but I am always getting an access violation. I tried both ways as below both times I get the violation.

Can anybody explain me, why this error occurs?

var dhcpServer = DhcpServer.Connect(192.168.0.1);
var scope = dhcpServer.Scopes.First();
var NewReservation = scope.Reservations.AddReservation("192.168.0.10", "AA:BB:CC:DD:EE:FF");
NewReservation.Client.Name = "Demo";
var Option67 = dhcpServer.Options.GetDefaultOption(67);
var ReservationOption67 = Option67.CreateOptionStringValue("demo");
NewReservation.Options.AddOrSetOptionValue(Option67);

NewReservation.Options.SetOptionValue(dhcpServer.Options.GetDefaultOption(67).CreateOptionStringValue("DEMO"));

Run into error when listing huge list of reservations

Hi,

I tried to get a list of all reservations on a dhcp server 2016 scope, but I ran into an error, that I attempted to read or write protected memory. Reading other scopes from other server with less reservations are working without any error. I am currently using 1.0.9 alpha version.

Currently there are more that 500 reservations in the scope. Do I run against any limits here?

Make global (server) options writable

Option values can only be written at the Scope and Reservation level.

Server-options should also be writable (and is required for #33 as DNS settings are stored as an option).

Just as with scopes and reservations, it would be expected that the API be exposed as Server.Options.[Set|Remove][Default|User|Vendor]OptionValue()

Enumerating Clients when none exist results in an exception

The following exception is thrown when trying to enumerate clients of a subnet with no clients.

Unhandled Exception: Dhcp.DhcpServerException: An error occurred calling 'DhcpEnumSubnetClientsVQ'. No more data is available. [ERROR_NO_MORE_ITEMS 259]
   at Dhcp.DhcpServerClient.<GetClientsVQ>d__64.MoveNext() in C:\GitHub\DhcpServerApi\src\Dhcp\DhcpServerClient.cs:line 317
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Expected behaviour is to return an empty list.

Correct memory leaks

Blocked by #13.
This task is a placeholder for any eventual tasks which are determined as necessary as a result.

Issue in syntax

Hi,

You wrote this on the readme:

// Connect to DHCP Server
var dhcpServer = DhcpServer.Servers.First();

// Display scope information
foreach (var scope in dhcpServer.Scopes)
{
Console.WriteLine("Scope: ", scope.Name);
Console.WriteLine(" Address: ", scope.Address);
Console.WriteLine(" Mask: ", scope.Mask);
Console.WriteLine(" Range: ", scope.IpRange);
Console.WriteLine(" State: ", scope.State);
}

But there is an issue, it should be:

// Connect to DHCP Server
var dhcpServer = DhcpServer.Servers.First();

// Display scope information
foreach (var scope in dhcpServer.Scopes)
{
Console.WriteLine("Scope: {0}", scope.Name);
Console.WriteLine(" Address: {0}", scope.Address);
Console.WriteLine(" Mask: {0}", scope.Mask);
Console.WriteLine(" Range: {0}", scope.IpRange);
Console.WriteLine(" State: {0}", scope.State);
}

Hope it helps,

Arnaud H.

DHCP Server and Scope - Policies

Hi gary,
I take this opportunity to tell you that you have done a really good job on this fantastic library.
I wanted to ask you if there was the possibility of being able to manage the "Policies" functionality. I couldn't find it on the repository.

image

Thank you,
Salvatore

Determine if entity cache can be removed

Currently the API caches lists of entites which could result in stale values for long-running processes. I feel the responsibility of caching certain values should be moved to the consumer (eg. a UI).

Implement DHCP Callout API

While not specifically related to the v1.0 project, source code was recovered which included a previous upgrade to this library.
The major feature worked on in this recovered source (besides efforts into #14) included an implementation of the DHCP Callout API.

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/dhcp/dhcp-server-api

Using DllExport this implementation allows for a managed .NET library to be loaded and interface directly with the DHCP Server.

All hooks are provided and can be consumed by simply implementing the managed interface.

The library automatically discovers and hooks multiple consumers and compiles with the Callout chaining technique.

DhcpCreateClientInfo not VQ

Hi @garysharp ,
When creating a reservation using the full AddClient parameters, then looking at the DHCP server, the DHCP type is always set to Both, but I set it to DHCP. Looking at the API code, I see you're not using the VQ version of the DhcpCreateClientInfo:

public static extern DhcpErrors DhcpCreateClientInfo(string ServerIpAddress, IntPtr ClientInfo);

Can it be the reason of the missing attributes creation?

Implement native methods for DHCP failover

Failover details are not currently included in the API. Create/Read/Update/Delete operations will be required.

Methods:

  • DhcpV4FailoverAddScopeToRelationship
  • DhcpV4FailoverCreateRelationship
  • DhcpV4FailoverDeleteRelationship
  • DhcpV4FailoverDeleteScopeFromRelationship
  • DhcpV4FailoverEnumRelationship
  • DhcpV4FailoverGetAddressStatus
  • DhcpV4FailoverGetClientInfo
  • DhcpV4FailoverGetRelationship
  • DhcpV4FailoverGetScopeRelationship
  • DhcpV4FailoverGetScopeStatistics
  • DhcpV4FailoverGetSystemTime
  • DhcpV4FailoverSetRelationship
  • DhcpV4FailoverTriggerAddrAllocation

Structures:

  • DHCP_FAILOVER_MODE
  • DHCP_FAILOVER_RELATIONSHIP
  • DHCP_FAILOVER_RELATIONSHIP_ARRAY
  • DHCP_FAILOVER_SERVER
  • DHCP_FAILOVER_STATISTICS
  • DHCPV4_FAILOVER_CLIENT_INFO
  • DHCPV4_FAILOVER_CLIENT_INFO_ARRAY

Note: Failover API functionality is supported Windows Server 2012 and newer.

Provide access to native API errors

When catching exceptions its nice to be able to filter for a particular API error.

For example:

// Discover DHCP Servers
try
{
    dhcpServers = DhcpServer.Servers.ToList();
}
catch (DhcpServerException ex) when (ex.ApiErrorNative == DhcpServerNativeErrors.DDS_NO_DS_AVAILABLE)
{
    // No DHCP Servers could be automatically discovered
}

Unable to impersonate user

I'm trying to impersonate a user so that I can pass in custom credentials when authenticating to the DHCP server, but it appears to ignore the impersonation context in most cases. It would be excellent if I could simply pass credentials in when calling Connect

Code cleanup

Perform some code cleanup to modernize and re-familiarize myself with the codebase.

Convert to interpolated strings
Convert simple parameters to lambda expression methods
Add readonly field hints
Convert static strings to use nameof() syntax (particularly with DhcpServerException constructor)
etc

Determine if project can be converted to .NET Standard

Migrating the project to .NET Standard would allow compatibility between the Full .NET Framework and .NET Core.

Possibly .NET Standard 1.1 (minimum requires .NET 4.5 or .NET Core 1.0).

If additional framework features are required I'm inclined to upgrade the requirement. If anyone has particular backwards compatibility requirements please speak up.

Scope loading performance improvements

For servers with large numbers of scopes (especially those with large latency between the library and the DHCP server) the (significant) number of round-trips impacts performance greatly.

It has been identified that all failover relationships and all clients can be loaded with a single API call. When enumerating scopes we can preload failover relationships and clients, pre-populating this data and avoid significant server roundtrips.

However, this behavior should be opt-in. Eager-loading all of this data is likely undesirable, unless specifically needing this behavior. An additional method should be added to the ScopeCollection class allowing consumers to request preloading of failover relationships and/or clients when enumerating scopes.

No behavior should change when loading individual scopes.

Memory leak somewhere in DhcpServerClient.GetClients()

If I use DhcpServerClient.GetClients() in my code, I can watch my process memory usage continuously increase until I stop and restart my process. I narrowed it down to somewhere in here but I'm not knoweldagable enough of the library at this point to fix it.

Hardware address exceeds maximum length

A user has encountered a ArgumentOutOfRangeException when reading scope reservations.

Unhandled Exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: length
   at Dhcp.DhcpServerHardwareAddress.FromNative(DhcpServerHardwareType type, IntPtr pointer, Int32 length) in src\Dhcp\DhcpServerHardwareAddress.cs:line 166
   at Dhcp.Native.DHCP_CLIENT_UID.get_ClientHardwareAddress() in src\Dhcp\Native\DHCP_CLIENT_UID.cs:line 53
   at Dhcp.DhcpServerScopeReservation.FromNative(DhcpServerScope scope, DHCP_IP_RESERVATION_V4& native) in src\Dhcp\DhcpServerScopeReservation.cs:line 91
   at Dhcp.DhcpServerScopeReservation.GetReservations(DhcpServerScope scope)+MoveNext() in src\Dhcp\DhcpServerScopeReservation.cs:line 74
   ...

This occurred when a reservation had been configured with an invalid hardware address. Unfortunately it means the reservations and clients cannot be enumerated (as this invalid one causes the enumeration to fail).

This library receives some big efficiency boosts by treating hardware addresses as value types (living on the stack instead of needing memory allocated). Typical hardware addresses are 24 bits long. I have encountered scenarios where 128 bit hardware addresses were used. This determined a maximum supported hardware address length (16 bytes; 2 x unsigned long).

I don't know what the limit is for the Microsoft DHCP Server.

We need a way of flagging a hardware address as invalid and perhaps offering the truncated value in a way which still allows reservations/clients to be enumerated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.