mirror of
https://github.com/openziti/zrok.git
synced 2025-01-24 14:59:08 +01:00
ripping out udp support for initial v0.4
This commit is contained in:
parent
25b1469acc
commit
bf0fbb0e35
@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
"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"
|
||||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
@ -24,7 +23,6 @@ func init() {
|
|||||||
|
|
||||||
type accessPrivateTunnelCommand struct {
|
type accessPrivateTunnelCommand struct {
|
||||||
bindAddress string
|
bindAddress string
|
||||||
udp bool
|
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +34,6 @@ func newAccessPrivateTunnelCommand() *accessPrivateTunnelCommand {
|
|||||||
}
|
}
|
||||||
command := &accessPrivateTunnelCommand{cmd: cmd}
|
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().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
|
cmd.Run = command.run
|
||||||
return command
|
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)
|
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, args[0], zrok, auth)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
||||||
if cmd.udp {
|
BindAddress: cmd.bindAddress,
|
||||||
fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{
|
IdentityName: "backend",
|
||||||
BindAddress: cmd.bindAddress,
|
ShrToken: args[0],
|
||||||
IdentityName: "backend",
|
})
|
||||||
ShrToken: args[0],
|
if err != nil {
|
||||||
})
|
panic(err)
|
||||||
if err != nil {
|
}
|
||||||
panic(err)
|
if err := fe.Run(); 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
time.Sleep(30 * 24 * time.Hour)
|
time.Sleep(30 * 24 * time.Hour)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/openziti/zrok/endpoints"
|
"github.com/openziti/zrok/endpoints"
|
||||||
"github.com/openziti/zrok/endpoints/proxy"
|
"github.com/openziti/zrok/endpoints/proxy"
|
||||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
||||||
"github.com/openziti/zrok/endpoints/udpTunnel"
|
|
||||||
"github.com/openziti/zrok/model"
|
"github.com/openziti/zrok/model"
|
||||||
"github.com/openziti/zrok/rest_client_zrok"
|
"github.com/openziti/zrok/rest_client_zrok"
|
||||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||||
@ -33,7 +32,6 @@ type sharePrivateCommand struct {
|
|||||||
backendMode string
|
backendMode string
|
||||||
headless bool
|
headless bool
|
||||||
insecure bool
|
insecure bool
|
||||||
udp bool
|
|
||||||
cmd *cobra.Command
|
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().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.headless, "headless", false, "Disable TUI and run headless")
|
||||||
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
|
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
|
||||||
cmd.Flags().BoolVar(&command.udp, "udp", false, "Enable UDP for tunnel backend")
|
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
@ -176,44 +173,23 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "tunnel":
|
case "tunnel":
|
||||||
if cmd.udp {
|
cfg := &tcpTunnel.BackendConfig{
|
||||||
cfg := &udpTunnel.BackendConfig{
|
IdentityPath: zif,
|
||||||
IdentityPath: zif,
|
EndpointAddress: target,
|
||||||
EndpointAddress: target,
|
ShrToken: resp.Payload.ShrToken,
|
||||||
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)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
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:
|
default:
|
||||||
tui.Error("invalid backend mode", nil)
|
tui.Error("invalid backend mode", nil)
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user