dhcp

package
v0.0.0-...-5dd9295 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package dhcp provides a Go library for handling Windows DHCP Server resources. The functions are related to the Powershell DhcpServer cmdlets provided by Windows.

https://learn.microsoft.com/en-us/powershell/module/dhcpserver/?view=windowsserver2022-ps

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Connection represents a connection.Connection object.
	Connection connection.Connection
	// contains filtered or unexported fields
}

Client represents a client for handling DHCP server functions.

func NewClient

func NewClient(conn connection.Connection) *Client

NewClient returns a new instance of the Client.

func NewClientWithParser

func NewClientWithParser(conn connection.Connection, parsing func(string) (string, error)) *Client

NewClientWithParser returns a new instance of the Client. It requires a connection and parsing as input parameters.

func (*Client) ExclusionRangeV4Create

func (c *Client) ExclusionRangeV4Create(ctx context.Context, params ExclusionRangeV4CreateParams) (ExclusionRangeV4, error)

ExclusionRangeV4Create creates a new IPv4 exclusion range. It returns a ExclusionRangeV4 object. It returns a *winerror.WinError if the windows client returns an error.

func (*Client) ExclusionRangeV4Delete

func (c *Client) ExclusionRangeV4Delete(ctx context.Context, params ExclusionRangeV4DeleteParams) error

ExclusionRangeV4Delete removes an IPv4 exclusion range. It returns a *winerror.WinError if the windows client returns an error.

func (*Client) ExclusionRangeV4Read

func (c *Client) ExclusionRangeV4Read(ctx context.Context, params ExclusionRangeV4ReadParams) (ExclusionRangeV4, error)

ExclusionRangeV4Read gets a DHCP exclusion range. It returns a ExclusionRangeV4 object. It returns a *winerror.WinError if the windows client returns an error.

func (*Client) FailoverV4Create

func (c *Client) FailoverV4Create(ctx context.Context, params FailoverV4CreateParams) (FailoverV4, error)

FailoverV4Create creates a new IPv4 failover and returns a FailoverV4 object.

func (*Client) FailoverV4Read

func (c *Client) FailoverV4Read(ctx context.Context, params FailoverV4ReadParams) (FailoverV4, error)

FailoverV4Read returns a FailoverV4 object.

func (*Client) ScopeV4Create

func (c *Client) ScopeV4Create(ctx context.Context, params ScopeV4CreateParams) (ScopeV4, error)

ScopeV4Create creates a new DHCP IPv4 scope. It returns a ScopeV4 object. It returns a *winerror.WinError if the windows client returns an error.

func (*Client) ScopeV4Delete

func (c *Client) ScopeV4Delete(ctx context.Context, params ScopeV4DeleteParams) error

ScopeV4Delete removes a DHCP IPv4 scope. It returns a *winerror.WinError if the windows client returns an error.

func (*Client) ScopeV4Read

func (c *Client) ScopeV4Read(ctx context.Context, params ScopeV4ReadParams) (ScopeV4, error)

ScopeV4Read gets a DHCP scope. It returns a ScopeV4 object. It returns a *winerror.WinError if the windows client returns an error.

func (*Client) ScopeV4Update

func (c *Client) ScopeV4Update(ctx context.Context, params ScopeV4UpdateParams) (ScopeV4, error)

ScopeV4Update updates a DHCP IPv4 scope. It returns a ScopeV4 object. It returns a *winerror.WinError if the windows client returns an error.

type ExclusionRangeV4

type ExclusionRangeV4 struct {
	ScopeId    addressString `json:"ScopeId"`
	StartRange addressString `json:"StartRange"`
	EndRange   addressString `json:"EndRange"`
}

ExclusionRangeV4 represents an IPv4 DHCP exclusion range.

type ExclusionRangeV4CreateParams

type ExclusionRangeV4CreateParams struct {
	// Specifies the ending IP address of the range in the subnet from which IP addresses should
	// be leased by the DHCP server service.
	EndRange netip.Addr

	// Specifies the identifier (ID) of the IPv4 scope from which the IP addresses are excluded.
	ScopeId netip.Addr

	// Specifies the starting IP address of the range in the subnet from which IP addresses should be leased
	// by the DHCP server service.
	StartRange netip.Addr
}

ExclusionRangeV4CreateParams represents parameters for the IPv4 exclusion range create function.

type ExclusionRangeV4DeleteParams

type ExclusionRangeV4DeleteParams struct {
	// Specifies the ending IPv4 address of the excluded IP range which is to be deleted.
	EndRange netip.Addr

	// Specifies the scope identifier (ID), in IPv4 address format, from which the exclusion range is to be deleted.
	ScopeId netip.Addr

	// Specifies the starting IPv4 address of the excluded IP range which is to be deleted.
	StartRange netip.Addr
}

