Skip to content

Commit

Permalink
WIP: drivers/net/dummy_rs
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Behrens <me@kloenk.de>
  • Loading branch information
kloenk committed Apr 22, 2021
1 parent f4f00c7 commit 28d4703
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ config DUMMY
To compile this driver as a module, choose M here: the module
will be called dummy.

config DUMMY_RS
tristate "Dummy net driver support"
depends on HAS_RUST
help
This is essentially a bit-bucket device (i.e. traffic you send to
this device is consigned into oblivion) with a configurable IP
address. It is most commonly used in order to make your currently
inactive SLIP address seem like a real address for local programs.
If you use SLIP or PPP, you might want to say Y here. It won't
enlarge your kernel. What a deal. Read about it in the Network
Administrator's Guide, available from
<http://www.tldp.org/docs.html#guide>.

To compile this driver as a module, choose M here: the module
will be called dummy_rs.

config WIREGUARD
tristate "WireGuard secure network tunnel"
depends on NET && INET
Expand Down
1 change: 1 addition & 0 deletions drivers/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ obj-$(CONFIG_BONDING) += bonding/
obj-$(CONFIG_IPVLAN) += ipvlan/
obj-$(CONFIG_IPVTAP) += ipvlan/
obj-$(CONFIG_DUMMY) += dummy.o
obj-$(CONFIG_DUMMY_RS) += dummy_rs.o
obj-$(CONFIG_WIREGUARD) += wireguard/
obj-$(CONFIG_EQUALIZER) += eql.o
obj-$(CONFIG_IFB) += ifb.o
Expand Down
112 changes: 112 additions & 0 deletions drivers/net/dummy_rs.rs
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!();
}

0 comments on commit 28d4703

Please sign in to comment.