mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 02:13:24 +00:00
Move IpEndpoint
to socket/ip/addr.rs
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
b11628b9ce
commit
d814603504
@ -1,7 +1,11 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{Iface, IpAddress, IpEndpoint};
|
||||
use crate::{events::Observer, prelude::*};
|
||||
use super::Iface;
|
||||
use crate::{
|
||||
events::Observer,
|
||||
net::socket::ip::{IpAddress, IpEndpoint},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
pub type RawTcpSocket = smoltcp::socket::tcp::Socket<'static>;
|
||||
pub type RawUdpSocket = smoltcp::socket::udp::Socket<'static>;
|
||||
|
@ -15,9 +15,9 @@ use super::{
|
||||
any_socket::{AnyBoundSocketInner, AnyRawSocket, AnyUnboundSocket, SocketFamily},
|
||||
time::get_network_timestamp,
|
||||
util::BindPortConfig,
|
||||
AnyBoundSocket, Iface, Ipv4Address,
|
||||
AnyBoundSocket, Iface,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
use crate::{net::socket::ip::Ipv4Address, prelude::*};
|
||||
|
||||
pub struct IfaceCommon {
|
||||
interface: SpinLock<smoltcp::iface::Interface>,
|
||||
|
@ -6,8 +6,11 @@ use smoltcp::{
|
||||
wire::IpCidr,
|
||||
};
|
||||
|
||||
use super::{common::IfaceCommon, internal::IfaceInternal, Iface, IpAddress, Ipv4Address};
|
||||
use crate::prelude::*;
|
||||
use super::{common::IfaceCommon, internal::IfaceInternal, Iface};
|
||||
use crate::{
|
||||
net::socket::ip::{IpAddress, Ipv4Address},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
pub const LOOPBACK_ADDRESS: IpAddress = {
|
||||
let ipv4_addr = Ipv4Address::new(127, 0, 0, 1);
|
||||
|
@ -17,10 +17,12 @@ pub use any_socket::{
|
||||
AnyBoundSocket, AnyUnboundSocket, RawTcpSocket, RawUdpSocket, RECV_BUF_LEN, SEND_BUF_LEN,
|
||||
};
|
||||
pub use loopback::IfaceLoopback;
|
||||
pub use smoltcp::wire::{EthernetAddress, IpAddress, IpEndpoint, Ipv4Address};
|
||||
pub use smoltcp::wire::EthernetAddress;
|
||||
pub use util::{spawn_background_poll_thread, BindPortConfig};
|
||||
pub use virtio::IfaceVirtio;
|
||||
|
||||
use crate::net::socket::ip::Ipv4Address;
|
||||
|
||||
/// Network interface.
|
||||
///
|
||||
/// A network interface (abbreviated as iface) is a hardware or software component that connects a device or computer to a network.
|
||||
|
31
kernel/aster-nix/src/net/socket/ip/addr.rs
Normal file
31
kernel/aster-nix/src/net/socket/ip/addr.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
pub use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address};
|
||||
|
||||
use crate::{net::socket::SocketAddr, prelude::*, return_errno_with_message};
|
||||
|
||||
pub type PortNum = u16;
|
||||
|
||||
impl TryFrom<SocketAddr> for IpEndpoint {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: SocketAddr) -> Result<Self> {
|
||||
match value {
|
||||
SocketAddr::IPv4(addr, port) => Ok(IpEndpoint::new(addr.into_address(), port)),
|
||||
_ => return_errno_with_message!(
|
||||
Errno::EAFNOSUPPORT,
|
||||
"the address is in an unsupported address family"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IpEndpoint> for SocketAddr {
|
||||
fn from(endpoint: IpEndpoint) -> Self {
|
||||
let port = endpoint.port;
|
||||
match endpoint.addr {
|
||||
IpAddress::Ipv4(addr) => SocketAddr::IPv4(addr, port),
|
||||
// TODO: support IPv6
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{IpAddress, IpEndpoint};
|
||||
use crate::{
|
||||
net::{
|
||||
iface::{AnyBoundSocket, AnyUnboundSocket, BindPortConfig, Iface, IpAddress, IpEndpoint},
|
||||
iface::{AnyBoundSocket, AnyUnboundSocket, BindPortConfig, Iface},
|
||||
IFACES,
|
||||
},
|
||||
prelude::*,
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
use smoltcp::socket::udp::{RecvError, SendError};
|
||||
|
||||
use super::IpEndpoint;
|
||||
use crate::{
|
||||
events::IoEvents,
|
||||
net::{
|
||||
iface::{AnyBoundSocket, IpEndpoint, RawUdpSocket},
|
||||
iface::{AnyBoundSocket, RawUdpSocket},
|
||||
socket::util::send_recv_flags::SendRecvFlags,
|
||||
},
|
||||
prelude::*,
|
||||
|
@ -5,12 +5,11 @@ use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use takeable::Takeable;
|
||||
|
||||
use self::{bound::BoundDatagram, unbound::UnboundDatagram};
|
||||
use super::{common::get_ephemeral_endpoint, UNSPECIFIED_LOCAL_ENDPOINT};
|
||||
use super::{common::get_ephemeral_endpoint, IpEndpoint, UNSPECIFIED_LOCAL_ENDPOINT};
|
||||
use crate::{
|
||||
events::{IoEvents, Observer},
|
||||
fs::{file_handle::FileLike, utils::StatusFlags},
|
||||
net::{
|
||||
iface::IpEndpoint,
|
||||
poll_ifaces,
|
||||
socket::{
|
||||
util::{
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
use alloc::sync::Weak;
|
||||
|
||||
use super::bound::BoundDatagram;
|
||||
use super::{bound::BoundDatagram, IpEndpoint};
|
||||
use crate::{
|
||||
events::{IoEvents, Observer},
|
||||
net::{
|
||||
iface::{AnyUnboundSocket, IpEndpoint, RawUdpSocket},
|
||||
iface::{AnyUnboundSocket, RawUdpSocket},
|
||||
socket::ip::common::bind_socket,
|
||||
},
|
||||
prelude::*,
|
||||
|
@ -1,11 +1,11 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::net::iface::{IpAddress, IpEndpoint, Ipv4Address};
|
||||
|
||||
mod addr;
|
||||
mod common;
|
||||
mod datagram;
|
||||
pub mod stream;
|
||||
|
||||
pub use addr::{IpAddress, IpEndpoint, Ipv4Address, PortNum};
|
||||
pub use datagram::DatagramSocket;
|
||||
pub use stream::StreamSocket;
|
||||
|
||||
|
@ -4,10 +4,11 @@ use alloc::sync::Weak;
|
||||
|
||||
use smoltcp::socket::tcp::{RecvError, SendError};
|
||||
|
||||
use super::IpEndpoint;
|
||||
use crate::{
|
||||
events::{IoEvents, Observer},
|
||||
net::{
|
||||
iface::{AnyBoundSocket, IpEndpoint, RawTcpSocket},
|
||||
iface::{AnyBoundSocket, RawTcpSocket},
|
||||
socket::util::{send_recv_flags::SendRecvFlags, shutdown_cmd::SockShutdownCmd},
|
||||
},
|
||||
prelude::*,
|
||||
|
@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{connected::ConnectedStream, init::InitStream};
|
||||
use super::{connected::ConnectedStream, init::InitStream, IpEndpoint};
|
||||
use crate::{
|
||||
net::iface::{AnyBoundSocket, IpEndpoint, RawTcpSocket},
|
||||
net::iface::{AnyBoundSocket, RawTcpSocket},
|
||||
prelude::*,
|
||||
process::signal::Pollee,
|
||||
};
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
use alloc::sync::Weak;
|
||||
|
||||
use super::{connecting::ConnectingStream, listen::ListenStream};
|
||||
use super::{connecting::ConnectingStream, listen::ListenStream, IpEndpoint};
|
||||
use crate::{
|
||||
events::{IoEvents, Observer},
|
||||
net::{
|
||||
iface::{AnyBoundSocket, AnyUnboundSocket, IpEndpoint},
|
||||
iface::{AnyBoundSocket, AnyUnboundSocket},
|
||||
socket::ip::common::{bind_socket, get_ephemeral_endpoint},
|
||||
},
|
||||
prelude::*,
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
use smoltcp::socket::tcp::ListenError;
|
||||
|
||||
use super::connected::ConnectedStream;
|
||||
use super::{connected::ConnectedStream, IpEndpoint};
|
||||
use crate::{
|
||||
events::IoEvents,
|
||||
net::iface::{AnyBoundSocket, AnyUnboundSocket, BindPortConfig, IpEndpoint, RawTcpSocket},
|
||||
net::iface::{AnyBoundSocket, AnyUnboundSocket, BindPortConfig, RawTcpSocket},
|
||||
prelude::*,
|
||||
process::signal::Pollee,
|
||||
};
|
||||
|
@ -1,15 +1,14 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{
|
||||
net::{
|
||||
iface::{IpAddress, IpEndpoint, Ipv4Address},
|
||||
socket::{unix::UnixSocketAddr, vsock::addr::VsockSocketAddr},
|
||||
net::socket::{
|
||||
ip::{Ipv4Address, PortNum},
|
||||
unix::UnixSocketAddr,
|
||||
vsock::addr::VsockSocketAddr,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
type PortNum = u16;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum SocketAddr {
|
||||
Unix(UnixSocketAddr),
|
||||
@ -17,27 +16,3 @@ pub enum SocketAddr {
|
||||
IPv6,
|
||||
Vsock(VsockSocketAddr),
|
||||
}
|
||||
|
||||
impl TryFrom<SocketAddr> for IpEndpoint {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: SocketAddr) -> Result<Self> {
|
||||
match value {
|
||||
SocketAddr::IPv4(addr, port) => Ok(IpEndpoint::new(addr.into_address(), port)),
|
||||
_ => return_errno_with_message!(
|
||||
Errno::EAFNOSUPPORT,
|
||||
"the address is in an unsupported address family"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IpEndpoint> for SocketAddr {
|
||||
fn from(endpoint: IpEndpoint) -> Self {
|
||||
let port = endpoint.port;
|
||||
match endpoint.addr {
|
||||
IpAddress::Ipv4(addr) => SocketAddr::IPv4(addr, port),
|
||||
// TODO: support IPv6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,7 @@
|
||||
#![allow(unused_variables)]
|
||||
|
||||
use crate::{
|
||||
net::{
|
||||
iface::Ipv4Address,
|
||||
socket::{unix::UnixSocketAddr, vsock::VsockSocketAddr, SocketAddr},
|
||||
},
|
||||
net::socket::{ip::Ipv4Address, unix::UnixSocketAddr, vsock::VsockSocketAddr, SocketAddr},
|
||||
prelude::*,
|
||||
util::{read_bytes_from_user, read_val_from_user, write_val_to_user},
|
||||
};
|
||||
|
Reference in New Issue
Block a user