Compare commits
21 Commits
20180220.1
...
20171103.0
Author | SHA1 | Date | |
---|---|---|---|
|
4c92c29948 | ||
|
cadb142455 | ||
|
fcb418f5ea | ||
|
63eb7f1f7f | ||
|
66b2bb87c5 | ||
|
6b27f8624d | ||
|
ce7b89f6b6 | ||
|
a0bfa86699 | ||
|
e332cabfed | ||
|
9798bf496a | ||
|
7aa4b8745e | ||
|
ea6a41ebb3 | ||
|
77ba1161f5 | ||
|
7858c4d832 | ||
|
71152ffbe3 | ||
|
b06e979dc8 | ||
|
5300f98b0a | ||
|
063d133463 | ||
|
4c88df9c0e | ||
|
52cb20ec20 | ||
|
7aede9edd0 |
@@ -1,6 +0,0 @@
|
|||||||
For English speaking user:
|
|
||||||
https://github.com/wangyu-/UDPspeeder/wiki/Issue-Guide
|
|
||||||
|
|
||||||
中文用户请看:
|
|
||||||
https://github.com/wangyu-/UDPspeeder/wiki/发Issue前请看
|
|
||||||
(否则Issue可能被忽略,或被直接关掉)
|
|
15
README.md
@@ -3,19 +3,20 @@
|
|||||||
|
|
||||||
A Tunnel which turns UDP Traffic into Encrypted FakeTCP/UDP/ICMP Traffic by using Raw Socket, helps you Bypass UDP FireWalls(or Unstable UDP Environment). It can defend Replay-Attack and supports Multiplexing. It also acts as a Connection Stabilizer.
|
A Tunnel which turns UDP Traffic into Encrypted FakeTCP/UDP/ICMP Traffic by using Raw Socket, helps you Bypass UDP FireWalls(or Unstable UDP Environment). It can defend Replay-Attack and supports Multiplexing. It also acts as a Connection Stabilizer.
|
||||||
|
|
||||||
|
When used alone,udp2raw tunnels only UDP traffic. Nevertheless,if you used udp2raw + any UDP-based VPN together,you can tunnel any traffic(include TCP/UDP/ICMP),currently OpenVPN/L2TP/ShadowVPN and [tinyFecVPN](https://github.com/wangyu-/tinyFecVPN) are confirmed to be supported。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
When used alone,udp2raw tunnels only UDP traffic. Nevertheless,if you used udp2raw + any UDP-based VPN together,you can tunnel any traffic(include TCP/UDP/ICMP),currently OpenVPN/L2TP/ShadowVPN and [tinyfecVPN](https://github.com/wangyu-/tinyfecVPN) are confirmed to be supported.
|
or
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[简体中文](/doc/README.zh-cn.md)(内容更丰富)
|
[简体中文](/doc/README.zh-cn.md)
|
||||||
|
|
||||||
# Support Platforms
|
# Support Platforms
|
||||||
Linux host (including desktop Linux,Android phone/tablet,OpenWRT router,or Raspberry PI) with root access.
|
Linux host (including desktop Linux,Android phone/tablet,OpenWRT router,or Raspberry PI) with root access.
|
||||||
|
|
||||||
For Windows and MacOS You can run udp2raw inside [this](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20171108.0/lede-17.01.2-x86_virtual_machine_image.zip) 7.5mb virtual machine image(make sure network adapter runs at bridged mode).
|
For Winodws/MacOS,the 4.4mb virtual image with udp2raw pre-installed has been released,you can load it with Vmware/VirtualBox.The virtual image has been set to auto obtain ip,udp2raw can be run imidiately after boot finished(make sure network mode of virtual machine has been set to bridged)(only udp2raw has to be run under virtual machine,all other programs runs under Windows/MacOS as usual).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
@@ -81,8 +82,6 @@ Assume your UDP is blocked or being QOS-ed or just poorly supported. Assume your
|
|||||||
# Run at client side
|
# 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
|
||||||
```
|
```
|
||||||
(The above commands need to be run as root. For better security, with some extra steps, you can run udp2raw as non-root. Check [this link](https://github.com/wangyu-/udp2raw-tunnel/wiki/run-udp2raw-as-non-root) for more info )
|
|
||||||
|
|
||||||
###### Server Output:
|
###### Server Output:
|
||||||

|

|
||||||
###### Client Output:
|
###### Client Output:
|
||||||
@@ -93,9 +92,9 @@ Now,an encrypted raw tunnel has been established between client and server throu
|
|||||||
### Note
|
### Note
|
||||||
To run on Android, check [Android_Guide](/doc/android_guide.md)
|
To run on Android, check [Android_Guide](/doc/android_guide.md)
|
||||||
|
|
||||||
If you have connection problems. Take a look at `--seq-mode` option.
|
If you have connection problems.Take a look at `--seq-mode` option.
|
||||||
|
|
||||||
|
|
||||||
|
You can run udp2raw with a non-root account(for better security).Take a look at [#26](https://github.com/wangyu-/udp2raw-tunnel/issues/26) for more info.
|
||||||
|
|
||||||
# Advanced Topic
|
# Advanced Topic
|
||||||
### Usage
|
### Usage
|
||||||
|
@@ -16,7 +16,7 @@ u64_t get_current_time()
|
|||||||
{
|
{
|
||||||
timespec tmp_time;
|
timespec tmp_time;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||||
return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
return tmp_time.tv_sec*1000+tmp_time.tv_nsec/(1000*1000l);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64_t pack_u64(u32_t a,u32_t b)
|
u64_t pack_u64(u32_t a,u32_t b)
|
||||||
|
2
common.h
@@ -85,7 +85,7 @@ struct ip_port_t
|
|||||||
|
|
||||||
typedef u64_t fd64_t;
|
typedef u64_t fd64_t;
|
||||||
|
|
||||||
const int max_data_len=1800;
|
const int max_data_len=1600;
|
||||||
const int buf_len=max_data_len+400;
|
const int buf_len=max_data_len+400;
|
||||||
|
|
||||||
u64_t get_current_time();
|
u64_t get_current_time();
|
||||||
|
@@ -711,17 +711,7 @@ int parse_safer(conn_info_t &conn_info,const char * input,int input_len,char &ty
|
|||||||
conn_info.oppsite_roller=roller;
|
conn_info.oppsite_roller=roller;
|
||||||
conn_info.last_oppsite_roller_time=get_current_time();
|
conn_info.last_oppsite_roller_time=get_current_time();
|
||||||
}
|
}
|
||||||
if(hb_mode==0)
|
conn_info.my_roller++;//increase on a successful recv
|
||||||
conn_info.my_roller++;//increase on a successful recv
|
|
||||||
else if(hb_mode==1)
|
|
||||||
{
|
|
||||||
if(type=='h')
|
|
||||||
conn_info.my_roller++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(0==1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(after_recv_raw0(conn_info.raw_info)!=0) return -1;
|
if(after_recv_raw0(conn_info.raw_info)!=0) return -1;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
# Udp2raw-tunnel
|
Udp2raw-tunnel
|
||||||

|

|
||||||
udp2raw tunnel,通过raw socket给UDP包加上TCP或ICMP header,进而绕过UDP屏蔽或QoS,或在UDP不稳定的环境下提升稳定性。可以有效防止在使用kcptun或者finalspeed的情况下udp端口被运营商限速。
|
udp2raw tunnel,通过raw socket给UDP包加上TCP或ICMP header,进而绕过UDP屏蔽或QoS,或在UDP不稳定的环境下提升稳定性。可以有效防止在使用kcptun或者finalspeed的情况下udp端口被运营商限速。
|
||||||
|
|
||||||
支持心跳保活、自动重连,重连后会恢复上次连接,在底层掉线的情况下可以保持上层不掉线。同时有加密、防重放攻击、信道复用的功能。
|
支持心跳保活、自动重连,重连后会恢复上次连接,在底层掉线的情况下可以保持上层不掉线。同时有加密、防重放攻击、信道复用的功能。
|
||||||
@@ -20,17 +20,8 @@ https://github.com/wangyu-/UDPspeeder
|
|||||||
# 支持的平台
|
# 支持的平台
|
||||||
Linux主机,有root权限。可以是PC、android手机/平板、openwrt路由器、树莓派。主机上最好安装了iptables命令(apt/yum很容易安装)。
|
Linux主机,有root权限。可以是PC、android手机/平板、openwrt路由器、树莓派。主机上最好安装了iptables命令(apt/yum很容易安装)。
|
||||||
|
|
||||||
Release中提供了`amd64`、`x86`、`arm`、`mips_be`、`mips_le`的预编译binary.
|
在windows和mac上预装了udp2raw的虚拟机镜像已发布,可以用Vmware或VirtualBox加载,容量4.4mb,已经配置好了自动获取网卡ip,开机即用,稳定,性能很好。
|
||||||
|
(udp2raw跑在虚拟机里,其他应用照常跑在windows上)(确保虚拟机网卡工作在桥接模式)(Vmware player 75mb,VirtualBox 118mb,很容易安装)。
|
||||||
##### 对于windows和mac用户:
|
|
||||||
|
|
||||||
在虚拟机中可以稳定使用(udp2raw跑在Linux里,其他应用照常跑在window里;确保虚拟机网卡工作在桥接模式)。可以使用[这个](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20171108.0/lede-17.01.2-x86_virtual_machine_image.zip)虚拟机镜像,大小只有7.5mb,免去在虚拟机里装系统的麻烦;虚拟机自带ssh server,可以scp拷贝文件,可以ssh进去,可以复制粘贴,root密码123456。
|
|
||||||
|
|
||||||
如果你的网络不允许桥接,也是有办法用的,具体方法请看wiki。
|
|
||||||
|
|
||||||
##### 对于ios和游戏主机用户:
|
|
||||||
|
|
||||||
可以把udp2raw运行在局域网的其他机器上。最好的办法是买个能刷OpenWrt/LEDE/梅林的路由器,把udp2raw运行在路由器上。
|
|
||||||
|
|
||||||
# 功能特性
|
# 功能特性
|
||||||
### 把udp流量伪装成tcp /icmp
|
### 把udp流量伪装成tcp /icmp
|
||||||
@@ -60,9 +51,9 @@ NAT 穿透 ,tcp icmp udp模式都支持nat穿透。
|
|||||||
|
|
||||||
支持Openvz,配合finalspeed使用,可以在openvz上用tcp模式的finalspeed
|
支持Openvz,配合finalspeed使用,可以在openvz上用tcp模式的finalspeed
|
||||||
|
|
||||||
支持Openwrt,没有编译依赖,容易编译到任何平台上。
|
支持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
|
||||||
@@ -79,13 +70,11 @@ https://github.com/wangyu-/udp2raw-tunnel/releases
|
|||||||
|
|
||||||
```
|
```
|
||||||
在server端运行:
|
在server端运行:
|
||||||
./udp2raw_amd64 -s -l0.0.0.0:4096 -r127.0.0.1:7777 -a -k "passwd" --raw-mode faketcp --cipher-mode xor
|
./udp2raw_amd64 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -a -k "passwd" --raw-mode faketcp
|
||||||
|
|
||||||
在client端运行:
|
在client端运行:
|
||||||
./udp2raw_amd64 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -a -k "passwd" --raw-mode faketcp --cipher-mode xor
|
./udp2raw_amd64 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -a -k "passwd" --raw-mode faketcp
|
||||||
```
|
```
|
||||||
(以上例子需要用root账号运行。 用非root运行udp2raw需要一些额外的步骤,具体方法请看 [这个](https://github.com/wangyu-/udp2raw-tunnel/wiki/run-udp2raw-as-non-root) 链接。用非root运行更安全)
|
|
||||||
|
|
||||||
###### Server端输出:
|
###### Server端输出:
|
||||||

|

|
||||||
###### Client端输出:
|
###### Client端输出:
|
||||||
@@ -98,14 +87,14 @@ https://github.com/wangyu-/udp2raw-tunnel/releases
|
|||||||
不论你用udp2raw来加速kcptun还是vpn,为了稳定使用,都需要设置合理的MTU(在kcptun/vpn里设置,而不是在udp2raw里),建议把MTU设置成1200。client和server端都要设置。
|
不论你用udp2raw来加速kcptun还是vpn,为了稳定使用,都需要设置合理的MTU(在kcptun/vpn里设置,而不是在udp2raw里),建议把MTU设置成1200。client和server端都要设置。
|
||||||
|
|
||||||
### 提醒
|
### 提醒
|
||||||
`--cipher-mode xor`表示仅使用简单的XOR加密,这样可以节省CPU占用,以免CPU成为速度瓶颈。如果你需要更强的加密,可以去掉此选项,使用默认的AES加密。加密相关的选项见后文的`--cipher-mode`和`--auth-mode`。
|
|
||||||
|
|
||||||
如果要在anroid上运行,请看[Android简明教程](/doc/android_guide.md)
|
如果要在anroid上运行,请看[Android简明教程](/doc/android_guide.md)
|
||||||
|
|
||||||
如果要在梅林固件的路由器上使用,添加`--lower-level auto` `--keep-rule`
|
如果要在梅林固件的路由器上使用,添加`--lower-level auto` `--keep-rule`
|
||||||
|
|
||||||
如果client和server无法连接,或者连接经常断开,请看一下`--seq-mode`的用法,尝试不同的seq-mode。
|
如果client和server无法连接,或者连接经常断开,请看一下`--seq-mode`的用法,尝试不同的seq-mode。
|
||||||
|
|
||||||
|
udp2raw可以用非root账号运行,这样更安全。具体方法见:[#26](https://github.com/wangyu-/udp2raw-tunnel/issues/26)
|
||||||
|
|
||||||
# 进阶操作说明
|
# 进阶操作说明
|
||||||
|
|
||||||
### 命令选项
|
### 命令选项
|
||||||
@@ -166,7 +155,7 @@ other options:
|
|||||||
|
|
||||||
用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`
|
||||||
如果要最大的安全性建议用aes128cbc+md5。如果要运行在路由器上,建议用xor+simple,可以节省CPU。但是注意xor+simple只能骗过防火墙的包检测,不能防止真正的攻击者。
|
如果要最大的安全性建议用aes128cbc+md5。如果要运行再路由器上,建议xor+simple。但是注意xor+simple只能骗过防火墙的包检测,不能防止真正的攻击者。
|
||||||
|
|
||||||
### `--seq-mode`
|
### `--seq-mode`
|
||||||
facktcp模式并没有模拟tcp的全部。所以理论上有办法把faketcp和真正的tcp流量区分开来(虽然大部分ISP不太可能做这种程度的包检测)。seq-mode可以改变一些seq ack的行为。如果遇到了连接问题,可以尝试更改。在我这边的移动线路用3种模式都没问题。
|
facktcp模式并没有模拟tcp的全部。所以理论上有办法把faketcp和真正的tcp流量区分开来(虽然大部分ISP不太可能做这种程度的包检测)。seq-mode可以改变一些seq ack的行为。如果遇到了连接问题,可以尝试更改。在我这边的移动线路用3种模式都没问题。
|
||||||
@@ -174,14 +163,14 @@ facktcp模式并没有模拟tcp的全部。所以理论上有办法把faketcp和
|
|||||||
### `--keep-rule`
|
### `--keep-rule`
|
||||||
定期主动检查iptables,如果udp2raw添加的iptables规则丢了,就重新添加。在一些iptables可能会被其他程序清空的情况下(比如梅林固件和openwrt的路由器)格外有用。
|
定期主动检查iptables,如果udp2raw添加的iptables规则丢了,就重新添加。在一些iptables可能会被其他程序清空的情况下(比如梅林固件和openwrt的路由器)格外有用。
|
||||||
|
|
||||||
|
### `--lower-level`
|
||||||
|
大部分udp2raw不能连通的情况都是设置了不兼容的iptables造成的。--lower-level选项允许绕过本地iptables。在一些iptables不好改动的情况下尤其有效(比如你用的是梅林固件,iptables全是固件自己生成的)。
|
||||||
|
|
||||||
### `--fifo`
|
### `--fifo`
|
||||||
指定一个fifo(named pipe)来向运行中的程序发送命令,例如`--fifo fifo.file`:
|
指定一个fifo(named pipe)来向运行中的程序发送命令,例如`--fifo fifo.file`:
|
||||||
|
|
||||||
在client端,可以用`echo reconnect >fifo.file`来强制client换端口重连(上层不断线).对Server,目前没有效果。
|
在client端,可以用`echo reconnect >fifo.file`来强制client换端口重连(上层不断线).对Server,目前没有效果。
|
||||||
|
|
||||||
### `--lower-level`
|
|
||||||
大部分udp2raw不能连通的情况都是设置了不兼容的iptables造成的。--lower-level选项允许绕过本地iptables。在一些iptables不好改动的情况下尤其有效(比如你用的是梅林固件,iptables全是固件自己生成的)。
|
|
||||||
|
|
||||||
##### 格式
|
##### 格式
|
||||||
`if_name#dest_mac_adress`,例如 `eth0#00:23:45:67:89:b9` 。`eth0`换成你的出口网卡名。`00:23:45:67:89:b9`换成网关的mac地址(如果client和server在同一个局域网内,可能不需要网关,这时候直接用对方主机的mac地址,这个属于罕见的应用场景,可以忽略)。
|
`if_name#dest_mac_adress`,例如 `eth0#00:23:45:67:89:b9` 。`eth0`换成你的出口网卡名。`00:23:45:67:89:b9`换成网关的mac地址(如果client和server在同一个局域网内,可能不需要网关,这时候直接用对方主机的mac地址,这个属于罕见的应用场景,可以忽略)。
|
||||||
|
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
# udp2raw build guide
|
# udp2raw build guide
|
||||||
|
|
||||||
the guide on how to build udp2raw
|
the guide on how to build udp2raw to you own platform
|
||||||
|
|
||||||
## Build udp2raw for a specific platform
|
## linux platform which supports local compile
|
||||||
|
|
||||||
### linux platform which supports local compile
|
|
||||||
such as PC,raspberry pi
|
such as PC,raspberry pi
|
||||||
|
|
||||||
##### install git
|
##### install git
|
||||||
@@ -38,7 +36,7 @@ sudo yum groupinstall 'Development Tools'
|
|||||||
|
|
||||||
run 'make',compilation done. the udp2raw file is the just compiled binary
|
run 'make',compilation done. the udp2raw file is the just compiled binary
|
||||||
|
|
||||||
### platform which needs cross-compile
|
## platform which needs cross-compile
|
||||||
such as openwrt router,run following instructions on your PC
|
such as openwrt router,run following instructions on your PC
|
||||||
|
|
||||||
##### install git
|
##### install git
|
||||||
@@ -76,17 +74,3 @@ cc_cross=/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uC
|
|||||||
run `make cross`,the just generated `udp2raw_cross` is the binary,compile done. copy it to your router to run.
|
run `make cross`,the just generated `udp2raw_cross` is the binary,compile done. copy it to your router to run.
|
||||||
|
|
||||||
`make cross` generates non-static binary. If you have any problem on running it,try to compile a static binary by using `make cross2` or `make cross3`.If your toolchain supports static compiling, usually one of them will succeed. The generated file is still named `udp2raw_cross`.
|
`make cross` generates non-static binary. If you have any problem on running it,try to compile a static binary by using `make cross2` or `make cross3`.If your toolchain supports static compiling, usually one of them will succeed. The generated file is still named `udp2raw_cross`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Build a full release (include all binaries supported in the makefile)
|
|
||||||
|
|
||||||
1. make sure your linux is amd64 version
|
|
||||||
|
|
||||||
2. clone the repo
|
|
||||||
|
|
||||||
3. make sure you have g++ , make sure your g++ support the `-m32` option; make your your have installed libraries for `-m32` option
|
|
||||||
|
|
||||||
4. download https://github.com/wangyu-/files/releases/download/files/toolchains.tar.gz , and extract it to the right position (according to the makefile)
|
|
||||||
|
|
||||||
5. run `make release` inside udp2raw's directory
|
|
||||||
|
47
encrypt.cpp
@@ -17,13 +17,23 @@ static int8_t zero_iv[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0};//this prog
|
|||||||
****/
|
****/
|
||||||
|
|
||||||
char key[16];//generated from key_string by md5.
|
char key[16];//generated from key_string by md5.
|
||||||
//TODO key derive function
|
/*
|
||||||
|
TODO
|
||||||
|
|
||||||
|
Change md5 to HMAC-md5 if necessary.Change padding to PKCS#7 style if necessary.
|
||||||
|
|
||||||
|
Need someone with cryptography knowledge to help review the encryption method.
|
||||||
|
|
||||||
|
Change them if necessary(I can do this by myself,if it turns out to be necessary).
|
||||||
|
|
||||||
|
github issue:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/udp2raw-tunnel/issues/17
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
unordered_map<int, const char *> auth_mode_tostring = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_simple,"simple"}};
|
unordered_map<int, const char *> auth_mode_tostring = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_simple,"simple"}};
|
||||||
//TODO HMAC-md5 ,HMAC-sha1
|
|
||||||
|
|
||||||
unordered_map<int, const char *> cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"}};
|
unordered_map<int, const char *> cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"}};
|
||||||
//TODO aes-gcm
|
|
||||||
|
|
||||||
auth_mode_t auth_mode=auth_md5;
|
auth_mode_t auth_mode=auth_md5;
|
||||||
cipher_mode_t cipher_mode=cipher_aes128cbc;
|
cipher_mode_t cipher_mode=cipher_aes128cbc;
|
||||||
@@ -346,28 +356,13 @@ int my_decrypt(const char *data,char *output,int &len,char * key)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int encrypt_AE(const char *data,char *output,int &len,char * key)
|
int my_encrypt_pesudo_header(uint8_t *data,uint8_t *output,int &len,uint8_t * key,uint8_t *header,int hlen)
|
||||||
{
|
{
|
||||||
//TODO
|
|
||||||
//use encrypt-then-MAC scheme
|
return 0;
|
||||||
return -1;
|
}
|
||||||
}
|
int my_decrypt_pesudo_header(uint8_t *data,uint8_t *output,int &len,uint8_t * key,uint8_t *header,int hlen)
|
||||||
|
{
|
||||||
int decrypt_AE(const char *data,char *output,int &len,char * key)
|
return 0;
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int encrypt_AEAD(uint8_t *data,uint8_t *output,int &len,uint8_t * key,uint8_t *header,int hlen)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int decrypt_AEAD(uint8_t *data,uint8_t *output,int &len,uint8_t * key,uint8_t *header,int hlen)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,9 @@ extern char key[16];
|
|||||||
int my_encrypt(const char *data,char *output,int &len,char * key);
|
int my_encrypt(const char *data,char *output,int &len,char * key);
|
||||||
int my_decrypt(const char *data,char *output,int &len,char * key);
|
int my_decrypt(const char *data,char *output,int &len,char * key);
|
||||||
|
|
||||||
|
int my_encrypt_pesudo_header(uint8_t *data,uint8_t *output,int &len,uint8_t * key,uint8_t *header,int hlen);
|
||||||
|
int my_decrypt_pesudo_header(uint8_t *data,uint8_t *output,int &len,uint8_t * key,uint8_t *header,int hlen);
|
||||||
|
|
||||||
|
|
||||||
unsigned short csum(const unsigned short *ptr,int nbytes) ;
|
unsigned short csum(const unsigned short *ptr,int nbytes) ;
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 44 KiB |
@@ -1 +0,0 @@
|
|||||||
|
|
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 29 KiB |
144
main.cpp
@@ -7,9 +7,7 @@
|
|||||||
#include "encrypt.h"
|
#include "encrypt.h"
|
||||||
#include "fd_manager.h"
|
#include "fd_manager.h"
|
||||||
|
|
||||||
|
int mtu_warn=1375;//if a packet larger than mtu warn is receviced,there will be a warning
|
||||||
char hb_buf[buf_len];
|
|
||||||
|
|
||||||
|
|
||||||
int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp_oppsite_const_id);
|
int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp_oppsite_const_id);
|
||||||
int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,char *data,int data_len);
|
int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,char *data,int data_len);
|
||||||
@@ -227,6 +225,11 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(get_current_time()-conn_info.last_hb_sent_time<heartbeat_interval)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if(get_current_time()- conn_info.last_oppsite_roller_time>client_conn_uplink_timeout)
|
if(get_current_time()- conn_info.last_oppsite_roller_time>client_conn_uplink_timeout)
|
||||||
{
|
{
|
||||||
conn_info.state.client_current_state=client_idle;
|
conn_info.state.client_current_state=client_idle;
|
||||||
@@ -234,20 +237,10 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
|||||||
mylog(log_info,"state back to client_idle from client_ready bc of client-->server direction timeout\n");
|
mylog(log_info,"state back to client_idle from client_ready bc of client-->server direction timeout\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(get_current_time()-conn_info.last_hb_sent_time<heartbeat_interval)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mylog(log_debug,"heartbeat sent <%x,%x>\n",conn_info.oppsite_id,conn_info.my_id);
|
mylog(log_debug,"heartbeat sent <%x,%x>\n",conn_info.oppsite_id,conn_info.my_id);
|
||||||
|
|
||||||
if(hb_mode==0)
|
send_safer(conn_info,'h',"",0);/////////////send
|
||||||
send_safer(conn_info,'h',hb_buf,0);/////////////send
|
|
||||||
else
|
|
||||||
send_safer(conn_info,'h',hb_buf,hb_len);
|
|
||||||
conn_info.last_hb_sent_time=get_current_time();
|
conn_info.last_hb_sent_time=get_current_time();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -289,10 +282,8 @@ int server_on_timer_multi(conn_info_t &conn_info,char * ip_port) //for server.
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hb_mode==0)
|
send_safer(conn_info,'h',"",0); /////////////send
|
||||||
send_safer(conn_info,'h',hb_buf,0); /////////////send
|
|
||||||
else
|
|
||||||
send_safer(conn_info,'h',hb_buf,hb_len);
|
|
||||||
conn_info.last_hb_sent_time=get_current_time();
|
conn_info.last_hb_sent_time=get_current_time();
|
||||||
|
|
||||||
mylog(log_debug,"heart beat sent<%x,%x>\n",conn_info.my_id,conn_info.oppsite_id);
|
mylog(log_debug,"heart beat sent<%x,%x>\n",conn_info.my_id,conn_info.oppsite_id);
|
||||||
@@ -438,9 +429,9 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
|||||||
conn_info.last_oppsite_roller_time=conn_info.last_hb_recv_time;
|
conn_info.last_oppsite_roller_time=conn_info.last_hb_recv_time;
|
||||||
client_on_timer(conn_info);
|
client_on_timer(conn_info);
|
||||||
}
|
}
|
||||||
if(data_len>=0&&type=='h')
|
if(data_len==0&&type=='h')
|
||||||
{
|
{
|
||||||
mylog(log_debug,"[hb]heart beat received,oppsite_roller=%d\n",int(conn_info.oppsite_roller));
|
mylog(log_debug,"[hb]heart beat received\n");
|
||||||
conn_info.last_hb_recv_time=get_current_time();
|
conn_info.last_hb_recv_time=get_current_time();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -448,8 +439,7 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
|||||||
{
|
{
|
||||||
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
|
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
|
||||||
|
|
||||||
if(hb_mode==0)
|
conn_info.last_hb_recv_time=get_current_time();
|
||||||
conn_info.last_hb_recv_time=get_current_time();
|
|
||||||
|
|
||||||
//u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0]));
|
//u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0]));
|
||||||
u32_t tmp_conv_id;
|
u32_t tmp_conv_id;
|
||||||
@@ -783,7 +773,7 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
|
|||||||
return 0;
|
return 0;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (type == 'h' && data_len >= 0) {
|
if (type == 'h' && data_len == 0) {
|
||||||
//u32_t tmp = ntohl(*((u32_t *) &data[sizeof(u32_t)]));
|
//u32_t tmp = ntohl(*((u32_t *) &data[sizeof(u32_t)]));
|
||||||
mylog(log_debug,"[%s][hb]received hb \n",ip_port);
|
mylog(log_debug,"[%s][hb]received hb \n",ip_port);
|
||||||
conn_info.last_hb_recv_time = get_current_time();
|
conn_info.last_hb_recv_time = get_current_time();
|
||||||
@@ -797,8 +787,7 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
|
|||||||
tmp_conv_id=ntohl(tmp_conv_id);
|
tmp_conv_id=ntohl(tmp_conv_id);
|
||||||
|
|
||||||
|
|
||||||
if(hb_mode==0)
|
conn_info.last_hb_recv_time = get_current_time();
|
||||||
conn_info.last_hb_recv_time = get_current_time();
|
|
||||||
|
|
||||||
mylog(log_trace, "conv:%u\n", tmp_conv_id);
|
mylog(log_trace, "conv:%u\n", tmp_conv_id);
|
||||||
if (!conn_info.blob->conv_manager.is_conv_used(tmp_conv_id)) {
|
if (!conn_info.blob->conv_manager.is_conv_used(tmp_conv_id)) {
|
||||||
@@ -924,14 +913,11 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
|
|||||||
|
|
||||||
//my_id=conn_info.my_id;
|
//my_id=conn_info.my_id;
|
||||||
//oppsite_id=conn_info.oppsite_id;
|
//oppsite_id=conn_info.oppsite_id;
|
||||||
conn_info.last_hb_recv_time = get_current_time();
|
|
||||||
|
|
||||||
|
conn_info.last_hb_recv_time = get_current_time();
|
||||||
conn_info.last_hb_sent_time = conn_info.last_hb_recv_time;//=get_current_time()
|
conn_info.last_hb_sent_time = conn_info.last_hb_recv_time;//=get_current_time()
|
||||||
|
|
||||||
if(hb_mode==0)
|
send_safer(conn_info, 'h',"", 0); /////////////send
|
||||||
send_safer(conn_info,'h',hb_buf,0);/////////////send
|
|
||||||
else
|
|
||||||
send_safer(conn_info,'h',hb_buf,hb_len);
|
|
||||||
|
|
||||||
mylog(log_info, "[%s]changed state to server_ready\n",ip_port);
|
mylog(log_info, "[%s]changed state to server_ready\n",ip_port);
|
||||||
conn_info.blob->anti_replay.re_init();
|
conn_info.blob->anti_replay.re_init();
|
||||||
@@ -991,14 +977,8 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
|
|||||||
//ori_conn_info.state.server_current_state=server_ready;
|
//ori_conn_info.state.server_current_state=server_ready;
|
||||||
ori_conn_info.recover(conn_info);
|
ori_conn_info.recover(conn_info);
|
||||||
|
|
||||||
//send_safer(ori_conn_info, 'h',hb_buf, hb_len);
|
send_safer(ori_conn_info, 'h',"", 0);
|
||||||
//ori_conn_info.blob->anti_replay.re_init();
|
//ori_conn_info.blob->anti_replay.re_init();
|
||||||
if(hb_mode==0)
|
|
||||||
send_safer(ori_conn_info,'h',hb_buf,0);/////////////send
|
|
||||||
else
|
|
||||||
send_safer(ori_conn_info,'h',hb_buf,hb_len);
|
|
||||||
|
|
||||||
ori_conn_info.last_hb_recv_time=get_current_time();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1049,31 +1029,10 @@ int client_event_loop()
|
|||||||
u32_t dest_ip;
|
u32_t dest_ip;
|
||||||
string if_name_string;
|
string if_name_string;
|
||||||
string hw_string;
|
string hw_string;
|
||||||
|
if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0)
|
||||||
if(retry_on_error==0)
|
|
||||||
{
|
{
|
||||||
if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0)
|
mylog(log_fatal,"auto detect lower-level info failed for %s,specific it manually\n",remote_ip);
|
||||||
{
|
myexit(-1);
|
||||||
mylog(log_fatal,"auto detect lower-level info failed for %s,specific it manually\n",remote_ip);
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int ok=0;
|
|
||||||
while(!ok)
|
|
||||||
{
|
|
||||||
if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"auto detect lower-level info failed for %s,retry in %d seconds\n",remote_ip,retry_on_error_interval);
|
|
||||||
sleep(retry_on_error_interval);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ok=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mylog(log_info,"we are running at lower-level (auto) mode,%s %s %s\n",my_ntoa(dest_ip),if_name_string.c_str(),hw_string.c_str());
|
mylog(log_info,"we are running at lower-level (auto) mode,%s %s %s\n",my_ntoa(dest_ip),if_name_string.c_str(),hw_string.c_str());
|
||||||
|
|
||||||
@@ -1107,32 +1066,11 @@ int client_event_loop()
|
|||||||
if(source_ip_uint32==0)
|
if(source_ip_uint32==0)
|
||||||
{
|
{
|
||||||
mylog(log_info,"get_src_adress called\n");
|
mylog(log_info,"get_src_adress called\n");
|
||||||
if(retry_on_error==0)
|
if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0)
|
||||||
{
|
{
|
||||||
if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0)
|
mylog(log_fatal,"the trick to auto get source ip failed,you should specific an ip by --source-ip\n");
|
||||||
{
|
myexit(-1);
|
||||||
mylog(log_fatal,"the trick to auto get source ip failed, maybe you dont have internet access\n");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
int ok=0;
|
|
||||||
while(!ok)
|
|
||||||
{
|
|
||||||
if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"the trick to auto get source ip failed, maybe you dont have internet access, retry in %d seconds\n",retry_on_error_interval);
|
|
||||||
sleep(retry_on_error_interval);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ok=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
in_addr tmp;
|
in_addr tmp;
|
||||||
tmp.s_addr=source_ip_uint32;
|
tmp.s_addr=source_ip_uint32;
|
||||||
@@ -1238,13 +1176,13 @@ int client_event_loop()
|
|||||||
if (nfds < 0) { //allow zero
|
if (nfds < 0) { //allow zero
|
||||||
if(errno==EINTR )
|
if(errno==EINTR )
|
||||||
{
|
{
|
||||||
mylog(log_info,"epoll interrupted by signal,continue\n");
|
mylog(log_info,"epoll interrupted by signal\n");
|
||||||
//close(fifo_fd);
|
//close(fifo_fd);
|
||||||
//myexit(0);
|
myexit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"epoll_wait return %d,%s\n", nfds,strerror(errno));
|
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1294,18 +1232,12 @@ int client_event_loop()
|
|||||||
int recv_len;
|
int recv_len;
|
||||||
struct sockaddr_in udp_new_addr_in={0};
|
struct sockaddr_in udp_new_addr_in={0};
|
||||||
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
|
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
|
||||||
if ((recv_len = recvfrom(udp_fd, buf, max_data_len+1, 0,
|
if ((recv_len = recvfrom(udp_fd, buf, max_data_len, 0,
|
||||||
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
|
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
|
||||||
mylog(log_error,"recv_from error,this shouldnt happen at client\n");
|
mylog(log_error,"recv_from error,this shouldnt happen at client\n");
|
||||||
myexit(1);
|
myexit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
if(recv_len==max_data_len+1)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(recv_len>=mtu_warn)
|
if(recv_len>=mtu_warn)
|
||||||
{
|
{
|
||||||
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",recv_len,mtu_warn);
|
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",recv_len,mtu_warn);
|
||||||
@@ -1488,12 +1420,12 @@ int server_event_loop()
|
|||||||
if (nfds < 0) { //allow zero
|
if (nfds < 0) { //allow zero
|
||||||
if(errno==EINTR )
|
if(errno==EINTR )
|
||||||
{
|
{
|
||||||
mylog(log_info,"epoll interrupted by signal,continue\n");
|
mylog(log_info,"epoll interrupted by signal\n");
|
||||||
//myexit(0);
|
myexit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"epoll_wait return %d,%s\n", nfds,strerror(errno));
|
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1645,16 +1577,10 @@ int server_event_loop()
|
|||||||
|
|
||||||
int fd=fd_manager.to_fd(fd64);
|
int fd=fd_manager.to_fd(fd64);
|
||||||
|
|
||||||
int recv_len=recv(fd,buf,max_data_len+1,0);
|
int recv_len=recv(fd,buf,max_data_len,0);
|
||||||
|
|
||||||
mylog(log_trace,"received a packet from udp_fd,len:%d\n",recv_len);
|
mylog(log_trace,"received a packet from udp_fd,len:%d\n",recv_len);
|
||||||
|
|
||||||
if(recv_len==max_data_len+1)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(recv_len<0)
|
if(recv_len<0)
|
||||||
{
|
{
|
||||||
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
|
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
|
||||||
@@ -1730,11 +1656,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(geteuid() != 0)
|
if(geteuid() != 0)
|
||||||
{
|
{
|
||||||
mylog(log_error,"root check failed, it seems like you are using a non-root account. we can try to continue, but it may fail. If you want to run udp2raw as non-root, you have to add iptables rule manually, and grant udp2raw CAP_NET_RAW capability, check README.md in repo for more info.\n");
|
mylog(log_error,"root check failed,make sure you run this program with root,we can try to continue,but it will likely fail\n");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(log_warn,"you can run udp2raw with non-root account for better security. check README.md in repo for more info.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local_ip_uint32=inet_addr(local_ip);
|
local_ip_uint32=inet_addr(local_ip);
|
||||||
|
9
makefile
@@ -1,12 +1,10 @@
|
|||||||
cc_cross=/home/wangyu/Desktop/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
cc_cross=/home/wangyu/Desktop/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
||||||
cc_local=g++
|
cc_local=g++
|
||||||
#cc_local=/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-g++
|
|
||||||
#cc_mips34kc=/toolchains/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++
|
#cc_mips34kc=/toolchains/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++
|
||||||
cc_mips24kc_be=/toolchains/lede-sdk-17.01.2-ar71xx-generic_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin/mips-openwrt-linux-musl-g++
|
cc_mips24kc_be=/toolchains/lede-sdk-17.01.2-ar71xx-generic_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin/mips-openwrt-linux-musl-g++
|
||||||
cc_mips24kc_le=/toolchains/lede-sdk-17.01.2-ramips-mt7621_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16/bin/mipsel-openwrt-linux-musl-g++
|
cc_mips24kc_le=/toolchains/lede-sdk-17.01.2-ramips-mt7621_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16/bin/mipsel-openwrt-linux-musl-g++
|
||||||
#cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm
|
#cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm
|
||||||
cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
||||||
#cc_arm=/toolchains/lede-sdk-17.01.2-brcm2708-bcm2708_gcc-5.4.0_musl-1.1.16_eabi.Linux-x86_64/staging_dir/toolchain-arm_arm1176jzf-s+vfp_gcc-5.4.0_musl-1.1.16_eabi/bin/arm-openwrt-linux-muslgnueabi-g++
|
|
||||||
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
||||||
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
|
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
|
||||||
|
|
||||||
@@ -49,10 +47,6 @@ mips24kc_le_asm_aes: git_version
|
|||||||
# ${cc_bcm2708} -o ${NAME}_bcm2708 -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
# ${cc_bcm2708} -o ${NAME}_bcm2708 -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
||||||
amd64:git_version
|
amd64:git_version
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
||||||
|
|
||||||
amd64_perf:git_version
|
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O0 -fno-omit-frame-pointer -g
|
|
||||||
|
|
||||||
amd64_hw_aes:git_version
|
amd64_hw_aes:git_version
|
||||||
${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/x64.S
|
${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/x64.S
|
||||||
x86:git_version
|
x86:git_version
|
||||||
@@ -62,9 +56,6 @@ x86_asm_aes:git_version
|
|||||||
arm:git_version
|
arm:git_version
|
||||||
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
||||||
|
|
||||||
arm_perf:git_version
|
|
||||||
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -mapcs-frame -fno-omit-frame-pointer -g -O0 -lgcc_eh
|
|
||||||
|
|
||||||
arm_asm_aes:git_version
|
arm_asm_aes:git_version
|
||||||
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/arm.S
|
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/arm.S
|
||||||
|
|
||||||
|
144
misc.cpp
@@ -13,12 +13,6 @@
|
|||||||
#include "fd_manager.h"
|
#include "fd_manager.h"
|
||||||
|
|
||||||
|
|
||||||
int hb_mode=1;
|
|
||||||
int hb_len=1200;
|
|
||||||
|
|
||||||
int mtu_warn=1375;//if a packet larger than mtu warn is receviced,there will be a warning
|
|
||||||
|
|
||||||
|
|
||||||
fd_manager_t fd_manager;
|
fd_manager_t fd_manager;
|
||||||
|
|
||||||
char local_ip[100]="0.0.0.0", remote_ip[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_ip for -r option,source for --source-ip
|
char local_ip[100]="0.0.0.0", remote_ip[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_ip for -r option,source for --source-ip
|
||||||
@@ -44,18 +38,12 @@ int auto_add_iptables_rule=0;//if -a is set
|
|||||||
int generate_iptables_rule=0;//if -g is set
|
int generate_iptables_rule=0;//if -g is set
|
||||||
int generate_iptables_rule_add=0;// if --gen-add is set
|
int generate_iptables_rule_add=0;// if --gen-add is set
|
||||||
|
|
||||||
int retry_on_error=0;
|
|
||||||
|
|
||||||
int debug_resend=0; // debug only
|
int debug_resend=0; // debug only
|
||||||
|
|
||||||
char key_string[1000]= "secret key";// -k option
|
char key_string[1000]= "secret key";// -k option
|
||||||
|
|
||||||
char fifo_file[1000]="";
|
char fifo_file[1000]="";
|
||||||
|
|
||||||
int clear_iptables=0;
|
|
||||||
int wait_xtables_lock=0;
|
|
||||||
string iptables_command0="iptables ";
|
|
||||||
string iptables_command="";
|
|
||||||
string iptables_pattern="";
|
string iptables_pattern="";
|
||||||
int iptables_rule_added=0;
|
int iptables_rule_added=0;
|
||||||
int iptables_rule_keeped=0;
|
int iptables_rule_keeped=0;
|
||||||
@@ -159,13 +147,9 @@ void print_help()
|
|||||||
printf(" --lower-level <string> send packets at OSI level 2, format:'if_name#dest_mac_adress'\n");
|
printf(" --lower-level <string> send packets at OSI level 2, format:'if_name#dest_mac_adress'\n");
|
||||||
printf(" ie:'eth0#00:23:45:67:89:b9'.or try '--lower-level auto' to obtain\n");
|
printf(" ie:'eth0#00:23:45:67:89:b9'.or try '--lower-level auto' to obtain\n");
|
||||||
printf(" the parameter automatically,specify it manually if 'auto' failed\n");
|
printf(" the parameter automatically,specify it manually if 'auto' failed\n");
|
||||||
printf(" --wait-lock wait for xtables lock while invoking iptables, need iptables v1.4.20+\n");
|
|
||||||
printf(" --gen-add generate iptables rule and add it permanently,then exit.overrides -g\n");
|
printf(" --gen-add generate iptables rule and add it permanently,then exit.overrides -g\n");
|
||||||
printf(" --keep-rule monitor iptables and auto re-add if necessary.implys -a\n");
|
printf(" --keep-rule monitor iptables and auto re-add if necessary.implys -a\n");
|
||||||
printf(" --hb-len <number> length of heart-beat packet, >=0 and <=1500\n");
|
|
||||||
printf(" --mtu-warn <number> mtu warning threshold, unit:byte, default:1375\n");
|
|
||||||
printf(" --clear clear any iptables rules added by this program.overrides everything\n");
|
printf(" --clear clear any iptables rules added by this program.overrides everything\n");
|
||||||
printf(" --retry-on-error retry on error, allow to start udp2raw before network is initialized\n");
|
|
||||||
printf(" -h,--help print this help message\n");
|
printf(" -h,--help print this help message\n");
|
||||||
|
|
||||||
//printf("common options,these options must be same on both side\n");
|
//printf("common options,these options must be same on both side\n");
|
||||||
@@ -253,7 +237,6 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
{"gen-rule", no_argument, 0, 'g'},
|
{"gen-rule", no_argument, 0, 'g'},
|
||||||
{"gen-add", no_argument, 0, 1},
|
{"gen-add", no_argument, 0, 1},
|
||||||
{"debug", no_argument, 0, 1},
|
{"debug", no_argument, 0, 1},
|
||||||
{"retry-on-error", no_argument, 0, 1},
|
|
||||||
{"clear", no_argument, 0, 1},
|
{"clear", no_argument, 0, 1},
|
||||||
{"simple-rule", no_argument, 0, 1},
|
{"simple-rule", no_argument, 0, 1},
|
||||||
{"keep-rule", no_argument, 0, 1},
|
{"keep-rule", no_argument, 0, 1},
|
||||||
@@ -262,12 +245,8 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
{"seq-mode", required_argument, 0, 1},
|
{"seq-mode", required_argument, 0, 1},
|
||||||
{"conf-file", required_argument, 0, 1},
|
{"conf-file", required_argument, 0, 1},
|
||||||
{"force-sock-buf", no_argument, 0, 1},
|
{"force-sock-buf", no_argument, 0, 1},
|
||||||
{"wait-lock", no_argument, 0, 1},
|
|
||||||
{"random-drop", required_argument, 0, 1},
|
{"random-drop", required_argument, 0, 1},
|
||||||
{"fifo", required_argument, 0, 1},
|
{"fifo", required_argument, 0, 1},
|
||||||
{"hb-mode", required_argument, 0, 1},
|
|
||||||
{"hb-len", required_argument, 0, 1},
|
|
||||||
{"mtu-warn", required_argument, 0, 1},
|
|
||||||
{NULL, 0, 0, 0}
|
{NULL, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -436,7 +415,15 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
mylog(log_debug,"option_index: %d\n",option_index);
|
mylog(log_debug,"option_index: %d\n",option_index);
|
||||||
if(strcmp(long_options[option_index].name,"clear")==0)
|
if(strcmp(long_options[option_index].name,"clear")==0)
|
||||||
{
|
{
|
||||||
clear_iptables=1;
|
char *output;
|
||||||
|
//int ret =system("iptables-save |grep udp2raw_dWRwMnJhdw|sed -n 's/^-A/iptables -D/p'|sh");
|
||||||
|
int ret =run_command("iptables -S|sed -n '/udp2rawDwrW/p'|sed -n 's/^-A/iptables -D/p'|sh",output);
|
||||||
|
|
||||||
|
int ret2 =run_command("iptables -S|sed -n '/udp2rawDwrW/p'|sed -n 's/^-N/iptables -X/p'|sh",output);
|
||||||
|
//system("iptables-save |grep udp2raw_dWRwMnJhdw|sed 's/^-A/iptables -D/'|sh");
|
||||||
|
//system("iptables-save|grep -v udp2raw_dWRwMnJhdw|iptables-restore");
|
||||||
|
mylog(log_info,"tried to clear all iptables rule created previously,return value %d %d\n",ret,ret2);
|
||||||
|
myexit(-1);
|
||||||
}
|
}
|
||||||
else if(strcmp(long_options[option_index].name,"source-ip")==0)
|
else if(strcmp(long_options[option_index].name,"source-ip")==0)
|
||||||
{
|
{
|
||||||
@@ -548,14 +535,6 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
{
|
{
|
||||||
force_socket_buf=1;
|
force_socket_buf=1;
|
||||||
}
|
}
|
||||||
else if(strcmp(long_options[option_index].name,"retry-on-error")==0)
|
|
||||||
{
|
|
||||||
retry_on_error=1;
|
|
||||||
}
|
|
||||||
else if(strcmp(long_options[option_index].name,"wait-lock")==0)
|
|
||||||
{
|
|
||||||
wait_xtables_lock=1;
|
|
||||||
}
|
|
||||||
else if(strcmp(long_options[option_index].name,"disable-bpf")==0)
|
else if(strcmp(long_options[option_index].name,"disable-bpf")==0)
|
||||||
{
|
{
|
||||||
disable_bpf_filter=1;
|
disable_bpf_filter=1;
|
||||||
@@ -610,24 +589,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
{
|
{
|
||||||
mylog(log_info,"configuration loaded from %s\n",optarg);
|
mylog(log_info,"configuration loaded from %s\n",optarg);
|
||||||
}
|
}
|
||||||
else if(strcmp(long_options[option_index].name,"hb-mode")==0)
|
|
||||||
{
|
|
||||||
sscanf(optarg,"%d",&hb_mode);
|
|
||||||
assert(hb_mode==0||hb_mode==1);
|
|
||||||
mylog(log_info,"hb_mode =%d \n",hb_mode);
|
|
||||||
}
|
|
||||||
else if(strcmp(long_options[option_index].name,"hb-len")==0)
|
|
||||||
{
|
|
||||||
sscanf(optarg,"%d",&hb_len);
|
|
||||||
assert(hb_len>=0&&hb_len<=1500);
|
|
||||||
mylog(log_info,"hb_len =%d \n",hb_len);
|
|
||||||
}
|
|
||||||
else if(strcmp(long_options[option_index].name,"mtu-warn")==0)
|
|
||||||
{
|
|
||||||
sscanf(optarg,"%d",&mtu_warn);
|
|
||||||
assert(mtu_warn>0);
|
|
||||||
mylog(log_info,"mtu_warn=%d \n",mtu_warn);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_warn,"ignored unknown long option ,option_index:%d code:<%x>\n",option_index, optopt);
|
mylog(log_warn,"ignored unknown long option ,option_index:%d code:<%x>\n",option_index, optopt);
|
||||||
@@ -650,7 +612,6 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
print_help();
|
print_help();
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(lower_level)
|
//if(lower_level)
|
||||||
//process_lower_level_arg();
|
//process_lower_level_arg();
|
||||||
|
|
||||||
@@ -779,30 +740,8 @@ void *run_keep(void *none) //called in a new thread for --keep-rule option
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
void iptables_rule() // handles -a -g --gen-add --keep-rule --clear --wait-lock
|
void iptables_rule() // handles -a -g --gen-add --keep-rule
|
||||||
{
|
{
|
||||||
if(!wait_xtables_lock)
|
|
||||||
{
|
|
||||||
iptables_command=iptables_command0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iptables_command=iptables_command0+"-w ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(clear_iptables)
|
|
||||||
{
|
|
||||||
char *output;
|
|
||||||
//int ret =system("iptables-save |grep udp2raw_dWRwMnJhdw|sed -n 's/^-A/iptables -D/p'|sh");
|
|
||||||
int ret =run_command(iptables_command+"-S|sed -n '/udp2rawDwrW/p'|sed -n 's/^-A/"+iptables_command+"-D/p'|sh",output);
|
|
||||||
|
|
||||||
int ret2 =run_command(iptables_command+"-S|sed -n '/udp2rawDwrW/p'|sed -n 's/^-N/"+iptables_command+"-X/p'|sh",output);
|
|
||||||
//system("iptables-save |grep udp2raw_dWRwMnJhdw|sed 's/^-A/iptables -D/'|sh");
|
|
||||||
//system("iptables-save|grep -v udp2raw_dWRwMnJhdw|iptables-restore");
|
|
||||||
mylog(log_info,"tried to clear all iptables rule created previously,return value %d %d\n",ret,ret2);
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(auto_add_iptables_rule&&generate_iptables_rule)
|
if(auto_add_iptables_rule&&generate_iptables_rule)
|
||||||
{
|
{
|
||||||
mylog(log_warn," -g overrides -a\n");
|
mylog(log_warn," -g overrides -a\n");
|
||||||
@@ -905,7 +844,7 @@ void iptables_rule() // handles -a -g --gen-add --keep-rule --clear --wait-loc
|
|||||||
}
|
}
|
||||||
if(generate_iptables_rule)
|
if(generate_iptables_rule)
|
||||||
{
|
{
|
||||||
string rule=iptables_command+"-I INPUT ";
|
string rule="iptables -I INPUT ";
|
||||||
rule+=pattern;
|
rule+=pattern;
|
||||||
rule+=" -j DROP";
|
rule+=" -j DROP";
|
||||||
|
|
||||||
@@ -1075,6 +1014,31 @@ int handle_lower_level(raw_info_t &raw_info)//fill lower_level info,when --lower
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
int add_iptables_rule(const char * s)
|
||||||
|
{
|
||||||
|
|
||||||
|
iptables_pattern=s;
|
||||||
|
|
||||||
|
string rule="iptables -I INPUT ";
|
||||||
|
rule+=iptables_pattern;
|
||||||
|
rule+=" -j DROP";
|
||||||
|
|
||||||
|
char *output;
|
||||||
|
if(run_command(rule.c_str(),output)==0)
|
||||||
|
{
|
||||||
|
mylog(log_warn,"auto added iptables rule by: %s\n",rule.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mylog(log_fatal,"auto added iptables failed by: %s\n",rule.c_str());
|
||||||
|
//mylog(log_fatal,"reason : %s\n",strerror(errno));
|
||||||
|
myexit(-1);
|
||||||
|
}
|
||||||
|
iptables_rule_added=1;
|
||||||
|
return 0;
|
||||||
|
}*/
|
||||||
string chain[2];
|
string chain[2];
|
||||||
string rule_keep[2];
|
string rule_keep[2];
|
||||||
string rule_keep_add[2];
|
string rule_keep_add[2];
|
||||||
@@ -1089,14 +1053,14 @@ int iptables_gen_add(const char * s,u32_t const_id)
|
|||||||
iptables_pattern=s;
|
iptables_pattern=s;
|
||||||
chain[0] =dummy+ "udp2rawDwrW_C";
|
chain[0] =dummy+ "udp2rawDwrW_C";
|
||||||
rule_keep[0]=dummy+ iptables_pattern+" -j " +chain[0];
|
rule_keep[0]=dummy+ iptables_pattern+" -j " +chain[0];
|
||||||
rule_keep_add[0]=iptables_command+"-I INPUT "+rule_keep[0];
|
rule_keep_add[0]=dummy+"iptables -I INPUT "+rule_keep[0];
|
||||||
|
|
||||||
char *output;
|
char *output;
|
||||||
run_command(iptables_command+"-N "+chain[0],output,show_none);
|
run_command(dummy+"iptables -N "+chain[0],output,show_none);
|
||||||
run_command(iptables_command+"-F "+chain[0],output);
|
run_command(dummy+"iptables -F "+chain[0],output);
|
||||||
run_command(iptables_command+"-I "+chain[0] + " -j DROP",output);
|
run_command(dummy+"iptables -I "+chain[0] + " -j DROP",output);
|
||||||
|
|
||||||
rule_keep_del[0]=iptables_command+"-D INPUT "+rule_keep[0];
|
rule_keep_del[0]=dummy+"iptables -D INPUT "+rule_keep[0];
|
||||||
|
|
||||||
run_command(rule_keep_del[0],output,show_none);
|
run_command(rule_keep_del[0],output,show_none);
|
||||||
run_command(rule_keep_del[0],output,show_none);
|
run_command(rule_keep_del[0],output,show_none);
|
||||||
@@ -1124,11 +1088,11 @@ int iptables_rule_init(const char * s,u32_t const_id,int keep)
|
|||||||
rule_keep[0]=dummy+ iptables_pattern+" -j " +chain[0];
|
rule_keep[0]=dummy+ iptables_pattern+" -j " +chain[0];
|
||||||
rule_keep[1]=dummy+ iptables_pattern+" -j " +chain[1];
|
rule_keep[1]=dummy+ iptables_pattern+" -j " +chain[1];
|
||||||
|
|
||||||
rule_keep_add[0]=iptables_command+"-I INPUT "+rule_keep[0];
|
rule_keep_add[0]=dummy+"iptables -I INPUT "+rule_keep[0];
|
||||||
rule_keep_add[1]=iptables_command+"-I INPUT "+rule_keep[1];
|
rule_keep_add[1]=dummy+"iptables -I INPUT "+rule_keep[1];
|
||||||
|
|
||||||
rule_keep_del[0]=iptables_command+"-D INPUT "+rule_keep[0];
|
rule_keep_del[0]=dummy+"iptables -D INPUT "+rule_keep[0];
|
||||||
rule_keep_del[1]=iptables_command+"-D INPUT "+rule_keep[1];
|
rule_keep_del[1]=dummy+"iptables -D INPUT "+rule_keep[1];
|
||||||
|
|
||||||
keep_rule_last_time=get_current_time();
|
keep_rule_last_time=get_current_time();
|
||||||
|
|
||||||
@@ -1136,9 +1100,9 @@ int iptables_rule_init(const char * s,u32_t const_id,int keep)
|
|||||||
|
|
||||||
for(int i=0;i<=iptables_rule_keeped;i++)
|
for(int i=0;i<=iptables_rule_keeped;i++)
|
||||||
{
|
{
|
||||||
run_command(iptables_command+"-N "+chain[i],output);
|
run_command(dummy+"iptables -N "+chain[i],output);
|
||||||
run_command(iptables_command+"-F "+chain[i],output);
|
run_command(dummy+"iptables -F "+chain[i],output);
|
||||||
run_command(iptables_command+"-I "+chain[i] + " -j DROP",output);
|
run_command(dummy+"iptables -I "+chain[i] + " -j DROP",output);
|
||||||
|
|
||||||
if(run_command(rule_keep_add[i],output)!=0)
|
if(run_command(rule_keep_add[i],output)!=0)
|
||||||
{
|
{
|
||||||
@@ -1175,12 +1139,12 @@ int keep_iptables_rule() //magic to work on a machine without grep/iptables --c
|
|||||||
|
|
||||||
int i=iptables_rule_keep_index;
|
int i=iptables_rule_keep_index;
|
||||||
|
|
||||||
run_command(iptables_command + "-N " + chain[i], output,show_none);
|
run_command(dummy + "iptables -N " + chain[i], output,show_none);
|
||||||
|
|
||||||
if (run_command(iptables_command + "-F " + chain[i], output,show_none) != 0)
|
if (run_command(dummy + "iptables -F " + chain[i], output,show_none) != 0)
|
||||||
mylog(log_warn, "iptables -F failed %d\n",i);
|
mylog(log_warn, "iptables -F failed %d\n",i);
|
||||||
|
|
||||||
if (run_command(iptables_command + "-I " + chain[i] + " -j DROP",output,show_none) != 0)
|
if (run_command(dummy + "iptables -I " + chain[i] + " -j DROP",output,show_none) != 0)
|
||||||
mylog(log_warn, "iptables -I failed %d\n",i);
|
mylog(log_warn, "iptables -I failed %d\n",i);
|
||||||
|
|
||||||
if (run_command(rule_keep_del[i], output,show_none) != 0)
|
if (run_command(rule_keep_del[i], output,show_none) != 0)
|
||||||
@@ -1204,8 +1168,8 @@ int clear_iptables_rule()
|
|||||||
for(int i=0;i<=iptables_rule_keeped;i++ )
|
for(int i=0;i<=iptables_rule_keeped;i++ )
|
||||||
{
|
{
|
||||||
run_command(rule_keep_del[i],output);
|
run_command(rule_keep_del[i],output);
|
||||||
run_command(iptables_command+"-F "+chain[i],output);
|
run_command(dummy+"iptables -F "+chain[i],output);
|
||||||
run_command(iptables_command+"-X "+chain[i],output);
|
run_command(dummy+"iptables -X "+chain[i],output);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
20
misc.h
@@ -13,9 +13,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
extern int hb_mode;
|
|
||||||
extern int hb_len;
|
|
||||||
extern int mtu_warn;
|
|
||||||
|
|
||||||
const u32_t max_handshake_conn_num=10000;
|
const u32_t max_handshake_conn_num=10000;
|
||||||
const u32_t max_ready_conn_num=1000;
|
const u32_t max_ready_conn_num=1000;
|
||||||
@@ -27,22 +25,22 @@ const u32_t client_retry_interval=1000;//ms
|
|||||||
|
|
||||||
const u32_t server_handshake_timeout=client_handshake_timeout+5000;// this should be longer than clients. client retry initially ,server retry passtively
|
const u32_t server_handshake_timeout=client_handshake_timeout+5000;// this should be longer than clients. client retry initially ,server retry passtively
|
||||||
|
|
||||||
const int conv_clear_ratio=30; //conv grabage collecter check 1/30 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=50;
|
const int conn_clear_ratio=30;
|
||||||
const int conv_clear_min=1;
|
const int conv_clear_min=1;
|
||||||
const int conn_clear_min=1;
|
const int conn_clear_min=1;
|
||||||
|
|
||||||
const u32_t conv_clear_interval=1000;//ms
|
const u32_t conv_clear_interval=3000;//ms
|
||||||
const u32_t conn_clear_interval=1000;//ms
|
const u32_t conn_clear_interval=3000;//ms
|
||||||
|
|
||||||
|
|
||||||
const i32_t max_fail_time=0;//disable
|
const i32_t max_fail_time=0;//disable
|
||||||
|
|
||||||
const u32_t heartbeat_interval=600;//ms
|
const u32_t heartbeat_interval=1000;//ms
|
||||||
|
|
||||||
const u32_t timer_interval=400;//ms. this should be smaller than heartbeat_interval and retry interval;
|
const u32_t timer_interval=400;//ms. this should be smaller than heartbeat_interval and retry interval;
|
||||||
|
|
||||||
const uint32_t conv_timeout=180000; //ms. 120 second
|
const uint32_t conv_timeout=120000; //ms. 120 second
|
||||||
//const u32_t conv_timeout=30000; //for test
|
//const u32_t conv_timeout=30000; //for test
|
||||||
|
|
||||||
const u32_t client_conn_timeout=10000;//ms.
|
const u32_t client_conn_timeout=10000;//ms.
|
||||||
@@ -51,7 +49,7 @@ const u32_t client_conn_uplink_timeout=client_conn_timeout+2000;//ms
|
|||||||
const uint32_t server_conn_timeout=conv_timeout+60000;//ms. this should be 60s+ longer than conv_timeout,so that conv_manager can destruct convs gradually,to avoid latency glicth
|
const uint32_t server_conn_timeout=conv_timeout+60000;//ms. this should be 60s+ longer than conv_timeout,so that conv_manager can destruct convs gradually,to avoid latency glicth
|
||||||
//const u32_t server_conn_timeout=conv_timeout+10000;//for test
|
//const u32_t server_conn_timeout=conv_timeout+10000;//for test
|
||||||
|
|
||||||
const u32_t iptables_rule_keep_interval=20;//unit: second;
|
const u32_t iptables_rule_keep_interval=15;//unit: second;
|
||||||
|
|
||||||
enum server_current_state_t {server_idle=0,server_handshake1,server_ready}; //server state machine
|
enum server_current_state_t {server_idle=0,server_handshake1,server_ready}; //server state machine
|
||||||
enum client_current_state_t {client_idle=0,client_tcp_handshake,client_handshake1,client_handshake2,client_ready};//client state machine
|
enum client_current_state_t {client_idle=0,client_tcp_handshake,client_handshake1,client_handshake2,client_ready};//client state machine
|
||||||
@@ -87,8 +85,6 @@ extern int keep_rule; //whether to monitor the iptables rule periodly,re-add if
|
|||||||
extern int auto_add_iptables_rule;//if -a is set
|
extern int auto_add_iptables_rule;//if -a is set
|
||||||
extern int generate_iptables_rule;//if -g is set
|
extern int generate_iptables_rule;//if -g is set
|
||||||
extern int generate_iptables_rule_add;// if --gen-add is set
|
extern int generate_iptables_rule_add;// if --gen-add is set
|
||||||
extern int retry_on_error;
|
|
||||||
const int retry_on_error_interval=10;
|
|
||||||
|
|
||||||
extern int debug_resend; // debug only
|
extern int debug_resend; // debug only
|
||||||
|
|
||||||
|
@@ -704,13 +704,7 @@ int recv_raw_ip(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
|||||||
struct sockaddr_ll saddr={0};
|
struct sockaddr_ll saddr={0};
|
||||||
socklen_t saddr_size = sizeof(saddr);
|
socklen_t saddr_size = sizeof(saddr);
|
||||||
int flag=0;
|
int flag=0;
|
||||||
int recv_len = recvfrom(raw_recv_fd, recv_raw_ip_buf, max_data_len+1, flag ,(sockaddr*)&saddr , &saddr_size);
|
int recv_len = recvfrom(raw_recv_fd, recv_raw_ip_buf, max_data_len, flag ,(sockaddr*)&saddr , &saddr_size);
|
||||||
|
|
||||||
if(recv_len==max_data_len+1)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(recv_len<0)
|
if(recv_len<0)
|
||||||
{
|
{
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
https://github.com/sensec/luci-app-udp2raw
|
|
@@ -1 +0,0 @@
|
|||||||
https://github.com/sensec/openwrt-udp2raw
|
|