From a9e27312416473e781b264b594aa83dbe690fbc6 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 13 Jul 2022 15:37:22 +0530 Subject: [PATCH 1/7] Fix spelling --- internal/vpn/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/vpn/server.go b/internal/vpn/server.go index f0d7de6f2..9d2163067 100644 --- a/internal/vpn/server.go +++ b/internal/vpn/server.go @@ -74,18 +74,18 @@ func NewServer(cfg ServerConfig, appCl *app.Client) (*Server, error) { fmt.Println("Old IP forwarding values:") fmt.Printf("IPv4: %s, IPv6: %s\n", ipv4ForwardingVal, ipv6ForwardingVal) - iptablesForwarPolicy, err := GetIPTablesForwardPolicy() + iptablesForwardPolicy, err := GetIPTablesForwardPolicy() if err != nil { return nil, fmt.Errorf("error getting iptables forward policy: %w", err) } - fmt.Printf("Old iptables forward policy: %s\n", iptablesForwarPolicy) + fmt.Printf("Old iptables forward policy: %s\n", iptablesForwardPolicy) s.defaultNetworkInterface = defaultNetworkIfc s.defaultNetworkInterfaceIPs = defaultNetworkIfcIPs s.ipv4ForwardingVal = ipv4ForwardingVal s.ipv6ForwardingVal = ipv6ForwardingVal - s.iptablesForwardPolicy = iptablesForwarPolicy + s.iptablesForwardPolicy = iptablesForwardPolicy return s, nil } From 00a57caaa5be3981c2ecebe725e2df98823e7d14 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 13 Jul 2022 15:37:58 +0530 Subject: [PATCH 2/7] Fix spellings --- internal/vpn/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/vpn/server.go b/internal/vpn/server.go index 9d2163067..336d99cb3 100644 --- a/internal/vpn/server.go +++ b/internal/vpn/server.go @@ -41,7 +41,7 @@ func NewServer(cfg ServerConfig, appCl *app.Client) (*Server, error) { if err != nil { return nil, fmt.Errorf("error getting default network interface: %w", err) } - ifcs, hasMultiple := s.hasMutipleNetworkInterfaces(defaultNetworkIfcs) + ifcs, hasMultiple := s.hasMultipleNetworkInterfaces(defaultNetworkIfcs) if hasMultiple { if cfg.NetworkInterface == "" { return nil, fmt.Errorf("multiple default network interfaces detected...set a default one for VPN server or remove one: %v", ifcs) @@ -335,7 +335,7 @@ func (s *Server) shakeHands(conn net.Conn) (tunIP, tunGateway net.IP, unsecureVP if err := WriteJSON(conn, &sHello); err != nil { unsecureVPN() - return nil, nil, nil, fmt.Errorf("error finishing hadnshake: error sending server hello: %w", err) + return nil, nil, nil, fmt.Errorf("error finishing handshake: error sending server hello: %w", err) } return sTUNIP, sTUNGateway, unsecureVPN, nil @@ -363,7 +363,7 @@ func (s *Server) sendServerErrHello(conn net.Conn, status HandshakeStatus) { } } -func (s *Server) hasMutipleNetworkInterfaces(defaultNetworkInterface string) ([]string, bool) { +func (s *Server) hasMultipleNetworkInterfaces(defaultNetworkInterface string) ([]string, bool) { networkInterfaces := strings.Split(defaultNetworkInterface, "\n") if len(networkInterfaces) > 1 { return networkInterfaces, true From 698bef7cedeede8be8df497c2d6f767e81636f2d Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 27 Jul 2022 17:01:59 +0530 Subject: [PATCH 3/7] Fix spelling --- internal/vpn/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/vpn/client.go b/internal/vpn/client.go index f18f53514..243a602aa 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -710,7 +710,7 @@ func (c *Client) dialServer(appCl *app.Client, pk cipher.PubKey) (net.Conn, erro } if c.isClosed() { - // we need to signal outer code that connection object is inalid + // we need to signal outer code that connection object is invalid // in this case return nil, errors.New("client got closed") } From 31e06f088a39664e50a96bcf35cf28f6d477cf05 Mon Sep 17 00:00:00 2001 From: ersonp Date: Thu, 28 Jul 2022 10:27:36 +0530 Subject: [PATCH 4/7] Dirty fix --- internal/vpn/server.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/vpn/server.go b/internal/vpn/server.go index 336d99cb3..2ad5a3ede 100644 --- a/internal/vpn/server.go +++ b/internal/vpn/server.go @@ -245,14 +245,20 @@ func (s *Server) serveConn(conn net.Conn) { defer close(connToTunDoneCh) if _, err := io.Copy(tun, conn); err != nil { - print(fmt.Sprintf("Error resending traffic from VPN client to TUN %s: %v\n", tun.Name(), err)) + // when the vpn-client is closed we get the error EOF + if err.Error() != io.EOF.Error() { + print(fmt.Sprintf("Error resending traffic from VPN client to TUN %s: %v\n", tun.Name(), err)) + } } }() go func() { defer close(tunToConnCh) if _, err := io.Copy(conn, tun); err != nil { - print(fmt.Sprintf("Error resending traffic from TUN %s to VPN client: %v\n", tun.Name(), err)) + // when the vpn-client is closed we get the error EOF + if err.Error() != io.EOF.Error() { + print(fmt.Sprintf("Error resending traffic from TUN %s to VPN client: %v\n", tun.Name(), err)) + } } }() From 4471c8529a98054938ffca90decc1674b3c8f124 Mon Sep 17 00:00:00 2001 From: ersonp Date: Thu, 28 Jul 2022 10:49:40 +0530 Subject: [PATCH 5/7] Fix tun error --- internal/vpn/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/vpn/server.go b/internal/vpn/server.go index 2ad5a3ede..d2047a9ee 100644 --- a/internal/vpn/server.go +++ b/internal/vpn/server.go @@ -245,7 +245,7 @@ func (s *Server) serveConn(conn net.Conn) { defer close(connToTunDoneCh) if _, err := io.Copy(tun, conn); err != nil { - // when the vpn-client is closed we get the error EOF + // when the vpn-client is closed we get the error "EOF" if err.Error() != io.EOF.Error() { print(fmt.Sprintf("Error resending traffic from VPN client to TUN %s: %v\n", tun.Name(), err)) } @@ -255,8 +255,8 @@ func (s *Server) serveConn(conn net.Conn) { defer close(tunToConnCh) if _, err := io.Copy(conn, tun); err != nil { - // when the vpn-client is closed we get the error EOF - if err.Error() != io.EOF.Error() { + // when the vpn-client is closed we get the error "read tun: file already closed" + if err.Error() != "read tun: file already closed" { print(fmt.Sprintf("Error resending traffic from TUN %s to VPN client: %v\n", tun.Name(), err)) } } From ac27da2e1a19cb269272dd5103b4f9626d596906 Mon Sep 17 00:00:00 2001 From: ersonp Date: Thu, 28 Jul 2022 10:54:11 +0530 Subject: [PATCH 6/7] Rpc read error fix This commit fixes the warn error on Read on a closed connection by checking if the error is EOF. If it is then we do not print the error as EOF signals gracefull end of Read. --- pkg/app/appserver/rpc_ingress_gateway.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/app/appserver/rpc_ingress_gateway.go b/pkg/app/appserver/rpc_ingress_gateway.go index 515705af7..be4fdc6d6 100644 --- a/pkg/app/appserver/rpc_ingress_gateway.go +++ b/pkg/app/appserver/rpc_ingress_gateway.go @@ -276,10 +276,12 @@ func (r *RPCIngressGateway) Read(req *ReadReq, resp *ReadResp) error { copy(resp.B, buf[:resp.N]) } if err != nil { - // we don't print warning if the conn is already closed - _, ok := r.cm.Get(req.ConnID) - if ok { - r.log.WithError(err).Warn("Received unexpected error when reading from server.") + if err != io.EOF { + // we don't print warning if the conn is already closed + _, ok := r.cm.Get(req.ConnID) + if ok { + r.log.WithError(err).Warn("Received unexpected error when reading from server.") + } } } From 981d506a226c99471594e53ade1c746212dab6f9 Mon Sep 17 00:00:00 2001 From: ersonp Date: Thu, 28 Jul 2022 11:08:43 +0530 Subject: [PATCH 7/7] Fix rpc read error --- pkg/app/appserver/rpc_ingress_gateway.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/appserver/rpc_ingress_gateway.go b/pkg/app/appserver/rpc_ingress_gateway.go index be4fdc6d6..01510472b 100644 --- a/pkg/app/appserver/rpc_ingress_gateway.go +++ b/pkg/app/appserver/rpc_ingress_gateway.go @@ -276,7 +276,7 @@ func (r *RPCIngressGateway) Read(req *ReadReq, resp *ReadResp) error { copy(resp.B, buf[:resp.N]) } if err != nil { - if err != io.EOF { + if err.Error() != io.EOF.Error() { // we don't print warning if the conn is already closed _, ok := r.cm.Get(req.ConnID) if ok {