From 4d61591c0c5380921d2815ebe410b4d106acf75b Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 14 Aug 2018 13:33:30 +0100 Subject: [PATCH] Add cmd line option to ssl_client2 for datagram packing This commit adds a new command line option `dgram_packing` to the example server application programs/ssl/ssl_client2 allowing to allow/forbid the use of datagram packing. --- programs/ssl/ssl_client2.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 7cdc53a54..e72327315 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -107,6 +107,7 @@ int main( void ) #define DFL_HS_TO_MIN 0 #define DFL_HS_TO_MAX 0 #define DFL_DTLS_MTU -1 +#define DFL_DGRAM_PACKING 1 #define DFL_FALLBACK -1 #define DFL_EXTENDED_MS -1 #define DFL_ETM -1 @@ -200,7 +201,10 @@ int main( void ) " dtls=%%d default: 0 (TLS)\n" \ " hs_timeout=%%d-%%d default: (library default: 1000-60000)\n" \ " range of DTLS handshake timeouts in millisecs\n" \ - " mtu=%%d default: (library default: unlimited)\n" + " mtu=%%d default: (library default: unlimited)\n" \ + " dgram_packing=%%d default: 1 (allowed)\n" \ + " allow or forbid packing of multiple\n" \ + " records within a single datgram.\n" #else #define USAGE_DTLS "" #endif @@ -349,6 +353,7 @@ struct options uint32_t hs_to_max; /* Max value of DTLS handshake timer */ int dtls_mtu; /* UDP Maximum tranport unit for DTLS */ int fallback; /* is this a fallback connection? */ + int dgram_packing; /* allow/forbid datagram packing */ int extended_ms; /* negotiate extended master secret? */ int etm; /* negotiate encrypt then mac? */ } opt; @@ -624,6 +629,7 @@ int main( int argc, char *argv[] ) opt.fallback = DFL_FALLBACK; opt.extended_ms = DFL_EXTENDED_MS; opt.etm = DFL_ETM; + opt.dgram_packing = DFL_DGRAM_PACKING; for( i = 1; i < argc; i++ ) { @@ -937,6 +943,15 @@ int main( int argc, char *argv[] ) if( opt.dtls_mtu < 0 ) goto usage; } + else if( strcmp( p, "dgram_packing" ) == 0 ) + { + opt.dgram_packing = atoi( q ); + if( opt.dgram_packing != 0 && + opt.dgram_packing != 1 ) + { + goto usage; + } + } else if( strcmp( p, "recsplit" ) == 0 ) { opt.recsplit = atoi( q ); @@ -1340,6 +1355,9 @@ int main( int argc, char *argv[] ) if( opt.dtls_mtu != DFL_DTLS_MTU ) mbedtls_ssl_conf_mtu( &conf, opt.dtls_mtu ); + + if( opt.dgram_packing != DFL_DGRAM_PACKING ) + mbedtls_ssl_conf_datagram_packing( &ssl, opt.dgram_packing ); #endif /* MBEDTLS_SSL_PROTO_DTLS */ #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)