Skip to main content

Module dhcp

Module dhcp 

Source
Expand description

Minimal DHCPv4 server for access-point clients.

Implements the RFC 2131 subset needed to hand out addresses from a fixed pool: DISCOVER β†’ OFFER, REQUEST β†’ ACK/NAK, plus DECLINE, RELEASE and INFORM. Clients are identified by their hardware address (chaddr); every lease slot owns a stable pool address, so a reconnecting device keeps its previous address.

Replies are broadcast while the client has no address of its own (sender 0.0.0.0 or the RFC 2131 broadcast flag) and unicast for renewals. All packet access goes through the bounds-checked Reader and Writer below β€” client input is never indexed directly.

StructsΒ§

Action πŸ”’
The reply the server decided on for one client message.
ClientMsg πŸ”’
A validated client message.
Lease πŸ”’
One lease slot: a pool address bound to a client hardware address.
Reader πŸ”’
Bounds-checked cursor over an untrusted packet.
Server πŸ”’
The server’s fixed lease pool.
Writer πŸ”’
Bounds-checked cursor that appends to a reply buffer.

ConstantsΒ§

BOOTREPLY πŸ”’
BOOTP op: reply sent by the server (RFC 951).
BOOTREQUEST πŸ”’
BOOTP op: request sent by a client (RFC 951).
CLIENT_PORT πŸ”’
DHCP client port β€” every reply is sent there.
FLAG_BROADCAST πŸ”’
RFC 2131 flags broadcast bit.
HLEN_ETHERNET πŸ”’
hlen: six-byte MAC address length.
HTYPE_ETHERNET πŸ”’
htype: Ethernet hardware type (RFC 826).
LEASE πŸ”’
Lease duration (the embassy-time spelling of LEASE_SECS).
LEASE_SECS πŸ”’
Lease time handed out to clients, in seconds.
MAGIC_COOKIE πŸ”’
Magic cookie 0x63825363 preceding the options area (RFC 2131 Β§4.2).
MSG_ACK πŸ”’
Message type 5: server ACK.
MSG_DECLINE πŸ”’
Message type 4: client DECLINE.
MSG_DISCOVER πŸ”’
Message type 1: client DISCOVER.
MSG_INFORM πŸ”’
Message type 8: client INFORM.
MSG_NAK πŸ”’
Message type 6: server NAK.
MSG_OFFER πŸ”’
Message type 2: server OFFER.
MSG_RELEASE πŸ”’
Message type 7: client RELEASE.
MSG_REQUEST πŸ”’
Message type 3: client REQUEST.
NETMASK πŸ”’
Subnet mask sent with every lease β€” /24, matching super::AP_PREFIX; the pool layout above only supports a /24.
OPT_DNS πŸ”’
Option 6: DNS server.
OPT_END πŸ”’
Option 255: end of the options list.
OPT_LEASE_TIME πŸ”’
Option 51: IP address lease time.
OPT_MESSAGE_TYPE πŸ”’
Option 53: DHCP message type (see the MSG_* constants).
OPT_PAD πŸ”’
Option 0: padding byte (skip).
OPT_REQUESTED_IP πŸ”’
Option 50: requested IP address.
OPT_ROUTER πŸ”’
Option 3: default router.
OPT_SERVER_ID πŸ”’
Option 54: server identifier.
OPT_SUBNET_MASK πŸ”’
Option 1: subnet mask.
POOL_SIZE πŸ”’
Number of lease slots; slot i owns ….<POOL_START + i> (all slots must fit into that /24).
POOL_START πŸ”’
First pool address: <AP_IP network>.<POOL_START> β€” assumes the /24 declared by super::AP_PREFIX.
SERVER_PORT πŸ”’
DHCP server port β€” clients broadcast their requests here.

FunctionsΒ§

build_reply πŸ”’
Assemble a reply packet; returns the number of bytes used.
parse_client πŸ”’
Parse and validate a DHCP request; None for anything that is not a well-formed ethernet BOOTREQUEST from a client.
task
DHCP server task: answers client requests on the access-point interface until reboot. Spawned by super::task after link-up.