Skip to content

Commit

Permalink
fix dhcpd
Browse files Browse the repository at this point in the history
Signed-off-by: Anhad Singh <[email protected]>
  • Loading branch information
Andy-Python-Programmer committed Aug 4, 2023
1 parent 2adc7ac commit 41b4edc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
55 changes: 55 additions & 0 deletions src/aero_kernel/src/socket/ipv4.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

//! 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<Self> {
Arc::new(Self {})
}
}

impl INodeInterface for Ipv4Socket {
fn ioctl(&self, command: usize, arg: usize) -> Result<usize> {
match command {
SIOCGIFINDEX => {
let mut ifreq = unsafe { UserRef::<IfReq>::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!(),
}
}
}
1 change: 1 addition & 0 deletions src/aero_kernel/src/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with Aero. If not, see <https://www.gnu.org/licenses/>.

pub mod ipv4;
pub mod tcp;
pub mod udp;
pub mod unix;
Expand Down
12 changes: 1 addition & 11 deletions src/aero_kernel/src/socket/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with Aero. If not, see <https://www.gnu.org/licenses/>.

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};
Expand Down Expand Up @@ -209,16 +209,6 @@ impl INodeInterface for UdpSocket {

fn ioctl(&self, command: usize, arg: usize) -> fs::Result<usize> {
match command {
SIOCGIFINDEX => {
let mut ifreq = unsafe { UserRef::<IfReq>::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::<IfReq>::new(VirtAddr::new(arg as _)) };

Expand Down
4 changes: 3 additions & 1 deletion src/aero_kernel/src/syscall/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -123,7 +124,7 @@ fn create_socket(
socket_type: usize,
protocol: usize,
) -> Result<DirCacheItem, SyscallError> {
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 {
Expand All @@ -133,6 +134,7 @@ fn create_socket(
UdpSocket::new() as Arc<dyn INodeInterface>
}

(SocketType::Dgram, IpProtocol::Raw) => Ipv4Socket::new() as Arc<dyn INodeInterface>,
(SocketType::Stream, IpProtocol::Default | IpProtocol::Tcp) => {
TcpSocket::new() as Arc<dyn INodeInterface>
}
Expand Down

0 comments on commit 41b4edc

Please sign in to comment.