ready for merge in master (#964)

uevent should be format

Enum of smoltcp socket should be optimized.

need to add interface for routing subsys

actix is still not abled to run.

clean some casual added code to other places
This commit is contained in:
2024-10-10 17:53:39 +08:00
committed by GitHub
parent 79eda4bcf9
commit 40d9375b6b
102 changed files with 10497 additions and 3303 deletions

View File

@ -0,0 +1,76 @@
const SOL_SOCKET: u16 = 1;
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive, PartialEq, Eq)]
pub enum IPProtocol {
/// Dummy protocol for TCP.
IP = 0,
/// Internet Control Message Protocol.
ICMP = 1,
/// Internet Group Management Protocol.
IGMP = 2,
/// IPIP tunnels (older KA9Q tunnels use 94).
IPIP = 4,
/// Transmission Control Protocol.
TCP = 6,
/// Exterior Gateway Protocol.
EGP = 8,
/// PUP protocol.
PUP = 12,
/// User Datagram Protocol.
UDP = 17,
/// XNS IDP protocol.
IDP = 22,
/// SO Transport Protocol Class 4.
TP = 29,
/// Datagram Congestion Control Protocol.
DCCP = 33,
/// IPv6-in-IPv4 tunnelling.
IPv6 = 41,
/// RSVP Protocol.
RSVP = 46,
/// Generic Routing Encapsulation. (Cisco GRE) (rfc 1701, 1702)
GRE = 47,
/// Encapsulation Security Payload protocol
ESP = 50,
/// Authentication Header protocol
AH = 51,
/// Multicast Transport Protocol.
MTP = 92,
/// IP option pseudo header for BEET
BEETPH = 94,
/// Encapsulation Header.
ENCAP = 98,
/// Protocol Independent Multicast.
PIM = 103,
/// Compression Header Protocol.
COMP = 108,
/// Stream Control Transport Protocol
SCTP = 132,
/// UDP-Lite protocol (RFC 3828)
UDPLITE = 136,
/// MPLS in IP (RFC 4023)
MPLSINIP = 137,
/// Ethernet-within-IPv6 Encapsulation
ETHERNET = 143,
/// Raw IP packets
RAW = 255,
/// Multipath TCP connection
MPTCP = 262,
}
impl TryFrom<u16> for IPProtocol {
type Error = system_error::SystemError;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match <Self as num_traits::FromPrimitive>::from_u16(value) {
Some(p) => Ok(p),
None => Err(system_error::SystemError::EPROTONOSUPPORT),
}
}
}
impl From<IPProtocol> for u16 {
fn from(value: IPProtocol) -> Self {
<IPProtocol as num_traits::ToPrimitive>::to_u16(&value).unwrap()
}
}

View File

@ -0,0 +1,32 @@
mod option;
pub use option::Options;
mod option_level;
pub use option_level::OptionsLevel;
mod msg_flag;
pub use msg_flag::MessageFlag;
mod ipproto;
pub use ipproto::IPProtocol;
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum Type {
Stream = 1,
Datagram = 2,
Raw = 3,
RDM = 4,
SeqPacket = 5,
DCCP = 6,
Packet = 10,
}
use crate::net::syscall_util::SysArgSocketType;
impl TryFrom<SysArgSocketType> for Type {
type Error = system_error::SystemError;
fn try_from(x: SysArgSocketType) -> Result<Self, Self::Error> {
use num_traits::FromPrimitive;
return <Self as FromPrimitive>::from_u32(x.types().bits())
.ok_or(system_error::SystemError::EINVAL);
}
}

View File

