80,7 → 80,7 |
|
/** Minimum packet content length. |
*/ |
#define ETH_MIN_CONTENT 46 |
#define ETH_MIN_CONTENT 46u |
|
/** Maximum tagged packet content length. |
*/ |
381,10 → 381,11 |
|
eth_header_ex_ref header; |
size_t length; |
int type; |
eth_type_t type; |
size_t prefix; |
size_t suffix; |
eth_fcs_ref fcs; |
uint8_t * data; |
|
length = packet_get_data_length( packet ); |
if( IS_DUMMY( flags )){ |
391,13 → 392,15 |
packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
} |
if( length < sizeof( eth_header_t ) + ETH_MIN_CONTENT + ( IS_DUMMY( flags ) ? ETH_SUFFIX : 0 )) return NULL; |
header = ( eth_header_ex_ref ) packet_get_data( packet ); |
data = packet_get_data( packet ); |
header = ( eth_header_ex_ref ) data; |
type = ntohs( header->header.ethertype ); |
if( type >= ETH_MIN_PROTO ){ |
// DIX Ethernet |
prefix = sizeof( eth_header_t ); |
suffix = 0; |
fcs = (( void * ) header ) + length - sizeof( eth_fcs_t ); |
fcs = ( eth_fcs_ref ) data + length - sizeof( eth_fcs_t ); |
length -= sizeof( eth_fcs_t ); |
}else if( type <= ETH_MAX_CONTENT ){ |
// translate "LSAP" values |
if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
414,15 → 417,16 |
type = lsap_map( header->lsap.dsap ); |
prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t); |
} |
suffix = ( type < ETH_MIN_CONTENT ) ? ETH_MIN_CONTENT - type : 0; |
fcs = (( void * ) header ) + prefix + type + suffix; |
suffix = ( type < ETH_MIN_CONTENT ) ? ETH_MIN_CONTENT - type : 0u; |
fcs = ( eth_fcs_ref ) data + prefix + type + suffix; |
suffix += length - prefix - type; |
length = prefix + type + suffix; |
}else{ |
// invalid length/type, should not occurr |
return NULL; |
} |
if( IS_DUMMY( flags )){ |
if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
if(( ~ compute_crc32( ~ 0u, data, length * 8 )) != ntohl( * fcs )){ |
return NULL; |
} |
suffix += sizeof( eth_fcs_t ); |
541,14 → 545,14 |
eth_fcs_ref fcs; |
uint8_t * src; |
uint8_t * dest; |
int length; |
size_t length; |
int i; |
void * padding; |
eth_preamble_ref preamble; |
|
length = packet_get_addr( packet, & src, & dest ); |
if( length < 0 ) return length; |
if( length != ETH_ADDR ) return EINVAL; |
i = packet_get_addr( packet, & src, & dest ); |
if( i < 0 ) return i; |
if( i != ETH_ADDR ) return EINVAL; |
length = packet_get_data_length( packet ); |
if( length > mtu ) return EINVAL; |
if( length < ETH_MIN_TAGGED_CONTENT( flags )){ |
586,7 → 590,7 |
if( IS_DUMMY( flags )){ |
fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
if( ! fcs ) return ENOMEM; |
* fcs = htonl( ~ compute_crc32( ~ 0, src, ((( void * ) fcs ) - (( void * ) src )) * 8 )); |
* fcs = htonl( ~ compute_crc32( ~ 0u, src, length * 8 )); |
} |
return EOK; |
} |
679,10 → 683,10 |
if( ! ERROR_OCCURRED( packet_translate( eth_globals.net_phone, & packet, IPC_GET_PACKET( icall )))){ |
ERROR_CODE = nil_received_msg( 0, IPC_GET_DEVICE( icall ), packet, 0 ); |
} |
ipc_answer_0( iid, ERROR_CODE ); |
ipc_answer_0( iid, ( ipcarg_t ) ERROR_CODE ); |
break; |
default: |
ipc_answer_0( iid, ENOTSUP ); |
ipc_answer_0( iid, ( ipcarg_t ) ENOTSUP ); |
} |
iid = async_get_call( icall ); |
} |