Skip to content
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

feat: option to specify netlink header flags in LinkAddRequest #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/link/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl VxlanAddRequest {
pub struct LinkAddRequest {
handle: Handle,
message: LinkMessage,
replace: bool,
extra_flags: u16,
}

/// A quality-of-service mapping between the internal priority `from` to the
Expand All @@ -559,7 +559,7 @@ impl LinkAddRequest {
LinkAddRequest {
handle,
message: LinkMessage::default(),
replace: false,
extra_flags: NLM_F_EXCL | NLM_F_CREATE,
}
}

Expand All @@ -568,12 +568,11 @@ impl LinkAddRequest {
let LinkAddRequest {
mut handle,
message,
replace,
extra_flags,
} = self;
let mut req =
NetlinkMessage::from(RouteNetlinkMessage::NewLink(message));
let replace = if replace { NLM_F_REPLACE } else { NLM_F_EXCL };
req.header.flags = NLM_F_REQUEST | NLM_F_ACK | replace | NLM_F_CREATE;
req.header.flags = NLM_F_REQUEST | NLM_F_ACK | extra_flags;

let mut response = handle.request(req)?;
while let Some(message) = response.next().await {
Expand Down Expand Up @@ -771,7 +770,15 @@ impl LinkAddRequest {
/// Replace existing matching link.
pub fn replace(self) -> Self {
Self {
replace: true,
extra_flags: NLM_F_REPLACE | (self.extra_flags & (!NLM_F_EXCL)),
..self
}
}

/// Overrides the flags used on request execution
pub fn flags(self, flags: u16) -> Self {
Self {
extra_flags: flags,
..self
}
}
Expand Down
Loading