@ -0,0 +1,110 @@
bitflags::bitflags! {
/// # Message Flags
/// Flags we can use with send/ and recv. \
/// Added those for 1003.1g not all are supported yet
/// ## Reference
/// - [Linux Socket Flags](https://code.dragonos.org.cn/xref/linux-6.6.21/include/linux/socket.h#299)
pub struct MessageFlag: u32 {
/// `MSG_OOB`
/// `0b0000_0001`\
/// Process out-of-band data.
const OOB = 1;
/// `MSG_PEEK`
/// `0b0000_0010`\
/// Peek at an incoming message.
const PEEK = 2;
/// `MSG_DONTROUTE`
/// `0b0000_0100`\
/// Don't use routing tables.
const DONTROUTE = 4;
/// `MSG_TRYHARD`
/// `0b0000_0100`\
/// `MSG_TRYHARD` is not defined in the standard, but it is used in Linux.
const TRYHARD = 4;
/// `MSG_CTRUNC`
/// `0b0000_1000`\
/// Control data lost before delivery.
const CTRUNC = 8;
/// `MSG_PROBE`
/// `0b0001_0000`\
const PROBE = 0x10;
/// `MSG_TRUNC`
/// `0b0010_0000`\
/// Data truncated before delivery.
const TRUNC = 0x20;
/// `MSG_DONTWAIT`
/// `0b0100_0000`\
/// This flag is used to make the socket non-blocking.
const DONTWAIT = 0x40;
/// `MSG_EOR`
/// `0b1000_0000`\
/// End of record.
const EOR = 0x80;
/// `MSG_WAITALL`
/// `0b0001_0000_0000`\
/// Wait for full request or error.
const WAITALL = 0x100;
/// `MSG_FIN`
/// `0b0010_0000_0000`\
/// Terminate the connection.
const FIN = 0x200;
/// `MSG_SYN`
/// `0b0100_0000_0000`\
/// Synchronize sequence numbers.
const SYN = 0x400;
/// `MSG_CONFIRM`
/// `0b1000_0000_0000`\
/// Confirm path validity.
const CONFIRM = 0x800;
/// `MSG_RST`
/// `0b0001_0000_0000_0000`\
/// Reset the connection.
const RST = 0x1000;
/// `MSG_ERRQUEUE`
/// `0b0010_0000_0000_0000`\
/// Fetch message from error queue.
const ERRQUEUE = 0x2000;
/// `MSG_NOSIGNAL`
/// `0b0100_0000_0000_0000`\
/// Do not generate a signal.
const NOSIGNAL = 0x4000;
/// `MSG_MORE`
/// `0b1000_0000_0000_0000`\
/// Sender will send more.
const MORE = 0x8000;
/// `MSG_WAITFORONE`
/// `0b0001_0000_0000_0000_0000`\
/// For nonblocking operation.
const WAITFORONE = 0x10000;
/// `MSG_SENDPAGE_NOPOLICY`
/// `0b0010_0000_0000_0000_0000`\
/// Sendpage: do not apply policy.
const SENDPAGE_NOPOLICY = 0x10000;
/// `MSG_BATCH`
/// `0b0100_0000_0000_0000_0000`\
/// Sendpage: next message is batch.
const BATCH = 0x40000;
/// `MSG_EOF`
const EOF = Self::FIN.bits;
/// `MSG_NO_SHARED_FRAGS`
const NO_SHARED_FRAGS = 0x80000;
/// `MSG_SENDPAGE_DECRYPTED`
const SENDPAGE_DECRYPTED = 0x10_0000;
/// `MSG_ZEROCOPY`
const ZEROCOPY = 0x400_0000;
/// `MSG_SPLICE_PAGES`
const SPLICE_PAGES = 0x800_0000;
/// `MSG_FASTOPEN`
const FASTOPEN = 0x2000_0000;
/// `MSG_CMSG_CLOEXEC`
const CMSG_CLOEXEC = 0x4000_0000;
/// `MSG_CMSG_COMPAT`
// if define CONFIG_COMPAT
// const CMSG_COMPAT = 0x8000_0000;
const CMSG_COMPAT = 0;
/// `MSG_INTERNAL_SENDMSG_FLAGS`
const INTERNAL_SENDMSG_FLAGS
= Self::SPLICE_PAGES.bits | Self::SENDPAGE_NOPOLICY.bits | Self::SENDPAGE_DECRYPTED.bits;
}
}

