Compare commits

..

58 Commits

Author SHA1 Message Date
wangyu
2fa2666479 make cross2 cross3 2017-08-12 11:36:14 +08:00
wangyu-
fdbf1e082f Update README.md 2017-08-11 17:24:51 -07:00
wangyu
d502de0c7c Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-12 07:13:30 +08:00
wangyu
8487d7c624 updated image 2017-08-12 07:12:54 +08:00
wangyu-
83b00e79ad Add files via upload 2017-08-11 08:40:23 -07:00
wangyu-
36ed28064a Create 111 2017-08-11 08:39:43 -07:00
wangyu-
746aefa70a Update README.md 2017-08-11 06:54:39 -07:00
wangyu-
a69cbf23da Merge pull request #4 from t123yh/patch-1
Update README.md
2017-08-11 21:50:00 +08:00
Tian Yunhao
fc4d178657 Update README.md 2017-08-11 20:36:37 +08:00
wangyu-
ccab523ddf Update README.zh-cn.md 2017-08-11 02:46:33 -07:00
wangyu-
4eb72f6139 Update README.md 2017-08-11 02:45:29 -07:00
wangyu-
6296322e22 Update README.zh-cn.md 2017-08-11 02:41:07 -07:00
wangyu-
3a0c512e43 Update README.md 2017-08-11 02:39:46 -07:00
wangyu-
e01d7059ad Update README.zh-cn.md 2017-08-11 02:26:25 -07:00
wangyu-
5e6d977247 Update README.md 2017-08-11 02:25:14 -07:00
wangyu-
c08bd12ea0 Update README.md 2017-08-11 01:55:26 -07:00
wangyu-
ebdb08873a Update README.md 2017-08-11 01:54:39 -07:00
wangyu-
46b0a00b3e Update README.md 2017-08-11 01:53:03 -07:00
wangyu-
d1934dda4c Update README.md 2017-08-11 01:52:29 -07:00
wangyu-
81e599e84c Update README.zh-cn.md 2017-08-11 01:50:25 -07:00
wangyu-
fadf5a25c2 Update README.zh-cn.md 2017-08-11 01:49:56 -07:00
wangyu-
9f25a61dad Update README.md 2017-08-11 01:47:20 -07:00
wangyu-
165dc193f0 Update README.md 2017-08-11 01:45:53 -07:00
wangyu-
e732ce2a8a Update README.md 2017-08-11 01:33:20 -07:00
wangyu-
d7cae0be18 Update README.md 2017-08-11 01:32:55 -07:00
wangyu
c1b8eb23a2 english build_guide 2017-08-11 16:30:22 +08:00
wangyu
1bbe19cdee Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-11 16:17:43 +08:00
wangyu
b16b37c879 fixed cmake 2017-08-11 16:17:26 +08:00
wangyu-
9479c95510 Update README.md 2017-08-10 23:49:55 -07:00
wangyu-
90b1897d4a Update README.md 2017-08-10 23:49:24 -07:00
wangyu-
3fa1a99046 Update README.zh-cn.md 2017-08-10 23:47:36 -07:00
wangyu-
eb59012b7b Update README.md 2017-08-10 23:31:42 -07:00
wangyu-
1a2cd767c0 Update README.zh-cn.md 2017-08-10 23:06:34 -07:00
wangyu-
8f04c82788 Update README.md 2017-08-10 22:53:01 -07:00
wangyu-
1b9f2a1e0e Update README.md 2017-08-10 22:51:50 -07:00
wangyu-
7592729abc Update README.md 2017-08-10 22:42:00 -07:00
wangyu
e890a6344c reverted extern c syntax,fixed a makefile problem 2017-08-11 12:25:04 +08:00
wangyu-
bc6358aa0a Merge pull request #3 from BroncoTc/master
merged pull request "add cmake support and fix compile errors“
2017-08-11 11:39:05 +08:00
broncotc
ed6416a30d add cmake support and fix compile errors 2017-08-11 10:45:40 +08:00
wangyu-
9378cee8d1 Update kcptun_step_by_step.md 2017-08-10 08:46:05 -07:00
wangyu-
0b3fb41f6f Update kcptun_step_by_step.md 2017-08-10 08:45:45 -07:00
wangyu-
41489af1d1 Update build_guide.zh-cn.md 2017-08-10 07:15:10 -07:00
wangyu
3a1bacc11e Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-10 22:08:18 +08:00
wangyu-
06d7638c5f Update README.zh-cn.md 2017-08-10 07:08:21 -07:00
wangyu
380971fe2b modified makefile 2017-08-10 22:08:09 +08:00
wangyu-
709258b260 Update build_guide.zh-cn.md 2017-08-10 07:04:45 -07:00
wangyu-
c3a8305e49 Update build_guide.zh-cn.md 2017-08-10 07:03:57 -07:00
wangyu-
5c08d65d91 Update build_guide.zh-cn.md 2017-08-10 07:03:38 -07:00
wangyu-
6f9ab92c1d Create build_guide.zh-cn.md 2017-08-10 06:20:51 -07:00
wangyu-
2f57fa6670 Update openvpn_guide.md 2017-08-10 05:39:06 -07:00
wangyu-
d104074328 Update README.zh-cn.md 2017-08-10 03:21:34 -07:00
wangyu-
7c280ab335 Update README.md 2017-08-10 03:20:35 -07:00
wangyu-
eb8567b693 Update README.zh-cn.md 2017-08-10 00:05:47 -07:00
wangyu-
fec382ebab Update README.zh-cn.md 2017-08-09 23:46:03 -07:00
wangyu-
4d319f54ff Update README.zh-cn.md 2017-08-09 23:44:41 -07:00
wangyu-
a58618c73c Update README.zh-cn.md 2017-08-09 23:39:53 -07:00
wangyu-
456da000f4 Update README.zh-cn.md 2017-08-09 23:37:30 -07:00
wangyu-
91e229616c Update README.md 2017-08-09 20:49:44 -07:00
16 changed files with 273 additions and 65 deletions

