Subversion Repositories HelenOS

Rev

Rev 4724 | Rev 4731 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4724 Rev 4728
Line 120... Line 120...
120
 
120
 
121
/** IP packet maximum content length.
121
/** IP packet maximum content length.
122
 */
122
 */
123
#define IP_MAX_CONTENT                  65535
123
#define IP_MAX_CONTENT                  65535
124
 
124
 
125
/** Returns the actual IP header length.
-
 
126
 *  @param header The IP packet header. Input parameter.
-
 
127
 */
-
 
128
#define IP_HEADER_LENGTH( header )      (( header )->ihl * 4u )
-
 
129
 
-
 
130
/** Returns the actual IP packet total length.
-
 
131
 *  @param header The IP packet header. Input parameter.
-
 
132
 */
-
 
133
#define IP_TOTAL_LENGTH( header )       ntohs(( header )->total_length )
-
 
134
 
-
 
135
/** Returns the actual IP packet data length.
-
 
136
 *  @param header The IP packet header. Input parameter.
-
 
137
 */
-
 
138
#define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header ))
-
 
139
 
-
 
140
/** Returns the IP packet header checksum.
-
 
141
 *  @param header The IP packet header. Input parameter.
-
 
142
 */
-
 
143
#define IP_HEADER_CHECKSUM( header )    ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header ))))
-
 
144
 
-
 
145
/** Returns the fragment offest.
-
 
146
 *  @param length The prefixed data total length. Input parameter.
-
 
147
 */
-
 
148
#define IP_FRAGMENT_OFFSET( length ) (( length ) / 8 )
-
 
149
 
-
 
150
/** The IP localhost address.
125
/** The IP localhost address.
151
 */
126
 */
152
#define IPV4_LOCALHOST_ADDRESS  htonl(( 127 << 24 ) + 1 )
127
#define IPV4_LOCALHOST_ADDRESS  htonl(( 127 << 24 ) + 1 )
153
 
128
 
154
/** IP global data.
129
/** IP global data.
Line 704... Line 679...
704
            middle_header = ( ip_header_ref ) packet_prefix( next, IP_HEADER_LENGTH( last_header ));
679
            middle_header = ( ip_header_ref ) packet_prefix( next, IP_HEADER_LENGTH( last_header ));
705
            if( ! middle_header ) return ENOMEM;
680
            if( ! middle_header ) return ENOMEM;
706
            memcpy( middle_header, last_header, IP_HEADER_LENGTH( last_header ));
681
            memcpy( middle_header, last_header, IP_HEADER_LENGTH( last_header ));
707
            header->flags |= IPFLAG_MORE_FRAGMENTS;
682
            header->flags |= IPFLAG_MORE_FRAGMENTS;
708
            middle_header->total_length = htons( packet_get_data_length( next ));
683
            middle_header->total_length = htons( packet_get_data_length( next ));
709
            middle_header->fragment_offset = IP_FRAGMENT_OFFSET( length );
684
            middle_header->fragment_offset = IP_COMPUTE_FRAGMENT_OFFSET( length );
710
            middle_header->header_checksum = IP_HEADER_CHECKSUM( middle_header );
685
            middle_header->header_checksum = IP_HEADER_CHECKSUM( middle_header );
711
            if( destination ){
686
            if( destination ){
712
                ERROR_PROPAGATE( packet_set_addr( next, NULL, ( uint8_t * ) destination->value, CONVERT_SIZE( char, uint8_t, destination->length )));
687
                ERROR_PROPAGATE( packet_set_addr( next, NULL, ( uint8_t * ) destination->value, CONVERT_SIZE( char, uint8_t, destination->length )));
713
            }
688
            }
714
            length += packet_get_data_length( next );
689
            length += packet_get_data_length( next );
Line 716... Line 691...
716
        }
691
        }
717
        middle_header = ( ip_header_ref ) packet_prefix( next, IP_HEADER_LENGTH( last_header ));
692
        middle_header = ( ip_header_ref ) packet_prefix( next, IP_HEADER_LENGTH( last_header ));
718
        if( ! middle_header ) return ENOMEM;
693
        if( ! middle_header ) return ENOMEM;
719
        memcpy( middle_header, last_header, IP_HEADER_LENGTH( last_header ));
694
        memcpy( middle_header, last_header, IP_HEADER_LENGTH( last_header ));
720
        middle_header->total_length = htons( packet_get_data_length( next ));
695
        middle_header->total_length = htons( packet_get_data_length( next ));
721
        middle_header->fragment_offset = IP_FRAGMENT_OFFSET( length );
696
        middle_header->fragment_offset = IP_COMPUTE_FRAGMENT_OFFSET( length );
722
        middle_header->header_checksum = IP_HEADER_CHECKSUM( middle_header );
697
        middle_header->header_checksum = IP_HEADER_CHECKSUM( middle_header );
723
        if( destination ){
698
        if( destination ){
724
            ERROR_PROPAGATE( packet_set_addr( next, NULL, ( uint8_t * ) destination->value, CONVERT_SIZE( char, uint8_t, destination->length )));
699
            ERROR_PROPAGATE( packet_set_addr( next, NULL, ( uint8_t * ) destination->value, CONVERT_SIZE( char, uint8_t, destination->length )));
725
        }
700
        }
726
        length += packet_get_data_length( next );
701
        length += packet_get_data_length( next );
Line 1031... Line 1006...
1031
    // copy first itself
1006
    // copy first itself
1032
    memcpy( last, first, sizeof( ip_header_t ));
1007
    memcpy( last, first, sizeof( ip_header_t ));
1033
    length = sizeof( ip_header_t );
1008
    length = sizeof( ip_header_t );
1034
    next = sizeof( ip_header_t );
1009
    next = sizeof( ip_header_t );
1035
    // process all ip options
1010
    // process all ip options
1036
    while( next < first->ihl ){
1011
    while( next < first->header_length ){
1037
        option = ( ip_option_ref ) ((( uint8_t * ) first ) + next );
1012
        option = ( ip_option_ref ) ((( uint8_t * ) first ) + next );
1038
        // skip end or noop
1013
        // skip end or noop
1039
        if(( option->type == IPOPT_END ) || ( option->type == IPOPT_NOOP )){
1014
        if(( option->type == IPOPT_END ) || ( option->type == IPOPT_NOOP )){
1040
            ++ next;
1015
            ++ next;
1041
        }else{
1016
        }else{
Line 1049... Line 1024...
1049
        }
1024
        }
1050
    }
1025
    }
1051
    // align 4 byte boundary
1026
    // align 4 byte boundary
1052
    if( length % 4 ){
1027
    if( length % 4 ){
1053
        bzero((( uint8_t * ) last ) + length, 4 - ( length % 4 ));
1028
        bzero((( uint8_t * ) last ) + length, 4 - ( length % 4 ));
1054
        last->ihl = length / 4 + 1;
1029
        last->header_length = length / 4 + 1;
1055
    }else{
1030
    }else{
1056
        last->ihl = length / 4;
1031
        last->header_length = length / 4;
1057
    }
1032
    }
1058
    last->header_checksum = 0;
1033
    last->header_checksum = 0;
1059
}
1034
}
1060
 
1035
 
1061
int ip_receive_message( device_id_t device_id, packet_t packet ){
1036
int ip_receive_message( device_id_t device_id, packet_t packet ){