View File

@ -0,0 +1,92 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum Options {
DEBUG = 1,
REUSEADDR = 2,
TYPE = 3,
ERROR = 4,
DONTROUTE = 5,
BROADCAST = 6,
SNDBUF = 7,
RCVBUF = 8,
SNDBUFFORCE = 32,
RCVBUFFORCE = 33,
KEEPALIVE = 9,
OOBINLINE = 10,
NO_CHECK = 11,
PRIORITY = 12,
LINGER = 13,
BSDCOMPAT = 14,
REUSEPORT = 15,
PASSCRED = 16,
PEERCRED = 17,
RCVLOWAT = 18,
SNDLOWAT = 19,
RCVTIMEO_OLD = 20,
SNDTIMEO_OLD = 21,
SECURITY_AUTHENTICATION = 22,
SECURITY_ENCRYPTION_TRANSPORT = 23,
SECURITY_ENCRYPTION_NETWORK = 24,
BINDTODEVICE = 25,
/// 与GET_FILTER相同
ATTACH_FILTER = 26,
DETACH_FILTER = 27,
PEERNAME = 28,
ACCEPTCONN = 30,
PEERSEC = 31,
PASSSEC = 34,
MARK = 36,
PROTOCOL = 38,
DOMAIN = 39,
RXQ_OVFL = 40,
/// 与SCM_WIFI_STATUS相同
WIFI_STATUS = 41,
PEEK_OFF = 42,
/* Instruct lower device to use last 4-bytes of skb data as FCS */
NOFCS = 43,
LOCK_FILTER = 44,
SELECT_ERR_QUEUE = 45,
BUSY_POLL = 46,
MAX_PACING_RATE = 47,
BPF_EXTENSIONS = 48,
INCOMING_CPU = 49,
ATTACH_BPF = 50,
// DETACH_BPF = DETACH_FILTER,
ATTACH_REUSEPORT_CBPF = 51,
ATTACH_REUSEPORT_EBPF = 52,
CNX_ADVICE = 53,
SCM_TIMESTAMPING_OPT_STATS = 54,
MEMINFO = 55,
INCOMING_NAPI_ID = 56,
COOKIE = 57,
SCM_TIMESTAMPING_PKTINFO = 58,
PEERGROUPS = 59,
ZEROCOPY = 60,
/// 与SCM_TXTIME相同
TXTIME = 61,
BINDTOIFINDEX = 62,
TIMESTAMP_OLD = 29,
TIMESTAMPNS_OLD = 35,
TIMESTAMPING_OLD = 37,
TIMESTAMP_NEW = 63,
TIMESTAMPNS_NEW = 64,
TIMESTAMPING_NEW = 65,
RCVTIMEO_NEW = 66,
SNDTIMEO_NEW = 67,
DETACH_REUSEPORT_BPF = 68,
PREFER_BUSY_POLL = 69,
BUSY_POLL_BUDGET = 70,
NETNS_COOKIE = 71,
BUF_LOCK = 72,
RESERVE_MEM = 73,
TXREHASH = 74,
RCVMARK = 75,
}
impl TryFrom<u32> for Options {
type Error = system_error::SystemError;
fn try_from(x: u32) -> Result<Self, Self::Error> {
use num_traits::FromPrimitive;
return <Self as FromPrimitive>::from_u32(x).ok_or(system_error::SystemError::EINVAL);
}
}

View File

