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

Attempt to use AF_UNIX sockets instead of AF_INET on Windows 10+ #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dlenski
Copy link

@dlenski dlenski commented Oct 4, 2023

This PR is based on the improvements we made in OpenConnect in https://gitlab.com/openconnect/openconnect/-/merge_requests/320.

Unfortunately, and maddeningly, it's possible for the local IPv4 routes (127.0.0.0/8) to be deleted on Windows; this will prevent dumb_socketpair() from working in its current form. Using AF_UNIX sockets

In order to deal with the above weaknesses, the approach taken here is to first try creating an AF_UNIX socketpair, and then to fallback to AF_INET if it fails. Furthermore, because the AF_UNIX socketpair requires a real, writable filesystem path, it tries binding to each of the following before giving up on AF_UNIX:

  1. GetTempDir() \ (filename including PID and 64-bit time ticks)
  2. GetWindowsDirectory() \ Temp \ (...)
  3. C:\TEMP \ (...)
  4. . \ (...)

Based on testing so far, this implementation appears to be robust and to avoid the problems with deleted IPv4 localhost routes.

Also adds a stub for the <afunix.h>, which defines UNIX_PATH_MAX and struct sockaddr_un. MinGW lacks this header, but other FLOSS projects show how to embed the needed definitions:

This PR is based on the improvements we made in OpenConnect in
https://gitlab.com/openconnect/openconnect/-/merge_requests/320.

Unfortunately, and maddeningly, it's possible for the local IPv4 routes
(127.0.0.0/8) to be deleted on Windows; this will prevent dumb_socketpair()
from working in its current form. Using AF_UNIX sockets

- AF_UNIX/SOCK_STREAM became available in Windows 10:
  https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows
- There appears to be no other documentation whatsoever of Windows's support
  for AF_UNIX sockets.
- Contrary to the claims of that blog post, abstract sockets
  (filesystem-independent) are not implemented:
  microsoft/WSL#4240 (comment)

In order to deal with the above weaknesses, the approach taken here is
to first try creating an AF_UNIX socketpair, and then to fallback to
AF_INET if it fails. Furthermore, because the AF_UNIX socketpair
requires a real, writable filesystem path, it tries binding to each
of the following before giving up on AF_UNIX:

1. GetTempDir() \ (filename including PID and 64-bit time ticks)
2. GetWindowsDirectory() \ Temp \ (...)
3. C:\TEMP \                      (...)
4. . \                            (...)

Based on testing so far, this implementation appears to be robust and to
avoid the problems with deleted IPv4 localhost routes.

Also adds a stub for the <afunix.h>, which defines `UNIX_PATH_MAX` and
`struct sockaddr_un`.  MinGW lacks this header, but other FLOSS projects
show how to embed the needed definitions:

- MisterDA/ocaml@5855ce5
- https://github.com/curl/curl/blob/curl-7_74_0/lib/config-win32.h#L725-L734
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.

1 participant