Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
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
Railgun
tun
Commits
dc799bee
Commit
dc799bee
authored
Dec 11, 2025
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config
parent
64c6814d
Pipeline
#41945
passed with stages
in 1 minute and 16 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
src/config.rs
src/config.rs
+2
-0
src/router.rs
src/router.rs
+13
-7
No files found.
src/config.rs
View file @
dc799bee
...
@@ -23,7 +23,9 @@ pub struct ConfigRouter {
...
@@ -23,7 +23,9 @@ pub struct ConfigRouter {
pub
dst_port
:
u16
,
pub
dst_port
:
u16
,
#[serde(deserialize_with
=
"deserialize_domain"
)]
#[serde(deserialize_with
=
"deserialize_domain"
)]
pub
family
:
Domain
,
pub
family
:
Domain
,
#[serde(default)]
pub
mark
:
u32
,
pub
mark
:
u32
,
#[serde(default)]
pub
endpoint
:
String
,
pub
endpoint
:
String
,
#[serde(deserialize_with
=
"deserialize_secret"
)]
#[serde(deserialize_with
=
"deserialize_secret"
)]
pub
local_secret
:
[
u8
;
SECRET_LENGTH
],
pub
local_secret
:
[
u8
;
SECRET_LENGTH
],
...
...
src/router.rs
View file @
dc799bee
use
anyhow
::{
Result
,
bail
,
ensure
};
use
anyhow
::{
bail
,
ensure
,
Result
};
use
socket2
::{
Domain
,
Protocol
,
SockAddr
,
SockFilter
,
Socket
,
Type
};
use
socket2
::{
Domain
,
Protocol
,
SockAddr
,
SockFilter
,
Socket
,
Type
};
use
std
::
net
::
Shutdown
;
use
std
::
net
::
Shutdown
;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
...
@@ -14,10 +14,10 @@ use std::{
...
@@ -14,10 +14,10 @@ use std::{
use
tun
::
Device
;
use
tun
::
Device
;
use
crate
::
config
::{
ConfigRouter
,
Schema
};
use
crate
::
config
::{
ConfigRouter
,
Schema
};
use
crossbeam
::
epoch
::{
Atomic
,
pin
};
use
crossbeam
::
epoch
::{
pin
,
Atomic
};
use
libc
::{
use
libc
::{
BPF_ABS
,
BPF_B
,
BPF_IND
,
BPF_JEQ
,
BPF_JMP
,
BPF_K
,
BPF_LD
,
BPF_LDX
,
BPF_MSH
,
BPF_RET
,
BPF_W
,
MSG_FASTOPEN
,
SO_ATTACH_REUSEPORT_CBPF
,
SOL_SOCKET
,
setsockopt
,
setsockopt
,
sock_filter
,
sock_fprog
,
socklen_t
,
BPF_ABS
,
BPF_B
,
BPF_IND
,
BPF_JEQ
,
BPF_JMP
,
BPF_K
,
BPF_LD
,
BPF_LDX
,
BPF_MSH
,
BPF_RET
,
BPF_W
,
sock_filter
,
sock_fprog
,
socklen_t
,
MSG_FASTOPEN
,
SOL_SOCKET
,
SO_ATTACH_REUSEPORT_CBPF
,
};
};
pub
const
SECRET_LENGTH
:
usize
=
32
;
pub
const
SECRET_LENGTH
:
usize
=
32
;
...
@@ -70,13 +70,17 @@ impl Router {
...
@@ -70,13 +70,17 @@ impl Router {
match
config
.schema
{
match
config
.schema
{
Schema
::
IP
=>
{
Schema
::
IP
=>
{
let
result
=
Socket
::
new
(
config
.family
,
Type
::
RAW
,
Some
(
Protocol
::
from
(
config
.proto
as
i32
)))
?
;
let
result
=
Socket
::
new
(
config
.family
,
Type
::
RAW
,
Some
(
Protocol
::
from
(
config
.proto
as
i32
)))
?
;
result
.set_mark
(
config
.mark
)
?
;
if
config
.mark
!=
0
{
result
.set_mark
(
config
.mark
)
?
;
}
Self
::
attach_filter_ip
(
config
,
&
result
)
?
;
Self
::
attach_filter_ip
(
config
,
&
result
)
?
;
Ok
(
result
)
Ok
(
result
)
}
}
Schema
::
UDP
=>
{
Schema
::
UDP
=>
{
let
result
=
Socket
::
new
(
config
.family
,
Type
::
DGRAM
,
Some
(
Protocol
::
UDP
))
?
;
let
result
=
Socket
::
new
(
config
.family
,
Type
::
DGRAM
,
Some
(
Protocol
::
UDP
))
?
;
result
.set_mark
(
config
.mark
)
?
;
if
config
.mark
!=
0
{
result
.set_mark
(
config
.mark
)
?
;
}
if
config
.src_port
!=
0
{
if
config
.src_port
!=
0
{
result
.set_reuse_port
(
true
)
?
;
result
.set_reuse_port
(
true
)
?
;
let
addr
=
Self
::
bind_addr
(
config
);
let
addr
=
Self
::
bind_addr
(
config
);
...
@@ -105,7 +109,9 @@ impl Router {
...
@@ -105,7 +109,9 @@ impl Router {
// 创建 socket 和 获取 endpoint 失败会 panic,连接失败会 error
// 创建 socket 和 获取 endpoint 失败会 panic,连接失败会 error
let
result
=
Socket
::
new
(
self
.config.family
,
Type
::
STREAM
,
Some
(
Protocol
::
TCP
))
.unwrap
();
let
result
=
Socket
::
new
(
self
.config.family
,
Type
::
STREAM
,
Some
(
Protocol
::
TCP
))
.unwrap
();
result
.set_tcp_nodelay
(
true
)
.unwrap
();
result
.set_tcp_nodelay
(
true
)
.unwrap
();
result
.set_mark
(
self
.config.mark
)
.unwrap
();
if
self
.config.mark
!=
0
{
result
.set_mark
(
self
.config.mark
)
.unwrap
();
}
if
self
.config.src_port
!=
0
{
if
self
.config.src_port
!=
0
{
result
.set_reuse_address
(
true
)
.unwrap
();
result
.set_reuse_address
(
true
)
.unwrap
();
let
addr
=
Self
::
bind_addr
(
&
self
.config
);
let
addr
=
Self
::
bind_addr
(
&
self
.config
);
...
...
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