Skip to content

Commit

Permalink
DNS config
Browse files Browse the repository at this point in the history
  • Loading branch information
Place1 committed Jan 26, 2020
1 parent 248f8e5 commit 55ea349
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require (
github.com/gorilla/handlers v1.4.2 // indirect
github.com/gorilla/mux v1.7.3
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.8.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v1.2.1
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type AppConfig struct {
ExternalAddress string `yaml:"externalAddress`
// The WireGuard ListenPort
Port int `yaml:"port"`
// The DNS servers that VPN clients will be directed
// to use.
DNS []string `yaml:"dns"`
} `yaml:"wireguard"`
VPN struct {
// CIDR configures a network address space
Expand Down
5 changes: 3 additions & 2 deletions internal/services/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ type WireGuard struct {
iface string
externalAddress string
port int
dns []string
publicKey wgtypes.Key
lock sync.Mutex
}

func NewWireGuard(iface string, privateKey string, port int, externalAddress string) (*WireGuard, error) {
func NewWireGuard(iface string, privateKey string, port int, externalAddress string, dns []string) (*WireGuard, error) {
// wgctrl.New() will search for a kernel implementation
// of wireguard, then user implementations
// user implementations are found in /var/run/wireguard/<iface>.sock
Expand Down Expand Up @@ -142,7 +143,7 @@ func (s *WireGuard) Endpoint() string {
}

func (s *WireGuard) DNS() string {
return "1.1.1.1, 8.8.8.8" // TODO: dns stuff
return strings.Join(s.dns, ", ")
}

func (s *WireGuard) Device() (*wgtypes.Device, error) {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {
conf.WireGuard.PrivateKey,
conf.WireGuard.Port,
conf.WireGuard.ExternalAddress,
conf.WireGuard.DNS,
)
if err != nil {
logrus.Fatal(errors.Wrap(err, "failed to create wgserver"))
Expand Down

0 comments on commit 55ea349

Please sign in to comment.