Changeset 0743493a in mainline


Ignore:
Timestamp:
2011-05-28T19:48:29Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ce90544, 544a2e4
Parents:
7bf12387
git-author:
Jeff Rous <jeffrous@…> (2011-05-28 19:48:29)
git-committer:
Jakub Jermar <jakub@…> (2011-05-28 19:48:29)
Message:

tcp: Remove bit fields and use defines and bitwise ops instead.

Location:
uspace/srv/net/tl/tcp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/tcp/tcp.c

    r7bf12387 r0743493a  
    476476        old_incoming = socket_data->next_incoming;
    477477
    478         if (header->finalize) {
     478        if (GET_TCP_HEADER_FINALIZE(header)) {
    479479                socket_data->fin_incoming = new_sequence_number +
    480480                    total_length - TCP_HEADER_LENGTH(header);
     
    838838        assert(packet);
    839839
    840         if (!header->synchronize)
     840        if (!GET_TCP_HEADER_SYNCHRONIZE(header))
    841841                return tcp_release_and_return(packet, EINVAL);
    842842       
     
    903903        assert(packet);
    904904
    905         if (!header->synchronize)
     905        if (!GET_TCP_HEADER_SYNCHRONIZE(header))
    906906                return tcp_release_and_return(packet, EINVAL);
    907907
     
    10571057        assert(packet);
    10581058
    1059         if (!header->acknowledge)
     1059        if (!GET_TCP_HEADER_ACKNOWLEDGE(header))
    10601060                return tcp_release_and_return(packet, EINVAL);
    10611061
     
    11261126        assert(header);
    11271127
    1128         if (!header->acknowledge)
     1128        if (!GET_TCP_HEADER_ACKNOWLEDGE(header))
    11291129                return;
    11301130
     
    18331833
    18341834        /* Remember the outgoing FIN */
    1835         if (header->finalize)
     1835        if (GET_TCP_HEADER_FINALIZE(header))
    18361836                socket_data->fin_outgoing = socket_data->next_outgoing;
    18371837       
     
    19521952                header->acknowledgement_number =
    19531953                    htonl(socket_data->next_incoming);
    1954                 header->acknowledge = 1;
     1954                SET_TCP_HEADER_ACKNOWLEDGE(header, 1);
    19551955        }
    19561956        header->window = htons(socket_data->window);
     
    20242024        header->source_port = htons(socket->port);
    20252025        header->source_port = htons(socket_data->dest_port);
    2026         header->header_length = TCP_COMPUTE_HEADER_LENGTH(sizeof(*header));
    2027         header->synchronize = synchronize;
    2028         header->finalize = finalize;
     2026        SET_TCP_HEADER_LENGTH(header,
     2027            TCP_COMPUTE_HEADER_LENGTH(sizeof(*header)));
     2028        SET_TCP_HEADER_SYNCHRONIZE(header, synchronize);
     2029        SET_TCP_HEADER_FINALIZE(header, finalize);
    20292030}
    20302031
  • uspace/srv/net/tl/tcp/tcp_header.h

    r7bf12387 r0743493a  
    4747 * @param[in] header The TCP packet header.
    4848 */
    49 #define TCP_HEADER_LENGTH(header)               ((header)->header_length * 4U)
     49#define TCP_HEADER_LENGTH(header)               (GET_TCP_HEADER_LENGTH(header) * 4U)
    5050
    5151/** Returns the TCP header length.
     
    7373        uint32_t sequence_number;
    7474        uint32_t acknowledgement_number;
    75        
    76 #ifdef ARCH_IS_BIG_ENDIAN
    77         uint8_t header_length:4;
    78         uint8_t reserved1:4;
    79 #else
    80         uint8_t reserved1:4;
    81         uint8_t header_length:4;
    82 #endif
    8375
    84 #ifdef ARCH_IS_BIG_ENDIAN
    85         uint8_t reserved2:2;
    86         uint8_t urgent:1;
    87         uint8_t acknowledge:1;
    88         uint8_t push:1;
    89         uint8_t reset:1;
    90         uint8_t synchronize:1;
    91         uint8_t finalize:1;
    92 #else
    93         uint8_t finalize:1;
    94         uint8_t synchronize:1;
    95         uint8_t reset:1;
    96         uint8_t push:1;
    97         uint8_t acknowledge:1;
    98         uint8_t urgent:1;
    99         uint8_t reserved2:2;
    100 #endif
     76        uint8_t hlr; /* header length, reserved1 */
     77
     78#define GET_TCP_HEADER_LENGTH(header) \
     79        (((header)->hlr & 0xf0) >> 4)
     80#define SET_TCP_HEADER_LENGTH(header, length) \
     81        ((header)->hlr = \
     82         ((length & 0x0f) << 4) | ((header)->hlr & 0x0f))
     83
     84#define GET_TCP_HEADER_RESERVED1(header) \
     85        ((header)->hlr & 0x0f)
     86#define SET_TCP_HEADER_RESERVED1(header, reserved1) \
     87        ((header)->hlr = \
     88         (reserved1 & 0x0f) | ((header)->hlr & 0xf0))
     89
     90        /* reserved2, urgent, acknowledge, push, reset, synchronize, finalize */
     91        uint8_t ruaprsf; 
     92
     93#define GET_TCP_HEADER_RESERVED2(header) \
     94        (((header)->ruaprsf & 0xc0) >> 6)
     95#define SET_TCP_HEADER_RESERVED2(header, reserved2) \
     96        ((header)->ruaprsf = \
     97         ((reserved2 & 0x03) << 6) | ((header)->ruaprsf & 0x3f))
     98
     99#define GET_TCP_HEADER_URGENT(header) \
     100        (((header)->ruaprsf & 0x20) >> 5)
     101#define SET_TCP_HEADER_URGENT(header, urgent) \
     102        ((header)->ruaprsf = \
     103         ((urgent & 0x01) << 5) | ((header)->ruaprsf & 0xdf))
     104
     105#define GET_TCP_HEADER_ACKNOWLEDGE(header) \
     106        (((header)->ruaprsf & 0x10) >> 4)
     107#define SET_TCP_HEADER_ACKNOWLEDGE(header, acknowledge) \
     108        ((header)->ruaprsf = \
     109         ((acknowledge & 0x01) << 4) | ((header)->ruaprsf & 0xef))
     110
     111#define GET_TCP_HEADER_PUSH(header) \
     112        (((header)->ruaprsf & 0x08) >> 3)
     113#define SET_TCP_HEADER_PUSH(header, push) \
     114        ((header)->ruaprsf = \
     115         ((push & 0x01) << 3) | ((header)->ruaprsf & 0xf7))
     116
     117#define GET_TCP_HEADER_RESET(header) \
     118        (((header)->ruaprsf & 0x04) >> 2)
     119#define SET_TCP_HEADER_RESET(header, reset) \
     120        ((header)->ruaprsf = \
     121         ((reset & 0x01) << 2) | ((header)->ruaprsf & 0xfb))
     122
     123#define GET_TCP_HEADER_SYNCHRONIZE(header) \
     124        (((header)->ruaprsf & 0x02) >> 1)
     125#define SET_TCP_HEADER_SYNCHRONIZE(header, synchronize) \
     126        ((header)->ruaprsf = \
     127         ((synchronize & 0x01) << 1) | ((header)->ruaprsf & 0xfd))
     128
     129#define GET_TCP_HEADER_FINALIZE(header) \
     130        ((header)->ruaprsf & 0x01)
     131#define SET_TCP_HEADER_FINALIZE(header, finalize) \
     132        ((header)->ruaprsf = \
     133         (finalize & 0x01) | ((header)->ruaprsf & 0xfe))
    101134
    102135        uint16_t window;
Note: See TracChangeset for help on using the changeset viewer.