ip_forward() looked the route up with NHR_REF and released the nexthop
on every exit. The function runs in the network epoch, and nexthops are
destroyed through NET_EPOCH_CALL(), so the nexthop stays valid until
ip_forward() returns without a reference, as ip_tryforward() already
relies on. The reference costs two atomic operations per packet on a
counter that every CPU forwarding to that nexthop shares.
Look the nexthop up without NHR_REF, and set RT_NH_NOREF on the
on-stack route, so that ip_output() neither releases that nexthop nor
references one it looks up itself.
On a four-core router that encrypts what it forwards into one ESP
tunnel, this takes 60-byte packets from 913 to 970 kpps, and the CPU
time for packets dropped by a blackhole route goes down by 18 %.
No functional change intended.
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")