ExclusionRangeV4DeleteParams represents parameters for the IPv4 exclusion range delete function.

type ExclusionRangeV4ReadParams

type ExclusionRangeV4ReadParams struct {
	// Specifies the end IP address of the range that is excluded.
	EndRange netip.Addr

	// Specifies the scope ID, in IPv4 address format, from which the excluded IP address range is returned.
	ScopeId netip.Addr

	// Specifies the starting IP address of the range that is excluded.
	StartRange netip.Addr
}

ExclusionRangeV4ReadParams represents parameters for the ipv4 exclusion range read function.

type FailoverV4

type FailoverV4 struct {
	Name                string                  `json:"Name"`
	ScopeId             scopeIdVal              `json:"ScopeId"`
	PrimaryServerIp     addressString           `json:"PrimaryServerIP"`
	PrimaryServerName   string                  `json:"PrimaryServerName"`
	SecondaryServerIp   addressString           `json:"SecondaryServerIP"`
	SecondaryServerName string                  `json:"SecondaryServerName"`
	AutoStateTransition bool                    `json:"AutoStateTransition"`
	EnableAuth          bool                    `json:"EnableAuth"`
	LoadBalancePercent  uint32                  `json:"LoadBalancePercent"`
	MaxClientLeadTime   parsing.CimTimeDuration `json:"MaxClientLeadTime"`
	Mode                string                  `json:"Mode"`
	ReservePercent      uint32                  `json:"ReservePercent"`
	ServerRole          string                  `json:"ServerRole"`
	ServerType          string                  `json:"ServerType"`
	State               string                  `json:"State"`
	StateSwitchInterval parsing.CimTimeDuration `json:"StateSwitchInterval"`
}

FailoverV4 represents an IPv4 failover object.

type FailoverV4CreateParams

type FailoverV4CreateParams struct {
	// Specifies the percentage of DHCP client requests which should be served by the
	// local DHCP server service or the DHCP server service that runs on the computer
	// specified in the ComputerName parameter. The remaining requests would be served
	// by the partner DHCP server service.
	//
	// The default value is 50%.
	LoadBalancePercent uint32

	// Specifies the maximum client lead time for the failover relationship.
	//
	// The default value is 1 hour.
	MaxClientLeadTime time.Duration

	// Specifies the name of the failover relationship to create.
	Name string

	// Specifies the host name, of the partner DHCP server service
	// with which the failover relationship is created.
	PartnerServerName string

	// Specifies the IPv4 address of the partner DHCP server service
	// with which the failover relationship is created.
	PartnerServerIp netip.Addr

	// Specifies the percentage of free IPv4 addresses in the IPv4 address pool of
	// the scope which should be reserved on the standby DHCP server service.
	// In the case of a failover, the IPv4 address from this reserved pool on the
	// standby DHCP server service will be leased to new DHCP clients.
	//
	//The default value is 5.
	ReservePercent uint32

	// Specifies the scope identifiers, in IPv4 address format,
	// which are to be added to the failover relationship.
	ScopeIds []netip.Addr

	// Specifies the role of the local DHCP server service in the hot standby mode.
	//
	// The acceptable values for this parameter are: Active or Standby.
	//
	// The default value is Active for the local DHCP server service,
	// such as the partner DHCP server service that is specified will be a standby DHCP server service.
	ServerRole string

	// Specifies the shared secret to be used for message digest authentication.
	// If not specified, the message digest authentication is turned off.
	SharedSecret string

	// Specifies the time interval for which the DHCP server service operates
	// in the COMMUNICATION INTERRUPTED state before transitioning to the PARTNER DOWN state.
	StateSwitchInterval time.Duration
}

FailoverV4CreateParams represents the parameters for the FailoverV4Create function.

type FailoverV4ReadParams

type FailoverV4ReadParams struct {
	// Specifies the name of a failover relationship for which the properties are returned.
	Name string
}

FailoverV4ReadParams represents the parameters for the FailoverV4Read function.

type ScopeV4

type ScopeV4 struct {
	Name             string                  `json:"Name"`
	Description      string                  `json:"Description"`
	ScopeId          addressString           `json:"ScopeId"`
	StartRange       addressString           `json:"StartRange"`
	EndRange         addressString           `json:"EndRange"`
	SubnetMask       addressString           `json:"SubnetMask"`
	State            string                  `json:"State"`
	MaxBootpClients  uint32                  `json:"MaxBootpClients"`
	ActivatePolicies bool                    `json:"ActivatePolicies"`
	NapEnable        bool                    `json:"NapEnable"`
	NapProfile       string                  `json:"NapProfile"`
	Delay            uint16                  `json:"Delay"`
	LeaseDuration    parsing.CimTimeDuration `json:"LeaseDuration"`
}

ScopeV4 represents an IPv4 DHCP scope.

type ScopeV4CreateParams

