add an option to specifiy a config value that applies DNS back to the TUN

This commit is contained in:
dovholuknf
2021-04-11 11:44:34 -04:00
parent 4ef60a3428
commit 533ec9178d
5 changed files with 16 additions and 5 deletions
+1 -2
View File
@@ -296,7 +296,7 @@ func serviceCB(ziti_ctx C.ziti_context, service *C.ziti_service, status C.int, z
addresses = append(a)
} else {
strZitiTunnelerClientV1 := C.GoString(C.ziti_service_get_raw_config(service, cCfgZitiTunnelerClientV1))
log.Warnf("ziti-tunneler-client.v1: %s", strZitiTunnelerClientV1)
log.Tracef("ziti-tunneler-client.v1: %s", strZitiTunnelerClientV1)
var obj v1ClientCfg
uerr := json.Unmarshal([]byte(strZitiTunnelerClientV1), &obj)
if uerr != nil {
@@ -554,7 +554,6 @@ func eventCB(ztx C.ziti_context, event *C.ziti_event_t) {
}
func zitiContextEvent(ztx C.ziti_context, status C.int, zid *ZIdentity) {
zid.status = int(status)
zid.statusErr = zitiError(status)
zid.czctx = ztx
+1 -1
View File
@@ -18,9 +18,9 @@ package cli
*/
import (
"fmt"
"bufio"
"encoding/json"
"fmt"
"io"
"net"
"strings"
+1
View File
@@ -119,6 +119,7 @@ type TunnelStatus struct {
TunIpv4 string
TunIpv4Mask int
Status string
AddDns bool
}
type ServiceVersion struct {
+6 -1
View File
@@ -282,7 +282,7 @@ func initialize(cLogLevel int) error {
dnsIpAsUint32 := binary.BigEndian.Uint32(ipnet.IP)
cziti.InitTunnelerDns(dnsIpAsUint32, len(ipnet.Mask))
assignedIp, t, err := rts.CreateTun(rts.state.TunIpv4, rts.state.TunIpv4Mask)
assignedIp, t, err := rts.CreateTun(rts.state.TunIpv4, rts.state.TunIpv4Mask, rts.state.AddDns)
if err != nil {
return err
}
@@ -714,6 +714,7 @@ loop:
ferr := w.Flush()
if ferr != nil {
log.Warnf("flush error: %v", ferr)
return
}
log.Tracef("sent event to id: %s [%v]", id, msg)
case <-interrupt:
@@ -723,6 +724,10 @@ loop:
log.Info("a connected event client has disconnected")
}
func writerFlush(writer bufio.Writer) {
writer.Flush()
}
func reportStatus(out *json.Encoder) {
s := rts.ToStatus(true)
respond(out, dto.ZitiTunnelStatus{
+7 -1
View File
@@ -21,6 +21,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"golang.org/x/sys/windows"
"io"
"io/ioutil"
"net"
@@ -162,7 +163,7 @@ func (t *RuntimeState) ToMetrics() dto.TunnelStatus {
return clean
}
func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) (net.IP, *tun.Device, error) {
func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int, applyDns bool) (net.IP, *tun.Device, error) {
log.Infof("creating TUN device: %s", TunName)
tunDevice, err := tun.CreateTUN(TunName, 64*1024-1)
if err == nil {
@@ -219,6 +220,11 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) (net.IP, *tun.Device
}
log.Info("routing applied")
if applyDns {
//for windows 10+ this might be able to replace NRPT?
luid.SetDNS(windows.AF_INET, []net.IP{ip}, nil)
}
return ip, t.tun, nil
}