This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
rtnetlink: add a way to set netlink flags in requests #246
Open
little-dude
wants to merge
2
commits into
master
Choose a base branch
from
pr-237
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,132 @@ | ||
bitflags::bitflags! { | ||
pub struct GetFlags: u16 { | ||
/// Must be set on all request messages (typically from user | ||
/// space to kernel space) | ||
/// | ||
/// **This flag is set by default** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to mention that as people can tell that via |
||
const REQUEST = 1; | ||
/// Indicates the message is part of a multipart message | ||
/// terminated by NLMSG_DONE | ||
const MULTIPART = 2; | ||
/// Request for an acknowledgment on success. Typical | ||
/// direction of request is from user space (CPC) to kernel | ||
/// space (FEC). | ||
const ACK = 4; | ||
/// Echo this request. Typical direction of request is from | ||
/// user space (CPC) to kernel space (FEC). | ||
const ECHO = 8; | ||
/// Return the complete table instead of a single entry. | ||
const ROOT = 256; | ||
/// Return all entries matching criteria passed in message | ||
/// content. | ||
const MATCH = 512; | ||
/// Return an atomic snapshot of the table. Requires | ||
/// `CAP_NET_ADMIN` capability or a effective UID of 0. | ||
const ATOMIC = 1024; | ||
/// Equivalent to `ROOT|MATCH`. | ||
const DUMP = 768; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using integer is vulnerable to human error. The kernel code is using this kind format: #define NLM_F_ATOMIC 0x400
#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) So, the rust code should be const ATOMIC = 0x400;
const DUMP = Self.ROOT | Self.MATCH; |
||
} | ||
} | ||
|
||
impl GetFlags { | ||
/// Create new `GetFlags` with only `GetFlags::REQUEST`. | ||
pub fn new() -> Self { | ||
GetFlags::REQUEST | ||
} | ||
} | ||
|
||
impl Default for GetFlags { | ||
/// Create new `GetFlags` with only `GetFlags::REQUEST`. | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
bitflags::bitflags! { | ||
pub struct NewFlags: u16 { | ||
/// Must be set on all request messages (typically from user | ||
/// space to kernel space). | ||
/// | ||
/// **This flag is set by default** | ||
const REQUEST = 1; | ||
/// Indicates the message is part of a multipart message | ||
/// terminated by NLMSG_DONE | ||
const MULTIPART = 2; | ||
/// Request for an acknowledgment on success. Typical | ||
/// direction of request is from user space (CPC) to kernel | ||
/// space (FEC). | ||
/// | ||
/// **This flag is set by default** | ||
const ACK = 4; | ||
/// Echo this request. Typical direction of request is from | ||
/// user space (CPC) to kernel space (FEC). | ||
const ECHO = 8; | ||
/// Replace existing matching object. | ||
const REPLACE = 256; | ||
/// Don't replace if the object already exists. | ||
/// | ||
/// This flag is not set by default but can is pretty commonly | ||
/// used. | ||
const EXCL = 512; | ||
/// Create object if it doesn't already exist. | ||
/// | ||
/// **This flag is set by default** | ||
const CREATE = 1024; | ||
/// Add to the end of the object list. | ||
const APPEND = 2048; | ||
/// Do not delete recursively | ||
const NONREC = 256; | ||
} | ||
} | ||
|
||
impl NewFlags { | ||
/// Create new `NewFlags` with `REQUEST | ACK | CREATE` set. | ||
pub fn new() -> Self { | ||
Self::REQUEST | Self::ACK | Self::CREATE | ||
} | ||
} | ||
|
||
impl Default for NewFlags { | ||
/// Create new `NewFlags` with `REQUEST | ACK | CREATE` set. | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
bitflags::bitflags! { | ||
pub struct DelFlags: u16 { | ||
/// Must be set on all request messages (typically from user | ||
/// space to kernel space) | ||
/// | ||
/// **This flag is set by default** | ||
const REQUEST = 1; | ||
/// Indicates the message is part of a multipart message | ||
/// terminated by NLMSG_DONE | ||
const MULTIPART = 2; | ||
/// Request for an acknowledgment on success. Typical | ||
/// direction of request is from user space (CPC) to kernel | ||
/// space (FEC). | ||
/// | ||
/// **This flag is set by default** | ||
const ACK = 4; | ||
/// Echo this request. Typical direction of request is from | ||
/// user space (CPC) to kernel space (FEC). | ||
const ECHO = 8; | ||
/// Do not delete recursively | ||
const NONREC = 256; | ||
} | ||
} | ||
|
||
impl DelFlags { | ||
/// Create a new `DelFlags` with `REQUEST | ACK` set | ||
pub fn new() -> Self { | ||
Self::REQUEST | Self::ACK | ||
} | ||
} | ||
|
||
impl Default for DelFlags { | ||
/// Create a new `DelFlags` with `REQUEST | ACK` set | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -48,4 +48,5 @@ pub mod proto { | |
} | ||
pub use netlink_proto::sys; | ||
|
||
pub mod flags; | ||
mod macros; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
linux/netlink.h
does not say these flags is for rtnetlink only. I think there is no need to distinguish Get and Del, in stead, just name them asNetlinkMessageFlag
and place tonetlink-proto
.The user of this crate should aware only small potion of those flags is available for get , delete and etc.