From ab8b02ddd07140630b2fbb2ad4a413a27568a08b Mon Sep 17 00:00:00 2001 From: Mustafa ARICI Date: Sun, 4 Apr 2021 21:18:05 +0300 Subject: [PATCH] refactor(cmd/ovpmd): force listeners on tcp4 network Closes #108 --- CHANGELOG.md | 4 ++++ cmd/ovpmd/main.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26a8801..da324b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [Unreleased] + +- Make sure ovpmd listens on IPv4 interfaces [#108](https://github.com/cad/ovpm/issues/108) + ## [v0.2.10](https://github.com/cad/ovpm/tree/v0.2.10) - Fix ovpmd not starting error on Ubuntu. [#99](https://github.com/cad/ovpm/issues/99) diff --git a/cmd/ovpmd/main.go b/cmd/ovpmd/main.go index 4c20f65..09c2b61 100644 --- a/cmd/ovpmd/main.go +++ b/cmd/ovpmd/main.go @@ -77,6 +77,7 @@ func main() { type server struct { grpcPort string lis net.Listener + restLis net.Listener grpcServer *grpc.Server restServer http.Handler restCancel context.CancelFunc @@ -99,14 +100,19 @@ func newServer(port, webPort string) *server { }() if !ovpm.Testing { // NOTE(cad): gRPC endpoint listens on localhost. This is important - // because we don't authanticate requests coming from localhost. + // because we don't authenticate requests coming from localhost. // So gRPC endpoint should never listen on something else then // localhost. - lis, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%s", port)) + lis, err := net.Listen("tcp4", fmt.Sprintf("127.0.0.1:%s", port)) if err != nil { logrus.Fatalf("could not listen to port %s: %v", port, err) } + restLis, err := net.Listen("tcp4", fmt.Sprintf("0.0.0.0:%s", webPort)) + if err != nil { + logrus.Fatalf("could not listen to port %s: %v", webPort, err) + } + rpcServer := api.NewRPCServer() restServer, restCancel, err := api.NewRESTServer(port) if err != nil { @@ -115,6 +121,7 @@ func newServer(port, webPort string) *server { return &server{ lis: lis, + restLis: restLis, grpcServer: rpcServer, restServer: restServer, restCancel: context.CancelFunc(restCancel), @@ -131,7 +138,7 @@ func newServer(port, webPort string) *server { func (s *server) start() { logrus.Infof("OVPM %s is running gRPC:%s, REST:%s ...", ovpm.Version, s.grpcPort, s.restPort) go s.grpcServer.Serve(s.lis) - go http.ListenAndServe(":"+s.restPort, s.restServer) + go http.Serve(s.restLis, s.restServer) ovpm.TheServer().StartVPNProc() }