Merge pull request #992 from Samuka007/feat-network-rebuild

remove unnecessary comments, rename module to posix.
This commit is contained in:
Samuel Dai 2024-10-17 16:00:25 +08:00 committed by GitHub
commit 7ead4a0658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 22 additions and 215 deletions

View File

@ -38,7 +38,7 @@ use crate::{
},
},
exception::{irqdesc::IrqReturn, IrqNumber},
filesystem::{kernfs::KernFSInode, mbr::MbrDiskPartionTable, sysfs::AttributeGroup},
filesystem::{kernfs::KernFSInode, mbr::MbrDiskPartionTable},
init::initcall::INITCALL_POSTCORE,
libs::{
rwlock::{RwLockReadGuard, RwLockWriteGuard},
@ -407,10 +407,6 @@ impl Device for VirtIOBlkDevice {
fn set_dev_parent(&self, parent: Option<Weak<dyn Device>>) {
self.inner().device_common.parent = parent;
}
fn attribute_groups(&self) -> Option<&'static [&'static dyn AttributeGroup]> {
None
}
}
impl KObject for VirtIOBlkDevice {

View File

@ -23,7 +23,6 @@ impl IrqHandler for DefaultNetIrqHandler {
_dynamic_data: Option<Arc<dyn IrqHandlerData>>,
) -> Result<IrqReturn, SystemError> {
// poll_ifaces_try_lock_onetime().ok();
log::warn!("DefaultNetIrqHandler: poll_ifaces_try_lock_onetime -> poll_ifaces");
poll_ifaces();
Ok(IrqReturn::Handled)
}

View File

@ -286,17 +286,11 @@ impl LoopbackInterface {
smoltcp::iface::Interface::new(iface_config, &mut driver, Instant::now().into());
//设置网卡地址为127.0.0.1
iface.update_ip_addrs(|ip_addrs| {
for i in 1..=2 {
ip_addrs
.push(IpCidr::new(IpAddress::v4(127, 0, 0, i), 8))
.expect("Push ipCidr failed: full");
}
ip_addrs
.push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8))
.expect("Push ipCidr failed: full");
});
// iface.routes_mut().update(|routes_map| {
// routes_map[0].
// });
Arc::new(LoopbackInterface {
driver: LoopbackDriverWapper(UnsafeCell::new(driver)),
common: IfaceCommon::new(iface_id, iface),

View File

@ -230,6 +230,7 @@ impl IfaceCommon {
let new_instant = instant.total_millis() as u64;
self.poll_at_ms.store(new_instant, Ordering::Relaxed);
// TODO: poll at
// if old_instant == 0 || new_instant < old_instant {
// self.polling_wait_queue.wake_all();
// }
@ -237,12 +238,8 @@ impl IfaceCommon {
self.poll_at_ms.store(0, Ordering::Relaxed);
}
// if has_events {
// log::debug!("IfaceCommon::poll: has_events");
// We never try to hold the write lock in the IRQ context, and we disable IRQ when
// holding the write lock. So we don't need to disable IRQ when holding the read lock.
self.bounds.read().iter().for_each(|bound_socket| {
// incase our inet socket missed the event, we manually notify it each time we poll
bound_socket.on_iface_events();
if has_events {
bound_socket
@ -251,13 +248,13 @@ impl IfaceCommon {
}
});
// TODO: remove closed sockets
// let closed_sockets = self
// .closing_sockets
// .lock_irq_disabled()
// .extract_if(|closing_socket| closing_socket.is_closed())
// .collect::<Vec<_>>();
// drop(closed_sockets);
// }
}
pub fn update_ip_addrs(&self, ip_addrs: &[smoltcp::wire::IpCidr]) -> Result<(), SystemError> {

View File

@ -10,9 +10,9 @@ use crate::{driver::net::Iface, libs::rwlock::RwLock};
pub mod event_poll;
pub mod net_core;
pub mod posix;
pub mod socket;
pub mod syscall;
pub mod syscall_util;
lazy_static! {
/// # 所有网络接口的列表

View File

@ -1,3 +1,7 @@
//
// posix.rs 记录了系统调用时用到的结构
//
bitflags::bitflags! {
// #[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub struct PosixArgsSocketType: u32 {

View File

@ -1,7 +1,7 @@
#![allow(unused_variables)]
use crate::net::posix::MsgHdr;
use crate::net::socket::*;
use crate::net::syscall_util::MsgHdr;
use alloc::sync::Arc;
use core::any::Any;
use core::fmt::Debug;

View File

@ -307,129 +307,3 @@ bitflags! {
const ESPINTCP = 7; // Yikes, this is really xfrm encap types.
}
}
// fn sock_set_option(
// &self,
// _socket: &mut udp::Socket,
// _level: SocketOptionsLevel,
// optname: PosixSocketOption,
// _optval: &[u8],
// ) -> Result<(), SystemError> {
// use PosixSocketOption::*;
// use SystemError::*;
// if optname == SO_BINDTODEVICE {
// todo!("SO_BINDTODEVICE");
// }
// match optname {
// SO_TYPE => {}
// SO_PROTOCOL => {}
// SO_DOMAIN => {}
// SO_ERROR => {
// return Err(ENOPROTOOPT);
// }
// SO_TIMESTAMP_OLD => {}
// SO_TIMESTAMP_NEW => {}
// SO_TIMESTAMPNS_OLD => {}
// SO_TIMESTAMPING_OLD => {}
// SO_RCVTIMEO_OLD => {}
// SO_SNDTIMEO_OLD => {}
// // if define CONFIG_NET_RX_BUSY_POLL
// SO_BUSY_POLL | SO_PREFER_BUSY_POLL | SO_BUSY_POLL_BUDGET => {
// debug!("Unsupported socket option: {:?}", optname);
// return Err(ENOPROTOOPT);
// }
// // end if
// optname => {
// debug!("Unsupported socket option: {:?}", optname);
// return Err(ENOPROTOOPT);
// }
// }
// return Ok(());
// }
// fn udp_set_option(
// &self,
// level: SocketOptionsLevel,
// optname: usize,
// optval: &[u8],
// ) -> Result<(), SystemError> {
// use PosixSocketOption::*;
// let so_opt_name =
// PosixSocketOption::try_from(optname as i32)
// .map_err(|_| SystemError::ENOPROTOOPT)?;
// if level == SocketOptionsLevel::SOL_SOCKET {
// self.with_mut_socket(f)
// self.sock_set_option(self., level, so_opt_name, optval)?;
// if so_opt_name == SO_RCVBUF || so_opt_name == SO_RCVBUFFORCE {
// todo!("SO_RCVBUF");
// }
// }
// match UdpSocketOptions::from_bits_truncate(optname as u32) {
// UdpSocketOptions::UDP_CORK => {
// todo!("UDP_CORK");
// }
// UdpSocketOptions::UDP_ENCAP => {
// match UdpEncapTypes::from_bits_truncate(optval[0]) {
// UdpEncapTypes::ESPINUDP_NON_IKE => {
// todo!("ESPINUDP_NON_IKE");
// }
// UdpEncapTypes::ESPINUDP => {
// todo!("ESPINUDP");
// }
// UdpEncapTypes::L2TPINUDP => {
// todo!("L2TPINUDP");
// }
// UdpEncapTypes::GTP0 => {
// todo!("GTP0");
// }
// UdpEncapTypes::GTP1U => {
// todo!("GTP1U");
// }
// UdpEncapTypes::RXRPC => {
// todo!("RXRPC");
// }
// UdpEncapTypes::ESPINTCP => {
// todo!("ESPINTCP");
// }
// UdpEncapTypes::ZERO => {}
// _ => {
// return Err(SystemError::ENOPROTOOPT);
// }
// }
// }
// UdpSocketOptions::UDP_NO_CHECK6_TX => {
// todo!("UDP_NO_CHECK6_TX");
// }
// UdpSocketOptions::UDP_NO_CHECK6_RX => {
// todo!("UDP_NO_CHECK6_RX");
// }
// UdpSocketOptions::UDP_SEGMENT => {
// todo!("UDP_SEGMENT");
// }
// UdpSocketOptions::UDP_GRO => {
// todo!("UDP_GRO");
// }
// UdpSocketOptions::UDPLITE_RECV_CSCOV => {
// todo!("UDPLITE_RECV_CSCOV");
// }
// UdpSocketOptions::UDPLITE_SEND_CSCOV => {
// todo!("UDPLITE_SEND_CSCOV");
// }
// UdpSocketOptions::ZERO => {}
// _ => {
// return Err(SystemError::ENOPROTOOPT);
// }
// }
// return Ok(());
// }

View File

@ -30,54 +30,3 @@ pub trait InetSocket: Socket {
/// 通知socket发生的事件
fn on_iface_events(&self);
}
// #[derive(Debug)]
// pub enum InetSocket {
// // Raw(RawSocket),
// Udp(UdpSocket),
// Tcp(TcpSocket),
// }
// impl InetSocket {
// /// # `on_iface_events`
// /// 通知socket发生了事件
// pub fn on_iface_events(&self) {
// todo!()
// }
// }
// impl IndexNode for InetSocket {
// }
// impl Socket for InetSocket {
// fn epoll_items(&self) -> &super::common::poll_unit::EPollItems {
// match self {
// InetSocket::Udp(udp) => udp.epoll_items(),
// InetSocket::Tcp(tcp) => tcp.epoll_items(),
// }
// }
// fn bind(&self, endpoint: crate::net::Endpoint) -> Result<(), SystemError> {
// if let crate::net::Endpoint::Ip(ip) = endpoint {
// match self {
// InetSocket::Udp(udp) => {
// udp.do_bind(ip)?;
// },
// InetSocket::Tcp(tcp) => {
// tcp.do_bind(ip)?;
// },
// }
// return Ok(());
// }
// return Err(EINVAL);
// }
// fn wait_queue(&self) -> &super::common::poll_unit::WaitQueue {
// todo!()
// }
// fn on_iface_events(&self) {
// todo!()
// }
// }

View File

@ -14,20 +14,14 @@ fn create_inet_socket(
// log::debug!("type: {:?}, protocol: {:?}", socket_type, protocol);
use smoltcp::wire::IpProtocol::*;
match socket_type {
PSOCK::Datagram => {
match protocol {
HopByHop | Udp => {
return Ok(UdpSocket::new(false));
}
_ => {
return Err(EPROTONOSUPPORT);
}
PSOCK::Datagram => match protocol {
HopByHop | Udp => {
return Ok(UdpSocket::new(false));
}
// if !matches!(protocol, Udp) {
// return Err(EPROTONOSUPPORT);
// }
// return Ok(UdpSocket::new(false));
}
_ => {
return Err(EPROTONOSUPPORT);
}
},
PSOCK::Stream => match protocol {
HopByHop | Tcp => {
return Ok(TcpSocket::new(false));

View File

@ -9,7 +9,7 @@ pub enum Type {
Packet = 10,
}
use crate::net::syscall_util::PosixArgsSocketType;
use crate::net::posix::PosixArgsSocketType;
impl TryFrom<PosixArgsSocketType> for Type {
type Error = system_error::SystemError;
fn try_from(x: PosixArgsSocketType) -> Result<Self, Self::Error> {

View File

@ -10,7 +10,7 @@ use crate::{
use super::socket::{self, unix::Unix, AddressFamily as AF, Endpoint};
pub use super::syscall_util::*;
pub use super::posix::*;
/// Flags for socket, socketpair, accept4
const SOCK_CLOEXEC: FileMode = FileMode::O_CLOEXEC;