From 6434a4e46f3c8a60704dfed412aff5c99c9a9324 Mon Sep 17 00:00:00 2001 From: ziti-ci Date: Fri, 10 Jul 2020 14:21:19 -0400 Subject: [PATCH] * moved handleEvents() * remove duplicate call to setTunnelState * when ipv4 ip or mask is not provided - set some defaults into the config --- service/ziti-tunnel/service/ipc.go | 19 ++++++++----------- service/ziti-tunnel/service/state.go | 10 ++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index cdef8683..db0d906e 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -74,6 +74,9 @@ func SubMain(ops chan string, changes chan<- svc.Status) error { // wire in a log file for csdk troubleshooting cziti.InitializeCLogger(czitiLevel) + // setup events handler - needs to be before initialization + go handleEvents() + // initialize the network interface err := initialize(rts.state.TunIpv4, rts.state.TunIpv4Mask) @@ -84,9 +87,6 @@ func SubMain(ops chan string, changes chan<- svc.Status) error { setTunnelState(true) - // setup events handler - go handleEvents() - //listen for services that show up go acceptServices() @@ -227,12 +227,8 @@ func initialize(ipv4 string, ipv4mask int) error { } setTunInfo(rts.state, ipv4, ipv4mask) - s := rts.state - // decide if the tunnel should be active or not and if so - activate it - setTunnelState(s.Active) - // connect any identities that are enabled - for _, id := range s.Identities { + for _, id := range rts.state.Identities { connectIdentity(id) } @@ -244,10 +240,12 @@ func setTunInfo(s *dto.TunnelStatus, ipv4 string, ipv4mask int) { if strings.TrimSpace(ipv4) == "" { log.Infof("ip not provided using default: %v", ipv4) ipv4 = Ipv4ip + rts.UpdateIpv4(ipv4) } if ipv4mask < 8 || ipv4mask > 24 { log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask) ipv4mask = Ipv4mask + rts.UpdateIpv4Mask(ipv4mask) } _, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4, ipv4mask)) if err != nil { @@ -550,8 +548,7 @@ func setTunnelState(onOff bool) { if onOff { TunStarted = time.Now() - state := rts.state - for _, id := range state.Identities { + for _, id := range rts.state.Identities { connectIdentity(id) } } else { @@ -698,9 +695,9 @@ func respondWithError(out *json.Encoder, msg string, code int, err error) { } func connectIdentity(id *dto.Identity) { - log.Infof("connecting identity: %s", id.Name) if !id.Connected { + log.Infof("connecting identity: %s", id.Name) //tell the c sdk to use the file from the id and connect rts.LoadIdentity(id) activeIds[id.FingerPrint] = id diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index 33283c44..4e86942c 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -145,6 +145,7 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) error { if ipv4mask < 8 || ipv4mask > 24 { log.Warnf("provided mask is invalid: %d. using default value: %d", ipv4mask, Ipv4mask) ipv4mask = Ipv4mask + rts.UpdateIpv4Mask(ipv4mask) } ip, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4, ipv4mask)) if err != nil { @@ -258,4 +259,13 @@ func (t *RuntimeState) LoadConfig() { if err != nil { log.Errorf("could not close configuration file. this is not normal! %v", err) } +} + +func (t *RuntimeState) UpdateIpv4Mask(ipv4mask int){ + rts.state.TunIpv4Mask = ipv4mask + rts.SaveState() +} +func (t *RuntimeState) UpdateIpv4(ipv4 string){ + rts.state.TunIpv4 = ipv4 + rts.SaveState() } \ No newline at end of file