From 41b4edc8342d915cb75d673fffb24b657de3ab7a Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Fri, 4 Aug 2023 19:40:16 +1000 Subject: [PATCH] fix dhcpd Signed-off-by: Anhad Singh --- src/aero_kernel/src/socket/ipv4.rs | 55 ++++++++++++++++++++++++++++++ src/aero_kernel/src/socket/mod.rs | 1 + src/aero_kernel/src/socket/udp.rs | 12 +------ src/aero_kernel/src/syscall/net.rs | 4 ++- 4 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/aero_kernel/src/socket/ipv4.rs diff --git a/src/aero_kernel/src/socket/ipv4.rs b/src/aero_kernel/src/socket/ipv4.rs new file mode 100644 index 00000000000..d27895816a3 --- /dev/null +++ b/src/aero_kernel/src/socket/ipv4.rs @@ -0,0 +1,55 @@ +// Copyright (C) 2021-2023 The Aero Project Developers. +// +// This file is part of The Aero Project. +// +// Aero is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Aero is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Aero. If not, see . + +//! IPv4 or `AF_RAW` sockets. + +use alloc::sync::Arc; + +use aero_syscall::prelude::{IfReq, SIOCGIFINDEX}; + +use crate::arch::user_copy::UserRef; + +use crate::fs::inode::INodeInterface; +use crate::fs::Result; + +use crate::mem::paging::VirtAddr; + +pub struct Ipv4Socket {} + +impl Ipv4Socket { + pub fn new() -> Arc { + Arc::new(Self {}) + } +} + +impl INodeInterface for Ipv4Socket { + fn ioctl(&self, command: usize, arg: usize) -> Result { + match command { + SIOCGIFINDEX => { + let mut ifreq = unsafe { UserRef::::new(VirtAddr::new(arg as _)) }; + + let name = ifreq.name().unwrap(); + assert!(name == "eth0"); + + ifreq.data.ifindex = 1; // FIXME: Fill the actual interface index + Ok(0) + } + + _ => unimplemented!(), + } + } +} diff --git a/src/aero_kernel/src/socket/mod.rs b/src/aero_kernel/src/socket/mod.rs index 07a89ca8f5a..987bcb46f24 100644 --- a/src/aero_kernel/src/socket/mod.rs +++ b/src/aero_kernel/src/socket/mod.rs @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Aero. If not, see . +pub mod ipv4; pub mod tcp; pub mod udp; pub mod unix; diff --git a/src/aero_kernel/src/socket/udp.rs b/src/aero_kernel/src/socket/udp.rs index e39f9a8b819..4e45c8d83b2 100644 --- a/src/aero_kernel/src/socket/udp.rs +++ b/src/aero_kernel/src/socket/udp.rs @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Aero. If not, see . -use aero_syscall::prelude::{IfReq, SIOCGIFHWADDR, SIOCGIFINDEX, SIOCSIFADDR, SIOCSIFNETMASK}; +use aero_syscall::prelude::{IfReq, SIOCGIFHWADDR, SIOCSIFADDR, SIOCSIFNETMASK}; use aero_syscall::socket::{MessageFlags, MessageHeader}; use aero_syscall::{OpenFlags, SocketAddrInet}; use alloc::sync::{Arc, Weak}; @@ -209,16 +209,6 @@ impl INodeInterface for UdpSocket { fn ioctl(&self, command: usize, arg: usize) -> fs::Result { match command { - SIOCGIFINDEX => { - let mut ifreq = unsafe { UserRef::::new(VirtAddr::new(arg as _)) }; - - let name = ifreq.name().unwrap(); - assert!(name == "eth0"); - - ifreq.data.ifindex = 1; // FIXME: Fill the actual interface index - Ok(0) - } - SIOCGIFHWADDR => { let mut ifreq = unsafe { UserRef::::new(VirtAddr::new(arg as _)) }; diff --git a/src/aero_kernel/src/syscall/net.rs b/src/aero_kernel/src/syscall/net.rs index 05d90a22f55..b16a4e9360a 100644 --- a/src/aero_kernel/src/syscall/net.rs +++ b/src/aero_kernel/src/syscall/net.rs @@ -9,6 +9,7 @@ use crate::fs::cache::DirCacheItem; use crate::fs::inode::{DirEntry, INodeInterface}; use crate::mem::paging::VirtAddr; +use crate::socket::ipv4::Ipv4Socket; use crate::socket::tcp::TcpSocket; use crate::socket::udp::UdpSocket; use crate::socket::unix::*; @@ -123,7 +124,7 @@ fn create_socket( socket_type: usize, protocol: usize, ) -> Result { - let typ = SocketType::from_usize(socket_type).ok_or(SyscallError::EINVAL)?; + let typ = SocketType::from_usize(socket_type & 0b1111).ok_or(SyscallError::EINVAL)?; let protocol = IpProtocol::from_usize(protocol).ok_or(SyscallError::EINVAL)?; let socket = match domain as u32 { @@ -133,6 +134,7 @@ fn create_socket( UdpSocket::new() as Arc } + (SocketType::Dgram, IpProtocol::Raw) => Ipv4Socket::new() as Arc, (SocketType::Stream, IpProtocol::Default | IpProtocol::Tcp) => { TcpSocket::new() as Arc }