diff options
author | lloyd <[email protected]> | 2012-08-10 20:43:46 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-08-10 20:43:46 +0000 |
commit | 9a54147358810875d73e7d022fbdfda175cdb2ae (patch) | |
tree | ab88081d8ab762c555c53700ffba640bc5912768 | |
parent | 52de604c02536ef2724aa99632bf50efa9d09294 (diff) |
Hooks for DTLS fragmentation
-rw-r--r-- | src/tls/tls_handshake_io.cpp | 36 | ||||
-rw-r--r-- | src/tls/tls_handshake_io.h | 8 |
2 files changed, 32 insertions, 12 deletions
diff --git a/src/tls/tls_handshake_io.cpp b/src/tls/tls_handshake_io.cpp index 6ff8f71e0..51f04acd6 100644 --- a/src/tls/tls_handshake_io.cpp +++ b/src/tls/tls_handshake_io.cpp @@ -258,29 +258,37 @@ Datagram_Handshake_IO::Handshake_Reassembly::message() const } std::vector<byte> -Datagram_Handshake_IO::format_w_seq(const std::vector<byte>& msg, - Handshake_Type type, - u16bit msg_sequence) const +Datagram_Handshake_IO::format_fragment(const std::vector<byte>& frag, + Handshake_Type type, + u16bit msg_len, + u16bit frag_offset, + u16bit msg_sequence) const { - std::vector<byte> send_buf(12 + msg.size()); - - const size_t buf_size = msg.size(); + std::vector<byte> send_buf(12 + frag.size()); send_buf[0] = type; - store_be24(&send_buf[1], buf_size); + store_be24(&send_buf[1], msg_len); store_be(msg_sequence, &send_buf[4]); - store_be24(&send_buf[6], 0); // fragment_offset - store_be24(&send_buf[9], buf_size); // fragment_length + store_be24(&send_buf[6], frag_offset); + store_be24(&send_buf[9], frag.size()); - copy_mem(&send_buf[12], &msg[0], msg.size()); + copy_mem(&send_buf[12], &frag[0], frag.size()); return send_buf; } std::vector<byte> +Datagram_Handshake_IO::format_w_seq(const std::vector<byte>& msg, + Handshake_Type type, + u16bit msg_sequence) const + { + return format_fragment(msg, type, msg.size(), 0, msg_sequence); + } + +std::vector<byte> Datagram_Handshake_IO::format(const std::vector<byte>& msg, Handshake_Type type) const { @@ -301,8 +309,12 @@ Datagram_Handshake_IO::send(const Handshake_Message& msg) const std::vector<byte> no_fragment = format_w_seq(msg_bits, msg.type(), m_out_message_seq); - // FIXME: fragment to mtu size if needed - m_writer.send(HANDSHAKE, no_fragment); + if(no_fragment.size() <= m_mtu) + m_writer.send(HANDSHAKE, no_fragment); + else + { + throw Internal_Error("Fragmentation required"); + } m_out_message_seq += 1; diff --git a/src/tls/tls_handshake_io.h b/src/tls/tls_handshake_io.h index e57f6926d..6b82ed95d 100644 --- a/src/tls/tls_handshake_io.h +++ b/src/tls/tls_handshake_io.h @@ -110,6 +110,13 @@ class Datagram_Handshake_IO : public Handshake_IO std::pair<Handshake_Type, std::vector<byte>> get_next_record(bool expecting_ccs) override; private: + std::vector<byte> format_fragment( + const std::vector<byte>& fragment, + Handshake_Type type, + u16bit msg_len, + u16bit frag_offset, + u16bit msg_sequence) const; + std::vector<byte> format_w_seq( const std::vector<byte>& handshake_msg, Handshake_Type handshake_type, @@ -142,6 +149,7 @@ class Datagram_Handshake_IO : public Handshake_IO std::map<u16bit, Handshake_Reassembly> m_messages; std::set<u16bit> m_ccs_epochs; + u16bit m_mtu = 320; u16bit m_in_message_seq = 0; u16bit m_out_message_seq = 0; Record_Writer& m_writer; |