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 cmsg PKTINFO for IPv4 and IPv6. #990

Merged
merged 1 commit into from
Dec 17, 2018
Merged

Add cmsg PKTINFO for IPv4 and IPv6. #990

merged 1 commit into from
Dec 17, 2018

Conversation

pusateri
Copy link
Contributor

@pusateri pusateri commented Dec 4, 2018

Replaces #891 and attempts to address all previous concerns.

@pusateri
Copy link
Contributor Author

pusateri commented Dec 4, 2018

FreeBSD has IP_RECVIF and IP_RECVDSTADDR/IP_SENDSRCADDR to accomplish the same thing as IP_PKTINFO. I haven't added that yet. I will once this is committed.

@pusateri
Copy link
Contributor Author

pusateri commented Dec 4, 2018

OpenBSD has IPV6_PKTINFO but cargo test fails before these changes so I did not yet include OpenBSD cfg support.

@pusateri
Copy link
Contributor Author

pusateri commented Dec 4, 2018

Not sure if test_recv_ipv6pktinfo() should pass if there is no IPv6 address on the loopback interface. ::1 is missing on the amd64_fbsd11 buildbot automated test. The other alternative is to mark the test as ignore and let is only be run intentionally.

CHANGELOG.md Outdated
@@ -95,6 +95,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#857](https://github.com/nix-rust/nix/pull/857))
- Added `request_code_write_int!` on FreeBSD/DragonFlyBSD
([#833](https://github.com/nix-rust/nix/pull/833))
- Added PKTINFO cmsg support on Android/iOS/Linux/MacOS.
- Added V6PKTINFO cmsg support on Android/FreeBSD/iOS/Linux/MacOS.
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to move the changelog entries into the "Unreleased" section, and also add a link to the PR.

ControlMessage::Ipv4PacketInfo(pktinfo) => {
mem::size_of_val(pktinfo)
},
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "ios", target_os = "linux", target_os = "macos"))]
Copy link
Member

Choose a reason for hiding this comment

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

Can you please wrap to 80 columns?

@pusateri
Copy link
Contributor Author

pusateri commented Dec 4, 2018

mips-unknown-linux-gnu looks like an endian problem. Not sure how deep. Index probably should have been 1 and it was 1000000 (hex).

@pusateri
Copy link
Contributor Author

pusateri commented Dec 4, 2018

I tested on stable-armv7-unknown-linux-gnueabihf, Debian GNU/Linux 8.11 (jessie) with stable 1.30.0 and it passed. Not sure what's different with the test apparatus other than it using 1.24.1.

@asomers
Copy link
Member

asomers commented Dec 5, 2018

I tested on stable-armv7-unknown-linux-gnueabihf, Debian GNU/Linux 8.11 (jessie) with stable 1.30.0 and it passed. Not sure what's different with the test apparatus other than it using 1.24.1.

Were you actually running Debian on an arm? The test apparatus uses qemu to emulate the embedded architectures, and qemu's got some bugs.

@pusateri
Copy link
Contributor Author

pusateri commented Dec 5, 2018

I tested on stable-armv7-unknown-linux-gnueabihf, Debian GNU/Linux 8.11 (jessie) with stable 1.30.0 and it passed. Not sure what's different with the test apparatus other than it using 1.24.1.

Were you actually running Debian on an arm? The test apparatus uses qemu to emulate the embedded architectures, and qemu's got some bugs.

Yes. I compiled and tested on real armv7 hardware. It is a solid-run.com Hummingboard.

Linux hum 3.14.79-fslc-imx6-sr #1 SMP Fri Oct 20 18:16:19 UTC 2017 armv7l GNU/Linux

@asomers
Copy link
Member

asomers commented Dec 5, 2018

Looks like you're getting EPFNOSUPPORT on many of the QEMU platforms. You can either disable the test for those platforms, or else accept EPFNOSUPPORT (and print a warning) in the test.

@pusateri
Copy link
Contributor Author

pusateri commented Dec 5, 2018

Looks like you're getting EPFNOSUPPORT on many of the QEMU platforms. You can either disable the test for those platforms, or else accept EPFNOSUPPORT (and print a warning) in the test.

Yeah, I probably shouldn't be using unwrap() as much. It's probably when scanning the interfaces for addresses that it's failing. It's too bad that I can't get more info from it. I will try setting up QEMU and seeing if I can narrow it down instead of randomly removing unwrap() until I find it. :)

@pusateri
Copy link
Contributor Author

pusateri commented Dec 6, 2018

Cool. All that's left to fix is the big endian problem.

@pusateri
Copy link
Contributor Author

After some trouble, I got Ubuntu 16.04 LTS installed on a PowerMac Dual G5 and ran the pktinfo tests natively and both IPv4 and IPv6 tests passed. Maybe the endian bug is in the qemu emulator? I think the code is ok and don't have any more changes to make.

@pusateri
Copy link
Contributor Author

This leaves us in a bad situation for testing though. I tested with version 1.31.0. I will test with 1.24.1 and verify since that's what the emulator is running.

@asomers
Copy link
Member

asomers commented Dec 11, 2018

There definitely are bugs in QEMU. That's why many tests are disabled for the QEMU platforms. It's not necessary for this PR that you fix QEMU; just make sure the tests pass on real platforms and all checkmarks are green.

@pusateri
Copy link
Contributor Author

The powerpc tests passed on 1.24.1 as well. Currently, other tests are disabled for qemu bugs:

// qemu's handling of multiple cmsgs is bugged, ignore tests on non-x86
// see https://bugs.launchpad.net/qemu/+bug/1781280
#[cfg_attr(not(any(target_arch = "x86_64", target_arch = "x86")), ignore)]

Should I turn my tests off for powerpc and mips?

@asomers
Copy link
Member

asomers commented Dec 11, 2018

That's what I would do.

@asomers
Copy link
Member

asomers commented Dec 12, 2018

I'm afraid that you'll need to rebase. You somehow merged several other PRs into this one.

CHANGELOG.md Outdated
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Added PKTINFO cmsg support on Android/iOS/Linux/MacOS.
- Added V6PKTINFO cmsg support on Android/FreeBSD/iOS/Linux/MacOS.
- ([#990](https://github.com/nix-rust/nix/pull/990))
Copy link
Member

Choose a reason for hiding this comment

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

The PR doesn't get its own bullet. These three lines should either all share a bullet, or the "Added" lines should each get their own and each have the PR link.

.expect("Mutex got poisoned by another test");

let lo_ifaddr = loopback_v4addr();
let (lo_name, lo) = match lo_ifaddr {
Copy link
Member

Choose a reason for hiding this comment

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

Could you simplify the test by hardcoding this to ("lo0", "127.0.0.1")?

test/test.rs Outdated
@@ -77,4 +77,6 @@ lazy_static! {
pub static ref PTSNAME_MTX: Mutex<()> = Mutex::new(());
/// Any test that alters signal handling must grab this mutex.
pub static ref SIGNAL_MTX: Mutex<()> = Mutex::new(());
/// Any test sending packets over the loopback interface
pub static ref LOOP_MTX: Mutex<()> = Mutex::new(());
Copy link
Member

Choose a reason for hiding this comment

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

Is this really necessary? Why not just bind each test to a different port?

);
});

let slice = [1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8];
Copy link
Member

Choose a reason for hiding this comment

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

Pro tip: You can leave out the "u8" on the second and subsequent elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want me to fix the versions above in the other existing tests or just this new one?

@pusateri
Copy link
Contributor Author

From the nix gitter from me:
Is it ok to send packets through the loopback interface with sendmsg()/recvmsg() in a test (test/sys/test_socket.rs)?

@asomers replied:
@pusateri it's ok as long as you can guarantee that they won't interfere with anything else
Use the appropriate mutex from test/test.rs or create a new one to protect access to the loopback interface.
And don't assume that its address will be 127.0.0.1.

So that's what I did. Also Linux uses "lo" and BSDs and macOS use "lo0". Rather than hard coding it, it's safer to look for the LOOPBACK flag.

So now which way do you prefer?

@asomers
Copy link
Member

asomers commented Dec 13, 2018

From the nix gitter from me:
Is it ok to send packets through the loopback interface with sendmsg()/recvmsg() in a test (test/sys/test_socket.rs)?

@asomers replied:
@pusateri it's ok as long as you can guarantee that they won't interfere with anything else
Use the appropriate mutex from test/test.rs or create a new one to protect access to the loopback interface.
And don't assume that its address will be 127.0.0.1.

So that's what I did. Also Linux uses "lo" and BSDs and macOS use "lo0". Rather than hard coding it, it's safer to look for the LOOPBACK flag.

So now which way do you prefer?

Well, that answers the question about hardcoding the interface name and address. I guess it's not an issue for most tests, because most tests only need the address, not the name. As for the mutex, I think it's better to use separate port numbers. Using distinct ports is a way to guarantee that the tests won't interfere with each other.

@pusateri
Copy link
Contributor Author

It already has the kernel assign a random unused port number so all I should need to do is remove the mutex, fix the CHANGELOG, and remove the unnecessary u8's?

@asomers
Copy link
Member

asomers commented Dec 13, 2018

Sounds good.

@@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
- Added PKTINFO cmsg support on Android/iOS/Linux/MacOS.
- Added V6PKTINFO cmsg support on Android/FreeBSD/iOS/Linux/MacOS.
- ([#990](https://github.com/nix-rust/nix/pull/990))
([#990](https://github.com/nix-rust/nix/pull/990))
Copy link
Member

Choose a reason for hiding this comment

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

This still isn't correct because the link is only associated with the V6PKTINFO bullet. You need to either duplicate the link for both bullets, or collapse everything into a single bullet.

@asomers
Copy link
Member

asomers commented Dec 15, 2018

Ok, everything is good! Please squash and then I'll merge.

ignore pktinfo tests on qemu mips,mips64,powerpc64
Original work by @mcginty.
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

bors r+

bors bot added a commit that referenced this pull request Dec 17, 2018
990: Add cmsg PKTINFO for IPv4 and IPv6. r=asomers a=pusateri

Replaces #891 and attempts to address all previous concerns.

Co-authored-by: Tom Pusateri <[email protected]>
@bors
Copy link
Contributor

bors bot commented Dec 17, 2018

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