Since 9f48eea36607 ("rpcbind: get contact addr from xprt members"),
mergeaddr() takes the contact address from svc_getrpccallee(), i.e.
xp_ltaddr. For a UDP transport, svc_dg_create() fills xp_ltaddr once
from getsockname(), and rpcbind's UDP sockets are bound to the wildcard
address, so the contact address is always 0.0.0.0 or ::. addrmerge()
finds no exact match for a wildcard and returns the first non-loopback
address in interface order. The address the request was sent to, the
caller's address and any r_addr hint are all ignored.
Two kinds of callers break:
- The kernel NLM asks rpcbind at ::1 or 127.0.0.1 (UDP, empty r_addr) for rpc.statd's address at startup. It is given another interface's address. If that address is not reachable from rpc.lockd's FIB, the NLM cannot contact rpc.statd, logs "NLM: unexpected error contacting NSM", and rpc.lockd exits.
- A FreeBSD NFSv3 client's kernel NLM asks the server's rpcbind for nlockmgr with a UDP GETADDR and an empty r_addr, and sends its lock requests to the address it gets back. On a multi-homed server that can be an address on another network, so locking fails.
Fix both parts of the lookup:
- Treat a wildcard contact address as unknown. TCP transports are unaffected: their xp_ltaddr is the connection's real local address.
- For UDP over IPv4, use the destination address that svc_dg records for each request in su_srcaddr (IP_RECVDSTADDR), as rpcbind did before 9f48eea36607. xp_p2 is a struct svc_dg_data only for datagram transports, so check the semantics of the transport the request arrived on (xprt->xp_netid). Do not use the netid argument for this: RPCBPROC_GETADDRLIST calls mergeaddr() once per registered entry with that entry's netid, so the "tcp" entries of a request received over UDP would otherwise skip su_srcaddr and be answered with another address.
When neither is available (UDP over IPv6), mergeaddr() falls back to
the r_addr hint and then to the caller's address, as before
9f48eea36607.
PR: 300563
Fixes: 9f48eea36607 ("rpcbind: get contact addr from xprt members")
MFC after: 1 week