Skip to content

Commit

Permalink
Add option for UDP clients to always accept messages ignoring sysid
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoColli committed Dec 10, 2024
1 parent 73fdfec commit 2606061
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const ConfFile::OptionsTable UdpEndpoint::option_table[] = {
{"CoalesceBytes", false, ConfFile::parse_ul, OPTIONS_TABLE_STRUCT_FIELD(UdpEndpointConfig, coalesce_bytes)},
{"CoalesceMs", false, ConfFile::parse_ul, OPTIONS_TABLE_STRUCT_FIELD(UdpEndpointConfig, coalesce_ms)},
{"CoalesceNoDelay", false, ConfFile::parse_uint32_vector, OPTIONS_TABLE_STRUCT_FIELD(UdpEndpointConfig, coalesce_nodelay)},
{"AlwaysAccept", false, ConfFile::parse_bool, OPTIONS_TABLE_STRUCT_FIELD(UdpEndpointConfig, always_accept)},
{}
};

Expand Down Expand Up @@ -1161,6 +1162,7 @@ bool UdpEndpoint::setup(UdpEndpointConfig conf)
this->add_no_coalesce_msg_id(msg_id);
}

this->_always_accept = conf.always_accept;
return true;
}

Expand Down Expand Up @@ -1535,6 +1537,12 @@ Endpoint::AcceptState UdpEndpoint::accept_msg(const struct buffer *pbuf) const
return Endpoint::AcceptState::Filtered;
}

// Endpoint has the always accept flag set
if (this->_always_accept) {
log_trace("Endpoint [%d]%s: message accepted because the always_accept flag is set", fd, _name.c_str());
return Endpoint::AcceptState::Accepted;
}

// otherwise: refer to standard accept rules
return Endpoint::accept_msg(pbuf);
}
Expand Down
2 changes: 2 additions & 0 deletions src/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct UdpEndpointConfig {
unsigned long coalesce_bytes;
unsigned long coalesce_ms;
std::vector<uint32_t> coalesce_nodelay;
bool always_accept;
};

struct TcpEndpointConfig {
Expand Down Expand Up @@ -378,6 +379,7 @@ class UdpEndpoint : public Endpoint {
unsigned long _coalesce_ms = 0UL; // max time to hold data to try to coalesce packets together

UdpEndpointConfig::Mode _mode = UdpEndpointConfig::Mode::Undefined;
bool _always_accept = false; // always accept messages disregarding sys and com IDs
private:
bool is_ipv6;
struct sockaddr_in sockaddr;
Expand Down
10 changes: 7 additions & 3 deletions src/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ void Mainloop::handle_command_pipe()
// a0 a1 a2 a3 a4 a5 a6 a7 a8 a9
// allow_msg_id_out block_msg_id_out allow_src_comp_out block_src_comp_out allow_src_sys_out block_src_sys_out allow_msg_id_in
// a10 a11 a12 a13 a14 a15 a16
// block_msg_id_in allow_src_comp_in block_src_comp_in allow_src_sys_in block_src_sys_in
// a17 a18 a19 a20 a21
// block_msg_id_in allow_src_comp_in block_src_comp_in allow_src_sys_in block_src_sys_in always_accept
// a17 a18 a19 a20 a21 a22

std::set<unsigned> argc_options = {6, 7, 10, 22};
std::set<unsigned> argc_options = {6, 7, 10, 22, 23};

// Sanity checks
if (!argc_options.count(a.size()) || a[1] != "udp") {
Expand Down Expand Up @@ -354,6 +354,10 @@ void Mainloop::handle_command_pipe()
parse_into_vector(a[21], conf.block_src_sys_in);
}

if (a.size() > 22) { // always accept flag provided
conf.always_accept = a[4] == "true";
}

// UDP endpoint configuration to instance
auto dynamic_udp = std::make_shared<UdpEndpoint>(conf.name);
if (!dynamic_udp->setup(conf)) {
Expand Down

0 comments on commit 2606061

Please sign in to comment.