Skip to content

Commit 419ef04

Browse files
committed
Add rust net_device wrappers
Signed-off-by: Finn Behrens <me@kloenk.de>
1 parent e97ba67 commit 419ef04

File tree

12 files changed

+2115
-0
lines changed

12 files changed

+2115
-0
lines changed

rust/helpers.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <linux/mutex.h>
1212
#include <linux/platform_device.h>
1313
#include <linux/security.h>
14+
#include <linux/netdevice.h>
15+
#include <linux/etherdevice.h>
16+
#include <linux/rtnetlink.h>
1417

1518
void rust_helper_BUG(void)
1619
{
@@ -212,6 +215,34 @@ int rust_helper_security_binder_transfer_file(struct task_struct *from,
212215
}
213216
EXPORT_SYMBOL_GPL(rust_helper_security_binder_transfer_file);
214217

218+
void *rust_helper_netdev_priv(struct net_device *dev)
219+
{
220+
return netdev_priv(dev);
221+
}
222+
EXPORT_SYMBOL_GPL(rust_helper_netdev_priv);
223+
224+
void rust_helper_eth_hw_addr_random(struct net_device *dev)
225+
{
226+
eth_hw_addr_random(dev);
227+
}
228+
EXPORT_SYMBOL_GPL(rust_helper_eth_hw_addr_random);
229+
230+
int rust_helper_net_device_set_new_lstats(struct net_device *dev)
231+
{
232+
dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
233+
if (!dev->lstats)
234+
return -ENOMEM;
235+
236+
return 0;
237+
}
238+
EXPORT_SYMBOL_GPL(rust_helper_net_device_set_new_lstats);
239+
240+
void rust_helper_dev_lstats_add(struct net_device *dev, unsigned int len)
241+
{
242+
dev_lstats_add(dev, len);
243+
}
244+
EXPORT_SYMBOL_GPL(rust_helper_dev_lstats_add);
245+
215246
/* We use bindgen's --size_t-is-usize option to bind the C size_t type
216247
* as the Rust usize type, so we can use it in contexts where Rust
217248
* expects a usize like slice (array) indices. usize is defined to be

rust/kernel/bindings_helper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
#include <linux/platform_device.h>
1919
#include <linux/of_platform.h>
2020
#include <linux/security.h>
21+
#include <linux/netdevice.h>
22+
#include <linux/ethtool.h>
23+
#include <linux/etherdevice.h>
24+
#include <linux/netdev_features.h>
25+
#include <linux/rtnetlink.h>
26+
#include <net/rtnetlink.h>
2127

2228
// `bindgen` gets confused at certain things
2329
const gfp_t BINDINGS_GFP_KERNEL = GFP_KERNEL;
2430
const gfp_t BINDINGS___GFP_ZERO = __GFP_ZERO;
31+
32+
const int BINDINGS_NLA_HDRLEN = NLA_HDRLEN;

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod error;
4444
pub mod file;
4545
pub mod file_operations;
4646
pub mod miscdev;
47+
pub mod net;
4748
pub mod pages;
4849
pub mod security;
4950
pub mod str;

0 commit comments

Comments
 (0)