From fc805c253c4ec40ae6f6b1b48eb6bbbfb82a4a1e Mon Sep 17 00:00:00 2001
From: Aomx <aomx@riseup.net>
Date: Wed, 13 Jul 2016 14:48:25 +0200
Subject: [PATCH] added pretty printing for forward_tsn_chunk

---
 gtests/net/packetdrill/sctp_chunk_to_string.c | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/gtests/net/packetdrill/sctp_chunk_to_string.c b/gtests/net/packetdrill/sctp_chunk_to_string.c
index 2cb43820..16b0af4d 100644
--- a/gtests/net/packetdrill/sctp_chunk_to_string.c
+++ b/gtests/net/packetdrill/sctp_chunk_to_string.c
@@ -1654,6 +1654,45 @@ static int sctp_reconfig_chunk_to_string(
 	return result;
 }
 
+static u16 get_num_sid_blocks (u16 packet_length) {
+	return (packet_length - sizeof(struct sctp_forward_tsn_chunk)) / sizeof(struct sctp_stream_identifier_block);
+}
+
+static int sctp_forward_tsn_chunk_to_string(
+	FILE *s,
+	struct sctp_forward_tsn_chunk *chunk,
+	char **error)
+{
+	u16 length, i;
+	length = ntohs(chunk->length);
+	u16 num_sid_blocks = get_num_sid_blocks(length);
+	
+	if (length < sizeof(struct sctp_forward_tsn_chunk)) {
+		asprintf(error, "FORWARD_TSN chunk too short (length=%u)", length);
+		return STATUS_ERR;
+	}
+	
+	fputs("FORWARD_TSN[", s);
+	fprintf(s, "flgs=0x%02x, ", chunk->flags);
+	fprintf(s, "len=%u, ", length);
+	fprintf(s, "cum_tsn=%d, ", ntohl(chunk->cum_tsn));
+	
+	fprintf(s, "sids=[");
+	
+	for (i = 0; i < num_sid_blocks; i++) {
+		fprintf(s, "%u:%u",  
+			ntohs(chunk->stream_identifier_blocks[i].stream), 
+			ntohs(chunk->stream_identifier_blocks[i].stream_sequence));
+		if (i != num_sid_blocks-1) {
+			fprintf(s, ", ");
+		}
+	}
+	
+	fprintf(s, "]");
+	
+	return STATUS_OK;
+}
+
 static int sctp_unknown_chunk_to_string(FILE *s,
 					struct sctp_chunk *chunk,
 					char **error)
@@ -1750,6 +1789,10 @@ int sctp_chunk_to_string(FILE *s, struct sctp_chunk *chunk, char **error)
 		result = sctp_reconfig_chunk_to_string(s,
 			(struct sctp_reconfig_chunk *)chunk, error);
 		break;
+	case SCTP_FORWARD_TSN_CHUNK_TYPE:
+		result = sctp_forward_tsn_chunk_to_string(s,
+			(struct sctp_forward_tsn_chunk *)chunk, error);
+		break;
 	default:
 		result = sctp_unknown_chunk_to_string(s, chunk, error);
 		break;
-- 
GitLab