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.
- Client
Msg π - 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
flagsbroadcast bit. - HLEN_
ETHERNET π hlen: six-byte MAC address length.- HTYPE_
ETHERNET π htype: Ethernet hardware type (RFC 826).- LEASE π
- Lease duration (the
embassy-timespelling ofLEASE_SECS). - LEASE_
SECS π - Lease time handed out to clients, in seconds.
- MAGIC_
COOKIE π - Magic cookie
0x63825363preceding 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, matchingsuper::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/24declared bysuper::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;
Nonefor anything that is not a well-formed ethernetBOOTREQUESTfrom a client. - task
- DHCP server task: answers client requests on the access-point
interface until reboot. Spawned by
super::taskafter link-up.