From 777a76cac8cbe9a2f9d790df3c9bc01a248fa5bf Mon Sep 17 00:00:00 2001 From: Taras Nepyipyvo Date: Thu, 5 Nov 2020 19:18:33 +0200 Subject: [PATCH] Add line breakers to logs in VPN client. --- cmd/apps/vpn-client/vpn-client.go | 26 ++++++++++++------------- internal/vpn/client.go | 32 +++++++++++++++---------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cmd/apps/vpn-client/vpn-client.go b/cmd/apps/vpn-client/vpn-client.go index 5e4792978f..9f65d79e9c 100644 --- a/cmd/apps/vpn-client/vpn-client.go +++ b/cmd/apps/vpn-client/vpn-client.go @@ -56,14 +56,14 @@ func main() { serverPK := cipher.PubKey{} if err := serverPK.UnmarshalText([]byte(*serverPKStr)); err != nil { - fmt.Printf("Invalid VPN server pub key: %v", err) + fmt.Printf("Invalid VPN server pub key: %v\n", err) os.Exit(1) } localPK := cipher.PubKey{} if *localPKStr != "" { if err := localPK.UnmarshalText([]byte(*localPKStr)); err != nil { - fmt.Printf("Invalid local PK: %v", err) + fmt.Printf("Invalid local PK: %v\n", err) os.Exit(1) } } @@ -71,7 +71,7 @@ func main() { localSK := cipher.SecKey{} if *localSKStr != "" { if err := localSK.UnmarshalText([]byte(*localSKStr)); err != nil { - fmt.Printf("Invalid local SK: %v", err) + fmt.Printf("Invalid local SK: %v\n", err) os.Exit(1) } } @@ -85,11 +85,11 @@ func main() { parseIP := func(addr string) net.IP { ip, ok, err := vpn.ParseIP(addr) if err != nil { - fmt.Printf("Failed to parse IP %s: %v", addr, err) + fmt.Printf("Failed to parse IP %s: %v\n", addr, err) return nil } if !ok { - fmt.Printf("Failed to parse IP %s", addr) + fmt.Printf("Failed to parse IP %s\n", addr) return nil } @@ -111,7 +111,7 @@ func main() { appClient := app.NewClient(eventSub) defer appClient.Close() - fmt.Printf("Connecting to VPN server %s", serverPK.String()) + fmt.Printf("Connecting to VPN server %s\n", serverPK.String()) appConn, err := dialServer(appClient, serverPK) if err != nil { @@ -120,18 +120,18 @@ func main() { } defer func() { if err := appConn.Close(); err != nil { - fmt.Printf("Error closing connection to the VPN server: %v", err) + fmt.Printf("Error closing connection to the VPN server: %v\n", err) } }() - fmt.Printf("Dialed %s", appConn.RemoteAddr()) + fmt.Printf("Dialed %s\n", appConn.RemoteAddr()) vpnClientCfg := vpn.ClientConfig{ Passcode: *passcode, } vpnClient, err := vpn.NewClient(vpnClientCfg, log, appConn) if err != nil { - fmt.Printf("Error creating VPN client: %v", err) + fmt.Printf("Error creating VPN client: %v\n", err) } osSigs := make(chan os.Signal, 2) @@ -150,7 +150,7 @@ func main() { select { case ip := <-directIPsCh: if err := vpnClient.AddDirectRoute(ip); err != nil { - fmt.Printf("Failed to setup direct route to %s: %v", ip.String(), err) + fmt.Printf("Failed to setup direct route to %s: %v\n", ip.String(), err) } default: directRoutesDone = true @@ -160,7 +160,7 @@ func main() { go func() { for ip := range directIPsCh { if err := vpnClient.AddDirectRoute(ip); err != nil { - fmt.Printf("Failed to setup direct route to %s: %v", ip.String(), err) + fmt.Printf("Failed to setup direct route to %s: %v\n", ip.String(), err) } } }() @@ -168,13 +168,13 @@ func main() { go func() { for ip := range nonDirectIPsCh { if err := vpnClient.RemoveDirectRoute(ip); err != nil { - fmt.Printf("Failed to remove direct route to %s: %v", ip.String(), err) + fmt.Printf("Failed to remove direct route to %s: %v\n", ip.String(), err) } } }() if err := vpnClient.Serve(); err != nil { - fmt.Printf("Error serving VPN: %v", err) + fmt.Printf("Error serving VPN: %v\n", err) } } diff --git a/internal/vpn/client.go b/internal/vpn/client.go index db2abee4f4..15736047fb 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -84,7 +84,7 @@ func NewClient(cfg ClientConfig, l logrus.FieldLogger, conn net.Conn) (*Client, return nil, fmt.Errorf("error getting default network gateway: %w", err) } - fmt.Printf("Got default network gateway IP: %s", defaultGateway) + fmt.Printf("Got default network gateway IP: %s\n", defaultGateway) return &Client{ cfg: cfg, @@ -149,9 +149,9 @@ func (c *Client) Serve() error { return fmt.Errorf("error during client/server handshake: %w", err) } - fmt.Printf("Performed handshake with %s", c.conn.RemoteAddr()) - fmt.Printf("Local TUN IP: %s", tunIP.String()) - fmt.Printf("Local TUN gateway: %s", tunGateway.String()) + fmt.Printf("Performed handshake with %s\n", c.conn.RemoteAddr()) + fmt.Printf("Local TUN IP: %s\n", tunIP.String()) + fmt.Printf("Local TUN gateway: %s\n", tunGateway.String()) suid, err := setupClientSysPrivileges() if err != nil { @@ -166,13 +166,13 @@ func (c *Client) Serve() error { defer func() { tunName := tun.Name() if err := tun.Close(); err != nil { - fmt.Printf("Error closing TUN %s: %v", tunName, err) + fmt.Printf("Error closing TUN %s: %v\n", tunName, err) } c.releaseSysPrivileges(suid) }() - fmt.Printf("Allocated TUN %s: %v", tun.Name(), err) + fmt.Printf("Allocated TUN %s: %v\n", tun.Name(), err) if err := SetupTUN(tun.Name(), tunIP.String()+TUNNetmaskCIDR, tunGateway.String(), TUNMTU); err != nil { return fmt.Errorf("error setting up TUN %s: %w", tun.Name(), err) @@ -192,7 +192,7 @@ func (c *Client) Serve() error { } defer c.routeTrafficDirectly(tunGateway) - fmt.Printf("Routing all traffic through TUN %s: %v", tun.Name(), err) + fmt.Printf("Routing all traffic through TUN %s: %v\n", tun.Name(), err) if err := c.routeTrafficThroughTUN(tunGateway); err != nil { return fmt.Errorf("error routing traffic through TUN %s: %w", tun.Name(), err) } @@ -202,7 +202,7 @@ func (c *Client) Serve() error { // this will be executed first on return, so we setup privileges once again, // so other deferred clear up calls may be done successfully if _, err := setupClientSysPrivileges(); err != nil { - fmt.Printf("Failed to setup system privileges to clear up: %v", err) + fmt.Printf("Failed to setup system privileges to clear up: %v\n", err) } connToTunDoneCh := make(chan struct{}) @@ -212,14 +212,14 @@ func (c *Client) Serve() error { defer close(connToTunDoneCh) if _, err := io.Copy(tun, c.conn); err != nil { - fmt.Printf("Error resending traffic from TUN %s to VPN server: %v", tun.Name(), err) + fmt.Printf("Error resending traffic from TUN %s to VPN server: %v\n", tun.Name(), err) } }() go func() { defer close(tunToConnCh) if _, err := io.Copy(c.conn, tun); err != nil { - fmt.Printf("Error resending traffic from VPN server to TUN %s: %v", tun.Name(), err) + fmt.Printf("Error resending traffic from VPN server to TUN %s: %v\n", tun.Name(), err) } }() @@ -257,10 +257,10 @@ func (c *Client) routeTrafficDirectly(tunGateway net.IP) { // remove main route if err := DeleteRoute(ipv4FirstHalfAddr, tunGateway.String()); err != nil { - fmt.Printf("Error routing traffic through default network gateway: %v", err) + fmt.Printf("Error routing traffic through default network gateway: %v\n", err) } if err := DeleteRoute(ipv4SecondHalfAddr, tunGateway.String()); err != nil { - fmt.Printf("Error routing traffic through default network gateway: %v", err) + fmt.Printf("Error routing traffic through default network gateway: %v\n", err) } } @@ -290,7 +290,7 @@ func (c *Client) setupDirectRoute(ip net.IP) error { func (c *Client) removeDirectRoute(ip net.IP) error { if !ip.IsLoopback() { - fmt.Printf("Removing direct route to %s", ip.String()) + fmt.Printf("Removing direct route to %s\n", ip.String()) if err := DeleteRoute(ip.String()+directRouteNetmaskCIDR, c.defaultGateway.String()); err != nil { return err } @@ -306,7 +306,7 @@ func (c *Client) removeDirectRoutes() { for _, ip := range c.directIPs { if err := c.removeDirectRoute(ip); err != nil { // shouldn't return, just keep on trying the other IPs - fmt.Printf("Error removing direct route to %s: %v", ip.String(), err) + fmt.Printf("Error removing direct route to %s: %v\n", ip.String(), err) } } } @@ -423,7 +423,7 @@ func (c *Client) shakeHands() (TUNIP, TUNGateway net.IP, err error) { Passcode: c.cfg.Passcode, } - fmt.Printf("Sending client hello: %v", cHello) + fmt.Printf("Sending client hello: %v\n", cHello) if err := WriteJSON(c.conn, &cHello); err != nil { return nil, nil, fmt.Errorf("error sending client hello: %w", err) @@ -445,7 +445,7 @@ func (c *Client) shakeHands() (TUNIP, TUNGateway net.IP, err error) { func (c *Client) releaseSysPrivileges(suid int) { if err := releaseClientSysPrivileges(suid); err != nil { - fmt.Printf("Failed to release system privileges: %v", err) + fmt.Printf("Failed to release system privileges: %v\n", err) } }