2017-11-01 22:08:43 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
2009-02-12 13:03:36 +08: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 23:52:38 +08:00
|
|
|
#include <linux/types.h>
|
2009-02-12 13:03:36 +08:00
|
|
|
#include <linux/socket.h> /* for SO_TIMESTAMPING */
|
|
|
|
|
2021-06-30 16:11:59 +08:00
|
|
|
/* SO_TIMESTAMPING flags */
|
2009-02-12 13:03:36 +08:00
|
|
|
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 10:11:47 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_ID = (1<<7),
|
2014-08-05 10:11:48 +08:00
|
|
|
SOF_TIMESTAMPING_TX_SCHED = (1<<8),
|
2014-08-05 10:11:50 +08: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 11:22:34 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_CMSG = (1<<10),
|
2015-01-31 02:29:31 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_TSONLY = (1<<11),
|
2016-11-28 15:07:18 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_STATS = (1<<12),
|
2017-05-19 23:52:38 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
|
2017-05-19 23:52:40 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
|
2021-06-30 16:11:59 +08:00
|
|
|
SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
|
2022-12-07 22:37:01 +08:00
|
|
|
SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16),
|
2014-08-05 10:11:47 +08:00
|
|
|
|
2022-12-07 22:37:01 +08:00
|
|
|
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_ID_TCP,
|
2014-08-05 10:11:47 +08:00
|
|
|
SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
|
|
|
|
SOF_TIMESTAMPING_LAST
|
2009-02-12 13:03:36 +08:00
|
|
|
};
|
|
|
|
|
2016-04-03 11:08:09 +08: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)
|
|
|
|
|
2021-06-30 16:11:59 +08:00
|
|
|
/**
|
|
|
|
* struct so_timestamping - SO_TIMESTAMPING parameter
|
|
|
|
*
|
|
|
|
* @flags: SO_TIMESTAMPING flags
|
|
|
|
* @bind_phc: Index of PTP virtual clock bound to sock. This is available
|
|
|
|
* if flag SOF_TIMESTAMPING_BIND_PHC is set.
|
|
|
|
*/
|
|
|
|
struct so_timestamping {
|
|
|
|
int flags;
|
|
|
|
int bind_phc;
|
|
|
|
};
|
|
|
|
|
2009-02-12 13:03:36 +08:00
|
|
|
/**
|
2013-11-14 09:19:29 +08:00
|
|
|
* struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
|
2009-02-12 13:03:36 +08:00
|
|
|
*
|
2021-12-10 16:59:58 +08:00
|
|
|
* @flags: one of HWTSTAMP_FLAG_*
|
2009-02-12 13:03:36 +08:00
|
|
|
* @tx_type: one of HWTSTAMP_TX_*
|
2013-11-14 09:05:58 +08:00
|
|
|
* @rx_filter: one of HWTSTAMP_FILTER_*
|
2009-02-12 13:03:36 +08:00
|
|
|
*
|
2013-11-14 09:19:29 +08: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 13:03:36 +08:00
|
|
|
*/
|
|
|
|
struct hwtstamp_config {
|
|
|
|
int flags;
|
|
|
|
int tx_type;
|
|
|
|
int rx_filter;
|
|
|
|
};
|
|
|
|
|
2021-12-10 16:59:58 +08:00
|
|
|
/* possible values for hwtstamp_config->flags */
|
|
|
|
enum hwtstamp_flags {
|
|
|
|
/*
|
|
|
|
* With this flag, the user could get bond active interface's
|
|
|
|
* PHC index. Note this PHC index is not stable as when there
|
|
|
|
* is a failover, the bond active interface will be changed, so
|
|
|
|
* will be the PHC index.
|
|
|
|
*/
|
|
|
|
HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0),
|
2021-12-29 16:09:37 +08:00
|
|
|
#define HWTSTAMP_FLAG_BONDED_PHC_INDEX HWTSTAMP_FLAG_BONDED_PHC_INDEX
|
2021-12-10 16:59:58 +08:00
|
|
|
|
|
|
|
HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX,
|
|
|
|
HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST
|
|
|
|
};
|
|
|
|
|
2009-02-12 13:03:36 +08:00
|
|
|
/* possible values for hwtstamp_config->tx_type */
|
2011-10-20 05:00:35 +08:00
|
|
|
enum hwtstamp_tx_types {
|
2009-02-12 13:03:36 +08: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 09:43:15 +08: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,
|
2019-12-26 10:16:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time
|
|
|
|
* stamp insertion directly into PDelay_Resp packets. In this
|
|
|
|
* case, neither transmitted Sync nor PDelay_Resp packets will
|
|
|
|
* receive a time stamp via the socket error queue.
|
|
|
|
*/
|
|
|
|
HWTSTAMP_TX_ONESTEP_P2P,
|
2020-03-28 07:01:53 +08:00
|
|
|
|
|
|
|
/* add new constants above here */
|
|
|
|
__HWTSTAMP_TX_CNT
|
2009-02-12 13:03:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* possible values for hwtstamp_config->rx_filter */
|
2011-10-20 05:00:35 +08:00
|
|
|
enum hwtstamp_rx_filters {
|
2009-02-12 13:03:36 +08: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 23:52:35 +08:00
|
|
|
|
|
|
|
/* NTP, UDP, all versions and packet modes */
|
|
|
|
HWTSTAMP_FILTER_NTP_ALL,
|
2020-03-28 07:01:53 +08:00
|
|
|
|
|
|
|
/* add new constants above here */
|
|
|
|
__HWTSTAMP_FILTER_CNT
|
2009-02-12 13:03:36 +08:00
|
|
|
};
|
|
|
|
|
2017-05-19 23:52:38 +08:00
|
|
|
/* SCM_TIMESTAMPING_PKTINFO control message */
|
|
|
|
struct scm_ts_pktinfo {
|
|
|
|
__u32 if_index;
|
|
|
|
__u32 pkt_length;
|
|
|
|
__u32 reserved[2];
|
|
|
|
};
|
|
|
|
|
2018-07-04 06:42:48 +08: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 06:43:00 +08:00
|
|
|
SOF_TXTIME_REPORT_ERRORS = (1 << 1),
|
2018-07-04 06:42:48 +08:00
|
|
|
|
2018-07-04 06:43:00 +08: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 06:42:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sock_txtime {
|
2018-12-17 18:26:38 +08:00
|
|
|
__kernel_clockid_t clockid;/* reference clockid */
|
|
|
|
__u32 flags; /* as defined by enum txtime_flags */
|
2018-07-04 06:42:48 +08:00
|
|
|
};
|
|
|
|
|
2009-02-12 13:03:36 +08:00
|
|
|
#endif /* _NET_TIMESTAMPING_H */
|