Subject: Re: [PATCH net-next 1/7] net-timestamp: explicit SO_TIMESTAMPING ancillary data struct

From: Richard Cochran <[email-masked]>
Date: Wed, 25 Jun 2014 06:56:08 +0200

On Tue, Jun 24, 2014 at 11:43:46AM -0400, Willem de Bruijn wrote:

> The code is backward compatible with legacy applications that treat
> the ancillary data as an anonymous array 'struct timespec data[3]'.
> It will break applications that test the size of the cmsg data.

I think this introduces an unacceptable ABI change.
In linuxptp we have

		if (SOL_SOCKET == level && SO_TIMESTAMPING == type) {
			if (cm->cmsg_len < sizeof(*ts) * 3) {
				pr_warning("short SO_TIMESTAMPING message");
				return -1;
			}
			ts = (struct timespec *) CMSG_DATA(cm);
		}

but other applications might barf if the length isn't exactly right.

> +/**
> + *	struct sock_errqueue_timestamping - timestamps exposed through cmsg
> + *
> + *	The timestamping interfaces SO_TIMESTAMPING, MSG_TSTAMP_*
> + *	communicate network timestamps to userspace by passing this struct
> + *	through a cmsg in recvmsg().
> + *
> + *	@ts_sw:     the sw timestamp: the contents depends on ts_type.

This would overload the field. I don't like that.

> + *	@ts_hw_sys: a hardware generated timestamp converted to system time.
> + *	@ts_hw_raw: a hardware generated timestamp converted in its raw format.
> + *	@ts_type:   the type of timestamp ts_sw. One of SCM_TSTAMP_*
> + *	@ts_key:    socket flow index that the timestamps correspond to
> + *		    (stream transport protocols only, e.g., TCP seqno)
> + *
> + *	The first three fields are dictated by historical use. The hardware
> + *	timestamps are empty unless hardware timestamping is enabled, but
> + *	they have to be present in each message.
> + */
> +struct sock_errqueue_timestamping {
> +	struct timespec ts_sw;
> +	struct timespec ts_hw_sys;
> +	struct timespec ts_hw_raw;
> +	__u32 ts_key;
> +	__u16 ts_type;
> +	__u16 ts_padding;
> +};
> +
> +enum {
> +	SCM_TSTAMP_SND = 1,
> +	SCM_TSTAMP_ACK = 2,
> +	SCM_TSTAMP_ENQ = 3
> +};

So why not simply introduce a new kind of CMSG for these new time
stamps? It appears that the use case for these is totally different
than for SO_TIMESTAMPING. I can't imagine why you would want to mix
them together.

Thanks,
Richard