19
CMakeLists.txt Normal file
View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.7)
project(udp2raw_tunnel)
set(CMAKE_CXX_STANDARD 11)
set_source_files_properties(lib/aes.c lib/md5.c PROPERTIES LANGUAGE CXX )
set(SOURCE_FILES
lib/aes.c
lib/md5.c
common.cpp
encrypt.cpp
log.cpp
main.cpp
network.cpp
)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -static")
#set(CMAKE_LINK_LIBRARY_FLAG "-lrt")
add_executable(udp2raw_tunnel ${SOURCE_FILES})
target_link_libraries(udp2raw_tunnel rt)

114
README.md
View File

@@ -1,45 +1,70 @@
# Udp2raw-tunnel # Udp2raw-tunnel
![image0](images/image0.PNG) ![image0](images/image0.PNG)
An Encrpyted,Anti-Replay,Multiplexed Udp Tunnel,tunnels udp traffic through raw socket An encrpyted, anti-replay, multiplexing UDP tunnel which tunnels UDP traffic with fake TCP or ICMP header using raw socket. Also acts as a connection stablizer.
[简体中文](/doc/README.zh-cn.md) [简体中文](/doc/README.zh-cn.md)
### Send/Recv Udp Packet as Raw Packet with TCP header,ICMP header # Features
Which can help you bypass udp blocking or udp QOS or just poorly supported udp NAT behavior by some ISP. Raw packet with UDP header is also supported,in this way you can just make use of the encrpyting and anti-replay feature. ### Send / Receive UDP Packet with fake headers
### Encrpytion and Anti-Replay Fake headers help you bypass UDP blocking, UDP QOS or improper UDP NAT behavior on some ISPs. Raw packets with UDP headers are also supported, in this mode you can just use the encrpyting,anti-replay and connection-stablize feature.
encrypt your traffic with aes128cbc,protects data integrity by md5 or crc32,protect replay attack with an anti-replay window smiliar to ipsec/openvpn.
### Simulated TCP Handshake ### Simulate TCP Handshake
simulated 3-way handshake,simluated seq ack_seq. Simluated tcp options:MSS,sackOk,TS,TS_ack,wscale. Provides real-time delivery ,no tcp over tcp problem when using openvpn. Simulates the 3-way handshake, along with seq and ack_seq. TCP options MSS, sackOk, TS, TS_ack, wscale are also simulated. Real-time delivery guaranteed, no TCP over TCP problem when using OpenVPN.
### Connnection Failure Dectection & Recover
Conection failure detection by hearbeat. After hearbeat timeouts,client will auto change port and re-connect.if re-connection is successful,the previous connection will be recovered,and all existed udp conversations will stay vaild. ### Encrpytion, Anti-Replay, Anti-MITM
* Encrypt your traffic with AES-128-CBC.
* Protect data integrity by MD5 or CRC32.
* Defense replay attack with an anti-replay window, smiliar to IPSec and OpenVPN.
* Authenticate mutually, no more MITM attacks.
### Failure Dectection & Stablization (Connection Recovery)
Conection failures are detected by heartbeats. If timed-out, the client will automatically change the port number and reconnect. If reconnection is successful, the previous connection will be recovered, and all existing UDP conversations will stay vaild.
For example, if you use UDP2RAW + OpenVPN, OpenVPN won't lose connection after any reconnect, **even if the network cable is re-plugged or the WiFi access point is changed**.
### Other Features ### Other Features
Multiplexing ,one client supports multi udp connections,all of those traffic will share one raw connection * **Multiplexing** One client can handle multiple UDP connections, all of which share the same raw connection.
Multiple Clients Support,one server supports multiple clients. * **Multiple Clients** One server can have multiple clients.
NAT Supported,all 3 modes work in NAT environment * **NAT Support** All of the 3 modes work in NAT-ed environments.
OpenVZ Supported,tested on bandwagonhost * **OpenVZ Support** Tested on BandwagonHost.
* **OpenWRT Support** No dependencies, easy to build. Binary for ar71xx are included in release.
### Keywords
* UDP QoS Bypass
* UDP Blocking Bypass
* OpenVPN TCP over TCP problem
* OpenVPN over ICMP
* UDP to ICMP tunnel
* UDP to TCP tunnel
* UDP over ICMP
* UDP over TCP
Openwrt Supported,no dependence package,easy to compile,ar71xx binary included in release.
### Key Words
bypass udp qos,bypass udp blocking,openvpn tcp over tcp problem,openvpn over icmp,udp to icmp tunnel,udp to tcp tunnel,udp via icmp,udp via tcp
# Getting Started # Getting Started
### Prerequisites ### Prerequisites
linux host,root access. if you want to use it on window,you can use VMware in bridged mode. A Linux host (including desktop Linux, OpenWRT router, or Raspberry PI) with root access.
If you want to use it on MICRO$OFT Windows, you can use VMware or Hyper-V (both bridged mode and NAT mode are supported).
### Installing ### Installing
download binary release from https://github.com/wangyu-/udp2raw-tunnel/releases Download binary release from https://github.com/wangyu-/udp2raw-tunnel/releases
### Running ### Running
assume your udp is blocked or being QOS-ed or just poorly supported.assume your server ip is 44.55.66.77, you have a service listening on udp port 7777. Assume your UDP is blocked or being QOS-ed or just poorly supported. Assume your server ip is 44.55.66.77, you have a service listening on udp port 7777.
```
run at client side: ```bash
# Run at client side
./udp2raw_amd64 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -a -k "passwd" --raw-mode faketcp ./udp2raw_amd64 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -a -k "passwd" --raw-mode faketcp
run at server side: # Run at server side:
./udp2raw_amd64 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -a -k "passwd" --raw-mode faketcp ./udp2raw_amd64 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -a -k "passwd" --raw-mode faketcp
``` ```
Now,your client and server established a tunnel thorough tcp port 4096. Connecting to udp port 3333 at client side is equivalent with connecting to port 7777 at server side. No udp traffic will be exposed to outside.
Now,an encrypted raw tunnel has been established between client and server through TCP port 4096. Connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side. No UDP traffic will be exposed.
# Advanced Topic # Advanced Topic
### Usage ### Usage
``` ```
@@ -77,25 +102,30 @@ other options:
2:increase randomly, about every 3 packets (default) 2:increase randomly, about every 3 packets (default)
-h,--help print this help message -h,--help print this help message
``` ```
### iptables rule
this programs sends packet via raw socket.In faketcp mode,Linux Kernel TCP packet processing has to be blocked by a iptables rule on both sides,otherwise Kernel will automatically send RST for unrecongized TCP packet and you will sustain from stability/peformance problem.You can use -a option to let the program automatically add/del iptables rule on start/exit.You can also use the -g option to generate iptables rule and add it manually. ### IPTABLES rule
### cipher-mode and auth-mode This program sends packets via raw socket. In FakeTCP mode, Linux kernel TCP packet processing has to be blocked by a iptables rule on both sides, otherwise the kernel will automatically send RST for an unrecongized TCP packet and you will sustain from stability / peformance problems. You can use `-a` option to let the program automatically add / delete iptables rule on start / exit. You can also use the -g option to generate iptables rule and add it manually.
Its suggested to use aes128cbc + md5 to obtain maxmized security.If you want to run the program on a router,you can try xor+simple,it can fool Packet Inspection by firewalls most time, but it cant protect you from serious attackers. Mode none is only for debug,its not suggest to set cipher-mode or auth-mode to none.
### `cipher-mode` and `auth-mode`
It is suggested to use AES-128-CBC + MD5 to obtain maximum security. If you want to run the program on a router, you can try XOR + simple, which can fool packet inspection by firewalls the most of time, but it cannot protect you from serious attacks. Mode none is only for debugging purpose. It is not recommended to set the cipher-mode or auth-mode to none.
### seq-mode ### seq-mode
the faketcp mode doest not behave 100% like a real tcp connection.ISP may be able to distinguish the simulated tcp traffic from real tcp traffic(though its costly). seq-mode can help you changed the seq increase behavior a bit. If you experienced problems,try to change the value. The FakeTCP mode does not behave 100% like a real tcp connection. ISPs may be able to distinguish the simulated tcp traffic from the real TCP traffic (though it's costly). seq-mode can help you change the seq increase behavior slightly. If you experience any problems, try to change the value.
# Peformance Test # Peformance Test
#### test method: #### Test method:
iperf3 tcp via openvpn + udp2raw iperf3 TCP via OpenVPN + udp2raw
(iperf3 udp mode is not used bc of bug mentioned in this issue: https://github.com/esnet/iperf/issues/296 ,instead,we turn iperf3 's tcp traffic into udp by using openvpn,to test udp2raw 's peformance. Read [Application](https://github.com/wangyu-/udp2raw-tunnel#application) for detail ) (iperf3 UDP mode is not used because of a bug mentioned in this issue: https://github.com/esnet/iperf/issues/296 . Instead, we package the TCP traffic into UDP by OpenVPN to test the performance. Read [Application](https://github.com/wangyu-/udp2raw-tunnel#application) for details.
#### iperf3 command: #### iperf3 command:
``` ```
iperf3 -c 10.222.2.1 -P40 iperf3 -c 10.222.2.1 -P40
iperf3 -c 10.222.2.1 -P40 -R iperf3 -c 10.222.2.1 -P40 -R
``` ```
#### client host #### Environments
vultr $2.5/monthly plan(single core 2.4ghz cpu,512m ram,location:Tokyo,Japan), * **Client** Vultr $2.5/monthly plan (single core 2.4GHz cpu, 512MB RAM, Tokyo, Japan)
#### server host * **Server** BandwagonHost $3.99/annually plan (single core 2.0GHz cpu, 128MB RAM, Los Angeles, USA)
bandwagonhost $3.99/annually(single core 2.0ghz cpu,128m ram,location:Los Angeles,USA)
### Test1 ### Test1
raw_mode: faketcp cipher_mode: xor  auth_mode: simple raw_mode: faketcp cipher_mode: xor  auth_mode: simple
@@ -120,12 +150,15 @@ raw_mode: faketcp cipher_mode: aes128cbc  auth_mode: md5
3. openvpn over icmp also becomes a choice 3. openvpn over icmp also becomes a choice
more details at [openvpn+udp2raw_guide](/doc/openvpn_guide.md) more details at [openvpn+udp2raw_guide](/doc/openvpn_guide.md)
### tunneling kcptun ### speed-up tcp connection via raw traffic by using udp2raw+kcptun
make kcptun support tcp mode. kcptun is a tcp connection speed-up program,it speeds-up tcp connection by using kcp protocol on-top of udp.by using udp2raw,you can use kcptun while udp is QoSed or blocked.
(kcptun, https://github.com/xtaci/kcptun) (kcptun, https://github.com/xtaci/kcptun)
### tunneling finalspeed ### speed-up tcp connection via raw traffic by using udp2raw+finalspeed
finalspeed 's tcp mode doesnt work on openvz VPS.you can use finalspeed 's udp mode,and tunnel udp through tcp with this tunnel. finalspeed is a tcp connection speed-up program similiar to kcptun,it speeds-up tcp connection by using kcp protocol on-top of udp or tcp.but its tcp mode doesnt support openvz,you can bypass this problem if you use udp2raw+finalspeed together,and icmp mode also becomes avaliable.
# How to build
read [build_guide](/doc/build_guide.md)
# Related work # Related work
### kcptun-raw ### kcptun-raw
@@ -144,4 +177,3 @@ https://github.com/linhua55/some_kcptun_tools/tree/master/relayRawSocket
Transparently tunnel your IP traffic through ICMP echo and reply packets. Transparently tunnel your IP traffic through ICMP echo and reply packets.
https://github.com/DhavalKapil/icmptunnel https://github.com/DhavalKapil/icmptunnel

View File

@@ -71,7 +71,7 @@ const u32_t client_retry_interval=1000;
const u32_t server_handshake_timeout=10000;// this should be much longer than clients. client retry initially ,server retry passtively const u32_t server_handshake_timeout=10000;// this should be much longer than clients. client retry initially ,server retry passtively
const int conv_clear_ratio=10; //conv grabage collecter check 1/10 of all conv one time const int conv_clear_ratio=10; //conv grabage collecter check 1/10 of all conv one time
const int conn_clear_ratio=10; const int conn_clear_ratio=30;
const int conv_clear_min=5; const int conv_clear_min=5;
const int conn_clear_min=1; const int conn_clear_min=1;

View File

@@ -1,6 +1,6 @@
Udp2raw-tunnel Udp2raw-tunnel
![image2](/images/image2.PNG) ![image2](/images/image2.PNG)
加密、防重放攻击的、信道复用的udp tunnel利用raw socket中转udp流量 加密、防重放攻击的、信道复用的udp tunnel利用raw socket中转udp流量.同时有心跳保活,且在断线重连后保持上层连接不掉线的功能。
[English](/README.md) [English](/README.md)
@@ -11,25 +11,24 @@ Udp2raw-tunnel
如果你需要加速跨国网游、网页浏览解决方案在另一个repo 如果你需要加速跨国网游、网页浏览解决方案在另一个repo
https://github.com/wangyu-/UDPspeeder https://github.com/wangyu-/UDPspeeder
# 功能特性
### 把udp流量伪装成tcp /icmp ### 把udp流量伪装成tcp /icmp
用raw socket给udp包加上tcp/icmp包头可以突破udp流量限制或Udp QOS。或者在udp nat有问题的环境下提升稳定性。  另外也支持用raw 发udp包这样流量不会被伪装只会被加密。 用raw socket给udp包加上tcp/icmp包头可以突破udp流量限制或Udp QOS。或者在udp nat有问题的环境下提升稳定性。  另外也支持用raw 发udp包这样流量不会被伪装只会被加密。
### 加密 防重放攻击
用aes128cbc加密md5/crc32做数据完整校验。用类似ipsec/openvpn的 replay windows机制来防止重放攻击。
设计目标是即使攻击者可以监听到tunnel的所有包可以选择性丢弃tunnel的任意包可以重放任意包攻击者也没办法获得tunnel承载的任何数据也没办法向tunnel的数据流中通过包构造/包重放插入任何数据。
### 模拟TCP3次握手 ### 模拟TCP3次握手
模拟TCP3次握手模拟seq ack过程。另外还模拟了一些tcp optionMSS,sackOk,TS,TS_ack,wscale用来使流量看起来更像是由普通的linux tcp协议栈发送的。 模拟TCP3次握手模拟seq ack过程。另外还模拟了一些tcp optionMSS,sackOk,TS,TS_ack,wscale用来使流量看起来更像是由普通的linux tcp协议栈发送的。
### 连接保持,连接快速恢复,单向链路失效检测 ### 心跳保活、自动重连,连接快速恢复,单向链路失效检测
心跳机制检查连接是否中断一旦心跳超时。client会立即换raw socket的端口重连重连成功后会恢复之前中断的连接。虽然raw端的端口变了但是udp端的所有连接都会继续有效。udp这边感觉不到raw端的重连只会感觉到短暂断流,这跟普通的短暂丢包是类似的,不会导致上层应用重连。 心跳保活、自动重连udp2raw重连可以恢复上次的连接重连后上层连接继续有效底层掉线上层不掉线。有效解决上层连接断开的问题。 (功能借鉴自[kcptun-raw](https://github.com/Chion82/kcptun-raw)**就算你拔掉网线重插或者重新拨号获得新ip上层应用也不会断线**
Client能用单倍的超时时间检测到单向链路的失效不管是上行还是下行只要有一失效就能被client检测到。重连只需要client发起就可以立即被server处理不需要等到server端的连接超时后。 Client能用单倍的超时时间检测到单向链路的失效不管是上行还是下行只要有一个方向失效就能被client检测到。重连只需要client发起就可以立即被server处理不需要等到server端的连接超时后。
对于有大量client的情况对于不同client,server发送的心跳是错开时间发送的不会因为短时间发送大量的心跳而造成拥塞和延迟抖动。 对于有大量client的情况对于不同client,server发送的心跳是错开时间发送的不会因为短时间发送大量的心跳而造成拥塞和延迟抖动。
### 加密 防重放攻击 防中间人攻击
用aes128cbc加密md5/crc32做数据完整校验。用类似ipsec/openvpn的 replay windows机制来防止重放攻击。
设计目标是即使攻击者可以监听到tunnel的所有包可以选择性丢弃tunnel的任意包可以重放任意包攻击者也没办法获得tunnel承载的任何数据也没办法向tunnel的数据流中通过包构造/包重放插入任何数据。client和server互相认证对方无法被中间人攻击。
### 其他特性 ### 其他特性
信道复用client的udp端支持多个连接。 信道复用client的udp端支持多个连接。
@@ -40,9 +39,9 @@ NAT 穿透 tcp icmp udp模式都支持nat穿透。
支持Openvz配合finalspeed使用可以在openvz上用tcp模式的finalspeed 支持Openvz配合finalspeed使用可以在openvz上用tcp模式的finalspeed
支持Openwrt,没有编译依赖容易编译到任何平台上。release中提供了ar71xx版本的binary 支持Openwrt没有编译依赖容易编译到任何平台上。release中提供了ar71xx版本的binary
epoll纯异步高并发除了回收过期连接外所有操作的时间复杂度都跟连接数无关。回收过期连接的操做也是一点一点进行的不会因为消耗太多cpu时间造成延迟抖动。 epoll纯异步高并发除了回收过期连接外所有操作的时间复杂度都跟连接数无关。回收过期连接的操做也是柔和进行的不会因为消耗太多cpu时间造成延迟抖动。
### 关键词 ### 关键词
突破udp qos,突破udp屏蔽openvpn tcp over tcp problem,openvpn over icmp,udp to icmp tunnel,udp to tcp tunnel,udp via icmp,udp via tcp 突破udp qos,突破udp屏蔽openvpn tcp over tcp problem,openvpn over icmp,udp to icmp tunnel,udp to tcp tunnel,udp via icmp,udp via tcp
@@ -50,7 +49,7 @@ epoll纯异步高并发除了回收过期连接外所有操作的时间
# 简明操作说明 # 简明操作说明
### 环境要求 ### 环境要求
Linux主机有root权限。主机上最好安装了iptables命令(apt/yum很容易安装)。在windows和mac上可以开虚拟机桥接模式测试可用 Linux主机有root权限。主机上最好安装了iptables命令(apt/yum很容易安装)。在windows和mac上可以开虚拟机桥接模式和NAT模式经测试可用)。
### 安装 ### 安装
下载编译好的二进制文件,解压到任意目录。 下载编译好的二进制文件,解压到任意目录。
@@ -110,7 +109,7 @@ other options:
-h,--help print this help message -h,--help print this help message
``` ```
### iptables 规则 ### iptables 规则
用raw收发tcp包本质上绕过了linux内核的tcp协议栈。linux碰到raw socket发来的包会不认识如果一直收到不认识的包会回复大量RST造成不稳定或性能问题。所以强烈建议添加iptables规则屏蔽Linux内核的对指定端口的处理。用-a选项udp2raw会在启动的时候自动帮你加上Iptables规则退出的时候再自动删掉。如果你不信任-a选项的可靠性,可以用-g选项来生成相应的Ip规则再自己手动添加。 用raw收发tcp包本质上绕过了linux内核的tcp协议栈。linux碰到raw socket发来的包会不认识如果一直收到不认识的包会回复大量RST造成不稳定或性能问题。所以强烈建议添加iptables规则屏蔽Linux内核的对指定端口的处理。用-a选项udp2raw会在启动的时候自动帮你加上Iptables规则退出的时候再自动删掉。如果长期使用,可以用-g选项来生成相应的Iptables规则再自己手动添加这样规则不会在udp2raw退出时被删掉可以避免停掉udp2raw后内核向对端回复RST
用raw收发udp包也类似只是内核回复的是icmp unreachable。而用raw 收发icmp内核会自动回复icmp echo。都需要相应的iptables规则。 用raw收发udp包也类似只是内核回复的是icmp unreachable。而用raw 收发icmp内核会自动回复icmp echo。都需要相应的iptables规则。
### cipher-mode 和 auth-mode ### cipher-mode 和 auth-mode
@@ -154,6 +153,8 @@ raw_mode: faketcp cipher_mode: aes128cbc  auth_mode: md5
[udp2raw+kcptun step_by_step教程](kcptun_step_by_step.md) [udp2raw+kcptun step_by_step教程](kcptun_step_by_step.md)
### 中转 finalspeed ### 中转 finalspeed
[udp2raw+finalspeed step_by_step教程](finalspeed_step_by_step.md) [udp2raw+finalspeed step_by_step教程](finalspeed_step_by_step.md)
# 如何自己编译
[编译教程](build_guide.zh-cn.md)
# 相关repo # 相关repo
### kcptun-raw ### kcptun-raw
this project was inspired by kcptun-raw,which modified kcptun to support tcp mode. this project was inspired by kcptun-raw,which modified kcptun to support tcp mode.

74
doc/build_guide.md Normal file
View File

@@ -0,0 +1,74 @@
# udp2raw build guide
the guide on how to build udp2raw to you own platform
## linux platform which supports local compile
such as PC,raspberry pi
##### install git
run on debian/ubuntun
```
sudo apt-get install git
```
run on redhat/centos:
```
sudo yum install git
```
##### clone git code
run in any dir
```
git clone https://github.com/wangyu-/udp2raw-tunnel.git
cd udp2raw-tunnel
```
##### install compile tool
run on debian/ubuntun
```
sudo apt-get install build-essential
```
run on redhat/centos:
```
sudo yum groupinstall 'Development Tools'
```
run 'make'compilation done. the udp2raw file is the just compiled binary
## platform which needs cross-compile
such as openwrt router,run following instructions on your PC
##### install git
run on debian/ubuntun
```
sudo apt-get install git
```
run on redhat/centos:
```
sudo yum install git
```
##### download cross compile tool chain
find it on downloads.openwrt.org according to your openwrt version and cpu model.
for example, my tplink wdr4310 runs chaos_calmer 15.05,its with ar71xx cpudownload the following package.
```
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
```
unzip it to any dir,such as /home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2
cd into staging_dir toolchain-xxxxx bin .find the soft link with g++ suffix. in my case ,its mips-openwrt-linux-g++ ,check for its full path:
```
/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
##### compile
modify first line of makefile to:
```
cc_cross=/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
run 'make cross'the just generated udp2raw_cross is the binary,compile done. copy it to your router to run.

72
doc/build_guide.zh-cn.md Normal file
View File

@@ -0,0 +1,72 @@
# udp2raw编译方法
本文演示怎么把udp2raw编译到自己所需的平台。
## 可以本地编译的linux平台
比如电脑、树莓派
##### 首先安装git
debian/ubuntun执行
```
sudo apt-get install git
```
redhat/centos执行:
```
sudo yum install git
```
##### 用git把源码clone至本地
在任意目录执行:
```
git clone https://github.com/wangyu-/udp2raw-tunnel.git
cd udp2raw-tunnel
```
##### 安装g++ make 等工具
debian/ubuntun执行
```
sudo apt-get install build-essential
```
redhat/centos执行:
```
sudo yum groupinstall 'Development Tools'
```
然后运行make编译完成。 生成的udp2raw就是编译好的bianry。
## 需要交叉编译的平台
比如各种openwrt路由器
##### 首先安装git
debian/ubuntun执行
```
sudo apt-get install git
```
redhat/centos执行:
```
sudo yum install git
```
##### 下载安装交叉编译工具包
去downloads.openwrt.org上找到自己的openwrt版本和cpu型号对应的SDK。通常openwrt版本号不一样也问题不大最主要是cpu型号。
比如我的tplink wdr4310运行的是chaos_calmer 15.05,ar71xx cpu应该下载这个包
```
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
```
解压到本地任意目录,比如:/home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2
让后依次进入staging_dir toolchain-xxxxx bin 目录找到后缀是g++的软链,比如我的是mips-openwrt-linux-g++ ,记下这个文件的完整路径:
```
/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
##### 编译
把makefile的第一行 cross_cc=后面的内容改成你刚才记下的完整路径:
```
cc_cross=/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
执行make cross目录下生成udp2raw_cross文件。编译完成。

View File

@@ -1,7 +1,7 @@
# udp2raw+kcptun 加速tcp流量 Step by Step 教程 # udp2raw+kcptun 加速tcp流量 Step by Step 教程
![image](kcptun_step_by_step/Capture00.PNG) ![image](kcptun_step_by_step/Capture00.PNG)
本教程会一步一步演示用udp2raw+kcptun加速SSH流量的过程。加速任何其他tcp流量也一样。 本教程会一步一步演示用udp2raw+kcptun加速SSH流量的过程。加速任何其他tcp流量也一样包括ss本文避免涉及科学上网所以演示ssh
### 环境要求 ### 环境要求
两边的主机都是linux有root权限。 可以是openwrt路由器或树莓派windows上桥接模式的虚拟机也可用 两边的主机都是linux有root权限。 可以是openwrt路由器或树莓派windows上桥接模式的虚拟机也可用

View File

@@ -18,6 +18,9 @@ assume server ip is 45.66.77.88
#### client side config #### client side config
``` ```
client
dev tun100
proto udp
remote 127.0.0.1 3333 remote 127.0.0.1 3333
resolv-retry infinite resolv-retry infinite

View File

@@ -1,11 +1,11 @@
#include <lib/aes.h> #include "lib/aes.h"
#include <lib/md5.h> #include "lib/md5.h"
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <encrypt.h> #include "encrypt.h"
#include <common.h> #include "common.h"
#include "log.h" #include "log.h"
//static uint64_t seq=1; //static uint64_t seq=1;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 37 KiB

1
images/speedtest/111 Normal file
View File

@@ -0,0 +1 @@

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -1,4 +1,4 @@
#include <log.h> #include "log.h"
int log_level=log_info; int log_level=log_info;

2
log.h
View File

@@ -44,7 +44,7 @@
#include <sys/timerfd.h> #include <sys/timerfd.h>
#include <set> #include <set>
#include <encrypt.h> #include "encrypt.h"
#include <inttypes.h> #include <inttypes.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>

View File

@@ -1,10 +1,10 @@
ccmips=mips-openwrt-linux-g++ cc_cross=/home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
FLAGS=-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter FLAGS=-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
FLAGS2= -O3 FLAGS2= -O3
all: all:
sudo killall udp2raw||true sudo killall udp2raw||true
sleep 0.2 sleep 0.2
g++ main.cpp -o udp2raw -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2} gcc main.cpp -o udp2raw -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2}
# ${ccmips} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} ${FLAGS2} # ${ccmips} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} ${FLAGS2}
fast: fast:
sudo killall udp2raw||true sudo killall udp2raw||true
@@ -14,10 +14,16 @@ fast:
debug: debug:
g++ main.cpp -o udp2raw -static -ggdb -I. -Ilib lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} -Wformat-nonliteral -D MY_DEBUG g++ main.cpp -o udp2raw -static -ggdb -I. -Ilib lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} -Wformat-nonliteral -D MY_DEBUG
cross:
${cc_cross} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} ${FLAGS2}
cross2:
${cc_cross} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} -static -lgcc_eh -O3
cross3:
${cc_cross} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} -static -lgcc_eh
release: release:
g++ main.cpp -o udp2raw_amd64 -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2} g++ main.cpp -o udp2raw_amd64 -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2}
g++ main.cpp -o udp2raw_x86 -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2} -m32 g++ main.cpp -o udp2raw_x86 -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2} -m32
${ccmips} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} ${FLAGS2} ${cc_cross} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} -static -lgcc_eh -O3
tar -zcvf udp2raw_binaries.tar.gz udp2raw_amd64 udp2raw_x86 udp2raw_ar71xx tar -zcvf udp2raw_binaries.tar.gz udp2raw_amd64 udp2raw_x86 udp2raw_ar71xx