mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 16:13:27 +00:00
Rename crates from jinux-* to aster-*
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
6dbf5d560d
commit
93781df27b
4
services/libs/aster-std/src/net/socket/util/mod.rs
Normal file
4
services/libs/aster-std/src/net/socket/util/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub mod send_recv_flags;
|
||||
pub mod shutdown_cmd;
|
||||
pub mod sock_options;
|
||||
pub mod sockaddr;
|
@ -0,0 +1,45 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
bitflags! {
|
||||
/// Flags used for send/recv.
|
||||
/// The definiton is from https://elixir.bootlin.com/linux/v6.0.9/source/include/linux/socket.h
|
||||
#[repr(C)]
|
||||
#[derive(Pod)]
|
||||
pub struct SendRecvFlags: i32 {
|
||||
const MSG_OOB = 1;
|
||||
const MSG_PEEK = 2;
|
||||
const MSG_DONTROUTE = 4;
|
||||
// const MSG_TRYHARD = 4; /* Synonym for MSG_DONTROUTE for DECnet */
|
||||
const MSG_CTRUNC = 8;
|
||||
const MSG_PROBE = 0x10; /* Do not send. Only probe path f.e. for MTU */
|
||||
const MSG_TRUNC = 0x20;
|
||||
const MSG_DONTWAIT = 0x40; /* Nonblocking io */
|
||||
const MSG_EOR = 0x80; /* End of record */
|
||||
const MSG_WAITALL = 0x100; /* Wait for a full request */
|
||||
const MSG_FIN = 0x200;
|
||||
const MSG_SYN = 0x400;
|
||||
const MSG_CONFIRM = 0x800; /* Confirm path validity */
|
||||
const MSG_RST = 0x1000;
|
||||
const MSG_ERRQUEUE = 0x2000; /* Fetch message from error queue */
|
||||
const MSG_NOSIGNAL = 0x4000; /* Do not generate SIGPIPE */
|
||||
const MSG_MORE = 0x8000; /* Sender will send more */
|
||||
const MSG_WAITFORONE = 0x10000; /* recvmmsg(): block until 1+ packets avail */
|
||||
const MSG_SENDPAGE_NOPOLICY = 0x10000; /* sendpage() internal : do no apply policy */
|
||||
const MSG_SENDPAGE_NOTLAST = 0x20000; /* sendpage() internal : not the last page */
|
||||
const MSG_BATCH = 0x40000; /* sendmmsg(): more messages coming */
|
||||
// const MSG_EOF MSG_FIN
|
||||
const MSG_NO_SHARED_FRAGS = 0x80000; /* sendpage() internal : page frags are not shared */
|
||||
const MSG_SENDPAGE_DECRYPTED = 0x100000; /* sendpage() internal : page may carry plain text and require encryption */
|
||||
}
|
||||
}
|
||||
|
||||
impl SendRecvFlags {
|
||||
fn supported_flags() -> Self {
|
||||
SendRecvFlags::empty()
|
||||
}
|
||||
|
||||
pub fn is_all_supported(&self) -> bool {
|
||||
let supported_flags = Self::supported_flags();
|
||||
supported_flags.contains(*self)
|
||||
}
|
||||
}
|
25
services/libs/aster-std/src/net/socket/util/shutdown_cmd.rs
Normal file
25
services/libs/aster-std/src/net/socket/util/shutdown_cmd.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Shutdown types
|
||||
/// From https://elixir.bootlin.com/linux/v6.0.9/source/include/linux/net.h
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, TryFromInt)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum SockShutdownCmd {
|
||||
/// Shutdown receptions
|
||||
SHUT_RD = 0,
|
||||
/// Shutdown transmissions
|
||||
SHUT_WR = 1,
|
||||
/// Shutdown receptions and transmissions
|
||||
SHUT_RDWR = 2,
|
||||
}
|
||||
|
||||
impl SockShutdownCmd {
|
||||
pub fn shut_read(&self) -> bool {
|
||||
*self == Self::SHUT_RD || *self == Self::SHUT_RDWR
|
||||
}
|
||||
|
||||
pub fn shut_write(&self) -> bool {
|
||||
*self == Self::SHUT_WR || *self == Self::SHUT_RDWR
|
||||
}
|
||||
}
|
41
services/libs/aster-std/src/net/socket/util/sock_options.rs
Normal file
41
services/libs/aster-std/src/net/socket/util/sock_options.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
/// The definition is from https://elixir.bootlin.com/linux/v6.0.9/source/include/uapi/asm-generic/socket.h.
|
||||
/// We do not include all options here
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, TryFromInt, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum SockOptionName {
|
||||
SO_DEBUG = 1,
|
||||
SO_REUSEADDR = 2,
|
||||
SO_TYPE = 3,
|
||||
SO_ERROR = 4,
|
||||
SO_DONTROUTE = 5,
|
||||
SO_BROADCAST = 6,
|
||||
SO_SNDBUF = 7,
|
||||
SO_RCVBUF = 8,
|
||||
SO_SNDBUFFORCE = 32,
|
||||
SO_RCVBUFFORCE = 33,
|
||||
SO_KEEPALIVE = 9,
|
||||
SO_OOBINLINE = 10,
|
||||
SO_NO_CHECK = 11,
|
||||
SO_PRIORITY = 12,
|
||||
SO_LINGER = 13,
|
||||
SO_BSDCOMPAT = 14,
|
||||
SO_REUSEPORT = 15,
|
||||
SO_RCVTIMEO_NEW = 66,
|
||||
SO_SNDTIMEO_NEW = 67,
|
||||
}
|
||||
|
||||
/// Sock Opt level. The definition is from https://elixir.bootlin.com/linux/v6.0.9/source/include/linux/socket.h#L343
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, TryFromInt, PartialEq, Eq)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum SockOptionLevel {
|
||||
SOL_IP = 0,
|
||||
SOL_SOCKET = 1,
|
||||
SOL_TCP = 6,
|
||||
SOL_UDP = 17,
|
||||
SOL_IPV6 = 41,
|
||||
SOL_RAW = 255,
|
||||
}
|
52
services/libs/aster-std/src/net/socket/util/sockaddr.rs
Normal file
52
services/libs/aster-std/src/net/socket/util/sockaddr.rs
Normal file
@ -0,0 +1,52 @@
|
||||
use crate::net::iface::{IpAddress, Ipv4Address};
|
||||
use crate::net::iface::{IpEndpoint, IpListenEndpoint};
|
||||
use crate::net::socket::unix::UnixSocketAddr;
|
||||
use crate::prelude::*;
|
||||
|
||||
type PortNum = u16;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SocketAddr {
|
||||
Unix(UnixSocketAddr),
|
||||
IPv4(Ipv4Address, PortNum),
|
||||
IPv6,
|
||||
}
|
||||
|
||||
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::EINVAL,
|
||||
"sock addr cannot be converted as IpEndpoint"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IpEndpoint> for SocketAddr {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(endpoint: IpEndpoint) -> Result<Self> {
|
||||
let port = endpoint.port;
|
||||
let socket_addr = match endpoint.addr {
|
||||
IpAddress::Ipv4(addr) => SocketAddr::IPv4(addr, port), // TODO: support IPv6
|
||||
};
|
||||
Ok(socket_addr)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IpListenEndpoint> for SocketAddr {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: IpListenEndpoint) -> Result<Self> {
|
||||
let port = value.port;
|
||||
let socket_addr = match value.addr {
|
||||
None => return_errno_with_message!(Errno::EINVAL, "address is unspecified"),
|
||||
Some(IpAddress::Ipv4(address)) => SocketAddr::IPv4(address, port),
|
||||
};
|
||||
Ok(socket_addr)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user