32 #include <satcat5/ip_core.h>
34 #include <satcat5/udp_core.h>
37 #ifndef SATCAT5_DHCP_MAX_ID_LEN
38 #define SATCAT5_DHCP_MAX_ID_LEN 62
47 u8
id[SATCAT5_DHCP_MAX_ID_LEN];
104 { m_client_id = id; }
116 void send_message(u8 opcode);
179 {
return (
unsigned)(addr.
value - m_base.
value); }
182 {
return (idx < SIZE) ? (m_base + idx) : ADDR_NONE; }
185 {
return (idx < SIZE) ? (m_array + idx) : 0; }
206 void count_leases(
unsigned& free,
unsigned& taken)
const;
235 u32 client_id, u32 req_ipaddr, u32 req_lease);
237 u32 client_id, u32 req_ipaddr, u32 req_lease);
Callback interface for responding to ARP and ICMP events.
Limited read of next N bytes.
DHCP Client for leasing an IP address from a server.
void inform(const satcat5::ip::Addr &new_addr)
Set a static IP and fetch other parameters from the server.
u32 m_timeout
Time to next action, in seconds.
DhcpClient(satcat5::udp::Dispatch *iface)
Attach this DHCP client to a UDP-dispatch object.
void arp_event(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
Callback for any announced MAC/IP address pair.
void renew()
Request extension of current lease if held, otherwise request a new lease.
satcat5::ip::DhcpState m_state
Client state.
u32 m_server_id
Server-ID (may not match IP-addr)
satcat5::udp::Address m_server
Server IP+MAC address.
void timer_event() override
Child class MUST override this method.
void set_client_id(const satcat5::ip::DhcpId *id)
Set an explicit client identifier (RFC2132 Section 9.14).
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
satcat5::ip::Addr m_ipaddr
Assigned IP address, if any.
satcat5::ip::DhcpState state() const
Report current lease state.
void release(const satcat5::ip::Addr &new_addr=satcat5::ip::ADDR_NONE)
Relinquish the currently held lease, if one exists.
u32 m_xid
Client/server transaction-ID.
u32 status() const
Report remaining lease time, or zero if none is held.
u16 m_seconds
Seconds since start of process.
Generic container for a group of DhcpAddress objects.
virtual satcat5::ip::Addr idx2addr(unsigned idx) const =0
Fetch IP-address for Nth object in the pool.
virtual satcat5::ip::DhcpAddress * idx2meta(unsigned idx)=0
Fetch metadata for Nth object in the pool.or Returns NULL if the index is out of bounds.
satcat5::ip::DhcpAddress * addr2meta(const satcat5::ip::Addr &addr)
Two-step lookup of metadata from address.
virtual unsigned addr2idx(const satcat5::ip::Addr &addr) const =0
Find index associated with the given IP address.
bool contains(const satcat5::ip::Addr &addr)
Does this pool contain the designated address?
The simplest possible implementation of DhcpPool, supporting a contiguous range of IP-addresses from ...
satcat5::ip::DhcpAddress * idx2meta(unsigned idx) override
Fetch metadata for Nth object in the pool.or Returns NULL if the index is out of bounds.
satcat5::ip::Addr idx2addr(unsigned idx) const override
Fetch IP-address for Nth object in the pool.
unsigned addr2idx(const satcat5::ip::Addr &addr) const override
Find index associated with the given IP address.
DHCP Server for managing leases to other clients.
unsigned m_next_timer
Next timer event.
u32 m_max_lease
Maximum lease in seconds.
unsigned m_next_lease
Next lease request.
u32 m_time
Arbitrary timescale (+1/sec)
void set_domain(const char *name)
Set various optional client-configuration fields.
satcat5::ip::Subnet m_gateway
Default gateway and subnet mask.
DhcpServer(satcat5::udp::Dispatch *iface, satcat5::ip::DhcpPool *pool)
Attach this DHCP server to a UDP-dispatch object and address pool.
void set_gateway(const satcat5::ip::Subnet &gateway)
Set various optional client-configuration fields.
satcat5::ip::Addr m_dns
DNS server, if one is available.
const char * m_domain
Domain name (human-readable)
void timer_event() override
Child class MUST override this method.
satcat5::ip::Addr request(u32 lease_seconds, const satcat5::ip::Addr &addr=satcat5::ip::ADDR_NONE)
Manually request/reserve an IP address for the next N seconds.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
void count_leases(unsigned &free, unsigned &taken) const
Report the number of active or open leases.
void max_lease(u32 seconds)
Change the lease timeout. (Mostly used for testing.)
void set_dns(const satcat5::ip::Addr &addr)
Set various optional client-configuration fields.
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Timer objects are polled after a fixed delay or at a regular interval.
Implementation of "net::Address" for UDP Dispatch.
Dispatcher sorts incoming UDP messages by port index.
Protocol handler for the Address Resolution Protocol (ARP)
DhcpState
DHCP protocol state.
Generic network Dispatch API.
Core event-processing loop for SatCat5 software.
An Ethernet MAC address (with serializable interface).
IPv4 address is a 32-bit unsigned integer.
u32 value
Raw access to the underlying representation.
One address in the pool allocated to a DhcpServer.
u32 timeout
Lease expiration time.
u32 client
Hash of client-ID.
A unique client-identifier.
An IPv4 subnet consists of a base address and a subnet mask.