Skip to content

Commit 1ec9daf

Browse files
thepacketgeekdavem330
authored andcommitted
net: netconsole: append userdata to fragmented netconsole messages
Regardless of whether the original message body or formatted userdata exceeds the MAX_PRINT_CHUNK, append userdata to the netconsole message starting with the first chunk that has available space after writing the body. Co-developed-by: Breno Leitao <[email protected]> Signed-off-by: Breno Leitao <[email protected]> Signed-off-by: Matthew Wood <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b4ab4f2 commit 1ec9daf

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

drivers/net/netconsole.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,24 +1085,48 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
10851085
memcpy(buf + release_len, header, header_len);
10861086
header_len += release_len;
10871087

1088-
while (offset < body_len) {
1088+
while (offset < body_len + userdata_len) {
10891089
int this_header = header_len;
1090-
int this_chunk;
1090+
int this_offset = 0;
1091+
int this_chunk = 0;
10911092

10921093
this_header += scnprintf(buf + this_header,
10931094
sizeof(buf) - this_header,
1094-
",ncfrag=%d/%d;", offset, body_len);
1095-
1096-
this_chunk = min(body_len - offset,
1097-
MAX_PRINT_CHUNK - this_header);
1098-
if (WARN_ON_ONCE(this_chunk <= 0))
1099-
return;
1100-
1101-
memcpy(buf + this_header, body + offset, this_chunk);
1102-
1103-
netpoll_send_udp(&nt->np, buf, this_header + this_chunk);
1095+
",ncfrag=%d/%d;", offset,
1096+
body_len + userdata_len);
1097+
1098+
/* Not all body data has been written yet */
1099+
if (offset < body_len) {
1100+
this_chunk = min(body_len - offset,
1101+
MAX_PRINT_CHUNK - this_header);
1102+
if (WARN_ON_ONCE(this_chunk <= 0))
1103+
return;
1104+
memcpy(buf + this_header, body + offset, this_chunk);
1105+
this_offset += this_chunk;
1106+
}
1107+
/* Body is fully written and there is pending userdata to write,
1108+
* append userdata in this chunk
1109+
*/
1110+
if (offset + this_offset >= body_len &&
1111+
offset + this_offset < userdata_len + body_len) {
1112+
int sent_userdata = (offset + this_offset) - body_len;
1113+
int preceding_bytes = this_chunk + this_header;
1114+
1115+
if (WARN_ON_ONCE(sent_userdata < 0))
1116+
return;
1117+
1118+
this_chunk = min(userdata_len - sent_userdata,
1119+
MAX_PRINT_CHUNK - preceding_bytes);
1120+
if (WARN_ON_ONCE(this_chunk <= 0))
1121+
return;
1122+
memcpy(buf + this_header + this_offset,
1123+
userdata + sent_userdata,
1124+
this_chunk);
1125+
this_offset += this_chunk;
1126+
}
11041127

1105-
offset += this_chunk;
1128+
netpoll_send_udp(&nt->np, buf, this_header + this_offset);
1129+
offset += this_offset;
11061130
}
11071131
}
11081132

0 commit comments

Comments
 (0)