Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fqdn proxy: fix data race detection on TCP fqdn proxy #28219

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/fqdn/dnsproxy/noop_sessionudpfactory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package dnsproxy

import (
"net"

"github.com/cilium/dns"
)

type noopSessionUDPFactory struct{}

var _ dns.SessionUDPFactory = &noopSessionUDPFactory{}

func (*noopSessionUDPFactory) InitPool(msgSize int) {}

func (*noopSessionUDPFactory) ReadRequest(conn *net.UDPConn) ([]byte, dns.SessionUDP, error) {
return nil, nil, nil
}

func (*noopSessionUDPFactory) ReadRequestConn(conn net.PacketConn) ([]byte, net.Addr, error) {
return nil, nil, nil
}

func (*noopSessionUDPFactory) SetSocketOptions(conn *net.UDPConn) error {
return nil
}
3 changes: 3 additions & 0 deletions pkg/fqdn/dnsproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,9 @@ func bindToAddr(address string, port uint16, handler dns.Handler, ipv4, ipv6 boo
}
dnsServers = append(dnsServers, &dns.Server{
Listener: tcpListener, Handler: handler,
// Explicitly set a noop factory to prevent data race detection when InitPool is called
// multiple times on the default factory even for TCP (IPv4 & IPv6).
SessionUDPFactory: &noopSessionUDPFactory{},
// Net & Addr are only set for logging purposes and aren't used if using ActivateAndServe.
Net: ipFamily.TCPAddress, Addr: tcpListener.Addr().String(),
})
Expand Down