Ensure we have a local copy of the tag in our request structure - which will be useful for the event framework

This commit is contained in:
Hamish Coleman 2021-11-07 15:16:10 +00:00
parent 5bcc6fe67a
commit 40773b4e4d
2 changed files with 13 additions and 5 deletions

View File

@ -83,7 +83,8 @@ SubFields:
Each request provides a tag value. Any non error reply associated with this
request will include this tag value, allowing all related messages to be
collected within the client.
collected within the client. The tag will be truncated if needed by the
daemon, but there will be at least 8 octets of space available.
Where possible, the error replies will also include this tag, however some
errors occur before the tag is parsed.
@ -131,7 +132,7 @@ containing a fragment of information related to the entire reply.
There are two keys in each dictionary containing metadata. First
is the `_tag`, containing the Message Tag from the original request.
Second is the `_type` whic identifies the expected contents of this
Second is the `_type` which identifies the expected contents of this
packet.
### `_type: error`

View File

@ -25,7 +25,7 @@
typedef struct mgmt_req {
n2n_edge_t *eee;
enum n2n_mgmt_type type;
char *tag;
char tag[10];
struct sockaddr_in sender_sock;
} mgmt_req_t;
@ -359,6 +359,11 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
mgmt_handler_t *handler;
size_t msg_len;
/* Initialise the tag field until we extract it from the cmdline */
req->tag[0] = '-';
req->tag[1] = '1';
req->tag[2] = '\0';
/* save a copy of the commandline before we reuse the udp_buf */
strncpy(cmdlinebuf, udp_buf, sizeof(cmdlinebuf)-1);
cmdlinebuf[sizeof(cmdlinebuf)-1] = 0;
@ -366,7 +371,6 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
traceEvent(TRACE_DEBUG, "mgmt json %s", cmdlinebuf);
typechar = strtok(cmdlinebuf, " \r\n");
req->tag = "-1";
if(!typechar) {
/* should not happen */
mgmt_error(req, udp_buf, "notype");
@ -404,7 +408,10 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
/*
* There might be an auth token mixed in with the tag
*/
req->tag = strtok(options, ":");
char *tagp = strtok(options, ":");
strncpy(req->tag, tagp, sizeof(req->tag)-1);
req->tag[sizeof(req->tag)-1] = '\0';
flagstr = strtok(NULL, ":");
if(flagstr) {
flags = strtoul(flagstr, NULL, 16);