diff options
author | 2016-12-10 12:11:19 +0200 | |
---|---|---|
committer | 2016-12-10 12:11:19 +0200 | |
commit | 85a7f31e2122b52a913a36a8af66f393e99e9bf0 (patch) | |
tree | c92a568e5802eff716d107b9ea8e174d0bd13c39 | |
parent | 64660f1ff4d245e96eb93da54e94825e37b2c115 (diff) |
Limit ZMQ RPC requests to 999999 bytes at CPP side. TODO: split requests at Python to smaller chunks.
Change-Id: Ieaf477d2ed8264e30a8275a75d597fdc8858da79
Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
4 files changed, 23 insertions, 4 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index 93a930e4..ce430e2b 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -130,13 +130,13 @@ class JsonRpcClient(object): if self.zipper.check_threshold(buffer): response = self.send_raw_msg(self.zipper.compress(buffer)) - if response: - response = self.zipper.decompress(response) else: response = self.send_raw_msg(buffer) if not response: return response + elif self.zipper.is_compressed(response): + response = self.zipper.decompress(response) # return to string response = response.decode() diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py index 397ada16..a2a47927 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py @@ -6,7 +6,7 @@ class ZippedMsg: MSG_COMPRESS_THRESHOLD = 256 MSG_COMPRESS_HEADER_MAGIC = 0xABE85CEA - def check_threshold (self, msg): + def check_threshold(self, msg): return len(msg) >= self.MSG_COMPRESS_THRESHOLD def compress (self, msg): @@ -16,7 +16,7 @@ class ZippedMsg: return new_msg - def decompress (self, msg): + def decompress(self, msg): if len(msg) < 8: return None @@ -30,3 +30,15 @@ class ZippedMsg: return x + + def is_compressed(self, msg): + if len(msg) < 8: + return False + + t = struct.unpack(">II", msg[:8]) + if (t[0] != self.MSG_COMPRESS_HEADER_MAGIC): + return False + + return True + + diff --git a/src/rpc-server/trex_rpc_req_resp_server.cpp b/src/rpc-server/trex_rpc_req_resp_server.cpp index 28bf1d80..729917c0 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.cpp +++ b/src/rpc-server/trex_rpc_req_resp_server.cpp @@ -171,6 +171,12 @@ void TrexRpcServerReqRes::_stop_rpc_thread() { void TrexRpcServerReqRes::handle_request(const std::string &request) { std::string response; + if ( request.size() > MAX_RPC_MSG_LEN ) { + response = "Request is too large (" + std::to_string(request.size()) + " bytes). Consider splitting to smaller chunks."; + handle_server_error(response); + return; + } + process_request(request, response); zmq_send(m_socket, response.c_str(), response.size(), 0); diff --git a/src/rpc-server/trex_rpc_req_resp_server.h b/src/rpc-server/trex_rpc_req_resp_server.h index 92d51a2a..9a994044 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.h +++ b/src/rpc-server/trex_rpc_req_resp_server.h @@ -53,6 +53,7 @@ protected: void *m_context; void *m_socket; + static const uint32_t MAX_RPC_MSG_LEN = 999999; }; /** |