summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-11-20 18:00:05 +0000
committerGitHub <noreply@github.com>2024-11-20 18:00:05 +0000
commit3452f4239c91c6aaf30ed295482c26ef1b8c4697 (patch)
tree0ec0f9f4306b69c9ff12c8b8f90542014f06b9d5
parent1c8321a8679e132cec1b769ab364149e794558cc (diff)
parentf38a402f158dad178165e330f292393278705281 (diff)
downloadvyos-1x-3452f4239c91c6aaf30ed295482c26ef1b8c4697.tar.gz
vyos-1x-3452f4239c91c6aaf30ed295482c26ef1b8c4697.zip
Merge pull request #4197 from jestabro/multipart-msg-output
configd: T6899: use multipart message instead of extra exchange
-rwxr-xr-xsrc/services/vyos-configd28
-rw-r--r--src/shim/vyshim.c12
2 files changed, 13 insertions, 27 deletions
diff --git a/src/services/vyos-configd b/src/services/vyos-configd
index cb23642dc..d977ba2cb 100755
--- a/src/services/vyos-configd
+++ b/src/services/vyos-configd
@@ -56,6 +56,7 @@ else:
SOCKET_PATH = 'ipc:///run/vyos-configd.sock'
MAX_MSG_SIZE = 65535
+PAD_MSG_SIZE = 6
# Response error codes
R_SUCCESS = 1
@@ -256,25 +257,14 @@ def process_node_data(config, data, _last: bool = False) -> tuple[int, str]:
def send_result(sock, err, msg):
- msg_size = min(MAX_MSG_SIZE, len(msg)) if msg else 0
-
- err_rep = err.to_bytes(1, byteorder=sys.byteorder)
- logger.debug(f'Sending reply: {err}')
- sock.send(err_rep)
-
- # size req from vyshim client
- size_req = sock.recv().decode()
- logger.debug(f'Received request: {size_req}')
- msg_size_rep = hex(msg_size).encode()
- sock.send(msg_size_rep)
- logger.debug(f'Sending reply: {msg_size}')
-
- if msg_size > 0:
- # send req is sent from vyshim client only if msg_size > 0
- send_req = sock.recv().decode()
- logger.debug(f'Received request: {send_req}')
- sock.send(msg.encode())
- logger.debug('Sending reply with output')
+ msg = msg if msg else ''
+ msg_size = min(MAX_MSG_SIZE, len(msg))
+
+ err_rep = err.to_bytes(1)
+ msg_size_rep = f'{msg_size:#0{PAD_MSG_SIZE}x}'
+
+ logger.debug(f'Sending reply: error_code {err} with output')
+ sock.send_multipart([err_rep, msg_size_rep.encode(), msg.encode()])
write_stdout_log(script_stdout_log, msg)
diff --git a/src/shim/vyshim.c b/src/shim/vyshim.c
index 68e6c4015..1eb653cbf 100644
--- a/src/shim/vyshim.c
+++ b/src/shim/vyshim.c
@@ -119,21 +119,17 @@ int main(int argc, char* argv[])
zmq_send(requester, string_node_data_msg, strlen(string_node_data_msg), 0);
zmq_recv(requester, error_code, 1, 0);
- debug_print("Received node data receipt\n");
+ debug_print("Received node data receipt with error_code\n");
char msg_size_str[7];
- zmq_send(requester, "msg_size", 8, 0);
zmq_recv(requester, msg_size_str, 6, 0);
msg_size_str[6] = '\0';
int msg_size = (int)strtol(msg_size_str, NULL, 16);
debug_print("msg_size: %d\n", msg_size);
- if (msg_size > 0) {
- zmq_send(requester, "send", 4, 0);
- char *msg = s_recv_string(requester, msg_size);
- printf("%s", msg);
- free(msg);
- }
+ char *msg = s_recv_string(requester, msg_size);
+ printf("%s", msg);
+ free(msg);
free(string_node_data_msg);