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

feat: add initial implementation for parsing /proc/net/netstat #304

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

etolbakov
Copy link

Description

added parsing for /proc/net/netstat

How was this PR tested?

added a unit test

Related issues

#295

@etolbakov
Copy link
Author

@eminence
Could you please take a look at the change when you have time? Looking forward getting feedback.

  1. I've noticed the comment in net.rs so maybe the code should be moved there. I decided to come up with a dedicated file to make a review process simpler.
  2. some of the comments still have TODO, I haven't found any meaningful description for them.

/// Represents the data from `/proc/net/netstat`.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct Netstat {
Copy link
Owner

Choose a reason for hiding this comment

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

Do you think we should mark this struct as #[non_exhaustive], in case new fields get added in newer kernels?

Copy link
Author

Choose a reason for hiding this comment

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

yeah, good idea! I'll add #[non_exhaustive]

tcp_ext_tcp_ds_ack_ignored_dubious: from_str!(u64, expect!(tcp_ext.next())),
tcp_ext_tcp_migrate_req_success: from_str!(u64, expect!(tcp_ext.next())),
tcp_ext_tcp_migrate_req_failure: from_str!(u64, expect!(tcp_ext.next())),
tcp_ext_tcp_ecn_rehash: from_str!(u64, expect!(tcp_ext.next())),
Copy link
Owner

Choose a reason for hiding this comment

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

My 6.1.0 kernel doesn't have this field:

---- net::tests::test_netstats stdout ----
thread 'net::tests::test_netstats' panicked at procfs/src/net.rs:264:35:
called `Result::unwrap()` on an `Err` value: InternalError(bug at procfs-core/src/netstat.rs:534 (please report this procfs bug)
Internal Unwrap Error: NoneError)

We're going to want to find some older kernels to test this on. I'll try to capture some examples of /proc/net/netstat on some random old machines

Copy link
Author

Choose a reason for hiding this comment

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

Thank you! I'll provide the info about the kernel version I took it from

Copy link
Author

Choose a reason for hiding this comment

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

@eminence
I've confirmed that these parameters

TcpExt:....
TcpDuplicateDataRehash TCPDSACKRecvSegs TCPDSACKIgnoredDubious TCPMigrateReqSuccess TCPMigrateReqFailure TCPECNRehash

come from

sh-4.2$ uname -r
5.10.205-195.807.amzn2.x86_64

Not sure if that's too representative/widely used

@etolbakov
Copy link
Author

Hi Andrew @eminence
Thanks for taking a look at the PR! I'll address the suggestions shortly

@etolbakov
Copy link
Author

Hello Andrew @eminence !
Could you please let me know if anything else needed in the scope of this PR?

@eminence
Copy link
Owner

eminence commented Mar 5, 2024

We still have to fix the issue about fields that are only in newer kernels. These should become Option fields in Netstat struct

@etolbakov
Copy link
Author

Thanks understood, will adjust!
I wonder if you had time to get outputs from older kernels for tests?

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

Successfully merging this pull request may close these issues.

2 participants