DHCPv4.Server (DHCP v0.5.0)

View Source

DHCP Server Core - Pure Elixir DHCP protocol implementation for :abyss integration.

This module provides the core DHCP server logic without networking concerns. It handles lease management, IP allocation, and DHCP message processing.

Summary

Functions

Manually expire leases (for testing/cleanup).

Get current leases for monitoring/debugging.

Initialize DHCP server with configuration.

Process incoming DHCP message and return response messages.

Types

config()

@type config() :: %{
  subnet: :inet.ip4_address(),
  netmask: :inet.ip4_address(),
  range_start: :inet.ip4_address(),
  range_end: :inet.ip4_address(),
  gateway: :inet.ip4_address() | nil,
  dns_servers: [:inet.ip4_address()],
  lease_time: integer(),
  options: [DHCPv4.Message.Option.t()]
}

lease()

@type lease() :: %{
  ip: :inet.ip4_address(),
  mac: binary(),
  expires_at: integer(),
  client_id: binary() | nil,
  hostname: String.t() | nil,
  options: [DHCPv4.Message.Option.t()]
}

state()

@type state() :: %{
  config: config(),
  leases: %{required(binary()) => lease()},
  ip_pool: MapSet.t(:inet.ip4_address()),
  used_ips: MapSet.t(:inet.ip4_address())
}

Functions

expire_leases(state)

@spec expire_leases(state()) :: state()

Manually expire leases (for testing/cleanup).

get_leases(state)

@spec get_leases(state()) :: [lease()]

Get current leases for monitoring/debugging.

init(config)

@spec init(config()) :: state()

Initialize DHCP server with configuration.

process_message(state, message, client_ip, port)

@spec process_message(state(), DHCPv4.Message.t(), :inet.ip4_address(), integer()) ::
  {state(), [DHCPv4.Message.t()]}

Process incoming DHCP message and return response messages.