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 IP_RECVIF & IP_RECVDSTADDR. #1002

Merged
merged 1 commit into from
Jan 30, 2019
Merged

Add IP_RECVIF & IP_RECVDSTADDR. #1002

merged 1 commit into from
Jan 30, 2019

Conversation

pusateri
Copy link
Contributor

Add IP_RECVIF & IP_RECVDSTADDR on freebsd, ios, macos, netbsd, openbsd
Include IP_PKTINFO on netbsd
Include IP6_PKTINFO on netbsd, openbsd.

FreeBSD/OpenBSD do not support IP_PKTINFO for IPv4 but use IP_RECVIF for interface index and use IP_RECVDSTADDR for destination address.
NetBSD and macOS also support IP_RECVIF and IP_RECVDSTADDR in addition to IP_PKTINFO for IPv4.
(For IPv6, all use IPV6_PKTINFO)

@pusateri
Copy link
Contributor Author

pusateri commented Dec 30, 2018

Missing a constant in libc. Will be ready when libc pull request is merged rust-lang/libc#1189

@pusateri
Copy link
Contributor Author

pusateri commented Jan 2, 2019

Ok, libc change has been merged. Not sure how to re-run the CI tests but no code changes should be needed.

@Susurrus
Copy link
Contributor

Susurrus commented Jan 2, 2019

I restarted Travis manually. Should've only done the one target, but I didn't realize it was only 1 until too late.

@asomers
Copy link
Member

asomers commented Jan 4, 2019

I'm afraid you'll need to rebase, due to CI changes.

@pusateri
Copy link
Contributor Author

pusateri commented Jan 5, 2019

Just tried this myself and I can't get the doc test to fail on FreeBSD 11.2 amd64. I notice there's a cfg option to turn this doc test off for i386. What's that all about?

% freebsd-version
11.2-RELEASE-p5

% rustup show
Default host: x86_64-unknown-freebsd

installed toolchains
--------------------

stable-x86_64-unknown-freebsd
1.24.1-x86_64-unknown-freebsd (default)

active toolchain
----------------

1.24.1-x86_64-unknown-freebsd (default)
rustc 1.24.1 (d3ae9a9e0 2018-02-27)

% cargo test --doc
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
   Doc-tests nix

