Skip to content

Commit 4edb292

Browse files
committed
fix dns early data problem
1 parent 24652cb commit 4edb292

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/server/connection.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::io::Write;
12
use std::net::SocketAddr;
23
use std::time::Instant;
34

@@ -33,6 +34,7 @@ pub struct Connection {
3334
backend: Option<Box<dyn Backend>>,
3435
closing: bool,
3536
target_addr: Option<SocketAddr>,
37+
data: Vec<u8>,
3638
}
3739

3840
impl Connection {
@@ -48,6 +50,7 @@ impl Connection {
4850
backend: None,
4951
closing: false,
5052
target_addr: None,
53+
data: Vec::new(),
5154
}
5255
}
5356

@@ -207,12 +210,22 @@ impl Connection {
207210
}
208211
Status::DnsWait => {
209212
if self.command == CONNECT {
213+
//if dns query is not done, cache data now
214+
if let Err(err) = self.data.write(buffer) {
215+
log::warn!("connection:{} cache data failed", self.index);
216+
self.closing = true;
217+
return;
218+
} else {
219+
buffer = &[];
220+
}
221+
210222
if self.target_addr.is_none() {
211223
log::warn!("connection:{} dns query not done yet", self.index);
212224
return;
213225
}
214226

215227
if self.try_setup_tcp_target(opts, poll) {
228+
buffer = self.data.as_slice();
216229
self.status = Status::TCPForward;
217230
} else {
218231
return;

0 commit comments

Comments
 (0)