one_dhcpd v0.1.0 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

Link to this function default_subnet(ifname)
default_subnet(String.t()) :: :inet.ip4_address()

Calculate the default subnet for the specified Ethernet interface.

Link to this function default_subnet(ifname, hostname)
default_subnet(String.t(), String.t()) :: :inet.ip4_address()

Calculate the default subnet for the specified Ethernet interface and specify the hostname manually.

Return the subnet mask.

Currently this is hardcoded to a /30 network.

Link to this function our_ip_address(arg)
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.

Link to this function their_ip_address(arg)
their_ip_address(:inet.ip4_address()) :: :inet.ip4_address()

Return the IP address that’s given out to the client.