From: Pavel Emelyanov <xemul@openvz.org>
To: David Miller <davem@davemloft.net>
Cc: Linux Netdev List <netdev@vger.kernel.org>
Subject: [PATCH net-2.6.26 5/8][SIT]: Make tunnels hashes per-net.
Date: Tue, 15 Apr 2008 17:34:54 +0400 [thread overview]
Message-ID: <4804AEFE.4020305@openvz.org> (raw)
In-Reply-To: <4804ACFA.1040003@openvz.org>
Just move all the hashes on the sit_net structure and
patch the rest of the code appropriately.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
net/ipv6/sit.c | 45 +++++++++++++++++++++++++--------------------
1 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index d0c1f2d..f82494b 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -70,15 +70,15 @@ static void ipip6_tunnel_setup(struct net_device *dev);
static int sit_net_id;
struct sit_net {
+ struct ip_tunnel *tunnels_r_l[HASH_SIZE];
+ struct ip_tunnel *tunnels_r[HASH_SIZE];
+ struct ip_tunnel *tunnels_l[HASH_SIZE];
+ struct ip_tunnel *tunnels_wc[1];
+ struct ip_tunnel **tunnels[4];
+
struct net_device *fb_tunnel_dev;
};
-static struct ip_tunnel *tunnels_r_l[HASH_SIZE];
-static struct ip_tunnel *tunnels_r[HASH_SIZE];
-static struct ip_tunnel *tunnels_l[HASH_SIZE];
-static struct ip_tunnel *tunnels_wc[1];
-static struct ip_tunnel **tunnels[4] = { tunnels_wc, tunnels_l, tunnels_r, tunnels_r_l };
-
static DEFINE_RWLOCK(ipip6_lock);
static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net,
@@ -87,21 +87,22 @@ static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net,
unsigned h0 = HASH(remote);
unsigned h1 = HASH(local);
struct ip_tunnel *t;
+ struct sit_net *sitn = net_generic(net, sit_net_id);
- for (t = tunnels_r_l[h0^h1]; t; t = t->next) {
+ for (t = sitn->tunnels_r_l[h0^h1]; t; t = t->next) {
if (local == t->parms.iph.saddr &&
remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
return t;
}
- for (t = tunnels_r[h0]; t; t = t->next) {
+ for (t = sitn->tunnels_r[h0]; t; t = t->next) {
if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
return t;
}
- for (t = tunnels_l[h1]; t; t = t->next) {
+ for (t = sitn->tunnels_l[h1]; t; t = t->next) {
if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
return t;
}
- if ((t = tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP))
+ if ((t = sitn->tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP))
return t;
return NULL;
}
@@ -122,7 +123,7 @@ static struct ip_tunnel **__ipip6_bucket(struct sit_net *sitn,
prio |= 1;
h ^= HASH(local);
}
- return &tunnels[prio][h];
+ return &sitn->tunnels[prio][h];
}
static inline struct ip_tunnel **ipip6_bucket(struct sit_net *sitn,
@@ -387,7 +388,7 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
if (dev == sitn->fb_tunnel_dev) {
write_lock_bh(&ipip6_lock);
- tunnels_wc[0] = NULL;
+ sitn->tunnels_wc[0] = NULL;
write_unlock_bh(&ipip6_lock);
dev_put(dev);
} else {
@@ -1050,6 +1051,8 @@ static int ipip6_fb_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
struct iphdr *iph = &tunnel->parms.iph;
+ struct net *net = dev_net(dev);
+ struct sit_net *sitn = net_generic(net, sit_net_id);
tunnel->dev = dev;
strcpy(tunnel->parms.name, dev->name);
@@ -1060,7 +1063,7 @@ static int ipip6_fb_tunnel_init(struct net_device *dev)
iph->ttl = 64;
dev_hold(dev);
- tunnels_wc[0] = tunnel;
+ sitn->tunnels_wc[0] = tunnel;
return 0;
}
@@ -1070,7 +1073,7 @@ static struct xfrm_tunnel sit_handler = {
.priority = 1,
};
-static void __exit sit_destroy_tunnels(void)
+static void sit_destroy_tunnels(struct sit_net *sitn)
{
int prio;
@@ -1078,7 +1081,7 @@ static void __exit sit_destroy_tunnels(void)
int h;
for (h = 0; h < HASH_SIZE; h++) {
struct ip_tunnel *t;
- while ((t = tunnels[prio][h]) != NULL)
+ while ((t = sitn->tunnels[prio][h]) != NULL)
unregister_netdevice(t->dev);
}
}
@@ -1090,7 +1093,7 @@ static int sit_init_net(struct net *net)
struct sit_net *sitn;
err = -ENOMEM;
- sitn = kmalloc(sizeof(struct sit_net), GFP_KERNEL);
+ sitn = kzalloc(sizeof(struct sit_net), GFP_KERNEL);
if (sitn == NULL)
goto err_alloc;
@@ -1098,6 +1101,11 @@ static int sit_init_net(struct net *net)
if (err < 0)
goto err_assign;
+ sitn->tunnels[0] = sitn->tunnels_wc;
+ sitn->tunnels[1] = sitn->tunnels_l;
+ sitn->tunnels[2] = sitn->tunnels_r;
+ sitn->tunnels[3] = sitn->tunnels_r_l;
+
sitn->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "sit0",
ipip6_tunnel_setup);
if (!sitn->fb_tunnel_dev) {
@@ -1129,6 +1137,7 @@ static void sit_exit_net(struct net *net)
sitn = net_generic(net, sit_net_id);
rtnl_lock();
+ sit_destroy_tunnels(sitn);
unregister_netdevice(sitn->fb_tunnel_dev);
rtnl_unlock();
kfree(sitn);
@@ -1143,10 +1152,6 @@ static void __exit sit_cleanup(void)
{
xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
- rtnl_lock();
- sit_destroy_tunnels();
- rtnl_unlock();
-
unregister_pernet_gen_device(sit_net_id, &sit_net_ops);
}
--
1.5.3.4
next prev parent reply other threads:[~2008-04-15 13:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-15 13:26 [PATCH net-2.6.26 0/8][SIT]: Make SIT tunnel work in net namespaces Pavel Emelyanov
2008-04-15 13:27 ` [PATCH net-2.6.26 1/8][SIT]: Introduce empty struct sit_net and init/exit net ops Pavel Emelyanov
2008-04-15 13:29 ` [PATCH net-2.6.26 2/8][SIT]: Add net/sit_net argument to some functions Pavel Emelyanov
2008-04-15 13:31 ` [PATCH net-2.6.26 3/8][SIT]: Use proper net in hash-lookup functions Pavel Emelyanov
2008-04-15 13:33 ` [PATCH net-2.6.26 4/8][SIT]: Make the fallback tunnel device per-net Pavel Emelyanov
2008-04-15 13:34 ` Pavel Emelyanov [this message]
2008-04-15 13:36 ` [PATCH net-2.6.26 6/8][SIT]: Use proper net in routing calls Pavel Emelyanov
2008-04-15 13:37 ` [PATCH net-2.6.26 7/8][SIT]: Allow to create SIT tunnels in net namespaces Pavel Emelyanov
2008-04-15 13:39 ` [PATCH net-2.6.26 8/8][SIT]: Allow for IPPROTO_IPV6 protocol in namespaces Pavel Emelyanov
2008-04-16 8:19 ` [PATCH net-2.6.26 0/8][SIT]: Make SIT tunnel work in net namespaces David Miller
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=4804AEFE.4020305@openvz.org \
--to=xemul@openvz.org \
--cc=davem@davemloft.net \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.