remove code no longer needed. log the version when running as a service

This commit is contained in:
dovholuknf
2020-10-01 08:18:57 -04:00
parent dde53bac9f
commit 7c6fa18d9c
3 changed files with 5 additions and 157 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ func main() {
if err != nil {
return
}
log.Info("running as service")
log.Info("running as service. version: %s", version())
service.RunService(false)
log.Info("service has completed")
return
+4 -2
View File
@@ -162,15 +162,17 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int) error {
net.ParseIP(Ipv4dns).To4(),
net.ParseIP(Ipv6dns),
}
log.Infof("adding DNS servers to TUN: %s", dnsServers)
err = luid.AddDNS(dnsServers)
if err != nil {
return fmt.Errorf("failed to add DNS address: (%v)", err)
return fmt.Errorf("failed to add DNS addresses: (%v)", err)
}
log.Infof("checking dns servers")
dns, err := luid.DNS()
if err != nil {
return fmt.Errorf("failed to fetch DNS address: (%v)", err)
}
log.Debugf("dns servers set to = %s", dns)
log.Infof("dns servers set to: %s", dns)
log.Infof("routing destination [%s] through [%s]", *ipnet, ipnet.IP)
err = luid.SetRoutes([]*winipcfg.RouteData{{*ipnet, ipnet.IP, 0}})
-154
View File
@@ -1,154 +0,0 @@
/*
* Copyright NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package main
import (
"fmt"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/tun"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"net"
"os"
"os/signal"
user2 "os/user"
"path/filepath"
"syscall"
"github.com/openziti/desktop-edge-win/service/cziti"
"github.com/openziti/desktop-edge-win/service/cziti/windns"
)
const bufferSize = 64 * 1024
// TUN IPs
const ipv4ip = "169.254.1.1"
const ipv4mask = 24
const ipv4dns = "127.0.0.1" // use lo -- don't pass DNS queries through tunneler SDK
// IPv6 CIDR fe80:6e66:7a69:7469::/64
// <link-local>: nf : zi : ti ::
const ipv6pfx = "fe80:6e66:7a69:7469"
const ipv6ip = "1"
const ipv6mask = 64
const ipv6dns = "::1" // must be in "ipv6ip/ipv6mask" CIDR block
func main() {
user, err := user2.Current()
fmt.Printf("user [%v]\n", user)
if len(os.Args) < 3 {
fmt.Printf("usage: %s <interfaceName> <config file path>\n", filepath.Base(os.Args[0]))
os.Exit(1)
}
interfaceName := os.Args[1]
fmt.Println("creating TUN device")
tunDevice, err := tun.CreateTUN(interfaceName, 64*1024)
if err == nil {
realInterfaceName, err2 := tunDevice.Name()
if err2 == nil {
interfaceName = realInterfaceName
}
} else {
fmt.Printf("error creating TUN device: (%v)\n", err)
os.Exit(1)
}
if name, err := tunDevice.Name(); err == nil {
fmt.Printf("created TUN device [%s]\n", name)
}
nativeTunDevice := tunDevice.(*tun.NativeTun)
luid := winipcfg.LUID(nativeTunDevice.LUID())
ip, ipnet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", ipv4ip, ipv4mask))
if err != nil {
fatal(err)
}
fmt.Printf("setting TUN interface address to [%s]\n", ip)
err = luid.SetIPAddresses([]net.IPNet{{ip, ipnet.Mask}})
if err != nil {
fatal(err)
}
dnsServers := []net.IP{
net.ParseIP(ipv4dns).To4(),
net.ParseIP(ipv6dns),
}
err = luid.AddDNS(dnsServers)
if err != nil {
fatal(err)
}
dns, err := luid.DNS()
if err != nil {
fatal(err)
}
fmt.Println("dns servers = ", dns)
fmt.Printf("routing destination [%s] through [%s]\n", *ipnet, ipnet.IP)
err = luid.SetRoutes([]*winipcfg.RouteData{{*ipnet, ipnet.IP, 0}})
if err != nil {
fatal(err)
}
fmt.Println("routing applied")
errs := make(chan error)
term := make(chan os.Signal, 1)
fmt.Println("running")
cziti.DnsInit(ipv4ip, 24)
logFile, err := os.OpenFile("cziti.log", os.O_RDWR | os.O_CREATE, 0644)
if err != nil {
panic(err)
}
cziti.SetLog(logFile)
cziti.SetLogLevel(4)
cziti.Start()
_, err = cziti.HookupTun(tunDevice, dns)
if err != nil {
panic(err)
}
ctx := cziti.LoadZiti(os.Args[2])
if rc, err := ctx.Status(); err != nil {
fmt.Printf("failed to start %s@%s: %v\n", ctx.Name(), ctx.Controller(), err)
os.Exit(rc)
} else {
fmt.Printf("successfully loaded %s@%s\n", ctx.Name(), ctx.Controller())
}
signal.Notify(term, os.Interrupt)
signal.Notify(term, os.Kill)
signal.Notify(term, syscall.SIGTERM)
select {
case sig := <-term:
fmt.Println("received signal: %v", sig)
case <-errs:
}
windns.ResetDNS()
fmt.Println("shutting down")
}
func fatal(v ...interface{}) {
panic(windows.StringToUTF16Ptr(fmt.Sprint(v...)))
}