[ipxe-devel] [PATCH 1/7] icmpv6: Decode error codes

Michael Brown mcb30 at ipxe.org
Fri Apr 24 16:52:07 UTC 2015


On 01/04/15 08:26, Hannes Reinecke wrote:
> diff --git a/src/net/icmpv6.c b/src/net/icmpv6.c
> index 45a3444..99e61ee 100644
> --- a/src/net/icmpv6.c
> +++ b/src/net/icmpv6.c
> @@ -148,8 +148,28 @@ static int icmpv6_rx ( struct io_buffer *iobuf, struct net_device *netdev,
>   	/* Identify handler */
>   	handler = icmpv6_handler ( icmp->type );
>   	if ( ! handler ) {
> -		DBGC ( netdev, "ICMPv6 unrecognised type %d\n", icmp->type );
> -		rc = -ENOTSUP;
> +		switch (icmp->type) {
> +		case 1:
> +			DBGC ( netdev, "ICMPv6 destination unreachable\n" );
> +			rc = -ENETUNREACH;
> +			break;
> +		case 2:
> +			DBGC ( netdev, "ICMPv6 packet too big\n" );
> +			rc = -EOVERFLOW;
> +			break;
> +		case 3:
> +			DBGC ( netdev, "ICMPv6 timer exceeded\n" );
> +			rc = -ETIME;
> +			break;
> +		case 4:
> +			DBGC ( netdev, "ICMPv6 parameter problem\n" );
> +			rc = -EINVAL;
> +			break;
> +		default:
> +			DBGC ( netdev, "ICMPv6 unrecognised type %d\n",
> +			       icmp->type );
> +			rc = -ENOTSUP;
> +		}
>   		goto done;
>   	}

This would be a perfect candidate for using EUNIQ() (which would avoid 
the need for the switch() and allow for reporting any number of ICMP 
error types without further increasing the code size).  See e.g. the use 
of EPROTO_STATUS() in crypto/ocsp.c for a reference implementation.

Thanks,

Michael



More information about the ipxe-devel mailing list