From: Steffen Klassert <steffen.klassert@secunet.com>
To: "Yurij M. Plotnikov" <Yurij.Plotnikov@oktetlabs.ru>
Cc: Ben Hutchings <bhutchings@solarflare.com>,
netdev@vger.kernel.org,
"Alexandra N. Kossovsky" <Alexandra.Kossovsky@oktetlabs.ru>
Subject: [RFC PATCH 2/3] ipv4: Add a socket release callback for datagram sockets
Date: Fri, 18 Jan 2013 09:15:14 +0100 [thread overview]
Message-ID: <20130118081514.GD24987@secunet.com> (raw)
In-Reply-To: <20130118081145.GB24987@secunet.com>
This implements a socket release callback function to check
if the socket cached route got invalid during the time
we owned the socket. The function is used from udp, raw
and ping sockets.
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
include/net/ip.h | 2 ++
net/ipv4/datagram.c | 25 +++++++++++++++++++++++++
net/ipv4/ping.c | 1 +
net/ipv4/raw.c | 1 +
net/ipv4/udp.c | 1 +
5 files changed, 30 insertions(+)
diff --git a/include/net/ip.h b/include/net/ip.h
index 0707fb9..a68f838 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -143,6 +143,8 @@ static inline struct sk_buff *ip_finish_skb(struct sock *sk, struct flowi4 *fl4)
extern int ip4_datagram_connect(struct sock *sk,
struct sockaddr *uaddr, int addr_len);
+extern void ip4_datagram_release_cb(struct sock *sk);
+
struct ip_reply_arg {
struct kvec iov[1];
int flags;
diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
index 424fafb..b28e863 100644
--- a/net/ipv4/datagram.c
+++ b/net/ipv4/datagram.c
@@ -85,3 +85,28 @@ out:
return err;
}
EXPORT_SYMBOL(ip4_datagram_connect);
+
+void ip4_datagram_release_cb(struct sock *sk)
+{
+ const struct inet_sock *inet = inet_sk(sk);
+ const struct ip_options_rcu *inet_opt;
+ __be32 daddr = inet->inet_daddr;
+ struct flowi4 fl4;
+ struct rtable *rt;
+
+ if (! __sk_dst_get(sk) || __sk_dst_check(sk, 0))
+ return;
+
+ rcu_read_lock();
+ inet_opt = rcu_dereference(inet->inet_opt);
+ if (inet_opt && inet_opt->opt.srr)
+ daddr = inet_opt->opt.faddr;
+ rt = ip_route_output_ports(sock_net(sk), &fl4, sk, daddr,
+ inet->inet_saddr, inet->inet_dport,
+ inet->inet_sport, sk->sk_protocol,
+ RT_CONN_FLAGS(sk), sk->sk_bound_dev_if);
+ if (!IS_ERR(rt))
+ __sk_dst_set(sk, &rt->dst);
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL_GPL(ip4_datagram_release_cb);
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 8f3d054..6f9c072 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -738,6 +738,7 @@ struct proto ping_prot = {
.recvmsg = ping_recvmsg,
.bind = ping_bind,
.backlog_rcv = ping_queue_rcv_skb,
+ .release_cb = ip4_datagram_release_cb,
.hash = ping_v4_hash,
.unhash = ping_v4_unhash,
.get_port = ping_v4_get_port,
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 73d1e4d..6f08991 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -894,6 +894,7 @@ struct proto raw_prot = {
.recvmsg = raw_recvmsg,
.bind = raw_bind,
.backlog_rcv = raw_rcv_skb,
+ .release_cb = ip4_datagram_release_cb,
.hash = raw_hash_sk,
.unhash = raw_unhash_sk,
.obj_size = sizeof(struct raw_sock),
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 79c8dbe..1f4d405 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1952,6 +1952,7 @@ struct proto udp_prot = {
.recvmsg = udp_recvmsg,
.sendpage = udp_sendpage,
.backlog_rcv = __udp_queue_rcv_skb,
+ .release_cb = ip4_datagram_release_cb,
.hash = udp_lib_hash,
.unhash = udp_lib_unhash,
.rehash = udp_v4_rehash,
--
1.7.9.5
next prev parent reply other threads:[~2013-01-18 8:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-19 13:10 PMTU discovery is broken on kernel 3.7.1 for UDP sockets Yurij M. Plotnikov
2012-12-19 13:35 ` Ben Hutchings
2012-12-19 14:27 ` Yurij M. Plotnikov
2012-12-19 19:37 ` Ben Hutchings
2012-12-20 7:14 ` Yurij M. Plotnikov
2012-12-20 7:34 ` Steffen Klassert
2012-12-20 11:22 ` Yurij M. Plotnikov
2012-12-20 12:35 ` Steffen Klassert
2012-12-21 10:22 ` Steffen Klassert
2013-01-14 8:26 ` Yurij M. Plotnikov
2013-01-14 12:52 ` Steffen Klassert
2013-01-18 8:11 ` Steffen Klassert
2013-01-18 8:14 ` [RFC PATCH 1/3] ipv4: Invalidate the socket cached route on pmtu events if possible Steffen Klassert
2013-01-18 19:38 ` David Miller
2013-01-19 0:54 ` Julian Anastasov
2013-01-21 6:43 ` Steffen Klassert
2013-01-18 8:15 ` Steffen Klassert [this message]
2013-01-18 19:39 ` [RFC PATCH 2/3] ipv4: Add a socket release callback for datagram sockets David Miller
2013-01-18 8:16 ` [RFC PATCH 3/3] xfrm4: Invalidate all ipv4 routes on IPsec pmtu events Steffen Klassert
2013-01-18 19:39 ` David Miller
2013-01-21 6:48 ` Steffen Klassert
2013-01-21 12:04 ` Steffen Klassert
2013-01-21 11:31 ` PMTU discovery is broken on kernel 3.7.1 for UDP sockets Yurij M. Plotnikov
2013-01-21 11:38 ` Steffen Klassert
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=20130118081514.GD24987@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=Alexandra.Kossovsky@oktetlabs.ru \
--cc=Yurij.Plotnikov@oktetlabs.ru \
--cc=bhutchings@solarflare.com \
--cc=netdev@vger.kernel.org \
/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).