[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180528065701.dqdjbrqb34zfsfvo@unicorn.suse.cz>
Date: Mon, 28 May 2018 08:57:01 +0200
From: Michal Kubecek <mkubecek@...e.cz>
To: "Eric S. Raymond" <esr@...rsus.com>
Cc: netdev@...r.kernel.org
Subject: Re: Is it possible to get device information via CMSG?
On Sat, May 26, 2018 at 05:39:12AM -0400, Eric S. Raymond wrote:
> I'm trying to untangle some nasty code in the Mills implementation of
> NTP. I could simplify it a lot if there were a way to query a packet
> to find out the name of the network interface it arrived on. (At the
> moment the code has to iterate over all interfaces checking for
> traffic on each one just so it doesn't lose that information.)
>
> This seems like the kind of thing the CMSG macros are intended to
> support, but I can't find anywhere a specification of what cmsg_level
> and cmsg_type values are valid and what their semantics are.
>
> So I have two questions:
>
> 1. Is there a cmsg_level/cmsg_type combination that will return the
> name of the device the packet arrived through?
Not name directly, AFAIK, but you can set SOL_IP / IP_PKTINFO (or
SOL_IPV6 / IPV6_RECVPKTINFO) socket option and get IP_PKTINFO
(IPV6_PKTINFO) message with recvmsg(). This will tell you incoming
interface index so that you can look the name up. See ip(7) or ipv6(7)
for format of the message (struct ip_pktinfo, struct in6_pktinfo).
However, I suspect that userspace application is not really interested
in incoming interface name but rather in destination address of the
incoming packet which is also provided in IP_PKTINFO / IPV6_PKTINFO
message.
Michal Kubecek
Powered by blists - more mailing lists