-
Notifications
You must be signed in to change notification settings - Fork 324
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 support for AF_UNIX #674
base: latestw_all
Are you sure you want to change the base?
Changes from all commits
3a77587
f7a8825
6dd4311
b31d181
6cc801b
705ed7e
8ca026c
36e5db5
fd096f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,10 @@ | |
#include "inc\utf.h" | ||
#include "misc_internal.h" | ||
#include "debug.h" | ||
#include "../../../config.h" | ||
#ifdef HAVE_AFUNIX_H | ||
#include <afunix.h> | ||
#endif | ||
|
||
#define INTERNAL_SEND_BUFFER_SIZE 70*1024 //70KB | ||
#define INTERNAL_RECV_BUFFER_SIZE 70*1024 //70KB | ||
|
@@ -118,7 +122,12 @@ socketio_acceptEx(struct w32_io* pio) | |
} | ||
|
||
/* create accepting socket */ | ||
#ifdef HAVE_AFUNIX_H | ||
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_IP); | ||
#else | ||
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP); | ||
#endif | ||
Comment on lines
+125
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would need to try this out. I don't recall if |
||
|
||
if (context->accept_socket == INVALID_SOCKET) { | ||
errno = errno_from_WSALastError(); | ||
debug3("acceptEx - socket() ERROR:%d, io:%p", WSAGetLastError(), pio); | ||
|
@@ -756,6 +765,9 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen) | |
int | ||
socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen) | ||
{ | ||
#ifdef HAVE_AFUNIX_H | ||
struct sockaddr_un tmp_unix; | ||
#endif | ||
|
||
struct sockaddr_in tmp_addr4; | ||
struct sockaddr_in6 tmp_addr6; | ||
|
@@ -778,6 +790,13 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen) | |
tmp_addr4.sin_port = 0; | ||
tmp_addr = (SOCKADDR*)&tmp_addr4; | ||
tmp_addr_len = sizeof(tmp_addr4); | ||
#ifdef HAVE_AFUNIX_H | ||
} else if (name->sa_family == AF_UNIX) { | ||
ZeroMemory(&tmp_unix, sizeof(tmp_unix)); | ||
tmp_unix.sun_family = AF_UNIX; | ||
tmp_addr = (SOCKADDR*)&tmp_unix; | ||
tmp_addr_len = sizeof(tmp_unix); | ||
#endif | ||
} else { | ||
errno = ENOTSUP; | ||
debug3("connectex - ERROR: unsuppored address family:%d, io:%p", name->sa_family, pio); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
#include <sys\utime.h> | ||
#include "misc_internal.h" | ||
#include "debug.h" | ||
#include "../../../config.h" | ||
|
||
/* internal table that stores the fd to w32_io mapping*/ | ||
struct w32fd_table { | ||
|
@@ -298,9 +299,9 @@ w32_socket(int domain, int type, int protocol) | |
errno = 0; | ||
if (min_index == -1) | ||
return -1; | ||
|
||
if (domain == AF_UNIX && type == SOCK_STREAM) { | ||
pio = fileio_afunix_socket(); | ||
pio = fileio_afunix_socket(); | ||
if (pio == NULL) | ||
return -1; | ||
pio->type = NONSOCK_FD; | ||
|
@@ -309,7 +310,70 @@ w32_socket(int domain, int type, int protocol) | |
if (pio == NULL) | ||
return -1; | ||
pio->type = SOCK_FD; | ||
} | ||
} | ||
|
||
fd_table_set(pio, min_index); | ||
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index); | ||
return min_index; | ||
} | ||
|
||
int | ||
w32_afunix_socket(struct sockaddr_un* addr) | ||
{ | ||
#ifdef HAVE_AFUNIX_H | ||
/* | ||
If HAVE_AFUNIX_H is defined, we can be dealing with the ssh-agent named pipe or | ||
a AF_UNIX socket if ssh forwarding is enabled. If the addr->sun_path is the | ||
the well known named pipe, we open the socket with w32_fileio. | ||
*/ | ||
int len = wcslen(AGENT_PIPE_ID); | ||
char* pipeid = (char*)malloc(len + 1); | ||
memset(pipeid, 0, len + 1); | ||
|
||
if(wcstombs(pipeid, AGENT_PIPE_ID, len + 1) != (size_t) -1 && strcmp(addr->sun_path, pipeid) == 0) | ||
return w32_fileio_socket(SOCK_STREAM, 0); | ||
else | ||
return w32_unix_socket(SOCK_STREAM, 0); | ||
Comment on lines
+333
to
+336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand the code correctly, you could technically just call Besides, instead of checking whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally I was thinking of behaving this way just for this implementation but I think the prefix makes sense in order to support other implementations. |
||
#else | ||
return w32_socket(AF_UNIX, SOCK_STREAM, 0); | ||
#endif | ||
} | ||
|
||
int | ||
w32_unix_socket(int type, int protocol) | ||
{ | ||
int domain = AF_UNIX; | ||
int min_index = fd_table_get_min_index(); | ||
struct w32_io* pio = NULL; | ||
|
||
errno = 0; | ||
if (min_index == -1) | ||
return -1; | ||
|
||
pio = socketio_socket(domain, type, protocol); | ||
if (pio == NULL) | ||
return -1; | ||
pio->type = SOCK_FD; | ||
|
||
fd_table_set(pio, min_index); | ||
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index); | ||
return min_index; | ||
} | ||
|
||
int | ||
w32_fileio_socket(int type, int protocol) | ||
{ | ||
int min_index = fd_table_get_min_index(); | ||
struct w32_io* pio = NULL; | ||
|
||
errno = 0; | ||
if (min_index == -1) | ||
return -1; | ||
|
||
pio = fileio_afunix_socket(); | ||
if (pio == NULL) | ||
return -1; | ||
pio->type = NONSOCK_FD; | ||
|
||
fd_table_set(pio, min_index); | ||
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2268,7 +2268,13 @@ muxclient(const char *path) | |
fatal("ControlPath too long ('%s' >= %u bytes)", path, | ||
(unsigned int)sizeof(addr.sun_path)); | ||
|
||
if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) | ||
#ifdef HAVE_AFUNIX_H | ||
sock = w32_afunix_socket(&addr); | ||
#elif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this elif intentional? It doesn't even compile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thedarkcolour That's wrong, it should be an |
||
sock = socket(PF_UNIX, SOCK_STREAM, 0); | ||
#endif | ||
|
||
if (sock == -1) | ||
fatal_f("socket(): %s", strerror(errno)); | ||
|
||
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { | ||
|
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.
Why do you need this
#ifdef
condition? Shouldn't you be able to always callw32_afunix_socket
as this method already handles the#ifdef
condition internally? Same question applies tomisc.c
andmux.c
.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.
I think you are right. Will look into simplifying! Thanks