1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2025-01-01 00:57:32 +01:00

systemd support

How does it work? I don't know. Does it work? I don't know.
Would I encourage its use? No.
This commit is contained in:
Frank Denis 2018-01-24 14:44:32 +01:00
parent 0ce20518db
commit c184ce1a03
5 changed files with 52 additions and 2 deletions

View File

@ -136,7 +136,7 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
proxy.certRefreshDelayAfterFailure = time.Duration(10 * time.Second)
proxy.certIgnoreTimestamp = config.CertIgnoreTimestamp
if len(config.ListenAddresses) == 0 {
return errors.New("No local IP/port configured")
dlog.Debugf("No local IP/port configured")
}
proxy.listenAddresses = config.ListenAddresses
proxy.daemonize = config.Daemonize

View File

@ -18,7 +18,7 @@
## List of local addresses and ports to listen to. Can be IPv4 and/or IPv6.
## To only use systemd activation sockets, use an empty set: []
listen_addresses = ['127.0.0.1:53', '[::1]:53']

View File

@ -10,6 +10,7 @@ import (
"sync"
"time"
"github.com/coreos/go-systemd/activation"
"github.com/coreos/go-systemd/daemon"
"github.com/jedisct1/dlog"
"github.com/kardianos/service"
@ -165,6 +166,9 @@ func (proxy *Proxy) StartProxy() {
dlog.Fatal(err)
}
}
if err := proxy.systemDListeners(); err != nil {
dlog.Fatal(err)
}
liveServers, err := proxy.serversInfo.refresh(proxy)
if liveServers > 0 {
dlog.Noticef("dnscrypt-proxy is ready - live servers: %d", liveServers)
@ -261,6 +265,24 @@ func (proxy *Proxy) tcpListenerFromAddr(listenAddr *net.TCPAddr) error {
return nil
}
func (proxy *Proxy) systemDListeners() error {
listeners, err := activation.Listeners(true)
if err != nil && len(listeners) > 0 {
for i, listener := range listeners {
dlog.Noticef("Wiring systemd TCP socket #%d", i)
proxy.tcpListener(listener.(*net.TCPListener))
}
}
packetConns, err := activation.PacketConns(true)
if err != nil && len(packetConns) > 0 {
for i, packetConn := range packetConns {
dlog.Noticef("Wiring systemd UDP socket #%d", i)
proxy.udpListener(packetConn.(*net.UDPConn))
}
}
return nil
}
func (proxy *Proxy) exchangeWithUDPServer(serverInfo *ServerInfo, encryptedQuery []byte, clientNonce []byte) ([]byte, error) {
pc, err := net.DialUDP("udp", nil, serverInfo.UDPAddr)
if err != nil {

View File

@ -0,0 +1,17 @@
[Unit]
Description=DNSCrypt client proxy
Documentation=man:dnscrypt-proxy(8)
Requires=dnscrypt-proxy.socket
After=network.target
Before=nss-lookup.target
[Install]
Also=dnscrypt-proxy.socket
WantedBy=multi-user.target
[Service]
Type=simple
NonBlocking=true
# Change this
ExecStart=/opt/dnscrypt-proxy/dnscrypt-proxy

View File

@ -0,0 +1,11 @@
[Unit]
Description=dnscrypt-proxy listening socket
[Socket]
ListenStream=127.0.0.1:53
ListenDatagram=127.0.0.1:53
NoDelay=true
DeferAcceptSec=1
[Install]
WantedBy=sockets.target