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
bec54710
Commit
bec54710
authored
Sep 15, 2022
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new
parent
c512117d
Pipeline
#16679
passed with stages
in 43 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
13 deletions
+12
-13
CMakeLists.txt
CMakeLists.txt
+2
-2
entrypoint.sh
entrypoint.sh
+4
-3
src/Config.h
src/Config.h
+0
-1
src/checksum.h
src/checksum.h
+1
-2
src/main.cpp
src/main.cpp
+5
-5
No files found.
CMakeLists.txt
View file @
bec54710
...
...
@@ -3,9 +3,9 @@ project(tun)
set
(
CMAKE_CXX_STANDARD 20
)
add_executable
(
tun src/
Config.h src/Router.h src/checksum.h src/
main.cpp
)
add_executable
(
tun src/main.cpp
)
set
(
CMAKE_CXX_FLAGS_DEBUG -ggdb
)
#
set(CMAKE_CXX_FLAGS_DEBUG -ggdb)
find_package
(
Threads REQUIRED
)
target_link_libraries
(
tun Threads::Threads
)
...
...
entrypoint.sh
View file @
bec54710
#!/bin/bash
pid
=
0
down
=
$(
echo
$1
| jq
-r
'.routers | .[].up'
)
echo
$down
run_stop
()
{
signalCode
=
$1
if
[
-n
"
$
DOWN_SCRIPT
"
]
;
then
eval
"
$
DOWN_SCRIPT
"
if
[
-n
"
$
down
"
]
;
then
eval
"
$
down
"
fi
if
[
$pid
-ne
0
]
;
then
kill
"-
$signalCode
"
"
$pid
"
...
...
src/Config.h
View file @
bec54710
...
...
@@ -2,7 +2,6 @@
#define TUN_CONFIG_H
#include <nlohmann/json.hpp>
#include <boost/core/noncopyable.hpp>
using
json
=
nlohmann
::
json
;
...
...
src/checksum.h
View file @
bec54710
...
...
@@ -8,6 +8,5 @@ uint16_t csum(uint16_t *packet, int packlen) {
}
if
(
packlen
>
0
)
sum
+=
*
(
unsigned
char
*
)
packet
;
while
(
sum
>>
16
)
sum
=
(
sum
&
0xffff
)
+
(
sum
>>
16
);
return
(
uint16_t
)
~
sum
;
return
(
uint16_t
)
~
sum
;
}
\ No newline at end of file
src/main.cpp
View file @
bec54710
...
...
@@ -26,13 +26,13 @@ void inbound(int raw) {
socklen_t
address_length
=
sizeof
(
address
);
size_t
packet_length
;
while
((
packet_length
=
recvfrom
(
raw
,
buffer
,
sizeof
(
buffer
),
0
,
(
sockaddr
*
)
&
address
,
&
address_length
))
>=
0
)
{
auto
header_length
=
((
ipv6hdr
*
)
buffer
)
->
version
==
4
?
((
iphdr
*
)
buffer
)
->
ihl
:
sizeof
(
ipv6hdr
);
auto
header_length
=
((
ipv6hdr
*
)
buffer
)
->
version
==
4
?
((
iphdr
*
)
buffer
)
->
ihl
*
4
:
sizeof
(
ipv6hdr
);
auto
meta
=
(
Meta
*
)
(
buffer
+
header_length
);
if
(
!
(
Router
::
all
.
contains
(
meta
->
src_id
)
&&
meta
->
dst_id
==
config
.
local_id
&&
meta
->
reserved
==
0
))
continue
;
auto
router
=
Router
::
all
[
meta
->
src_id
];
auto
inner
=
buffer
+
header_length
+
sizeof
(
Meta
);
auto
payload_length
=
packet_length
-
header_length
-
sizeof
(
Meta
);
router
->
decrypt
(
inner
,
payload
_length
);
auto
inner
=
buffer
+
(
header_length
+
sizeof
(
Meta
)
);
auto
inner_length
=
packet_length
-
(
header_length
+
sizeof
(
Meta
)
);
router
->
decrypt
(
inner
,
inner
_length
);
switch
(((
ipv6hdr
*
)
inner
)
->
version
)
{
case
4
:
if
(
csum
((
uint16_t
*
)
inner
,
((
iphdr
*
)
inner
)
->
ihl
*
4
))
continue
;
...
...
@@ -45,7 +45,7 @@ void inbound(int raw) {
}
router
->
remote_addr
=
address
;
if
(
write
(
router
->
tun
,
inner
,
payload
_length
)
<
0
)
{
if
(
write
(
router
->
tun
,
inner
,
inner
_length
)
<
0
)
{
perror
(
"inbound write"
);
}
}
...
...
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