ethtool/channel/
set.rs

1// SPDX-License-Identifier: MIT
2
3use futures::TryStream;
4use netlink_packet_generic::GenlMessage;
5
6use crate::{
7    ethtool_execute, EthtoolAttr, EthtoolChannelAttr, EthtoolError,
8    EthtoolHandle, EthtoolMessage,
9};
10
11pub struct EthtoolChannelSetRequest {
12    handle: EthtoolHandle,
13    message: EthtoolMessage,
14    rx_count: Option<u32>,
15    tx_count: Option<u32>,
16    other_count: Option<u32>,
17    combined_count: Option<u32>,
18}
19
20impl EthtoolChannelSetRequest {
21    pub(crate) fn new(handle: EthtoolHandle, iface_name: &str) -> Self {
22        EthtoolChannelSetRequest {
23            handle,
24            message: EthtoolMessage::new_channel_set(iface_name),
25            rx_count: None,
26            tx_count: None,
27            other_count: None,
28            combined_count: None,
29        }
30    }
31
32    pub fn rx_count(mut self, count: u32) -> Self {
33        self.rx_count = Some(count);
34        self
35    }
36
37    pub fn tx_count(mut self, count: u32) -> Self {
38        self.tx_count = Some(count);
39        self
40    }
41
42    pub fn other_count(mut self, count: u32) -> Self {
43        self.other_count = Some(count);
44        self
45    }
46
47    pub fn combined_count(mut self, count: u32) -> Self {
48        self.combined_count = Some(count);
49        self
50    }
51
52    pub async fn execute(
53        self,
54    ) -> impl TryStream<Ok = GenlMessage<EthtoolMessage>, Error = EthtoolError>
55    {
56        let EthtoolChannelSetRequest {
57            mut handle,
58            mut message,
59            rx_count,
60            tx_count,
61            other_count,
62            combined_count,
63        } = self;
64
65        if let Some(count) = rx_count {
66            message
67                .nlas
68                .push(EthtoolAttr::Channel(EthtoolChannelAttr::RxCount(count)));
69        }
70        if let Some(count) = tx_count {
71            message
72                .nlas
73                .push(EthtoolAttr::Channel(EthtoolChannelAttr::TxCount(count)));
74        }
75        if let Some(count) = other_count {
76            message.nlas.push(EthtoolAttr::Channel(
77                EthtoolChannelAttr::OtherCount(count),
78            ));
79        }
80        if let Some(count) = combined_count {
81            message.nlas.push(EthtoolAttr::Channel(
82                EthtoolChannelAttr::CombinedCount(count),
83            ));
84        }
85
86        ethtool_execute(&mut handle, false, message).await
87    }
88}