Clean up public re-exports under net/

This commit is contained in:
Ruihan Li
2025-06-12 23:07:47 +08:00
committed by Jianfeng Jiang
parent 86a7aa09eb
commit 639bc91e31
43 changed files with 128 additions and 129 deletions

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
use super::sched::PollScheduler;
use crate::net::socket::ip::{datagram::DatagramObserver, stream::StreamObserver};
use crate::net::socket::ip::{DatagramObserver, StreamObserver};
pub struct BigtcpExt;

View File

@ -2,7 +2,7 @@
use aster_bigtcp::wire::{IpAddress, IpEndpoint, Ipv4Address};
use crate::{net::socket::SocketAddr, prelude::*, return_errno_with_message};
use crate::{net::socket::util::SocketAddr, prelude::*, return_errno_with_message};
impl TryFrom<SocketAddr> for IpEndpoint {
type Error = Error;

View File

@ -9,7 +9,7 @@ use crate::{
events::IoEvents,
net::{
iface::{Iface, UdpSocket},
socket::util::{datagram_common, send_recv_flags::SendRecvFlags},
socket::util::{datagram_common, SendRecvFlags},
},
prelude::*,
util::{MultiRead, MultiWrite},

View File

@ -3,10 +3,10 @@
use core::sync::atomic::{AtomicBool, Ordering};
use aster_bigtcp::wire::IpEndpoint;
use unbound::BindOptions;
use bound::BoundDatagram;
use unbound::{BindOptions, UnboundDatagram};
use self::{bound::BoundDatagram, unbound::UnboundDatagram};
use super::UNSPECIFIED_LOCAL_ENDPOINT;
use super::addr::UNSPECIFIED_LOCAL_ENDPOINT;
use crate::{
events::IoEvents,
match_sock_option_mut,
@ -16,9 +16,7 @@ use crate::{
util::{
datagram_common::{select_remote_and_bind, Bound, Inner},
options::{SetSocketLevelOption, SocketOptionSet},
send_recv_flags::SendRecvFlags,
socket_addr::SocketAddr,
MessageHeader,
MessageHeader, SendRecvFlags, SocketAddr,
},
Socket,
},
@ -28,11 +26,9 @@ use crate::{
};
mod bound;
mod observer;
pub(super) mod observer;
mod unbound;
pub(in crate::net) use self::observer::DatagramObserver;
#[derive(Debug, Clone)]
struct OptionSet {
socket: SocketOptionSet,

View File

@ -2,7 +2,7 @@
use aster_bigtcp::{socket::UdpSocket, wire::IpEndpoint};
use super::{bound::BoundDatagram, DatagramObserver};
use super::{bound::BoundDatagram, observer::DatagramObserver};
use crate::{
events::IoEvents,
net::socket::{

View File

@ -2,8 +2,11 @@
mod addr;
mod common;
pub mod datagram;
mod datagram;
pub mod options;
pub mod stream;
mod stream;
use addr::UNSPECIFIED_LOCAL_ENDPOINT;
pub(in crate::net) use datagram::observer::DatagramObserver;
pub use datagram::DatagramSocket;
pub(in crate::net) use stream::observer::StreamObserver;
pub use stream::{options as stream_options, StreamSocket};

View File

@ -6,15 +6,12 @@ use aster_bigtcp::{
wire::IpEndpoint,
};
use super::StreamObserver;
use super::observer::StreamObserver;
use crate::{
events::IoEvents,
net::{
iface::{Iface, RawTcpSocketExt, TcpConnection},
socket::{
util::{send_recv_flags::SendRecvFlags, shutdown_cmd::SockShutdownCmd},
LingerOption,
},
socket::util::{LingerOption, SendRecvFlags, SockShutdownCmd},
},
prelude::*,
process::signal::{Pollee, Poller},

View File

@ -6,7 +6,7 @@ use aster_bigtcp::{
wire::IpEndpoint,
};
use super::{connected::ConnectedStream, init::InitStream, StreamObserver};
use super::{connected::ConnectedStream, init::InitStream, observer::StreamObserver};
use crate::{
events::IoEvents,
net::iface::{BoundPort, Iface, TcpConnection},

View File

@ -7,14 +7,14 @@ use core::{
use aster_bigtcp::{socket::RawTcpOption, wire::IpEndpoint};
use super::{connecting::ConnectingStream, listen::ListenStream, StreamObserver};
use super::{connecting::ConnectingStream, listen::ListenStream, observer::StreamObserver};
use crate::{
events::IoEvents,
net::{
iface::BoundPort,
socket::{
ip::common::{bind_port, get_ephemeral_endpoint},
SocketAddr,
util::SocketAddr,
},
},
prelude::*,

View File

@ -6,7 +6,7 @@ use aster_bigtcp::{
wire::IpEndpoint,
};
use super::{connected::ConnectedStream, StreamObserver};
use super::{connected::ConnectedStream, observer::StreamObserver};
use crate::{
events::IoEvents,
net::iface::{BoundPort, Iface, TcpListener},

View File

@ -10,6 +10,7 @@ use connected::{close_and_linger, ConnectedStream};
use connecting::{ConnResult, ConnectingStream};
use init::InitStream;
use listen::ListenStream;
use observer::StreamObserver;
use options::{
Congestion, DeferAccept, Inq, KeepIdle, MaxSegment, NoDelay, SynCnt, UserTimeout, WindowClamp,
KEEPALIVE_INTERVAL,
@ -19,8 +20,8 @@ use takeable::Takeable;
use util::{Retrans, TcpOptionSet};
use super::{
addr::UNSPECIFIED_LOCAL_ENDPOINT,
options::{IpOptionSet, SetIpLevelOption},
UNSPECIFIED_LOCAL_ENDPOINT,
};
use crate::{
events::IoEvents,
@ -33,10 +34,7 @@ use crate::{
private::SocketPrivate,
util::{
options::{SetSocketLevelOption, SocketOptionSet},
send_recv_flags::SendRecvFlags,
shutdown_cmd::SockShutdownCmd,
socket_addr::SocketAddr,
MessageHeader,
MessageHeader, SendRecvFlags, SockShutdownCmd, SocketAddr,
},
Socket,
},
@ -50,13 +48,10 @@ mod connected;
mod connecting;
mod init;
mod listen;
mod observer;
pub(super) mod observer;
pub mod options;
mod util;
pub(in crate::net) use self::observer::StreamObserver;
pub use self::util::CongestionControl;
pub struct StreamSocket {
// Lock order: `state` first, `options` second
state: RwLock<Takeable<State>, PreemptDisabled>,

View File

@ -1,7 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use super::CongestionControl;
use crate::impl_socket_options;
use crate::{impl_socket_options, prelude::*};
impl_socket_options!(
pub struct NoDelay(bool);
@ -15,6 +14,34 @@ impl_socket_options!(
pub struct Inq(bool);
);
#[derive(Debug, Clone, Copy)]
pub enum CongestionControl {
Reno,
Cubic,
}
impl CongestionControl {
const RENO: &'static str = "reno";
const CUBIC: &'static str = "cubic";
pub fn new(name: &str) -> Result<Self> {
let congestion = match name {
Self::RENO => Self::Reno,
Self::CUBIC => Self::Cubic,
_ => return_errno_with_message!(Errno::ENOENT, "unsupported congestion name"),
};
Ok(congestion)
}
pub fn name(&self) -> &'static str {
match self {
Self::Reno => Self::RENO,
Self::Cubic => Self::CUBIC,
}
}
}
/// The keepalive interval.
///
/// The linux value can be found at `/proc/sys/net/ipv4/tcp_keepalive_intvl`,

View File

@ -2,6 +2,7 @@
use aster_bigtcp::time::Duration;
use super::options::CongestionControl;
use crate::prelude::*;
#[derive(Debug, Clone, Copy, CopyGetters, Setters)]
@ -102,31 +103,3 @@ impl Retrans {
period
}
}
#[derive(Debug, Clone, Copy)]
pub enum CongestionControl {
Reno,
Cubic,
}
impl CongestionControl {
const RENO: &'static str = "reno";
const CUBIC: &'static str = "cubic";
pub fn new(name: &str) -> Result<Self> {
let congestion = match name {
Self::RENO => Self::Reno,
Self::CUBIC => Self::Cubic,
_ => return_errno_with_message!(Errno::ENOENT, "unsupported congestion name"),
};
Ok(congestion)
}
pub fn name(&self) -> &'static str {
match self {
Self::Reno => Self::RENO,
Self::Cubic => Self::CUBIC,
}
}
}

View File

@ -1,10 +1,8 @@
// SPDX-License-Identifier: MPL-2.0
use self::options::SocketOption;
pub use self::util::{
options::LingerOption, send_recv_flags::SendRecvFlags, shutdown_cmd::SockShutdownCmd,
socket_addr::SocketAddr, MessageHeader,
};
use options::SocketOption;
use util::{MessageHeader, SendRecvFlags, SockShutdownCmd, SocketAddr};
use crate::{
fs::{
file_handle::FileLike,
@ -18,7 +16,7 @@ pub mod ip;
pub mod netlink;
pub mod options;
pub mod unix;
mod util;
pub mod util;
pub mod vsock;
mod private {

View File

@ -4,7 +4,7 @@ mod multicast;
pub use multicast::{GroupIdSet, MAX_GROUPS};
use crate::{net::socket::SocketAddr, prelude::*};
use crate::{net::socket::util::SocketAddr, prelude::*};
/// The socket address of a netlink socket.
///

View File

@ -13,8 +13,11 @@ use crate::{
netlink::{table::SupportedNetlinkProtocol, AddMembership, DropMembership},
options::SocketOption,
private::SocketPrivate,
util::datagram_common::{select_remote_and_bind, Bound, Inner},
MessageHeader, SendRecvFlags, Socket, SocketAddr,
util::{
datagram_common::{select_remote_and_bind, Bound, Inner},
MessageHeader, SendRecvFlags, SocketAddr,
},
Socket,
},
prelude::*,
process::signal::{PollHandle, Pollable, Pollee},

View File

@ -7,8 +7,7 @@ use crate::{
events::IoEvents,
net::socket::{
netlink::{common::BoundNetlink, NetlinkSocketAddr},
util::datagram_common,
SendRecvFlags,
util::{datagram_common, SendRecvFlags},
},
prelude::*,
util::{MultiRead, MultiWrite},

View File

@ -18,7 +18,8 @@ use crate::{
table::{NetlinkUeventProtocol, SupportedNetlinkProtocol},
GroupIdSet, NetlinkSocketAddr, NetlinkUeventSocket,
},
SendRecvFlags, Socket, SocketAddr,
util::{SendRecvFlags, SocketAddr},
Socket,
},
prelude::*,
};

View File

@ -10,8 +10,7 @@ use crate::{
common::BoundNetlink, message::ProtocolSegment,
route::kernel::get_netlink_route_kernel, NetlinkSocketAddr,
},
util::datagram_common,
SendRecvFlags,
util::{datagram_common, SendRecvFlags},
},
prelude::*,
util::{MultiRead, MultiWrite},

View File

@ -1,9 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
use super::util::LingerOption;
use crate::{impl_socket_options, prelude::*};
mod macros;
use super::LingerOption;
mod macros;
/// Socket options. This trait represents all options that can be set or got for a socket, including
/// socket level options and options for specific socket type like tcp socket.

View File

@ -5,7 +5,7 @@ use keyable_arc::KeyableArc;
use super::ns::{self, AbstractHandle};
use crate::{
fs::{path::Dentry, utils::Inode},
net::socket::util::socket_addr::SocketAddr,
net::socket::util::SocketAddr,
prelude::*,
};

View File

@ -9,7 +9,7 @@ use crate::{
fs::utils::{Channel, Consumer, Producer},
net::socket::{
unix::{addr::UnixSocketAddrBound, UnixSocketAddr},
SockShutdownCmd,
util::SockShutdownCmd,
},
prelude::*,
process::signal::{PollHandle, Pollee},

View File

@ -10,7 +10,7 @@ use crate::{
events::IoEvents,
net::socket::{
unix::addr::{UnixSocketAddr, UnixSocketAddrBound},
SockShutdownCmd,
util::SockShutdownCmd,
},
prelude::*,
process::signal::{PollHandle, Pollee},

View File

@ -14,7 +14,7 @@ use crate::{
fs::file_handle::FileLike,
net::socket::{
unix::addr::{UnixSocketAddrBound, UnixSocketAddrKey},
SockShutdownCmd, SocketAddr,
util::{SockShutdownCmd, SocketAddr},
},
prelude::*,
process::signal::{PollHandle, Pollee},

View File

@ -15,8 +15,8 @@ use crate::{
net::socket::{
private::SocketPrivate,
unix::UnixSocketAddr,
util::{send_recv_flags::SendRecvFlags, socket_addr::SocketAddr, MessageHeader},
SockShutdownCmd, Socket,
util::{MessageHeader, SendRecvFlags, SockShutdownCmd, SocketAddr},
Socket,
},
prelude::*,
process::signal::{PollHandle, Pollable},

View File

@ -2,7 +2,7 @@
use ostd::sync::RwMutex;
use super::send_recv_flags::SendRecvFlags;
use super::SendRecvFlags;
use crate::{
events::IoEvents,
process::signal::Pollee,

View File

@ -0,0 +1,23 @@
// SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
#[derive(Debug, Default, Clone, Copy)]
pub struct LingerOption {
is_on: bool,
timeout: Duration,
}
impl LingerOption {
pub fn new(is_on: bool, timeout: Duration) -> Self {
Self { is_on, timeout }
}
pub fn is_on(&self) -> bool {
self.is_on
}
pub fn timeout(&self) -> Duration {
self.timeout
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use super::socket_addr::SocketAddr;
use super::SocketAddr;
use crate::prelude::*;
/// Message header used for sendmsg/recvmsg.

View File

@ -1,10 +1,15 @@
// SPDX-License-Identifier: MPL-2.0
pub mod datagram_common;
pub(super) mod datagram_common;
mod linger_option;
mod message_header;
pub mod options;
pub mod send_recv_flags;
pub mod shutdown_cmd;
pub mod socket_addr;
pub(super) mod options;
mod send_recv_flags;
mod shutdown_cmd;
mod socket_addr;
pub use linger_option::LingerOption;
pub use message_header::MessageHeader;
pub use send_recv_flags::SendRecvFlags;
pub use shutdown_cmd::SockShutdownCmd;
pub use socket_addr::SocketAddr;

View File

@ -1,11 +1,10 @@
// SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
use aster_bigtcp::socket::{
NeedIfacePoll, TCP_RECV_BUF_LEN, TCP_SEND_BUF_LEN, UDP_RECV_PAYLOAD_LEN, UDP_SEND_PAYLOAD_LEN,
};
use super::LingerOption;
use crate::{
match_sock_option_mut, match_sock_option_ref,
net::socket::options::{
@ -137,26 +136,6 @@ impl SocketOptionSet {
pub const MIN_SENDBUF: u32 = 2304;
pub const MIN_RECVBUF: u32 = 2304;
#[derive(Debug, Default, Clone, Copy)]
pub struct LingerOption {
is_on: bool,
timeout: Duration,
}
impl LingerOption {
pub fn new(is_on: bool, timeout: Duration) -> Self {
Self { is_on, timeout }
}
pub fn is_on(&self) -> bool {
self.is_on
}
pub fn timeout(&self) -> Duration {
self.timeout
}
}
/// A trait used for setting socket level options on actual sockets.
pub(in crate::net) trait SetSocketLevelOption {
/// Sets whether keepalive messages are enabled.

View File

@ -2,7 +2,7 @@
use aster_virtio::device::socket::header::VsockDeviceAddr;
use crate::{net::socket::SocketAddr, prelude::*};
use crate::{net::socket::util::SocketAddr, prelude::*};
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct VsockSocketAddr {

View File

@ -6,8 +6,8 @@ use super::connecting::Connecting;
use crate::{
events::IoEvents,
net::socket::{
util::{SendRecvFlags, SockShutdownCmd},
vsock::{addr::VsockSocketAddr, VSOCK_GLOBAL},
SendRecvFlags, SockShutdownCmd,
},
prelude::*,
process::signal::{PollHandle, Pollee},

View File

@ -8,8 +8,9 @@ use crate::{
fs::file_handle::FileLike,
net::socket::{
private::SocketPrivate,
util::{MessageHeader, SendRecvFlags, SockShutdownCmd, SocketAddr},
vsock::{addr::VsockSocketAddr, VSOCK_GLOBAL},
MessageHeader, SendRecvFlags, SockShutdownCmd, Socket, SocketAddr,
Socket,
},
prelude::*,
process::signal::{PollHandle, Pollable, Poller},

View File

@ -3,7 +3,7 @@
use super::SyscallReturn;
use crate::{
fs::file_table::{get_file_fast, FileDesc},
net::socket::SendRecvFlags,
net::socket::util::SendRecvFlags,
prelude::*,
util::net::write_socket_addr_to_user,
};

View File

@ -3,7 +3,7 @@
use super::SyscallReturn;
use crate::{
fs::file_table::{get_file_fast, FileDesc},
net::socket::SendRecvFlags,
net::socket::util::SendRecvFlags,
prelude::*,
util::net::CUserMsgHdr,
};

View File

@ -3,7 +3,7 @@
use super::SyscallReturn;
use crate::{
fs::file_table::{get_file_fast, FileDesc},
net::socket::{MessageHeader, SendRecvFlags},
net::socket::util::{MessageHeader, SendRecvFlags},
prelude::*,
util::net::CUserMsgHdr,
};

View File

@ -3,7 +3,7 @@
use super::SyscallReturn;
use crate::{
fs::file_table::{get_file_fast, FileDesc},
net::socket::{MessageHeader, SendRecvFlags},
net::socket::util::{MessageHeader, SendRecvFlags},
prelude::*,
util::net::read_socket_addr_from_user,
};

View File

@ -3,7 +3,7 @@
use super::SyscallReturn;
use crate::{
fs::file_table::{get_file_fast, FileDesc},
net::socket::SockShutdownCmd,
net::socket::util::SockShutdownCmd,
prelude::*,
};

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{file_handle::FileLike, file_table::FdFlags},
net::socket::{
ip::{datagram::DatagramSocket, stream::StreamSocket},
ip::{DatagramSocket, StreamSocket},
netlink::{
is_valid_protocol, NetlinkRouteSocket, NetlinkUeventSocket, StandardNetlinkProtocol,
},

View File

@ -5,7 +5,7 @@ use core::cmp::min;
use ostd::task::Task;
use super::{ip::CSocketAddrInet, netlink::CSocketAddrNetlink, unix, vsock::CSocketAddrVm};
use crate::{current_userspace, net::socket::SocketAddr, prelude::*};
use crate::{current_userspace, net::socket::util::SocketAddr, prelude::*};
/// Address family.
///

View File

@ -3,7 +3,7 @@
use super::RawSocketOption;
use crate::{
impl_raw_socket_option,
net::socket::ip::stream::options::{
net::socket::ip::stream_options::{
Congestion, DeferAccept, Inq, KeepIdle, MaxSegment, NoDelay, SynCnt, UserTimeout,
WindowClamp,
},

View File

@ -5,8 +5,8 @@ use core::{num::NonZeroU8, time::Duration};
use crate::{
current_userspace,
net::socket::{
ip::{options::IpTtl, stream::CongestionControl},
LingerOption,
ip::{options::IpTtl, stream_options::CongestionControl},
util::LingerOption,
},
prelude::*,
};

View File

@ -2,7 +2,7 @@
use super::read_socket_addr_from_user;
use crate::{
net::socket::SocketAddr,
net::socket::util::SocketAddr,
prelude::*,
util::{net::write_socket_addr_with_max_len, VmReaderArray, VmWriterArray},
};