Add a sinkhole to the server example.

v0.7.x
whitequark 2017-05-29 16:54:51 +00:00
parent 5bac3e5a02
commit 53be7a7747
2 changed files with 25 additions and 0 deletions

View File

@ -189,6 +189,8 @@ It responds to:
where it will respond "yo dawg" to any incoming connection and immediately close it;
* TCP packets on port 6970 (`socat stdio tcp4-connect:192.168.69.1:6970 <<<"abcdefg"`),
where it will respond with reversed chunks of the input indefinitely.
* TCP packets on port 6971 (`cat /dev/urandom | socat stdio tcp4-connect:192.168.69.1:6971`),
which will be ignored.
The buffers are only 64 bytes long, for convenience of testing resource exhaustion conditions.

View File

@ -35,6 +35,10 @@ fn main() {
let tcp2_tx_buffer = TcpSocketBuffer::new(vec![0; 128]);
let tcp2_socket = TcpSocket::new(tcp2_rx_buffer, tcp2_tx_buffer);
let tcp3_rx_buffer = TcpSocketBuffer::new(vec![0; 65535]);
let tcp3_tx_buffer = TcpSocketBuffer::new(vec![0; 65535]);
let tcp3_socket = TcpSocket::new(tcp3_rx_buffer, tcp3_tx_buffer);
let hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
let protocol_addrs = [IpAddress::v4(192, 168, 69, 1)];
let mut iface = EthernetInterface::new(
@ -45,6 +49,7 @@ fn main() {
let udp_handle = sockets.add(udp_socket);
let tcp1_handle = sockets.add(tcp1_socket);
let tcp2_handle = sockets.add(tcp2_socket);
let tcp3_handle = sockets.add(tcp3_socket);
let mut tcp_6970_active = false;
loop {
@ -125,6 +130,24 @@ fn main() {
}
}
// tcp:6971: sinkhole
{
let socket: &mut TcpSocket = sockets.get_mut(tcp3_handle).as_socket();
if !socket.is_open() {
socket.listen(6971).unwrap()
}
if socket.may_recv() {
if let Ok(data) = socket.recv(65535) {
if data.len() > 0 {
debug!("tcp:6971 recv {:?} octets", data.len());
}
}
} else if socket.may_send() {
socket.close();
}
}
let timestamp = Instant::now().duration_since(startup_time);
let timestamp_ms = (timestamp.as_secs() * 1000) +
(timestamp.subsec_nanos() / 1000000) as u64;