Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Cargo.lock
target
vendor/

tags
*.swp
7 changes: 4 additions & 3 deletions examples/dump_channels.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -16,10 +16,11 @@ async fn get_channels(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut channel_handle = handle.channel().get(iface_name).execute().await;
let mut channel_handle =
handle.channel().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = channel_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = channel_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
9 changes: 5 additions & 4 deletions examples/dump_coalesce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -16,11 +16,12 @@ async fn get_coalesce(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut coalesce_handle = handle.coalesce().get(iface_name).execute().await;
let mut coalesce_handle =
handle.coalesce().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = coalesce_handle.try_next().await.unwrap() {
msgs.push(msg);
while let Some(Ok(msg)) = coalesce_handle.next().await {
msgs.push(msg.payload);
}
assert!(!msgs.is_empty());
for msg in msgs {
Expand Down
7 changes: 4 additions & 3 deletions examples/dump_eeprom_page.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

fn main() {
let rt = tokio::runtime::Builder::new_current_thread()
Expand All @@ -19,10 +19,11 @@ async fn get_eeprom(iface_name: Option<&str>) {
.eeprom()
.get(iface_name, 0, 1, 0, 0, 0x50)
.execute()
.await;
.await
.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = eeprom_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = eeprom_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
7 changes: 4 additions & 3 deletions examples/dump_features.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -16,10 +16,11 @@ async fn get_feature(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut feature_handle = handle.feature().get(iface_name).execute().await;
let mut feature_handle =
handle.feature().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = feature_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = feature_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
6 changes: 3 additions & 3 deletions examples/dump_fec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -17,10 +17,10 @@ async fn get_fec(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut fec_handle = handle.fec().get(iface_name).execute().await;
let mut fec_handle = handle.fec().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = fec_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = fec_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
6 changes: 3 additions & 3 deletions examples/dump_link_mode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -17,10 +17,10 @@ async fn get_link_mode(iface_name: Option<&str>) {
tokio::spawn(connection);

let mut link_mode_handle =
handle.link_mode().get(iface_name).execute().await;
handle.link_mode().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = link_mode_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = link_mode_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
7 changes: 4 additions & 3 deletions examples/dump_pause.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -17,10 +17,11 @@ async fn get_pause(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut pause_handle = handle.pause().get(iface_name).execute().await;
let mut pause_handle =
handle.pause().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = pause_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = pause_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
7 changes: 4 additions & 3 deletions examples/dump_rings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -16,10 +16,11 @@ async fn get_ring(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut ring_handle = handle.ring().get(iface_name).execute().await;
let mut ring_handle =
handle.ring().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = ring_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = ring_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
7 changes: 4 additions & 3 deletions examples/dump_tsinfo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::stream::TryStreamExt;
use futures_util::stream::StreamExt;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -17,10 +17,11 @@ async fn get_tsinfo(iface_name: Option<&str>) {
let (connection, mut handle, _) = ethtool::new_connection().unwrap();
tokio::spawn(connection);

let mut tsinfo_handle = handle.tsinfo().get(iface_name).execute().await;
let mut tsinfo_handle =
handle.tsinfo().get(iface_name).execute().await.unwrap();

let mut msgs = Vec::new();
while let Some(msg) = tsinfo_handle.try_next().await.unwrap() {
while let Some(Ok(msg)) = tsinfo_handle.next().await {
msgs.push(msg);
}
assert!(!msgs.is_empty());
Expand Down
8 changes: 5 additions & 3 deletions src/channel/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand All @@ -20,8 +20,10 @@ impl EthtoolChannelGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolChannelGetRequest {
mut handle,
iface_name,
Expand Down
8 changes: 5 additions & 3 deletions src/coalesce/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand All @@ -20,8 +20,10 @@ impl EthtoolCoalesceGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolCoalesceGetRequest {
mut handle,
iface_name,
Expand Down
8 changes: 5 additions & 3 deletions src/eeprom/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand Down Expand Up @@ -38,8 +38,10 @@ impl EthtoolModuleEEPROMGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolModuleEEPROMGetRequest {
mut handle,
iface_name,
Expand Down
8 changes: 5 additions & 3 deletions src/feature/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand All @@ -20,8 +20,10 @@ impl EthtoolFeatureGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolFeatureGetRequest {
mut handle,
iface_name,
Expand Down
8 changes: 5 additions & 3 deletions src/fec/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand All @@ -20,8 +20,10 @@ impl EthtoolFecGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolFecGetRequest {
mut handle,
iface_name,
Expand Down
23 changes: 9 additions & 14 deletions src/handle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::{future::Either, FutureExt, Stream, StreamExt, TryStream};
use futures_util::{Stream, StreamExt};
use genetlink::GenetlinkHandle;
use netlink_packet_core::DecodeError;
use netlink_packet_core::{
Expand Down Expand Up @@ -83,7 +83,10 @@ pub(crate) async fn ethtool_execute(
handle: &mut EthtoolHandle,
is_dump: bool,
ethtool_msg: EthtoolMessage,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError> {
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let nl_header_flags = if is_dump {
// The NLM_F_ACK is required due to bug of kernel:
// https://bugzilla.redhat.com/show_bug.cgi?id=1953847
Expand All @@ -101,16 +104,8 @@ pub(crate) async fn ethtool_execute(

nl_msg.header.flags = nl_header_flags;

match handle.request(nl_msg).await {
Ok(response) => {
Either::Left(response.map(move |msg| Ok(try_ethtool!(msg))))
}
Err(e) => Either::Right(
futures_util::future::err::<
GenlMessage<EthtoolMessage>,
EthtoolError,
>(e)
.into_stream(),
),
}
Ok(handle
.request(nl_msg)
.await?
.map(move |msg| Ok(try_ethtool!(msg))))
}
8 changes: 5 additions & 3 deletions src/link_mode/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand All @@ -20,8 +20,10 @@ impl EthtoolLinkModeGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolLinkModeGetRequest {
mut handle,
iface_name,
Expand Down
8 changes: 5 additions & 3 deletions src/pause/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

use futures_util::TryStream;
use futures_util::Stream;
use netlink_packet_generic::GenlMessage;

use crate::{ethtool_execute, EthtoolError, EthtoolHandle, EthtoolMessage};
Expand All @@ -20,8 +20,10 @@ impl EthtoolPauseGetRequest {

pub async fn execute(
self,
) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
{
) -> Result<
impl Stream<Item = Result<GenlMessage<EthtoolMessage>, EthtoolError>>,
EthtoolError,
> {
let EthtoolPauseGetRequest {
mut handle,
iface_name,
Expand Down
Loading