@ -0,0 +1,115 @@
// pub const SOL_SOCKET: u8 = 1,
// bitflags::bitflags! {
// pub struct OptionsLevel: u32 {
// const IP = 0,
// // const SOL_ICMP = 1, // No-no-no! Due to Linux :-) we cannot
// const SOCKET = 1,
// const TCP = 6,
// const UDP = 17,
// const IPV6 = 41,
// const ICMPV6 = 58,
// const SCTP = 132,
// const UDPLITE = 136, // UDP-Lite (RFC 3828)
// const RAW = 255,
// const IPX = 256,
// const AX25 = 257,
// const ATALK = 258,
// const NETROM = 259,
// const ROSE = 260,
// const DECNET = 261,
// const X25 = 262,
// const PACKET = 263,
// const ATM = 264, // ATM layer (cell level)
// const AAL = 265, // ATM Adaption Layer (packet level)
// const IRDA = 266,
// const NETBEUI = 267,
// const LLC = 268,
// const DCCP = 269,
// const NETLINK = 270,
// const TIPC = 271,
// const RXRPC = 272,
// const PPPOL2TP = 273,
// const BLUETOOTH = 274,
// const PNPIPE = 275,
// const RDS = 276,
// const IUCV = 277,
// const CAIF = 278,
// const ALG = 279,
// const NFC = 280,
// const KCM = 281,
// const TLS = 282,
// const XDP = 283,
// const MPTCP = 284,
// const MCTP = 285,
// const SMC = 286,
// const VSOCK = 287,
// }
// }
/// # SOL (Socket Option Level)
/// Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx
/// ## Reference
/// - [Setsockoptions(2) level](https://code.dragonos.org.cn/xref/linux-6.6.21/include/linux/socket.h#345)
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum OptionsLevel {
IP = 0,
SOCKET = 1,
// ICMP = 1, No-no-no! Due to Linux :-) we cannot
TCP = 6,
UDP = 17,
IPV6 = 41,
ICMPV6 = 58,
SCTP = 132,
UDPLITE = 136, // UDP-Lite (RFC 3828)
RAW = 255,
IPX = 256,
AX25 = 257,
ATALK = 258,
NETROM = 259,
ROSE = 260,
DECNET = 261,
X25 = 262,
PACKET = 263,
ATM = 264, // ATM layer (cell level)
AAL = 265, // ATM Adaption Layer (packet level)
IRDA = 266,
NETBEUI = 267,
LLC = 268,
DCCP = 269,
NETLINK = 270,
TIPC = 271,
RXRPC = 272,
PPPOL2TP = 273,
BLUETOOTH = 274,
PNPIPE = 275,
RDS = 276,
IUCV = 277,
CAIF = 278,
ALG = 279,
NFC = 280,
KCM = 281,
TLS = 282,
XDP = 283,
MPTCP = 284,
MCTP = 285,
SMC = 286,
VSOCK = 287,
}
impl TryFrom<u32> for OptionsLevel {
type Error = system_error::SystemError;
fn try_from(value: u32) -> Result<Self, Self::Error> {
match <Self as num_traits::FromPrimitive>::from_u32(value) {
Some(p) => Ok(p),
None => Err(system_error::SystemError::EPROTONOSUPPORT),
}
}
}
impl From<OptionsLevel> for u32 {
fn from(value: OptionsLevel) -> Self {
<OptionsLevel as num_traits::ToPrimitive>::to_u32(&value).unwrap()
}
}

View File

