Avoid unused variables in the network module

This commit is contained in:
Ruihan Li 2024-06-18 16:05:20 +08:00 committed by Tate, Hongliang Tian
parent 94e043ac8d
commit 5eefd600cc
18 changed files with 34 additions and 79 deletions

View File

@ -1,13 +1,10 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use super::{Iface, IpAddress, IpEndpoint}; use super::{Iface, IpAddress, IpEndpoint};
use crate::{events::Observer, prelude::*}; use crate::{events::Observer, prelude::*};
pub type RawTcpSocket = smoltcp::socket::tcp::Socket<'static>; pub type RawTcpSocket = smoltcp::socket::tcp::Socket<'static>;
pub type RawUdpSocket = smoltcp::socket::udp::Socket<'static>; pub type RawUdpSocket = smoltcp::socket::udp::Socket<'static>;
pub type RawSocketHandle = smoltcp::iface::SocketHandle;
pub struct AnyUnboundSocket { pub struct AnyUnboundSocket {
socket_family: AnyRawSocket, socket_family: AnyRawSocket,

View File

@ -1,9 +1,7 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use smoltcp::{ use smoltcp::{
iface::{Config, Routes}, iface::Config,
phy::{Loopback, Medium}, phy::{Loopback, Medium},
wire::IpCidr, wire::IpCidr,
}; };
@ -27,7 +25,6 @@ impl IfaceLoopback {
pub fn new() -> Arc<Self> { pub fn new() -> Arc<Self> {
let mut loopback = Loopback::new(Medium::Ip); let mut loopback = Loopback::new(Medium::Ip);
let interface = { let interface = {
let routes = Routes::new();
let config = Config::new(); let config = Config::new();
let mut interface = smoltcp::iface::Interface::new(config, &mut loopback); let mut interface = smoltcp::iface::Interface::new(config, &mut loopback);
interface.update_ip_addrs(|ip_addrs| { interface.update_ip_addrs(|ip_addrs| {

View File

@ -1,11 +1,9 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use aster_network::AnyNetworkDevice; use aster_network::AnyNetworkDevice;
use aster_virtio::device::network::DEVICE_NAME; use aster_virtio::device::network::DEVICE_NAME;
use smoltcp::{ use smoltcp::{
iface::{Config, Routes, SocketHandle, SocketSet}, iface::{Config, SocketHandle, SocketSet},
socket::dhcpv4, socket::dhcpv4,
wire::{self, IpCidr}, wire::{self, IpCidr},
}; };
@ -26,7 +24,6 @@ impl IfaceVirtio {
let interface = { let interface = {
let mac_addr = virtio_net.lock().mac_addr(); let mac_addr = virtio_net.lock().mac_addr();
let ip_addr = IpCidr::new(wire::IpAddress::Ipv4(wire::Ipv4Address::UNSPECIFIED), 0); let ip_addr = IpCidr::new(wire::IpAddress::Ipv4(wire::Ipv4Address::UNSPECIFIED), 0);
let routes = Routes::new();
let config = { let config = {
let mut config = Config::new(); let mut config = Config::new();
config.hardware_addr = Some(wire::HardwareAddress::Ethernet( config.hardware_addr = Some(wire::HardwareAddress::Ethernet(

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use smoltcp::socket::udp::{RecvError, SendError}; use smoltcp::socket::udp::{RecvError, SendError};
use crate::{ use crate::{
@ -39,7 +37,7 @@ impl BoundDatagram {
self.remote_endpoint = Some(*endpoint) self.remote_endpoint = Some(*endpoint)
} }
pub fn try_recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<(usize, IpEndpoint)> { pub fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<(usize, IpEndpoint)> {
let result = self let result = self
.bound_socket .bound_socket
.raw_with(|socket: &mut RawUdpSocket| socket.recv_slice(buf)); .raw_with(|socket: &mut RawUdpSocket| socket.recv_slice(buf));
@ -51,7 +49,12 @@ impl BoundDatagram {
} }
} }
pub fn try_send(&self, buf: &[u8], remote: &IpEndpoint, flags: SendRecvFlags) -> Result<usize> { pub fn try_send(
&self,
buf: &[u8],
remote: &IpEndpoint,
_flags: SendRecvFlags,
) -> Result<usize> {
let result = self.bound_socket.raw_with(|socket: &mut RawUdpSocket| { let result = self.bound_socket.raw_with(|socket: &mut RawUdpSocket| {
if socket.payload_send_capacity() < buf.len() { if socket.payload_send_capacity() < buf.len() {
return None; return None;

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use takeable::Takeable; use takeable::Takeable;
@ -301,7 +299,7 @@ impl Socket for DatagramSocket {
fn addr(&self) -> Result<SocketAddr> { fn addr(&self) -> Result<SocketAddr> {
let inner = self.inner.read(); let inner = self.inner.read();
match inner.as_ref() { match inner.as_ref() {
Inner::Unbound(unbound_datagram) => Ok(UNSPECIFIED_LOCAL_ENDPOINT.into()), Inner::Unbound(_) => Ok(UNSPECIFIED_LOCAL_ENDPOINT.into()),
Inner::Bound(bound_datagram) => Ok(bound_datagram.local_endpoint().into()), Inner::Bound(bound_datagram) => Ok(bound_datagram.local_endpoint().into()),
} }
} }
@ -373,7 +371,7 @@ impl Socket for DatagramSocket {
} }
impl Observer<()> for DatagramSocket { impl Observer<()> for DatagramSocket {
fn on_events(&self, events: &()) { fn on_events(&self, _events: &()) {
self.update_io_events(); self.update_io_events();
} }
} }

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use alloc::sync::Weak; use alloc::sync::Weak;
use smoltcp::socket::tcp::{RecvError, SendError}; use smoltcp::socket::tcp::{RecvError, SendError};
@ -45,7 +43,7 @@ impl ConnectedStream {
} }
} }
pub fn shutdown(&self, cmd: SockShutdownCmd) -> Result<()> { pub fn shutdown(&self, _cmd: SockShutdownCmd) -> Result<()> {
// TODO: deal with cmd // TODO: deal with cmd
self.bound_socket.raw_with(|socket: &mut RawTcpSocket| { self.bound_socket.raw_with(|socket: &mut RawTcpSocket| {
socket.close(); socket.close();
@ -53,7 +51,7 @@ impl ConnectedStream {
Ok(()) Ok(())
} }
pub fn try_recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<usize> { pub fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<usize> {
let result = self let result = self
.bound_socket .bound_socket
.raw_with(|socket: &mut RawTcpSocket| socket.recv_slice(buf)); .raw_with(|socket: &mut RawTcpSocket| socket.recv_slice(buf));
@ -68,7 +66,7 @@ impl ConnectedStream {
} }
} }
pub fn try_send(&self, buf: &[u8], flags: SendRecvFlags) -> Result<usize> { pub fn try_send(&self, buf: &[u8], _flags: SendRecvFlags) -> Result<usize> {
let result = self let result = self
.bound_socket .bound_socket
.raw_with(|socket: &mut RawTcpSocket| socket.send_slice(buf)); .raw_with(|socket: &mut RawTcpSocket| socket.send_slice(buf));

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use smoltcp::socket::tcp::ListenError; use smoltcp::socket::tcp::ListenError;
use super::connected::ConnectedStream; use super::connected::ConnectedStream;
@ -66,9 +64,8 @@ impl ListenStream {
})?; })?;
let active_backlog_socket = backlog_sockets.remove(index); let active_backlog_socket = backlog_sockets.remove(index);
match BacklogSocket::new(&self.bound_socket) { if let Ok(backlog_socket) = BacklogSocket::new(&self.bound_socket) {
Ok(backlog_socket) => backlog_sockets.push(backlog_socket), backlog_sockets.push(backlog_socket);
Err(err) => (),
} }
let remote_endpoint = active_backlog_socket.remote_endpoint().unwrap(); let remote_endpoint = active_backlog_socket.remote_endpoint().unwrap();

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use connected::ConnectedStream; use connected::ConnectedStream;
@ -713,7 +711,7 @@ impl Socket for StreamSocket {
} }
impl Observer<()> for StreamSocket { impl Observer<()> for StreamSocket {
fn on_events(&self, events: &()) { fn on_events(&self, _events: &()) {
let conn_ready = self.update_io_events(); let conn_ready = self.update_io_events();
if conn_ready { if conn_ready {

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use self::options::SocketOption; use self::options::SocketOption;
pub use self::util::{ pub use self::util::{
options::LingerOption, send_recv_flags::SendRecvFlags, shutdown_cmd::SockShutdownCmd, options::LingerOption, send_recv_flags::SendRecvFlags, shutdown_cmd::SockShutdownCmd,
@ -18,17 +16,17 @@ pub mod vsock;
/// Operations defined on a socket. /// Operations defined on a socket.
pub trait Socket: FileLike + Send + Sync { pub trait Socket: FileLike + Send + Sync {
/// Assign the address specified by socket_addr to the socket /// Assign the address specified by socket_addr to the socket
fn bind(&self, socket_addr: SocketAddr) -> Result<()> { fn bind(&self, _socket_addr: SocketAddr) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "bind() is not supported"); return_errno_with_message!(Errno::EOPNOTSUPP, "bind() is not supported");
} }
/// Build connection for a given address /// Build connection for a given address
fn connect(&self, socket_addr: SocketAddr) -> Result<()> { fn connect(&self, _socket_addr: SocketAddr) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "connect() is not supported"); return_errno_with_message!(Errno::EOPNOTSUPP, "connect() is not supported");
} }
/// Listen for connections on a socket /// Listen for connections on a socket
fn listen(&self, backlog: usize) -> Result<()> { fn listen(&self, _backlog: usize) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "listen() is not supported"); return_errno_with_message!(Errno::EOPNOTSUPP, "listen() is not supported");
} }
@ -38,7 +36,7 @@ pub trait Socket: FileLike + Send + Sync {
} }
/// Shut down part of a full-duplex connection /// Shut down part of a full-duplex connection
fn shutdown(&self, cmd: SockShutdownCmd) -> Result<()> { fn shutdown(&self, _cmd: SockShutdownCmd) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "shutdown() is not supported"); return_errno_with_message!(Errno::EOPNOTSUPP, "shutdown() is not supported");
} }
@ -54,12 +52,12 @@ pub trait Socket: FileLike + Send + Sync {
/// Get options on the socket. The resulted option will put in the `option` parameter, if /// Get options on the socket. The resulted option will put in the `option` parameter, if
/// this method returns success. /// this method returns success.
fn get_option(&self, option: &mut dyn SocketOption) -> Result<()> { fn get_option(&self, _option: &mut dyn SocketOption) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "getsockopt() is not supported"); return_errno_with_message!(Errno::EOPNOTSUPP, "getsockopt() is not supported");
} }
/// Set options on the socket. /// Set options on the socket.
fn set_option(&self, option: &dyn SocketOption) -> Result<()> { fn set_option(&self, _option: &dyn SocketOption) -> Result<()> {
return_errno_with_message!(Errno::EOPNOTSUPP, "setsockopt() is not supported"); return_errno_with_message!(Errno::EOPNOTSUPP, "setsockopt() is not supported");
} }

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use super::endpoint::Endpoint; use super::endpoint::Endpoint;
use crate::{ use crate::{
events::IoEvents, events::IoEvents,
@ -27,10 +25,6 @@ impl Connected {
self.local_endpoint.peer_addr() self.local_endpoint.peer_addr()
} }
pub(super) fn is_bound(&self) -> bool {
self.addr().is_some()
}
pub(super) fn write(&self, buf: &[u8]) -> Result<usize> { pub(super) fn write(&self, buf: &[u8]) -> Result<usize> {
self.local_endpoint.write(buf) self.local_endpoint.write(buf)
} }

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(unused_variables)]
use crate::{ use crate::{
events::IoEvents, events::IoEvents,
fs::utils::{Channel, Consumer, Producer, StatusFlags}, fs::utils::{Channel, Consumer, Producer, StatusFlags},

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use super::{connected::Connected, endpoint::Endpoint, listener::push_incoming}; use super::{connected::Connected, endpoint::Endpoint, listener::push_incoming};
@ -69,10 +67,6 @@ impl Init {
Ok(Connected::new(this_end)) Ok(Connected::new(this_end))
} }
pub(super) fn is_bound(&self) -> bool {
self.addr.lock().is_some()
}
pub(super) fn addr(&self) -> Option<UnixSocketAddrBound> { pub(super) fn addr(&self) -> Option<UnixSocketAddrBound> {
self.addr.lock().clone() self.addr.lock().clone()
} }

View File

@ -1,8 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
#![allow(unused_variables)]
use super::{ use super::{
connected::Connected, connected::Connected,
endpoint::Endpoint, endpoint::Endpoint,
@ -37,10 +34,6 @@ impl UnixStreamSocket {
Self(RwLock::new(State::Init(Arc::new(init)))) Self(RwLock::new(State::Init(Arc::new(init))))
} }
pub(super) fn new_listen(listen: Listener) -> Self {
Self(RwLock::new(State::Listen(Arc::new(listen))))
}
pub(super) fn new_connected(connected: Connected) -> Self { pub(super) fn new_connected(connected: Connected) -> Self {
Self(RwLock::new(State::Connected(Arc::new(connected)))) Self(RwLock::new(State::Connected(Arc::new(connected))))
} }
@ -91,7 +84,7 @@ impl UnixStreamSocket {
status_flags.intersection(SUPPORTED_FLAGS) status_flags.intersection(SUPPORTED_FLAGS)
} }
fn send(&self, buf: &[u8], flags: SendRecvFlags) -> Result<usize> { fn send(&self, buf: &[u8], _flags: SendRecvFlags) -> Result<usize> {
let connected = match &*self.0.read() { let connected = match &*self.0.read() {
State::Connected(connected) => connected.clone(), State::Connected(connected) => connected.clone(),
_ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"), _ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"),
@ -100,7 +93,7 @@ impl UnixStreamSocket {
connected.write(buf) connected.write(buf)
} }
fn recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<usize> { fn recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<usize> {
let connected = match &*self.0.read() { let connected = match &*self.0.read() {
State::Connected(connected) => connected.clone(), State::Connected(connected) => connected.clone(),
_ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"), _ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"),

View File

@ -47,7 +47,7 @@ pub fn copy_message_from_user(io_vecs: &[IoVec]) -> Box<[u8]> {
// FIXME: short read should be allowed here // FIXME: short read should be allowed here
match io_vec.read_exact_from_user(dst) { match io_vec.read_exact_from_user(dst) {
Ok(()) => total_bytes += io_vec.len(), Ok(()) => total_bytes += io_vec.len(),
Err(e) => { Err(_) => {
warn!("fails to copy message from user"); warn!("fails to copy message from user");
break; break;
} }
@ -84,7 +84,7 @@ pub fn copy_message_to_user(io_vecs: &[IoVec], message: &[u8]) -> usize {
let src = &message[total_bytes..total_bytes + len]; let src = &message[total_bytes..total_bytes + len];
match io_vec.write_to_user(src) { match io_vec.write_to_user(src) {
Ok(len) => total_bytes += len, Ok(len) => total_bytes += len,
Err(e) => { Err(_) => {
warn!("fails to copy message to user"); warn!("fails to copy message to user");
break; break;
} }

View File

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
#![allow(dead_code)]
use core::time::Duration; use core::time::Duration;
use crate::{ use crate::{
@ -19,7 +17,6 @@ pub struct SocketOptionSet {
send_buf: u32, send_buf: u32,
recv_buf: u32, recv_buf: u32,
linger: LingerOption, linger: LingerOption,
keep_alive: bool,
} }
impl SocketOptionSet { impl SocketOptionSet {
@ -32,7 +29,6 @@ impl SocketOptionSet {
send_buf: SEND_BUF_LEN as u32, send_buf: SEND_BUF_LEN as u32,
recv_buf: RECV_BUF_LEN as u32, recv_buf: RECV_BUF_LEN as u32,
linger: LingerOption::default(), linger: LingerOption::default(),
keep_alive: false,
} }
} }
} }

View File

@ -198,7 +198,6 @@ impl VsockSpace {
/// Poll for each event from the driver /// Poll for each event from the driver
pub fn poll(&self) -> Result<()> { pub fn poll(&self) -> Result<()> {
let mut driver = self.driver.lock_irq_disabled(); let mut driver = self.driver.lock_irq_disabled();
let guest_cid = driver.guest_cid() as u32;
while let Some(event) = self.poll_single(&mut driver)? { while let Some(event) = self.poll_single(&mut driver)? {
if !self.is_event_for_socket(&event) { if !self.is_event_for_socket(&event) {
@ -249,14 +248,14 @@ impl VsockSpace {
connecting.update_info(&event); connecting.update_info(&event);
connecting.add_events(IoEvents::IN); connecting.add_events(IoEvents::IN);
} }
VsockEventType::Disconnected { reason } => { VsockEventType::Disconnected { .. } => {
let connected_sockets = self.connected_sockets.read_irq_disabled(); let connected_sockets = self.connected_sockets.read_irq_disabled();
let Some(connected) = connected_sockets.get(&event.into()) else { let Some(connected) = connected_sockets.get(&event.into()) else {
return_errno_with_message!(Errno::ENOTCONN, "the socket hasn't connected"); return_errno_with_message!(Errno::ENOTCONN, "the socket hasn't connected");
}; };
connected.set_peer_requested_shutdown(); connected.set_peer_requested_shutdown();
} }
VsockEventType::Received { length } => {} VsockEventType::Received { .. } => {}
VsockEventType::CreditRequest => { VsockEventType::CreditRequest => {
let connected_sockets = self.connected_sockets.read_irq_disabled(); let connected_sockets = self.connected_sockets.read_irq_disabled();
let Some(connected) = connected_sockets.get(&event.into()) else { let Some(connected) = connected_sockets.get(&event.into()) else {
@ -282,7 +281,7 @@ impl VsockSpace {
driver driver
.poll(|event, body| { .poll(|event, body| {
// Deal with Received before the buffer are recycled. // Deal with Received before the buffer are recycled.
if let VsockEventType::Received { length } = event.event_type { if let VsockEventType::Received { .. } = event.event_type {
// Only consider the connected socket and copy body to buffer // Only consider the connected socket and copy body to buffer
let connected_sockets = self.connected_sockets.read_irq_disabled(); let connected_sockets = self.connected_sockets.read_irq_disabled();
let connected = connected_sockets.get(&event.into()).unwrap(); let connected = connected_sockets.get(&event.into()).unwrap();
@ -294,6 +293,6 @@ impl VsockSpace {
} }
Ok(Some(event)) Ok(Some(event))
}) })
.map_err(|e| Error::with_message(Errno::EIO, "driver poll failed")) .map_err(|_| Error::with_message(Errno::EIO, "driver poll failed"))
} }
} }

View File

@ -92,7 +92,7 @@ impl Connected {
connection.is_local_shutdown() connection.is_local_shutdown()
} }
pub fn shutdown(&self, cmd: SockShutdownCmd) -> Result<()> { pub fn shutdown(&self, _cmd: SockShutdownCmd) -> Result<()> {
// TODO: deal with cmd // TODO: deal with cmd
if self.should_close() { if self.should_close() {
let mut connection = self.connection.lock_irq_disabled(); let mut connection = self.connection.lock_irq_disabled();

View File

@ -124,7 +124,7 @@ impl VsockStreamSocket {
} }
} }
fn try_recv(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<(usize, SocketAddr)> { fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<(usize, SocketAddr)> {
let connected = match &*self.status.read() { let connected = match &*self.status.read() {
Status::Connected(connected) => connected.clone(), Status::Connected(connected) => connected.clone(),
Status::Init(_) | Status::Listen(_) => { Status::Init(_) | Status::Listen(_) => {
@ -162,14 +162,12 @@ impl FileLike for VsockStreamSocket {
fn read(&self, buf: &mut [u8]) -> Result<usize> { fn read(&self, buf: &mut [u8]) -> Result<usize> {
// TODO: Set correct flags // TODO: Set correct flags
let flags = SendRecvFlags::empty();
self.recv(buf, SendRecvFlags::empty()).map(|(len, _)| len) self.recv(buf, SendRecvFlags::empty()).map(|(len, _)| len)
} }
fn write(&self, buf: &[u8]) -> Result<usize> { fn write(&self, buf: &[u8]) -> Result<usize> {
// TODO: Set correct flags // TODO: Set correct flags
let flags = SendRecvFlags::empty(); self.send(buf, SendRecvFlags::empty())
self.send(buf, flags)
} }
fn poll(&self, mask: IoEvents, poller: Option<&Poller>) -> IoEvents { fn poll(&self, mask: IoEvents, poller: Option<&Poller>) -> IoEvents {