From b498e6655e1a1caa88ecb456f84ba09f1fd0584c Mon Sep 17 00:00:00 2001 From: dwimmer Date: Wed, 13 Jun 2018 09:49:32 -0500 Subject: [PATCH] Fix systemd socket connections (#492) Upstream systemd go library broke use of TCP and UDP sockets at the same time. Changed to use lower level API to work around this. Also improved logging of systemd socket connections to include systemd unit file name and address. --- dnscrypt-proxy/systemd_linux.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/dnscrypt-proxy/systemd_linux.go b/dnscrypt-proxy/systemd_linux.go index 5fc561ad..652c70ae 100644 --- a/dnscrypt-proxy/systemd_linux.go +++ b/dnscrypt-proxy/systemd_linux.go @@ -9,24 +9,19 @@ import ( ) func (proxy *Proxy) SystemDListeners() error { - listeners, err := activation.Listeners() - if err == nil && len(listeners) > 0 { - for i, listener := range listeners { - if listener != nil { - dlog.Noticef("Wiring systemd TCP socket #%d", i) - go proxy.tcpListener(listener.(*net.TCPListener)) - } - } - } - packetConns, err := activation.PacketConns() - if err == nil && len(packetConns) > 0 { - for i, packetConn := range packetConns { - if packetConn != nil { - dlog.Noticef("Wiring systemd UDP socket #%d", i) - go proxy.udpListener(packetConn.(*net.UDPConn)) - } + files := activation.Files(true) + + for i, file := range files { + if listener, err := net.FileListener(file); err == nil { + dlog.Noticef("Wiring systemd TCP socket #%d, %s, %s", i, file.Name(), listener.Addr()) + go proxy.tcpListener(listener.(*net.TCPListener)) + } else if pc, err := net.FilePacketConn(file); err == nil { + dlog.Noticef("Wiring systemd UDP socket #%d, %s, %s", i, file.Name(), pc.LocalAddr()) + go proxy.udpListener(pc.(*net.UDPConn)) } + file.Close() } + return nil }