Browse Source

test: don't assume broadcast traffic is unfiltered

parallel/test-dgram-broadcast-multi-process assumes non-local broadcast
traffic is unfiltered, an assumption that fails with, for example, the
default Fedora firewall rules.  Use a loopback interface instead.

Fixes: https://github.com/iojs/io.js/issues/219
PR-URL: https://github.com/iojs/io.js/pull/220
Reviewed-By: Fedor Indutny <fedor@indutny.com>
v1.8.0-commit
Ben Noordhuis 10 years ago
parent
commit
52e600a9c8
  1. 18
      test/parallel/test-dgram-broadcast-multi-process.js

18
test/parallel/test-dgram-broadcast-multi-process.js

@ -23,7 +23,6 @@ var common = require('../common'),
assert = require('assert'),
dgram = require('dgram'),
util = require('util'),
networkInterfaces = require('os').networkInterfaces(),
Buffer = require('buffer').Buffer,
fork = require('child_process').fork,
LOCAL_BROADCAST_HOST = '255.255.255.255',
@ -35,19 +34,6 @@ var common = require('../common'),
new Buffer('Fourth message to send')
];
// take the first non-internal interface as the address for binding
get_bindAddress: for (var name in networkInterfaces) {
var interfaces = networkInterfaces[name];
for(var i = 0; i < interfaces.length; i++) {
var localInterface = interfaces[i];
if (!localInterface.internal && localInterface.family === 'IPv4') {
var bindAddress = localInterface.address;
break get_bindAddress;
}
}
}
assert.ok(bindAddress);
if (process.argv[2] !== 'child') {
var workers = {},
listeners = 3,
@ -164,7 +150,7 @@ if (process.argv[2] !== 'child') {
// bind the address explicitly for sending
// INADDR_BROADCAST to only one interface
sendSocket.bind(common.PORT, bindAddress);
sendSocket.bind(common.PORT, '127.0.0.1');
sendSocket.on('listening', function () {
sendSocket.setBroadcast(true);
});
@ -211,7 +197,7 @@ if (process.argv[2] === 'child') {
listenSocket.on('message', function(buf, rinfo) {
// receive udp messages only sent from parent
if (rinfo.address !== bindAddress) return;
if (rinfo.address !== '127.0.0.1') return;
console.error('[CHILD] %s received %s from %j',
process.pid,

Loading…
Cancel
Save