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

unix_socket: add support for abstract unix domain socket #1197

Closed
wants to merge 1 commit into from

Conversation

iboukris
Copy link
Contributor

@iboukris iboukris commented Jan 8, 2017

In addition to unix domain sockets, Linux also supports an
abstract namespace which is independent of the filesystem.

In order to support it, add new CURLOPT_ABSTRACT_UNIX_SOCKET
option which uses the same storage as CURLOPT_UNIX_SOCKET_PATH
internally, along with a flag to specify abstract socket.

On non-supporting platforms, the abstract address will be
interpreted as an empty string and fail gracefully.

Also add new --abstract-unix-socket tool parameter.

Reported-by: Chungtsun Li (typeless)
Signed-off-by: Isaac Boukris iboukris@gmail.com

Fixes #1061

@mention-bot
Copy link

@Frenche, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bagder, @Lekensteyn and @yangtse to be potential reviewers.

@iboukris
Copy link
Contributor Author

iboukris commented Jan 8, 2017

Note, the man pages are missing, I'll work on it asap.
Just thought maybe someone could review meanwhile, thanks.

config->unix_socket_path);
my_setopt_str(curl, config->abstract_unix_socket ?
CURLOPT_ABSTRACT_UNIX_SOCKET :
CURLOPT_UNIX_SOCKET_PATH, config->unix_socket_path);
Copy link
Member

Choose a reason for hiding this comment

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

fix for style, use column alignment. suggest parentheses and braces to make it easier to understand

if(config->unix_socket_path) {
  my_setopt_str(curl, (config->abstract_unix_socket ?
                       CURLOPT_ABSTRACT_UNIX_SOCKET :
                       CURLOPT_UNIX_SOCKET_PATH),
                config->unix_socket_path);
}

Copy link
Member

Choose a reason for hiding this comment

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

Also it occurs to me that CURLoption parameter is stringized by the function-like macro so I'm pretty sure this is not going to work, run with --libcurl to confirm. Assuming that's the case do this instead

if(config->unix_socket_path) {
  if(config->abstract_unix_socket) {
    my_setopt_str(curl, CURLOPT_ABSTRACT_UNIX_SOCKET,
                  config->unix_socket_path);
  }
  else {
    my_setopt_str(curl, CURLOPT_UNIX_SOCKET_PATH,
                  config->unix_socket_path);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll fix this.

/* sun_path must be able to store the NUL-terminated path */
path_len = strlen(path);
if(path_len >= sizeof(sa_un->sun_path)) {
path_len = strlen(path) +1;
Copy link
Member

Choose a reason for hiding this comment

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

I would change all the +1 to + 1 and the -1 to - 1. I don't think we have a policy on it but foo +1 looks weird and I don't recall it elsewhere in the codebase. Occasionally I've seen foo+1 but foo + 1 I believe is more common

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.

@Lekensteyn
Copy link
Contributor

Can you modify this to use url-escaped paths (and make this encoding requirement very clear in the docs)? That will correctly handle paths containing NUL bytes.

(As for alternatives: curl_easy_setopt only accepts one parameter, so the length cannot be given. Requiring the user to pass a fixed-length buffer is error prone as well. I also considered an option to provide the length for an abstract socket path, but this is too complicated to get right.)

@iboukris
Copy link
Contributor Author

iboukris commented Jan 9, 2017

@Lekensteyn that was my initial intention (see comments in #1061), however it got complicated in matter of design, usage and implementation.
And frankly, I think using such path embedding zeros is a good recipe for troubles and should be discouraged. Also all the tools and services I've seen using abstract socket had proper normal abstract path (with only null prefix).

@iboukris iboukris force-pushed the abstract_unix_domain_socket branch 2 times, most recently from 4e932d7 to f9fb05d Compare January 9, 2017 22:46
@iboukris
Copy link
Contributor Author

iboukris commented Jan 9, 2017

I've addressed Jay's comments and added the missing doc, please review - thanks!

Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@Lekensteyn Lekensteyn left a comment

Choose a reason for hiding this comment

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

Looks good, only some doc nitpicks below :-)

.\" * | (__| |_| | _ <| |___
.\" * \___|\___/|_| \_\_____|
.\" *
.\" * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
Copy link
Contributor

Choose a reason for hiding this comment

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

We're already in 2017 :-)

.\" *
.\" **************************************************************************
.\"
.TH CURLOPT_ABSTRACT_UNIX_SOCKET 3 "08 Jan 2016" "libcurl 7.53.0" "curl_easy_setopt options"
Copy link
Contributor

Choose a reason for hiding this comment

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

2017

@@ -272,6 +272,7 @@ static const char *const helptext[] = {
" --tlspassword STRING TLS password",
" --tlsauthtype STRING TLS authentication type (default: SRP)",
" --unix-socket FILE Connect through this Unix domain socket",
" --abstract-unix-socket PATH Connect to an abstract Unix domain socket",
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with --unix-socket, maybe change FILE to PATH (or the other way round?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't a file in case of abstract, but path would be fine for both, I'll fix it.

In addition to unix domain sockets, Linux also supports an
abstract namespace which is independent of the filesystem.

In order to support it, add new CURLOPT_ABSTRACT_UNIX_SOCKET
option which uses the same storage as CURLOPT_UNIX_SOCKET_PATH
internally, along with a flag to specify abstract socket.

On non-supporting platforms, the abstract address will be
interpreted as an empty string and fail gracefully.

Also add new --abstract-unix-socket tool parameter.

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
Reported-by: Chungtsun Li (typeless)
@iboukris
Copy link
Contributor Author

Thanks for the reviews, I've addressed @Lekensteyn's comments.

@jay
Copy link
Member

jay commented Jan 12, 2017

It's better as FILE because that's what we use in the other options , see curl --help | grep FILE
Otherwise this looks ready to go. Before you send it upstream make sure to modify the commit message to point back to this thread with a Ref or Closes etc

@jay
Copy link
Member

jay commented Jan 12, 2017

I may have spoken too soon maybe it's not better as FILE, if it's not a file.

@iboukris
Copy link
Contributor Author

Yea, it is not a file, just a name (could be just 'foo', without slash).
In the unix(7) man page it is mostly referred to as path.

@jay
Copy link
Member

jay commented Jan 12, 2017

Ok, nevermind then

@iboukris
Copy link
Contributor Author

iboukris commented Jan 12, 2017

Actually, a regular unix socket which is a file, can also be set to just 'foo' as a relative path, but abstract is really not a file on the file system.

@jay
Copy link
Member

jay commented Jan 12, 2017

Ok, thanks for explaining that. I think it was fine the way you had it then, FILE for unix domain and PATH for abstract unix domain.

@iboukris
Copy link
Contributor Author

The man page terminology argument was about both :)

Copy link
Contributor

@Lekensteyn Lekensteyn left a comment

Choose a reason for hiding this comment

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

LGTM. I'll try to test the new functionality after the weekend and merge then.

(Hey, if you want to get your hands wet, maybe you can create another patch that extends the test suite with support for abstract domain sockets :-))

@Lekensteyn
Copy link
Contributor

Decided to apply it now anyway. Briefly tested with an out-of-tree autotools build. Tested things like:

socat ABSTRACT-LISTEN:meh,fork TCP-CONNECT:lekensteyn.nl:443
src/curl -vL --abstract-unix-socket meh https://lekensteyn.nl/files

@iboukris
Copy link
Contributor Author

Great, thanks all!

@iboukris iboukris deleted the abstract_unix_domain_socket branch March 28, 2017 21:16
@curl curl locked and limited conversation to collaborators May 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants