2017-11-01 21:08:43 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
2009-02-12 12:03:36 +07:00
|
|
|
/*
|
|
|
|
* Userspace API for hardware time stamping of network packets
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008,2009 Intel Corporation
|
|
|
|
* Author: Patrick Ohly <patrick.ohly@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NET_TIMESTAMPING_H
|
|
|
|
#define _NET_TIMESTAMPING_H
|
|
|
|
|
2017-05-19 22:52:38 +07:00
|
|
|
#include <linux/types.h>
|
2009-02-12 12:03:36 +07:00
|
|
|
#include <linux/socket.h> /* for SO_TIMESTAMPING */
|
|
|
|
|
|
|
|
/* SO_TIMESTAMPING gets an integer bit field comprised of these values */
|
|
|
|
enum {
|
|
|
|
SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
|
|
|
|
SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1),
|
|
|
|
SOF_TIMESTAMPING_RX_HARDWARE = (1<<2),
|
|
|
|
SOF_TIMESTAMPING_RX_SOFTWARE = (1<<3),
|
|
|
|
SOF_TIMESTAMPING_SOFTWARE = (1<<4),
|
|
|
|
SOF_TIMESTAMPING_SYS_HARDWARE = (1<<5),
|
|
|
|
SOF_TIMESTAMPING_RAW_HARDWARE = (1<<6),
|
2014-08-05 09:11:47 +07:00
|
|
|
SOF_TIMESTAMPING_OPT_ID = (1<<7),
|
2014-08-05 09:11:48 +07:00
|
|
|
SOF_TIMESTAMPING_TX_SCHED = (1<<8),
|
2014-08-05 09:11:50 +07:00
|
|
|
SOF_TIMESTAMPING_TX_ACK = (1<<9),
|
net-timestamp: allow reading recv cmsg on errqueue with origin tstamp
Allow reading of timestamps and cmsg at the same time on all relevant
socket families. One use is to correlate timestamps with egress
device, by asking for cmsg IP_PKTINFO.
on AF_INET sockets, call the relevant function (ip_cmsg_recv). To
avoid changing legacy expectations, only do so if the caller sets a
new timestamping flag SOF_TIMESTAMPING_OPT_CMSG.
on AF_INET6 sockets, IPV6_PKTINFO and all other recv cmsg are already
returned for all origins. only change is to set ifindex, which is
not initialized for all error origins.
In both cases, only generate the pktinfo message if an ifindex is
known. This is not the case for ACK timestamps.
The difference between the protocol families is probably a historical
accident as a result of the different conditions for generating cmsg
in the relevant ip(v6)_recv_error function:
ipv4: if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) {
ipv6: if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
At one time, this was the same test bar for the ICMP/ICMP6
distinction. This is no longer true.
Signed-off-by: Willem de Bruijn <willemb@google.com>
----
Changes
v1 -> v2
large rewrite
- integrate with existing pktinfo cmsg generation code
- on ipv4: only send with new flag, to maintain legacy behavior
- on ipv6: send at most a single pktinfo cmsg
- on ipv6: initialize fields if not yet initialized
The recv cmsg interfaces are also relevant to the discussion of
whether looping packet headers is problematic. For v6, cmsgs that
identify many headers are already returned. This patch expands
that to v4. If it sounds reasonable, I will follow with patches
1. request timestamps without payload with SOF_TIMESTAMPING_OPT_TSONLY
(http://patchwork.ozlabs.org/patch/366967/)
2. sysctl to conditionally drop all timestamps that have payload or
cmsg from users without CAP_NET_RAW.
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-12-01 10:22:34 +07:00
|
|
|
SOF_TIMESTAMPING_OPT_CMSG = (1<<10),
|
2015-01-31 01:29:31 +07:00
|
|
|
SOF_TIMESTAMPING_OPT_TSONLY = (1<<11),
|
2016-11-28 14:07:18 +07:00
|
|
|
SOF_TIMESTAMPING_OPT_STATS = (1<<12),
|
2017-05-19 22:52:38 +07:00
|
|
|
SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
|
2017-05-19 22:52:40 +07:00
|
|
|
SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
|
2014-08-05 09:11:47 +07:00
|
|
|
|
2017-05-19 22:52:40 +07:00
|
|
|
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
|
2014-08-05 09:11:47 +07:00
|
|
|
SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
|
|
|
|
SOF_TIMESTAMPING_LAST
|
2009-02-12 12:03:36 +07:00
|
|
|
};
|
|
|
|
|
2016-04-03 10:08:09 +07:00
|
|
|
/*
|
|
|
|
* SO_TIMESTAMPING flags are either for recording a packet timestamp or for
|
|
|
|
* reporting the timestamp to user space.
|
|
|
|
* Recording flags can be set both via socket options and control messages.
|
|
|
|
*/
|
|
|
|
#define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | \
|
|
|
|
SOF_TIMESTAMPING_TX_SOFTWARE | \
|
|
|
|
SOF_TIMESTAMPING_TX_SCHED | \
|
|
|
|
SOF_TIMESTAMPING_TX_ACK)
|
|
|
|
|
2009-02-12 12:03:36 +07:00
|
|
|
/**
|
2013-11-14 08:19:29 +07:00
|
|
|
* struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
|
2009-02-12 12:03:36 +07:00
|
|
|
*
|
2013-11-14 08:19:29 +07:00
|
|
|
* @flags: no flags defined right now, must be zero for %SIOCSHWTSTAMP
|
2009-02-12 12:03:36 +07:00
|
|
|
* @tx_type: one of HWTSTAMP_TX_*
|
2013-11-14 08:05:58 +07:00
|
|
|
* @rx_filter: one of HWTSTAMP_FILTER_*
|
2009-02-12 12:03:36 +07:00
|
|
|
*
|
2013-11-14 08:19:29 +07:00
|
|
|
* %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a
|
|
|
|
* ifr_data pointer to this structure. For %SIOCSHWTSTAMP, if the
|
|
|
|
* driver or hardware does not support the requested @rx_filter value,
|
|
|
|
* the driver may use a more general filter mode. In this case
|
|
|
|
* @rx_filter will indicate the actual mode on return.
|
2009-02-12 12:03:36 +07:00
|
|
|
*/
|
|
|
|
struct hwtstamp_config {
|
|
|
|
int flags;
|
|
|
|
int tx_type;
|
|
|
|
int rx_filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* possible values for hwtstamp_config->tx_type */
|
2011-10-20 04:00:35 +07:00
|
|
|
enum hwtstamp_tx_types {
|
2009-02-12 12:03:36 +07:00
|
|
|
/*
|
|
|
|
* No outgoing packet will need hardware time stamping;
|
|
|
|
* should a packet arrive which asks for it, no hardware
|
|
|
|
* time stamping will be done.
|
|
|
|
*/
|
|
|
|
HWTSTAMP_TX_OFF,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enables hardware time stamping for outgoing packets;
|
|
|
|
* the sender of the packet decides which are to be
|
|
|
|
* time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
|
|
|
|
* before sending the packet.
|
|
|
|
*/
|
|
|
|
HWTSTAMP_TX_ON,
|
2011-09-20 08:43:15 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enables time stamping for outgoing packets just as
|
|
|
|
* HWTSTAMP_TX_ON does, but also enables time stamp insertion
|
|
|
|
* directly into Sync packets. In this case, transmitted Sync
|
|
|
|
* packets will not received a time stamp via the socket error
|
|
|
|
* queue.
|
|
|
|
*/
|
|
|
|
HWTSTAMP_TX_ONESTEP_SYNC,
|
2009-02-12 12:03:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* possible values for hwtstamp_config->rx_filter */
|
2011-10-20 04:00:35 +07:00
|
|
|
enum hwtstamp_rx_filters {
|
2009-02-12 12:03:36 +07:00
|
|
|
/* time stamp no incoming packet at all */
|
|
|
|
HWTSTAMP_FILTER_NONE,
|
|
|
|
|
|
|
|
/* time stamp any incoming packet */
|
|
|
|
HWTSTAMP_FILTER_ALL,
|
|
|
|
|
|
|
|
/* return value: time stamp all packets requested plus some others */
|
|
|
|
HWTSTAMP_FILTER_SOME,
|
|
|
|
|
|
|
|
/* PTP v1, UDP, any kind of event packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
|
|
|
|
/* PTP v1, UDP, Sync packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V1_L4_SYNC,
|
|
|
|
/* PTP v1, UDP, Delay_req packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ,
|
|
|
|
/* PTP v2, UDP, any kind of event packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_L4_EVENT,
|
|
|
|
/* PTP v2, UDP, Sync packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_L4_SYNC,
|
|
|
|
/* PTP v2, UDP, Delay_req packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ,
|
|
|
|
|
|
|
|
/* 802.AS1, Ethernet, any kind of event packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_L2_EVENT,
|
|
|
|
/* 802.AS1, Ethernet, Sync packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_L2_SYNC,
|
|
|
|
/* 802.AS1, Ethernet, Delay_req packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ,
|
|
|
|
|
|
|
|
/* PTP v2/802.AS1, any layer, any kind of event packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_EVENT,
|
|
|
|
/* PTP v2/802.AS1, any layer, Sync packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_SYNC,
|
|
|
|
/* PTP v2/802.AS1, any layer, Delay_req packet */
|
|
|
|
HWTSTAMP_FILTER_PTP_V2_DELAY_REQ,
|
2017-05-19 22:52:35 +07:00
|
|
|
|
|
|
|
/* NTP, UDP, all versions and packet modes */
|
|
|
|
HWTSTAMP_FILTER_NTP_ALL,
|
2009-02-12 12:03:36 +07:00
|
|
|
};
|
|
|
|
|
2017-05-19 22:52:38 +07:00
|
|
|
/* SCM_TIMESTAMPING_PKTINFO control message */
|
|
|
|
struct scm_ts_pktinfo {
|
|
|
|
__u32 if_index;
|
|
|
|
__u32 pkt_length;
|
|
|
|
__u32 reserved[2];
|
|
|
|
};
|
|
|
|
|
2018-07-04 05:42:48 +07:00
|
|
|
/*
|
|
|
|
* SO_TXTIME gets a struct sock_txtime with flags being an integer bit
|
|
|
|
* field comprised of these values.
|
|
|
|
*/
|
|
|
|
enum txtime_flags {
|
|
|
|
SOF_TXTIME_DEADLINE_MODE = (1 << 0),
|
2018-07-04 05:43:00 +07:00
|
|
|
SOF_TXTIME_REPORT_ERRORS = (1 << 1),
|
2018-07-04 05:42:48 +07:00
|
|
|
|
2018-07-04 05:43:00 +07:00
|
|
|
SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS,
|
|
|
|
SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) |
|
|
|
|
SOF_TXTIME_FLAGS_LAST
|
2018-07-04 05:42:48 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sock_txtime {
|
2018-12-17 17:26:38 +07:00
|
|
|
__kernel_clockid_t clockid;/* reference clockid */
|
|
|
|
__u32 flags; /* as defined by enum txtime_flags */
|
2018-07-04 05:42:48 +07:00
|
|
|
};
|
|
|
|
|
2009-02-12 12:03:36 +07:00
|
|
|
#endif /* _NET_TIMESTAMPING_H */
|