Home » Mailing lists » Devel » [RFC] network namespaces
[PATCH 5/9] network namespaces: async socket operations [message #5169 is a reply to message #5165] |
Tue, 15 August 2006 14:48   |
Andrey Savochkin
Messages: 47 Registered: December 2005
|
Member |
|
|
Non-trivial part of socket namespaces: asynchronous events
should be run in proper context.
Signed-off-by: Andrey Savochkin <saw@swsoft.com>
---
af_inet.c | 10 ++++++++++
inet_timewait_sock.c | 8 ++++++++
tcp_timer.c | 9 +++++++++
3 files changed, 27 insertions(+)
--- ./net/ipv4/af_inet.c.venssock-asyn Mon Aug 14 17:04:07 2006
+++ ./net/ipv4/af_inet.c Tue Aug 15 13:45:44 2006
@@ -366,10 +366,17 @@ out_rcu_unlock:
int inet_release(struct socket *sock)
{
struct sock *sk = sock->sk;
+ struct net_namespace *ns, *orig_net_ns;
if (sk) {
long timeout;
+ /* Need to change context here since protocol ->close
+ * operation may send packets.
+ */
+ ns = get_net_ns(sk->sk_net_ns);
+ push_net_ns(ns, orig_net_ns);
+
/* Applications forget to leave groups before exiting */
ip_mc_drop_socket(sk);
@@ -386,6 +393,9 @@ int inet_release(struct socket *sock)
timeout = sk->sk_lingertime;
sock->sk = NULL;
sk->sk_prot->close(sk, timeout);
+
+ pop_net_ns(orig_net_ns);
+ put_net_ns(ns);
}
return 0;
}
--- ./net/ipv4/inet_timewait_sock.c.venssock-asyn Tue Aug 15 13:45:44 2006
+++ ./net/ipv4/inet_timewait_sock.c Tue Aug 15 13:45:44 2006
@@ -129,6 +129,7 @@ static int inet_twdr_do_twkill_work(stru
{
struct inet_timewait_sock *tw;
struct hlist_node *node;
+ struct net_namespace *orig_net_ns;
unsigned int killed;
int ret;
@@ -140,8 +141,10 @@ static int inet_twdr_do_twkill_work(stru
*/
killed = 0;
ret = 0;
+ push_net_ns(current_net_ns, orig_net_ns);
rescan:
inet_twsk_for_each_inmate(tw, node, &twdr->cells[slot]) {
+ switch_net_ns(tw->tw_net_ns);
__inet_twsk_del_dead_node(tw);
spin_unlock(&twdr->death_lock);
__inet_twsk_kill(tw, twdr->hashinfo);
@@ -164,6 +167,7 @@ rescan:
twdr->tw_count -= killed;
NET_ADD_STATS_BH(LINUX_MIB_TIMEWAITED, killed);
+ pop_net_ns(orig_net_ns);
return ret;
}
@@ -338,10 +342,12 @@ void inet_twdr_twcal_tick(unsigned long
int n, slot;
unsigned long j;
unsigned long now = jiffies;
+ struct net_namespace *orig_net_ns;
int killed = 0;
int adv = 0;
twdr = (struct inet_timewait_death_row *)data;
+ push_net_ns(current_net_ns, orig_net_ns);
spin_lock(&twdr->death_lock);
if (twdr->twcal_hand < 0)
@@ -357,6 +363,7 @@ void inet_twdr_twcal_tick(unsigned long
inet_twsk_for_each_inmate_safe(tw, node, safe,
&twdr->twcal_row[slot]) {
+ switch_net_ns(tw->tw_net_ns);
__inet_twsk_del_dead_node(tw);
__inet_twsk_kill(tw, twdr->hashinfo);
inet_twsk_put(tw);
@@ -384,6 +391,7 @@ out:
del_timer(&twdr->tw_timer);
NET_ADD_STATS_BH(LINUX_MIB_TIMEWAITKILLED, killed);
spin_unlock(&twdr->death_lock);
+ pop_net_ns(orig_net_ns);
}
EXPORT_SYMBOL_GPL(inet_twdr_twcal_tick);
--- ./net/ipv4/tcp_timer.c.venssock-asyn Mon Aug 14 16:43:51 2006
+++ ./net/ipv4/tcp_timer.c Tue Aug 15 13:45:44 2006
@@ -171,7 +171,9 @@ static void tcp_delack_timer(unsigned lo
struct sock *sk = (struct sock*)data;
struct tcp_sock *tp = tcp_sk(sk);
struct inet_connection_sock *icsk = inet_csk(sk);
+ struct net_namespace *orig_net_ns;
+ push_net_ns(sk->sk_net_ns, orig_net_ns);
bh_lock_sock(sk);
if (sock_owned_by_user(sk)) {
/* Try again later. */
@@ -225,6 +227,7 @@ out:
out_unlock:
bh_unlock_sock(sk);
sock_put(sk);
+ pop_net_ns(orig_net_ns);
}
static void tcp_probe_timer(struct sock *sk)
@@ -384,8 +387,10 @@ static void tcp_write_timer(unsigned lon
{
struct sock *sk = (struct sock*)data;
struct inet_connection_sock *icsk = inet_csk(sk);
+ struct net_namespace *orig_net_ns;
int event;
+ push_net_ns(sk->sk_net_ns, orig_net_ns);
bh_lock_sock(sk);
if (sock_owned_by_user(sk)) {
/* Try again later */
@@ -419,6 +424,7 @@ out:
out_unlock:
bh_unlock_sock(sk);
sock_put(sk);
+ pop_net_ns(orig_net_ns);
}
/*
@@ -447,9 +453,11 @@ static void tcp_keepalive_timer (unsigne
{
struct sock *sk = (struct sock *) data;
struct inet_connection_sock *icsk = inet_csk(sk);
+ struct net_namespace *orig_net_ns;
struct tcp_sock *tp = tcp_sk(sk);
__u32 elapsed;
+ push_net_ns(sk->sk_net_ns, orig_net_ns);
/* Only process if socket is not in use. */
bh_lock_sock(sk);
if (sock_owned_by_user(sk)) {
@@ -521,4 +529,5 @@ death:
out:
bh_unlock_sock(sk);
sock_put(sk);
+ put_net_ns(orig_net_ns);
}
|
|
|
 |
|
[RFC] network namespaces
|
 |
|
[PATCH 1/9] network namespaces: core and device list
|
 |
|
Re: [PATCH 1/9] network namespaces: core and device list
|
 |
|
Re: [PATCH 1/9] network namespaces: core and device list
|
 |
|
[PATCH 2/9] network namespaces: IPv4 routing
|
 |
|
[PATCH 6/9] allow proc_dir_entries to have destructor
|
 |
|
[PATCH 5/9] network namespaces: async socket operations
|
 |
|
Re: [PATCH 5/9] network namespaces: async socket operations
|
 |
|
Re: [PATCH 5/9] network namespaces: async socket operations
|
 |
|
[PATCH 7/9] net_device seq_file
|
 |
|
[PATCH 8/9] network namespaces: device to pass packets between namespaces
|
 |
|
[PATCH 4/9] network namespaces: socket hashes
|
 |
|
Re: [PATCH 4/9] network namespaces: socket hashes
|
 |
|
Re: [PATCH 4/9] network namespaces: socket hashes
|
 |
|
Re: [PATCH 4/9] network namespaces: socket hashes
|
 |
|
[PATCH 9/9] network namespaces: playing with pass-through device
|
 |
|
Re: [RFC] network namespaces
By: serue on Wed, 16 August 2006 11:53
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Wed, 16 August 2006 17:35
|
 |
|
Re: [RFC] network namespaces
By: dev on Thu, 17 August 2006 08:28
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Tue, 05 September 2006 14:45
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
By: kir on Wed, 06 September 2006 17:36
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Wed, 06 September 2006 18:34
|
 |
|
Re: [RFC] network namespaces
By: kir on Wed, 06 September 2006 18:56
|
 |
|
Re: [RFC] network namespaces
|
 |
|
RE: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Thu, 07 September 2006 18:29
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
By: dev on Thu, 07 September 2006 16:20
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Tue, 12 September 2006 03:26
|
 |
|
Re: Re: [RFC] network namespaces
By: ebiederm on Sun, 10 September 2006 03:41
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Tue, 12 September 2006 03:28
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
By: ebiederm on Thu, 07 September 2006 19:50
|
 |
|
Re: Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Wed, 06 September 2006 17:58
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Tue, 05 September 2006 18:27
|
 |
|
Re: [RFC] network namespaces
By: dev on Wed, 06 September 2006 14:52
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: dev on Tue, 05 September 2006 15:44
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Tue, 05 September 2006 17:09
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: Re: [RFC] network namespaces
By: kir on Wed, 06 September 2006 15:09
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Wed, 06 September 2006 20:40
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Wed, 06 September 2006 23:25
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Thu, 07 September 2006 05:11
|
 |
|
Re: [RFC] network namespaces
|
 |
|
Re: [RFC] network namespaces
By: ebiederm on Sun, 10 September 2006 11:48
|
Goto Forum:
Current Time: Sun Aug 03 05:27:33 GMT 2025
Total time taken to generate the page: 0.82900 seconds
|