running 75 tests
test src/pty.rs - pty::posix_openpt (line 92) ... ok
test src/lib.rs - Error::as_errno (line 117) ... ok
test src/ifaddrs.rs - ifaddrs::getifaddrs (line 112) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::cancel (line 728) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::error (line 783) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_boxed_slice (line 365) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_boxed_mut_slice (line 482) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_boxed_slice (line 397) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_boxed_slice (line 423) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_fd (line 228) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_mut_slice (line 289) ... ok
test src/sys/aio.rs - sys::aio::LioCb<'a>::listio_resubmit (line 1156) ... ok
test src/sys/aio.rs - sys::aio::AioCb<'a>::from_slice (line 644) ... ok
test src/sys/aio.rs - sys::aio::aio_suspend (line 981) ... ok
test src/sys/ioctl/mod.rs - ioctl_none (line 269) ... ignored
test src/sys/ioctl/mod.rs - ioctl_none (line 287) ... ok
test src/sys/ioctl/mod.rs - ioctl_none_bad (line 310) ... ignored
test src/sys/ioctl/mod.rs - ioctl_none_bad (line 319) ... ok
test src/sys/ioctl/mod.rs - ioctl_read (line 353) ... ignored
test src/sys/ioctl/bsd.rs - request_code_none (line 41) ... ok
test src/sys/ioctl/mod.rs - ioctl_read_bad (line 390) ... ignored
test src/sys/aio.rs - sys::aio::LioCb<'a>::listio (line 1099) ... ok
test src/sys/ioctl/mod.rs - ioctl_read_buf (line 694) ... ignored
test src/sys/ioctl/mod.rs - ioctl_readwrite (line 629) ... ignored
test src/sys/ioctl/mod.rs - ioctl_read (line 362) ... ok
test src/sys/ioctl/mod.rs - ioctl_readwrite_bad (line 665) ... ignored
test src/sys/ioctl/mod.rs - ioctl_readwrite_buf (line 762) ... ignored
test src/sys/ioctl/mod.rs - ioctl_write_buf (line 723) ... ignored
test src/sys/aio.rs - sys::aio::aio_cancel_all (line 927) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_int (line 503) ... ignored
test src/sys/ioctl/mod.rs - ioctl_read_bad (line 399) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_int_bad (line 584) ... ignored
test src/sys/ioctl/mod.rs - ioctl_readwrite (line 638) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_int_bad (line 593) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_ptr (line 428) ... ignored
test src/sys/ioctl/mod.rs - ioctl_write_int (line 516) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_ptr_bad (line 464) ... ignored
test src/sys/ioctl/mod.rs - ioctl_write_buf (line 732) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_int_bad (line 602) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_ptr (line 437) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 125) ... ok
test src/sys/ioctl/mod.rs - ioctl_write_ptr_bad (line 473) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 167) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 179) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 217) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 56) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 67) ... ok
test src/sys/ioctl/mod.rs - sys::ioctl (line 92) ... ok
test src/sys/ptrace/bsd.rs - sys::ptrace::bsd::step (line 123) ... ok
test src/sys/select.rs - sys::select::FdSet::highest (line 49) ... ok
test src/sys/socket/mod.rs - sys::socket::CmsgSpace (line 356) ... ok
test src/sys/socket/mod.rs - sys::socket::setsockopt (line 1214) ... ok
test src/sys/termios.rs - sys::termios (line 108) ... ok
test src/sys/termios.rs - sys::termios (line 122) ... ok
test src/sys/termios.rs - sys::termios (line 25) ... ok
test src/sys/termios.rs - sys::termios (line 137) ... ok
test src/sys/socket/mod.rs - sys::socket::ControlMessage::ScmTimestamp (line 473) ... ok
test src/sys/termios.rs - sys::termios (line 94) ... ignored
test src/sys/termios.rs - sys::termios (line 40) ... ok
test src/sys/termios.rs - sys::termios::Termios::get_libc_termios (line 200) ... ok
test src/sys/termios.rs - sys::termios (line 65) ... ok
test src/sys/termios.rs - sys::termios (line 79) ... ok
test src/sys/wait.rs - sys::wait::WaitStatus::from_raw (line 173) ... ok
test src/unistd.rs - unistd::close (line 902) ... ok
test src/unistd.rs - unistd::fork (line 192) ... ok
test src/unistd.rs - unistd::alarm (line 1499) ... ok
test src/unistd.rs - unistd::gethostname (line 873) ... ok
test src/unistd.rs - unistd::initgroups (line 1443) ... ok
test src/unistd.rs - unistd::close (line 916) ... ok
test src/unistd.rs - unistd::getcwd (line 544) ... ok
test src/unistd.rs - unistd::mkstemp (line 1611) ... ok
test src/unistd.rs - unistd::mkdir (line 438) ... ok
test src/unistd.rs - unistd::setgroups (line 1310) ... ok
test src/unistd.rs - unistd::mkfifo (line 481) ... ok
test src/unistd.rs - unistd::alarm (line 1513) ... ok

test result: ok. 61 passed; 0 failed; 14 ignored; 0 measured; 0 filtered out

@pusateri
Copy link
Contributor Author

pusateri commented Jan 6, 2019

There may be a problem with the test environment.

@asomers
Copy link
Member

asomers commented Jan 6, 2019

The test is not really valid. It's basically asserting that the sleep plus the 2nd sendmsg call take no more than 255ms, when it reality they took 275ms. But there's nothing that guarantees that. In a non-real time operating system, you could be delayed at any time. The test is also wildly overcomplicated. I'll fix it.

.intersects(MsgFlags::MSG_TRUNC | MsgFlags::MSG_CTRUNC)
);

for cmsg in msg.cmsgs() {
Copy link
Member

Choose a reason for hiding this comment

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

There's nothing to ensure that cmsgs were actually received. Shouldn't you have some kind of assertion to that effect?

Copy link
Member

Choose a reason for hiding this comment

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

Your latest updated didn't address this issue. Do you plan to?

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 just want something like this:

assert_eq!(msg.cmsgs().count(), 2, "expected 2 cmsgs");

or did you have something different in mind?

Copy link
Member

Choose a reason for hiding this comment

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

That statement wouldn't check that you got the right types of cmsgs. I think you need to check that the cmsgs were of the right types, too.

Copy link
Contributor Author

@pusateri pusateri Jan 20, 2019

Choose a reason for hiding this comment

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

the match condition '_' in the for loop would assert if it was any other type. So this would ensure there were two messages and the types were either Ipv4RecvIf or Ipv4RecvDstAddr. Since the kernel can't send two of the same type, I think this is sufficient, no?

Copy link
Member

Choose a reason for hiding this comment

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

I think the test should verify that we got one of each. Otherwise it wouldn't catch a regression that decodes the types incorrectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, just added some code that I think covers this. So now, I check to make sure they're are only two and I check to make sure each type is received and it fails if something other than the expected two message types are received.

).expect("send socket failed");
sendmsg(send, &iov, &[], MsgFlags::empty(), Some(&sa)).expect("sendmsg failed");

