Safe Haskell | None |
---|---|
Language | Haskell98 |
The Dhcp4
module defines the various messages and
transitions used in the DHCPv4 protocol. This module provides both
a high-level view of the message types as well as a low-level
intermediate form which is closely tied to the binary format.
References: RFC 2131 - Dynamic Host Configuration Protocol http://www.faqs.org/rfcs/rfc2131.html
- data RequestMessage
- data Request = Request {}
- data Discover = Discover {}
- data ServerSettings = Settings {}
- data ReplyMessage
- data Ack = Ack {
- ackHops :: Word8
- ackXid :: Xid
- ackYourAddr :: IP4
- ackServerAddr :: IP4
- ackRelayAddr :: IP4
- ackClientHardwareAddr :: Mac
- ackLeaseTime :: Word32
- ackOptions :: [Dhcp4Option]
- data Offer = Offer {}
- data Dhcp4Message = Dhcp4Message {
- dhcp4Op :: Dhcp4Op
- dhcp4Hops :: Word8
- dhcp4Xid :: Xid
- dhcp4Secs :: Word16
- dhcp4Broadcast :: Bool
- dhcp4ClientAddr :: IP4
- dhcp4YourAddr :: IP4
- dhcp4ServerAddr :: IP4
- dhcp4RelayAddr :: IP4
- dhcp4ClientHardwareAddr :: Mac
- dhcp4ServerHostname :: String
- dhcp4BootFilename :: String
- dhcp4Options :: [Dhcp4Option]
- newtype Xid = Xid Word32
- requestToAck :: ServerSettings -> Request -> Ack
- discoverToOffer :: ServerSettings -> Discover -> Offer
- mkDiscover :: Xid -> Mac -> Discover
- offerToRequest :: Offer -> Request
- requestToMessage :: Request -> Dhcp4Message
- ackToMessage :: Ack -> Dhcp4Message
- offerToMessage :: Offer -> Dhcp4Message
- discoverToMessage :: Discover -> Dhcp4Message
- parseDhcpMessage :: Dhcp4Message -> Maybe (Either RequestMessage ReplyMessage)
- getDhcp4Message :: ByteString -> Either String Dhcp4Message
- putDhcp4Message :: Dhcp4Message -> ByteString
High-level client types
data RequestMessage Source
RequestMessage
is a sum of the client request messages.
Request
is used by the client to accept an offered lease.
Request | |
|
Discover
is used by the client to discover what servers are available.
This message is sent to the IPv4 broadcast.
Discover | |
|
High-level server types
data ServerSettings Source
ServerSettings
define all of the information that would be needed to
act as a DHCP server for one client. The server is defined to be able to
issue a single "lease" whose parameters are defined below.
Settings | |
|
data ReplyMessage Source
ReplyMessage
is a sum of the server response messages.
Ack
is sent by the DHCPv4 server to acknowledge a sucessful Request
message. Upon receiving this message the client has completed the
exchange and has successfully obtained a lease.
Ack | |
|
Offer
is sent by the DHCPv4 server in response to a Discover
.
This offer is only valid for a short period of time as the client
might receive many offers. The client must next request a lease
from a specific server using the information in that server's offer.
Offer | |
|
Low-level message types
data Dhcp4Message Source
Dhcp4Message
is a low-level message container that is very close to
the binary representation of DHCPv4 message. It is suitable for containing
any DHCPv4 message. Values of this type should only be created using the
publicly exported functions.
Dhcp4Message | |
|
Xid
is a Transaction ID, a random number chosen by the client,
used by the client and server to associate messages and responses between a
client and a server.
Server message transition logic
:: ServerSettings | DHCPv4 server settings |
-> Request | Client's request message |
-> Ack |
requestToAck
creates Ack
messages suitable for responding to Request
messages given a static ServerSettings
configuration.
:: ServerSettings | DHCPv4 server settings |
-> Discover | Client's discover message |
-> Offer |
discoverToOffer
creates a suitable Offer
in response to a client's
Discover
message using the configuration settings specified in the
given ServerSettings
.
Client message transition logic
mkDiscover
creates a new Discover
message with a set
of options suitable for configuring a basic network stack.
offerToRequest
creates a Request
message suitable for accepting
an Offer
from the DHCPv4 server.
Convert high-level message types to low-level format
requestToMessage :: Request -> Dhcp4Message Source
requestToMessage
embeds Request
messages in the low-level
Dhcp4Message
type, typically for the purpose of serialization.
ackToMessage :: Ack -> Dhcp4Message Source
ackToMessage
embeds Ack
messages in the low-level
Dhcp4Message
type, typically for the purpose of serialization.
offerToMessage :: Offer -> Dhcp4Message Source
offerToMessage
embeds Offer
messages in the low-level
Dhcp4Message
type, typically for the purpose of serialization.
discoverToMessage :: Discover -> Dhcp4Message Source
discoverToMessage
embeds Discover
messages in the low-level
Dhcp4Message
type, typically for the purpose of serialization.
Convert low-level message type to high-level format
parseDhcpMessage :: Dhcp4Message -> Maybe (Either RequestMessage ReplyMessage) Source
parseDhcpMessage
attempts to find a valid high-level message
contained in a low-level message. The Dhcp4Message
is a large
type and can encode invalid combinations of options.
Convert low-level message type to binary format
getDhcp4Message :: ByteString -> Either String Dhcp4Message Source
getDhcp4Message
is the binary decoder for parsing Dhcp4Message
values.
putDhcp4Message :: Dhcp4Message -> ByteString Source
getDhcp4Message
is the binary encoder for rendering Dhcp4Message
values.