added register packet handle

This commit is contained in:
asxalex 2024-02-22 16:20:30 +08:00
parent 60ae19cfcf
commit 7e80578038
5 changed files with 38 additions and 2 deletions

View File

@ -63,6 +63,12 @@ sdlan协议的总体格式如下
"v4": [1,2,3,4],
// 如果family为10则v6有用一个16字节的数组表示ipv6地址
"v6": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
}
},
// data为二进制的字节数组为aes加密之后的tun流量。
"data": []
}
```
```
其中,`src_ip`为tun的ip数据包的来源ip`dst_ip`为tun的ip数据包的目的ip。均为大端序的32位无符号整数。`sock`为转发时由sn填充的发送客户端的信息发送短不需要处理。`data`为tun的数据流量使用`network_pass`进行加密后的二进制数据。
在发送packet数据包之前消息体部分的数据为json化之后的packet使用`header_pass`进行aes加密后的二进制数据。

View File

@ -81,6 +81,8 @@ pub enum PacketType {
PKTRegisterSuper,
// 数据转发
PKTPacket,
// 打洞消息
PKTRegister,
}
impl std::convert::From<u8> for PacketType {
@ -89,6 +91,7 @@ impl std::convert::From<u8> for PacketType {
// 0 => Self::PacketInvalid,
1 => Self::PKTRegisterSuper,
2 => Self::PKTPacket,
3 => Self::PKTRegister,
_ => Self::PKTInvalid,
}
}
@ -100,6 +103,7 @@ impl PacketType {
Self::PKTInvalid => 0,
Self::PKTRegisterSuper => 1,
Self::PKTPacket => 2,
Self::PKTRegister => 3,
}
}
}

View File

@ -6,3 +6,6 @@ pub use register_super::*;
mod packet;
pub use packet::*;
mod register;
pub use register::*;

15
src/packet/register.rs Normal file
View File

@ -0,0 +1,15 @@
use serde::{Deserialize, Serialize};
use crate::peer::{IpSubnet, SdlanSock};
#[derive(Serialize, Deserialize)]
pub struct Register {
// 源ip
pub src_ip: u32,
// 目的ip
pub dst_ip: u32,
// supernode转发时开到的发送者的外网ip信息
pub sock: SdlanSock,
// 发送者的tun的ip信息
pub dev_addr: IpSubnet,
}

View File

@ -101,6 +101,14 @@ pub fn is_multicast(ip: u32) -> bool {
first >= 224 && first <= 239
}
pub fn is_multi_broadcast(ip: u32) -> bool {
if ip == 0xffffffff {
return true;
}
let first = ((ip >> 24) & 0xff) as u8;
first >= 224 && first <= 239
}
pub fn ip_to_string(ip: u32) -> String {
format!(
"{}.{}.{}.{}",