From: Willem de Bruijn <willemb@google.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, luto@amacapital.net,
richardcochran@gmail.com, Willem de Bruijn <willemb@google.com>
Subject: [PATCH rfc 2/4] net-errqueue: add IP(V6)_PKTINFO support
Date: Tue, 25 Nov 2014 12:58:04 -0500 [thread overview]
Message-ID: <1416938286-14147-3-git-send-email-willemb@google.com> (raw)
In-Reply-To: <1416938286-14147-1-git-send-email-willemb@google.com>
From: Willem de Bruijn <willemb@google.com>
On INET and INET6 sockets with the IP_PKTINFO or IPV6_RECVPKTINFO
socket option set, return a matching cmsg also for packets queued
to the error queue.
These packets are transmitted packets looped back. The fields of
struct in[6]_pktinfo are changed to reflect that:
ifindex: index of the outgoing device, if configured
addr: destination address
spec_dst: source address (absent in v6)
On IPv6, the mechanism currently returns two IPV6_PKTINFO when
the option is enabled, because the existing code already supports
the feature. The legacy data does not produce a correct ifindex,
however. Perhaps I can revise the patch to only send the legacy
patch, but use the correct ifindex source in case of ERRQUEUE.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
net/ipv4/ip_sockglue.c | 15 +++++++++++++++
net/ipv6/datagram.c | 22 ++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index b782657..615f783 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -399,6 +399,20 @@ void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 port, u32 inf
kfree_skb(skb);
}
+static void ip_recv_error_pktinfo(struct msghdr *msg, struct sock *sk,
+ struct sk_buff *skb)
+{
+ if (inet_sk(sk)->cmsg_flags & IP_CMSG_PKTINFO && skb->dev) {
+ struct in_pktinfo info = {0};
+
+ info.ipi_spec_dst.s_addr = ip_hdr(skb)->saddr;
+ info.ipi_addr.s_addr = ip_hdr(skb)->daddr;
+ info.ipi_ifindex = skb->dev->ifindex;
+
+ put_cmsg(msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
+ }
+}
+
/*
* Handle MSG_ERRQUEUE
*/
@@ -429,6 +443,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
goto out_free_skb;
sock_recv_timestamp(msg, sk, skb);
+ ip_recv_error_pktinfo(msg, sk, skb);
serr = SKB_EXT_ERR(skb);
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index cc11396..7d2ef7c 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -325,6 +325,27 @@ void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu)
kfree_skb(skb);
}
+static void ipv6_recv_error_pktinfo(struct msghdr *msg, struct sock *sk,
+ struct sk_buff *skb)
+{
+ struct ipv6_pinfo *np = inet6_sk(sk);
+
+ if (np->rxopt.bits.rxinfo && skb->dev) {
+ struct in6_pktinfo info;
+
+ memset(&info, 0, sizeof(info));
+ if (skb->protocol == htons(ETH_P_IPV6))
+ info.ipi6_addr = ipv6_hdr(skb)->daddr;
+ else
+ ipv6_addr_set_v4mapped(ip_hdr(skb)->daddr,
+ &info.ipi6_addr);
+
+ info.ipi6_ifindex = skb->dev->ifindex;
+ net_info_ratelimited("yes: ifindex=%d\n", info.ipi6_ifindex);
+ put_cmsg(msg, SOL_IPV6, IPV6_PKTINFO, sizeof(info), &info);
+ }
+}
+
/*
* Handle MSG_ERRQUEUE
*/
@@ -356,6 +377,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
goto out_free_skb;
sock_recv_timestamp(msg, sk, skb);
+ ipv6_recv_error_pktinfo(msg, sk, skb);
serr = SKB_EXT_ERR(skb);
--
2.1.0.rc2.206.gedb03e5
next prev parent reply other threads:[~2014-11-25 17:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 17:58 [PATCH rfc 0/4] timestamping updates Willem de Bruijn
2014-11-25 17:58 ` [PATCH rfc 1/4] net-timestamp: pull headers for SOCK_STREAM Willem de Bruijn
2014-11-25 18:42 ` David Miller
2014-11-25 19:52 ` Willem de Bruijn
2014-11-25 19:54 ` David Miller
2014-11-25 21:39 ` Andy Lutomirski
2014-11-26 21:03 ` Willem de Bruijn
2014-11-27 0:36 ` Andy Lutomirski
2014-11-27 12:30 ` Richard Cochran
2014-11-25 17:58 ` Willem de Bruijn [this message]
2014-11-25 18:04 ` [PATCH rfc 2/4] net-errqueue: add IP(V6)_PKTINFO support Willem de Bruijn
2014-11-25 18:41 ` David Miller
2014-11-25 21:16 ` Willem de Bruijn
2014-11-25 17:58 ` [PATCH rfc 3/4] net-timestamp: tcp sockets return v6 errors on v6 sockets Willem de Bruijn
2014-11-25 18:41 ` David Miller
2014-11-25 19:53 ` Willem de Bruijn
2014-11-25 17:58 ` [PATCH rfc 4/4] net-timestamp: expand txtimestamp test with payload and PKTINFO Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1416938286-14147-3-git-send-email-willemb@google.com \
--to=willemb@google.com \
--cc=davem@davemloft.net \
--cc=luto@amacapital.net \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).