1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #1302 from cgundogan/fix_tcp_header_data_offset

destiny: using a bit field for tcp_header->data_offset is more convenient
This commit is contained in:
Christian Mehlis 2014-06-14 15:40:49 +02:00
commit 997dcd7e88
4 changed files with 33 additions and 31 deletions

View File

@ -51,21 +51,22 @@ typedef struct __attribute__((packed)) {
* @see <a href="http://tools.ietf.org/html/rfc793">RFC 793</a>
*/
typedef struct __attribute__((packed)) {
uint16_t src_port; ///< source port
uint16_t dst_port; ///< destination port
uint32_t seq_nr; ///< sequence number
uint32_t ack_nr; ///< acknowledgement number
uint8_t dataOffset_reserved; ///< 4 MSBs data offsets,
///< 4 LSBs reserved (must be zero)
uint8_t reserved_flags; ///< MSB reserved, rest flags
uint16_t window; ///< receiver window
uint16_t src_port; ///< source port
uint16_t dst_port; ///< destination port
uint32_t seq_nr; ///< sequence number
uint32_t ack_nr; ///< acknowledgement number
uint8_t flag_ns :1; ///< ECN-nonce concealment protection (since RFC 3540).
uint8_t reserved :3; ///< for future use - set to zero
uint8_t data_offset :4;
uint8_t reserved_flags; ///< TODO: break this down into another bitfield: flag_fin, flag_syn, etc
uint16_t window; ///< receiver window
/**
* internet checksum
*
* @see <a href="http://tools.ietf.org/html/rfc1071">RFC 1071</a>
*/
uint16_t checksum;
uint16_t urg_pointer; ///< urgent pointer
uint16_t checksum;
uint16_t urg_pointer; ///< urgent pointer
} tcp_hdr_t;
/**

View File

@ -48,7 +48,7 @@ void set_socket_address(sockaddr6_t *sockaddr, sa_family_t sin6_family,
ipv6_addr_t *sin6_addr);
void set_tcp_packet(tcp_hdr_t *tcp_hdr, uint16_t src_port, uint16_t dst_port,
uint32_t seq_nr, uint32_t ack_nr,
uint8_t dataOffset_reserved, uint8_t reserved_flags,
uint8_t data_offset, uint8_t reserved_flags,
uint16_t window, uint16_t checksum, uint16_t urg_pointer);
void printf_tcp_context(tcp_hc_context_t *current_tcp_context)
@ -390,19 +390,21 @@ void set_socket_address(sockaddr6_t *sockaddr, uint8_t sin6_family,
}
void set_tcp_packet(tcp_hdr_t *tcp_hdr, uint16_t src_port, uint16_t dst_port,
uint32_t seq_nr, uint32_t ack_nr, uint8_t dataOffset_reserved,
uint32_t seq_nr, uint32_t ack_nr, uint8_t data_offset,
uint8_t reserved_flags, uint16_t window, uint16_t checksum,
uint16_t urg_pointer)
{
tcp_hdr->ack_nr = ack_nr;
tcp_hdr->checksum = checksum;
tcp_hdr->dataOffset_reserved = dataOffset_reserved;
tcp_hdr->dst_port = dst_port;
tcp_hdr->reserved_flags = reserved_flags;
tcp_hdr->seq_nr = seq_nr;
tcp_hdr->src_port = src_port;
tcp_hdr->urg_pointer = urg_pointer;
tcp_hdr->window = window;
tcp_hdr->ack_nr = ack_nr;
tcp_hdr->checksum = checksum;
tcp_hdr->data_offset = data_offset;
tcp_hdr->dst_port = dst_port;
tcp_hdr->reserved_flags = reserved_flags;
tcp_hdr->reserved = 0;
tcp_hdr->flag_ns = 0;
tcp_hdr->seq_nr = seq_nr;
tcp_hdr->src_port = src_port;
tcp_hdr->urg_pointer = urg_pointer;
tcp_hdr->window = window;
}
/* Check for consistent ACK and SEQ number */
@ -428,7 +430,7 @@ int check_tcp_consistency(socket_t *current_tcp_socket, tcp_hdr_t *tcp_header)
void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet)
{
if (current_tcp_packet->dataOffset_reserved * 4 > TCP_HDR_LEN) {
if (current_tcp_packet->data_offset * 4 > TCP_HDR_LEN) {
if (*(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN) == TCP_MSS_OPTION) {
uint8_t *packet_pointer = (uint8_t *)current_tcp_packet;
packet_pointer += (TCP_HDR_LEN + 2);
@ -621,7 +623,7 @@ int destiny_socket_connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
/* Got SYN ACK from Server */
/* Refresh foreign TCP socket information */
if ((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) &&
if ((tcp_header->data_offset * 4 > TCP_HDR_LEN) &&
(*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) {
current_tcp_socket->tcp_control.mss =
*((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2));
@ -1360,7 +1362,7 @@ socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header,
&ipv6_header->destaddr);
/* Foreign TCP information */
if ((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) &&
if ((tcp_header->data_offset * 4 > TCP_HDR_LEN) &&
(*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) {
current_queued_socket->socket_values.tcp_control.mss =
*((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2));

View File

@ -48,7 +48,7 @@ void printTCPHeader(tcp_hdr_t *tcp_header)
printf("\nBEGIN: TCP HEADER\n");
printf("ack_nr: %" PRIu32 "\n", tcp_header->ack_nr);
printf("checksum: %i\n", tcp_header->checksum);
printf("dataOffset_reserved: %i\n", tcp_header->dataOffset_reserved);
printf("data_offset: %i\n", tcp_header->data_offset);
printf("dst_port: %i\n", tcp_header->dst_port);
printf("reserved_flags: %i\n", tcp_header->reserved_flags);
printf("seq_nr: %" PRIu32 "\n", tcp_header->seq_nr);
@ -331,15 +331,14 @@ void tcp_packet_handler(void)
#endif
chksum = tcp_csum(ipv6_header, tcp_header);
payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN +
tcp_header->dataOffset_reserved * 4);
payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN + tcp_header->data_offset * 4);
if ((chksum == 0xffff) && (tcp_socket != NULL)) {
#ifdef TCP_HC
update_tcp_hc_context(true, tcp_socket, tcp_header);
#endif
/* Remove reserved bits from tcp flags field */
uint8_t tcp_flags = tcp_header->reserved_flags & REMOVE_RESERVED;
uint8_t tcp_flags = tcp_header->reserved_flags;
switch (tcp_flags) {
case TCP_ACK: {

View File

@ -90,7 +90,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
/* Move tcp packet 3 bytes to add padding and Context ID */
memmove(current_tcp_packet + 3, current_tcp_packet,
((((tcp_hdr_t *)current_tcp_packet)->dataOffset_reserved) * 4) +
((((tcp_hdr_t *)current_tcp_packet)->data_offset) * 4) +
payload_length);
/* 1 padding byte with value 0x01 to introduce full header TCP_HC
@ -102,7 +102,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket,
memcpy(current_tcp_packet + 1, &current_context, 2);
/* Return correct header length (+3) */
packet_size = ((((tcp_hdr_t *)(current_tcp_packet + 3))->dataOffset_reserved) * 4) + 3 +
packet_size = ((((tcp_hdr_t *)(current_tcp_packet + 3))->data_offset) * 4) + 3 +
payload_length;
/* Update the tcp context fields */
@ -616,7 +616,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
&current_socket->socket_values.foreign_address.sin6_port, 2);
/* Ordinary TCP header length */
full_tcp_header.dataOffset_reserved = TCP_HDR_LEN / 4;
full_tcp_header.data_offset = TCP_HDR_LEN / 4;
/* Move payload to end of tcp header */
memmove(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN + TCP_HDR_LEN,