Skip to content

net: reduce log level for PCP/NAT-PMP NOT_AUTHORIZED failures#34117

Closed
ANAVHEOBA wants to merge 2 commits intobitcoin:masterfrom
ANAVHEOBA:master
Closed

net: reduce log level for PCP/NAT-PMP NOT_AUTHORIZED failures#34117
ANAVHEOBA wants to merge 2 commits intobitcoin:masterfrom
ANAVHEOBA:master

Conversation

@ANAVHEOBA
Copy link
Contributor

Users running Bitcoin Core on home networks with routers that don't support PCP (Port Control Protocol) or NAT-PMP port mapping receive frequent warning-level log messages every few minutes:

"pcp: Mapping failed with result NOT_AUTHORIZED (code 2)"

This is expected behavior for many consumer routers that have PCP disabled by default, not an actionable error. The repeated warnings create unnecessary log noise.

This change:

  • Adds explicit constants for NOT_AUTHORIZED result code (value 2) for both NAT-PMP and PCP protocols
  • Downgrades NOT_AUTHORIZED failures from LogWarning to LogDebug since this is an expected condition on many networks
  • Keeps LogWarning for other failure types that may indicate actual configuration or network issues

The NOT_AUTHORIZED message will still be visible when running with -debug=net for users who need to troubleshoot port mapping issues.

Fixes #34114

Users running Bitcoin Core on home networks with routers that don't
support PCP (Port Control Protocol) or NAT-PMP port mapping receive
frequent warning-level log messages every few minutes:

  "pcp: Mapping failed with result NOT_AUTHORIZED (code 2)"

This is expected behavior for many consumer routers that have PCP
disabled by default, not an actionable error. The repeated warnings
create unnecessary log noise.

This change:
- Adds explicit constants for NOT_AUTHORIZED result code (value 2)
  for both NAT-PMP and PCP protocols
- Downgrades NOT_AUTHORIZED failures from LogWarning to LogDebug
  since this is an expected condition on many networks
- Keeps LogWarning for other failure types that may indicate
  actual configuration or network issues

The NOT_AUTHORIZED message will still be visible when running with
-debug=net for users who need to troubleshoot port mapping issues.

Fixes bitcoin#34114
@DrahtBot DrahtBot added the P2P label Dec 19, 2025
@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 19, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34117.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

When -externalip is specified, Bitcoin Core disables automatic address
discovery by setting fDiscover to false. This is intended to prevent
discovery of IPv4/IPv6 addresses when the user already knows their
public IP.

However, this also incorrectly prevented CJDNS addresses from being
discovered and added to the local address list. CJDNS is a separate
overlay network, and specifying an IPv4/IPv6 external IP should not
affect CJDNS address advertising.

This fix modifies:
1. Discover() - Continue processing CJDNS addresses even when fDiscover
   is false, skipping only non-CJDNS addresses
2. AddLocal() - Allow CJDNS addresses to be added even when discovery
   is disabled, since they should still be advertised

Now users running with -externalip and -cjdnsreachable will have their
CJDNS address properly appear in local addresses and be logged via
AddLocal(), matching the behavior when -externalip is not specified.

Fixes bitcoin#33471
@janb84
Copy link
Contributor

janb84 commented Dec 19, 2025

you have created a PR with 2 commits, one is unrelated to this PR it seems

@ANAVHEOBA
Copy link
Contributor Author

Both commit were on the issues list

@janb84
Copy link
Contributor

janb84 commented Dec 22, 2025

Both commit were on the issues list

Not how this works, one PR one topic. Currently the PR description describes the commit for fixing #34114, I suggest that you keep that commit and create a new PR for the other commit, that has code for fixing #33471.

@bensig
Copy link
Contributor

bensig commented Jan 5, 2026

This PR mixes two unrelated changes:

  1. Log level reduction for PCP/NAT-PMP NOT_AUTHORIZED (pcp.cpp) - fixes log: frequent pcp: Mapping failed with result NOT_AUTHORIZED (code 2) logs as net:warning #34114
  2. CJDNS address discovery fix when -externalip is set (net.cpp) - fixes Inconsistent CJDNS address handling in Local addresses and AddLocal logs #33471

These should be separate PRs. Each change looks reasonable on its own, but combining unrelated fixes makes review harder and complicates git history/bisecting.

Would you please split this into two PRs and resubmit?

@maflcko
Copy link
Member

maflcko commented Jan 5, 2026

@ANAVHEOBA are you still working on this?

@ANAVHEOBA
Copy link
Contributor Author

Yes, I push today

@ANAVHEOBA
Copy link
Contributor Author

I am interested in working with bitcoin what is it going to take

@maflcko
Copy link
Member

maflcko commented Jan 6, 2026

I'll go ahead and close this for now. This clearly needs separate pull requests, so this one will need to be closed either way.

@maflcko maflcko closed this Jan 6, 2026
@willcl-ark
Copy link
Member

@ANAVHEOBA do you intend to open a new PR with the first commit only as a fix to #34114?

If you don't want to then I'd be happy to cherry-pick your commit and open a pr with it in, as the fix looks good to me.

luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Jan 22, 2026
…s by default

Users running Bitcoin Core on home networks with routers that don't
support PCP (Port Control Protocol) or NAT-PMP port mapping receive
frequent warning-level log messages every few minutes:

  "pcp: Mapping failed with result NOT_AUTHORIZED (code 2)"

This is expected behavior for many consumer routers that have PCP
disabled by default. The repeated warnings create unnecessary log
noise.

This change:
- Adds explicit constants for NOT_AUTHORIZED result code (value 2)
  for both NAT-PMP and PCP protocols
- Downgrades NOT_AUTHORIZED failures from LogWarning to LogDebug
  after the first failure since this is an expected condition on
  many networks, UNLESS the user has explicitly enabled -natpmp
- Keeps LogWarning for other failure types that may indicate
  actual configuration or network issues

The NOT_AUTHORIZED message will still be visible when running with
-debug=net for users who need to troubleshoot port mapping issues.

Fixes bitcoin#34114

Inspired-by: 78e7259 (bitcoin#34117)
Inspired-by-author: ANAVHEOBA <wisdomabraham92@gmail.com>
princeOmri84

This comment was marked as spam.

@bitcoin bitcoin locked and limited conversation to collaborators Feb 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log: frequent pcp: Mapping failed with result NOT_AUTHORIZED (code 2) logs as net:warning

7 participants