summaryrefslogtreecommitdiff
path: root/src/sys/socket
AgeCommit message (Collapse)Author
2020-10-03Renable the ScmTimestamp test on FreeBSD i386Alan Somers
The relevant bug was fixed in 11.3-RELEASE https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222039
2020-08-18Add Netlink Protocol Families to SockProtocol enumsinkingpoint
Currently the SockProtocol enum is rather scarce. This commit adds the Netlink protocols defined in netlink(7) to the SockProtocol enum allowing us to use the Nix socket library for more indepth Netlink work
2020-07-04Expose IP_PKTINFO Control Message on AndroidBruno Tavares
The commit https://github.com/nix-rust/nix/pull/1222 added the very useful Ipv4PktInfo to allow `sendmsg` to define the origin of the ip. Unfortunattely, it didn't add the struct to Android target devices as well. This commit adds the `target_os = "android"` checks on the same place to allow the compilation to work for the following archs tested: - `cross build --target aarch64-linux-android` - `cross build --target x86_64-linux-android` - `cross build --target armv7-linux-androideabi` Also introduces iOS to allow using on libs for those platforms
2020-06-27Make SockAddr::as_ffi_pair safeAlan Somers
It was only marked unsafe because it did a pointer cast, but that particular pointer cast is always allowed by C.
2020-06-27implement Default for UnixCredentials on LinuxAlan Somers
2020-06-27Make sys::socket::sockaddr_storage a safe functionAlan Somers
It already fully validated its arguments, so there's no need for it to be `unsafe`.
2020-06-26Add Ipv{4,6}PacketInfo support to ControlMessage for send{m,}msgPerry Lorier
This adds Ipv4PacketInfo and Ipv6PacketInfo to ControlMessage, allowing these to be used with sendmsg/sendmmsg. This change contains the following squashed commits: Add Ipv{4,6}PacketInfo to ControlMessage. Add documentation links to Ipv{4,6}PacketInfo Add changelog entry for Ipv{4,6}PacketInfo Add link to PR in the Changelog. Add extra build environments. Add tests for Ipv{4,6}PacketInfo. Swap #[test] and #[cfg] The CI appears to be running the test, even though it's not cfg'd for that platform. I _think_ this might be due to these being in the wrong order. So lets try swapping them. s/freebsd/netbsd/ for Ipv4PacketInfo netbsd supports in_pktinfo, not freebsd. Fix the cfg for Ipv{4,6}PacketInfo usage. Ah, I see what I did wrong. I had fixed the definitions, but I had the wrong cfg() in the usage. This has the usage match the definitions. Change SOL_IPV6 to IPPROTO_IPV6. FreeBSD doesn't have SOL_IPV6, but does have IPPROTO_IPV6, and the two constants are defined as being equal. So change to use IPPROTO_IPV6. Skip Ipv6PacketInfo test if v6 is not available. If IPv6 is not available, then when we try and bind to ip6-localhost, we'll get a EADDRNOTAVAIL, so skip the test. This should mean that the test will run on any machine that has a v6 loopback address. More architecture cfg() fixes. These all need to be the same, and they were not. Make them them all the same. Attempt III. Fix up mismatched cfg's again. Take IV. Make sure the cfg's that use a enum variant match the enum definition.
2020-05-31Convert the crate to edition 2018Alan Somers
2020-05-26Fix build on OpenBSD caused by erroneous inclusion in allowed OS list for ↵Nick Pelone
sendmmsg() / recvmmsg() in #1208. In #1208, sendmmsg() / recvmmsg() were added, but OpenBSD(who doesn't support these) was included on the list of allowed operating systems for sendmmsg() related things. This broke the build on OpenBSD. For more Rust-world examples, see: https://github.com/rust-lang/libc/commit/6f6297301d49ff67b8ca044d651f36a56950298c
2020-05-16Apply `repr(transparent)` to several FFI typesAlan Somers
repr(transparent) is required in order to safely cast between an FFI type and its NewType. This commit applies that attribute to PollFd, EpollEvent, IpMembershipRequest, Ipv6MembershipRequest, TimeVal, and IoVec. Fixes #1241
2020-05-08Add SO_BINDTODEVICE sockoptJean Pierre Dudey
This is available only on Linux as far I know, [socket(7)](https://linux.die.net/man/7/socket) has some information about the `SO_BINDTODEVICE` sockopt. In simple words it binds a socket to an specific network device (specified as an string like "wlo1", "eth0", etc.), to only process packets from that device. Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2020-05-02Add UnixCredentials support on FreeBSD/DragonFly (cmsgcred/SCM_CREDS)Greg V
2020-05-01Merge #1215bors[bot]
1215: Remove sys::socket::addr::from_libc_sockaddr from the public API r=posborne a=asomers This function never should've been public, since it's basically impossible to use directly. It's only public due to an oversight from PR #667 . Co-authored-by: Alan Somers <asomers@gmail.com>
2020-04-26Eliminate a mem::zeroed() in recvmmsgAlan Somers
2020-04-26Support sendmmsg/recvmmsgGleb Pomykalov
2020-04-25Support UDP GSO and GRO on linuxGleb Pomykalov
2020-04-19Merge #1206bors[bot]
1206: Fix unaligned casting of cmsg data to af_alg_iv r=asomers a=glebpom Casting a pointer to `cmsg_data` to `af_alg_iv` is incorrect since it's not properly aligned. As of the [`cmsg` man page](http://man7.org/linux/man-pages/man3/cmsg.3.html) "Applications should not cast it to a pointer type matching the payload, but should instead use memcpy(3) to copy data to or from a suitably declared object." Co-authored-by: Gleb Pomykalov <gleb@lancastr.com>
2020-04-12Remove sys::socket::addr::from_libc_sockaddr from the public APIAlan Somers
This function never should've been public, since it's basically impossible to use directly. It's only public due to an oversight from PR #667 .
2020-04-12Fix UB in getsockoptAlan Somers
The old code tried to zero-initialize an enum for which 0 is not a valid value. That worked for older compilers, but triggers a panic with Rust 1.44.0. The correct technique is to use mem::MaybeUninit. Fixes #1212
2020-04-08Fix unaligned castting of cmsg data to af_alg_ivGleb Pomykalov
2019-12-01ScmCredentials now wraps UnixCredentials instead of libc::ucredAlan Somers
2019-11-30Remove the deprecated CmsgSpaceAlan Somers
This eliminates one of the last remaining uninitialized memory accesses in Nix. Fixes #1142
2019-10-28Fix sys::socket::recvfrom for TCP socketsAlan Somers
recvfrom(2) only returns the sender's address for protocols that provide it. Usually, that means it returns the sender's address for datagram sockets but not for stream sockets. Fixes #1144
2019-10-15Properly initialize msghdr when using muslYuxuan Shui
Because of the use of MaybeUninit::uninit, the padding fields in msghdr, which only present on musl builds, are not initialized. Causing garbage data to be sent to the kernel. This change ensures the paddings are always zeroed.
2019-09-19Where relevant, replace equality checks in assert! with assert_eq!Xavier L'Heureux
`assert_eq!` gives more debug info when the test fails by default than `assert!`. This should help make debugging easier.
2019-09-04Merge #1120bors[bot]
1120: Fix length of abstract socket address r=asomers a=yshui NULL bytes have no special significance in an abstrace address, and the length of the address is solely decided by the length member. If the length is set to sun_path.len(), all the NULL bytes will be considered part of the address. Tests are updated accordingly. Closes #1119 Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com> Co-authored-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-09-04Fix length of abstract socket addressYuxuan Shui
NULL bytes have no special significance in an abstrace address, and the length of the address is solely decided by the length member. If the length is set to sun_path.len(), all the NULL bytes will be considered part of the address. Tests are updated accordingly. Closes #1119 Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-09-03Replace most instances of mem::uninitialized with mem::MaybeUninitAlan Somers
Only two instances remain: * For the deprecated sys::socket::CmsgSpace::new. We should probably just remove that method. * For sys::termios::Termios::default_uninit. This will require some more thought. Fixes #1096
2019-08-29Implement Default for FdSetAlan Somers
2019-08-29Remove an obsolete commentAlan Somers
It was leftover from internal churn during PR #1020.
2019-08-29Clippy: silence a false-positive cast alignment warningAlan Somers
2019-08-29Clippy: remove unnecessary mem::transmuteAlan Somers
2019-08-29Clippy cleanupAlan Somers
2019-07-13Merge #1095bors[bot]
1095: Fix warnings on Rust 1.37.0 r=asomers a=asomers * Replace obsolete range syntax "..." with inclusive range "..=" * Use dyn Trait syntax instead of Box<Trait> * Raise MSRV to 1.27.0 (for dyn Trait syntax) * Test with nightly again Co-authored-by: Alan Somers <asomers@gmail.com>
2019-07-13Fix warnings on Rust 1.37.0Alan Somers
* Replace obsolete range syntax "..." with inclusive range "..=" * Use dyn Trait syntax instead of Box<Trait> * Raise MSRV to 1.27.0 (for dyn Trait syntax) * Raise MSRV to 1.31.0 (because of rand) tempfile pulls in rand, and rand pulls in fuchsia-cprng, which requires 1.31.0. Why rand pulls in fuchsia-cprng I don't know. It's specified as a target-specific dependency, but Cargo tries to build it anyway (only on Linux, not on FreeBSD or OSX). A bug in Cargo 1.27.0?
2019-07-12socket: add support for AF_VSOCKStefano Garzarella
This patch adds AF_VSOCK support to AddressFamily in order to use VSOCK socket. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2019-06-11Fix tests for abstract socketsBryant Mairs
Abstract paths should always be N-1 in length where N is the length of the `sun_path` field (first byte is \0). Given that, `UnixAddr::new_abstract()` should always return this N-1 length, not just the length of the string provided (the rest of the array will be \0s).
2019-06-09Add extra traits for all typesBryant Mairs
Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all traits are supported by all types, which is why many are missing some.
2019-06-07socket: expose MSG_WAITALL in MsgFlagsStefano Garzarella
MSG_WAITALL can be useful with recv() to wait the full amount of data requested. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2019-06-06Fix the is_so_mark_functional test in Linux containersAlan Somers
It's not sufficient to check for root privileges. In a container, the euid may be root even though the user lacks some capabilities. Replace this test's root check with a check for the CAP_NET_ADMIN capability instead.
2019-06-03Check euid, not uid, for socket testsAlan Somers
2019-05-31fix more uintXY_t instancesJohannes Schilling
2019-05-31libc::uint8_t deprecated in favor of rust u8Johannes Schilling
2019-04-29Restored the bytes field on RecvMsg in order to know the amount of bytes ↵Vincent Dagonneau
received using recvmsg.
2019-04-09Uncomment to_std and from_std methods for IpAddrrabbott99
2019-03-12Support AF_ALGGleb Pomykalov
2019-02-14Enable IPv4PacketInfo and Ipv6PacketInfo on more OSes.Alan Somers
This was an oversight from PR #1002
2019-02-14Fix misaligned references when using recvmsg with control messagesAlan Somers
On some platforms the alignment of cmsg_data could be less than the alignment of the messages that it contains. That led to unaligned reads on those platforms. This change fixes the issue by always copying the message contents into aligned objects. The change is not 100% backwards compatible when using recvmsg. Users may have to replace code like this: ```rust if let ControlMessage::ScmRights(&fds) = cmsg { ``` with this: ```rust if let ControlMessageOwned::ScmRights(fds) = cmsg { ``` Fixes #999
2019-02-14Replace CmsgSpace with a macroAlan Somers
CmsgSpace had three problems: 1) It would oversize buffers that expect multiple control messages 2) It didn't use the libc CMSG_SPACE(3) macro, so it might actually undersize a buffer for a single control message. 3) It could do bad things on drop, if you instantiate it with a type that implements Drop (which none of the currently supported ControlMessage types do). Fixes #994
2019-02-14Fix error handling of RecvMsgAlan Somers
There were two problems: 1) It would always return Ok, even on error 2) It could panic if there was an error, because sockaddr_storage_to_addr would be called on uninitialized memory.