Page MenuHomeFreeBSD

Don't iterate over the ifnet addr list in ip_output()
ClosedPublic

Authored by rstone on Jul 20 2016, 11:45 PM.

Details

Summary

For almost every packet that is transmitted through ip_output(),
a call to in_broadcast() was made to decide if the destination
IP was a broadcast address. in_broadcast() iterates over the
ifnet's address to find a source IP matching the subnet of the
destination IP, and then checks if the IP is a broadcast in that
subnet.

This is completely redundant as we have already performed the
route lookup, so the source IP is already known. Just use that
address to directly check whether the destination IP is a
broadcast address or not.

Test Plan

Used ping, traceroute and a custom UDP program to send broadcast packets, and used dtrace to ensure that in_ifaddr_broadcast() was returning the right result.

Used traceroute -r to send packets on an SO_DONTROUTE socket and confirmed that in_ifaddr_broadcast() returned the right result and that a broadcast or unicast MAC address was used appropriately.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

rstone retitled this revision from to Don't iterate over the ifnet addr list in ip_output().
rstone edited the test plan for this revision. (Show Details)
rstone updated this object.
This revision was automatically updated to reflect the committed changes.