diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-06-26 04:29:38 -0700 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-06-26 05:01:58 -0700 |
commit | 77acf6b41f705384593a057c2bea057283bf429b (patch) | |
tree | 1605971b7759d8f81964576dd92d0657efbd37a6 /src/include/ipxe/ip.h | |
parent | 821bb326f87fbc000376fdc5371e9e53f666267a (diff) | |
download | ipxe-77acf6b41f705384593a057c2bea057283bf429b.tar.gz |
[ipv4] Support small subnets with no directed broadcast address
In a small subnet (with a /31 or /32 subnet mask), all addresses
within the subnet are valid host addresses: there is no separate
network address or directed broadcast address.
The logic used in iPXE to determine whether or not to use a link-layer
broadcast address will currently fail in these subnets. In a /31
subnet, the higher of the two host addresses (i.e. the address with
all host bits set) will be treated as a broadcast address. In a /32
subnet, the single valid host address will be treated as a broadcast
address.
Fix by adding the concept of a host mask, defined such that an address
in the local subnet with all of the mask bits set to zero represents
the network address, and an address in the local subnet with all of
the mask bits set to one represents the directed broadcast address.
For most subnets, this is simply the inverse of the subnet mask. For
small subnets (/31 or /32) we can obtain the desired behaviour by
setting the host mask to all ones, so that only the local broadcast
address 255.255.255.255 will be treated as a broadcast address.
Originally-fixed-by: Lukas Stockner <lstockner@genesiscloud.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/ip.h')
-rw-r--r-- | src/include/ipxe/ip.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/include/ipxe/ip.h b/src/include/ipxe/ip.h index 285be6dcd..b1b5cb2e7 100644 --- a/src/include/ipxe/ip.h +++ b/src/include/ipxe/ip.h @@ -64,9 +64,27 @@ struct ipv4_miniroute { /** IPv4 address */ struct in_addr address; - /** Subnet mask */ + /** Subnet mask + * + * An address with all of these bits in common with our IPv4 + * address is in the local subnet. + */ struct in_addr netmask; - /** Gateway address */ + /** Host mask + * + * An address in the local subnet with all of these bits set + * to zero represents the network address, and an address in + * the local subnet with all of these bits set to one + * represents the directed broadcast address. All other + * addresses in the local subnet are valid host addresses. + * + * For most subnets, this is the inverse of the subnet mask. + * In a small subnet (/31 or /32) there is no network address + * or directed broadcast address, and all addresses in the + * subnet are valid host addresses. + */ + struct in_addr hostmask; + /** Gateway address, or zero for no gateway */ struct in_addr gateway; }; |