pub struct IpPool { /* private fields */ }Expand description
Used to manage the dynamic collection of IP addresses that the server leases.
Implementations§
Source§impl IpPool
impl IpPool
Sourcepub const FILE_NAME: &'static str = "toe-beans-leases.toml"
pub const FILE_NAME: &'static str = "toe-beans-leases.toml"
The file name that the IpPool is read from and written to.
Sourcepub fn new(config: &Config) -> Self
pub fn new(config: &Config) -> Self
Create a pool with the capacity of the configured network’s size.
Sourcepub fn restore(config: &Config) -> Result<Self>
pub fn restore(config: &Config) -> Result<Self>
Restores the state of an IpPool from a toe-beans-leases.toml as long as the IpPool’s network (range/capacity) has not changed. Static leases are verified to be within network range.
This does not restore dhcp offers.
Sourcepub fn restore_or_new(config: &Config) -> Self
pub fn restore_or_new(config: &Config) -> Self
Use the toe-beans-leases.toml to restore past leases or return a new IpPool if that was not successful.
Sourcepub fn offer(
&mut self,
owner: MacAddress,
requested_ip: Option<Ipv4Addr>,
) -> Result<Ipv4Addr>
pub fn offer( &mut self, owner: MacAddress, requested_ip: Option<Ipv4Addr>, ) -> Result<Ipv4Addr>
Takes an available IP address, marks it as offered, and returns it.
Returns one of:
- The previously offered address, if one has been offered.
- The requested address:
- If one was requested,
- and it is in the pool’s range,
- and it is available
- Otherwise any available address (unless none are available).
Sourcepub fn ack(&mut self, owner: MacAddress) -> Result<Ipv4Addr>
pub fn ack(&mut self, owner: MacAddress) -> Result<Ipv4Addr>
Takes a chaddr’s offered ip address and marks it as reserved then commits it to persistent storage and returns the address.
Currently only one IP is allowed per chaddr.
Sourcepub fn extend(&mut self, owner: MacAddress, ip: Ipv4Addr) -> Result<()>
pub fn extend(&mut self, owner: MacAddress, ip: Ipv4Addr) -> Result<()>
Resets the time of an acked lease. Used in the lease renew/rebind process.
Sourcepub fn unoffer(&mut self, owner: MacAddress) -> Result<()>
pub fn unoffer(&mut self, owner: MacAddress) -> Result<()>
Makes an ip address that was reserved during an offer available again.
Sourcepub fn release(&mut self, owner: MacAddress) -> Result<()>
pub fn release(&mut self, owner: MacAddress) -> Result<()>
Makes an ip address that was acked available again.
Sourcepub fn is_available(&self, ip: &Ipv4Addr) -> bool
pub fn is_available(&self, ip: &Ipv4Addr) -> bool
Checks whether the passed IP address is available in the pool.
Sourcepub fn verify_lease(&self, owner: MacAddress, ip: &Ipv4Addr) -> Result<()>
pub fn verify_lease(&self, owner: MacAddress, ip: &Ipv4Addr) -> Result<()>
Checks if the passed IP address matches the committed, leased IP address, and that the lease is not expired.
Sourcepub fn is_expired(&self, owner: &MacAddress) -> Result<bool>
pub fn is_expired(&self, owner: &MacAddress) -> Result<bool>
Looks up a lease, if one is found, and checks if it has expired.