X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcypherpunks.ru%2Fgovpn%2Fcmd%2Fgovpn-client%2Fmain.go;h=36ff72a113e6ac0db3e809e90af6954fb57f9f6c;hb=a11b0bda178937e6891770f40f800d69b5640313;hp=b46a16eb93203cb93a7002d372b24b64de050602;hpb=a87ec543051d428aaa3888804d6c8451f6d537c9;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/cmd/govpn-client/main.go b/src/cypherpunks.ru/govpn/cmd/govpn-client/main.go index b46a16e..36ff72a 100644 --- a/src/cypherpunks.ru/govpn/cmd/govpn-client/main.go +++ b/src/cypherpunks.ru/govpn/cmd/govpn-client/main.go @@ -21,6 +21,7 @@ package main import ( "flag" + "fmt" "log" "net" "os" @@ -33,7 +34,7 @@ import ( var ( remoteAddr = flag.String("remote", "", "Remote server address") proto = flag.String("proto", "udp", "Protocol to use: udp or tcp") - ifaceName = flag.String("iface", "tap0", "TAP network interface") + ifaceName = flag.String("iface", "tap0", "TUN/TAP network interface") verifierRaw = flag.String("verifier", "", "Verifier") keyPath = flag.String("key", "", "Path to passphrase file") upPath = flag.String("up", "", "Path to up-script") @@ -41,23 +42,36 @@ var ( stats = flag.String("stats", "", "Enable stats retrieving on host:port") proxyAddr = flag.String("proxy", "", "Use HTTP proxy on host:port") proxyAuth = flag.String("proxy-auth", "", "user:password Basic proxy auth") - mtu = flag.Int("mtu", govpn.MTUDefault, "MTU of TAP interface") + mtu = flag.Int("mtu", govpn.MTUDefault, "MTU of TUN/TAP interface") timeoutP = flag.Int("timeout", 60, "Timeout seconds") + timeSync = flag.Int("timesync", 0, "Time synchronization requirement") + noreconnect = flag.Bool("noreconnect", false, "Disable reconnection after timeout") noisy = flag.Bool("noise", false, "Enable noise appending") encless = flag.Bool("encless", false, "Encryptionless mode") cpr = flag.Int("cpr", 0, "Enable constant KiB/sec out traffic rate") egdPath = flag.String("egd", "", "Optional path to EGD socket") + syslog = flag.Bool("syslog", false, "Enable logging to syslog") + version = flag.Bool("version", false, "Print version information") + warranty = flag.Bool("warranty", false, "Print warranty information") conf *govpn.PeerConf tap *govpn.TAP timeout int firstUpCall bool = true knownPeers govpn.KnownPeers - idsCache *govpn.CipherCache + idsCache *govpn.MACCache ) func main() { flag.Parse() + if *warranty { + fmt.Println(govpn.Warranty) + return + } + if *version { + fmt.Println(govpn.VersionGet()) + return + } timeout = *timeoutP var err error log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile) @@ -70,6 +84,15 @@ func main() { govpn.EGDInit(*egdPath) } + if *proxyAddr != "" { + *proto = "tcp" + } + if !(*proto == "udp" || *proto == "tcp") { + log.Fatalln("Unknown protocol specified") + } + if *verifierRaw == "" { + log.Fatalln("No verifier specified") + } verifier, err := govpn.VerifierFromString(*verifierRaw) if err != nil { log.Fatalln(err) @@ -90,18 +113,21 @@ func main() { Iface: *ifaceName, MTU: *mtu, Timeout: time.Second * time.Duration(timeout), + TimeSync: *timeSync, Noise: *noisy, CPR: *cpr, Encless: *encless, Verifier: verifier, DSAPriv: priv, } - idsCache = govpn.NewCipherCache([]govpn.PeerId{*verifier.Id}) + idsCache = govpn.NewMACCache() + confs := map[govpn.PeerId]*govpn.PeerConf{*verifier.Id: conf} + idsCache.Update(&confs) log.Println(govpn.VersionGet()) tap, err = govpn.TAPListen(*ifaceName, *mtu) if err != nil { - log.Fatalln("Can not listen on TAP interface:", err) + log.Fatalln("Can not listen on TUN/TAP interface:", err) } if *stats != "" { @@ -113,6 +139,10 @@ func main() { go govpn.StatsProcessor(statsPort, &knownPeers) } + if *syslog { + govpn.SyslogEnable() + } + termSignal := make(chan os.Signal, 1) signal.Notify(termSignal, os.Interrupt, os.Kill) @@ -121,9 +151,6 @@ MainCycle: timeouted := make(chan struct{}) rehandshaking := make(chan struct{}) termination := make(chan struct{}) - if *proxyAddr != "" { - *proto = "tcp" - } switch *proto { case "udp": go startUDP(timeouted, rehandshaking, termination) @@ -133,21 +160,23 @@ MainCycle: } else { go startTCP(timeouted, rehandshaking, termination) } - default: - log.Fatalln("Unknown protocol specified") } select { case <-termSignal: - log.Fatalln("Finishing") + govpn.BothPrintf(`[finish remote="%s"]`, *remoteAddr) termination <- struct{}{} break MainCycle case <-timeouted: - break MainCycle + if *noreconnect { + break MainCycle + } + govpn.BothPrintf(`[sleep seconds="%d"]`, timeout) + time.Sleep(time.Second * time.Duration(timeout)) case <-rehandshaking: } close(timeouted) close(rehandshaking) close(termination) } - govpn.ScriptCall(*downPath, *ifaceName) + govpn.ScriptCall(*downPath, *ifaceName, *remoteAddr) }