mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 14:16:47 +00:00
loopback assign single ip, remove unnecessary comments
This commit is contained in:
parent
149fc8377c
commit
c9806be704
@ -286,17 +286,9 @@ 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),
|
||||
|
@ -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> {
|
||||
|
@ -12,7 +12,7 @@ pub mod event_poll;
|
||||
pub mod net_core;
|
||||
pub mod socket;
|
||||
pub mod syscall;
|
||||
pub mod syscall_util;
|
||||
pub mod posix;
|
||||
|
||||
lazy_static! {
|
||||
/// # 所有网络接口的列表
|
||||
|
@ -1,3 +1,7 @@
|
||||
//
|
||||
// posix.rs 记录了系统调用时用到的结构
|
||||
//
|
||||
|
||||
bitflags::bitflags! {
|
||||
// #[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||
pub struct PosixArgsSocketType: u32 {
|
@ -1,7 +1,7 @@
|
||||
#![allow(unused_variables)]
|
||||
|
||||
use crate::net::socket::*;
|
||||
use crate::net::syscall_util::MsgHdr;
|
||||
use crate::net::posix::MsgHdr;
|
||||
use alloc::sync::Arc;
|
||||
use core::any::Any;
|
||||
use core::fmt::Debug;
|
||||
|
@ -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(());
|
||||
// }
|
||||
|
@ -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!()
|
||||
// }
|
||||
// }
|
||||
|
@ -23,10 +23,6 @@ fn create_inet_socket(
|
||||
return Err(EPROTONOSUPPORT);
|
||||
}
|
||||
}
|
||||
// if !matches!(protocol, Udp) {
|
||||
// return Err(EPROTONOSUPPORT);
|
||||
// }
|
||||
// return Ok(UdpSocket::new(false));
|
||||
}
|
||||
PSOCK::Stream => match protocol {
|
||||
HopByHop | Tcp => {
|
||||
|
@ -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> {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user