mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-04 13:47:39 +03: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:
parent
0ce20518db
commit
c184ce1a03
5 changed files with 52 additions and 2 deletions
|
@ -136,7 +136,7 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
|
||||||
proxy.certRefreshDelayAfterFailure = time.Duration(10 * time.Second)
|
proxy.certRefreshDelayAfterFailure = time.Duration(10 * time.Second)
|
||||||
proxy.certIgnoreTimestamp = config.CertIgnoreTimestamp
|
proxy.certIgnoreTimestamp = config.CertIgnoreTimestamp
|
||||||
if len(config.ListenAddresses) == 0 {
|
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.listenAddresses = config.ListenAddresses
|
||||||
proxy.daemonize = config.Daemonize
|
proxy.daemonize = config.Daemonize
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
## List of local addresses and ports to listen to. Can be IPv4 and/or IPv6.
|
## 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']
|
listen_addresses = ['127.0.0.1:53', '[::1]:53']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/coreos/go-systemd/activation"
|
||||||
"github.com/coreos/go-systemd/daemon"
|
"github.com/coreos/go-systemd/daemon"
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/kardianos/service"
|
"github.com/kardianos/service"
|
||||||
|
@ -165,6 +166,9 @@ func (proxy *Proxy) StartProxy() {
|
||||||
dlog.Fatal(err)
|
dlog.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := proxy.systemDListeners(); err != nil {
|
||||||
|
dlog.Fatal(err)
|
||||||
|
}
|
||||||
liveServers, err := proxy.serversInfo.refresh(proxy)
|
liveServers, err := proxy.serversInfo.refresh(proxy)
|
||||||
if liveServers > 0 {
|
if liveServers > 0 {
|
||||||
dlog.Noticef("dnscrypt-proxy is ready - live servers: %d", liveServers)
|
dlog.Noticef("dnscrypt-proxy is ready - live servers: %d", liveServers)
|
||||||
|
@ -261,6 +265,24 @@ func (proxy *Proxy) tcpListenerFromAddr(listenAddr *net.TCPAddr) error {
|
||||||
return nil
|
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) {
|
func (proxy *Proxy) exchangeWithUDPServer(serverInfo *ServerInfo, encryptedQuery []byte, clientNonce []byte) ([]byte, error) {
|
||||||
pc, err := net.DialUDP("udp", nil, serverInfo.UDPAddr)
|
pc, err := net.DialUDP("udp", nil, serverInfo.UDPAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
17
systemd/dnscrypt-proxy.service
Normal file
17
systemd/dnscrypt-proxy.service
Normal 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
|
11
systemd/dnscrypt-proxy.socket
Normal file
11
systemd/dnscrypt-proxy.socket
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue