Skip to content

dns: support an opt-in custom detection port - #3232

Merged
lucaderi merged 1 commit into
ntop:devfrom
RajaMuhammadAwais:fix/1788-custom-dns-port
Aug 23, 2026
Merged

dns: support an opt-in custom detection port#3232
lucaderi merged 1 commit into
ntop:devfrom
RajaMuhammadAwais:fix/1788-custom-dns-port

Conversation

@RajaMuhammadAwais

@RajaMuhammadAwais RajaMuhammadAwais commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Related issue

Fixes #1788

Summary

DNS detection is currently restricted to the standard DNS, mDNS, and LLMNR ports. This prevents nDPI from recognizing valid DNS traffic deployed on a user-selected nonstandard port. The behavior was confirmed in the issue discussion and reproduced with the official dns_on_port_80.pcapng capture.

This pull request adds an explicit, disabled-by-default configuration parameter that enables DNS detection on one additional exact TCP or UDP port.

Configuration

--cfg=dns,custom_port,80

The default value is 0, which keeps existing behavior unchanged. The accepted range is 0 through 65535. Only the configured port is added to the DNS entry-point gate. Standard DNS on port 53, mDNS on port 5353, and LLMNR on port 5355 retain their existing handling.

Implementation details

The DNS port classification helper now receives the nDPI configuration context and returns NDPI_PROTOCOL_DNS only when the configured custom port matches either flow endpoint. Existing DNS structural validation remains mandatory, so enabling a custom port does not classify arbitrary traffic solely because it uses that port.

The configuration parameter is registered in src/lib/ndpi_config.c, stored in the private configuration structure, and documented in doc/configuration_parameters.rst.

Evidence and regression testing

The official issue capture is included as the positive regression fixture:

PCAP: tests/cfgs/dns_custom_port/pcap/dns_on_port_80.pcapng
Config: --cfg=dns,custom_port,80
Result: DNS, 2 packets, 1 flow

The same capture without the configuration remains Unknown, confirming that the option is disabled by default. Standard DNS traffic remains classified as DNS when the option is enabled. An unrelated HTTP capture with port 80 produced no DNS classification. An invalid value of 70000 is rejected by the configuration API.

The following checks passed locally:

make -j2
./tests/unit/unit
Focused positive and negative ndpiReader checks
Standard DNS compatibility check
Port-80 HTTP false-positive check
Invalid configuration range check
Address, Undefined, and Leak Sanitizer build and fixture run
git diff --check

The sanitizer run completed without an AddressSanitizer, UndefinedBehaviorSanitizer, or LeakSanitizer report.

Files changed

File Change
src/lib/protocols/dns.c Add exact custom-port matching while preserving standard-port logic
src/lib/ndpi_config.c Register dns.custom_port with default 0 and range 0 to 65535
src/include/ndpi_private.h Add the private configuration field
doc/configuration_parameters.rst Document the parameter and its default behavior
tests/cfgs/dns_custom_port/ Add the official PCAP fixture, configuration, and expected output

Checklist

References

  1. nDPI issue #1788
  2. nDPI contributing guidelines
  3. Fork branch

Keep standard DNS, mDNS, and LLMNR port handling unchanged while allowing deployments with DNS on one explicitly configured port. The option is disabled by default and is covered by the official DNS-on-port-80 regression capture, including the expected classification output.
@sonarqubecloud

Copy link
Copy Markdown

@lucaderi
lucaderi merged commit 54d23c2 into ntop:dev Aug 23, 2026
13 of 27 checks passed
@lucaderi

Copy link
Copy Markdown
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nDPI fails to recognize custom DNS ports

2 participants