For chan_sip, they can be matched on IP address (type=peer), user part of From: header address (type=user), or either (type=friend). I think there is also an option to match on authorisation user, but I don’t know the details, and that clearly wouldn’t help you.
I imagine pjsip has something similar, but I think there are significant structural differences in this area.
That will change and many people would want to do it.
There are plenty of people with dynamic public IP addresses, but who are still using chan_sip on their trunks.
With many moving over to pjsip in the mid term future, this topic will come up again.
The problem is finally solved quite properly. Since Asterisk 14.7 and 13.8 you’re able to set a domain name as external_media_address and external_signaling_address, which dnsmgr resolves regularly. Thereby it’s possbile to run Asterisk behind NAT with a dynamic IP address!