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

aya-log: Allow logging core::net::Ipv4Addr and core::net::Ipv6Addr #966

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

vadorovsky
Copy link
Member

@vadorovsky vadorovsky commented Jun 8, 2024

IP address types are available in core, so they can be used also in eBPF programs. This change adds support of these types in aya-log.

  • Add implementation of WriteTuBuf to these types.
  • Support these types in Ipv4Formatter and Ipv6Formatter.
  • Support them with DisplayHint::Ip.

This change is Reviewable

Copy link

netlify bot commented Jun 8, 2024

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 637f4f9
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/6697f9a4391a170008b6d12b
😎 Deploy Preview https://deploy-preview-966--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mergify mergify bot added the aya-log Relating to aya-log label Jun 8, 2024
@mergify mergify bot added the test A PR that improves test cases or CI label Jun 19, 2024
@vadorovsky vadorovsky force-pushed the log-ip-types branch 2 times, most recently from ce46c19 to 6f95b89 Compare July 15, 2024 21:10
Copy link

mergify bot commented Jul 15, 2024

Hey @alessandrod, this pull request changes the Aya Public API and requires your review.

@mergify mergify bot requested a review from alessandrod July 15, 2024 21:10
@mergify mergify bot added the api/needs-review Makes an API change that needs review label Jul 15, 2024
@vadorovsky vadorovsky requested a review from tamird July 15, 2024 22:35
Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @alessandrod and @vadorovsky)


aya-log/src/lib.rs line 322 at r1 (raw file):

            Some(DisplayHint::LowerMac) => Err(()),
            Some(DisplayHint::UpperMac) => Err(()),
            _ => Ok(Ipv4Formatter::format(*self)),

are these arms just None? can we s/_/None/ everywhere?


aya-log/src/lib.rs line 839 at r1 (raw file):

        len += "ipv4: ".write(&mut input[len..]).unwrap().get();
        len += DisplayHint::Ip.write(&mut input[len..]).unwrap().get();
        Ipv4Addr::new(10, 0, 0, 1)

len +=


aya-log/src/lib.rs line 862 at r1 (raw file):

        len += "ipv4: ".write(&mut input[len..]).unwrap().get();
        len += DisplayHint::Ip.write(&mut input[len..]).unwrap().get();
        IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1))

len +=


aya-log/src/lib.rs line 906 at r1 (raw file):

        len += "ipv6: ".write(&mut input[len..]).unwrap().get();
        len += DisplayHint::Ip.write(&mut input[len..]).unwrap().get();
        Ipv6Addr::new(

len+=


aya-log/src/lib.rs line 931 at r1 (raw file):

        len += "ipv6: ".write(&mut input[len..]).unwrap().get();
        len += DisplayHint::Ip.write(&mut input[len..]).unwrap().get();
        IpAddr::V6(Ipv6Addr::new(

len+=


test/integration-ebpf/src/log.rs line 22 at r1 (raw file):

    let ipv4 = Ipv4Addr::new(10, 0, 0, 1);
    let ipv6 = Ipv6Addr::new(8193, 3512, 0, 0, 0, 0, 0, 1);
    info!(&ctx, "ip structs: ipv4: {:i}, ipv6: {:i}", ipv4, ipv6); // 2001:db8::1

comment in wrong place?


test/integration-ebpf/src/log.rs line 23 at r1 (raw file):

    let ipv6 = Ipv6Addr::new(8193, 3512, 0, 0, 0, 0, 0, 1);
    info!(&ctx, "ip structs: ipv4: {:i}, ipv6: {:i}", ipv4, ipv6); // 2001:db8::1
    let ipv4 = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1));

use ipv4 from above?


test/integration-ebpf/src/log.rs line 24 at r1 (raw file):

    info!(&ctx, "ip structs: ipv4: {:i}, ipv6: {:i}", ipv4, ipv6); // 2001:db8::1
    let ipv4 = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1));
    let ipv6 = IpAddr::V6(Ipv6Addr::new(8193, 3512, 0, 0, 0, 0, 0, 1));

use ipv6 from above?


test/integration-ebpf/src/log.rs line 26 at r1 (raw file):

    let ipv6 = IpAddr::V6(Ipv6Addr::new(8193, 3512, 0, 0, 0, 0, 0, 1));
    info!(&ctx, "ip enums: ipv4: {:i}, ipv6: {:i}", ipv4, ipv6);
    let ipv4 = 167772161u32; // 10.0.0.1

we're on nightly here, we can use https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.to_bits to avoid the repetition

or use https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.octets


test/integration-ebpf/src/log.rs line 27 at r1 (raw file):

    info!(&ctx, "ip enums: ipv4: {:i}, ipv6: {:i}", ipv4, ipv6);
    let ipv4 = 167772161u32; // 10.0.0.1
    let ipv6 = [

https://doc.rust-lang.org/stable/std/net/struct.Ipv6Addr.html#method.octets

Copy link
Member Author

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 5 files reviewed, 10 unresolved discussions (waiting on @alessandrod and @tamird)


aya-log/src/lib.rs line 322 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

are these arms just None? can we s/_/None/ everywhere?

Done.


aya-log/src/lib.rs line 839 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

len +=

Done.


aya-log/src/lib.rs line 862 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

len +=

Done.


aya-log/src/lib.rs line 906 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

len+=

Done.


aya-log/src/lib.rs line 931 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

len+=

Done.


test/integration-ebpf/src/log.rs line 22 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

comment in wrong place?

Done.


test/integration-ebpf/src/log.rs line 23 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

use ipv4 from above?

Done.


test/integration-ebpf/src/log.rs line 24 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

use ipv6 from above?

Done.


test/integration-ebpf/src/log.rs line 26 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

we're on nightly here, we can use https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.to_bits to avoid the repetition

or use https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.octets

Done.


test/integration-ebpf/src/log.rs line 27 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

https://doc.rust-lang.org/stable/std/net/struct.Ipv6Addr.html#method.octets

Done.

IP address types are available in `core`, so they can be used also in
eBPF programs. This change adds support of these types in aya-log.

* Add implementation of `WriteTuBuf` to these types.
* Support these types in `Ipv4Formatter` and `Ipv6Formatter`.
* Support them with `DisplayHint::Ip`.
* Add support for formatting `[u8; 4]`, to be able to handle
  `Ipv4Addr::octets`.
Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Beautiful.

Reviewed 5 of 5 files at r3, 4 of 4 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @alessandrod)

@vadorovsky vadorovsky merged commit 6dab717 into aya-rs:main Jul 17, 2024
21 checks passed
@vadorovsky vadorovsky deleted the log-ip-types branch July 17, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/needs-review Makes an API change that needs review aya-log Relating to aya-log test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants