Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

rtnetlink/neigh: add append helper to AF_BRIDGE #237

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 19 additions & 2 deletions rtnetlink/src/neighbour/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct NeighbourAddRequest {
handle: Handle,
message: NeighbourMessage,
replace: bool,
append: bool,
}

impl NeighbourAddRequest {
Expand All @@ -42,6 +43,7 @@ impl NeighbourAddRequest {
handle,
message,
replace: false,
append: false,
}
}

Expand All @@ -59,6 +61,7 @@ impl NeighbourAddRequest {
handle,
message,
replace: false,
append: false,
}
}

Expand Down Expand Up @@ -128,17 +131,31 @@ impl NeighbourAddRequest {
}
}

/// Append to the end of the neighbours list (equivalent to `bridge fdb append`).
pub fn replace(self) -> Self {
Self {
replace: true,
..self
}
}

/// Execute the request.
pub async fn execute(self) -> Result<(), Error> {
let NeighbourAddRequest {
mut handle,
message,
replace,
append,
} = self;

let mut req = NetlinkMessage::from(RtnlMessage::NewNeighbour(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;
let mut flag = if replace { NLM_F_REPLACE } else { NLM_F_EXCL };

if append {
flag = NLM_F_APPEND;
}

req.header.flags = NLM_F_REQUEST | NLM_F_ACK | flag | NLM_F_CREATE;

let mut response = handle.request(req)?;
while let Some(message) = response.next().await {
Expand Down