View Source OneDHCPD.IPCalculator (one_dhcpd v2.0.0)
This module handles IP address calculations.
The most involved of the calculations is the determination of a good IP subnet to use. OneDHCPD subnet tries for the following:
- Subnets should be the same across reboots (convenience and no surprise conflicts)
- Support running on more than one interface (unique subnets on device)
- Support hosts than have more than one device (unique subnets between devices)
- Don't conflict with the IPs used on the host for Internet
The algorithm here is to hash the hostname (uniqueness between devices assuming the hostname is unique) and the network interface (uniqueness on device). Then use those bits to pick a subnet in the 172.31.0.0/16 private address range. That private range was picked arbitrarily since 10.0.0.0/8 and 192.168.0.0/16 ranges are commonly used. 172.18.0.0/16 is used by Docker.
Link to this section Summary
Functions
Calculate the default subnet for the specified Ethernet interface.
Calculate the default subnet for the specified Ethernet interface and specify the hostname manually.
Return the subnet mask.
Return our IP address. This is the one that should be set as a static address on the interface if using the defaults.
Return the prefix length that OneDHCPD uses.
Return the IP address that's given out to the client.
Link to this section Functions
Specs
default_subnet(String.t()) :: :inet.ip4_address()
Calculate the default subnet for the specified Ethernet interface.
Specs
default_subnet(String.t(), String.t()) :: :inet.ip4_address()
Calculate the default subnet for the specified Ethernet interface and specify the hostname manually.
Specs
mask() :: :inet.ip4_address()
Return the subnet mask.
Currently this is hardcoded to a /30 network.
Specs
our_ip_address(:inet.ip4_address()) :: :inet.ip4_address()
Return our IP address. This is the one that should be set as a static address on the interface if using the defaults.
Specs
prefix_length() :: 30
Return the prefix length that OneDHCPD uses.
Specs
their_ip_address(:inet.ip4_address()) :: :inet.ip4_address()
Return the IP address that's given out to the client.