2个版本
0.1.1 | 2022年3月10日 |
---|---|
0.1.0 | 2022年1月30日 |
#18 in #udp-server
2.5MB
786 代码行
包含 (ELF可执行文件/库, 8.5MB) target/release/examples/acton
Acton
acton
为使用Rust实现以太网UDP网络提供linux
API。
示例
更多示例,包括数据包记录器和以太网UDP服务器及客户端的版本,可以在examples/
目录中找到。
以太网UDP服务器和客户端
此代码实现了一个以太网UDP服务器和客户端。每当在接口上收到服务器上的以太网帧时,它将数据包发送给客户端,反之亦然。在服务中,实现了简单的以太网MAC学习,并带有MAC转发表老化。服务器发送的广播(Broadcast)、未知(Unknown)、多播(Multicast)帧将被广播给所有客户端。但客户端之间的本地交换是不允许的(P2MP转发方式)。定义并使用专有控制包用于会话生命周期管理(hello和keepalive控制包)
可扩展性
已测试1,000个客户端(应考虑Linux系统资源限制)
如何安装
wget https://raw.githubusercontent.com/simonrho/acton/main/target/release/examples/acton; chmod +x ./acton
如何使用
poc@r1:~/acton$ sudo ./acton
acton 0.1.0
Ethernet over UDP tunnel tools
USAGE:
acton <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
client client connect mode for L2 tunnel establishment
help Prints this message or the help of the given subcommand(s)
server server listen mode for L2 tunnel requests
运行服务器
poc@r1:~/acton$ sudo ./acton server --help
acton-server 0.1.0
server listen mode for L2 tunnel requests
USAGE:
acton server [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-a, --address <address> tap ip network (a.b.c.d/n) [env: CLIENT_TAP_NETWORK=] [default: 0.0.0.0/0]
-l, --listen <listen> server listen address [env: SERVER_LISTEN_ADDRESS=] [default: 0.0.0.0]
-m, --mac <mac> tap mac address (xx:xx:xx:xx:xx:xx) [env: SERVER_TAP_MAC=] [default:
00:00:00:00:00:00]
-p, --port <port> server listen port [env: SERVER_LISTEN_PORT=] [default: 8080]
-t, --tap-name <tap-name> tap interface name [env: SERVER_TAP_NAME=] [default: server]
poc@r1:~/acton$
poc@r1:~/acton$ sudo ./acton server -m 00:01:02:03:04:05 -a 100.0.0.1/24
[2022-01-30T10:35:24Z INFO acton::server] server starts!
运行客户端
poc@r2:~/acton$ sudo ./acton client -h
acton-client 0.1.0
client connect mode for L2 tunnel establishment
USAGE:
acton client [OPTIONS] <server>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-a, --address <address> tap ip network (a.b.c.d/n) [env: CLIENT_TAP_NETWORK=] [default: 0.0.0.0/0]
-m, --mac <mac> tap mac address (xx:xx:xx:xx:xx:xx) [env: CLIENT_TAP_MAC=] [default:
00:00:00:00:00:00]
-p, --port <port> server destination port [env: CLIENT_SERVER_PORT=] [default: 8080]
-t, --tap-name <tap-name> tap interface name [env: CLIENT_TAP_NAME=] [default: client]
ARGS:
<server> server destination address [env: CLIENT_SERVER_ADDRESS=]
Beware `-d`, interoperable with socat command
poc@r2:~/acton$ sudo ./acton client 192.168.99.11 -a 100.0.0.2/24 -t client -m 00:02:03:04:05:06
[2022-01-30T10:38:10Z INFO acton::client] client starts
[2022-01-30T10:38:10Z INFO acton::client] connected: 192.168.99.11:8080
ping测试
poc@r2:~/acton$ ping 100.0.0.1
PING 100.0.0.1 (100.0.0.1) 56(84) bytes of data.
64 bytes from 100.0.0.1: icmp_seq=1 ttl=64 time=0.971 ms
64 bytes from 100.0.0.1: icmp_seq=2 ttl=64 time=0.990 ms
64 bytes from 100.0.0.1: icmp_seq=3 ttl=64 time=1.05 ms
64 bytes from 100.0.0.1: icmp_seq=4 ttl=64 time=1.22 ms
64 bytes from 100.0.0.1: icmp_seq=5 ttl=64 time=0.875 ms
64 bytes from 100.0.0.1: icmp_seq=6 ttl=64 time=1.05 ms
^C
--- 100.0.0.1 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5064ms
rtt min/avg/max/mdev = 0.875/1.027/1.222/0.105 ms
poc@r2:~/acton$
依赖关系
~13–24MB
~338K SLoC