-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: Hijacker for original/redirect IP addresses when using IP_TRANSPARENT or NAT/NAPT #18734
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
Comments
Dup of #18686 from my interpretation. |
If it's not a dup, please clarify what you want. Maybe https://golang.org/wiki/Questions would be a better forum until the proposal can be refined. Maybe it already exists. |
@bradfitz I will try to clear up thing.
|
/cc @mikioh, who knows networking things. |
FWIW, in such case I tend to use a package like github.com/mikioh/tcp. |
@mikioh but what do you mean by using this package? |
Simply, 1) make a custom TCP listener type which implements net.Listener interface, 2) make the Accept method of the custom TCP listener type identify the original destination IP address, 3) pass the custom TCP listener to http.Serve function, and let it run with your HTTP serve handler. I don't see any problem to have a map containing remote and original destination IP addresses, and reading it from your HTTP serve handler. |
@mikioh I am not sure I understood yet. I will try to illustrate the question with code snippet:
will result in this:
I want to be able to use the stock HTTP Serve and pull the LocalAddr() without breaking the option to handle the connection later inside the handler or leaving open FD. Thanks, |
I believe this is a duplicate issue of #18686. It looks like what you want is simply "an IP address which is shared between http.Request and net.Conn on a passive-open side established TCP connection ." So you can use the RemoteAddr field of http.Request as a search key for IP addresses stored in somewhere. Using a platform-dependent option like IP_TRANSPARENT doesn't matter. You can write a type that keeps IP addresses for HTTP clients, use it in a custom net.Listener for storing the IP addresses and retrieve an IP address from it by using the RemoteAddr field of http.Request.
|
@mikioh Thanks!!! |
It depends on your circumstances. In general, it could be similar to an algorithm and data structure for IP address prefix lookup. There are tons of tradeoffs, but I guess it would be the most fun part of your software. So enjoy it! |
@mikioh No the most efficient example: |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.6+1.7
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/eliezer/go-workspace"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build576063994=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
What did you do?
I use http connection hijack and it locks the connection completly.
https://golang.org/src/net/http/server.go?h=hijacked#L254
What did you expect to see?
An option to hijack the connection so I would be able to extrct from it the local address(for a transparent proxy)
Like I can be done on a regular connection at:
https://github.com/elico/go-linux-tproxy/blob/master/examples/tcpproxy1.go#L167
And I am sure a method that can be a way to do so without any issues.
I was thikning aobut supplying a special listener with a middleware that will pass the local address into the request as an header But would be happy to see one(maybe there is and I don't know about).
What did you see instead?
The only option is to hijack the connection and then manage it.
This is while I don't touch any read or write methods on the connections,
The text was updated successfully, but these errors were encountered: