Skip to content

Commit 3b8d59e

Browse files
authored
Add an option to configure the interface used by UDPOutput (#359)
1 parent 29e2397 commit 3b8d59e

File tree

7 files changed

+24
-6
lines changed

7 files changed

+24
-6
lines changed

MessageControl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(PLUGIN_MESSAGECONTROL_MAX_EXPORTCONNECTIONS 5 CACHE STRING "Maximum allowed
3333
set(PLUGIN_MESSAGECONTROL_REMOTE "false" CACHE STRING "Remote binding details enabled")
3434
set(PLUGIN_MESSAGECONTROL_PORT "0" CACHE STRING "PORT address")
3535
set(PLUGIN_MESSAGECONTROL_BINDING "0.0.0.0" CACHE STRING "Binding IP Address")
36+
set(PLUGIN_MESSAGECONTROL_INTERFACE "eth0" CACHE STRING "Interface to bind to")
3637

3738
add_subdirectory(BuffersFlush)
3839

MessageControl/MessageControl.conf.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ if boolean("@PLUGIN_MESSAGECONTROL_REMOTE@"):
2020
remote = JSON()
2121
remote.add("port", "@PLUGIN_MESSAGECONTROL_PORT@")
2222
remote.add("binding", "@PLUGIN_MESSAGECONTROL_BINDING@")
23+
remote.add("interface", "@PLUGIN_MESSAGECONTROL_INTERFACE@")
2324
configuration.add("remote", remote)

MessageControl/MessageControl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ namespace Thunder {
4343
: Core::JSON::Container()
4444
, Port(2200)
4545
, Binding("0.0.0.0")
46+
, Interface("eth0")
4647
{
4748
Add(_T("port"), &Port);
4849
Add(_T("binding"), &Binding);
50+
Add(_T("interface"), &Interface);
4951
}
5052

5153
MessageControl::Config::NetworkNode::NetworkNode(const NetworkNode& copy)
5254
: Core::JSON::Container()
5355
, Port(copy.Port)
5456
, Binding(copy.Binding)
57+
, Interface(copy.Interface)
5558
{
5659
Add(_T("port"), &Port);
5760
Add(_T("binding"), &Binding);
61+
Add(_T("interface"), &Interface);
5862
}
5963

6064
MessageControl::MessageControl()
@@ -115,8 +119,8 @@ namespace Thunder {
115119
_config.FileName = service->VolatilePath() + _config.FileName.Value();
116120
Announce(new Publishers::FileOutput(abbreviate, _config.FileName.Value()));
117121
}
118-
if ((_config.Remote.IsSet() == true) && (_config.Remote.Binding.Value().empty() == false) && (_config.Remote.Port.Value() != 0)) {
119-
Announce(new Publishers::UDPOutput(abbreviate, Core::NodeId(_config.Remote.NodeId()), _service));
122+
if ((_config.Remote.IsSet() == true) && (_config.Remote.Binding.Value().empty() == false) && (_config.Remote.Port.Value() != 0) && (_config.Remote.Interface.Value().empty() == false)) {
123+
Announce(new Publishers::UDPOutput(abbreviate, Core::NodeId(_config.Remote.NodeId()), _service, _config.Remote.Interface.Value()));
120124
}
121125

122126
_webSocketExporter.Initialize(service, _config.MaxExportConnections.Value());

MessageControl/MessageControl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ namespace Plugin {
9090
public:
9191
Core::JSON::DecUInt16 Port;
9292
Core::JSON::String Binding;
93+
Core::JSON::String Interface;
9394
};
9495

9596
public:

MessageControl/MessageControlPlugin.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
"bindig" : {
4343
"type": "string",
4444
"description": "Binding address"
45+
},
46+
"interface" : {
47+
"type": "string",
48+
"description": "Interface"
4549
}
4650
},
47-
"required": [ "port", "binding" ]
51+
"required": [ "port", "binding", "interface" ]
4852
}
4953
},
5054
"required": [

MessageControl/MessageOutput.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ namespace Publishers {
180180
Trigger();
181181
}
182182

183-
UDPOutput::UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service)
183+
UDPOutput::UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service, const string& interface)
184184
: _convertor(abbreviate)
185185
, _output(nodeId)
186186
, _notification(*this)
187187
, _subSystem(service->SubSystems())
188+
, _interface(interface)
188189
{
189190
ASSERT(_subSystem != nullptr);
190191

@@ -198,7 +199,12 @@ namespace Publishers {
198199
{
199200
if (_subSystem->IsActive(PluginHost::ISubSystem::NETWORK)) {
200201
if (_output.IsOpen() == false) {
201-
_output.Open(0);
202+
if (_interface.empty() == false) {
203+
_output.Open(0, _interface);
204+
}
205+
else {
206+
_output.Open(0);
207+
}
202208
}
203209
ASSERT(_output.IsOpen() == true);
204210
}

MessageControl/MessageOutput.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ namespace Publishers {
401401
UDPOutput(const UDPOutput&) = delete;
402402
UDPOutput& operator=(const UDPOutput&) = delete;
403403

404-
explicit UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service);
404+
explicit UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service, const string& interface);
405405

406406
~UDPOutput() override
407407
{
@@ -420,6 +420,7 @@ namespace Publishers {
420420
Channel _output;
421421
Core::SinkType<Notification> _notification;
422422
PluginHost::ISubSystem* _subSystem;
423+
string _interface;
423424
};
424425

425426
class WebSocketOutput : public IPublish {

0 commit comments

Comments
 (0)