Skip to content

Commit 41b4edc

Browse files
fix dhcpd
Signed-off-by: Anhad Singh <[email protected]>
1 parent 2adc7ac commit 41b4edc

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

src/aero_kernel/src/socket/ipv4.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (C) 2021-2023 The Aero Project Developers.
2+
//
3+
// This file is part of The Aero Project.
4+
//
5+
// Aero is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Aero is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
17+
18+
//! IPv4 or `AF_RAW` sockets.
19+
20+
use alloc::sync::Arc;
21+
22+
use aero_syscall::prelude::{IfReq, SIOCGIFINDEX};
23+
24+
use crate::arch::user_copy::UserRef;
25+
26+
use crate::fs::inode::INodeInterface;
27+
use crate::fs::Result;
28+
29+
use crate::mem::paging::VirtAddr;
30+
31+
pub struct Ipv4Socket {}
32+
33+
impl Ipv4Socket {
34+
pub fn new() -> Arc<Self> {
35+
Arc::new(Self {})
36+
}
37+
}
38+
39+
impl INodeInterface for Ipv4Socket {
40+
fn ioctl(&self, command: usize, arg: usize) -> Result<usize> {
41+
match command {
42+
SIOCGIFINDEX => {
43+
let mut ifreq = unsafe { UserRef::<IfReq>::new(VirtAddr::new(arg as _)) };
44+
45+
let name = ifreq.name().unwrap();
46+
assert!(name == "eth0");
47+
48+
ifreq.data.ifindex = 1; // FIXME: Fill the actual interface index
49+
Ok(0)
50+
}
51+
52+
_ => unimplemented!(),
53+
}
54+
}
55+
}

src/aero_kernel/src/socket/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717

18+
pub mod ipv4;
1819
pub mod tcp;
1920
pub mod udp;
2021
pub mod unix;

src/aero_kernel/src/socket/udp.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717

18-
use aero_syscall::prelude::{IfReq, SIOCGIFHWADDR, SIOCGIFINDEX, SIOCSIFADDR, SIOCSIFNETMASK};
18+
use aero_syscall::prelude::{IfReq, SIOCGIFHWADDR, SIOCSIFADDR, SIOCSIFNETMASK};
1919
use aero_syscall::socket::{MessageFlags, MessageHeader};
2020
use aero_syscall::{OpenFlags, SocketAddrInet};
2121
use alloc::sync::{Arc, Weak};
@@ -209,16 +209,6 @@ impl INodeInterface for UdpSocket {
209209

210210
fn ioctl(&self, command: usize, arg: usize) -> fs::Result<usize> {
211211
match command {
212-
SIOCGIFINDEX => {
213-
let mut ifreq = unsafe { UserRef::<IfReq>::new(VirtAddr::new(arg as _)) };
214-
215-
let name = ifreq.name().unwrap();
216-
assert!(name == "eth0");
217-
218-
ifreq.data.ifindex = 1; // FIXME: Fill the actual interface index
219-
Ok(0)
220-
}
221-
222212
SIOCGIFHWADDR => {
223213
let mut ifreq = unsafe { UserRef::<IfReq>::new(VirtAddr::new(arg as _)) };
224214

src/aero_kernel/src/syscall/net.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::fs::cache::DirCacheItem;
99
use crate::fs::inode::{DirEntry, INodeInterface};
1010
use crate::mem::paging::VirtAddr;
1111

12+
use crate::socket::ipv4::Ipv4Socket;
1213
use crate::socket::tcp::TcpSocket;
1314
use crate::socket::udp::UdpSocket;
1415
use crate::socket::unix::*;
@@ -123,7 +124,7 @@ fn create_socket(
123124
socket_type: usize,
124125
protocol: usize,
125126
) -> Result<DirCacheItem, SyscallError> {
126-
let typ = SocketType::from_usize(socket_type).ok_or(SyscallError::EINVAL)?;
127+
let typ = SocketType::from_usize(socket_type & 0b1111).ok_or(SyscallError::EINVAL)?;
127128
let protocol = IpProtocol::from_usize(protocol).ok_or(SyscallError::EINVAL)?;
128129

129130
let socket = match domain as u32 {
@@ -133,6 +134,7 @@ fn create_socket(
133134
UdpSocket::new() as Arc<dyn INodeInterface>
134135
}
135136

137+
(SocketType::Dgram, IpProtocol::Raw) => Ipv4Socket::new() as Arc<dyn INodeInterface>,
136138
(SocketType::Stream, IpProtocol::Default | IpProtocol::Tcp) => {
137139
TcpSocket::new() as Arc<dyn INodeInterface>
138140
}

0 commit comments

Comments
 (0)