type ScopeV4CreateParams struct {
	// Specifies the enabled state of the policy enforcement on the scope that is added.
	ActivatePolicies bool

	// Specifies the number of milliseconds by which the DHCP server service should wait before
	// responding to the client requests. Specify this parameter if the scope is part of a split
	// scope deployment and this DHCP server service should act as a secondary DHCP server service
	// for the scope being added.
	Delay uint16

	// Specifies the description string for the IPv4 scope that is added.
	Description string

	// Specify if the scope is enabled.
	Enabled bool

	// Specifies the ending IP address of the range in the subnet from which IP addresses should
	// be leased by the DHCP server service.
	EndRange netip.Addr

	// Specifies the time interval for which an IP address should be leased to a client in this scope.
	LeaseDuration time.Duration

	// Specifies, if the scope type is specified as Both to allow for both DHCP and BootP clients,
	// the maximum number of BootP clients which should be leased an IP address from this scope.
	MaxBootpClients uint32

	// Specifies the name of the IPv4 scope that is added.
	Name string

	// Specifies the enabled state of Network Access Protection (NAP) for this scope.
	// If NAP is enabled, then the DHCP server service passes the statement of health (SoH) received
	// from the client to the network policy server (NPS). Based on the NAP profile set,
	// the NPS determines the network access to grant to the client.
	NapEnable bool

	// Specifies that the NAP profile should be set only if NAP is enabled on the scope.
	// The NAP profile refers to the MS Service Class which is a condition used in network policies on NPS.
	NapProfile string

	// Specifies the starting IP address of the range in the subnet from which IP addresses should be leased
	// by the DHCP server service.
	StartRange netip.Addr

	// Specifies the subnet mask for the scope specified in IP address format. For example: 255.255.255.0.
	SubnetMask netip.Addr

	// Specifies the name of the superscope to which the scope is added.
	Superscope string

	// Specifies the type of clients to be serviced by the scope.
	// The type of the scope determines whether the DHCP server service responds to only DHCP client requests,
	// only BootP client requests, or Both types of clients.
	//
	// The acceptable values for this parameter are:
	// "Dhcp", "Bootp", "Both".
	Type string
}

ScopeV4CreateParams represents parameters for the scope create function.

type ScopeV4DeleteParams

type ScopeV4DeleteParams struct {
	// Specifies the scope identifier (ID), in IPv4 address format, to delete.
	ScopeId netip.Addr
}

ScopeV4DeleteParams represents parameters for the scope delete function.

type ScopeV4ReadParams

type ScopeV4ReadParams struct {
	// Specify the ID of the scope.
	// This is the scopes network address, e.g. 192.168.10.0.
	ScopeId netip.Addr
}

ScopeV4ReadParams represents parameters for the scope read function.

type ScopeV4UpdateParams

type ScopeV4UpdateParams struct {
	// Specifies the enabled state for the policy enforcement on the scope.
	ActivatePolicies bool

	// Specifies the time, in milliseconds, by which the DHCP server service should delay sending
	//a response to the clients. This parameter should be used on the secondary DHCP server service
	// in a split scope configuration.
	Delay uint16

	// Specifies the description to set for the scope.
	Description string

	// Specify if the scope is enabled.
	Enabled bool

	// Specifies the ending address of the IPv4 range to set for the scope.
	// If a new IPv4 range is being set, then the previously set IPv4 range of the scope is discarded.
	EndRange netip.Addr

	// Specifies the duration of the IPv4 address lease to give for the clients of the scope.
	LeaseDuration time.Duration

	// Specifies the maximum number of Bootp clients permitted to get an IP address lease from the scope.
	// This parameter can only be used if the Type parameter value is Both.
	MaxBootpClients uint32

	// Specifies the name for the scope.
	Name string

	// Specifies the enabled state for network access protection (NAP) for the scope.
	NapEnable bool

	// Specifies the name of the NAP profile for clients in the scope.
	// The NAP profile refers to the Microsoft Service Class which is a condition used in network policies
	// on the network policy server (NPS).
	//
	// This parameter can only be used if the NapEnable parameter value is true.
	NapProfile string

	// Specifies the scope identifier (ID), in IPv4 address format, for which the properties are set.
	ScopeId netip.Addr

	// Specifies the starting address of the IPv4 range to set for the scope.
	// If a new IP range is being set, the previously set IP range of the scope is discarded.
	StartRange netip.Addr

	// Specifies the name of the superscope to which this scope is added.
	Superscope string

	// Specifies the type of the scope.
	// The type of the scope determines if the DHCP server service responds to only DHCP client requests,
	// only BootP client requests, or Both types of clients.
	//
	// The acceptable values for this parameter are:
	// "Dhcp", "Bootp", "Both".
	Type string
}

ScopeV4UpdateParams represents parameters for the scope update function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL