From 0a5ede90786d104c2157ab619366f5fdbd160df5 Mon Sep 17 00:00:00 2001 From: Michael Tuexen <tuexen@fh-muenster.de> Date: Fri, 13 Oct 2017 19:36:57 +0200 Subject: [PATCH] Restrict the usage of partial TLVs to imbound packets. --- gtests/net/packetdrill/sctp_packet.c | 36 ++++++++++++++++++++++++++++ gtests/net/packetdrill/sctp_packet.h | 16 +++++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/gtests/net/packetdrill/sctp_packet.c b/gtests/net/packetdrill/sctp_packet.c index f383f7b4..c84be0ee 100644 --- a/gtests/net/packetdrill/sctp_packet.c +++ b/gtests/net/packetdrill/sctp_packet.c @@ -516,6 +516,9 @@ sctp_generic_chunk_new(s64 type, s64 flgs, s64 len, } if (bytes != NULL) { value_length = bytes->nr_entries; + if (value_length < length - header_length) { + flags |= FLAG_CHUNK_PARTIAL; + } } else { value_length = length- header_length; flags |= FLAG_CHUNK_VALUE_NOCHECK; @@ -1768,6 +1771,9 @@ sctp_generic_parameter_new(s64 type, s64 len, struct sctp_byte_list *bytes) } if (bytes != NULL) { value_length = bytes->nr_entries; + if (value_length < length - header_length) { + flags |= FLAG_PARAMETER_PARTIAL; + } } else { value_length = length - header_length; flags |= FLAG_PARAMETER_VALUE_NOCHECK; @@ -2526,6 +2532,9 @@ sctp_generic_cause_new(s64 code, s64 len, struct sctp_byte_list *bytes) } if (bytes != NULL) { information_length = bytes->nr_entries; + if (information_length < length - header_length) { + flags |= FLAG_CAUSE_PARTIAL; + } } else { information_length = length - header_length; flags |= FLAG_CAUSE_INFORMATION_NOCHECK; @@ -3403,6 +3412,33 @@ new_sctp_packet(int address_family, "bad CRC32C can only be requested for inbound packets"); return NULL; } + for (chunk_item = list->first; + chunk_item != NULL; + chunk_item = chunk_item->next) { + if (chunk_item->flags & FLAG_CHUNK_PARTIAL) { + asprintf(error, + "Partial chunks not supported for outbound packets"); + return NULL; + } + for (parameter_item = chunk_item->parameter_list->first; + parameter_item != NULL; + parameter_item = parameter_item->next) { + if (parameter_item->flags & FLAG_PARAMETER_PARTIAL) { + asprintf(error, + "Partial parameters not supported for outbound packets"); + return NULL; + } + } + for (cause_item = chunk_item->cause_list->first; + cause_item != NULL; + cause_item = cause_item->next) { + if (cause_item->flags & FLAG_CAUSE_PARTIAL) { + asprintf(error, + "Partial causes not supported for outbound packets"); + return NULL; + } + } + } } /* Allocate and zero out a packet object of the desired size */ diff --git a/gtests/net/packetdrill/sctp_packet.h b/gtests/net/packetdrill/sctp_packet.h index 33f420e5..e9f8e899 100644 --- a/gtests/net/packetdrill/sctp_packet.h +++ b/gtests/net/packetdrill/sctp_packet.h @@ -261,6 +261,7 @@ sctp_chunk_list_item_new(struct sctp_chunk *chunk, u32 length, u32 flags, #define FLAG_CHUNK_FLAGS_NOCHECK 0x00000002 #define FLAG_CHUNK_LENGTH_NOCHECK 0x00000004 #define FLAG_CHUNK_VALUE_NOCHECK 0x00000008 +#define FLAG_CHUNK_PARTIAL 0x00000010 struct sctp_chunk_list_item * sctp_generic_chunk_new(s64 type, s64 flgs, s64 len, @@ -400,9 +401,10 @@ sctp_chunk_list_append(struct sctp_chunk_list *list, void sctp_chunk_list_free(struct sctp_chunk_list *list); -#define FLAG_PARAMETER_TYPE_NOCHECK 0x00000001 -#define FLAG_PARAMETER_LENGTH_NOCHECK 0x00000002 -#define FLAG_PARAMETER_VALUE_NOCHECK 0x00000004 +#define FLAG_PARAMETER_TYPE_NOCHECK 0x00000001 +#define FLAG_PARAMETER_LENGTH_NOCHECK 0x00000002 +#define FLAG_PARAMETER_VALUE_NOCHECK 0x00000004 +#define FLAG_PARAMETER_PARTIAL 0x00000008 struct sctp_parameter_list_item * sctp_parameter_list_item_new(struct sctp_parameter *parameter, @@ -498,10 +500,10 @@ struct sctp_cause_list_item * sctp_cause_list_item_new(struct sctp_cause *cause, u32 length, u32 flags); -#define FLAG_CAUSE_CODE_NOCHECK 0x00000001 -#define FLAG_CAUSE_LENGTH_NOCHECK 0x00000002 -#define FLAG_CAUSE_INFORMATION_NOCHECK 0x00000004 - +#define FLAG_CAUSE_CODE_NOCHECK 0x00000001 +#define FLAG_CAUSE_LENGTH_NOCHECK 0x00000002 +#define FLAG_CAUSE_INFORMATION_NOCHECK 0x00000004 +#define FLAG_CAUSE_PARTIAL 0x00000008 struct sctp_cause_list_item * sctp_generic_cause_new(s64 code, s64 len, struct sctp_byte_list *bytes); -- GitLab