diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2012-06-29 21:14:25 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-06-30 01:01:34 +0200 |
commit | 9348c9d9acd4cf5b5b0261a24c9bd9bc0f3f1de6 (patch) | |
tree | ff19fe980dd3110707a8703f94d786d5068b3c8d | |
parent | 6d0b4dc6ef9ed41982d82318f3aa577d8745f69f (diff) | |
download | gnutls-9348c9d9acd4cf5b5b0261a24c9bd9bc0f3f1de6.tar.gz |
Add gnutls_dtls_set_data_mtu()
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
-rw-r--r-- | lib/gnutls_dtls.c | 40 | ||||
-rw-r--r-- | lib/includes/gnutls/dtls.h | 1 | ||||
-rw-r--r-- | lib/libgnutls.map | 1 |
3 files changed, 42 insertions, 0 deletions
diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c index 979198cc2e..04aa646f7d 100644 --- a/lib/gnutls_dtls.c +++ b/lib/gnutls_dtls.c @@ -669,6 +669,46 @@ int overhead; } /** + * gnutls_dtls_set_data_mtu: + * @session: is a #gnutls_session_t structure. + * @mtu: The maximum unencrypted transfer unit of the session + * + * This function will set the maximum size of the *unencrypted* records + * which will be sent over a DTLS session. It is equivalent to calculating + * the DTLS packet overhead with the current encryption parameters, and + * calling gnutls_dtls_set_mtu() with that value. In particular, this means + * that you may need to call this function again after any negotiation or + * renegotiation, in order to ensure that the MTU is still sufficient to + * account for the new protocol overhead. + * + * Returns: %GNUTLS_E_SUCCESS (0) on success, or a negative error code. + * + * Since: 3.1 + **/ +int gnutls_dtls_set_data_mtu (gnutls_session_t session, unsigned int mtu) +{ + int blocksize; + int overhead = _gnutls_record_overhead_rt(session, &blocksize); + + /* You can't call this until the session is actually running */ + if (overhead < 0) + return GNUTLS_E_INVALID_SESSION; + + /* Add the overhead inside the encrypted part */ + mtu += overhead; + + /* Round it up to the next multiple of blocksize */ + mtu += blocksize - 1; + mtu -= mtu % blocksize; + + /* Add the *unencrypted header size */ + mtu += RECORD_HEADER_SIZE(session); + + gnutls_dtls_set_mtu(session, mtu); + return GNUTLS_E_SUCCESS; +} + +/** * gnutls_dtls_get_mtu: * @session: is a #gnutls_session_t structure. * diff --git a/lib/includes/gnutls/dtls.h b/lib/includes/gnutls/dtls.h index f65c0092e7..909f0d3885 100644 --- a/lib/includes/gnutls/dtls.h +++ b/lib/includes/gnutls/dtls.h @@ -44,6 +44,7 @@ unsigned int gnutls_dtls_get_mtu (gnutls_session_t session); unsigned int gnutls_dtls_get_data_mtu (gnutls_session_t session); void gnutls_dtls_set_mtu (gnutls_session_t session, unsigned int mtu); +int gnutls_dtls_set_data_mtu (gnutls_session_t session, unsigned int mtu); unsigned int gnutls_dtls_get_timeout (gnutls_session_t session); diff --git a/lib/libgnutls.map b/lib/libgnutls.map index 108c765808..1078a07680 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -691,6 +691,7 @@ GNUTLS_3_0_0 { gnutls_dtls_cookie_send; gnutls_dtls_prestate_set; gnutls_dtls_get_data_mtu; + gnutls_dtls_set_data_mtu; gnutls_cipher_set_iv; gnutls_pcert_deinit; gnutls_pcert_import_x509; |