Skip to content

Commit 489886d

Browse files
committed
feat: advertise DNS services to peers
1 parent f066030 commit 489886d

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

pkg/cmd/nodecmd/global/global.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ func (o *Options) Overlay(opts ...any) error {
234234
}
235235
}
236236
if primaryEndpoint.IsValid() {
237+
// Determine the raft and wireguard ports so we can set our
238+
// advertise addresses.
237239
var raftPort, wireguardPort uint16
238240
for _, inOpts := range opts {
239241
if vopt, ok := inOpts.(*raft.Options); ok {
@@ -321,7 +323,20 @@ func (o *Options) Overlay(opts ...any) error {
321323
v.TURN.PublicIP = primaryEndpoint.String()
322324
}
323325
}
324-
326+
if v.MeshDNS.Enabled && v.MeshDNS.ListenUDP != "" && !o.DisableFeatureAdvertisement {
327+
// Set the advertise DNS port
328+
dnsAddr, err := netip.ParseAddrPort(v.MeshDNS.ListenUDP)
329+
if err != nil {
330+
return fmt.Errorf("failed to parse listen address: %w", err)
331+
}
332+
for _, inOpts := range opts {
333+
if vopt, ok := inOpts.(*mesh.Options); ok {
334+
if vopt.Mesh.DNSPort == 0 {
335+
vopt.Mesh.DNSPort = int(dnsAddr.Port())
336+
}
337+
}
338+
}
339+
}
325340
}
326341
}
327342
return nil

pkg/mesh/mesh_join.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func (s *meshStore) joinWithConn(ctx context.Context, c *grpc.ClientConn, featur
137137
PublicKey: key.PublicKey().String(),
138138
RaftPort: int32(s.raft.ListenPort()),
139139
GrpcPort: int32(s.opts.Mesh.GRPCPort),
140+
MeshdnsPort: int32(s.opts.Mesh.DNSPort),
140141
PrimaryEndpoint: s.opts.Mesh.PrimaryEndpoint,
141142
WireguardEndpoints: s.opts.WireGuard.Endpoints,
142143
ZoneAwarenessId: s.opts.Mesh.ZoneAwarenessID,

pkg/mesh/options_mesh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333
MaxJoinRetriesEnvVar = "MESH_MAX_JOIN_RETRIES"
3434
JoinTimeoutEnvVar = "MESH_JOIN_TIMEOUT"
3535
GRPCAdvertisePortEnvVar = "MESH_GRPC_PORT"
36+
DNSAdvertisePortEnvVar = "MESH_DNS_PORT"
3637
PrimaryEndpointEnvVar = "MESH_PRIMARY_ENDPOINT"
3738
NodeRoutesEnvVar = "MESH_ROUTES"
3839
NodeDirectPeersEnvVar = "MESH_DIRECT_PEERS"
@@ -64,6 +65,8 @@ type MeshOptions struct {
6465
DirectPeers []string `json:"direct-peers,omitempty" yaml:"direct-peers,omitempty" toml:"direct-peers,omitempty"`
6566
// GRPCPort is the port to advertise for gRPC.
6667
GRPCPort int `json:"grpc-port,omitempty" yaml:"grpc-port,omitempty" toml:"grpc-port,omitempty"`
68+
// DNSPort is the port to advertise for DNS.
69+
DNSPort int `json:"dns-port,omitempty" yaml:"dns-port,omitempty" toml:"dns-port,omitempty"`
6770
// NoIPv4 disables IPv4 usage.
6871
NoIPv4 bool `json:"no-ipv4,omitempty" yaml:"no-ipv4,omitempty" toml:"no-ipv4,omitempty"`
6972
// NoIPv6 disables IPv6 usage.
@@ -121,6 +124,8 @@ func (o *MeshOptions) BindFlags(fl *flag.FlagSet) {
121124
"Join the cluster as a voter. Default behavior is to join as an observer.")
122125
fl.IntVar(&o.GRPCPort, "mesh.grpc-port", util.GetEnvIntDefault(GRPCAdvertisePortEnvVar, 8443),
123126
"GRPC advertise port.")
127+
fl.IntVar(&o.DNSPort, "mesh.dns-port", util.GetEnvIntDefault(DNSAdvertisePortEnvVar, 0),
128+
"DNS advertise port. This is set automatically when advertising is enabled and the mesh-dns server is running. Default is 0 (disabled).")
124129
fl.StringVar(&o.PrimaryEndpoint, "mesh.primary-endpoint", util.GetEnvDefault(PrimaryEndpointEnvVar, ""),
125130
`The primary endpoint to broadcast when joining a cluster.
126131
This is only necessary if the node intends on being publicly accessible.`)

pkg/meshdb/peers/peers.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,8 @@ func (p *peers) ListByFeature(ctx context.Context, feature v1.Feature) ([]Node,
314314
}
315315
out := make([]Node, 0)
316316
for _, node := range nodes {
317-
for _, f := range node.Features {
318-
if f == feature {
319-
out = append(out, node)
320-
break
321-
}
317+
if node.HasFeature(feature) {
318+
out = append(out, node)
322319
}
323320
}
324321
return out, nil

pkg/net/inspect/inspect.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

pkg/services/node/server_join.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ func (s *Server) Join(ctx context.Context, req *v1.JoinRequest) (*v1.JoinRespons
408408
log.Warn("could not lookup DNS servers", slog.String("error", err.Error()))
409409
} else {
410410
for _, peer := range dnsServers {
411+
if peer.ID == req.GetId() {
412+
continue
413+
}
411414
switch {
412415
// Prefer the IPv4 address
413416
case peer.PrivateDNSAddrV4().IsValid():
@@ -437,6 +440,9 @@ func (s *Server) Join(ctx context.Context, req *v1.JoinRequest) (*v1.JoinRespons
437440
return nil, status.Errorf(codes.Internal, "failed to list peers by ICE feature: %v", err)
438441
}
439442
for _, peer := range peers {
443+
if peer.ID == req.GetId() {
444+
continue
445+
}
440446
// We only return peers that are publicly accessible for now.
441447
// This should be configurable in the future.
442448
publicAddr := peer.PublicRPCAddr()

0 commit comments

Comments
 (0)