Summary: an IPv4 host with a netmask not matching that of the subnet to which the interface is connected likely builds incorrect routing tables, misses some broadcasts, may incorrectly identify broadcasts as unicasts, and unintentionally broadcast to own subnet.
What does the netmask determine?The netmask (in IPv4 terminology) and network prefix (in IPv6 terminology) can be associated with an IP subnet, and correspondingly with a network interface. This post handles IPv4 only, so the term "netmask" will be used. Together with own IP address, the netmask determines whether another IP address belongs to the same IP subnet as the NIC. Good, so how is this knowledge used?
Processing of multicast packets is not affected by the netmask, thus multicast would not be mentioned here further. For unicast and broadcast, the netmask is consulted in three different situations, listed in the following sections.
Case 1. Netmask can be used as input for constructing the routing tableThe routing system normally automatically creates routes to the subnet to which each network interface belongs. I.e. for each network interface I with address AI and netmask M, the host calculates the subnet of this interface SI = AI & M. Outgoing packets to any address AP such that AP & M = SI would be emitted from the interface I.
While this behavior is typical, nothing mandates hosts to create such routing table entry. For example, if a host has two interfaces on the same subnet, then obviously some more information is needed to decide, which of the interfaces shall send the packets destined to their common subnet. Another example is a firewall with more restrictive forwarding policy than just "put every packet for subnet SI to interface I".
Case 2. Netmask is used to determine whether an arrived packet is a (directed) broadcast to a subnet of some local interfaceAfter the routing is covered, we can limit our further investigation to only:
- Unicast packets, destined to "this host" (i.e. one of its interfaces).
- Directed broadcast packets to "this network". There can be more than one "this" network if the host has more than one network interface (the host can be or not be a router).
- Directed broadcast to a network not in "our network" set is handled as any other packet subject to possible routing.
- Local broadcast packets are obviously not affected by the netmask setting.
For hosts which are not routers RFC922 defines handling of broadcast packets in a simple way:
In the absence of broadcasting, a host determines if it is the recipient of a datagram by matching the destination address against all of its IP addresses. With broadcasting, a host must compare the destination address not only against the host's addresses, but also against the possible broadcast addresses for that host.
Now imagine that an interface of some host has netmask, which does not match one of the subnet this interface is connected to.
Interface misconfigured with shorter netmask fails to process broadcasts: they are understood as unicasts by such host.
- Example: in 18.104.22.168/24 network, a packet to a broadcast address 22.214.171.124 will not be recognized as broadcast by a misconfigured interface 126.96.36.199/16.
- That is, unless the network has all bits in the netmask difference equal to 1.
- Example: in 188.8.131.52/24 network, a packet to a broadcast address 184.108.40.206 will be, by a coincidence, correctly accepted as broadcast by a misconfigured interface 220.127.116.11/16.
- Broadcast packet which is incorrectly understood as unicast by a misconfigured interface can also happen to bear the destination address of this interface itself.
- Example: in 18.104.22.168/16 network, a broadcast packet to 22.214.171.124 will be received as unicast by a misconfigured interface 126.96.36.199/8.
- Additionally, the host may attempt to send a unicast packet which would appear as a valid broadcast on the network.
- Example: in 188.8.131.52/16 network, a host misconfigured as 184.108.40.206/8 sends a unicast to destination address 220.127.116.11. It appears as broadcast on this network. In fact, there can be no host with address 18.104.22.168 on this network (as it is a broadcast address), so nobody answers ARP query and the host will not be able to send such packet.
- Example: in 22.214.171.124/8 network, a packet to a broadcast address 126.96.36.199 will not be received by a misconfigured interface 188.8.131.52/16.
- Again, unless the address of the misconfigured interface happens to have all bits in the netmask difference being equal to 1.
- Example: in that same network, that same broadcast packet will be accepted just fine by a misconfigured interface 184.108.40.206/16.
...if the datagram is addressed to a hardware network to which the gateway is connected, it should be sent as a (data link layer) broadcast on that network. Again, the gateway should consider itself a destination of the datagram.
In this case, the netmask of the router's interface, where the packet has been received, is not relevant - packet should be processed anyway. Instead, the packet's destination interface configuration is the basis for the decision. Correspondingly, mismatch between the netmask of the destination interface and the sender's expectation of the netmask leads to same consequences as listed above for non-forwarding hosts.
Have we covered all cases? Three independent factors affect the outcome:
- Is the receiver's netmask shorter or longer than of the subnet it is connected to?
- Are the bits from the difference in netmask lengths all equal to one?
- Is the packet unicast or (directed) multicast?
Case 3. Netmask is used for setting destination address of outgoing broadcast packetsWhen a host wishes to send a broadcast packet from certain interface, it sets the destination address to that of the interface and puts 1 to all bits which are zeros in the netmask. Correspondingly:
Host with shorter netmask will set too many bits to 1. On the local subnet, these packets will be recognized as belonging to other subnet by other hosts and consequently not processed.
- Example: in /24 network 220.127.116.11/24, host misconfigured as 18.104.22.168/16 sends what it thinks a "broadcast" with destination 22.214.171.124. (It will be sent as link-layer broadcast.) No other host on this network accepts it.
- Unless if the network has all bits in the netmask difference being equal to one.
- Example: in /24 network 126.96.36.199/24, a misconfigured host 188.8.131.52/16 sends a "broadcast" packet to 184.108.40.206, which happens to be a valid broadcast on this network.
- Example: in /8 network 220.127.116.11/8, a host misconfigured as 18.104.22.168/16 sends what it thinks to be a broadcast packet to 22.214.171.124. It appears as valid unicast on this subnet. If there is a host with address 126.96.36.199, this host will accept this packet. (Besides probably unexpected IP content, the host may also notice that the layer 2 address of this packet was a layer 2 broadcast.)
Conclusion1. Netmask is normally (but not necessarily) used as input for the routing table construction. If used, then a wrong interface netmask makes possible the following routing failures:
- Too long netmask: the host will have no route for some packets, actually belonging to a subnet of this interface. Attempt to send packet to a host outside the too long misconfigured netmask but inside the correct netmask of the net results in ICMP error "Destination net unreachable". If there is a default outgoing interface, the host will not generate the error, but send the packets to the default interface instead of the interface of this subnet.
- Too short netmask: the host may attempt to send to the interface packets, which would not be received by any host of the connected subnet. This attempt probably fails, because no host answers the ARP request. This results in ICMP error "Destination host unreachable".
- failure to receive broadcast packets
- failure to forward broadcast packets by routers
- forwarding broadcast packets, destined to own network
- accepting unicast packets, destined to some host, as broadcasts
- accepting broadcast packets as unicast.