forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Finn Behrens <[email protected]>
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
//! Rust dummy network driver | ||
#![no_std] | ||
#![feature(allocator_api, global_asm)] | ||
|
||
use kernel::prelude::*; | ||
use kernel::net::prelude::*; | ||
use kernel::net::device; | ||
|
||
module! { | ||
type: RustNetDummy, | ||
name: b"dummy_rs", | ||
author: b"Rust for Linux Contributors", | ||
description: b"Rust dummy network driver", | ||
license: b"GPL v2", | ||
params: { | ||
numdummies: usize { | ||
default: 0, | ||
permissions: 0o644, | ||
description: b"Number of dummy_rs pseudo devices", | ||
}, | ||
}, | ||
} | ||
|
||
fn setup(dev: &mut NetDevice<DummyRsDev>) { | ||
dev.ether_setup(); | ||
|
||
// Fill in device structure with ethernet-generic values. | ||
dev.add_flag(device::Iff::NOARP); | ||
dev.remove_flag(device::Iff::MULTICAST); | ||
|
||
dev.add_private_flag(device::IffPriv::LIVE_ADDR_CHANGE); | ||
dev.add_private_flag(device::IffPriv::IFF_NO_QUEUE); | ||
|
||
dev.add_feature(device::Feature::NETIF_F_SG); | ||
dev.add_feature(device::Feature::NETIF_F_FRAGLIST_BIT); | ||
dev.add_feature(device::Feature::NETIF_F_GSO_SOFTWARE); | ||
} | ||
|
||
rtnl_link_ops! { | ||
kind: b"dummy_rs", | ||
type: DummyRsDev, | ||
setup: setup, | ||
maxtype: 20, | ||
} | ||
|
||
struct RustNetDummy { | ||
dev: NetDevice<DummyRsDev>, | ||
} | ||
|
||
|
||
impl KernelModule for RustNetDummy { | ||
fn init() -> KernelResult<Self> { | ||
{ | ||
let lock =THIS_MODULE.kernel_param_lock(); | ||
pr_info!("Rust Network Dummy with {} pseudo devices\n", numdummies.read(&lock)); | ||
} | ||
|
||
let dev = NetDevice::new(DummyRsDev, kernel::cstr!("dummyrs%d"), kernel::net::device::NetNameAssingType::Enum, 1, 1)?; | ||
|
||
if let Err(e) = dev.register() { | ||
pr_warn!("could not register: {}", e.to_kernel_errno()); | ||
} | ||
|
||
Ok(RustNetDummy { | ||
dev, | ||
}) | ||
} | ||
} | ||
|
||
impl Drop for RustNetDummy { | ||
fn drop(&mut self) { | ||
pr_info!("remove rust net dummy"); | ||
// TODO | ||
} | ||
} | ||
|
||
|
||
struct DummyRsDev; | ||
|
||
impl NetDeviceOps<Self> for DummyRsDev { | ||
kernel::declare_net_device_ops!(); | ||
|
||
fn init(dev: &NetDevice<Self>) -> KernelResult<()> { | ||
Ok(()) | ||
} | ||
|
||
fn uninit(dev: &NetDevice<Self>) { | ||
|
||
} | ||
} | ||
|
||
impl NetDeviceAdapter for DummyRsDev { | ||
type Inner = Self; | ||
|
||
type Ops = Self; | ||
|
||
type EthOps = Self; | ||
|
||
fn setup(dev: &mut NetDevice<Self>) { | ||
pr_info!("called netdev_setup"); | ||
//dev.rtnl_link_ops = unsafe { &dummy_rs_rtnl_link_ops as *const kernel::bindings::rtnl_link_ops as *mut _ }; | ||
dev.set_rtnl_ops( unsafe { &dummy_rs_rtnl_link_ops }); | ||
|
||
} | ||
} | ||
|
||
impl EthToolOps<Self> for DummyRsDev { | ||
kernel::declare_eth_tool_ops!(); | ||
} |