1Record Layer Design 2=================== 3 4This file provides some guidance on the thinking behind the design of the 5record layer code to aid future maintenance. 6 7The record layer is divided into a number of components. At the time of writing 8there are four: SSL3_RECORD, SSL3_BUFFER, DLTS1_BITMAP and RECORD_LAYER. Each 9of these components is defined by: 101) A struct definition of the same name as the component 112) A set of source files that define the functions for that component 123) A set of accessor macros 13 14All struct definitions are in record.h. The functions and macros are either 15defined in record.h or record_local.h dependent on whether they are intended to 16be private to the record layer, or whether they form part of the API to the rest 17of libssl. 18 19The source files map to components as follows: 20 21 dtls1_bitmap.c -> DTLS1_BITMAP component 22 ssl3_buffer.c -> SSL3_BUFFER component 23 ssl3_record.c -> SSL3_RECORD component 24 rec_layer_s3.c, rec_layer_d1.c -> RECORD_LAYER component 25 26The RECORD_LAYER component is a facade pattern, i.e. it provides a simplified 27interface to the record layer for the rest of libssl. The other 3 components are 28entirely private to the record layer and therefore should never be accessed 29directly by libssl. 30 31Any component can directly access its own members - they are private to that 32component, e.g. ssl3_buffer.c can access members of the SSL3_BUFFER struct 33without using a macro. No component can directly access the members of another 34component, e.g. ssl3_buffer cannot reach inside the RECORD_LAYER component to 35directly access its members. Instead components use accessor macros, so if code 36in ssl3_buffer.c wants to access the members of the RECORD_LAYER it uses the 37RECORD_LAYER_* macros. 38 39Conceptually it looks like this: 40 41 libssl 42 | 43 -------------------------|-----record.h------------------------------------ 44 | 45 _______V______________ 46 | | 47 | RECORD_LAYER | 48 | | 49 | rec_layer_s3.c | 50 | ^ | 51 | _________|__________ | 52 || || 53 || DTLS1_RECORD_LAYER || 54 || || 55 || rec_layer_d1.c || 56 ||____________________|| 57 |______________________| 58 record_local.h ^ ^ ^ 59 _________________| | |_________________ 60 | | | 61 _____V_________ ______V________ _______V________ 62 | | | | | | 63 | SSL3_BUFFER | | SSL3_RECORD | | DTLS1_BITMAP | 64 | |--->| | | | 65 | ssl3_buffer.c | | ssl3_record.c | | dtls1_bitmap.c | 66 |_______________| |_______________| |________________| 67 68The two RECORD_LAYER source files build on each other, i.e. 69the main one is rec_layer_s3.c which provides the core SSL/TLS layer. The second 70one is rec_layer_d1.c which builds off of the SSL/TLS code to provide DTLS 71specific capabilities. It uses some DTLS specific RECORD_LAYER component members 72which should only be accessed from rec_layer_d1.c. These are held in the 73DTLS1_RECORD_LAYER struct. 74