Skip to content

Conversation

hakansa
Copy link
Member

@hakansa hakansa commented Sep 11, 2025

Describe your changes

[management,client] Make DNS ForwarderPort Configurable & Change Well Known Port

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

@hakansa hakansa changed the title [client] Make DNS ForwarderPort Configurable & Change Well Known Port [management,client] Make DNS ForwarderPort Configurable & Change Well Known Port Sep 19, 2025
@hakansa hakansa marked this pull request as ready for review September 19, 2025 13:42
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 13:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR makes the DNS forwarder port configurable in the management and client components, while changing the well-known port from 5454 to 22054. The change includes version-aware port assignment to ensure backward compatibility.

  • Adds a configurable ForwarderPort field to the DNS configuration protocol
  • Implements version-based port computation that returns the new port (22054) only when all peers support version 0.58.0 or newer
  • Updates the client to dynamically restart the DNS forwarder when the port changes

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
shared/management/proto/management.proto Adds ForwarderPort field to DNSConfig message
shared/management/proto/management.pb.go Generated protobuf code with ForwarderPort field and getter method
management/server/dns.go Implements port computation logic based on peer versions
management/server/dns_test.go Adds comprehensive tests for the port computation functionality
management/server/grpcserver.go Updates toSyncResponse function to pass all peers for port computation
management/server/peer.go Updates calls to toSyncResponse with additional peers parameter
management/server/peer_test.go Updates test call to toSyncResponse with empty peers slice
client/internal/engine.go Implements DNS forwarder restart logic when port changes
client/internal/dnsfwd/manager.go Updates manager to accept configurable port parameter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 1880 to 1891
func (e *Engine) restartDnsFwd(fwdEntries []*dnsfwd.ForwarderEntry, forwarderPort int) {
log.Infof("updating domain router service port from %d to %d", e.dnsFwdPort, forwarderPort)
// stop and start the forwarder to apply the new port
if err := e.dnsForwardMgr.Stop(context.Background()); err != nil {
log.Errorf("failed to stop DNS forward: %v", err)
}
e.dnsForwardMgr = dnsfwd.NewManager(e.firewall, e.statusRecorder, forwarderPort)
if err := e.dnsForwardMgr.Start(fwdEntries); err != nil {
log.Errorf("failed to start DNS forward: %v", err)
e.dnsForwardMgr = nil
}
}
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function has a duplicate log message (line 1881 and 1882). The log message on line 1881 should be removed since it's identical to the one in the calling function and adds no additional value.

Copilot uses AI. Check for mistakes.

hakansa and others added 4 commits September 19, 2025 23:05
bcmmbaga
bcmmbaga previously approved these changes Sep 19, 2025
if listenPort > 0 {
ListenPort = listenPort
}
m.dnsForwarder = NewDNSForwarder(fmt.Sprintf(":%d", listenPort), dnsTTL, m.firewall, m.statusRecorder)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case the port is 0 we do skip setting it globally. Why do we restart the forwarder with port 0. Should be capital L no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, nice catch! fixed.

pascal-fischer
pascal-fischer previously approved these changes Sep 23, 2025
const (
var (
// ListenPort is the port that the DNS forwarder listens on. It has been used by the client peers also
ListenPort = 5353
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This var is not sufficiently protected against races (e.g. ServeDNS reads this outside of the engine's lock). Why do we need a global var accessed by the engine in the first place?

nit: Make this a uint16, then you don't need to convert everywhere else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this listen port value on DNS Interceptor and somewhere in netflow logger. I've guarded this var with a method and mutex, should be fine now.

Copy link

Copy link
Collaborator

@lixmal lixmal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client changes look OK to me

@mlsmaycon mlsmaycon merged commit 9bcd3eb into main Oct 1, 2025
37 checks passed
@mlsmaycon mlsmaycon deleted the feat/cfg-dns-fwd-port branch October 1, 2025 23:02
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.

5 participants