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

Add channel get and set functionality #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

connorworley
Copy link

I wrote this before realizing #8 already adds get functionality, oops. This also adds set functionality.

@cathay4t
Copy link
Member

Let's wait #8 been updated and merged.

@connorworley
Copy link
Author

@cathay4t that PR seems to be abandoned. Any objection to continuing here?

@cathay4t
Copy link
Member

@cathay4t that PR seems to be abandoned. Any objection to continuing here?

Please continue here. Thanks!

@connorworley
Copy link
Author

OK, ready for review :)

@cathay4t
Copy link
Member

@connorworley The code looks good. Could you include a unit test like https://github.com/rust-netlink/netlink-packet-route/blob/main/src/link/tests/bond.rs or at lease provide a example code?

I tried strace -s 1000 ethtool -l enp86s0, it seems ethtool is using netlink, so it should be easy to capture the netlink package using nlmon suggested at https://github.com/rust-netlink/netlink-packet-route/blob/main/README.md

}
}

pub fn rx_count(mut self, count: u32) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of every function pushing a NLA, could you try builder way like rust-netlink/rtnetlink#57

@connorworley connorworley requested a review from cathay4t May 22, 2024 05:32
@xujunjie-cover
Copy link

xujunjie-cover commented Jul 7, 2024

@connorworley hello,I try to set combined like this.

async fn set_channel(iface_name: &str, count: u32) {
    let (connection, mut handle, _) = ethtool::new_connection().unwrap();
    tokio::spawn(connection);

    let mut request = handle.channel().set(iface_name).combined_count(count).execute().await;

    match a.try_next().await {
        Ok(Some(msg)) => {
            println!("{msg:?}");
        }
        Ok(None) => {
            println!("No message");
        }
        Err(e) => {
            eprintln!("Error: {:?}", e);
        }
    }
}

but no msg in stream. It will be blocked.
Did I use the wrong method.
thanks

Perhaps I need to use notify?

@xujunjie-cover
Copy link

@connorworley hello,I try to set combined like this.

async fn set_channel(iface_name: &str, count: u32) {
    let (connection, mut handle, _) = ethtool::new_connection().unwrap();
    tokio::spawn(connection);

    let mut request = handle.channel().set(iface_name).combined_count(count).execute().await;

    match a.try_next().await {
        Ok(Some(msg)) => {
            println!("{msg:?}");
        }
        Ok(None) => {
            println!("No message");
        }
        Err(e) => {
            eprintln!("Error: {:?}", e);
        }
    }
}

but no msg in stream. It will be blocked. Did I use the wrong method. thanks

Perhaps I need to use notify?

strace info

mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb5560cb000
arch_prctl(ARCH_SET_FS, 0x7fb5560cb740) = 0
set_tid_address(0x7fb5560cba10)         = 8210
set_robust_list(0x7fb5560cba20, 24)     = 0
mprotect(0x7fb5562b7000, 12288, PROT_READ) = 0
mprotect(0x7fb5562cb000, 4096, PROT_READ) = 0
mprotect(0x7fb5563a7000, 4096, PROT_READ) = 0
mprotect(0x5629996a9000, 53248, PROT_READ) = 0
mprotect(0x7fb5563e5000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=10240*1024, rlim_max=20480*1024}) = 0
munmap(0x7fb5563ab000, 48603)           = 0
getrandom("\x63\xc8\xfb\x44\xf2\xf7\x7e\x7c", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x562999ba8000
brk(0x562999bc9000)                     = 0x562999bc9000
socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) = 3
setsockopt(3, SOL_NETLINK, NETLINK_EXT_ACK, [1], 4) = 0
bind(3, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, nl_pid=8210, nl_groups=00000000}, [12]) = 0
sendto(3, [{nlmsg_len=32, nlmsg_type=nlctrl, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=1, nlmsg_pid=0}, "\x03\x01\x00\x00\x0c\x00\x02\x00\x65\x74\x68\x74\x6f\x6f\x6c\x00"], 32, 0, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 32
recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{nlmsg_len=656, nlmsg_type=nlctrl, nlmsg_flags=0, nlmsg_seq=1, nlmsg_pid=8210}, "\x01\x02\x00\x00\x0c\x00\x02\x00\x65\x74\x68\x74\x6f\x6f\x6c\x00\x06\x00\x01\x00\x15\x00\x00\x00\x08\x00\x03\x00\x01\x00\x00\x00"...], iov_len=65536}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 656
recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{nlmsg_len=36, nlmsg_type=NLMSG_ERROR, nlmsg_flags=NLM_F_CAPPED, nlmsg_seq=1, nlmsg_pid=8210}, {error=0, msg={nlmsg_len=32, nlmsg_type=nlctrl, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=1, nlmsg_pid=0}}], iov_len=65536}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 36
sendto(3, [{nlmsg_len=44, nlmsg_type=ethtool, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=2, nlmsg_pid=0}, "\x12\x01\x00\x00\x10\x00\x01\x80\x09\x00\x02\x00\x65\x74\x68\x30\x00\x00\x00\x00\x08\x00\x09\x00\x32\x00\x00\x00"], 44, 0, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 44
recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{nlmsg_len=36, nlmsg_type=NLMSG_ERROR, nlmsg_flags=NLM_F_CAPPED, nlmsg_seq=2, nlmsg_pid=8210}, {error=0, msg={nlmsg_len=44, nlmsg_type=ethtool, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=2, nlmsg_pid=0}}], iov_len=65536}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 36
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

sendto(3, [{nlmsg_len=44, nlmsg_type=ethtool, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=2, nlmsg_pid=0},

ethtool/src/handle.rs

Lines 78 to 85 in 96a97a7

// multiple netlink message in single socket reply.
// Using NLM_F_ACK will force rust-netlink to parse all till
// acked at the end.
NLM_F_DUMP | NLM_F_REQUEST | NLM_F_ACK
} else {
NLM_F_REQUEST
};

no NLM_F_ACK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants