mirror of
https://github.com/openziti/desktop-edge-win.git
synced 2026-10-13 16:21:25 +00:00
refactor globals -> constants/logging
change ip and mask to 100.64.0.0/10
This commit is contained in:
@@ -21,6 +21,8 @@ import "C"
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/constants"
|
||||
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -35,9 +37,6 @@ type DnsManager interface {
|
||||
GetService(ip net.IP, port uint16) (*CZitiCtx, string, error)
|
||||
}
|
||||
|
||||
const defaultCidr = "169.254.0.0"
|
||||
const defaultMaskBits = 16
|
||||
|
||||
var initOnce = sync.Once{}
|
||||
var DNS = &dnsImpl{}
|
||||
|
||||
@@ -80,7 +79,7 @@ func normalizeDnsName(dnsName string) string {
|
||||
// assigned to a hostname an error will also be returned indicating why.
|
||||
func (dns *dnsImpl) RegisterService(svcId string, dnsNameToReg string, port uint16, ctx *CZitiCtx, svcName string) (net.IP, error) {
|
||||
log.Infof("adding DNS entry for service name %s@%s:%d", svcName, dnsNameToReg, port)
|
||||
DnsInit(defaultCidr, defaultMaskBits)
|
||||
DnsInit(constants.Ipv4ip, constants.Ipv4DefaultMask)
|
||||
dnsName := normalizeDnsName(dnsNameToReg)
|
||||
key := fmt.Sprint(dnsName, ':', port)
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package constants
|
||||
|
||||
const(
|
||||
Ipv4ip = "100.64.0.0"
|
||||
Ipv4MaxMask = 10
|
||||
Ipv4DefaultMask = 24
|
||||
)
|
||||
@@ -21,17 +21,17 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/util/logging"
|
||||
"golang.org/x/sys/windows/svc/debug"
|
||||
"golang.org/x/sys/windows/svc/eventlog"
|
||||
"os"
|
||||
"strings"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/globals"
|
||||
|
||||
"golang.org/x/sys/windows/svc"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/service"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
)
|
||||
|
||||
var log = globals.Logger()
|
||||
var log = logging.Logger()
|
||||
|
||||
func main() {
|
||||
service.Version = dto.ServiceVersion{
|
||||
@@ -39,7 +39,7 @@ func main() {
|
||||
Revision: Revision,
|
||||
BuildDate: BuildDate,
|
||||
}
|
||||
globals.InitLogger("info")
|
||||
logging.InitLogger("info")
|
||||
|
||||
//if len(os.Args) < 2 {
|
||||
// // if no args supplied - expect to run as service
|
||||
@@ -57,9 +57,9 @@ func main() {
|
||||
|
||||
var err error
|
||||
if hasArgs {
|
||||
globals.Elog = debug.New(service.SvcName)
|
||||
logging.Elog = debug.New(service.SvcName)
|
||||
} else {
|
||||
globals.Elog, err = eventlog.Open(service.SvcName)
|
||||
logging.Elog, err = eventlog.Open(service.SvcName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -74,9 +74,9 @@ func main() {
|
||||
usage("no command specified")
|
||||
}
|
||||
|
||||
defer globals.Elog.Close()
|
||||
defer logging.Elog.Close()
|
||||
|
||||
elog := globals.Elog
|
||||
elog := logging.Elog
|
||||
|
||||
cmd := strings.ToLower(os.Args[1])
|
||||
switch cmd {
|
||||
|
||||
@@ -23,14 +23,16 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Microsoft/go-winio"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/constants"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/util/idutil"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/util/logging"
|
||||
"github.com/openziti/foundation/identity/identity"
|
||||
idcfg "github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/openziti/sdk-golang/ziti/enroll"
|
||||
"github.com/openziti/desktop-edge-win/service/cziti"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/config"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/globals"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/idutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
"io"
|
||||
@@ -63,11 +65,11 @@ func SubMain(ops chan string, changes chan<- svc.Status) error {
|
||||
|
||||
rts.LoadConfig()
|
||||
l := rts.state.LogLevel
|
||||
_, czitiLevel := globals.ParseLevel(l)
|
||||
_, czitiLevel := logging.ParseLevel(l)
|
||||
|
||||
globals.InitLogger(l)
|
||||
logging.InitLogger(l )
|
||||
|
||||
_ = globals.Elog.Info(InformationEvent, SvcName+" starting. log file located at "+config.LogFile())
|
||||
_ = logging.Elog.Info(InformationEvent, SvcName+" starting. log file located at "+config.LogFile())
|
||||
|
||||
// create a channel for notifying any connections that they are to be interrupted
|
||||
interrupt = make(chan struct{}, 8)
|
||||
@@ -100,7 +102,7 @@ func SubMain(ops chan string, changes chan<- svc.Status) error {
|
||||
|
||||
// notify the service is running
|
||||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||
_ = globals.Elog.Info(InformationEvent, SvcName+" status set to running")
|
||||
_ = logging.Elog.Info(InformationEvent, SvcName+" status set to running")
|
||||
log.Info(SvcName + " status set to running. starting cancel loop")
|
||||
|
||||
waitForStopRequest(ops)
|
||||
@@ -245,12 +247,12 @@ func initialize(ipv4 string, ipv4mask int) error {
|
||||
func setTunInfo(s *dto.TunnelStatus, ipv4 string, ipv4mask int) {
|
||||
if strings.TrimSpace(ipv4) == "" {
|
||||
log.Infof("ip not provided using default: %v", ipv4)
|
||||
ipv4 = Ipv4ip
|
||||
ipv4 = constants.Ipv4ip
|
||||
rts.UpdateIpv4(ipv4)
|
||||
}
|
||||
if ipv4mask < 8 || ipv4mask > 24 {
|
||||
log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask)
|
||||
ipv4mask = Ipv4mask
|
||||
if ipv4mask < 8 || ipv4mask > constants.Ipv4MaxMask {
|
||||
log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, constants.Ipv4DefaultMask)
|
||||
ipv4mask = constants.Ipv4DefaultMask
|
||||
rts.UpdateIpv4Mask(ipv4mask)
|
||||
}
|
||||
_, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4, ipv4mask))
|
||||
@@ -295,7 +297,7 @@ func accept(p net.Listener, serveFunction func(net.Conn), debug string) {
|
||||
c, err := p.Accept()
|
||||
if err != nil {
|
||||
if err != winio.ErrPipeListenerClosed {
|
||||
log.Errorf("unexpected error while accepting a connection. exiting loop. %v", err)
|
||||
log.Errorf("%v unexpected error while accepting a connection. exiting loop. %v", debug, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -332,7 +334,7 @@ func serveIpc(conn net.Conn) {
|
||||
select {
|
||||
case <-interrupt:
|
||||
log.Info("request to interrupt read loop received")
|
||||
conn.Close()
|
||||
_ = conn.Close()
|
||||
log.Info("read loop interrupted")
|
||||
case <-done:
|
||||
log.Debug("loop finished normally")
|
||||
@@ -430,8 +432,10 @@ func serveIpc(conn net.Conn) {
|
||||
}
|
||||
|
||||
func setLogLevel(out *json.Encoder, level string) {
|
||||
goLevel, cLevel := globals.ParseLevel(level)
|
||||
globals.SetLogLevel(goLevel, cLevel)
|
||||
goLevel, cLevel := logging.ParseLevel(level)
|
||||
logrus.Infof("Setting logger levels to %s", goLevel)
|
||||
logrus.SetLevel(goLevel)
|
||||
cziti.SetLogLevel(cLevel)
|
||||
rts.state.LogLevel = goLevel.String()
|
||||
respond(out, dto.Response{Message: "log level set", Code: SUCCESS, Error: "", Payload: nil})
|
||||
}
|
||||
@@ -600,7 +604,7 @@ func toggleIdentity(out *json.Encoder, fingerprint string, onOff bool) {
|
||||
if onOff {
|
||||
connectIdentity(id)
|
||||
} else {
|
||||
disconnectIdentity(id)
|
||||
_ = disconnectIdentity(id)
|
||||
}
|
||||
|
||||
respond(out, dto.Response{Message: "identity toggled", Code: SUCCESS, Error: "", Payload: idutil.Clean(*id)})
|
||||
@@ -846,7 +850,7 @@ func acceptServices() {
|
||||
switch c.Operation {
|
||||
case cziti.ADDED:
|
||||
//add the service to the identity
|
||||
svc := dto.Service{
|
||||
s := dto.Service{
|
||||
Name: c.Service.Name,
|
||||
InterceptHost: c.Service.InterceptHost,
|
||||
InterceptPort: c.Service.InterceptPort,
|
||||
@@ -854,22 +858,22 @@ func acceptServices() {
|
||||
AssignedIP: c.Service.AssignedIP,
|
||||
OwnsIntercept: c.Service.OwnsIntercept,
|
||||
}
|
||||
id.Services = append(id.Services, &svc)
|
||||
id.Services = append(id.Services, &s)
|
||||
|
||||
events.broadcast <- dto.ServiceEvent{
|
||||
ActionEvent: SERVICE_ADDED,
|
||||
Fingerprint: id.FingerPrint,
|
||||
Service: svc,
|
||||
Service: s,
|
||||
}
|
||||
log.Debug("dispatched added service change event")
|
||||
case cziti.REMOVED:
|
||||
for idx, svc := range id.Services {
|
||||
if svc.Name == c.Service.Name {
|
||||
for idx, s := range id.Services {
|
||||
if s.Name == c.Service.Name {
|
||||
id.Services = append(id.Services[:idx], id.Services[idx+1:]...)
|
||||
events.broadcast <- dto.ServiceEvent{
|
||||
ActionEvent: SERVICE_REMOVED,
|
||||
Fingerprint: id.FingerPrint,
|
||||
Service: *svc,
|
||||
Service: *s,
|
||||
}
|
||||
log.Debug(" dispatched remove service change event")
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/util/logging"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
"sync"
|
||||
"time"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/globals"
|
||||
)
|
||||
var Version dto.ServiceVersion
|
||||
var pipeBase = `\\.\pipe\NetFoundry\tunneler\`
|
||||
@@ -39,7 +39,7 @@ var eventsConnections int
|
||||
var Debug bool
|
||||
|
||||
var TunStarted time.Time
|
||||
var log = globals.Logger()
|
||||
var log = logging.Logger()
|
||||
|
||||
var events = newTopic()
|
||||
|
||||
@@ -87,8 +87,6 @@ const (
|
||||
NF_GROUP_NAME = "NetFoundry Tunneler Users"
|
||||
TunName = "ZitiTUN"
|
||||
|
||||
Ipv4ip = "169.254.1.1"
|
||||
Ipv4mask = 24
|
||||
Ipv4dns = "127.0.0.1" // use lo -- don't pass DNS queries through tunneler SDK
|
||||
|
||||
// IPv6 CIDR fe80:6e66:7a69:7469::/64
|
||||
|
||||
@@ -21,9 +21,9 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/util/logging"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
"golang.org/x/sys/windows/svc/debug"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/globals"
|
||||
)
|
||||
|
||||
type zitiService struct{}
|
||||
@@ -51,26 +51,26 @@ loop:
|
||||
switch c.Cmd {
|
||||
case svc.Interrogate:
|
||||
changes <- c.CurrentStatus
|
||||
_ = globals.Elog.Info(InterrogateEvent, "interrogate request received")
|
||||
_ = logging.Elog.Info(InterrogateEvent, "interrogate request received")
|
||||
changes <- c.CurrentStatus
|
||||
case svc.Stop:
|
||||
_ = globals.Elog.Info(StopEvent, "issuing stop")
|
||||
_ = logging.Elog.Info(StopEvent, "issuing stop")
|
||||
control <- "stop"
|
||||
_ = globals.Elog.Info(StopEvent, "stop issued")
|
||||
_ = logging.Elog.Info(StopEvent, "stop issued")
|
||||
break loop
|
||||
case svc.Shutdown:
|
||||
_ = globals.Elog.Info(ShutdownEvent, "issuing shutdown")
|
||||
_ = logging.Elog.Info(ShutdownEvent, "issuing shutdown")
|
||||
control <- "stop"
|
||||
_ = globals.Elog.Info(ShutdownEvent, "shutdown issued")
|
||||
_ = logging.Elog.Info(ShutdownEvent, "shutdown issued")
|
||||
break loop
|
||||
case svc.Pause:
|
||||
changes <- svc.Status{State: svc.Paused, Accepts: cmdsAccepted}
|
||||
_ = globals.Elog.Info(PauseEvent, "request to pause service received. todo - unimplemented")
|
||||
_ = logging.Elog.Info(PauseEvent, "request to pause service received. todo - unimplemented")
|
||||
case svc.Continue:
|
||||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||
_ = globals.Elog.Info(ContinueEvent, "request to continue service received. todo - unimplemented")
|
||||
_ = logging.Elog.Info(ContinueEvent, "request to continue service received. todo - unimplemented")
|
||||
default:
|
||||
_ = globals.Elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
|
||||
_ = logging.Elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ loop:
|
||||
}
|
||||
|
||||
func RunService(isDebug bool) {
|
||||
_ = globals.Elog.Info(InformationEvent, fmt.Sprintf("starting %s service", SvcStartName))
|
||||
_ = logging.Elog.Info(InformationEvent, fmt.Sprintf("starting %s service", SvcStartName))
|
||||
run := svc.Run
|
||||
if isDebug {
|
||||
log.Info("debug specified. using debug.run")
|
||||
@@ -94,8 +94,8 @@ func RunService(isDebug bool) {
|
||||
err := run(SvcStartName, &zitiService{})
|
||||
|
||||
if err != nil {
|
||||
_ = globals.Elog.Error(ErrorEvent, fmt.Sprintf("%s service failed: %v", SvcStartName, err))
|
||||
_ = logging.Elog.Error(ErrorEvent, fmt.Sprintf("%s service failed: %v", SvcStartName, err))
|
||||
return
|
||||
}
|
||||
_ = globals.Elog.Info(StopEvent, fmt.Sprintf("%s service stopped", SvcStartName))
|
||||
_ = logging.Elog.Info(StopEvent, fmt.Sprintf("%s service stopped", SvcStartName))
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ import (
|
||||
"fmt"
|
||||
"github.com/openziti/desktop-edge-win/service/cziti"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/config"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/constants"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/idutil"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/util/idutil"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
|
||||
@@ -147,11 +148,11 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) error {
|
||||
|
||||
if strings.TrimSpace(ipv4) == "" {
|
||||
log.Infof("ip not provided using default: %v", ipv4)
|
||||
ipv4 = Ipv4ip
|
||||
ipv4 = constants.Ipv4ip
|
||||
}
|
||||
if ipv4mask < 8 || ipv4mask > 24 {
|
||||
log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask)
|
||||
ipv4mask = Ipv4mask
|
||||
if ipv4mask < 8 || ipv4mask > constants.Ipv4MaxMask {
|
||||
log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, constants.Ipv4DefaultMask)
|
||||
ipv4mask = constants.Ipv4DefaultMask
|
||||
rts.UpdateIpv4Mask(ipv4mask)
|
||||
}
|
||||
ip, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4, ipv4mask))
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ipchanges
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package globals
|
||||
package logging
|
||||
|
||||
import (
|
||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||
Reference in New Issue
Block a user