228,10 → 228,18 |
* Sets the message type and code and computes the checksum. |
* Error messages are sent only if allowed in the configuration. |
* Releases the packet on errors. |
* @param type The message type. Input parameter. |
* @param code The message code. Input parameter. |
* @param packet The message packet to be sent. Input parameter. |
* @param header The ICMP header. Input parameter. |
* @param error The error service to be announced. Should be SERVICE_ICMP or zero (0). Input parametr. |
* @param ttl The time to live. Input parameter. |
* @param tos The type of service. Input parameter. |
* @param dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery. Input parameter. |
* @returns EOK on success. |
* @returns EPERM if the error message is not allowed. |
*/ |
int icmp_send_packet( icmp_type_t type, icmp_code_t code, packet_t packet, icmp_header_ref header, services_t error ); |
int icmp_send_packet( icmp_type_t type, icmp_code_t code, packet_t packet, icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment ); |
|
/** Tries to set the pending reply result as the received message type. |
* If the reply data are still present, the reply timeouted and the parent fibril is awaken. |
404,7 → 412,7 |
fibril_rwlock_write_unlock( & icmp_globals.lock ); |
|
// send the request |
icmp_send_packet( ICMP_ECHO, 0, packet, header, 0 ); |
icmp_send_packet( ICMP_ECHO, 0, packet, header, 0, ttl, tos, dont_fragment ); |
|
// wait for a reply |
fibril_condvar_wait( & reply->condvar, & reply->mutex ); |
428,7 → 436,7 |
if( mtu ){ |
header->un.frag.mtu = mtu; |
} |
return icmp_send_packet( ICMP_DEST_UNREACH, code, packet, header, SERVICE_ICMP ); |
return icmp_send_packet( ICMP_DEST_UNREACH, code, packet, header, SERVICE_ICMP, 0, 0, 0 ); |
} |
|
int icmp_source_quench_msg( int icmp_phone, packet_t packet ){ |
438,7 → 446,7 |
if( ! header ){ |
return icmp_release_and_return( packet, ENOMEM ); |
} |
return icmp_send_packet( ICMP_SOURCE_QUENCH, 0, packet, header, SERVICE_ICMP ); |
return icmp_send_packet( ICMP_SOURCE_QUENCH, 0, packet, header, SERVICE_ICMP, 0, 0, 0 ); |
} |
|
int icmp_time_exceeded_msg( int icmp_phone, icmp_code_t code, packet_t packet ){ |
448,7 → 456,7 |
if( ! header ){ |
return icmp_release_and_return( packet, ENOMEM ); |
} |
return icmp_send_packet( ICMP_TIME_EXCEEDED, code, packet, header, SERVICE_ICMP ); |
return icmp_send_packet( ICMP_TIME_EXCEEDED, code, packet, header, SERVICE_ICMP, 0, 0, 0 ); |
} |
|
int icmp_parameter_problem_msg( int icmp_phone, icmp_code_t code, icmp_param_t pointer, packet_t packet ){ |
459,7 → 467,7 |
return icmp_release_and_return( packet, ENOMEM ); |
} |
header->un.param.pointer = pointer; |
return icmp_send_packet( ICMP_PARAMETERPROB, code, packet, header, SERVICE_ICMP ); |
return icmp_send_packet( ICMP_PARAMETERPROB, code, packet, header, SERVICE_ICMP, 0, 0, 0 ); |
} |
|
icmp_header_ref icmp_prepare_packet( packet_t packet ){ |
482,7 → 490,7 |
return header; |
} |
|
int icmp_send_packet( icmp_type_t type, icmp_code_t code, packet_t packet, icmp_header_ref header, services_t error ){ |
int icmp_send_packet( icmp_type_t type, icmp_code_t code, packet_t packet, icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment ){ |
ERROR_DECLARE; |
|
// do not send an error if disabled |
493,7 → 501,7 |
header->code = code; |
header->checksum = 0; |
header->checksum = ICMP_CHECKSUM( header, packet_get_data_length( packet )); |
if( ERROR_OCCURRED( ip_client_prepare_packet( packet, IPPROTO_ICMP, 0, 0, 0, 0 ))){ |
if( ERROR_OCCURRED( ip_client_prepare_packet( packet, IPPROTO_ICMP, ttl, tos, dont_fragment, 0 ))){ |
return icmp_release_and_return( packet, ERROR_CODE ); |
} |
return ip_send_msg( icmp_globals.ip_phone, -1, packet, SERVICE_ICMP, error ); |
587,8 → 595,6 |
result = icmp_client_process_packet( packet, & type, & code, NULL, NULL ); |
if( result < 0 ) return result; |
length = ( size_t ) result; |
// TODO remove debug dump |
printf( "ICMP error %d (%d) in packet %d\n", type, code, packet_get_id( packet ) ); |
// remove the error header |
ERROR_PROPAGATE( packet_trim( packet, length, 0 )); |
break; |
639,7 → 645,7 |
// set both addresses to the source one (avoids the source address deletion before setting the destination one) |
&& ( packet_set_addr( packet, src, src, ( size_t ) addrlen ) == EOK )){ |
// send the reply |
icmp_send_packet( ICMP_ECHOREPLY, 0, packet, header, 0 ); |
icmp_send_packet( ICMP_ECHOREPLY, 0, packet, header, 0, 0, 0, 0 ); |
return EOK; |
}else{ |
return EINVAL; |