-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[net] Add Ethernet lengths and Header/Address types #1014
base: rust
Are you sure you want to change the base?
Conversation
Force-pushed with changes suggested by @bjorn3 . EDIT: I missed the answer to whether or not to use |
Nit: to be clear, that applies to the |
My bad, I forgot that |
rust/kernel/net/ethernet.rs
Outdated
/// Return the unspecified Ethernet address | ||
pub const fn get_address_unspecified() -> Address { | ||
Address([0x00; ALEN]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was originally thinking about const ADDRESS_UNSPECIFIED: Address = Address([0x00; ALEN]);
but this works too I guess. By the way does the C side have similar constants, or is it manually written everywhere?
Edit: Found eth_zero_addr()
and eth_broadcast_addr()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Those are the functions I originally copied from C, which is why I thought about making them functions first.
I could make them into associated methods to Address though? That'd mirror the way Ipv4Addr works IIRC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. And yeah, making them methods would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved them to Address::broadcast()
and Address::unspecified()
.
This patch adds a module to the `net` module of `kernel` that provides constants for ethernet lengths (address length, type length, etc), as well as the enumeration of all protocols currently understood by the network stack. The latter are represented as 16-bit integers in memory to simplify conversion to and from the types read directly from Ethernet II frames. This patch also contains a conversion from/to `u16`. The `ethernet` module also contains a `Header` abstraction that just wraps around `struct ethhdr` defined in the UAPI. There is a simple builder function implemented as well as getters for src/dst address, and protocol number. Signed-off-by: Amélie Gonzalez <[email protected]>
(proper patch note below)
I know this repo is sort of meant to stay as an archive as development has moved to mainline. I'm only based on
rust
because I needed the fundamentals ofnet
.This PR is just a showcase of some of the most uncontroversial and menial work (the kind you script with
sed
eventually) I had to do in the course of a work project where I wrote the necessary abstractions to have a tunneling driver (including RTNL, NAPI, someDevice
stuff, someSkBuff
stuff, UDP Sockets, etc) working in Rust for Linux. I know the infrastructure fornet
is slowly being added torust-next
by Tomonori FUJITA[1], and that base is needed for me to even begin to consider the idea of presenting any of the rest I have to that branch.I'm just looking for feedback, like protocol names, conventions used for naming structs, methods and enums. Anything that can be improved.
[1]: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
This patch adds a module to the
net
module ofkernel
that provides enumerations with constants for ethernet lengths (address length, type length, etc), as well as the enumeration of all protocols currently understood by the network stack. The latter are represented as 16-bit integers in memory to simplify conversion to and from the types read directly from Ethernet II frames. This patch also contains a conversion from/tou16
.The
ethernet
module also contains aHeader
abstraction that just wraps aroundstruct ethhdr
defined in the UAPI. There is a simple builder function implemented as well as getters for src/dst address, and protocol number.