pub struct NetworkNamespace {
pub unix: Arc<AtomicRefCell<AbstractUnixNamespace>>,
pub localhost: RefCell<NetworkInterface>,
pub internet: RefCell<NetworkInterface>,
pub default_address: SyncSendPointer<Address>,
pub default_ip: Ipv4Addr,
/* private fields */
}
Expand description
Represents a network namespace.
Can be thought of as roughly equivalent to a Linux struct net
. Shadow doesn’t support multiple
network namespaces, but this NetworkNamespace
allows us to consolidate the host’s networking
objects, and hopefully might make it easier to support multiple network namespaces if we want to
in the future.
Fields§
§unix: Arc<AtomicRefCell<AbstractUnixNamespace>>
§localhost: RefCell<NetworkInterface>
§internet: RefCell<NetworkInterface>
§default_address: SyncSendPointer<Address>
§default_ip: Ipv4Addr
Implementations§
source§impl NetworkNamespace
impl NetworkNamespace
sourcepub unsafe fn new(
host_id: HostId,
hostname: Vec<NonZeroU8>,
public_ip: Ipv4Addr,
pcap: Option<PcapOptions>,
qdisc: QDiscMode,
dns: *mut DNS,
) -> Self
pub unsafe fn new( host_id: HostId, hostname: Vec<NonZeroU8>, public_ip: Ipv4Addr, pcap: Option<PcapOptions>, qdisc: QDiscMode, dns: *mut DNS, ) -> Self
§Safety
dns
must be a valid pointer.
sourcepub fn cleanup(&self, dns: &DNS)
pub fn cleanup(&self, dns: &DNS)
Clean up the network namespace. This should be called while Worker
has the active host
set. The dns
object should be the same object that was originally provided to
Self::new
.
sourcepub fn interface_borrow(
&self,
addr: Ipv4Addr,
) -> Option<impl Deref<Target = NetworkInterface> + '_>
pub fn interface_borrow( &self, addr: Ipv4Addr, ) -> Option<impl Deref<Target = NetworkInterface> + '_>
Returns None
if there is no such interface.
sourcepub fn interface_borrow_mut(
&self,
addr: Ipv4Addr,
) -> Option<impl DerefMut<Target = NetworkInterface> + '_>
pub fn interface_borrow_mut( &self, addr: Ipv4Addr, ) -> Option<impl DerefMut<Target = NetworkInterface> + '_>
Returns None
if there is no such interface.
pub fn is_addr_in_use( &self, protocol_type: ProtocolType, src: SocketAddrV4, dst: SocketAddrV4, ) -> Result<bool, NoInterface>
sourcepub fn get_random_free_port(
&self,
protocol_type: ProtocolType,
interface_ip: Ipv4Addr,
peer: SocketAddrV4,
rng: impl Rng,
) -> Option<u16>
pub fn get_random_free_port( &self, protocol_type: ProtocolType, interface_ip: Ipv4Addr, peer: SocketAddrV4, rng: impl Rng, ) -> Option<u16>
Returns a random port in host byte order.
sourcepub unsafe fn associate_interface(
&self,
socket: &InetSocket,
protocol: ProtocolType,
bind_addr: SocketAddrV4,
peer_addr: SocketAddrV4,
) -> AssociationHandle
pub unsafe fn associate_interface( &self, socket: &InetSocket, protocol: ProtocolType, bind_addr: SocketAddrV4, peer_addr: SocketAddrV4, ) -> AssociationHandle
Associate the socket with any applicable network interfaces. The socket will be automatically disassociated when the returned handle is dropped.
§Safety
Pointer args must be safely dereferenceable.
sourcepub fn disassociate_interface(
&self,
protocol: ProtocolType,
bind_addr: SocketAddrV4,
peer_addr: SocketAddrV4,
)
pub fn disassociate_interface( &self, protocol: ProtocolType, bind_addr: SocketAddrV4, peer_addr: SocketAddrV4, )
Disassociate the socket associated using the local and remote addresses from all network interfaces.
Is only public so that it can be called from host_disassociateInterface
. Normally this
should only be called from the AssociationHandle
.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for NetworkNamespace
impl !RefUnwindSafe for NetworkNamespace
impl Send for NetworkNamespace
impl !Sync for NetworkNamespace
impl Unpin for NetworkNamespace
impl !UnwindSafe for NetworkNamespace
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more