mirror of
https://github.com/dndx/phantun.git
synced 2025-07-02 07:06:06 +08:00
Let the memory allocator zero initialize the memory
This commit is contained in:
parent
f649c79656
commit
f06533f943
@ -15,7 +15,7 @@ packet oriented tunneling with minimum overhead.
|
||||
benchmark = []
|
||||
|
||||
[dependencies]
|
||||
bytes = "1"
|
||||
bytes = "1.2"
|
||||
pnet = "0.31"
|
||||
tokio = { version = "1.14", features = ["full"] }
|
||||
rand = { version = "0.8", features = ["small_rng"] }
|
||||
|
@ -436,8 +436,7 @@ impl Stack {
|
||||
let mut tuples: HashMap<AddrTuple, flume::Sender<Bytes>> = HashMap::new();
|
||||
|
||||
loop {
|
||||
let mut buf = BytesMut::with_capacity(MAX_PACKET_LEN);
|
||||
buf.resize(MAX_PACKET_LEN, 0);
|
||||
let mut buf = BytesMut::zeroed(MAX_PACKET_LEN);
|
||||
|
||||
tokio::select! {
|
||||
size = tun.recv(&mut buf) => {
|
||||
|
@ -47,8 +47,7 @@ pub fn build_tcp_packet(
|
||||
let tcp_header_len = TCP_HEADER_LEN + if wscale { 4 } else { 0 }; // nop + wscale
|
||||
let tcp_total_len = tcp_header_len + payload.map_or(0, |payload| payload.len());
|
||||
let total_len = ip_header_len + tcp_total_len;
|
||||
let mut buf = BytesMut::with_capacity(total_len);
|
||||
buf.resize(total_len, 0);
|
||||
let mut buf = BytesMut::zeroed(total_len);
|
||||
|
||||
let mut ip_buf = buf.split_to(ip_header_len);
|
||||
let mut tcp_buf = buf.split_to(tcp_total_len);
|
||||
|
Loading…
x
Reference in New Issue
Block a user