bpf: obtain timestamps from controller via pkthdr if available

r325506 (3cf8254f1e) extended struct pkthdr to add packet timestamp in
mbuf(9) chain.  For example, cxgbe(4) and mlx5en(4) support this feature.
Use the timestamp for bpf(4) if it is available.

Reviewed by:	hselasky, kib, np
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36868
This commit is contained in:
Jung-uk Kim 2022-10-03 18:45:56 -04:00
parent 85b715baae
commit 56cdab3372

View File

@ -2265,6 +2265,7 @@ bpf_ts_quality(int tstype)
static int
bpf_gettime(struct bintime *bt, int tstype, struct mbuf *m)
{
struct timespec ts;
struct m_tag *tag;
int quality;
@ -2273,6 +2274,11 @@ bpf_gettime(struct bintime *bt, int tstype, struct mbuf *m)
return (quality);
if (m != NULL) {
if ((m->m_flags & (M_PKTHDR | M_TSTMP)) == (M_PKTHDR | M_TSTMP)) {
mbuf_tstmp2timespec(m, &ts);
timespec2bintime(&ts, bt);
return (BPF_TSTAMP_EXTERN);
}
tag = m_tag_locate(m, MTAG_BPF, MTAG_BPF_TIMESTAMP, NULL);
if (tag != NULL) {
*bt = *(struct bintime *)(tag + 1);