aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_epoll.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-11 15:48:30 +0200
committerKim Alvefur <zash@zash.se>2018-10-11 15:48:30 +0200
commit8a62a14e5da8c27202cc11a37243569ab8962f76 (patch)
tree1f23a6726a51d1b6c2dc854dd34812f3e6ed656c /net/server_epoll.lua
parent1c5c6c92c1c2fedeeeb2e5287c667cabcadb41cf (diff)
downloadprosody-8a62a14e5da8c27202cc11a37243569ab8962f76.tar.gz
prosody-8a62a14e5da8c27202cc11a37243569ab8962f76.zip
net.server: Require IP address as argument to addclient (no DNS names)
The net.connect API should be used to resolve DNS names first
Diffstat (limited to 'net/server_epoll.lua')
-rw-r--r--net/server_epoll.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index 7a860878..b5053d22 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -21,6 +21,8 @@ local socket = require "socket";
local luasec = require "ssl";
local gettime = require "util.time".now;
local createtable = require "util.table".create;
+local inet = require "util.net";
+local inet_pton = inet.pton;
local _SOCKETINVALID = socket._SOCKETINVALID or -1;
local poll = require "util.poll".new();
@@ -614,7 +616,8 @@ local function wrapclient(conn, addr, port, listeners, read_size, tls_ctx)
if not client.peername then
client.peername, client.peerport = addr, port;
end
- client:init();
+ local ok, err = client:init();
+ if not ok then return ok, err; end
if tls_ctx then
client:starttls(tls_ctx);
end
@@ -623,12 +626,20 @@ end
-- New outgoing TCP connection
local function addclient(addr, port, listeners, read_size, tls_ctx)
- local conn, err = socket.tcp();
- if not conn then return conn, err; end
+ local n = inet_pton(addr);
+ if not n then return nil, "invalid-ip"; end
+ local create
+ if #n == 16 then
+ create = socket.tcp6 or socket.tcp;
+ else
+ create = socket.tcp4 or socket.tcp;
+ end
+ local conn, err = create();
conn:settimeout(0);
conn:connect(addr, port);
local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx)
- client:init();
+ local ok, err = client:init();
+ if not ok then return ok, err; end
if tls_ctx then
client:starttls(tls_ctx);
end