In r222488, we introduced ipi_hash_lock alongside ipi_lock, which stopped using ipi_lock for stabilizing four-tuple source/destination matches. This patch adds a second check once the inpcb lock is held in udp_input() and udp6_input().
Also, compare the IP details as a separate function to prevent code duplication.