-
Notifications
You must be signed in to change notification settings - Fork 7.4k
net: socket: syscall for socketpair(2) #24813
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
net: socket: syscall for socketpair(2) #24813
Conversation
All checks are passing now. checkpatch (informational only, not a failure)
Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
Ugh... let me take care of those gitlint issues |
I omitted the Please suggest any additional testing or technical changes that you feel are necessary. |
Looks as though the shippable failures have nothing to do with this change - seems to be Bluetooth related. |
@pfalcon - blocking / non-blocking reads / writes working with test
cases. Would like some suggestions for `ZFD_IOCTL_POLL_PREPARE` and
`ZFD_IOCTL_POLL_UPDATE` (I don't think that
`ZFD_IOCTL_POLL_OFFLOAD` applies here, am I wrong?).
So my issue is, that I'd like to avoid using a net_context if
possible (because as you pointed out, why bring in ip at all?) but
simultaneously, I'd prefer not to duplicate code from sockets.c,
which is currently where much of the `poll` machinery lives.
However, `sock_set_flag()` depends on `net_context`.
Thoughts?
Sorry, was on public holidays, will look into that as time permits.
|
That definitely becomes a problem, I submitted on that #24966. Even if done now, it unlikely would get into the 2.3 release (needless risk), and then it makes no sense to rush with it now (I'm for one still preoccupied with other tasks). And then, this code would need to deal with the current situation (workaround it/whatever). |
I would suggest, and even urge, to remove any calls of select() from the code in this PR. select() is explicitly defined as being implemented on top of poll(), and being a legacy and inefficient API. The only test for it we need is that select() <-> poll() marshalling works correctly (and we have such a test). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I am very happy to see such extensive testing for this, thumbs up for that.
Some minor comments about coding style, I did not comment coding style in tests as there was so much stuff there, but I would appreciate if you can check those files too and fix relevant style issues there.
We first should decide whether unix domain sockets are "networking code" per se. I didn't look thru the code in detail yet, but @cfriedt, I'd urge you to consider whether this code should belong to subsys/net/lib/, or lib/posix/ instead.
IMHO, this is an example of "feudalism" in Zephyr's subsystems. If it's quite useful, then certainly it should have been contributed to the generic logging (and e.g. made configurable per-logger, like currently default logging level is). |
It's a tricky subject. Technically, they are sockets, but they don't depend on IP support. I'd be happy keeping them in net until #24966 is resolved, and would be happy to refactor as part of that change at some point. Edit: @pfalcon - it's not possible to just put it in lib/posix as-is, is it? I guess, technically, I could and then just use Kconfig to make it depend on Edit: @pfalcon - i tried the above, but for some reason it could not find zsock_impl_socketpair() to link with. Probably best to save that for another day, but I do agree it should eventually go in lib/posix. |
Sounds good. |
I will do. So much work to get it passing checkpatch already though. checkpatch doesn't fix all of these things. I know there a program that supposedly does, but I forget its name. clang-format is pretty great, but it doesn't work perfectly atm. Edit: uncrustify is the one #21392 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfriedt, please split addition of the functionality from the addition of tests/samples into separate commits. (Rule of thumb: better to have well-separated commits, it's much easier to squash them together than split them.)
Also, as suggested, please make sure tests use poll(), not select().
Thanks.
The question is how that is supposed to work. I myself don't have a knowledge of entire POSIX/extended POSIX APIs. But maintain an idea that the whole purpose of those APIs in Zephyr is to aid software portability (and I'm specifically interested in in maintaining that outlook because native Zephyr APIs don't often demonstrate that level of design consideration/conciseness/generality). So, there would need need to be some references of how a particular functionality should work, so we can check that Zephyr implementation adheres to it. And as even the POSIX standard offers only so much detail, that ultimately means writing tests to check behavior of a particular well-known, well-developed, popular system, Linux being an obvious choice. But that definitely requires quite an extra effort, so I'm all for limiting the scope. More specifically, I'm trying to see if it's possible to extend "depth" of scope, implement 2 distinct features in one go, that's why I suggested to look into possibility of implementing socketpair() in terms of pipe(). I'm all ok to limit "breadth" of scope, like start with supporting less socket types (up to just 1), don't support extended operations like recvfrom/sendto, making some support API kernel-only for starters, and leaving synchronization of such internal to API clients - all that is ok by me for initial version (which can be extended later as needed, based on the actual usecases). (I write this down as a kind of abstracted feedback, and that's definitely my personal outlook, which may be not shared by other developers.) Specific concern with SOCK_RAW is that in case of UDP/TCP it causes sockets to work on the level of packets, and packets are themselves datagrams, and working with datagrams over sockets is peculiar matter, so you wisely didn't include SOCK_DGRAM into this initial implementation. Now I don't know what SOCK_RAW could mean for the case of AF_UNIX, but I fully support leaving it out of scope of the initial implementation. And if the need for it arises, I'd love to see a test-like examples, with the source which can be compiled with both Zephyr and (for example) Linux, so consistent behavior can be demonstrated. |
I do have pretty detailed knowledge of POSIX APIs. It's better to have a limited subset of functionality than broken functionality, or OS-specific functionality. E.g. I know from experience that socketpair works equally well with either SOCK_STREAM or SOCK_RAW on several different OS's.
Right. Originally, I completely agreed that implementing socketpair in terms of pipe was a good idea, and then I remembered that bidirectional pipes are non-portable. Some POSIX APIs support them, others don't. They spec does not specify that it cannot be bidirectional, but it's wrong for the application to assume so. Since Zephyr pipes are also unidirectional, it makes sense to not force a square peg into a round hole, and also since it would have consumed excessive (dynamically allocated) resources, it seemed like the wrong approach. No judgement. It's smart to try to reuse code that way.
On every POSIX OS I've ever used (Linux, Darwin, QNX, my own RTOSs, probably BSDs), a RAW socket is the same as a STREAM when dealing with AF_UNIX, but it is kind of sloppy, and is not in POSIX, so best to cut it out. It's probably a bad habit I picked up from my time at a certain fruity phone manufacturer.
Agreed. |
All tests are successful now, except for the very last one -
|
@cfriedt: This has a single commit again (instead of 2 commits for subsys vs tests), marked as Draft, commit message is not descriptive of the feature added. Is this targeted for 2.3? (If so, these points should be addressed, to (potentially) allow merging as an initial implementation to be elaborated during the freeze window). |
I assumed you didn't have a chance to look into that, so looking myself. For reference, command to reproduce it is:
Where SANITYCHECK.sh
(You obviously will have your own convenience wrappers.) And --testcase-root there is purely to speed up matters, you can run ./scripts/sanitycheck alone and wait couple of hours ;-). And well, looking at your testcase.yaml it's not hard to spot problem:
That depends_on looks suspicious. You know, it's YAML syntax for mapping, and as you don't specify value after
(I.e. I killed empty depends_on:, but then common: becomes empty! Too shy to kill that, so moved "tags:" there. Why didn't move min_ram: there? Because "net.socket.socketpair:" would become empty! I hope you got rules of jongling by now.) So, I don't try to submit any patch for sanitycheck itself - fixing leaf error of "local variable 'v' referenced before assignment" won't lead to any "correct" behavior, it likely will just hit another error level up. The real solution would be to better specify testcase.yaml syntax, allow empty/placeholder values, and raise awareness so people weren't afraid to use them, etc., etc. And that's quite different kind of task. |
Btw, after these manipulations, what I get from sanitycheck is:
|
Right - sorry. I'm mostly concerned with getting it working before the commits are polished. |
@cfriedt: Please un-draft this PR, so I could dismiss my -1. Don't see a way to do that now, and draft stay is my only guess. (On holiday on Monday otherwise, and don't want my -1 to block this, just in case.) |
Fixed. I was just missing a |
Fixed that. Not sure what's up with sanitycheck now. |
Thanks, unblocking PR from my side, IMHO it's in good shape to be merged as EXPERIMENTAL (as it's marked in Kconfig).
I'd suggest to spend a couple of minutes to click thru Shippable CI UI to familiarize yourself with it. You'd soon arrive at https://app.shippable.com/github/zephyrproject-rtos/zephyr/runs/72444/5/tests, which shows what's wrong. |
I did run sanitycheck - just couldn't see it at the time (was falling asleep). Looks like the closing paren is missing for z_oops though |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@carlescufi : Please consider for merging.
Working: * non-blocking reads / writes * blocking reads / writes * send(2) / recv(2) / sendto(2) / recvfrom(2) / sendmsg(2) * select(2) * poll(2) Fixes #24366 Signed-off-by: Christopher Friedt <[email protected]>
Tests for issue #24366 Signed-off-by: Christopher Friedt <[email protected]>
@carlescufi - I've disabled the tests that require userspace + threads + permission fixes until I figure it out. |
@cfriedt: CI may randomly fail, yes. (~Last month is happens more often than previous years.) Quick way to restart build is to close and reopen a PR. (Doing now.) |
Working:
Fixes #24366