Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] TCP proxy supporting #229

Open
benja-wu opened this issue Sep 2, 2021 · 7 comments
Open

[feature] TCP proxy supporting #229

benja-wu opened this issue Sep 2, 2021 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@benja-wu
Copy link
Contributor

benja-wu commented Sep 2, 2021

Background

  • Easegress works as an L7-level proxy with multiple useful features. But it can't work as an L4-level proxy.

Requirement

  • Make Easegress as an L4-level proxy as well

Discussion

Question 1: Which kind of instance should this feature belong to?

  • Currently, Easegress has a big catalog as TafficGate for specified application protocols, such as HTTP, MQTT, and WebSocket.
  • There is a system-level controller called TrafficController, which manages HTTP-protocol-based HTTPServer and Pipeline by namespace.

Propose to add a new TCPProxy as HTTPServer. Other application level protocol implementations which are using TCP connection directly can be benefited from this TCPProxy managed by TrafficController

Question 2: Are there some awesome, open-sourced packages can we directly import?

  • The goproxy[1] seems to be a quite popular proxy implemented in Golang.

Question 3: How many basic features should a TCP proxy supported?

  • TLS supporting: multiple certificates supporting?
  • Multiple backends load-balancing: Round Robin, Weight Round Robin, Random...?
  • Timeout: sending timeout, connection timeout, receiving timeout?
  • Limited connection: reusing NewLimitListener in Easegress's util pkg?

Propose to confirm the TCPProxy spec firstly. In this spec, it should have a load balance type, listening port, backend array, TLS certificate encoding in base64, and so on...

Question 4: Should we introduce these advanced features in the future?

  • Health checking: such as NGINX[3]
  • Failover: such as Google Cloud balancing[4]
    .....

Summary

  • This is a draft design for the opening discussion. It's welcome to join us for telling your requirements and user scenarios, and let's figure out the basic, core features it should have together. Since Easegress is focusing on modern traffic orchestrating, some nice-to-have advanced feature we can hold it on and plan it implemented in the future.
  • Once we come to a Version 1 conclusion for this TCPProxy, PR for this implementation is also welcomed!

References

  1. https://github.com/snail007/goproxy
  2. https://doc.traefik.io/traefik/routing/services/
  3. https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-health-check/
  4. https://cloud.google.com/load-balancing/docs/tcp
@benja-wu benja-wu added enhancement New feature or request help wanted Extra attention is needed labels Sep 2, 2021
@benja-wu benja-wu added this to the v1.4.0 milestone Sep 2, 2021
@benja-wu benja-wu added this to To do in Easegress Project via automation Sep 2, 2021
@benja-wu
Copy link
Contributor Author

benja-wu commented Sep 2, 2021

@jxd134 @siaron
Maybe we can figure out the design here together. :-)

@benja-wu benja-wu changed the title TCP proxy supporting [feature] TCP proxy supporting Sep 2, 2021
@jxd134
Copy link
Contributor

jxd134 commented Sep 3, 2021

(1) we should seperate tcp/udp proxy with httpserver.
(2) we can use http balance method for tcp/udp proxy (expect headerhash);
(3) there is no need to add tcp/udp pipeline like httppipeline right now;
(4) which indicators of tcp/udp are counted? eg: connection num/send/recv bytes/packet num;
(5)health check is invalid for tpc/udp proxy.

@benja-wu benja-wu linked a pull request Sep 3, 2021 that will close this issue
@ccwxl
Copy link

ccwxl commented Sep 3, 2021

Question 3: These are very useful function support.
What easegress has some introductory materials for developers. I just started go language .thanks

@benja-wu
Copy link
Contributor Author

benja-wu commented Sep 3, 2021

Question 3: These are very useful function support.
What easegress has some introductory materials for developers. I just started go language .thanks

Yes, here is an Easegress development guide.

@nevill
Copy link
Contributor

nevill commented Sep 13, 2021

We have to discuss the spec first. Let me think of an example for this feature.

kind: TCPServer
name: server-demo
port: 10080
rules:
    backend: tcp-demo

---

name: tcp-demo
kind: TCPPipeline
flow:
  - filter: proxy
filters:
  - name: proxy
    kind: TCPProxy
    mainPool:
      servers:
      - url: tcp://127.0.0.1:9095
      - url: tcp://127.0.0.1:9096
      - url: tcp://127.0.0.1:9097

Or, even we can have TCP servers behind HTTPServer, like

kind: HTTPServer
name: server-demo
port: 10080
keepAlive: true
https: false
rules:
  - paths:
    - pathPrefix: /pipeline
      backend: tcp-demo

---

name: tcp-demo
kind: TCPPipeline
flow:
  - filter: proxy
filters:
  - name: proxy
    kind: TCPProxy
    mainPool:
      servers:
      - url: tcp://127.0.0.1:9095
      - url: tcp://127.0.0.1:9096
      - url: tcp://127.0.0.1:9097

@jxd134
Copy link
Contributor

jxd134 commented Sep 13, 2021

@nevill My implementation tends to be the second.
HttpPipeline unable to adapt to tcp bidirectional stream.
Now what is confused is how the tcp data stream is passed in the filters.

The handler I designed is as follows(like netty):

type (
	// Layer4Handler is the common handler for the all backends
	// which handle the traffic from layer4(tcp/udp) server.
	Layer4Handler interface {
		InboundHandler(ctx context.Layer4Context, object interface{})
		OutboundHandler(ctx context.Layer4Context, object interface{})
	}

	// Layer4MuxMapper gets layer4 handler pipeline with mutex
	Layer4MuxMapper interface {
		GetHandler(name string) (Layer4Handler, bool)
	}
)

@xxx7xxxx
Copy link
Contributor

We will hold the 4-layer traffic support until imminent requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Development

Successfully merging a pull request may close this issue.

5 participants