-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusocket-patch-drop-ipv6.lisp
More file actions
32 lines (27 loc) · 1.2 KB
/
usocket-patch-drop-ipv6.lisp
File metadata and controls
32 lines (27 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;; To avoid failures of socket(2) on EPERM, I drop IPv6 support.
;;; Please see:
;;; https://blog.marshallbrekka.com/post/2016-06-10/erlang-on-aws-lambda/
;;;
;;; This code is only for SBCL.
(in-package :aws-lambda-runtime)
(defvar *original-get-host-by-name* nil)
(defun get-hosts-by-name-and-remove-ipv6 (name)
"Calls the original `usocket:get-hosts-by-name' (via `*original-get-host-by-name*')
and removes IPv6 addresses, for supress making IPv6 sockets."
(loop with all-addrs = (funcall *original-get-host-by-name* name)
for addr in all-addrs
unless (= 16 (length addr)) ; see usocket's sbcl code.
collect addr into ret
finally
(let ((*print-pretty* nil))
(format *debug-io* "~&addrs ~A -> ~A~%" all-addrs ret))
(return ret)))
(defun patch-get-hosts-by-name ()
"Replace `usocket:get-hosts-by-name' with our `get-hosts-by-name-and-remove-ipv6'"
(unless *original-get-host-by-name*
(setf *original-get-host-by-name*
(fdefinition 'usocket::get-hosts-by-name)))
(shiftf (fdefinition 'usocket::get-hosts-by-name)
(fdefinition 'get-hosts-by-name-and-remove-ipv6)))
;; To drop IPv6 support, call `patch-get-hosts-by-name' at the
;; initialization phase in `bootstrap'.