mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-23 00:16:17 +04:00
Implement ioctl arp translation
This commit is contained in:
parent
55df9ca892
commit
b0c9087f0f
6
kernel/Cargo.lock
generated
6
kernel/Cargo.lock
generated
@ -333,7 +333,7 @@ dependencies = [
|
|||||||
"rcore-memory 0.1.0",
|
"rcore-memory 0.1.0",
|
||||||
"rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread)",
|
"rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread)",
|
||||||
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
|
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
|
||||||
"smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"smoltcp 0.5.0 (git+https://github.com/rcore-os/smoltcp)",
|
||||||
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -443,7 +443,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "smoltcp"
|
name = "smoltcp"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/rcore-os/smoltcp#107d299b41a8f8cc370e3105dda38acc33609483"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -647,7 +647,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||||
"checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c"
|
"checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c"
|
||||||
"checksum smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fef582369edb298c6c41319a544ca9c4e83622f226055ccfcb35974fbb55ed34"
|
"checksum smoltcp 0.5.0 (git+https://github.com/rcore-os/smoltcp)" = "<none>"
|
||||||
"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
|
"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
|
||||||
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
|
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
|
||||||
"checksum static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "389ce475f424f267dbed6479cbd8f126c5e1afb053b0acdaa019c74305fc65d1"
|
"checksum static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "389ce475f424f267dbed6479cbd8f126c5e1afb053b0acdaa019c74305fc65d1"
|
||||||
|
@ -62,8 +62,7 @@ endif
|
|||||||
### qemu options ###
|
### qemu options ###
|
||||||
qemu_opts := \
|
qemu_opts := \
|
||||||
-smp cores=$(smp)
|
-smp cores=$(smp)
|
||||||
qemu_net_opts := \
|
qemu_net_opts :=
|
||||||
-netdev type=tap,id=net0,script=no,downscript=no
|
|
||||||
|
|
||||||
ifeq ($(arch), x86_64)
|
ifeq ($(arch), x86_64)
|
||||||
qemu_opts += \
|
qemu_opts += \
|
||||||
@ -76,6 +75,7 @@ qemu_opts += \
|
|||||||
-device isa-debug-exit
|
-device isa-debug-exit
|
||||||
ifeq ($(pci_passthru), )
|
ifeq ($(pci_passthru), )
|
||||||
qemu_net_opts += \
|
qemu_net_opts += \
|
||||||
|
-netdev type=tap,id=net0,script=no,downscript=no \
|
||||||
-device e1000e,netdev=net0
|
-device e1000e,netdev=net0
|
||||||
else
|
else
|
||||||
qemu_opts += \
|
qemu_opts += \
|
||||||
@ -96,6 +96,7 @@ qemu_opts += \
|
|||||||
-drive file=$(SFSIMG),format=qcow2,id=sfs \
|
-drive file=$(SFSIMG),format=qcow2,id=sfs \
|
||||||
-device virtio-blk-device,drive=sfs
|
-device virtio-blk-device,drive=sfs
|
||||||
qemu_net_opts += \
|
qemu_net_opts += \
|
||||||
|
-netdev type=tap,id=net0,script=no,downscript=no \
|
||||||
-device virtio-net-device,netdev=net0
|
-device virtio-net-device,netdev=net0
|
||||||
|
|
||||||
else ifeq ($(arch), riscv64)
|
else ifeq ($(arch), riscv64)
|
||||||
@ -105,6 +106,7 @@ qemu_opts += \
|
|||||||
-drive file=$(SFSIMG),format=qcow2,id=sfs \
|
-drive file=$(SFSIMG),format=qcow2,id=sfs \
|
||||||
-device virtio-blk-device,drive=sfs
|
-device virtio-blk-device,drive=sfs
|
||||||
qemu_net_opts += \
|
qemu_net_opts += \
|
||||||
|
-netdev type=tap,id=net0,script=no,downscript=no \
|
||||||
-device virtio-net-device,netdev=net0
|
-device virtio-net-device,netdev=net0
|
||||||
|
|
||||||
else ifeq ($(arch), aarch64)
|
else ifeq ($(arch), aarch64)
|
||||||
|
@ -132,9 +132,11 @@ pub fn init_driver(dev: &PCIDevice) {
|
|||||||
active_table().map_if_not_exists(KERNEL_OFFSET + current_addr, current_addr);
|
active_table().map_if_not_exists(KERNEL_OFFSET + current_addr, current_addr);
|
||||||
current_addr = current_addr + PAGE_SIZE;
|
current_addr = current_addr + PAGE_SIZE;
|
||||||
}
|
}
|
||||||
PCI_DRIVERS
|
let index = NET_DRIVERS.read().len();
|
||||||
.lock()
|
PCI_DRIVERS.lock().insert(
|
||||||
.insert(dev.loc, ixgbe::ixgbe_init(name, irq, vaddr, len as usize));
|
dev.loc,
|
||||||
|
ixgbe::ixgbe_init(name, irq, vaddr, len as usize, index),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(0x8086, 0x2922) => {
|
(0x8086, 0x2922) => {
|
||||||
|
@ -3,7 +3,7 @@ use alloc::sync::Arc;
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use smoltcp::wire::{EthernetAddress, Ipv4Address};
|
use smoltcp::wire::{EthernetAddress, IpAddress, Ipv4Address};
|
||||||
use spin::RwLock;
|
use spin::RwLock;
|
||||||
|
|
||||||
use crate::sync::Condvar;
|
use crate::sync::Condvar;
|
||||||
@ -71,6 +71,11 @@ pub trait Driver: Send + Sync {
|
|||||||
unimplemented!("not a net driver")
|
unimplemented!("not a net driver")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get mac address from ip address in arp table
|
||||||
|
fn get_arp(&self, ip: IpAddress) -> Option<EthernetAddress> {
|
||||||
|
unimplemented!("not a net driver")
|
||||||
|
}
|
||||||
|
|
||||||
// block related drivers should implement these
|
// block related drivers should implement these
|
||||||
fn read_block(&self, block_id: usize, buf: &mut [u8]) -> bool {
|
fn read_block(&self, block_id: usize, buf: &mut [u8]) -> bool {
|
||||||
unimplemented!("not a block driver")
|
unimplemented!("not a block driver")
|
||||||
|
@ -150,7 +150,6 @@ impl Driver for E1000Interface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send an ethernet frame, only use it when necessary
|
|
||||||
fn send(&self, data: &[u8]) -> Option<usize> {
|
fn send(&self, data: &[u8]) -> Option<usize> {
|
||||||
use smoltcp::phy::TxToken;
|
use smoltcp::phy::TxToken;
|
||||||
let token = E1000TxToken(self.driver.clone());
|
let token = E1000TxToken(self.driver.clone());
|
||||||
@ -166,6 +165,12 @@ impl Driver for E1000Interface {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_arp(&self, ip: IpAddress) -> Option<EthernetAddress> {
|
||||||
|
let iface = self.iface.lock();
|
||||||
|
let cache = iface.neighbor_cache();
|
||||||
|
cache.lookup_pure(&ip, Instant::from_millis(0))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -493,7 +498,7 @@ pub fn e1000_init(name: String, irq: Option<u32>, header: usize, size: usize, in
|
|||||||
.neighbor_cache(neighbor_cache)
|
.neighbor_cache(neighbor_cache)
|
||||||
.finalize();
|
.finalize();
|
||||||
|
|
||||||
info!("e1000 interface {} has addr 10.0.{}.2/24", name, index);
|
info!("e1000 interface {} up with addr 10.0.{}.2/24", name, index);
|
||||||
let e1000_iface = E1000Interface {
|
let e1000_iface = E1000Interface {
|
||||||
iface: Mutex::new(iface),
|
iface: Mutex::new(iface),
|
||||||
driver: net_driver.clone(),
|
driver: net_driver.clone(),
|
||||||
|
@ -100,6 +100,12 @@ impl Driver for IXGBEInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_arp(&self, ip: IpAddress) -> Option<EthernetAddress> {
|
||||||
|
let iface = self.iface.lock();
|
||||||
|
let cache = iface.neighbor_cache();
|
||||||
|
cache.lookup_pure(&ip, Instant::from_millis(0))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub struct IXGBERxToken(Vec<u8>);
|
pub struct IXGBERxToken(Vec<u8>);
|
||||||
pub struct IXGBETxToken(IXGBEDriver);
|
pub struct IXGBETxToken(IXGBEDriver);
|
||||||
@ -171,6 +177,7 @@ pub fn ixgbe_init(
|
|||||||
irq: Option<u32>,
|
irq: Option<u32>,
|
||||||
header: usize,
|
header: usize,
|
||||||
size: usize,
|
size: usize,
|
||||||
|
index: usize,
|
||||||
) -> Arc<IXGBEInterface> {
|
) -> Arc<IXGBEInterface> {
|
||||||
let _ = FlagsGuard::no_irq_region();
|
let _ = FlagsGuard::no_irq_region();
|
||||||
let ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), header, size);
|
let ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), header, size);
|
||||||
@ -185,12 +192,9 @@ pub fn ixgbe_init(
|
|||||||
mtu: 1500,
|
mtu: 1500,
|
||||||
};
|
};
|
||||||
|
|
||||||
let ip_addrs = [IpCidr::new(IpAddress::v4(10, 0, 0, 2), 24)];
|
let ip_addrs = [IpCidr::new(IpAddress::v4(10, 0, index as u8, 2), 24)];
|
||||||
let neighbor_cache = NeighborCache::new(BTreeMap::new());
|
let neighbor_cache = NeighborCache::new(BTreeMap::new());
|
||||||
let mut routes = Routes::new(BTreeMap::new());
|
let routes = Routes::new(BTreeMap::new());
|
||||||
routes
|
|
||||||
.add_default_ipv4_route(Ipv4Address::new(10, 0, 0, 1))
|
|
||||||
.unwrap();
|
|
||||||
let mut iface = EthernetInterfaceBuilder::new(net_driver.clone())
|
let mut iface = EthernetInterfaceBuilder::new(net_driver.clone())
|
||||||
.ethernet_addr(ethernet_addr)
|
.ethernet_addr(ethernet_addr)
|
||||||
.ip_addrs(ip_addrs)
|
.ip_addrs(ip_addrs)
|
||||||
@ -198,7 +202,7 @@ pub fn ixgbe_init(
|
|||||||
.routes(routes)
|
.routes(routes)
|
||||||
.finalize();
|
.finalize();
|
||||||
|
|
||||||
info!("ixgbe: interface {} up", &name);
|
info!("ixgbe interface {} up with addr 10.0.{}.2/24", name, index);
|
||||||
|
|
||||||
let ixgbe_iface = IXGBEInterface {
|
let ixgbe_iface = IXGBEInterface {
|
||||||
iface: Mutex::new(iface),
|
iface: Mutex::new(iface),
|
||||||
|
@ -505,7 +505,7 @@ impl Socket for UdpSocketState {
|
|||||||
// SIOCGARP
|
// SIOCGARP
|
||||||
0x8954 => {
|
0x8954 => {
|
||||||
// FIXME: check addr
|
// FIXME: check addr
|
||||||
let req = unsafe { &mut *(request as *mut ArpReq) };
|
let req = unsafe { &mut *(arg1 as *mut ArpReq) };
|
||||||
if let AddressFamily::Internet = AddressFamily::from(req.arp_pa.family) {
|
if let AddressFamily::Internet = AddressFamily::from(req.arp_pa.family) {
|
||||||
let name = req.arp_dev.as_ptr();
|
let name = req.arp_dev.as_ptr();
|
||||||
let ifname = unsafe { util::from_cstr(name) };
|
let ifname = unsafe { util::from_cstr(name) };
|
||||||
@ -518,6 +518,14 @@ impl Socket for UdpSocketState {
|
|||||||
for iface in NET_DRIVERS.read().iter() {
|
for iface in NET_DRIVERS.read().iter() {
|
||||||
if iface.get_ifname() == ifname {
|
if iface.get_ifname() == ifname {
|
||||||
debug!("get arp matched ifname {}", ifname);
|
debug!("get arp matched ifname {}", ifname);
|
||||||
|
return match iface.get_arp(addr) {
|
||||||
|
Some(mac) => {
|
||||||
|
// TODO: update flags
|
||||||
|
req.arp_ha.data[0..6].copy_from_slice(mac.as_bytes());
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
None => Err(SysError::ENOENT),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(SysError::ENOENT)
|
Err(SysError::ENOENT)
|
||||||
|
@ -474,7 +474,7 @@ pub fn sys_dup2(fd1: usize, fd2: usize) -> SysResult {
|
|||||||
|
|
||||||
pub fn sys_ioctl(fd: usize, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult {
|
pub fn sys_ioctl(fd: usize, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult {
|
||||||
info!(
|
info!(
|
||||||
"ioctl: fd:{}, request:{}, args: {} {} {}",
|
"ioctl: fd: {}, request: {}, args: {} {} {}",
|
||||||
fd, request, arg1, arg2, arg3
|
fd, request, arg1, arg2, arg3
|
||||||
);
|
);
|
||||||
let mut proc = process();
|
let mut proc = process();
|
||||||
|
@ -70,10 +70,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
|||||||
warn!("sys_sigprocmask is unimplemented");
|
warn!("sys_sigprocmask is unimplemented");
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
SYS_IOCTL => {
|
SYS_IOCTL => sys_ioctl(args[0], args[1], args[2], args[3], args[4]),
|
||||||
warn!("sys_ioctl is unimplemented");
|
|
||||||
Ok(0)
|
|
||||||
}
|
|
||||||
SYS_PREAD64 => sys_pread(args[0], args[1] as *mut u8, args[2], args[3]),
|
SYS_PREAD64 => sys_pread(args[0], args[1] as *mut u8, args[2], args[3]),
|
||||||
SYS_PWRITE64 => sys_pwrite(args[0], args[1] as *const u8, args[2], args[3]),
|
SYS_PWRITE64 => sys_pwrite(args[0], args[1] as *const u8, args[2], args[3]),
|
||||||
SYS_READV => sys_readv(args[0], args[1] as *const IoVec, args[2]),
|
SYS_READV => sys_readv(args[0], args[1] as *const IoVec, args[2]),
|
||||||
|
Loading…
Reference in New Issue
Block a user