From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from c.mail.sonic.net (c.mail.sonic.net [64.142.111.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id 4885A3B29E; Sun, 20 Jun 2021 16:08:39 -0400 (EDT) Received: from 107-137-68-211.lightspeed.sntcca.sbcglobal.net (107-137-68-211.lightspeed.sntcca.sbcglobal.net [107.137.68.211]) (authenticated bits=0) by c.mail.sonic.net (8.15.1/8.15.1) with ESMTPSA id 15KK8X1N016630 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 20 Jun 2021 13:08:33 -0700 Received: from hgm (localhost [IPv6:::1]) by 107-137-68-211.lightspeed.sntcca.sbcglobal.net (Postfix) with ESMTP id 1AC6A28C157; Sun, 20 Jun 2021 13:08:33 -0700 (PDT) X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.7.1 To: Matt Mathis cc: Dave Taht , bloat , Cake List , cerowrt-devel , Hal Murray From: Hal Murray In-Reply-To: Message from Matt Mathis of "Sat, 19 Jun 2021 18:59:06 -0700." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 20 Jun 2021 13:08:33 -0700 Message-Id: <20210620200833.1AC6A28C157@107-137-68-211.lightspeed.sntcca.sbcglobal.net> X-Sonic-CAuth: UmFuZG9tSVaFWIGgVepw14eBXH8lftW3NSYGnQ2cVBPXOxeP2kaueihYXvRlM0J6VJYUJ7YZ+gaVDNJjXmKEsp69kQjy1SB5PGpyPcNGd8Y= X-Sonic-ID: C;OkT3SQPS6xG+yZ3Pl+vPsg== M;iKopSgPS6xG+yZ3Pl+vPsg== X-Spam-Flag: No X-Sonic-Spam-Details: -1.5/5.0 by cerberusd Subject: Re: [Bloat] [Cake] access to cmsg from go? X-BeenThere: bloat@lists.bufferbloat.net X-Mailman-Version: 2.1.20 Precedence: list List-Id: General list for discussing Bufferbloat List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jun 2021 20:08:39 -0000 > Is there running code in C? Yes. The NTPsec code is full of #ifdef kludgery. The C API started with SO_TIMESTAMP for microsecond precision then added SO_TIMESTAMPNS for nanosecond precision: timeval vs timespec There is also SO_TIMESTAMPNS vs SCM_TIMESTAMPNS The basic idea is to use recvmsg rather than recv. In addition to the data buffer, you feed it another buffer where it can put meta data like timestamps. Then you have to scan that buffer to find the part you want. Both buffers are passed to the kernel via a single msghdr parameter (which also has a pointer for the addr you get via recvfrom). Details are in man recvmsg and man cmsg I thought they were reasonably clear. Without the ifdefs: You have to start by using setsockopt to turn on SO_TIMESTAMPNS. setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPNS, (const void *)&on, sizeof(on))); The setup code for recvmsg: struct msghdr msghdr; struct iovec iovec; char control[100]; /* FIXME: Need space for time stamp plus overhead */ iovec.iov_base = &rb->recv_buffer; iovec.iov_len = sizeof(rb->recv_buffer); memset(&msghdr, '\0', sizeof(msghdr)); msghdr.msg_name = &rb->recv_srcadr; msghdr.msg_namelen = fromlen; msghdr.msg_iov = &iovec; msghdr.msg_iovlen = 1; msghdr.msg_flags = 0; msghdr.msg_control = (void *)&control; msghdr.msg_controllen = sizeof(control); The actual call: buflen = recvmsg(fd, &msghdr, 0); The extract code: struct timespec * tsp; cmsghdr = CMSG_FIRSTHDR(msghdr); if (NULL == cmsghdr) { extra checking because this code is in a subroutine error } if (SCM_TIMESTAMPNS != cmsghdr->cmsg_type) { There is only one -- no need to loop error } tsp = (struct timespec *)CMSG_DATA(cmsghdr); Actual code is in: read_network_packet in ntpd/ntp_io.c https://gitlab.com/NTPsec/ntpsec/-/blob/master/ntpd/ntp_io.c and fetch_packetstamp() in ntpd/ntp_packetstamp.c https://gitlab.com/NTPsec/ntpsec/-/blob/master/ntpd/ntp_packetstamp.c -- These are my opinions. I hate spam.