-onlynet is documented to only affect automatic outbound connections, but it also currently prevents -externalip addresses from being advertised when their network isn’t in the -onlynet set. This is because of the g_reachable_nets.Contains() check in AddLocal(), which rejects all addresses outside the reachable set, regardless of how they were specified.
Previous attempts to fix this (#24835 and #25690) both tried removal of the g_reachable_nets check from AddLocal().
This approach uses a bool flag, fExternalIP, and pass it through AddLocal(), set only in the -externalip startup path. The g_reachable_nets check is bypassed only when this flag is true.
Discovered addresses on non-onlynet networks are still not advertised. The bypass applies only to addresses explicitly provided via -externalip. This addresses the concern raised in #25690 (comment)
I think it might also be weird for a user to activate -onlynet and keep on advertising their clearnet address to the network
Note: -torcontrol and I2P SAM also call AddLocal() with LOCAL_MANUAL but do not set the flag. Whether those paths should also bypass -onlynet is a separate question and this PR therefore intentionally scopes the fix to -externalip only.