From bf0fbb0e35f289151914a6bee01c30f7790672ef Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 24 Apr 2023 15:37:41 -0400 Subject: [PATCH] ripping out udp support for initial v0.4 --- cmd/zrok/accessPrivateTunnel.go | 39 +++++------------ cmd/zrok/sharePrivate.go | 56 +++++++------------------ endpoints/udpTunnel/backend.go | 74 --------------------------------- endpoints/udpTunnel/frontend.go | 68 ------------------------------ 4 files changed, 26 insertions(+), 211 deletions(-) delete mode 100644 endpoints/udpTunnel/backend.go delete mode 100644 endpoints/udpTunnel/frontend.go diff --git a/cmd/zrok/accessPrivateTunnel.go b/cmd/zrok/accessPrivateTunnel.go index 3b53f986..c2feafa0 100644 --- a/cmd/zrok/accessPrivateTunnel.go +++ b/cmd/zrok/accessPrivateTunnel.go @@ -4,7 +4,6 @@ import ( "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/zrok/endpoints/tcpTunnel" - "github.com/openziti/zrok/endpoints/udpTunnel" "github.com/openziti/zrok/rest_client_zrok" "github.com/openziti/zrok/rest_client_zrok/share" "github.com/openziti/zrok/rest_model_zrok" @@ -24,7 +23,6 @@ func init() { type accessPrivateTunnelCommand struct { bindAddress string - udp bool cmd *cobra.Command } @@ -36,7 +34,6 @@ func newAccessPrivateTunnelCommand() *accessPrivateTunnelCommand { } command := &accessPrivateTunnelCommand{cmd: cmd} cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private tunnel") - cmd.Flags().BoolVar(&command.udp, "udp", false, "Use UDP") cmd.Run = command.run return command } @@ -78,32 +75,16 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) { cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, args[0], zrok, auth) os.Exit(0) }() - - if cmd.udp { - fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{ - BindAddress: cmd.bindAddress, - IdentityName: "backend", - ShrToken: args[0], - }) - if err != nil { - panic(err) - } - if err := fe.Run(); err != nil { - panic(err) - } - - } else { - fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{ - BindAddress: cmd.bindAddress, - IdentityName: "backend", - ShrToken: args[0], - }) - if err != nil { - panic(err) - } - if err := fe.Run(); err != nil { - panic(err) - } + fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{ + BindAddress: cmd.bindAddress, + IdentityName: "backend", + ShrToken: args[0], + }) + if err != nil { + panic(err) + } + if err := fe.Run(); err != nil { + panic(err) } for { time.Sleep(30 * 24 * time.Hour) diff --git a/cmd/zrok/sharePrivate.go b/cmd/zrok/sharePrivate.go index 777e9f6b..c9a61f8e 100644 --- a/cmd/zrok/sharePrivate.go +++ b/cmd/zrok/sharePrivate.go @@ -8,7 +8,6 @@ import ( "github.com/openziti/zrok/endpoints" "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/endpoints/tcpTunnel" - "github.com/openziti/zrok/endpoints/udpTunnel" "github.com/openziti/zrok/model" "github.com/openziti/zrok/rest_client_zrok" "github.com/openziti/zrok/rest_client_zrok/share" @@ -33,7 +32,6 @@ type sharePrivateCommand struct { backendMode string headless bool insecure bool - udp bool cmd *cobra.Command } @@ -48,7 +46,6 @@ func newSharePrivateCommand() *sharePrivateCommand { cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web, tunnel}") cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless") cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for ") - cmd.Flags().BoolVar(&command.udp, "udp", false, "Enable UDP for tunnel backend") cmd.Run = command.run return command } @@ -176,44 +173,23 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) { } case "tunnel": - if cmd.udp { - cfg := &udpTunnel.BackendConfig{ - IdentityPath: zif, - EndpointAddress: target, - ShrToken: resp.Payload.ShrToken, - } - be, err := udpTunnel.NewBackend(cfg) - if err != nil { - if !panicInstead { - tui.Error("unable to create udp tunnel backend", err) - } - panic(err) - } - go func() { - if err := be.Run(); err != nil { - logrus.Errorf("error running udp tunnel backend: %v", err) - } - }() - - } else { - cfg := &tcpTunnel.BackendConfig{ - IdentityPath: zif, - EndpointAddress: target, - ShrToken: resp.Payload.ShrToken, - } - be, err := tcpTunnel.NewBackend(cfg) - if err != nil { - if !panicInstead { - tui.Error("unable to create tunnel backend", err) - } - panic(err) - } - go func() { - if err := be.Run(); err != nil { - logrus.Errorf("error running tunnel backend: %v", err) - } - }() + cfg := &tcpTunnel.BackendConfig{ + IdentityPath: zif, + EndpointAddress: target, + ShrToken: resp.Payload.ShrToken, } + be, err := tcpTunnel.NewBackend(cfg) + if err != nil { + if !panicInstead { + tui.Error("unable to create tunnel backend", err) + } + panic(err) + } + go func() { + if err := be.Run(); err != nil { + logrus.Errorf("error running tunnel backend: %v", err) + } + }() default: tui.Error("invalid backend mode", nil) diff --git a/endpoints/udpTunnel/backend.go b/endpoints/udpTunnel/backend.go deleted file mode 100644 index 8cb4b200..00000000 --- a/endpoints/udpTunnel/backend.go +++ /dev/null @@ -1,74 +0,0 @@ -package udpTunnel - -import ( - "github.com/openziti/sdk-golang/ziti" - "github.com/openziti/sdk-golang/ziti/config" - "github.com/openziti/sdk-golang/ziti/edge" - "github.com/openziti/zrok/endpoints" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "net" - "time" -) - -type BackendConfig struct { - IdentityPath string - EndpointAddress string - ShrToken string -} - -type Backend struct { - cfg *BackendConfig - listener edge.Listener -} - -func NewBackend(cfg *BackendConfig) (*Backend, error) { - options := ziti.ListenOptions{ - ConnectTimeout: 5 * time.Minute, - MaxConnections: 64, - } - zcfg, err := config.NewFromFile(cfg.IdentityPath) - if err != nil { - return nil, errors.Wrap(err, "error loading config") - } - listener, err := ziti.NewContextWithConfig(zcfg).ListenWithOptions(cfg.ShrToken, &options) - if err != nil { - return nil, errors.Wrap(err, "error listening") - } - b := &Backend{ - cfg: cfg, - listener: listener, - } - return b, nil -} - -func (b *Backend) Run() error { - logrus.Info("started") - defer logrus.Info("exited") - - for { - if conn, err := b.listener.Accept(); err == nil { - go b.handle(conn) - } else { - return errors.Wrap(err, "error accepting") - } - } -} - -func (b *Backend) handle(conn net.Conn) { - logrus.Infof("handling '%v'", conn.RemoteAddr()) - defer logrus.Infof("completed '%v'", conn.RemoteAddr()) - - if rAddr, err := net.ResolveUDPAddr("udp", b.cfg.EndpointAddress); err == nil { - if rConn, err := net.DialUDP("udp", nil, rAddr); err == nil { - go endpoints.TXer(conn, rConn) - go endpoints.TXer(rConn, conn) - } else { - logrus.Errorf("error dialing '%v': %v", rAddr, err) - _ = conn.Close() - return - } - } else { - logrus.Errorf("error resolving '%v': %v", b.cfg.EndpointAddress, err) - } -} diff --git a/endpoints/udpTunnel/frontend.go b/endpoints/udpTunnel/frontend.go deleted file mode 100644 index f75b8fd9..00000000 --- a/endpoints/udpTunnel/frontend.go +++ /dev/null @@ -1,68 +0,0 @@ -package udpTunnel - -import ( - "github.com/openziti/sdk-golang/ziti" - "github.com/openziti/sdk-golang/ziti/config" - "github.com/openziti/zrok/endpoints" - "github.com/openziti/zrok/model" - "github.com/openziti/zrok/zrokdir" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "net" -) - -type FrontendConfig struct { - BindAddress string - IdentityName string - ShrToken string -} - -type Frontend struct { - cfg *FrontendConfig - zCtx ziti.Context - lAddr *net.UDPAddr -} - -func NewFrontend(cfg *FrontendConfig) (*Frontend, error) { - lAddr, err := net.ResolveUDPAddr("udp", cfg.BindAddress) - if err != nil { - return nil, errors.Wrapf(err, "error resolving udp address '%v'", cfg.BindAddress) - } - zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.IdentityName) - if err != nil { - return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.IdentityName) - } - zCfg, err := config.NewFromFile(zCfgPath) - if err != nil { - return nil, errors.Wrap(err, "error loading config") - } - zCfg.ConfigTypes = []string{model.ZrokProxyConfig} - zCtx := ziti.NewContextWithConfig(zCfg) - return &Frontend{ - cfg: cfg, - zCtx: zCtx, - lAddr: lAddr, - }, nil -} - -func (f *Frontend) Run() error { - for { - if conn, err := net.ListenUDP("udp", f.lAddr); err == nil { - go f.accept(conn) - logrus.Infof("accepted udp connection from '%v'", conn.RemoteAddr()) - } else { - return err - } - } -} - -func (f *Frontend) accept(conn *net.UDPConn) { - if zConn, err := f.zCtx.Dial(f.cfg.ShrToken); err == nil { - go endpoints.TXer(conn, zConn) - go endpoints.TXer(zConn, conn) - logrus.Infof("accepted '%v' <=> '%v'", conn.RemoteAddr(), zConn.RemoteAddr()) - } else { - logrus.Errorf("error dialing '%v': %v", f.cfg.ShrToken, err) - _ = conn.Close() - } -}