@ -0,0 +1,133 @@
// bitflags! {
// // #[derive(PartialEq, Eq, Debug, Clone, Copy)]
// pub struct Options: u32 {
// const DEBUG = 1;
// const REUSEADDR = 2;
// const TYPE = 3;
// const ERROR = 4;
// const DONTROUTE = 5;
// const BROADCAST = 6;
// const SNDBUF = 7;
// const RCVBUF = 8;
// const SNDBUFFORCE = 32;
// const RCVBUFFORCE = 33;
// const KEEPALIVE = 9;
// const OOBINLINE = 10;
// const NO_CHECK = 11;
// const PRIORITY = 12;
// const LINGER = 13;
// const BSDCOMPAT = 14;
// const REUSEPORT = 15;
// const PASSCRED = 16;
// const PEERCRED = 17;
// const RCVLOWAT = 18;
// const SNDLOWAT = 19;
// const RCVTIMEO_OLD = 20;
// const SNDTIMEO_OLD = 21;
//
// const SECURITY_AUTHENTICATION = 22;
// const SECURITY_ENCRYPTION_TRANSPORT = 23;
// const SECURITY_ENCRYPTION_NETWORK = 24;
//
// const BINDTODEVICE = 25;
//
// /// 与GET_FILTER相同
// const ATTACH_FILTER = 26;
// const DETACH_FILTER = 27;
//
// const PEERNAME = 28;
//
// const ACCEPTCONN = 30;
//
// const PEERSEC = 31;
// const PASSSEC = 34;
//
// const MARK = 36;
//
// const PROTOCOL = 38;
// const DOMAIN = 39;
//
// const RXQ_OVFL = 40;
//
// /// 与SCM_WIFI_STATUS相同
// const WIFI_STATUS = 41;
// const PEEK_OFF = 42;
//
// /* Instruct lower device to use last 4-bytes of skb data as FCS */
// const NOFCS = 43;
//
// const LOCK_FILTER = 44;
// const SELECT_ERR_QUEUE = 45;
// const BUSY_POLL = 46;
// const MAX_PACING_RATE = 47;
// const BPF_EXTENSIONS = 48;
// const INCOMING_CPU = 49;
// const ATTACH_BPF = 50;
// // DETACH_BPF = DETACH_FILTER;
// const ATTACH_REUSEPORT_CBPF = 51;
// const ATTACH_REUSEPORT_EBPF = 52;
//
// const CNX_ADVICE = 53;
// const SCM_TIMESTAMPING_OPT_STATS = 54;
// const MEMINFO = 55;
// const INCOMING_NAPI_ID = 56;
// const COOKIE = 57;
// const SCM_TIMESTAMPING_PKTINFO = 58;
// const PEERGROUPS = 59;
// const ZEROCOPY = 60;
// /// 与SCM_TXTIME相同
// const TXTIME = 61;
//
// const BINDTOIFINDEX = 62;
//
// const TIMESTAMP_OLD = 29;
// const TIMESTAMPNS_OLD = 35;
// const TIMESTAMPING_OLD = 37;
// const TIMESTAMP_NEW = 63;
// const TIMESTAMPNS_NEW = 64;
// const TIMESTAMPING_NEW = 65;
//
// const RCVTIMEO_NEW = 66;
// const SNDTIMEO_NEW = 67;
//
// const DETACH_REUSEPORT_BPF = 68;
//
// const PREFER_BUSY_POLL = 69;
// const BUSY_POLL_BUDGET = 70;
//
// const NETNS_COOKIE = 71;
// const BUF_LOCK = 72;
// const RESERVE_MEM = 73;
// const TXREHASH = 74;
// const RCVMARK = 75;
// }
// }
// bitflags::bitflags! {
// pub struct Level: i32 {
// const SOL_SOCKET = 1;
// const IPPROTO_IP = super::ip::Protocol::IP.bits();
// const IPPROTO_IPV6 = super::ip::Protocol::IPv6.bits();
// const IPPROTO_TCP = super::ip::Protocol::TCP.bits();
// }
// }
// bitflags! {
// /// @brief socket的选项
// #[derive(Default)]
// pub struct Options: u32 {
// /// 是否阻塞
// const BLOCK = 1 << 0;
// /// 是否允许广播
// const BROADCAST = 1 << 1;
// /// 是否允许多播
// const MULTICAST = 1 << 2;
// /// 是否允许重用地址
// const REUSEADDR = 1 << 3;
// /// 是否允许重用端口
// const REUSEPORT = 1 << 4;
// }
// }