Skip to content

Commit

Permalink
Add rust net_device wrappers
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Behrens <me@kloenk.de>
  • Loading branch information
kloenk committed Jul 10, 2021
1 parent e97ba67 commit 3878bda
Show file tree
Hide file tree
Showing 12 changed files with 2,128 additions and 1 deletion.
31 changes: 31 additions & 0 deletions rust/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/security.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>

void rust_helper_BUG(void)
{
Expand Down Expand Up @@ -212,6 +215,34 @@ int rust_helper_security_binder_transfer_file(struct task_struct *from,
}
EXPORT_SYMBOL_GPL(rust_helper_security_binder_transfer_file);

void *rust_helper_netdev_priv(struct net_device *dev)
{
return netdev_priv(dev);
}
EXPORT_SYMBOL_GPL(rust_helper_netdev_priv);

void rust_helper_eth_hw_addr_random(struct net_device *dev)
{
eth_hw_addr_random(dev);
}
EXPORT_SYMBOL_GPL(rust_helper_eth_hw_addr_random);

int rust_helper_net_device_set_new_lstats(struct net_device *dev)
{
dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
if (!dev->lstats)
return -ENOMEM;

return 0;
}
EXPORT_SYMBOL_GPL(rust_helper_net_device_set_new_lstats);

void rust_helper_dev_lstats_add(struct net_device *dev, unsigned int len)
{
dev_lstats_add(dev, len);
}
EXPORT_SYMBOL_GPL(rust_helper_dev_lstats_add);

/* We use bindgen's --size_t-is-usize option to bind the C size_t type
* as the Rust usize type, so we can use it in contexts where Rust
* expects a usize like slice (array) indices. usize is defined to be
Expand Down
8 changes: 8 additions & 0 deletions rust/kernel/bindings_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/security.h>
#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/etherdevice.h>
#include <linux/netdev_features.h>
#include <linux/rtnetlink.h>
#include <net/rtnetlink.h>

// `bindgen` gets confused at certain things
const gfp_t BINDINGS_GFP_KERNEL = GFP_KERNEL;
const gfp_t BINDINGS___GFP_ZERO = __GFP_ZERO;

const int BINDINGS_NLA_HDRLEN = NLA_HDRLEN;
3 changes: 2 additions & 1 deletion rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod error;
pub mod file;
pub mod file_operations;
pub mod miscdev;
pub mod net;
pub mod pages;
pub mod security;
pub mod str;
Expand Down Expand Up @@ -78,7 +79,7 @@ pub mod user_ptr;
pub use build_error::build_error;

pub use crate::error::{Error, Result};
pub use crate::types::{Mode, ScopeGuard};
pub use crate::types::{Mode, SavedAsPointer, SavedAsPointerMut, ScopeGuard};

/// Page size defined in terms of the `PAGE_SHIFT` macro from C.
///
Expand Down

0 comments on commit 3878bda

Please sign in to comment.