Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
62d92d95
Commit
62d92d95
authored
Jan 04, 2017
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#61 add transparent proxy support
parent
a0649528
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
2 deletions
+105
-2
README_en.md
README_en.md
+1
-1
node.go
node.go
+1
-1
redirect.go
redirect.go
+101
-0
server.go
server.go
+2
-0
No files found.
README_en.md
View file @
62d92d95
...
@@ -265,7 +265,7 @@ gost -L=:8080 -F=ss://aes-128-cfb:123456@server_ip:8338
...
@@ -265,7 +265,7 @@ gost -L=:8080 -F=ss://aes-128-cfb:123456@server_ip:8338
#### TLS
#### TLS
There is built-in TLS certificate in gost, if you need to use other TLS certificate, there are two ways:
There is built-in TLS certificate in gost, if you need to use other TLS certificate, there are two ways:
*
Place two files cert.pem (public key) and key.pem (private key) in the current working directory, gost will automatically load them.
*
Place two files cert.pem (public key) and key.pem (private key) in the current working directory, gost will automatically load them.
*
Use the parameter to specify the path to the certificate file
:
*
Use the parameter to specify the path to the certificate file
:
```
bash
```
bash
gost
-L
=
"http2://:443?cert=/path/to/my/cert/file&key=/path/to/my/key/file"
gost
-L
=
"http2://:443?cert=/path/to/my/cert/file&key=/path/to/my/key/file"
```
```
...
...
node.go
View file @
62d92d95
...
@@ -71,7 +71,7 @@ func ParseProxyNode(s string) (node ProxyNode, err error) {
...
@@ -71,7 +71,7 @@ func ParseProxyNode(s string) (node ProxyNode, err error) {
}
}
switch
node
.
Transport
{
switch
node
.
Transport
{
case
"ws"
,
"wss"
,
"tls"
,
"http2"
,
"ssu"
,
"quic"
,
"kcp"
:
case
"ws"
,
"wss"
,
"tls"
,
"http2"
,
"ssu"
,
"quic"
,
"kcp"
,
"redirect"
:
case
"https"
:
case
"https"
:
node
.
Protocol
=
"http"
node
.
Protocol
=
"http"
node
.
Transport
=
"tls"
node
.
Transport
=
"tls"
...
...
redirect.go
0 → 100644
View file @
62d92d95
package
gost
import
(
"errors"
"fmt"
"github.com/golang/glog"
"net"
"syscall"
)
const
(
SO_ORIGINAL_DST
=
80
)
type
RedsocksTCPServer
struct
{
Base
*
ProxyServer
}
func
NewRedsocksTCPServer
(
base
*
ProxyServer
)
*
RedsocksTCPServer
{
return
&
RedsocksTCPServer
{
Base
:
base
,
}
}
func
(
s
*
RedsocksTCPServer
)
ListenAndServe
()
error
{
laddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp"
,
s
.
Base
.
Node
.
Addr
)
if
err
!=
nil
{
return
err
}
ln
,
err
:=
net
.
ListenTCP
(
"tcp"
,
laddr
)
if
err
!=
nil
{
return
err
}
defer
ln
.
Close
()
for
{
conn
,
err
:=
ln
.
AcceptTCP
()
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
err
)
continue
}
go
s
.
handleRedirectTCP
(
conn
)
}
}
func
(
s
*
RedsocksTCPServer
)
handleRedirectTCP
(
conn
*
net
.
TCPConn
)
{
srcAddr
:=
conn
.
RemoteAddr
()
dstAddr
,
conn
,
err
:=
getOriginalDstAddr
(
conn
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infof
(
"[red-tcp] %s -> %s : %s"
,
srcAddr
,
dstAddr
,
err
)
return
}
defer
conn
.
Close
()
glog
.
V
(
LINFO
)
.
Infof
(
"[red-tcp] %s -> %s"
,
srcAddr
,
dstAddr
)
cc
,
err
:=
s
.
Base
.
Chain
.
Dial
(
dstAddr
.
String
())
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infof
(
"[red-tcp] %s -> %s : %s"
,
srcAddr
,
dstAddr
,
err
)
return
}
defer
cc
.
Close
()
glog
.
V
(
LINFO
)
.
Infof
(
"[red-tcp] %s <-> %s"
,
srcAddr
,
dstAddr
)
s
.
Base
.
transport
(
conn
,
cc
)
glog
.
V
(
LINFO
)
.
Infof
(
"[red-tcp] %s >-< %s"
,
srcAddr
,
dstAddr
)
}
func
getOriginalDstAddr
(
conn
*
net
.
TCPConn
)
(
addr
net
.
Addr
,
c
*
net
.
TCPConn
,
err
error
)
{
defer
conn
.
Close
()
fc
,
err
:=
conn
.
File
()
if
err
!=
nil
{
return
}
defer
fc
.
Close
()
mreq
,
err
:=
syscall
.
GetsockoptIPv6Mreq
(
int
(
fc
.
Fd
()),
syscall
.
IPPROTO_IP
,
SO_ORIGINAL_DST
)
if
err
!=
nil
{
return
}
// only ipv4 support
ip
:=
net
.
IPv4
(
mreq
.
Multiaddr
[
4
],
mreq
.
Multiaddr
[
5
],
mreq
.
Multiaddr
[
6
],
mreq
.
Multiaddr
[
7
])
port
:=
uint16
(
mreq
.
Multiaddr
[
2
])
<<
8
+
uint16
(
mreq
.
Multiaddr
[
3
])
addr
,
err
=
net
.
ResolveTCPAddr
(
"tcp4"
,
fmt
.
Sprintf
(
"%s:%d"
,
ip
.
String
(),
port
))
if
err
!=
nil
{
return
}
cc
,
err
:=
net
.
FileConn
(
fc
)
if
err
!=
nil
{
return
}
c
,
ok
:=
cc
.
(
*
net
.
TCPConn
)
if
!
ok
{
err
=
errors
.
New
(
"not a TCP connection"
)
}
return
}
server.go
View file @
62d92d95
...
@@ -95,6 +95,8 @@ func (s *ProxyServer) Serve() error {
...
@@ -95,6 +95,8 @@ func (s *ProxyServer) Serve() error {
config
.
Key
,
_
=
s
.
Node
.
Users
[
0
]
.
Password
()
config
.
Key
,
_
=
s
.
Node
.
Users
[
0
]
.
Password
()
}
}
return
NewKCPServer
(
s
,
config
)
.
ListenAndServe
()
return
NewKCPServer
(
s
,
config
)
.
ListenAndServe
()
case
"redirect"
:
return
NewRedsocksTCPServer
(
s
)
.
ListenAndServe
()
default
:
default
:
ln
,
err
=
net
.
Listen
(
"tcp"
,
node
.
Addr
)
ln
,
err
=
net
.
Listen
(
"tcp"
,
node
.
Addr
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment