diff --git a/lib/api-functions.coffee b/lib/api-functions.coffee index 956bf13..899392b 100644 --- a/lib/api-functions.coffee +++ b/lib/api-functions.coffee @@ -46,7 +46,13 @@ udpConReq = (address, un, key, callback) -> message = Buffer.from("GET #{uri} HTTP/1.1\r\nHost: #{address}\r\n\r\n") - client = dgram.createSocket('udp4') + client = dgram.createSocket({type: 'udp4', reuseAddr: true}) + UDP_CONNECTION_REQUEST_PORT = config.get('UDP_CONNECTION_REQUEST_PORT') + if UDP_CONNECTION_REQUEST_PORT + # When a device is NAT'ed, the UDP Connection Request must originate from the same address and port used by the STUN server, in order to traverse the firewall. + # This does require that the Genieacs NBI and STUN server are allowed to bind to the same address and port. + # The STUN server needs to open its UDP port with the SO_REUSEADDR option, allowing the NBI to also bind to the same port. + client.bind({port: UDP_CONNECTION_REQUEST_PORT, exclusive: true}) count = 3 client.send(message, 0, message.length, port, host, f = (err) -> diff --git a/lib/cluster.js b/lib/cluster.js index f3f3788..c7dd8b4 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -68,6 +68,8 @@ function restartWorker(worker, code, signal) { function start(service) { logger.init(service, VERSION); const config = require("./config"); + const SERVICE_ADDRESS = config.get(`${service.toUpperCase()}_INTERFACE`) + const SERVICE_PORT = config.get(`${service.toUpperCase()}_PORT`) logger.info({ message: `GenieACS (genieacs-${service}) starting`, @@ -78,12 +80,15 @@ function start(service) { }); cluster.on("listening", function(worker, address) { - logger.info({ - message: "Worker listening", - pid: worker.process.pid, - address: address.address, - port: address.port - }); + if ((address.addressType === 4 || address.addressType === 6) && + address.address === SERVICE_ADDRESS && address.port === SERVICE_PORT) { + logger.info({ + message: "Worker listening", + pid: worker.process.pid, + address: address.address, + port: address.port + }); + } }); cluster.on("exit", restartWorker); diff --git a/lib/config.coffee b/lib/config.coffee index c212fe9..c2b3f60 100644 --- a/lib/config.coffee +++ b/lib/config.coffee @@ -49,6 +49,8 @@ options = { FS_LOG_FILE : {type: 'path', default : ''}, FS_ACCESS_LOG_FILE : {type : 'path', default : ''}, + UDP_CONNECTION_REQUEST_PORT : {type : 'int', default : 0}, + DOWNLOAD_TIMEOUT: {type : 'int', default : 3600}, EXT_TIMEOUT: {type: 'int', default: 3000}, MAX_CACHE_TTL : {type : 'int', default : 86400},