inetpeer: add parameter net for inet_getpeer_v4,v6

add struct net as a parameter of inet_getpeer_v[4,6],
use net to replace &init_net.

and modify some places to provide net for inet_getpeer_v[4,6]

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Gao feng 2012-06-08 01:21:40 +00:00 committed by David S. Miller
parent c8a627ed06
commit 54db0cc2ba
7 changed files with 29 additions and 14 deletions

View File

@ -79,22 +79,26 @@ struct inet_peer *inet_getpeer(struct net *net,
const struct inetpeer_addr *daddr,
int create);
static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
static inline struct inet_peer *inet_getpeer_v4(struct net *net,
__be32 v4daddr,
int create)
{
struct inetpeer_addr daddr;
daddr.addr.a4 = v4daddr;
daddr.family = AF_INET;
return inet_getpeer(&init_net, &daddr, create);
return inet_getpeer(net, &daddr, create);
}
static inline struct inet_peer *inet_getpeer_v6(const struct in6_addr *v6daddr, int create)
static inline struct inet_peer *inet_getpeer_v6(struct net *net,
const struct in6_addr *v6daddr,
int create)
{
struct inetpeer_addr daddr;
*(struct in6_addr *)daddr.addr.a6 = *v6daddr;
daddr.family = AF_INET6;
return inet_getpeer(&init_net, &daddr, create);
return inet_getpeer(net, &daddr, create);
}
/* can be called from BH context or outside */

View File

@ -243,12 +243,12 @@ static struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,
if (q == NULL)
return NULL;
q->net = nf;
f->constructor(q, arg);
atomic_add(f->qsize, &nf->mem);
setup_timer(&q->timer, f->frag_expire, (unsigned long)q);
spin_lock_init(&q->lock);
atomic_set(&q->refcnt, 1);
q->net = nf;
return q;
}

View File

@ -171,6 +171,10 @@ static void frag_kfree_skb(struct netns_frags *nf, struct sk_buff *skb)
static void ip4_frag_init(struct inet_frag_queue *q, void *a)
{
struct ipq *qp = container_of(q, struct ipq, q);
struct netns_ipv4 *ipv4 = container_of(q->net, struct netns_ipv4,
frags);
struct net *net = container_of(ipv4, struct net, ipv4);
struct ip4_create_arg *arg = a;
qp->protocol = arg->iph->protocol;
@ -180,7 +184,7 @@ static void ip4_frag_init(struct inet_frag_queue *q, void *a)
qp->daddr = arg->iph->daddr;
qp->user = arg->user;
qp->peer = sysctl_ipfrag_max_dist ?
inet_getpeer_v4(arg->iph->saddr, 1) : NULL;
inet_getpeer_v4(net, arg->iph->saddr, 1) : NULL;
}
static __inline__ void ip4_frag_free(struct inet_frag_queue *q)

View File

@ -1328,9 +1328,10 @@ static u32 rt_peer_genid(void)
void rt_bind_peer(struct rtable *rt, __be32 daddr, int create)
{
struct net *net = dev_net(rt->dst.dev);
struct inet_peer *peer;
peer = inet_getpeer_v4(daddr, create);
peer = inet_getpeer_v4(net, daddr, create);
if (peer && cmpxchg(&rt->peer, NULL, peer) != NULL)
inet_putpeer(peer);
@ -1694,7 +1695,7 @@ unsigned short ip_rt_frag_needed(struct net *net, const struct iphdr *iph,
unsigned short est_mtu = 0;
struct inet_peer *peer;
peer = inet_getpeer_v4(iph->daddr, 1);
peer = inet_getpeer_v4(net, iph->daddr, 1);
if (peer) {
unsigned short mtu = new_mtu;
@ -1935,6 +1936,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
static void rt_init_metrics(struct rtable *rt, const struct flowi4 *fl4,
struct fib_info *fi)
{
struct net *net = dev_net(rt->dst.dev);
struct inet_peer *peer;
int create = 0;
@ -1944,7 +1946,7 @@ static void rt_init_metrics(struct rtable *rt, const struct flowi4 *fl4,
if (fl4 && (fl4->flowi4_flags & FLOWI_FLAG_PRECOW_METRICS))
create = 1;
rt->peer = peer = inet_getpeer_v4(rt->rt_dst, create);
rt->peer = peer = inet_getpeer_v4(net, rt->rt_dst, create);
if (peer) {
rt->rt_peer_genid = rt_peer_genid();
if (inet_metrics_new(peer))

View File

@ -1824,11 +1824,12 @@ struct inet_peer *tcp_v4_get_peer(struct sock *sk, bool *release_it)
{
struct rtable *rt = (struct rtable *) __sk_dst_get(sk);
struct inet_sock *inet = inet_sk(sk);
struct net *net = sock_net(sk);
struct inet_peer *peer;
if (!rt ||
inet->cork.fl.u.ip4.daddr != inet->inet_daddr) {
peer = inet_getpeer_v4(inet->inet_daddr, 1);
peer = inet_getpeer_v4(net, inet->inet_daddr, 1);
*release_it = true;
} else {
if (!rt->peer)
@ -1844,8 +1845,9 @@ EXPORT_SYMBOL(tcp_v4_get_peer);
void *tcp_v4_tw_get_peer(struct sock *sk)
{
const struct inet_timewait_sock *tw = inet_twsk(sk);
struct net *net = sock_net(sk);
return inet_getpeer_v4(tw->tw_daddr, 1);
return inet_getpeer_v4(net, tw->tw_daddr, 1);
}
EXPORT_SYMBOL(tcp_v4_tw_get_peer);

View File

@ -306,9 +306,10 @@ static u32 rt6_peer_genid(void)
void rt6_bind_peer(struct rt6_info *rt, int create)
{
struct net *net = dev_net(rt->dst.dev);
struct inet_peer *peer;
peer = inet_getpeer_v6(&rt->rt6i_dst.addr, create);
peer = inet_getpeer_v6(net, &rt->rt6i_dst.addr, create);
if (peer && cmpxchg(&rt->rt6i_peer, NULL, peer) != NULL)
inet_putpeer(peer);
else

View File

@ -1736,11 +1736,12 @@ static struct inet_peer *tcp_v6_get_peer(struct sock *sk, bool *release_it)
{
struct rt6_info *rt = (struct rt6_info *) __sk_dst_get(sk);
struct ipv6_pinfo *np = inet6_sk(sk);
struct net *net = sock_net(sk);
struct inet_peer *peer;
if (!rt ||
!ipv6_addr_equal(&np->daddr, &rt->rt6i_dst.addr)) {
peer = inet_getpeer_v6(&np->daddr, 1);
peer = inet_getpeer_v6(net, &np->daddr, 1);
*release_it = true;
} else {
if (!rt->rt6i_peer)
@ -1756,11 +1757,12 @@ static void *tcp_v6_tw_get_peer(struct sock *sk)
{
const struct inet6_timewait_sock *tw6 = inet6_twsk(sk);
const struct inet_timewait_sock *tw = inet_twsk(sk);
struct net *net = sock_net(sk);
if (tw->tw_family == AF_INET)
return tcp_v4_tw_get_peer(sk);
return inet_getpeer_v6(&tw6->tw_v6_daddr, 1);
return inet_getpeer_v6(net, &tw6->tw_v6_daddr, 1);
}
static struct timewait_sock_ops tcp6_timewait_sock_ops = {