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
d9f3b4dd
Commit
d9f3b4dd
authored
Aug 13, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add mark option
parent
a4695ece
Pipeline
#4648
canceled with stages
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
0 deletions
+26
-0
chain.go
chain.go
+22
-0
cmd/gost/main.go
cmd/gost/main.go
+1
-0
cmd/gost/route.go
cmd/gost/route.go
+2
-0
handler.go
handler.go
+1
-0
No files found.
chain.go
View file @
d9f3b4dd
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"errors"
"errors"
"net"
"net"
"syscall"
"time"
"time"
"github.com/go-log/log"
"github.com/go-log/log"
...
@@ -18,6 +19,7 @@ var (
...
@@ -18,6 +19,7 @@ var (
type
Chain
struct
{
type
Chain
struct
{
isRoute
bool
isRoute
bool
Retries
int
Retries
int
Mark
int
nodeGroups
[]
*
NodeGroup
nodeGroups
[]
*
NodeGroup
route
[]
Node
// nodes in the selected route
route
[]
Node
// nodes in the selected route
}
}
...
@@ -131,6 +133,10 @@ func (c *Chain) DialContext(ctx context.Context, network, address string, opts .
...
@@ -131,6 +133,10 @@ func (c *Chain) DialContext(ctx context.Context, network, address string, opts .
return
return
}
}
func
setSocketMark
(
fd
int
,
value
int
)
(
e
error
)
{
return
syscall
.
SetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
syscall
.
SO_MARK
,
value
)
}
func
(
c
*
Chain
)
dialWithOptions
(
ctx
context
.
Context
,
network
,
address
string
,
options
*
ChainOptions
)
(
net
.
Conn
,
error
)
{
func
(
c
*
Chain
)
dialWithOptions
(
ctx
context
.
Context
,
network
,
address
string
,
options
*
ChainOptions
)
(
net
.
Conn
,
error
)
{
if
options
==
nil
{
if
options
==
nil
{
options
=
&
ChainOptions
{}
options
=
&
ChainOptions
{}
...
@@ -150,6 +156,20 @@ func (c *Chain) dialWithOptions(ctx context.Context, network, address string, op
...
@@ -150,6 +156,20 @@ func (c *Chain) dialWithOptions(ctx context.Context, network, address string, op
timeout
=
DialTimeout
timeout
=
DialTimeout
}
}
var
controlFunction
func
(
_
string
,
_
string
,
c
syscall
.
RawConn
)
error
=
nil
if
c
.
Mark
>
0
{
controlFunction
=
func
(
_
,
_
string
,
cc
syscall
.
RawConn
)
error
{
return
cc
.
Control
(
func
(
fd
uintptr
)
{
ex
:=
setSocketMark
(
int
(
fd
),
c
.
Mark
)
if
ex
!=
nil
{
log
.
Logf
(
"net dialer set mark %d error: %s"
,
options
.
Mark
,
ex
)
}
else
{
log
.
Logf
(
"net dialer set mark %d success"
,
options
.
Mark
)
}
})
}
}
if
route
.
IsEmpty
()
{
if
route
.
IsEmpty
()
{
switch
network
{
switch
network
{
case
"udp"
,
"udp4"
,
"udp6"
:
case
"udp"
,
"udp4"
,
"udp6"
:
...
@@ -160,6 +180,7 @@ func (c *Chain) dialWithOptions(ctx context.Context, network, address string, op
...
@@ -160,6 +180,7 @@ func (c *Chain) dialWithOptions(ctx context.Context, network, address string, op
}
}
d
:=
&
net
.
Dialer
{
d
:=
&
net
.
Dialer
{
Timeout
:
timeout
,
Timeout
:
timeout
,
Control
:
controlFunction
,
// LocalAddr: laddr, // TODO: optional local address
// LocalAddr: laddr, // TODO: optional local address
}
}
return
d
.
DialContext
(
ctx
,
network
,
ipAddr
)
return
d
.
DialContext
(
ctx
,
network
,
ipAddr
)
...
@@ -328,6 +349,7 @@ type ChainOptions struct {
...
@@ -328,6 +349,7 @@ type ChainOptions struct {
Timeout
time
.
Duration
Timeout
time
.
Duration
Hosts
*
Hosts
Hosts
*
Hosts
Resolver
Resolver
Resolver
Resolver
Mark
int
}
}
// ChainOption allows a common way to set chain options.
// ChainOption allows a common way to set chain options.
...
...
cmd/gost/main.go
View file @
d9f3b4dd
...
@@ -31,6 +31,7 @@ func init() {
...
@@ -31,6 +31,7 @@ func init() {
flag
.
Var
(
&
baseCfg
.
route
.
ChainNodes
,
"F"
,
"forward address, can make a forward chain"
)
flag
.
Var
(
&
baseCfg
.
route
.
ChainNodes
,
"F"
,
"forward address, can make a forward chain"
)
flag
.
Var
(
&
baseCfg
.
route
.
ServeNodes
,
"L"
,
"listen address, can listen on multiple ports (required)"
)
flag
.
Var
(
&
baseCfg
.
route
.
ServeNodes
,
"L"
,
"listen address, can listen on multiple ports (required)"
)
flag
.
IntVar
(
&
baseCfg
.
route
.
Mark
,
"M"
,
0
,
"Specify out connection mark"
)
flag
.
StringVar
(
&
configureFile
,
"C"
,
""
,
"configure file"
)
flag
.
StringVar
(
&
configureFile
,
"C"
,
""
,
"configure file"
)
flag
.
BoolVar
(
&
baseCfg
.
Debug
,
"D"
,
false
,
"enable debug log"
)
flag
.
BoolVar
(
&
baseCfg
.
Debug
,
"D"
,
false
,
"enable debug log"
)
flag
.
BoolVar
(
&
printVersion
,
"V"
,
false
,
"print version"
)
flag
.
BoolVar
(
&
printVersion
,
"V"
,
false
,
"print version"
)
...
...
cmd/gost/route.go
View file @
d9f3b4dd
...
@@ -30,11 +30,13 @@ type route struct {
...
@@ -30,11 +30,13 @@ type route struct {
ServeNodes
stringList
ServeNodes
stringList
ChainNodes
stringList
ChainNodes
stringList
Retries
int
Retries
int
Mark
int
}
}
func
(
r
*
route
)
parseChain
()
(
*
gost
.
Chain
,
error
)
{
func
(
r
*
route
)
parseChain
()
(
*
gost
.
Chain
,
error
)
{
chain
:=
gost
.
NewChain
()
chain
:=
gost
.
NewChain
()
chain
.
Retries
=
r
.
Retries
chain
.
Retries
=
r
.
Retries
chain
.
Mark
=
r
.
Mark
gid
:=
1
// group ID
gid
:=
1
// group ID
for
_
,
ns
:=
range
r
.
ChainNodes
{
for
_
,
ns
:=
range
r
.
ChainNodes
{
...
...
handler.go
View file @
d9f3b4dd
...
@@ -42,6 +42,7 @@ type HandlerOptions struct {
...
@@ -42,6 +42,7 @@ type HandlerOptions struct {
IPs
[]
string
IPs
[]
string
TCPMode
bool
TCPMode
bool
IPRoutes
[]
IPRoute
IPRoutes
[]
IPRoute
Mark
int
}
}
// HandlerOption allows a common way to set handler options.
// HandlerOption allows a common way to set handler options.
...
...
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