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

Support ip route get #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/addr/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use futures::{
future::{self, Either},
stream::{StreamExt, TryStream, TryStreamExt},
stream::{Stream, StreamExt, TryStreamExt},
FutureExt,
};
use std::net::IpAddr;
Expand Down Expand Up @@ -34,7 +34,7 @@ impl AddressGetRequest {
&mut self.message
}

pub fn execute(self) -> impl TryStream<Ok = AddressMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<AddressMessage, Error>> {
let AddressGetRequest {
mut handle,
message,
Expand Down
4 changes: 2 additions & 2 deletions src/link/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use futures::{
future::{self, Either},
stream::{StreamExt, TryStream},
stream::{Stream, StreamExt},
FutureExt,
};
use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
Expand Down Expand Up @@ -48,7 +48,7 @@ impl LinkGetRequest {
}

/// Execute the request
pub fn execute(self) -> impl TryStream<Ok = LinkMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<LinkMessage, Error>> {
let LinkGetRequest {
mut handle,
message,
Expand Down
4 changes: 2 additions & 2 deletions src/neighbour/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use futures::{
future::{self, Either},
stream::{StreamExt, TryStream},
stream::{Stream, StreamExt},
FutureExt,
};
use netlink_packet_core::{
Expand Down Expand Up @@ -41,7 +41,7 @@ impl NeighbourGetRequest {
/// Execute the request
pub fn execute(
self,
) -> impl TryStream<Ok = NeighbourMessage, Error = Error> {
) -> impl Stream<Item = Result<NeighbourMessage, Error>> {
let NeighbourGetRequest {
mut handle,
message,
Expand Down
18 changes: 14 additions & 4 deletions src/route/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

use futures::{
future::{self, Either},
stream::{StreamExt, TryStream},
stream::{Stream, StreamExt},
FutureExt,
};

use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
use netlink_packet_route::{
route::RouteMessage, AddressFamily, RouteNetlinkMessage,
route::{RouteAttribute, RouteMessage},
AddressFamily, RouteNetlinkMessage,
};

use crate::{try_rtnl, Error, Handle};
Expand Down Expand Up @@ -45,15 +46,24 @@ impl RouteGetRequest {
&mut self.message
}

pub fn execute(self) -> impl TryStream<Ok = RouteMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<RouteMessage, Error>> {
let RouteGetRequest {
mut handle,
message,
} = self;

let has_dest = message
.attributes
.iter()
.any(|attr| matches!(attr, RouteAttribute::Destination(_)));

let mut req =
NetlinkMessage::from(RouteNetlinkMessage::GetRoute(message));
req.header.flags = NLM_F_REQUEST | NLM_F_DUMP;
req.header.flags = NLM_F_REQUEST;

if !has_dest {
req.header.flags |= NLM_F_DUMP;
}

match handle.request(req) {
Ok(response) => Either::Left(response.map(move |msg| {
Expand Down
4 changes: 2 additions & 2 deletions src/rule/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use futures::{
future::{self, Either},
stream::{StreamExt, TryStream},
stream::{Stream, StreamExt},
FutureExt,
};
use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
Expand Down Expand Up @@ -37,7 +37,7 @@ impl RuleGetRequest {
&mut self.message
}

pub fn execute(self) -> impl TryStream<Ok = RuleMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<RuleMessage, Error>> {
let RuleGetRequest {
mut handle,
message,
Expand Down
10 changes: 5 additions & 5 deletions src/traffic_control/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use futures::{
future::{self, Either},
stream::{StreamExt, TryStream},
stream::{Stream, StreamExt},
FutureExt,
};
use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
Expand All @@ -27,7 +27,7 @@ impl QDiscGetRequest {
}

/// Execute the request
pub fn execute(self) -> impl TryStream<Ok = TcMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<TcMessage, Error>> {
let QDiscGetRequest {
mut handle,
message,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl TrafficClassGetRequest {
}

/// Execute the request
pub fn execute(self) -> impl TryStream<Ok = TcMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<TcMessage, Error>> {
let TrafficClassGetRequest {
mut handle,
message,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl TrafficFilterGetRequest {
}

/// Execute the request
pub fn execute(self) -> impl TryStream<Ok = TcMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<TcMessage, Error>> {
let TrafficFilterGetRequest {
mut handle,
message,
Expand Down Expand Up @@ -148,7 +148,7 @@ impl TrafficChainGetRequest {
}

/// Execute the request
pub fn execute(self) -> impl TryStream<Ok = TcMessage, Error = Error> {
pub fn execute(self) -> impl Stream<Item = Result<TcMessage, Error>> {
let TrafficChainGetRequest {
mut handle,
message,
Expand Down