pub struct PortPools {
pub buckets: Vec<u64>,
/* private fields */
}
Expand description
Random Port
Recently, awareness has been raised about a number of “blind” attacks (i.e., attacks that can be performed without the need to sniff the packets that correspond to the transport protocol instance to be attacked) that can be performed against the Transmission Control Protocol (TCP) [RFC0793] and similar protocols. The consequences of these attacks range from throughput reduction to broken connections or data corruption [RFC5927] [RFC4953] [Watson].
All these attacks rely on the attacker’s ability to guess or know the five-tuple (Protocol, Source Address, Source port, Destination Address, Destination Port) that identifies the transport protocol instance to be attacked.
Services are usually located at fixed, “well-known” ports [IANA] at the host supplying the service (the server). Client applications connecting to any such service will contact the server by specifying the server IP address and service port number. The IP address and port number of the client are normally left unspecified by the client application and thus are chosen automatically by the client networking stack. Ports chosen automatically by the networking stack are known as ephemeral ports [Stevens].
While the server IP address, the well-known port, and the client IP address may be known by an attacker, the ephemeral port of the client is usually unknown and must be guessed.
Fields§
§buckets: Vec<u64>
Implementations§
Source§impl PortPools
impl PortPools
pub fn new() -> Self
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
get pools capacity.
§Examples
use turn_rs::router::ports::Bit;
use turn_rs::router::ports::PortPools;
let pools = PortPools::new();
assert_eq!(pools.capacity(), 65535 - 49152);
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
get pools allocated size.
use turn_rs::router::ports::PortPools;
let mut pools = PortPools::new();
assert_eq!(pools.len(), 0);
pools.alloc(None).unwrap();
assert_eq!(pools.len(), 1);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
get pools allocated size is empty.
use turn_rs::router::ports::PortPools;
let mut pools = PortPools::new();
assert_eq!(pools.len(), 0);
assert_eq!(pools.is_empty(), true);
Sourcepub fn alloc(&mut self, si: Option<usize>) -> Option<u16>
pub fn alloc(&mut self, si: Option<usize>) -> Option<u16>
random assign a port.
§Examples
use turn_rs::router::ports::PortPools;
let mut pool = PortPools::new();
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));
assert!(pool.alloc(None).is_some());
Sourcepub fn find_high(&self, i: usize) -> Option<u32>
pub fn find_high(&self, i: usize) -> Option<u32>
find the high bit in the bucket.
§Examples
use turn_rs::router::ports::PortPools;
let mut pool = PortPools::new();
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));
assert_eq!(pool.find_high(0), Some(2));
assert_eq!(pool.find_high(0), Some(2));
assert_eq!(pool.find_high(1), Some(0));
Sourcepub fn write(&mut self, offset: usize, i: usize, bit: Bit)
pub fn write(&mut self, offset: usize, i: usize, bit: Bit)
write bit flag in the bucket.
§Examples
use turn_rs::router::ports::Bit;
use turn_rs::router::ports::PortPools;
let mut pool = PortPools::new();
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));
pool.write(0, 0, Bit::High);
pool.write(0, 1, Bit::High);
assert_eq!(pool.alloc(Some(0)), Some(49154));
assert_eq!(pool.alloc(Some(0)), Some(49155));
Sourcepub fn read(&self, o: usize, i: usize) -> Bit
pub fn read(&self, o: usize, i: usize) -> Bit
read bucket bit value.
§Examples
use turn_rs::router::ports::Bit;
use turn_rs::router::ports::PortPools;
let mut pool = PortPools::new();
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));
assert_eq!(pool.find_high(0), Some(2));
assert_eq!(pool.find_high(1), Some(0));
pool.write(0, 0, Bit::High);
pool.write(0, 1, Bit::High);
assert_eq!(pool.alloc(Some(0)), Some(49154));
assert_eq!(pool.alloc(Some(0)), Some(49155));
pool.restore(49152);
pool.restore(49153);
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));
Sourcepub fn restore(&mut self, port: u16)
pub fn restore(&mut self, port: u16)
restore port in the buckets.
§Examples
use turn_rs::router::ports::PortPools;
let mut pool = PortPools::new();
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));
pool.restore(49152);
pool.restore(49153);
assert_eq!(pool.alloc(Some(0)), Some(49152));
assert_eq!(pool.alloc(Some(0)), Some(49153));