one_dhcpd v0.2.1 OneDHCPD.IPCalculator
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.16.0.0/12 private address range. That private range was picked arbitrarily since it seems like the 10.0.0.0/8 and 192.168.0.0/16 ranges are used a lot more often in home and corporate networks.
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 IP address that's given out to the client
Link to this section Functions
default_subnet(ifname)
default_subnet(String.t()) :: :inet.ip4_address()
default_subnet(String.t()) :: :inet.ip4_address()
Calculate the default subnet for the specified Ethernet interface.
default_subnet(ifname, hostname)
default_subnet(String.t(), String.t()) :: :inet.ip4_address()
default_subnet(String.t(), String.t()) :: :inet.ip4_address()
Calculate the default subnet for the specified Ethernet interface and specify the hostname manually.
mask()
mask() :: :inet.ip4_address()
mask() :: :inet.ip4_address()
Return the subnet mask.
Currently this is hardcoded to a /30 network.
our_ip_address(arg)
our_ip_address(:inet.ip4_address()) :: :inet.ip4_address()
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.
their_ip_address(arg)
their_ip_address(:inet.ip4_address()) :: :inet.ip4_address()
their_ip_address(:inet.ip4_address()) :: :inet.ip4_address()
Return the IP address that's given out to the client.