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
b63f8153
Commit
b63f8153
authored
Aug 20, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improves
parent
54fd3bfb
Pipeline
#40640
passed with stages
in 1 minute and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
+28
-8
src/main.rs
src/main.rs
+0
-2
src/router.rs
src/router.rs
+28
-6
No files found.
src/main.rs
View file @
b63f8153
...
...
@@ -101,8 +101,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let
n
=
router
.tun_reader
.read
(
&
mut
buffer
[
meta_size
..
])
.unwrap
();
if
let
Some
(
ref
addr
)
=
*
router
.endpoint
.read
()
.unwrap
()
{
router
.encrypt
(
&
mut
buffer
[
meta_size
..
meta_size
+
n
]);
#[cfg(target_os
=
"linux"
)]
let
_
=
router
.socket
.set_mark
(
router
.config.mark
);
let
_
=
router
.socket
.send_to
(
&
buffer
[
..
meta_size
+
n
],
addr
);
}
}
...
...
src/router.rs
View file @
b63f8153
...
...
@@ -9,6 +9,26 @@ pub const SECRET_LENGTH: usize = 32;
use
crate
::
ConfigRouter
;
use
base64
::
prelude
::
*
;
#[inline]
fn
xor_with_secret
(
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
SECRET_LENGTH
])
{
let
mut
i
=
0
;
let
len
=
data
.len
();
// 处理完整块
while
i
+
SECRET_LENGTH
<=
len
{
for
j
in
0
..
SECRET_LENGTH
{
data
[
i
+
j
]
^=
secret
[
j
];
}
i
+=
SECRET_LENGTH
;
}
// 处理剩余尾部
for
j
in
0
..
len
-
i
{
data
[
i
+
j
]
^=
secret
[
j
];
}
}
// tun -> raw
pub
struct
RouterReader
<
'a
>
{
pub
config
:
&
'a
ConfigRouter
,
...
...
@@ -19,10 +39,9 @@ pub struct RouterReader<'a> {
}
impl
<
'a
>
RouterReader
<
'a
>
{
#[inline]
pub
(
crate
)
fn
encrypt
(
&
self
,
data
:
&
mut
[
u8
])
{
for
(
i
,
b
)
in
data
.iter_mut
()
.enumerate
()
{
*
b
^=
self
.secret
[
i
%
SECRET_LENGTH
];
}
xor_with_secret
(
data
,
&
self
.secret
);
}
}
...
...
@@ -34,10 +53,9 @@ pub struct RouterWriter<'a> {
}
impl
<
'a
>
RouterWriter
<
'a
>
{
#[inline]
pub
(
crate
)
fn
decrypt
(
&
self
,
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
SECRET_LENGTH
])
{
for
(
i
,
b
)
in
data
.iter_mut
()
.enumerate
()
{
*
b
^=
secret
[
i
%
SECRET_LENGTH
];
}
xor_with_secret
(
data
,
secret
);
}
pub
(
crate
)
fn
key
(
&
self
)
->
u16
{
...
...
@@ -119,6 +137,10 @@ impl<'a> Router<'a> {
let
secret
=
Self
::
create_secret
(
config
.remote_secret
.as_str
())
?
;
let
endpoint
=
Self
::
create_endpoint
(
&
config
)
?
;
let
socket
=
Self
::
create_raw_socket
(
&
config
,
sockets
)
?
;
if
(
config
.mark
>
0
)
{
#[cfg(target_os
=
"linux"
)]
let
_
=
socket
.set_mark
(
config
.mark
);
}
let
(
tun_reader
,
tun_writer
)
=
Self
::
create_tun_device
(
&
config
)
?
;
Self
::
run_up_script
(
&
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