thread.join().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need a separate thread. sendmsg(2) should return before recvmsg(2) gets called.

use std::io::Write;
use std::thread;

fn loopback_v4addr() -> Option<InterfaceAddress> {
Copy link
Member

Choose a reason for hiding this comment

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

I'm getting deja vu here. Didn't a recent PR of yours contain something similar or identical to this function? If so, could you make it common code?

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.

Ok, I think this is looking good now! It just needs a CHANGELOG entry and a squash.

Include IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
@pusateri
Copy link
Contributor Author

Anything else I need to do here?

@asomers
Copy link
Member

asomers commented Jan 25, 2019

I've restarted the Cirrus test. We'll see if it actually runs this time.

@pusateri
Copy link
Contributor Author

Still is still ready to merge and the CI is still failing for no good reason. I don't think the FreeBSD CI change is working well.

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.

Ok, the third time was the charm. I've opened an issue upstream with Cirrus; we'll see what they say.

bors r+

bors bot added a commit that referenced this pull request Jan 30, 2019
1002: Add IP_RECVIF & IP_RECVDSTADDR. r=asomers a=pusateri

Add IP_RECVIF & IP_RECVDSTADDR on freebsd, ios, macos, netbsd, openbsd
Include IP_PKTINFO on netbsd
Include IP6_PKTINFO on netbsd, openbsd.

FreeBSD/OpenBSD do not support IP_PKTINFO for IPv4 but use IP_RECVIF for interface index and use IP_RECVDSTADDR for destination address.
NetBSD and macOS also support IP_RECVIF and IP_RECVDSTADDR in addition to IP_PKTINFO for IPv4.
(For IPv6, all use IPV6_PKTINFO)

Co-authored-by: Tom Pusateri <pusateri@bangj.com>
@bors
Copy link
Contributor

bors bot commented Jan 30, 2019

Build failed

  • FreeBSD 11.2

@asomers
Copy link
Member

asomers commented Jan 30, 2019

bors retry

bors bot added a commit that referenced this pull request Jan 30, 2019
1002: Add IP_RECVIF & IP_RECVDSTADDR. r=asomers a=pusateri

Add IP_RECVIF & IP_RECVDSTADDR on freebsd, ios, macos, netbsd, openbsd
Include IP_PKTINFO on netbsd
Include IP6_PKTINFO on netbsd, openbsd.

FreeBSD/OpenBSD do not support IP_PKTINFO for IPv4 but use IP_RECVIF for interface index and use IP_RECVDSTADDR for destination address.
NetBSD and macOS also support IP_RECVIF and IP_RECVDSTADDR in addition to IP_PKTINFO for IPv4.
(For IPv6, all use IPV6_PKTINFO)

Co-authored-by: Tom Pusateri <pusateri@bangj.com>
@bors
Copy link
Contributor

bors bot commented Jan 30, 2019

Build succeeded

@bors bors bot merged commit 147f791 into nix-rust:master Jan 30, 2019
@asomers
Copy link
Member

asomers commented Jan 31, 2019

FWIW The Cirrus people say they've fixed the bug now.

@pusateri
Copy link
Contributor Author

Great. Thanks! False negatives waste a lot of time.

@pusateri pusateri deleted the recvif branch January 31, 2019 04:28
asomers added a commit to asomers/nix that referenced this pull request Jan 31, 2019
asomers added a commit to asomers/nix that referenced this pull request Jan 31, 2019
asomers added a commit to asomers/nix that referenced this pull request Feb 12, 2019
asomers added a commit to asomers/nix that referenced this pull request Feb 12, 2019
asomers added a commit to asomers/nix that referenced this pull request Feb 14, 2019
vdagonneau pushed a commit to vdagonneau/nix that referenced this pull request Feb 20, 2019
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.

None yet

3 participants