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
641f7806
Commit
641f7806
authored
Aug 17, 2022
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipv6
parent
fb2be580
Pipeline
#15703
passed with stages
in 1 minute
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
17 deletions
+31
-17
src/main.cpp
src/main.cpp
+31
-17
No files found.
src/main.cpp
View file @
641f7806
...
...
@@ -45,24 +45,29 @@ uint16_t csum(uint16_t *packet, int packlen) {
}
class
Secret
{
private:
char
*
key
;
size_t
length
;
public:
Secret
(
char
*
key
)
:
key
(
key
),
length
(
strlen
(
key
))
{}
void
encrypt
(
unsigned
char
*
data
,
size_t
length
)
{
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
data
[
i
]
^=
key
[
i
%
this
->
length
];
}
}
void
decrypt
(
unsigned
char
*
data
,
size_t
length
)
{
encrypt
(
data
,
length
);
private:
char
*
key
;
size_t
length
;
public:
Secret
(
char
*
key
)
:
key
(
key
),
length
(
strlen
(
key
))
{}
void
encrypt
(
unsigned
char
*
data
,
size_t
length
)
{
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
data
[
i
]
^=
key
[
i
%
this
->
length
];
}
}
void
decrypt
(
unsigned
char
*
data
,
size_t
length
)
{
encrypt
(
data
,
length
);
}
};
Secret
*
localSecret
;
Secret
*
remoteSecret
;
#include <linux/ipv6.h>
// internet -> tun
void
inbound
(
int
raw
,
int
tun
)
{
unsigned
char
buffer
[
ETH_DATA_LEN
];
...
...
@@ -75,11 +80,20 @@ void inbound(int raw, int tun) {
auto
payload
=
buffer
+
overhead
;
auto
meta
=
(
Meta
*
)
payload
;
if
(
!
(
meta
->
src_id
==
remote_id
&&
meta
->
dst_id
==
local_id
&&
meta
->
reversed
==
0
))
continue
;
auto
inner
=
(
iphdr
*
)
(
payload
+
sizeof
(
Meta
));
auto
inner
=
(
payload
+
sizeof
(
Meta
));
auto
payload_length
=
packet_length
-
overhead
-
sizeof
(
Meta
);
remoteSecret
->
decrypt
((
unsigned
char
*
)
inner
,
payload_length
);
remoteSecret
->
decrypt
(
inner
,
payload_length
);
switch
(((
ipv6hdr
*
)
inner
)
->
version
)
{
case
4
:
if
(
csum
((
uint16_t
*
)
inner
,
((
iphdr
*
)
inner
)
->
ihl
*
4
))
continue
;
break
;
case
6
:
// ipv6 don't have checksum, do nothing
break
;
default:
continue
;
}
// if (ip_fast_csum(inner, inner->ihl)) continue;
if
(
csum
((
uint16_t
*
)
inner
,
inner
->
ihl
*
4
))
continue
;
// std::cout << "packet_length " << packet_length
// << " tot_len " << ntohs(packet->tot_len)
// << " inner->tot_len " << ntohs(inner->tot_len)
...
...
@@ -116,7 +130,7 @@ void outbound(int raw, int tun) {
perror
(
"outbound read"
);
}
auto
get_var
(
const
char
*
varname
,
bool
required
=
false
)
{
auto
get_var
(
const
char
*
varname
,
bool
required
=
false
)
{
auto
value
=
getenv
(
varname
);
if
(
value
==
nullptr
&&
required
)
{
std
::
cerr
<<
"missing required environment variable: "
<<
varname
<<
std
::
endl
;
...
...
@@ -125,7 +139,7 @@ auto get_var(const char* varname, bool required = false) {
return
value
;
}
auto
get_var_number
(
const
char
*
varname
,
bool
required
=
false
)
{
auto
get_var_number
(
const
char
*
varname
,
bool
required
=
false
)
{
auto
value
=
get_var
(
varname
,
required
);
if
(
value
==
nullptr
)
return
0
;
return
atoi
(
value
);
...
...
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