diff options
| author | Robert Pluim | 2019-01-31 14:20:32 +0100 |
|---|---|---|
| committer | Robert Pluim | 2019-02-04 10:06:04 +0100 |
| commit | 49f6243027d910032f014be15b2c4ac2175c25f8 (patch) | |
| tree | f54edbb0c9d82bcb006bead0d30c8498f1bbd54f | |
| parent | 4633b0ef3ff7fc8ac013e4236edf782fb3cadfb4 (diff) | |
| download | emacs-49f6243027d910032f014be15b2c4ac2175c25f8.tar.gz emacs-49f6243027d910032f014be15b2c4ac2175c25f8.zip | |
Use IPv6 localhost when family is 'ipv6
This fixes Bug#34193
* src/process.c (Fmake_network_process): Explicitly use ::1 when
using IPv6 with 'local. Update docstring.
* test/lisp/net/network-stream-tests.el
(make-ipv6-tcp-server-with-unspecified-port):
(make-ipv6-tcp-server-with-specified-port): Test creating ipv6
local server.
(make-server): Add optional family argument, default ipv4
(echo-server-with-local-ipv4): Test connecting to 'local ipv4
(echo-server-with-local-ipv6): Test connecting to 'local ipv6
* doc/lispref/processes.texi (Network Processes): Describe
behavior when using 'local.
* etc/NEWS: Document new 'make-network-process' behavior when
connecting to 'local with ipv6.
| -rw-r--r-- | doc/lispref/processes.texi | 4 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | src/process.c | 16 | ||||
| -rw-r--r-- | test/lisp/net/network-stream-tests.el | 59 |
4 files changed, 79 insertions, 5 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index fd6686e8828..7b02759b307 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi | |||
| @@ -2640,7 +2640,9 @@ Specify the host to connect to. @var{host} should be a host name or | |||
| 2640 | Internet address, as a string, or the symbol @code{local} to specify | 2640 | Internet address, as a string, or the symbol @code{local} to specify |
| 2641 | the local host. If you specify @var{host} for a server, it must | 2641 | the local host. If you specify @var{host} for a server, it must |
| 2642 | specify a valid address for the local host, and only clients | 2642 | specify a valid address for the local host, and only clients |
| 2643 | connecting to that address will be accepted. | 2643 | connecting to that address will be accepted. When using @code{local}, |
| 2644 | by default IPv4 will be used, specify a @var{family} of @code{ipv6} to | ||
| 2645 | override this. | ||
| 2644 | 2646 | ||
| 2645 | @item :service @var{service} | 2647 | @item :service @var{service} |
| 2646 | @var{service} specifies a port number to connect to; or, for a server, | 2648 | @var{service} specifies a port number to connect to; or, for a server, |
| @@ -324,6 +324,11 @@ write alists of variables to ".dir-locals.el". This is the same | |||
| 324 | syntax that you can see in the example of a ".dir-locals.el" file in | 324 | syntax that you can see in the example of a ".dir-locals.el" file in |
| 325 | the node "(emacs) Directory Variables" of the user manual. | 325 | the node "(emacs) Directory Variables" of the user manual. |
| 326 | 326 | ||
| 327 | +++ | ||
| 328 | ** Network connections using 'local can now use IPv6. | ||
| 329 | 'make-network-process' now uses the correct loopback address when | ||
| 330 | asked to use :host 'local and :family 'ipv6. | ||
| 331 | |||
| 327 | 332 | ||
| 328 | * Changes in Specialized Modes and Packages in Emacs 27.1 | 333 | * Changes in Specialized Modes and Packages in Emacs 27.1 |
| 329 | 334 | ||
diff --git a/src/process.c b/src/process.c index 728c14a7624..9502ef461e8 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -3733,6 +3733,8 @@ also nil, meaning that this process is not associated with any buffer. | |||
| 3733 | address. The symbol `local' specifies the local host. If specified | 3733 | address. The symbol `local' specifies the local host. If specified |
| 3734 | for a server process, it must be a valid name or address for the local | 3734 | for a server process, it must be a valid name or address for the local |
| 3735 | host, and only clients connecting to that address will be accepted. | 3735 | host, and only clients connecting to that address will be accepted. |
| 3736 | `local' will use IPv4 by default, use a FAMILY of 'ipv6 to override | ||
| 3737 | this. | ||
| 3736 | 3738 | ||
| 3737 | :service SERVICE -- SERVICE is name of the service desired, or an | 3739 | :service SERVICE -- SERVICE is name of the service desired, or an |
| 3738 | integer specifying a port number to connect to. If SERVICE is t, | 3740 | integer specifying a port number to connect to. If SERVICE is t, |
| @@ -3983,14 +3985,24 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3983 | #ifdef HAVE_LOCAL_SOCKETS | 3985 | #ifdef HAVE_LOCAL_SOCKETS |
| 3984 | if (family != AF_LOCAL) | 3986 | if (family != AF_LOCAL) |
| 3985 | #endif | 3987 | #endif |
| 3986 | host = build_string ("127.0.0.1"); | 3988 | { |
| 3989 | if (family == AF_INET6) | ||
| 3990 | host = build_string ("::1"); | ||
| 3991 | else | ||
| 3992 | host = build_string ("127.0.0.1"); | ||
| 3993 | } | ||
| 3987 | } | 3994 | } |
| 3988 | else | 3995 | else |
| 3989 | { | 3996 | { |
| 3990 | if (EQ (host, Qlocal)) | 3997 | if (EQ (host, Qlocal)) |
| 3998 | { | ||
| 3991 | /* Depending on setup, "localhost" may map to different IPv4 and/or | 3999 | /* Depending on setup, "localhost" may map to different IPv4 and/or |
| 3992 | IPv6 addresses, so it's better to be explicit (Bug#6781). */ | 4000 | IPv6 addresses, so it's better to be explicit (Bug#6781). */ |
| 3993 | host = build_string ("127.0.0.1"); | 4001 | if (family == AF_INET6) |
| 4002 | host = build_string ("::1"); | ||
| 4003 | else | ||
| 4004 | host = build_string ("127.0.0.1"); | ||
| 4005 | } | ||
| 3994 | CHECK_STRING (host); | 4006 | CHECK_STRING (host); |
| 3995 | } | 4007 | } |
| 3996 | 4008 | ||
diff --git a/test/lisp/net/network-stream-tests.el b/test/lisp/net/network-stream-tests.el index 6ad0c25903f..6151c3064c4 100644 --- a/test/lisp/net/network-stream-tests.el +++ b/test/lisp/net/network-stream-tests.el | |||
| @@ -71,12 +71,39 @@ | |||
| 71 | (= (aref (process-contact server :local) 4) 57869))) | 71 | (= (aref (process-contact server :local) 4) 57869))) |
| 72 | (delete-process server))) | 72 | (delete-process server))) |
| 73 | 73 | ||
| 74 | (defun make-server (host) | 74 | (ert-deftest make-ipv6-tcp-server-with-unspecified-port () |
| 75 | (let ((server | ||
| 76 | (make-network-process | ||
| 77 | :name "server" | ||
| 78 | :server t | ||
| 79 | :noquery t | ||
| 80 | :family 'ipv6 | ||
| 81 | :service t | ||
| 82 | :host 'local))) | ||
| 83 | (should (and (arrayp (process-contact server :local)) | ||
| 84 | (numberp (aref (process-contact server :local) 8)) | ||
| 85 | (> (aref (process-contact server :local) 8) 0))) | ||
| 86 | (delete-process server))) | ||
| 87 | |||
| 88 | (ert-deftest make-ipv6-tcp-server-with-specified-port () | ||
| 89 | (let ((server | ||
| 90 | (make-network-process | ||
| 91 | :name "server" | ||
| 92 | :server t | ||
| 93 | :noquery t | ||
| 94 | :family 'ipv6 | ||
| 95 | :service 57870 | ||
| 96 | :host 'local))) | ||
| 97 | (should (and (arrayp (process-contact server :local)) | ||
| 98 | (= (aref (process-contact server :local) 8) 57870))) | ||
| 99 | (delete-process server))) | ||
| 100 | |||
| 101 | (defun make-server (host &optional family) | ||
| 75 | (make-network-process | 102 | (make-network-process |
| 76 | :name "server" | 103 | :name "server" |
| 77 | :server t | 104 | :server t |
| 78 | :noquery t | 105 | :noquery t |
| 79 | :family 'ipv4 | 106 | :family (or family 'ipv4) |
| 80 | :coding 'raw-text-unix | 107 | :coding 'raw-text-unix |
| 81 | :buffer (get-buffer-create "*server*") | 108 | :buffer (get-buffer-create "*server*") |
| 82 | :service t | 109 | :service t |
| @@ -129,6 +156,34 @@ | |||
| 129 | (should (equal (buffer-string) "foo\n"))) | 156 | (should (equal (buffer-string) "foo\n"))) |
| 130 | (delete-process server))) | 157 | (delete-process server))) |
| 131 | 158 | ||
| 159 | (ert-deftest echo-server-with-local-ipv4 () | ||
| 160 | (let* ((server (make-server 'local 'ipv4)) | ||
| 161 | (port (aref (process-contact server :local) 4)) | ||
| 162 | (proc (make-network-process :name "foo" | ||
| 163 | :buffer (generate-new-buffer "*foo*") | ||
| 164 | :host 'local | ||
| 165 | :family 'ipv4 | ||
| 166 | :service port))) | ||
| 167 | (with-current-buffer (process-buffer proc) | ||
| 168 | (process-send-string proc "echo foo") | ||
| 169 | (sleep-for 0.1) | ||
| 170 | (should (equal (buffer-string) "foo\n"))) | ||
| 171 | (delete-process server))) | ||
| 172 | |||
| 173 | (ert-deftest echo-server-with-local-ipv6 () | ||
| 174 | (let* ((server (make-server 'local 'ipv6)) | ||
| 175 | (port (aref (process-contact server :local) 8)) | ||
| 176 | (proc (make-network-process :name "foo" | ||
| 177 | :buffer (generate-new-buffer "*foo*") | ||
| 178 | :host 'local | ||
| 179 | :family 'ipv6 | ||
| 180 | :service port))) | ||
| 181 | (with-current-buffer (process-buffer proc) | ||
| 182 | (process-send-string proc "echo foo") | ||
| 183 | (sleep-for 0.1) | ||
| 184 | (should (equal (buffer-string) "foo\n"))) | ||
| 185 | (delete-process server))) | ||
| 186 | |||
| 132 | (ert-deftest echo-server-with-ip () | 187 | (ert-deftest echo-server-with-ip () |
| 133 | (let* ((server (make-server 'local)) | 188 | (let* ((server (make-server 'local)) |
| 134 | (port (aref (process-contact server :local) 4)) | 189 | (port (aref (process-contact server :local) 4)) |