* [RFC 1/4] net: pppoe - code cleanup and helpers
[not found] <20090109195154.320495476@gmail.com>
@ 2009-01-09 19:51 ` Cyrill Gorcunov
2009-01-09 19:51 ` [RFC 2/4] net: pppoe - introduce net-namespace functionality Cyrill Gorcunov
` (2 subsequent siblings)
3 siblings, 0 replies; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-09 19:51 UTC (permalink / raw)
To: davem, linux-kernel, netdev
Cc: gorcunov, devel, xemul, Michal Ostrowski, Cyrill Gorcunov
[-- Attachment #1: net-pppoe-cleanup --]
[-- Type: text/plain, Size: 11879 bytes --]
- Introduce PPPOE_HASH_MASK.
- Remove redundant declaration of pppoe_chan_ops.
- Introduce stage_session helper.
- Tabs, space, long-line-split cleanup.
CC: Michal Ostrowski <mostrows@earthlink.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
drivers/net/pppoe.c | 167 ++++++++++++++++++++++++++--------------------------
1 file changed, 86 insertions(+), 81 deletions(-)
Index: linux-2.6.git/drivers/net/pppoe.c
===================================================================
--- linux-2.6.git.orig/drivers/net/pppoe.c
+++ linux-2.6.git/drivers/net/pppoe.c
@@ -84,32 +84,43 @@
#include <asm/uaccess.h>
#define PPPOE_HASH_BITS 4
-#define PPPOE_HASH_SIZE (1<<PPPOE_HASH_BITS)
-
-static struct ppp_channel_ops pppoe_chan_ops;
+#define PPPOE_HASH_SIZE (1 << PPPOE_HASH_BITS)
+#define PPPOE_HASH_MASK (PPPOE_HASH_SIZE - 1)
static int pppoe_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb);
static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb);
static const struct proto_ops pppoe_ops;
+static struct ppp_channel_ops pppoe_chan_ops;
static DEFINE_RWLOCK(pppoe_hash_lock);
-static struct ppp_channel_ops pppoe_chan_ops;
+/*
+ * PPPoE could be in the following stages:
+ * 1) Discovery stage (to obtain remote MAC and Session ID)
+ * 2) Session stage (MAC and SID are known)
+ *
+ * Ethernet frames have a special tag for this but
+ * we use simplier approach based on session id
+ */
+static inline bool stage_session(__be16 sid)
+{
+ return sid != 0;
+}
static inline int cmp_2_addr(struct pppoe_addr *a, struct pppoe_addr *b)
{
- return (a->sid == b->sid &&
- (memcmp(a->remote, b->remote, ETH_ALEN) == 0));
+ return a->sid == b->sid &&
+ (memcmp(a->remote, b->remote, ETH_ALEN) == 0);
}
static inline int cmp_addr(struct pppoe_addr *a, __be16 sid, char *addr)
{
- return (a->sid == sid &&
- (memcmp(a->remote,addr,ETH_ALEN) == 0));
+ return a->sid == sid &&
+ (memcmp(a->remote, addr, ETH_ALEN) == 0);
}
-#if 8%PPPOE_HASH_BITS
+#if 8 % PPPOE_HASH_BITS
#error 8 must be a multiple of PPPOE_HASH_BITS
#endif
@@ -118,17 +129,14 @@ static int hash_item(__be16 sid, unsigne
unsigned char hash = 0;
unsigned int i;
- for (i = 0 ; i < ETH_ALEN ; i++) {
+ for (i = 0; i < ETH_ALEN; i++)
hash ^= addr[i];
- }
- for (i = 0 ; i < sizeof(sid_t)*8 ; i += 8 ){
- hash ^= (__force __u32)sid>>i;
- }
- for (i = 8 ; (i>>=1) >= PPPOE_HASH_BITS ; ) {
- hash ^= hash>>i;
- }
+ for (i = 0; i < sizeof(sid_t) * 8; i += 8)
+ hash ^= (__force __u32)sid >> i;
+ for (i = 8; (i >>= 1) >= PPPOE_HASH_BITS;)
+ hash ^= hash >> i;
- return hash & ( PPPOE_HASH_SIZE - 1 );
+ return hash & PPPOE_HASH_MASK;
}
/* zeroed because its in .bss */
@@ -146,10 +154,15 @@ static struct pppox_sock *__get_item(__b
ret = item_hash_table[hash];
- while (ret && !(cmp_addr(&ret->pppoe_pa, sid, addr) && ret->pppoe_ifindex == ifindex))
+ while (ret) {
+ if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
+ ret->pppoe_ifindex == ifindex)
+ return ret;
+
ret = ret->next;
+ }
- return ret;
+ return NULL;
}
static int __set_item(struct pppox_sock *po)
@@ -159,7 +172,8 @@ static int __set_item(struct pppox_sock
ret = item_hash_table[hash];
while (ret) {
- if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa) && ret->pppoe_ifindex == po->pppoe_ifindex)
+ if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa) &&
+ ret->pppoe_ifindex == po->pppoe_ifindex)
return -EALREADY;
ret = ret->next;
@@ -180,7 +194,8 @@ static struct pppox_sock *__delete_item(
src = &item_hash_table[hash];
while (ret) {
- if (cmp_addr(&ret->pppoe_pa, sid, addr) && ret->pppoe_ifindex == ifindex) {
+ if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
+ ret->pppoe_ifindex == ifindex) {
*src = ret->next;
break;
}
@@ -217,7 +232,7 @@ static inline struct pppox_sock *get_ite
int ifindex;
dev = dev_get_by_name(&init_net, sp->sa_addr.pppoe.dev);
- if(!dev)
+ if (!dev)
return NULL;
ifindex = dev->ifindex;
dev_put(dev);
@@ -329,7 +344,6 @@ static struct notifier_block pppoe_notif
.notifier_call = pppoe_device_event,
};
-
/************************************************************************
*
* Do the real work of receiving a PPPoE Session frame.
@@ -383,7 +397,8 @@ static int pppoe_rcv(struct sk_buff *skb
struct pppox_sock *po;
int len;
- if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
+ skb = skb_share_check(skb, GFP_ATOMIC);
+ if (!skb)
goto out;
if (dev_net(dev) != &init_net)
@@ -432,7 +447,8 @@ static int pppoe_disc_rcv(struct sk_buff
if (dev_net(dev) != &init_net)
goto abort;
- if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
+ skb = skb_share_check(skb, GFP_ATOMIC);
+ if (!skb)
goto out;
if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
@@ -493,12 +509,11 @@ static struct proto pppoe_sk_proto = {
**********************************************************************/
static int pppoe_create(struct net *net, struct socket *sock)
{
- int error = -ENOMEM;
struct sock *sk;
sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppoe_sk_proto);
if (!sk)
- goto out;
+ return -ENOMEM;
sock_init_data(sock, sk);
@@ -511,8 +526,7 @@ static int pppoe_create(struct net *net,
sk->sk_family = PF_PPPOX;
sk->sk_protocol = PX_PROTO_OE;
- error = 0;
-out: return error;
+ return 0;
}
static int pppoe_release(struct socket *sock)
@@ -524,7 +538,7 @@ static int pppoe_release(struct socket *
return 0;
lock_sock(sk);
- if (sock_flag(sk, SOCK_DEAD)){
+ if (sock_flag(sk, SOCK_DEAD)) {
release_sock(sk);
return -EBADF;
}
@@ -542,7 +556,7 @@ static int pppoe_release(struct socket *
write_lock_bh(&pppoe_hash_lock);
po = pppox_sk(sk);
- if (po->pppoe_pa.sid) {
+ if (stage_session(po->pppoe_pa.sid)) {
__delete_item(po->pppoe_pa.sid,
po->pppoe_pa.remote, po->pppoe_ifindex);
}
@@ -564,7 +578,6 @@ static int pppoe_release(struct socket *
return 0;
}
-
static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
int sockaddr_len, int flags)
{
@@ -582,32 +595,31 @@ static int pppoe_connect(struct socket *
/* Check for already bound sockets */
error = -EBUSY;
- if ((sk->sk_state & PPPOX_CONNECTED) && sp->sa_addr.pppoe.sid)
+ if ((sk->sk_state & PPPOX_CONNECTED) &&
+ stage_session(sp->sa_addr.pppoe.sid))
goto end;
/* Check for already disconnected sockets, on attempts to disconnect */
error = -EALREADY;
- if ((sk->sk_state & PPPOX_DEAD) && !sp->sa_addr.pppoe.sid )
+ if ((sk->sk_state & PPPOX_DEAD) &&
+ !stage_session(sp->sa_addr.pppoe.sid))
goto end;
error = 0;
- if (po->pppoe_pa.sid) {
- pppox_unbind_sock(sk);
-
- /* Delete the old binding */
- delete_item(po->pppoe_pa.sid,po->pppoe_pa.remote,po->pppoe_ifindex);
- if(po->pppoe_dev)
+ /* Delete the old binding */
+ if (stage_session(po->pppoe_pa.sid)) {
+ pppox_unbind_sock(sk);
+ delete_item(po->pppoe_pa.sid, po->pppoe_pa.remote, po->pppoe_ifindex);
+ if (po->pppoe_dev)
dev_put(po->pppoe_dev);
-
memset(sk_pppox(po) + 1, 0,
sizeof(struct pppox_sock) - sizeof(struct sock));
-
sk->sk_state = PPPOX_NONE;
}
- /* Don't re-bind if sid==0 */
- if (sp->sa_addr.pppoe.sid != 0) {
+ /* Re-bind in session stage only */
+ if (stage_session(sp->sa_addr.pppoe.sid)) {
dev = dev_get_by_name(&init_net, sp->sa_addr.pppoe.dev);
error = -ENODEV;
@@ -618,7 +630,7 @@ static int pppoe_connect(struct socket *
po->pppoe_ifindex = dev->ifindex;
write_lock_bh(&pppoe_hash_lock);
- if (!(dev->flags & IFF_UP)){
+ if (!(dev->flags & IFF_UP)) {
write_unlock_bh(&pppoe_hash_lock);
goto err_put;
}
@@ -648,7 +660,7 @@ static int pppoe_connect(struct socket *
po->num = sp->sa_addr.pppoe.sid;
- end:
+end:
release_sock(sk);
return error;
err_put:
@@ -659,7 +671,6 @@ err_put:
goto end;
}
-
static int pppoe_getname(struct socket *sock, struct sockaddr *uaddr,
int *usockaddr_len, int peer)
{
@@ -678,7 +689,6 @@ static int pppoe_getname(struct socket *
return 0;
}
-
static int pppoe_ioctl(struct socket *sock, unsigned int cmd,
unsigned long arg)
{
@@ -709,7 +719,7 @@ static int pppoe_ioctl(struct socket *so
break;
err = -EFAULT;
- if (get_user(val,(int __user *) arg))
+ if (get_user(val, (int __user *)arg))
break;
if (val < (po->pppoe_dev->mtu
@@ -722,7 +732,7 @@ static int pppoe_ioctl(struct socket *so
case PPPIOCSFLAGS:
err = -EFAULT;
- if (get_user(val, (int __user *) arg))
+ if (get_user(val, (int __user *)arg))
break;
err = 0;
break;
@@ -749,7 +759,7 @@ static int pppoe_ioctl(struct socket *so
err = -EINVAL;
if (po->pppoe_relay.sa_family != AF_PPPOX ||
- po->pppoe_relay.sa_protocol!= PX_PROTO_OE)
+ po->pppoe_relay.sa_protocol != PX_PROTO_OE)
break;
/* Check that the socket referenced by the address
@@ -781,7 +791,6 @@ static int pppoe_ioctl(struct socket *so
return err;
}
-
static int pppoe_sendmsg(struct kiocb *iocb, struct socket *sock,
struct msghdr *m, size_t total_len)
{
@@ -808,7 +817,7 @@ static int pppoe_sendmsg(struct kiocb *i
dev = po->pppoe_dev;
error = -EMSGSIZE;
- if (total_len > (dev->mtu + dev->hard_header_len))
+ if (total_len > (dev->mtu + dev->hard_header_len))
goto end;
@@ -853,7 +862,6 @@ end:
return error;
}
-
/************************************************************************
*
* xmit function for internal use.
@@ -903,7 +911,6 @@ abort:
return 1;
}
-
/************************************************************************
*
* xmit function called by generic PPP driver
@@ -916,7 +923,6 @@ static int pppoe_xmit(struct ppp_channel
return __pppoe_xmit(sk, skb);
}
-
static struct ppp_channel_ops pppoe_chan_ops = {
.start_xmit = pppoe_xmit,
};
@@ -976,9 +982,9 @@ out:
static __inline__ struct pppox_sock *pppoe_get_idx(loff_t pos)
{
struct pppox_sock *po;
- int i = 0;
+ int i;
- for (; i < PPPOE_HASH_SIZE; i++) {
+ for (i = 0; i < PPPOE_HASH_SIZE; i++) {
po = item_hash_table[i];
while (po) {
if (!pos--)
@@ -1064,32 +1070,31 @@ static inline int pppoe_proc_init(void)
#endif /* CONFIG_PROC_FS */
static const struct proto_ops pppoe_ops = {
- .family = AF_PPPOX,
- .owner = THIS_MODULE,
- .release = pppoe_release,
- .bind = sock_no_bind,
- .connect = pppoe_connect,
- .socketpair = sock_no_socketpair,
- .accept = sock_no_accept,
- .getname = pppoe_getname,
- .poll = datagram_poll,
- .listen = sock_no_listen,
- .shutdown = sock_no_shutdown,
- .setsockopt = sock_no_setsockopt,
- .getsockopt = sock_no_getsockopt,
- .sendmsg = pppoe_sendmsg,
- .recvmsg = pppoe_recvmsg,
- .mmap = sock_no_mmap,
- .ioctl = pppox_ioctl,
+ .family = AF_PPPOX,
+ .owner = THIS_MODULE,
+ .release = pppoe_release,
+ .bind = sock_no_bind,
+ .connect = pppoe_connect,
+ .socketpair = sock_no_socketpair,
+ .accept = sock_no_accept,
+ .getname = pppoe_getname,
+ .poll = datagram_poll,
+ .listen = sock_no_listen,
+ .shutdown = sock_no_shutdown,
+ .setsockopt = sock_no_setsockopt,
+ .getsockopt = sock_no_getsockopt,
+ .sendmsg = pppoe_sendmsg,
+ .recvmsg = pppoe_recvmsg,
+ .mmap = sock_no_mmap,
+ .ioctl = pppox_ioctl,
};
static struct pppox_proto pppoe_proto = {
- .create = pppoe_create,
- .ioctl = pppoe_ioctl,
- .owner = THIS_MODULE,
+ .create = pppoe_create,
+ .ioctl = pppoe_ioctl,
+ .owner = THIS_MODULE,
};
-
static int __init pppoe_init(void)
{
int err = proto_register(&pppoe_sk_proto, 0);
@@ -1097,7 +1102,7 @@ static int __init pppoe_init(void)
if (err)
goto out;
- err = register_pppox_proto(PX_PROTO_OE, &pppoe_proto);
+ err = register_pppox_proto(PX_PROTO_OE, &pppoe_proto);
if (err)
goto out_unregister_pppoe_proto;
--
^ permalink raw reply [flat|nested] 20+ messages in thread* [RFC 2/4] net: pppoe - introduce net-namespace functionality
[not found] <20090109195154.320495476@gmail.com>
2009-01-09 19:51 ` [RFC 1/4] net: pppoe - code cleanup and helpers Cyrill Gorcunov
@ 2009-01-09 19:51 ` Cyrill Gorcunov
2009-01-09 19:51 ` [RFC 3/4] net: pppol2tp " Cyrill Gorcunov
2009-01-09 19:51 ` [RFC 4/4] net: ppp_generic " Cyrill Gorcunov
3 siblings, 0 replies; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-09 19:51 UTC (permalink / raw)
To: davem, linux-kernel, netdev
Cc: gorcunov, devel, xemul, Michal Ostrowski, Cyrill Gorcunov
[-- Attachment #1: net-pppoe-namespace --]
[-- Type: text/plain, Size: 23296 bytes --]
- each net-namespace for pppoe module is having own
hash table and appropriate locks wich are allocated
at time of namespace intialization. It requires about
140 bytes of memory for every new namespace but such
approach allow us to escape from hash chains growing
and additional lock contends (especially in SMP environment).
- pppox code allows to create per-namespace sockets for
PX_PROTO_OE protocol only (since at this moment support
for pppol2tp net-namespace is not implemented yet).
CC: Michal Ostrowski <mostrows@earthlink.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
drivers/net/pppoe.c | 383 +++++++++++++++++++++++++++++++++-------------------
drivers/net/pppox.c | 7
2 files changed, 254 insertions(+), 136 deletions(-)
Index: linux-2.6.git/drivers/net/pppoe.c
===================================================================
--- linux-2.6.git.orig/drivers/net/pppoe.c
+++ linux-2.6.git/drivers/net/pppoe.c
@@ -78,7 +78,9 @@
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/nsproxy.h>
#include <net/net_namespace.h>
+#include <net/netns/generic.h>
#include <net/sock.h>
#include <asm/uaccess.h>
@@ -93,7 +95,24 @@ static int __pppoe_xmit(struct sock *sk,
static const struct proto_ops pppoe_ops;
static struct ppp_channel_ops pppoe_chan_ops;
-static DEFINE_RWLOCK(pppoe_hash_lock);
+
+/* per-net private data for this module */
+static unsigned int pppoe_net_id;
+struct pppoe_net {
+ /*
+ * we could use _single_ hash table for all
+ * nets by injecting net id into the hash but
+ * it would increase hash chains and add
+ * a few additional math comparations messy
+ * as well, moreover in case of SMP less locking
+ * controversy here
+ */
+ struct pppox_sock *hash_table[PPPOE_HASH_SIZE];
+ rwlock_t hash_lock;
+};
+
+/* to eliminate a race btw pppoe_flush_dev and pppoe_release */
+static DEFINE_SPINLOCK(flush_lock);
/*
* PPPoE could be in the following stages:
@@ -108,16 +127,21 @@ static inline bool stage_session(__be16
return sid != 0;
}
+static inline struct pppoe_net *pppoe_pernet(struct net *net)
+{
+ BUG_ON(!net);
+
+ return net_generic(net, pppoe_net_id);
+}
+
static inline int cmp_2_addr(struct pppoe_addr *a, struct pppoe_addr *b)
{
- return a->sid == b->sid &&
- (memcmp(a->remote, b->remote, ETH_ALEN) == 0);
+ return a->sid == b->sid && !memcmp(a->remote, b->remote, ETH_ALEN);
}
static inline int cmp_addr(struct pppoe_addr *a, __be16 sid, char *addr)
{
- return a->sid == sid &&
- (memcmp(a->remote, addr, ETH_ALEN) == 0);
+ return a->sid == sid && !memcmp(a->remote, addr, ETH_ALEN);
}
#if 8 % PPPOE_HASH_BITS
@@ -139,21 +163,18 @@ static int hash_item(__be16 sid, unsigne
return hash & PPPOE_HASH_MASK;
}
-/* zeroed because its in .bss */
-static struct pppox_sock *item_hash_table[PPPOE_HASH_SIZE];
-
/**********************************************************************
*
* Set/get/delete/rehash items (internal versions)
*
**********************************************************************/
-static struct pppox_sock *__get_item(__be16 sid, unsigned char *addr, int ifindex)
+static struct pppox_sock *__get_item(struct pppoe_net *pn, __be16 sid,
+ unsigned char *addr, int ifindex)
{
int hash = hash_item(sid, addr);
struct pppox_sock *ret;
- ret = item_hash_table[hash];
-
+ ret = pn->hash_table[hash];
while (ret) {
if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
ret->pppoe_ifindex == ifindex)
@@ -165,12 +186,12 @@ static struct pppox_sock *__get_item(__b
return NULL;
}
-static int __set_item(struct pppox_sock *po)
+static int __set_item(struct pppoe_net *pn, struct pppox_sock *po)
{
int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
struct pppox_sock *ret;
- ret = item_hash_table[hash];
+ ret = pn->hash_table[hash];
while (ret) {
if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa) &&
ret->pppoe_ifindex == po->pppoe_ifindex)
@@ -179,19 +200,20 @@ static int __set_item(struct pppox_sock
ret = ret->next;
}
- po->next = item_hash_table[hash];
- item_hash_table[hash] = po;
+ po->next = pn->hash_table[hash];
+ pn->hash_table[hash] = po;
return 0;
}
-static struct pppox_sock *__delete_item(__be16 sid, char *addr, int ifindex)
+static struct pppox_sock *__delete_item(struct pppoe_net *pn, __be16 sid,
+ char *addr, int ifindex)
{
int hash = hash_item(sid, addr);
struct pppox_sock *ret, **src;
- ret = item_hash_table[hash];
- src = &item_hash_table[hash];
+ ret = pn->hash_table[hash];
+ src = &pn->hash_table[hash];
while (ret) {
if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
@@ -212,46 +234,54 @@ static struct pppox_sock *__delete_item(
* Set/get/delete/rehash items
*
**********************************************************************/
-static inline struct pppox_sock *get_item(__be16 sid,
- unsigned char *addr, int ifindex)
+static inline struct pppox_sock *get_item(struct pppoe_net *pn, __be16 sid,
+ unsigned char *addr, int ifindex)
{
struct pppox_sock *po;
- read_lock_bh(&pppoe_hash_lock);
- po = __get_item(sid, addr, ifindex);
+ read_lock_bh(&pn->hash_lock);
+ po = __get_item(pn, sid, addr, ifindex);
if (po)
sock_hold(sk_pppox(po));
- read_unlock_bh(&pppoe_hash_lock);
+ read_unlock_bh(&pn->hash_lock);
return po;
}
-static inline struct pppox_sock *get_item_by_addr(struct sockaddr_pppox *sp)
+static inline struct pppox_sock *get_item_by_addr(struct net *net,
+ struct sockaddr_pppox *sp)
{
struct net_device *dev;
+ struct pppoe_net *pn;
+ struct pppox_sock *pppox_sock;
+
int ifindex;
- dev = dev_get_by_name(&init_net, sp->sa_addr.pppoe.dev);
+ dev = dev_get_by_name(net, sp->sa_addr.pppoe.dev);
if (!dev)
return NULL;
+
ifindex = dev->ifindex;
+ pn = net_generic(net, pppoe_net_id);
+ pppox_sock = get_item(pn, sp->sa_addr.pppoe.sid,
+ sp->sa_addr.pppoe.remote, ifindex);
dev_put(dev);
- return get_item(sp->sa_addr.pppoe.sid, sp->sa_addr.pppoe.remote, ifindex);
+
+ return pppox_sock;
}
-static inline struct pppox_sock *delete_item(__be16 sid, char *addr, int ifindex)
+static inline struct pppox_sock *delete_item(struct pppoe_net *pn, __be16 sid,
+ char *addr, int ifindex)
{
struct pppox_sock *ret;
- write_lock_bh(&pppoe_hash_lock);
- ret = __delete_item(sid, addr, ifindex);
- write_unlock_bh(&pppoe_hash_lock);
+ write_lock_bh(&pn->hash_lock);
+ ret = __delete_item(pn, sid, addr, ifindex);
+ write_unlock_bh(&pn->hash_lock);
return ret;
}
-
-
/***************************************************************************
*
* Handler for device events.
@@ -261,25 +291,33 @@ static inline struct pppox_sock *delete_
static void pppoe_flush_dev(struct net_device *dev)
{
- int hash;
+ struct pppoe_net *pn;
+ int i;
+
BUG_ON(dev == NULL);
- write_lock_bh(&pppoe_hash_lock);
- for (hash = 0; hash < PPPOE_HASH_SIZE; hash++) {
- struct pppox_sock *po = item_hash_table[hash];
+ pn = pppoe_pernet(dev_net(dev));
+ if (!pn) /* already freed */
+ return;
+
+ write_lock_bh(&pn->hash_lock);
+ for (i = 0; i < PPPOE_HASH_SIZE; i++) {
+ struct pppox_sock *po = pn->hash_table[i];
while (po != NULL) {
- struct sock *sk = sk_pppox(po);
+ struct sock *sk;
if (po->pppoe_dev != dev) {
po = po->next;
continue;
}
+ sk = sk_pppox(po);
+ spin_lock(&flush_lock);
po->pppoe_dev = NULL;
+ spin_unlock(&flush_lock);
dev_put(dev);
-
/* We always grab the socket lock, followed by the
- * pppoe_hash_lock, in that order. Since we should
+ * hash_lock, in that order. Since we should
* hold the sock lock while doing any unbinding,
* we need to release the lock we're holding.
* Hold a reference to the sock so it doesn't disappear
@@ -288,7 +326,7 @@ static void pppoe_flush_dev(struct net_d
sock_hold(sk);
- write_unlock_bh(&pppoe_hash_lock);
+ write_unlock_bh(&pn->hash_lock);
lock_sock(sk);
if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
@@ -304,20 +342,17 @@ static void pppoe_flush_dev(struct net_d
* While the lock was dropped the chain contents may
* have changed.
*/
- write_lock_bh(&pppoe_hash_lock);
- po = item_hash_table[hash];
+ write_lock_bh(&pn->hash_lock);
+ po = pn->hash_table[i];
}
}
- write_unlock_bh(&pppoe_hash_lock);
+ write_unlock_bh(&pn->hash_lock);
}
static int pppoe_device_event(struct notifier_block *this,
unsigned long event, void *ptr)
{
- struct net_device *dev = (struct net_device *) ptr;
-
- if (dev_net(dev) != &init_net)
- return NOTIFY_DONE;
+ struct net_device *dev = (struct net_device *)ptr;
/* Only look at sockets that are using this specific device. */
switch (event) {
@@ -339,7 +374,6 @@ static int pppoe_device_event(struct not
return NOTIFY_DONE;
}
-
static struct notifier_block pppoe_notifier = {
.notifier_call = pppoe_device_event,
};
@@ -357,8 +391,8 @@ static int pppoe_rcv_core(struct sock *s
if (sk->sk_state & PPPOX_BOUND) {
ppp_input(&po->chan, skb);
} else if (sk->sk_state & PPPOX_RELAY) {
- relay_po = get_item_by_addr(&po->pppoe_relay);
-
+ relay_po = get_item_by_addr(dev_net(po->pppoe_dev),
+ &po->pppoe_relay);
if (relay_po == NULL)
goto abort_kfree;
@@ -387,23 +421,18 @@ abort_kfree:
* Receive wrapper called in BH context.
*
***********************************************************************/
-static int pppoe_rcv(struct sk_buff *skb,
- struct net_device *dev,
- struct packet_type *pt,
- struct net_device *orig_dev)
-
+static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,
+ struct packet_type *pt, struct net_device *orig_dev)
{
struct pppoe_hdr *ph;
struct pppox_sock *po;
+ struct pppoe_net *pn;
int len;
skb = skb_share_check(skb, GFP_ATOMIC);
if (!skb)
goto out;
- if (dev_net(dev) != &init_net)
- goto drop;
-
if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
goto drop;
@@ -417,7 +446,8 @@ static int pppoe_rcv(struct sk_buff *skb
if (pskb_trim_rcsum(skb, len))
goto drop;
- po = get_item(ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
+ pn = pppoe_pernet(dev_net(dev));
+ po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
if (!po)
goto drop;
@@ -435,17 +465,13 @@ out:
* This is solely for detection of PADT frames
*
***********************************************************************/
-static int pppoe_disc_rcv(struct sk_buff *skb,
- struct net_device *dev,
- struct packet_type *pt,
- struct net_device *orig_dev)
+static int pppoe_disc_rcv(struct sk_buff *skb, struct net_device *dev,
+ struct packet_type *pt, struct net_device *orig_dev)
{
struct pppoe_hdr *ph;
struct pppox_sock *po;
-
- if (dev_net(dev) != &init_net)
- goto abort;
+ struct pppoe_net *pn;
skb = skb_share_check(skb, GFP_ATOMIC);
if (!skb)
@@ -458,7 +484,8 @@ static int pppoe_disc_rcv(struct sk_buff
if (ph->code != PADT_CODE)
goto abort;
- po = get_item(ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
+ pn = pppoe_pernet(dev_net(dev));
+ po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
if (po) {
struct sock *sk = sk_pppox(po);
@@ -517,14 +544,14 @@ static int pppoe_create(struct net *net,
sock_init_data(sock, sk);
- sock->state = SS_UNCONNECTED;
- sock->ops = &pppoe_ops;
+ sock->state = SS_UNCONNECTED;
+ sock->ops = &pppoe_ops;
- sk->sk_backlog_rcv = pppoe_rcv_core;
- sk->sk_state = PPPOX_NONE;
- sk->sk_type = SOCK_STREAM;
- sk->sk_family = PF_PPPOX;
- sk->sk_protocol = PX_PROTO_OE;
+ sk->sk_backlog_rcv = pppoe_rcv_core;
+ sk->sk_state = PPPOX_NONE;
+ sk->sk_type = SOCK_STREAM;
+ sk->sk_family = PF_PPPOX;
+ sk->sk_protocol = PX_PROTO_OE;
return 0;
}
@@ -533,6 +560,7 @@ static int pppoe_release(struct socket *
{
struct sock *sk = sock->sk;
struct pppox_sock *po;
+ struct pppoe_net *pn;
if (!sk)
return 0;
@@ -548,26 +576,39 @@ static int pppoe_release(struct socket *
/* Signal the death of the socket. */
sk->sk_state = PPPOX_DEAD;
+ /*
+ * pppoe_flush_dev could lead to a race with
+ * this routine so we use flush_lock to eliminate
+ * such a case (we only need per-net specific data)
+ */
+ spin_lock(&flush_lock);
+ po = pppox_sk(sk);
+ if (!po->pppoe_dev) {
+ spin_unlock(&flush_lock);
+ goto out;
+ }
+ pn = pppoe_pernet(dev_net(po->pppoe_dev));
+ spin_unlock(&flush_lock);
- /* Write lock on hash lock protects the entire "po" struct from
- * concurrent updates via pppoe_flush_dev. The "po" struct should
- * be considered part of the hash table contents, thus protected
- * by the hash table lock */
- write_lock_bh(&pppoe_hash_lock);
+ /*
+ * protect "po" from concurrent updates
+ * on pppoe_flush_dev
+ */
+ write_lock_bh(&pn->hash_lock);
po = pppox_sk(sk);
- if (stage_session(po->pppoe_pa.sid)) {
- __delete_item(po->pppoe_pa.sid,
- po->pppoe_pa.remote, po->pppoe_ifindex);
- }
+ if (stage_session(po->pppoe_pa.sid))
+ __delete_item(pn, po->pppoe_pa.sid, po->pppoe_pa.remote,
+ po->pppoe_ifindex);
if (po->pppoe_dev) {
dev_put(po->pppoe_dev);
po->pppoe_dev = NULL;
}
- write_unlock_bh(&pppoe_hash_lock);
+ write_unlock_bh(&pn->hash_lock);
+out:
sock_orphan(sk);
sock->sk = NULL;
@@ -582,9 +623,10 @@ static int pppoe_connect(struct socket *
int sockaddr_len, int flags)
{
struct sock *sk = sock->sk;
- struct net_device *dev;
- struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
+ struct sockaddr_pppox *sp = (struct sockaddr_pppox *)uservaddr;
struct pppox_sock *po = pppox_sk(sk);
+ struct net_device *dev;
+ struct pppoe_net *pn;
int error;
lock_sock(sk);
@@ -610,9 +652,12 @@ static int pppoe_connect(struct socket *
/* Delete the old binding */
if (stage_session(po->pppoe_pa.sid)) {
pppox_unbind_sock(sk);
- delete_item(po->pppoe_pa.sid, po->pppoe_pa.remote, po->pppoe_ifindex);
- if (po->pppoe_dev)
+ if (po->pppoe_dev) {
+ pn = pppoe_pernet(dev_net(po->pppoe_dev));
+ delete_item(pn, po->pppoe_pa.sid,
+ po->pppoe_pa.remote, po->pppoe_ifindex);
dev_put(po->pppoe_dev);
+ }
memset(sk_pppox(po) + 1, 0,
sizeof(struct pppox_sock) - sizeof(struct sock));
sk->sk_state = PPPOX_NONE;
@@ -620,18 +665,17 @@ static int pppoe_connect(struct socket *
/* Re-bind in session stage only */
if (stage_session(sp->sa_addr.pppoe.sid)) {
- dev = dev_get_by_name(&init_net, sp->sa_addr.pppoe.dev);
-
error = -ENODEV;
+ dev = dev_get_by_name(current->nsproxy->net_ns, sp->sa_addr.pppoe.dev);
if (!dev)
goto end;
po->pppoe_dev = dev;
po->pppoe_ifindex = dev->ifindex;
-
- write_lock_bh(&pppoe_hash_lock);
+ pn = pppoe_pernet(dev_net(dev));
+ write_lock_bh(&pn->hash_lock);
if (!(dev->flags & IFF_UP)) {
- write_unlock_bh(&pppoe_hash_lock);
+ write_unlock_bh(&pn->hash_lock);
goto err_put;
}
@@ -639,8 +683,8 @@ static int pppoe_connect(struct socket *
&sp->sa_addr.pppoe,
sizeof(struct pppoe_addr));
- error = __set_item(po);
- write_unlock_bh(&pppoe_hash_lock);
+ error = __set_item(pn, po);
+ write_unlock_bh(&pn->hash_lock);
if (error < 0)
goto err_put;
@@ -700,7 +744,6 @@ static int pppoe_ioctl(struct socket *so
switch (cmd) {
case PPPIOCGMRU:
err = -ENXIO;
-
if (!(sk->sk_state & PPPOX_CONNECTED))
break;
@@ -708,7 +751,7 @@ static int pppoe_ioctl(struct socket *so
if (put_user(po->pppoe_dev->mtu -
sizeof(struct pppoe_hdr) -
PPP_HDRLEN,
- (int __user *) arg))
+ (int __user *)arg))
break;
err = 0;
break;
@@ -764,8 +807,8 @@ static int pppoe_ioctl(struct socket *so
/* Check that the socket referenced by the address
actually exists. */
- relay_po = get_item_by_addr(&po->pppoe_relay);
-
+ relay_po = get_item_by_addr(current->nsproxy->net_ns,
+ &po->pppoe_relay);
if (!relay_po)
break;
@@ -837,11 +880,10 @@ static int pppoe_sendmsg(struct kiocb *i
skb->priority = sk->sk_priority;
skb->protocol = __constant_htons(ETH_P_PPP_SES);
- ph = (struct pppoe_hdr *) skb_put(skb, total_len + sizeof(struct pppoe_hdr));
- start = (char *) &ph->tag[0];
+ ph = (struct pppoe_hdr *)skb_put(skb, total_len + sizeof(struct pppoe_hdr));
+ start = (char *)&ph->tag[0];
error = memcpy_fromiovec(start, m->msg_iov, total_len);
-
if (error < 0) {
kfree_skb(skb);
goto end;
@@ -919,7 +961,7 @@ abort:
***********************************************************************/
static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
{
- struct sock *sk = (struct sock *) chan->private;
+ struct sock *sk = (struct sock *)chan->private;
return __pppoe_xmit(sk, skb);
}
@@ -941,7 +983,6 @@ static int pppoe_recvmsg(struct kiocb *i
skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
flags & MSG_DONTWAIT, &error);
-
if (error < 0)
goto end;
@@ -964,6 +1005,7 @@ static int pppoe_seq_show(struct seq_fil
{
struct pppox_sock *po;
char *dev_name;
+ DECLARE_MAC_BUF(mac);
if (v == SEQ_START_TOKEN) {
seq_puts(seq, "Id Address Device\n");
@@ -974,44 +1016,47 @@ static int pppoe_seq_show(struct seq_fil
dev_name = po->pppoe_pa.dev;
seq_printf(seq, "%08X %pM %8s\n",
- po->pppoe_pa.sid, po->pppoe_pa.remote, dev_name);
+ po->pppoe_pa.sid, po->pppoe_pa.remote, dev_name);
out:
return 0;
}
-static __inline__ struct pppox_sock *pppoe_get_idx(loff_t pos)
+static inline struct pppox_sock *pppoe_get_idx(struct pppoe_net *pn, loff_t pos)
{
struct pppox_sock *po;
int i;
for (i = 0; i < PPPOE_HASH_SIZE; i++) {
- po = item_hash_table[i];
+ po = pn->hash_table[i];
while (po) {
if (!pos--)
goto out;
po = po->next;
}
}
+
out:
return po;
}
static void *pppoe_seq_start(struct seq_file *seq, loff_t *pos)
- __acquires(pppoe_hash_lock)
+ __acquires(pn->hash_lock)
{
+ struct pppoe_net *pn = pppoe_pernet(seq->private);
loff_t l = *pos;
- read_lock_bh(&pppoe_hash_lock);
- return l ? pppoe_get_idx(--l) : SEQ_START_TOKEN;
+ read_lock_bh(&pn->hash_lock);
+ return l ? pppoe_get_idx(pn, --l) : SEQ_START_TOKEN;
}
static void *pppoe_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
+ struct pppoe_net *pn = pppoe_pernet(seq->private);
struct pppox_sock *po;
++*pos;
if (v == SEQ_START_TOKEN) {
- po = pppoe_get_idx(0);
+ po = pppoe_get_idx(pn, 0);
goto out;
}
po = v;
@@ -1021,19 +1066,21 @@ static void *pppoe_seq_next(struct seq_f
int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
while (++hash < PPPOE_HASH_SIZE) {
- po = item_hash_table[hash];
+ po = pn->hash_table[hash];
if (po)
break;
}
}
+
out:
return po;
}
static void pppoe_seq_stop(struct seq_file *seq, void *v)
- __releases(pppoe_hash_lock)
+ __releases(pn->hash_lock)
{
- read_unlock_bh(&pppoe_hash_lock);
+ struct pppoe_net *pn = pppoe_pernet(seq->private);
+ read_unlock_bh(&pn->hash_lock);
}
static struct seq_operations pppoe_seq_ops = {
@@ -1045,7 +1092,30 @@ static struct seq_operations pppoe_seq_o
static int pppoe_seq_open(struct inode *inode, struct file *file)
{
- return seq_open(file, &pppoe_seq_ops);
+ struct seq_file *m;
+ struct net *net;
+ int err;
+
+ err = seq_open(file, &pppoe_seq_ops);
+ if (err)
+ return err;
+
+ m = file->private_data;
+ net = maybe_get_net(PDE_NET(PDE(inode)));
+ BUG_ON(!net);
+ m->private = net;
+
+ return err;
+}
+
+static int pppoe_seq_release(struct inode *inode, struct file *file)
+{
+ struct seq_file *m;
+
+ m = file->private_data;
+ put_net((struct net*)m->private);
+
+ return seq_release(inode, file);
}
static const struct file_operations pppoe_seq_fops = {
@@ -1053,20 +1123,9 @@ static const struct file_operations pppo
.open = pppoe_seq_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = seq_release,
+ .release = pppoe_seq_release,
};
-static int __init pppoe_proc_init(void)
-{
- struct proc_dir_entry *p;
-
- p = proc_net_fops_create(&init_net, "pppoe", S_IRUGO, &pppoe_seq_fops);
- if (!p)
- return -ENOMEM;
- return 0;
-}
-#else /* CONFIG_PROC_FS */
-static inline int pppoe_proc_init(void) { return 0; }
#endif /* CONFIG_PROC_FS */
static const struct proto_ops pppoe_ops = {
@@ -1095,10 +1154,65 @@ static struct pppox_proto pppoe_proto =
.owner = THIS_MODULE,
};
+static __net_init int pppoe_init_net(struct net *net)
+{
+ struct pppoe_net *pn;
+ struct proc_dir_entry *pde;
+ int err;
+
+ pn = kzalloc(sizeof(*pn), GFP_KERNEL);
+ if (!pn)
+ return -ENOMEM;
+
+ rwlock_init(&pn->hash_lock);
+
+ err = net_assign_generic(net, pppoe_net_id, pn);
+ if (err)
+ goto out;
+
+ pde = proc_net_fops_create(net, "pppoe", S_IRUGO, &pppoe_seq_fops);
+#ifdef CONFIG_PROC_FS
+ if (!pde) {
+ err = -ENOMEM;
+ goto out;
+ }
+#endif
+
+ try_module_get(THIS_MODULE);
+
+ return 0;
+
+out:
+ kfree(pn);
+ return err;
+}
+
+static __net_exit void pppoe_exit_net(struct net *net)
+{
+ struct pppoe_net *pn;
+
+ proc_net_remove(net, "pppoe");
+ pn = net_generic(net, pppoe_net_id);
+ /*
+ * if someone has cached our net then
+ * further net_generic call will return NULL
+ */
+ net_assign_generic(net, pppoe_net_id, NULL);
+ kfree(pn);
+
+ module_put(THIS_MODULE);
+}
+
+static __net_initdata struct pernet_operations pppoe_net_ops = {
+ .init = pppoe_init_net,
+ .exit = pppoe_exit_net,
+};
+
static int __init pppoe_init(void)
{
- int err = proto_register(&pppoe_sk_proto, 0);
+ int err;
+ err = proto_register(&pppoe_sk_proto, 0);
if (err)
goto out;
@@ -1106,20 +1220,22 @@ static int __init pppoe_init(void)
if (err)
goto out_unregister_pppoe_proto;
- err = pppoe_proc_init();
+ err = register_pernet_gen_device(&pppoe_net_id, &pppoe_net_ops);
if (err)
goto out_unregister_pppox_proto;
dev_add_pack(&pppoes_ptype);
dev_add_pack(&pppoed_ptype);
register_netdevice_notifier(&pppoe_notifier);
-out:
- return err;
+
+ return 0;
+
out_unregister_pppox_proto:
unregister_pppox_proto(PX_PROTO_OE);
out_unregister_pppoe_proto:
proto_unregister(&pppoe_sk_proto);
- goto out;
+out:
+ return err;
}
static void __exit pppoe_exit(void)
@@ -1128,7 +1244,7 @@ static void __exit pppoe_exit(void)
dev_remove_pack(&pppoes_ptype);
dev_remove_pack(&pppoed_ptype);
unregister_netdevice_notifier(&pppoe_notifier);
- remove_proc_entry("pppoe", init_net.proc_net);
+ unregister_pernet_gen_device(pppoe_net_id, &pppoe_net_ops);
proto_unregister(&pppoe_sk_proto);
}
@@ -1139,3 +1255,4 @@ MODULE_AUTHOR("Michal Ostrowski <mostrow
MODULE_DESCRIPTION("PPP over Ethernet driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS_NETPROTO(PF_PPPOX);
+
Index: linux-2.6.git/drivers/net/pppox.c
===================================================================
--- linux-2.6.git.orig/drivers/net/pppox.c
+++ linux-2.6.git/drivers/net/pppox.c
@@ -108,12 +108,13 @@ static int pppox_create(struct net *net,
{
int rc = -EPROTOTYPE;
- if (net != &init_net)
- return -EAFNOSUPPORT;
-
if (protocol < 0 || protocol > PX_MAX_PROTO)
goto out;
+ /* we support net-namespaces for PPPoE only (yet) */
+ if (protocol != PX_PROTO_OE && net != &init_net)
+ return -EAFNOSUPPORT;
+
rc = -EPROTONOSUPPORT;
if (!pppox_protos[protocol])
request_module("pppox-proto-%d", protocol);
--
^ permalink raw reply [flat|nested] 20+ messages in thread* [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
[not found] <20090109195154.320495476@gmail.com>
2009-01-09 19:51 ` [RFC 1/4] net: pppoe - code cleanup and helpers Cyrill Gorcunov
2009-01-09 19:51 ` [RFC 2/4] net: pppoe - introduce net-namespace functionality Cyrill Gorcunov
@ 2009-01-09 19:51 ` Cyrill Gorcunov
2009-01-10 11:06 ` James Chapman
2009-01-09 19:51 ` [RFC 4/4] net: ppp_generic " Cyrill Gorcunov
3 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-09 19:51 UTC (permalink / raw)
To: davem, linux-kernel, netdev
Cc: gorcunov, devel, xemul, James Chapman, Cyrill Gorcunov
[-- Attachment #1: net-pppol2tp-namespace --]
[-- Type: text/plain, Size: 11457 bytes --]
- Each tunnel and appropriate lock are inside own namespace now.
- pppox code allows to create per-namespace sockets for
both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
now pppox_create support net-namespaces new PPPo... protocols
(if they ever will be) should support net-namespace too otherwise
explicit check for &init_net would be needed.
CC: James Chapman <jchapman@katalix.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
drivers/net/pppol2tp.c | 164 ++++++++++++++++++++++++++++++++++++-------------
drivers/net/pppox.c | 4 -
2 files changed, 121 insertions(+), 47 deletions(-)
Index: linux-2.6.git/drivers/net/pppol2tp.c
===================================================================
--- linux-2.6.git.orig/drivers/net/pppol2tp.c
+++ linux-2.6.git/drivers/net/pppol2tp.c
@@ -90,7 +90,9 @@
#include <linux/hash.h>
#include <linux/sort.h>
#include <linux/proc_fs.h>
+#include <linux/nsproxy.h>
#include <net/net_namespace.h>
+#include <net/netns/generic.h>
#include <net/dst.h>
#include <net/ip.h>
#include <net/udp.h>
@@ -204,6 +206,7 @@ struct pppol2tp_tunnel
struct sock *sock; /* Parent socket */
struct list_head list; /* Keep a list of all open
* prepared sockets */
+ struct net *pppol2tp_net; /* the net we belong to */
atomic_t ref_count;
};
@@ -227,8 +230,20 @@ static atomic_t pppol2tp_tunnel_count;
static atomic_t pppol2tp_session_count;
static struct ppp_channel_ops pppol2tp_chan_ops = { pppol2tp_xmit , NULL };
static struct proto_ops pppol2tp_ops;
-static LIST_HEAD(pppol2tp_tunnel_list);
-static DEFINE_RWLOCK(pppol2tp_tunnel_list_lock);
+
+/* per-net private data for this module */
+static unsigned int pppol2tp_net_id;
+struct pppol2tp_net {
+ struct list_head pppol2tp_tunnel_list;
+ rwlock_t pppol2tp_tunnel_list_lock;
+};
+
+static inline struct pppol2tp_net *pppol2tp_pernet(struct net *net)
+{
+ BUG_ON(!net);
+
+ return net_generic(net, pppol2tp_net_id);
+}
/* Helpers to obtain tunnel/session contexts from sockets.
*/
@@ -321,18 +336,19 @@ pppol2tp_session_find(struct pppol2tp_tu
/* Lookup a tunnel by id
*/
-static struct pppol2tp_tunnel *pppol2tp_tunnel_find(u16 tunnel_id)
+static struct pppol2tp_tunnel *pppol2tp_tunnel_find(struct net *net, u16 tunnel_id)
{
- struct pppol2tp_tunnel *tunnel = NULL;
+ struct pppol2tp_tunnel *tunnel;
+ struct pppol2tp_net *pn = pppol2tp_pernet(net);
- read_lock_bh(&pppol2tp_tunnel_list_lock);
- list_for_each_entry(tunnel, &pppol2tp_tunnel_list, list) {
+ read_lock_bh(&pn->pppol2tp_tunnel_list_lock);
+ list_for_each_entry(tunnel, &pn->pppol2tp_tunnel_list, list) {
if (tunnel->stats.tunnel_id == tunnel_id) {
- read_unlock_bh(&pppol2tp_tunnel_list_lock);
+ read_unlock_bh(&pn->pppol2tp_tunnel_list_lock);
return tunnel;
}
}
- read_unlock_bh(&pppol2tp_tunnel_list_lock);
+ read_unlock_bh(&pn->pppol2tp_tunnel_list_lock);
return NULL;
}
@@ -1287,10 +1303,12 @@ again:
*/
static void pppol2tp_tunnel_free(struct pppol2tp_tunnel *tunnel)
{
+ struct pppol2tp_net *pn = pppol2tp_pernet(tunnel->pppol2tp_net);
+
/* Remove from socket list */
- write_lock_bh(&pppol2tp_tunnel_list_lock);
+ write_lock_bh(&pn->pppol2tp_tunnel_list_lock);
list_del_init(&tunnel->list);
- write_unlock_bh(&pppol2tp_tunnel_list_lock);
+ write_unlock_bh(&pn->pppol2tp_tunnel_list_lock);
atomic_dec(&pppol2tp_tunnel_count);
kfree(tunnel);
@@ -1444,13 +1462,14 @@ error:
/* Internal function to prepare a tunnel (UDP) socket to have PPPoX
* sockets attached to it.
*/
-static struct sock *pppol2tp_prepare_tunnel_socket(int fd, u16 tunnel_id,
- int *error)
+static struct sock *pppol2tp_prepare_tunnel_socket(struct net *net,
+ int fd, u16 tunnel_id, int *error)
{
int err;
struct socket *sock = NULL;
struct sock *sk;
struct pppol2tp_tunnel *tunnel;
+ struct pppol2tp_net *pn;
struct sock *ret = NULL;
/* Get the tunnel UDP socket from the fd, which was opened by
@@ -1524,11 +1543,15 @@ static struct sock *pppol2tp_prepare_tun
/* Misc init */
rwlock_init(&tunnel->hlist_lock);
+ /* The net we belong to */
+ tunnel->pppol2tp_net = net;
+ pn = pppol2tp_pernet(net);
+
/* Add tunnel to our list */
INIT_LIST_HEAD(&tunnel->list);
- write_lock_bh(&pppol2tp_tunnel_list_lock);
- list_add(&tunnel->list, &pppol2tp_tunnel_list);
- write_unlock_bh(&pppol2tp_tunnel_list_lock);
+ write_lock_bh(&pn->pppol2tp_tunnel_list_lock);
+ list_add(&tunnel->list, &pn->pppol2tp_tunnel_list);
+ write_unlock_bh(&pn->pppol2tp_tunnel_list_lock);
atomic_inc(&pppol2tp_tunnel_count);
/* Bump the reference count. The tunnel context is deleted
@@ -1629,7 +1652,8 @@ static int pppol2tp_connect(struct socke
* tunnel id.
*/
if ((sp->pppol2tp.s_session == 0) && (sp->pppol2tp.d_session == 0)) {
- tunnel_sock = pppol2tp_prepare_tunnel_socket(sp->pppol2tp.fd,
+ tunnel_sock = pppol2tp_prepare_tunnel_socket(current->nsproxy->net_ns,
+ sp->pppol2tp.fd,
sp->pppol2tp.s_tunnel,
&error);
if (tunnel_sock == NULL)
@@ -1637,7 +1661,7 @@ static int pppol2tp_connect(struct socke
tunnel = tunnel_sock->sk_user_data;
} else {
- tunnel = pppol2tp_tunnel_find(sp->pppol2tp.s_tunnel);
+ tunnel = pppol2tp_tunnel_find(current->nsproxy->net_ns, sp->pppol2tp.s_tunnel);
/* Error if we can't find the tunnel */
error = -ENOENT;
@@ -2347,8 +2371,9 @@ end:
#include <linux/seq_file.h>
struct pppol2tp_seq_data {
- struct pppol2tp_tunnel *tunnel; /* current tunnel */
- struct pppol2tp_session *session; /* NULL means get first session in tunnel */
+ struct net *seq_net; /* net of inode */
+ struct pppol2tp_tunnel *tunnel; /* current tunnel */
+ struct pppol2tp_session *session; /* NULL means get first session in tunnel */
};
static struct pppol2tp_session *next_session(struct pppol2tp_tunnel *tunnel, struct pppol2tp_session *curr)
@@ -2384,17 +2409,18 @@ out:
return session;
}
-static struct pppol2tp_tunnel *next_tunnel(struct pppol2tp_tunnel *curr)
+static struct pppol2tp_tunnel *next_tunnel(struct pppol2tp_net *pn,
+ struct pppol2tp_tunnel *curr)
{
struct pppol2tp_tunnel *tunnel = NULL;
- read_lock_bh(&pppol2tp_tunnel_list_lock);
- if (list_is_last(&curr->list, &pppol2tp_tunnel_list)) {
+ read_lock_bh(&pn->pppol2tp_tunnel_list_lock);
+ if (list_is_last(&curr->list, &pn->pppol2tp_tunnel_list)) {
goto out;
}
tunnel = list_entry(curr->list.next, struct pppol2tp_tunnel, list);
out:
- read_unlock_bh(&pppol2tp_tunnel_list_lock);
+ read_unlock_bh(&pn->pppol2tp_tunnel_list_lock);
return tunnel;
}
@@ -2402,6 +2428,7 @@ out:
static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
{
struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
+ struct pppol2tp_net *pn;
loff_t pos = *offs;
if (!pos)
@@ -2409,14 +2436,15 @@ static void *pppol2tp_seq_start(struct s
BUG_ON(m->private == NULL);
pd = m->private;
+ pn = pppol2tp_pernet(pd->seq_net);
if (pd->tunnel == NULL) {
- if (!list_empty(&pppol2tp_tunnel_list))
- pd->tunnel = list_entry(pppol2tp_tunnel_list.next, struct pppol2tp_tunnel, list);
+ if (!list_empty(&pn->pppol2tp_tunnel_list))
+ pd->tunnel = list_entry(pn->pppol2tp_tunnel_list.next, struct pppol2tp_tunnel, list);
} else {
pd->session = next_session(pd->tunnel, pd->session);
if (pd->session == NULL) {
- pd->tunnel = next_tunnel(pd->tunnel);
+ pd->tunnel = next_tunnel(pn, pd->tunnel);
}
}
@@ -2532,6 +2560,7 @@ static int pppol2tp_proc_open(struct ino
{
struct seq_file *m;
struct pppol2tp_seq_data *pd;
+ struct net *net;
int ret = 0;
ret = seq_open(file, &pppol2tp_seq_ops);
@@ -2542,12 +2571,15 @@ static int pppol2tp_proc_open(struct ino
/* Allocate and fill our proc_data for access later */
ret = -ENOMEM;
- m->private = kzalloc(sizeof(struct pppol2tp_seq_data), GFP_KERNEL);
+ m->private = kzalloc(sizeof(*pd), GFP_KERNEL);
if (m->private == NULL)
goto out;
pd = m->private;
- ret = 0;
+ net = maybe_get_net(PDE_NET(PDE(inode)));
+ BUG_ON(!net);
+ pd->seq_net = net;
+ return 0;
out:
return ret;
@@ -2558,6 +2590,9 @@ out:
static int pppol2tp_proc_release(struct inode *inode, struct file *file)
{
struct seq_file *m = (struct seq_file *)file->private_data;
+ struct pppol2tp_seq_data *pd = m->private;
+
+ put_net(pd->seq_net);
kfree(m->private);
m->private = NULL;
@@ -2573,8 +2608,6 @@ static struct file_operations pppol2tp_p
.release = pppol2tp_proc_release,
};
-static struct proc_dir_entry *pppol2tp_proc;
-
#endif /* CONFIG_PROC_FS */
/*****************************************************************************
@@ -2606,6 +2639,61 @@ static struct pppox_proto pppol2tp_proto
.ioctl = pppol2tp_ioctl
};
+static __net_init int pppol2tp_init_net(struct net *net)
+{
+ struct pppol2tp_net *pn;
+ struct proc_dir_entry *pde;
+ int err;
+
+ pn = kzalloc(sizeof(*pn), GFP_KERNEL);
+ if (!pn)
+ return -ENOMEM;
+
+ INIT_LIST_HEAD(&pn->pppol2tp_tunnel_list);
+ rwlock_init(&pn->pppol2tp_tunnel_list_lock);
+
+ err = net_assign_generic(net, pppol2tp_net_id, pn);
+ if (err)
+ goto out;
+
+ pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops);
+#ifdef CONFIG_PROC_FS
+ if (!pde) {
+ err = -ENOMEM;
+ goto out;
+ }
+#endif
+
+ try_module_get(THIS_MODULE);
+
+ return 0;
+
+out:
+ kfree(pn);
+ return err;
+}
+
+static __net_exit void pppol2tp_exit_net(struct net *net)
+{
+ struct pppoe_net *pn;
+
+ proc_net_remove(net, "pppol2tp");
+ pn = net_generic(net, pppol2tp_net_id);
+ /*
+ * if someone has cached our net then
+ * further net_generic call will return NULL
+ */
+ net_assign_generic(net, pppol2tp_net_id, NULL);
+ kfree(pn);
+
+ module_put(THIS_MODULE);
+}
+
+static __net_initdata struct pernet_operations pppol2tp_net_ops = {
+ .init = pppol2tp_init_net,
+ .exit = pppol2tp_exit_net,
+};
+
static int __init pppol2tp_init(void)
{
int err;
@@ -2617,23 +2705,17 @@ static int __init pppol2tp_init(void)
if (err)
goto out_unregister_pppol2tp_proto;
-#ifdef CONFIG_PROC_FS
- pppol2tp_proc = proc_net_fops_create(&init_net, "pppol2tp", 0,
- &pppol2tp_proc_fops);
- if (!pppol2tp_proc) {
- err = -ENOMEM;
+ err = register_pernet_gen_device(&pppol2tp_net_id, &pppol2tp_net_ops);
+ if (err)
goto out_unregister_pppox_proto;
- }
-#endif /* CONFIG_PROC_FS */
+
printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
PPPOL2TP_DRV_VERSION);
out:
return err;
-#ifdef CONFIG_PROC_FS
out_unregister_pppox_proto:
unregister_pppox_proto(PX_PROTO_OL2TP);
-#endif
out_unregister_pppol2tp_proto:
proto_unregister(&pppol2tp_sk_proto);
goto out;
@@ -2642,10 +2724,6 @@ out_unregister_pppol2tp_proto:
static void __exit pppol2tp_exit(void)
{
unregister_pppox_proto(PX_PROTO_OL2TP);
-
-#ifdef CONFIG_PROC_FS
- remove_proc_entry("pppol2tp", init_net.proc_net);
-#endif
proto_unregister(&pppol2tp_sk_proto);
}
Index: linux-2.6.git/drivers/net/pppox.c
===================================================================
--- linux-2.6.git.orig/drivers/net/pppox.c
+++ linux-2.6.git/drivers/net/pppox.c
@@ -111,10 +111,6 @@ static int pppox_create(struct net *net,
if (protocol < 0 || protocol > PX_MAX_PROTO)
goto out;
- /* we support net-namespaces for PPPoE only (yet) */
- if (protocol != PX_PROTO_OE && net != &init_net)
- return -EAFNOSUPPORT;
-
rc = -EPROTONOSUPPORT;
if (!pppox_protos[protocol])
request_module("pppox-proto-%d", protocol);
--
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-09 19:51 ` [RFC 3/4] net: pppol2tp " Cyrill Gorcunov
@ 2009-01-10 11:06 ` James Chapman
2009-01-10 11:13 ` Cyrill Gorcunov
0 siblings, 1 reply; 20+ messages in thread
From: James Chapman @ 2009-01-10 11:06 UTC (permalink / raw)
To: Cyrill Gorcunov
Cc: davem, linux-kernel, netdev, devel, xemul, Cyrill Gorcunov
Cyrill Gorcunov wrote:
> - Each tunnel and appropriate lock are inside own namespace now.
> - pppox code allows to create per-namespace sockets for
> both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
> now pppox_create support net-namespaces new PPPo... protocols
> (if they ever will be) should support net-namespace too otherwise
> explicit check for &init_net would be needed.
>
> CC: James Chapman <jchapman@katalix.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> ---
> drivers/net/pppol2tp.c | 164 ++++++++++++++++++++++++++++++++++++-------------
> drivers/net/pppox.c | 4 -
> 2 files changed, 121 insertions(+), 47 deletions(-)
Looks ok from a pppol2tp point of view, though I'm not an expert on the
netns stuff.
The patches don't apply against latest net-next-2.6. If you respin the
patches, I'll test them for pppol2tp.
--
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 11:06 ` James Chapman
@ 2009-01-10 11:13 ` Cyrill Gorcunov
2009-01-10 12:54 ` Cyrill Gorcunov
0 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 11:13 UTC (permalink / raw)
To: James Chapman; +Cc: davem, linux-kernel, netdev, devel, xemul
[James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
| Cyrill Gorcunov wrote:
| > - Each tunnel and appropriate lock are inside own namespace now.
| > - pppox code allows to create per-namespace sockets for
| > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
| > now pppox_create support net-namespaces new PPPo... protocols
| > (if they ever will be) should support net-namespace too otherwise
| > explicit check for &init_net would be needed.
| >
| > CC: James Chapman <jchapman@katalix.com>
| > Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
| > ---
| > drivers/net/pppol2tp.c | 164 ++++++++++++++++++++++++++++++++++++-------------
| > drivers/net/pppox.c | 4 -
| > 2 files changed, 121 insertions(+), 47 deletions(-)
|
| Looks ok from a pppol2tp point of view, though I'm not an expert on the
| netns stuff.
|
| The patches don't apply against latest net-next-2.6. If you respin the
| patches, I'll test them for pppol2tp.
|
| --
| James Chapman
| Katalix Systems Ltd
| http://www.katalix.com
| Catalysts for your Embedded Linux software development
|
Thanks James for taken look on. I'll check the latest net-next-2.6
tree and update the patches soon. Thanks!
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 11:13 ` Cyrill Gorcunov
@ 2009-01-10 12:54 ` Cyrill Gorcunov
2009-01-10 13:13 ` James Chapman
` (2 more replies)
0 siblings, 3 replies; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 12:54 UTC (permalink / raw)
To: James Chapman, davem, linux-kernel, netdev, devel, xemul
[Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
| [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
| | Cyrill Gorcunov wrote:
| | > - Each tunnel and appropriate lock are inside own namespace now.
| | > - pppox code allows to create per-namespace sockets for
| | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
| | > now pppox_create support net-namespaces new PPPo... protocols
| | > (if they ever will be) should support net-namespace too otherwise
| | > explicit check for &init_net would be needed.
| | >
| | > CC: James Chapman <jchapman@katalix.com>
| | > Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
| | > ---
| | > drivers/net/pppol2tp.c | 164 ++++++++++++++++++++++++++++++++++++-------------
| | > drivers/net/pppox.c | 4 -
| | > 2 files changed, 121 insertions(+), 47 deletions(-)
| |
| | Looks ok from a pppol2tp point of view, though I'm not an expert on the
| | netns stuff.
| |
| | The patches don't apply against latest net-next-2.6. If you respin the
| | patches, I'll test them for pppol2tp.
| |
| | --
| | James Chapman
| | Katalix Systems Ltd
| | http://www.katalix.com
| | Catalysts for your Embedded Linux software development
| |
|
| Thanks James for taken look on. I'll check the latest net-next-2.6
| tree and update the patches soon. Thanks!
|
| - Cyrill -
James I just fetched latest net-next-2.6 with
commit
---
commit 3c92ec8ae91ecf59d88c798301833d7cf83f2179
Merge: c4c9f01... ca9153a...
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Dec 28 16:54:33 2008 -0800
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
---
and patches are being applied on top without problems.
Maybe you have some other commits which are not propogated
to net-next-2.6 yet?
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 12:54 ` Cyrill Gorcunov
@ 2009-01-10 13:13 ` James Chapman
2009-01-10 15:05 ` James Chapman
2009-01-11 7:36 ` David Miller
2 siblings, 0 replies; 20+ messages in thread
From: James Chapman @ 2009-01-10 13:13 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: davem, linux-kernel, netdev, devel, xemul
Cyrill Gorcunov wrote:
> [Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
> | [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
> | | Cyrill Gorcunov wrote:
> | | > - Each tunnel and appropriate lock are inside own namespace now.
> | | > - pppox code allows to create per-namespace sockets for
> | | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
> | | > now pppox_create support net-namespaces new PPPo... protocols
> | | > (if they ever will be) should support net-namespace too otherwise
> | | > explicit check for &init_net would be needed.
> | | >
> | | > CC: James Chapman <jchapman@katalix.com>
> | | > Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> | | > ---
> | | > drivers/net/pppol2tp.c | 164 ++++++++++++++++++++++++++++++++++++-------------
> | | > drivers/net/pppox.c | 4 -
> | | > 2 files changed, 121 insertions(+), 47 deletions(-)
> | |
> | | Looks ok from a pppol2tp point of view, though I'm not an expert on the
> | | netns stuff.
> | |
> | | The patches don't apply against latest net-next-2.6. If you respin the
> | | patches, I'll test them for pppol2tp.
> | |
> | | --
> | | James Chapman
> | | Katalix Systems Ltd
> | | http://www.katalix.com
> | | Catalysts for your Embedded Linux software development
> | |
> |
> | Thanks James for taken look on. I'll check the latest net-next-2.6
> | tree and update the patches soon. Thanks!
> |
> | - Cyrill -
>
> James I just fetched latest net-next-2.6 with
> commit
>
> ---
> commit 3c92ec8ae91ecf59d88c798301833d7cf83f2179
> Merge: c4c9f01... ca9153a...
> Author: Linus Torvalds <torvalds@linux-foundation.org>
> Date: Sun Dec 28 16:54:33 2008 -0800
>
> Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
> ---
>
> and patches are being applied on top without problems.
> Maybe you have some other commits which are not propogated
> to net-next-2.6 yet?
My mistake. I missed one of the patches when applying the series.
--
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 12:54 ` Cyrill Gorcunov
2009-01-10 13:13 ` James Chapman
@ 2009-01-10 15:05 ` James Chapman
2009-01-10 15:19 ` Cyrill Gorcunov
2009-01-11 7:36 ` David Miller
2 siblings, 1 reply; 20+ messages in thread
From: James Chapman @ 2009-01-10 15:05 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: davem, linux-kernel, netdev, devel, xemul
Cyrill Gorcunov wrote:
> [Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
> | [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
> | | Cyrill Gorcunov wrote:
> | | > - Each tunnel and appropriate lock are inside own namespace now.
> | | > - pppox code allows to create per-namespace sockets for
> | | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
> | | > now pppox_create support net-namespaces new PPPo... protocols
> | | > (if they ever will be) should support net-namespace too otherwise
> | | > explicit check for &init_net would be needed.
Ok, I tested this in my L2TP setup. The first ppp session setup fails
because the PPPIOCNEWUNIT ioctl returns -EEXIST. I think the problem is
the logic in ppp_create_interface(), which does the following to create
a new ppp interface:
/* Initialize the new ppp unit */
ppp->file.index = unit;
sprintf(dev->name, "ppp%d", unit);
ret = register_netdev(dev);
Looks like there is more work to do in the ppp changes.
--
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 15:05 ` James Chapman
@ 2009-01-10 15:19 ` Cyrill Gorcunov
2009-01-10 16:12 ` Cyrill Gorcunov
0 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 15:19 UTC (permalink / raw)
To: James Chapman; +Cc: davem, linux-kernel, netdev, devel, xemul
[James Chapman - Sat, Jan 10, 2009 at 03:05:13PM +0000]
| Cyrill Gorcunov wrote:
| > [Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
| > | [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
| > | | Cyrill Gorcunov wrote:
| > | | > - Each tunnel and appropriate lock are inside own namespace now.
| > | | > - pppox code allows to create per-namespace sockets for
| > | | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
| > | | > now pppox_create support net-namespaces new PPPo... protocols
| > | | > (if they ever will be) should support net-namespace too otherwise
| > | | > explicit check for &init_net would be needed.
|
| Ok, I tested this in my L2TP setup. The first ppp session setup fails
| because the PPPIOCNEWUNIT ioctl returns -EEXIST. I think the problem is
| the logic in ppp_create_interface(), which does the following to create
| a new ppp interface:
|
| /* Initialize the new ppp unit */
| ppp->file.index = unit;
| sprintf(dev->name, "ppp%d", unit);
|
| ret = register_netdev(dev);
|
| Looks like there is more work to do in the ppp changes.
|
| --
| James Chapman
| Katalix Systems Ltd
| http://www.katalix.com
| Catalysts for your Embedded Linux software development
|
Thanks a lot James for testing!!! Will keep you in touch.
Thanks again!
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 15:19 ` Cyrill Gorcunov
@ 2009-01-10 16:12 ` Cyrill Gorcunov
2009-01-10 18:14 ` James Chapman
0 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 16:12 UTC (permalink / raw)
To: James Chapman, davem, linux-kernel, netdev, devel, xemul
[Cyrill Gorcunov - Sat, Jan 10, 2009 at 06:19:58PM +0300]
| [James Chapman - Sat, Jan 10, 2009 at 03:05:13PM +0000]
| | Cyrill Gorcunov wrote:
| | > [Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
| | > | [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
| | > | | Cyrill Gorcunov wrote:
| | > | | > - Each tunnel and appropriate lock are inside own namespace now.
| | > | | > - pppox code allows to create per-namespace sockets for
| | > | | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
| | > | | > now pppox_create support net-namespaces new PPPo... protocols
| | > | | > (if they ever will be) should support net-namespace too otherwise
| | > | | > explicit check for &init_net would be needed.
| |
| | Ok, I tested this in my L2TP setup. The first ppp session setup fails
| | because the PPPIOCNEWUNIT ioctl returns -EEXIST. I think the problem is
| | the logic in ppp_create_interface(), which does the following to create
| | a new ppp interface:
| |
| | /* Initialize the new ppp unit */
| | ppp->file.index = unit;
| | sprintf(dev->name, "ppp%d", unit);
| |
| | ret = register_netdev(dev);
| |
| | Looks like there is more work to do in the ppp changes.
| |
| | --
| | James Chapman
| | Katalix Systems Ltd
| | http://www.katalix.com
| | Catalysts for your Embedded Linux software development
| |
...
Btw James did connection work without these patches? On
pure net-next-2.6 tree? I've some bad feeling that this
fail is related to different patch. Just to be sure.
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 16:12 ` Cyrill Gorcunov
@ 2009-01-10 18:14 ` James Chapman
2009-01-10 18:51 ` Cyrill Gorcunov
0 siblings, 1 reply; 20+ messages in thread
From: James Chapman @ 2009-01-10 18:14 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: davem, linux-kernel, netdev, devel, xemul
Cyrill Gorcunov wrote:
> [Cyrill Gorcunov - Sat, Jan 10, 2009 at 06:19:58PM +0300]
> | [James Chapman - Sat, Jan 10, 2009 at 03:05:13PM +0000]
> | | Cyrill Gorcunov wrote:
> | | > [Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
> | | > | [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
> | | > | | Cyrill Gorcunov wrote:
> | | > | | > - Each tunnel and appropriate lock are inside own namespace now.
> | | > | | > - pppox code allows to create per-namespace sockets for
> | | > | | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
> | | > | | > now pppox_create support net-namespaces new PPPo... protocols
> | | > | | > (if they ever will be) should support net-namespace too otherwise
> | | > | | > explicit check for &init_net would be needed.
> | |
> | | Ok, I tested this in my L2TP setup. The first ppp session setup fails
> | | because the PPPIOCNEWUNIT ioctl returns -EEXIST. I think the problem is
> | | the logic in ppp_create_interface(), which does the following to create
> | | a new ppp interface:
> | |
> | | /* Initialize the new ppp unit */
> | | ppp->file.index = unit;
> | | sprintf(dev->name, "ppp%d", unit);
> | |
> | | ret = register_netdev(dev);
> | |
> | | Looks like there is more work to do in the ppp changes.
> | |
> | |
> ...
>
> Btw James did connection work without these patches? On
> pure net-next-2.6 tree? I've some bad feeling that this
> fail is related to different patch. Just to be sure.
If you mean, does pppol2tp work with the patches applied when no
namespace is configured, yes it does.
But to test this patch, I ran two l2tp daemons (in different namespaces
on the same box) and used the veth device to connect them. The failure
happened on the first l2tp session create because each side tried to
create a ppp interface called ppp0.
Should all interface names be unique across the system even when netns
is used? If so, then ppp_generic needs to assign system-wide unique ppp
unit numbers.
--
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 18:14 ` James Chapman
@ 2009-01-10 18:51 ` Cyrill Gorcunov
0 siblings, 0 replies; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 18:51 UTC (permalink / raw)
To: James Chapman; +Cc: davem, linux-kernel, netdev, devel, xemul
[James Chapman - Sat, Jan 10, 2009 at 06:14:33PM +0000]
| Cyrill Gorcunov wrote:
| > [Cyrill Gorcunov - Sat, Jan 10, 2009 at 06:19:58PM +0300]
| > | [James Chapman - Sat, Jan 10, 2009 at 03:05:13PM +0000]
| > | | Cyrill Gorcunov wrote:
| > | | > [Cyrill Gorcunov - Sat, Jan 10, 2009 at 02:13:59PM +0300]
| > | | > | [James Chapman - Sat, Jan 10, 2009 at 11:06:08AM +0000]
| > | | > | | Cyrill Gorcunov wrote:
| > | | > | | > - Each tunnel and appropriate lock are inside own namespace now.
| > | | > | | > - pppox code allows to create per-namespace sockets for
| > | | > | | > both PX_PROTO_OE and PX_PROTO_OL2TP protocols. Actually since
| > | | > | | > now pppox_create support net-namespaces new PPPo... protocols
| > | | > | | > (if they ever will be) should support net-namespace too otherwise
| > | | > | | > explicit check for &init_net would be needed.
| > | |
| > | | Ok, I tested this in my L2TP setup. The first ppp session setup fails
| > | | because the PPPIOCNEWUNIT ioctl returns -EEXIST. I think the problem is
| > | | the logic in ppp_create_interface(), which does the following to create
| > | | a new ppp interface:
| > | |
| > | | /* Initialize the new ppp unit */
| > | | ppp->file.index = unit;
| > | | sprintf(dev->name, "ppp%d", unit);
| > | |
| > | | ret = register_netdev(dev);
| > | |
| > | | Looks like there is more work to do in the ppp changes.
| > | |
| > | |
| > ...
| >
| > Btw James did connection work without these patches? On
| > pure net-next-2.6 tree? I've some bad feeling that this
| > fail is related to different patch. Just to be sure.
|
| If you mean, does pppol2tp work with the patches applied when no
| namespace is configured, yes it does.
|
James I just found that my previous commits in net-next-2.6 could
be breaking the user side apps. I mean when cardmap was here
ppp_create_interface does not fail if user-side application
has asked not for'new' (ie -1) unit but some predefined number not
being used before so any PPPIOCNEWUNIT ioctl call with new unit number was
serviced by ppp module successfully. As only I've introduced idr
technique I missed such a case and now any PPPIOCNEWUNIT call
will not mark unit as 'reserved'. That is why I asked if l2tp
does work without these 'namespace' related patches.
I'm investigating this issue now. It seems idr can't guarantee
to allocate predefined id number (it could be 'equal' or 'above').
Maybe we would have to revert these commits
(commits 7a95d267fb62cd6b80ef73be0592bbbe1dbd5df7 and
ab5024ab23b78c86a0a1425defcdde48710fe449).
But this issue is not related to what you have now.
|
| But to test this patch, I ran two l2tp daemons (in different namespaces
| on the same box) and used the veth device to connect them. The failure
| happened on the first l2tp session create because each side tried to
| create a ppp interface called ppp0.
|
| Should all interface names be unique across the system even when netns
| is used? If so, then ppp_generic needs to assign system-wide unique ppp
| unit numbers.
|
I don't think it should be like that since net_device is 'net-namespace'
bound. At least register_netdevice() retrieve *net from device being
registered so I suppose devices with same names but in different
namespace could take place. I'll recheck.
Thanks for testing James!
|
| --
| James Chapman
| Katalix Systems Ltd
| http://www.katalix.com
| Catalysts for your Embedded Linux software development
|
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 3/4] net: pppol2tp - introduce net-namespace functionality
2009-01-10 12:54 ` Cyrill Gorcunov
2009-01-10 13:13 ` James Chapman
2009-01-10 15:05 ` James Chapman
@ 2009-01-11 7:36 ` David Miller
2 siblings, 0 replies; 20+ messages in thread
From: David Miller @ 2009-01-11 7:36 UTC (permalink / raw)
To: gorcunov; +Cc: jchapman, linux-kernel, netdev, devel, xemul
From: Cyrill Gorcunov <gorcunov@gmail.com>
Date: Sat, 10 Jan 2009 15:54:44 +0300
> Maybe you have some other commits which are not propogated
> to net-next-2.6 yet?
net-next-2.6 is a throw away tree that is a clone of essentially
2.6.28 after Linus first took the net-next-2.6
It has not been updated for weeks, all development has been
occurring in the net-2.6 tree
^ permalink raw reply [flat|nested] 20+ messages in thread
* [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
[not found] <20090109195154.320495476@gmail.com>
` (2 preceding siblings ...)
2009-01-09 19:51 ` [RFC 3/4] net: pppol2tp " Cyrill Gorcunov
@ 2009-01-09 19:51 ` Cyrill Gorcunov
2009-01-10 9:22 ` Cyrill Gorcunov
3 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-09 19:51 UTC (permalink / raw)
To: davem, linux-kernel, netdev
Cc: gorcunov, devel, xemul, Paul Mackerras, Cyrill Gorcunov
[-- Attachment #1: net-ppp-generic-namespace --]
[-- Type: text/plain, Size: 14224 bytes --]
- Each namespace contain ppp channels and units separately
with appropriate locks
CC: Paul Mackerras <paulus@samba.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
drivers/net/ppp_generic.c | 242 +++++++++++++++++++++++++++++++++-------------
1 file changed, 175 insertions(+), 67 deletions(-)
Index: linux-2.6.git/drivers/net/ppp_generic.c
===================================================================
--- linux-2.6.git.orig/drivers/net/ppp_generic.c
+++ linux-2.6.git/drivers/net/ppp_generic.c
@@ -49,6 +49,10 @@
#include <net/slhc_vj.h>
#include <asm/atomic.h>
+#include <linux/nsproxy.h>
+#include <net/net_namespace.h>
+#include <net/netns/generic.h>
+
#define PPP_VERSION "2.4.2"
/*
@@ -89,6 +93,8 @@ struct ppp_file {
#define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp)
#define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel)
+struct ppp_net;
+
/*
* Data structure describing one ppp unit.
* A ppp unit corresponds to a ppp network interface device
@@ -131,6 +137,7 @@ struct ppp {
struct sock_filter *active_filter;/* filter for pkts to reset idle */
unsigned pass_len, active_len;
#endif /* CONFIG_PPP_FILTER */
+ struct net *ppp_net; /* the net we belong to */
};
/*
@@ -173,25 +180,36 @@ struct channel {
* channel.downl.
*/
-/*
- * all_ppp_mutex protects the all_ppp_units mapping.
- * It also ensures that finding a ppp unit in the all_ppp_units map
- * and updating its file.refcnt field is atomic.
- */
-static DEFINE_MUTEX(all_ppp_mutex);
static atomic_t ppp_unit_count = ATOMIC_INIT(0);
-static DEFINE_IDR(ppp_units_idr);
+static atomic_t channel_count = ATOMIC_INIT(0);
/*
- * all_channels_lock protects all_channels and last_channel_index,
- * and the atomicity of find a channel and updating its file.refcnt
- * field.
+ * per net-namespace data for this module
*/
-static DEFINE_SPINLOCK(all_channels_lock);
-static LIST_HEAD(all_channels);
-static LIST_HEAD(new_channels);
-static int last_channel_index;
-static atomic_t channel_count = ATOMIC_INIT(0);
+static unsigned int ppp_net_id;
+struct ppp_net {
+ /* units to ppp mapping */
+ struct idr units_idr;
+
+ /* channels */
+ struct list_head all_channels;
+ struct list_head new_channels;
+ int last_channel_index;
+
+ /*
+ * all_ppp_mutex protects the units_idr mapping.
+ * It also ensures that finding a ppp unit in the units_idr
+ * map and updating its file.refcnt field is atomic.
+ */
+ struct mutex all_ppp_mutex;
+
+ /*
+ * all_channels_lock protects all_channels and
+ * last_channel_index, and the atomicity of find
+ * a channel and updating its file.refcnt field.
+ */
+ spinlock_t all_channels_lock;
+};
/* Get the PPP protocol number from a skb */
#define PPP_PROTO(skb) (((skb)->data[0] << 8) + (skb)->data[1])
@@ -240,21 +258,28 @@ static void ppp_ccp_peek(struct ppp *ppp
static void ppp_ccp_closed(struct ppp *ppp);
static struct compressor *find_compressor(int type);
static void ppp_get_stats(struct ppp *ppp, struct ppp_stats *st);
-static struct ppp *ppp_create_interface(int unit, int *retp);
+static struct ppp *ppp_create_interface(struct net *net, int unit, int *retp);
static void init_ppp_file(struct ppp_file *pf, int kind);
static void ppp_shutdown_interface(struct ppp *ppp);
static void ppp_destroy_interface(struct ppp *ppp);
-static struct ppp *ppp_find_unit(int unit);
-static struct channel *ppp_find_channel(int unit);
+static struct channel *ppp_find_channel(struct net *net, int unit);
static int ppp_connect_channel(struct channel *pch, int unit);
static int ppp_disconnect_channel(struct channel *pch);
static void ppp_destroy_channel(struct channel *pch);
-static int unit_get(struct idr *p, void *ptr);
-static void unit_put(struct idr *p, int n);
-static void *unit_find(struct idr *p, int n);
+static int unit_get(struct net *net, void *ptr);
+static void unit_put(struct net *net, int n);
+static void *unit_find(struct net *net, int n);
static struct class *ppp_class;
+/* per net-namespace data */
+static inline struct ppp_net *ppp_pernet(struct net *net)
+{
+ BUG_ON(!net);
+
+ return net_generic(net, ppp_net_id);
+}
+
/* Translates a PPP protocol number to a NP index (NP == network protocol) */
static inline int proto_to_npindex(int proto)
{
@@ -343,6 +368,7 @@ static int ppp_open(struct inode *inode,
*/
if (!capable(CAP_NET_ADMIN))
return -EPERM;
+
return 0;
}
@@ -768,6 +794,7 @@ static int ppp_unattached_ioctl(struct p
int unit, err = -EFAULT;
struct ppp *ppp;
struct channel *chan;
+ struct ppp_net *pn;
int __user *p = (int __user *)arg;
lock_kernel();
@@ -776,7 +803,7 @@ static int ppp_unattached_ioctl(struct p
/* Create a new ppp unit */
if (get_user(unit, p))
break;
- ppp = ppp_create_interface(unit, &err);
+ ppp = ppp_create_interface(current->nsproxy->net_ns, unit, &err);
if (!ppp)
break;
file->private_data = &ppp->file;
@@ -791,29 +818,31 @@ static int ppp_unattached_ioctl(struct p
/* Attach to an existing ppp unit */
if (get_user(unit, p))
break;
- mutex_lock(&all_ppp_mutex);
+ pn = ppp_pernet(current->nsproxy->net_ns);
+ mutex_lock(&pn->all_ppp_mutex);
err = -ENXIO;
- ppp = ppp_find_unit(unit);
+ ppp = unit_find(current->nsproxy->net_ns, unit);
if (ppp) {
atomic_inc(&ppp->file.refcnt);
file->private_data = &ppp->file;
err = 0;
}
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
break;
case PPPIOCATTCHAN:
if (get_user(unit, p))
break;
- spin_lock_bh(&all_channels_lock);
+ pn = ppp_pernet(current->nsproxy->net_ns);
+ spin_lock_bh(&pn->all_channels_lock);
err = -ENXIO;
- chan = ppp_find_channel(unit);
+ chan = ppp_find_channel(current->nsproxy->net_ns, unit);
if (chan) {
atomic_inc(&chan->file.refcnt);
file->private_data = &chan->file;
err = 0;
}
- spin_unlock_bh(&all_channels_lock);
+ spin_unlock_bh(&pn->all_channels_lock);
break;
default:
@@ -833,6 +862,54 @@ static const struct file_operations ppp_
.release = ppp_release
};
+static __net_init int ppp_init_net(struct net *net)
+{
+ struct ppp_net *pn;
+ int err;
+
+ pn = kzalloc(sizeof(*pn), GFP_KERNEL);
+ if (!pn)
+ return -ENOMEM;
+
+ idr_init(&pn->units_idr);
+
+ INIT_LIST_HEAD(&pn->all_channels);
+ INIT_LIST_HEAD(&pn->new_channels);
+
+ mutex_init(&pn->all_ppp_mutex);
+ spin_lock_init(&pn->all_channels_lock);
+
+ err = net_assign_generic(net, ppp_net_id, pn);
+ if (err) {
+ kfree(pn);
+ return err;
+ }
+
+ try_module_get(THIS_MODULE);
+ return 0;
+}
+
+static __net_exit void ppp_exit_net(struct net *net)
+{
+ struct ppp_net *pn;
+
+ pn = net_generic(net, ppp_net_id);
+ idr_destroy(&pn->units_idr);
+ /*
+ * if someone has cached our net then
+ * further net_generic call will return NULL
+ */
+ net_assign_generic(net, ppp_net_id, NULL);
+ kfree(pn);
+
+ module_put(THIS_MODULE);
+}
+
+static __net_initdata struct pernet_operations ppp_net_ops = {
+ .init = ppp_init_net,
+ .exit = ppp_exit_net,
+};
+
#define PPP_MAJOR 108
/* Called at boot time if ppp is compiled into the kernel,
@@ -1992,10 +2069,14 @@ int
ppp_register_channel(struct ppp_channel *chan)
{
struct channel *pch;
+ struct ppp_net *pn;
pch = kzalloc(sizeof(struct channel), GFP_KERNEL);
if (!pch)
return -ENOMEM;
+
+ pn = ppp_pernet(current->nsproxy->net_ns);
+
pch->ppp = NULL;
pch->chan = chan;
chan->ppp = pch;
@@ -2007,11 +2088,11 @@ ppp_register_channel(struct ppp_channel
init_rwsem(&pch->chan_sem);
spin_lock_init(&pch->downl);
rwlock_init(&pch->upl);
- spin_lock_bh(&all_channels_lock);
- pch->file.index = ++last_channel_index;
- list_add(&pch->list, &new_channels);
+ spin_lock_bh(&pn->all_channels_lock);
+ pch->file.index = ++pn->last_channel_index;
+ list_add(&pch->list, &pn->new_channels);
atomic_inc(&channel_count);
- spin_unlock_bh(&all_channels_lock);
+ spin_unlock_bh(&pn->all_channels_lock);
return 0;
}
@@ -2052,11 +2133,17 @@ void
ppp_unregister_channel(struct ppp_channel *chan)
{
struct channel *pch = chan->ppp;
+ struct ppp_net *pn;
if (!pch)
return; /* should never happen */
chan->ppp = NULL;
+ if (pch->ppp->ppp_net)
+ pn = ppp_pernet(pch->ppp->ppp_net);
+ else
+ pn = ppp_pernet(current->nsproxy->net_ns);
+
/*
* This ensures that we have returned from any calls into the
* the channel's start_xmit or ioctl routine before we proceed.
@@ -2067,9 +2154,9 @@ ppp_unregister_channel(struct ppp_channe
spin_unlock_bh(&pch->downl);
up_write(&pch->chan_sem);
ppp_disconnect_channel(pch);
- spin_lock_bh(&all_channels_lock);
+ spin_lock_bh(&pn->all_channels_lock);
list_del(&pch->list);
- spin_unlock_bh(&all_channels_lock);
+ spin_unlock_bh(&pn->all_channels_lock);
pch->file.dead = 1;
wake_up_interruptible(&pch->file.rwait);
if (atomic_dec_and_test(&pch->file.refcnt))
@@ -2394,10 +2481,11 @@ ppp_get_stats(struct ppp *ppp, struct pp
* unit == -1 means allocate a new number.
*/
static struct ppp *
-ppp_create_interface(int unit, int *retp)
+ppp_create_interface(struct net *net, int unit, int *retp)
{
struct ppp *ppp;
- struct net_device *dev = NULL;
+ struct net_device *dev;
+ struct ppp_net *pn;
int ret = -ENOMEM;
int i;
@@ -2408,6 +2496,7 @@ ppp_create_interface(int unit, int *retp
ppp = netdev_priv(dev);
ppp->dev = dev;
ppp->mru = PPP_MRU;
+ ppp->ppp_net = net;
init_ppp_file(&ppp->file, INTERFACE);
ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */
for (i = 0; i < NUM_NP; ++i)
@@ -2421,19 +2510,21 @@ ppp_create_interface(int unit, int *retp
#endif /* CONFIG_PPP_MULTILINK */
ret = -EEXIST;
- mutex_lock(&all_ppp_mutex);
+
+ pn = ppp_pernet(net);
+ mutex_lock(&pn->all_ppp_mutex);
if (unit < 0) {
- unit = unit_get(&ppp_units_idr, ppp);
+ unit = unit_get(net, ppp);
if (unit < 0) {
*retp = unit;
goto out2;
}
} else {
- if (unit_find(&ppp_units_idr, unit))
+ if (unit_find(net, unit))
goto out2; /* unit already exists */
else {
- /* darn, someone is cheating us? */
+ /* darn, someone is cheatting us? */
*retp = -EINVAL;
goto out2;
}
@@ -2445,20 +2536,20 @@ ppp_create_interface(int unit, int *retp
ret = register_netdev(dev);
if (ret != 0) {
- unit_put(&ppp_units_idr, unit);
+ unit_put(net, unit);
printk(KERN_ERR "PPP: couldn't register device %s (%d)\n",
dev->name, ret);
goto out2;
}
atomic_inc(&ppp_unit_count);
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
*retp = 0;
return ppp;
out2:
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
free_netdev(dev);
out1:
*retp = ret;
@@ -2484,7 +2575,9 @@ init_ppp_file(struct ppp_file *pf, int k
*/
static void ppp_shutdown_interface(struct ppp *ppp)
{
- mutex_lock(&all_ppp_mutex);
+ struct ppp_net *pn = ppp_pernet(ppp->ppp_net);
+
+ mutex_lock(&pn->all_ppp_mutex);
/* This will call dev_close() for us. */
ppp_lock(ppp);
if (!ppp->closing) {
@@ -2494,11 +2587,11 @@ static void ppp_shutdown_interface(struc
} else
ppp_unlock(ppp);
- unit_put(&ppp_units_idr, ppp->file.index);
+ unit_put(ppp->ppp_net, ppp->file.index);
ppp->file.dead = 1;
ppp->owner = NULL;
wake_up_interruptible(&ppp->file.rwait);
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
}
/*
@@ -2542,16 +2635,6 @@ static void ppp_destroy_interface(struct
}
/*
- * Locate an existing ppp unit.
- * The caller should have locked the all_ppp_mutex.
- */
-static struct ppp *
-ppp_find_unit(int unit)
-{
- return unit_find(&ppp_units_idr, unit);
-}
-
-/*
* Locate an existing ppp channel.
* The caller should have locked the all_channels_lock.
* First we look in the new_channels list, then in the
@@ -2560,20 +2643,25 @@ ppp_find_unit(int unit)
* when we have a lot of channels in use.
*/
static struct channel *
-ppp_find_channel(int unit)
+ppp_find_channel(struct net *net, int unit)
{
struct channel *pch;
+ struct ppp_net *pn;
- list_for_each_entry(pch, &new_channels, list) {
+ pn = ppp_pernet(net);
+
+ list_for_each_entry(pch, &pn->new_channels, list) {
if (pch->file.index == unit) {
- list_move(&pch->list, &all_channels);
+ list_move(&pch->list, &pn->all_channels);
return pch;
}
}
- list_for_each_entry(pch, &all_channels, list) {
+
+ list_for_each_entry(pch, &pn->all_channels, list) {
if (pch->file.index == unit)
return pch;
}
+
return NULL;
}
@@ -2584,11 +2672,14 @@ static int
ppp_connect_channel(struct channel *pch, int unit)
{
struct ppp *ppp;
+ struct ppp_net *pn;
int ret = -ENXIO;
int hdrlen;
- mutex_lock(&all_ppp_mutex);
- ppp = ppp_find_unit(unit);
+ pn = ppp_pernet(current->nsproxy->net_ns);
+
+ mutex_lock(&pn->all_ppp_mutex);
+ ppp = unit_find(current->nsproxy->net_ns, unit);
if (!ppp)
goto out;
write_lock_bh(&pch->upl);
@@ -2612,7 +2703,7 @@ ppp_connect_channel(struct channel *pch,
outl:
write_unlock_bh(&pch->upl);
out:
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
return ret;
}
@@ -2669,7 +2760,7 @@ static void __exit ppp_cleanup(void)
unregister_chrdev(PPP_MAJOR, "ppp");
device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
class_destroy(ppp_class);
- idr_destroy(&ppp_units_idr);
+ unregister_pernet_gen_device(ppp_net_id, &ppp_net_ops);
}
/*
@@ -2678,9 +2769,14 @@ static void __exit ppp_cleanup(void)
*/
/* get new free unit number and associate pointer with it */
-static int unit_get(struct idr *p, void *ptr)
+static int unit_get(struct net *net, void *ptr)
{
int unit, err;
+ struct ppp_net *pn;
+ struct idr *p;
+
+ pn = ppp_pernet(net);
+ p = &pn->units_idr;
again:
if (idr_pre_get(p, GFP_KERNEL) == 0) {
@@ -2696,14 +2792,26 @@ again:
}
/* put unit number back to a pool */
-static void unit_put(struct idr *p, int n)
+static void unit_put(struct net *net, int n)
{
+ struct ppp_net *pn;
+ struct idr *p;
+
+ pn = ppp_pernet(net);
+ p = &pn->units_idr;
+
idr_remove(p, n);
}
/* get pointer associated with the number */
-static void *unit_find(struct idr *p, int n)
+static void *unit_find(struct net *net, int n)
{
+ struct ppp_net *pn;
+ struct idr *p;
+
+ pn = ppp_pernet(net);
+ p = &pn->units_idr;
+
return idr_find(p, n);
}
--
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
2009-01-09 19:51 ` [RFC 4/4] net: ppp_generic " Cyrill Gorcunov
@ 2009-01-10 9:22 ` Cyrill Gorcunov
2009-01-10 9:28 ` Cyrill Gorcunov
0 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 9:22 UTC (permalink / raw)
To: davem, linux-kernel, netdev, devel, xemul, Paul Mackerras
[Cyrill Gorcunov - Fri, Jan 09, 2009 at 10:51:58PM +0300]
| - Each namespace contain ppp channels and units separately
| with appropriate locks
|
| CC: Paul Mackerras <paulus@samba.org>
| Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
...
Please ignore this one -- I forgot to update
ppp_init while was porting the patch. Will
fix.
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
2009-01-10 9:22 ` Cyrill Gorcunov
@ 2009-01-10 9:28 ` Cyrill Gorcunov
2009-01-11 0:33 ` Paul Mackerras
0 siblings, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-10 9:28 UTC (permalink / raw)
To: davem, linux-kernel, netdev, devel, xemul, Paul Mackerras
[Cyrill Gorcunov - Sat, Jan 10, 2009 at 12:22:58PM +0300]
| [Cyrill Gorcunov - Fri, Jan 09, 2009 at 10:51:58PM +0300]
| | - Each namespace contain ppp channels and units separately
| | with appropriate locks
| |
| | CC: Paul Mackerras <paulus@samba.org>
| | Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
| ...
|
| Please ignore this one -- I forgot to update
| ppp_init while was porting the patch. Will
| fix.
|
| - Cyrill -
ok, here is an updated version
- Cyrill -
---
From: Cyrill Gorcunov <gorcunov@gmail.com>
Subecjt: [RFC] net: ppp_generic - introduce net-namespace functionality
- Each namespace contain ppp channels and units separately
with appropriate locks
CC: Paul Mackerras <paulus@samba.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
drivers/net/ppp_generic.c | 279 ++++++++++++++++++++++++++++++++--------------
1 file changed, 199 insertions(+), 80 deletions(-)
Index: linux-2.6.git/drivers/net/ppp_generic.c
===================================================================
--- linux-2.6.git.orig/drivers/net/ppp_generic.c
+++ linux-2.6.git/drivers/net/ppp_generic.c
@@ -49,6 +49,10 @@
#include <net/slhc_vj.h>
#include <asm/atomic.h>
+#include <linux/nsproxy.h>
+#include <net/net_namespace.h>
+#include <net/netns/generic.h>
+
#define PPP_VERSION "2.4.2"
/*
@@ -89,6 +93,8 @@ struct ppp_file {
#define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp)
#define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel)
+struct ppp_net;
+
/*
* Data structure describing one ppp unit.
* A ppp unit corresponds to a ppp network interface device
@@ -131,6 +137,7 @@ struct ppp {
struct sock_filter *active_filter;/* filter for pkts to reset idle */
unsigned pass_len, active_len;
#endif /* CONFIG_PPP_FILTER */
+ struct net *ppp_net; /* the net we belong to */
};
/*
@@ -173,25 +180,36 @@ struct channel {
* channel.downl.
*/
-/*
- * all_ppp_mutex protects the all_ppp_units mapping.
- * It also ensures that finding a ppp unit in the all_ppp_units map
- * and updating its file.refcnt field is atomic.
- */
-static DEFINE_MUTEX(all_ppp_mutex);
static atomic_t ppp_unit_count = ATOMIC_INIT(0);
-static DEFINE_IDR(ppp_units_idr);
+static atomic_t channel_count = ATOMIC_INIT(0);
/*
- * all_channels_lock protects all_channels and last_channel_index,
- * and the atomicity of find a channel and updating its file.refcnt
- * field.
+ * per net-namespace data for this module
*/
-static DEFINE_SPINLOCK(all_channels_lock);
-static LIST_HEAD(all_channels);
-static LIST_HEAD(new_channels);
-static int last_channel_index;
-static atomic_t channel_count = ATOMIC_INIT(0);
+static unsigned int ppp_net_id;
+struct ppp_net {
+ /* units to ppp mapping */
+ struct idr units_idr;
+
+ /* channels */
+ struct list_head all_channels;
+ struct list_head new_channels;
+ int last_channel_index;
+
+ /*
+ * all_ppp_mutex protects the units_idr mapping.
+ * It also ensures that finding a ppp unit in the units_idr
+ * map and updating its file.refcnt field is atomic.
+ */
+ struct mutex all_ppp_mutex;
+
+ /*
+ * all_channels_lock protects all_channels and
+ * last_channel_index, and the atomicity of find
+ * a channel and updating its file.refcnt field.
+ */
+ spinlock_t all_channels_lock;
+};
/* Get the PPP protocol number from a skb */
#define PPP_PROTO(skb) (((skb)->data[0] << 8) + (skb)->data[1])
@@ -240,21 +258,28 @@ static void ppp_ccp_peek(struct ppp *ppp
static void ppp_ccp_closed(struct ppp *ppp);
static struct compressor *find_compressor(int type);
static void ppp_get_stats(struct ppp *ppp, struct ppp_stats *st);
-static struct ppp *ppp_create_interface(int unit, int *retp);
+static struct ppp *ppp_create_interface(struct net *net, int unit, int *retp);
static void init_ppp_file(struct ppp_file *pf, int kind);
static void ppp_shutdown_interface(struct ppp *ppp);
static void ppp_destroy_interface(struct ppp *ppp);
-static struct ppp *ppp_find_unit(int unit);
-static struct channel *ppp_find_channel(int unit);
+static struct channel *ppp_find_channel(struct net *net, int unit);
static int ppp_connect_channel(struct channel *pch, int unit);
static int ppp_disconnect_channel(struct channel *pch);
static void ppp_destroy_channel(struct channel *pch);
-static int unit_get(struct idr *p, void *ptr);
-static void unit_put(struct idr *p, int n);
-static void *unit_find(struct idr *p, int n);
+static int unit_get(struct net *net, void *ptr);
+static void unit_put(struct net *net, int n);
+static void *unit_find(struct net *net, int n);
static struct class *ppp_class;
+/* per net-namespace data */
+static inline struct ppp_net *ppp_pernet(struct net *net)
+{
+ BUG_ON(!net);
+
+ return net_generic(net, ppp_net_id);
+}
+
/* Translates a PPP protocol number to a NP index (NP == network protocol) */
static inline int proto_to_npindex(int proto)
{
@@ -343,6 +368,7 @@ static int ppp_open(struct inode *inode,
*/
if (!capable(CAP_NET_ADMIN))
return -EPERM;
+
return 0;
}
@@ -768,6 +794,7 @@ static int ppp_unattached_ioctl(struct p
int unit, err = -EFAULT;
struct ppp *ppp;
struct channel *chan;
+ struct ppp_net *pn;
int __user *p = (int __user *)arg;
lock_kernel();
@@ -776,7 +803,7 @@ static int ppp_unattached_ioctl(struct p
/* Create a new ppp unit */
if (get_user(unit, p))
break;
- ppp = ppp_create_interface(unit, &err);
+ ppp = ppp_create_interface(current->nsproxy->net_ns, unit, &err);
if (!ppp)
break;
file->private_data = &ppp->file;
@@ -791,29 +818,31 @@ static int ppp_unattached_ioctl(struct p
/* Attach to an existing ppp unit */
if (get_user(unit, p))
break;
- mutex_lock(&all_ppp_mutex);
+ pn = ppp_pernet(current->nsproxy->net_ns);
+ mutex_lock(&pn->all_ppp_mutex);
err = -ENXIO;
- ppp = ppp_find_unit(unit);
+ ppp = unit_find(current->nsproxy->net_ns, unit);
if (ppp) {
atomic_inc(&ppp->file.refcnt);
file->private_data = &ppp->file;
err = 0;
}
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
break;
case PPPIOCATTCHAN:
if (get_user(unit, p))
break;
- spin_lock_bh(&all_channels_lock);
+ pn = ppp_pernet(current->nsproxy->net_ns);
+ spin_lock_bh(&pn->all_channels_lock);
err = -ENXIO;
- chan = ppp_find_channel(unit);
+ chan = ppp_find_channel(current->nsproxy->net_ns, unit);
if (chan) {
atomic_inc(&chan->file.refcnt);
file->private_data = &chan->file;
err = 0;
}
- spin_unlock_bh(&all_channels_lock);
+ spin_unlock_bh(&pn->all_channels_lock);
break;
default:
@@ -833,6 +862,54 @@ static const struct file_operations ppp_
.release = ppp_release
};
+static __net_init int ppp_init_net(struct net *net)
+{
+ struct ppp_net *pn;
+ int err;
+
+ pn = kzalloc(sizeof(*pn), GFP_KERNEL);
+ if (!pn)
+ return -ENOMEM;
+
+ idr_init(&pn->units_idr);
+
+ INIT_LIST_HEAD(&pn->all_channels);
+ INIT_LIST_HEAD(&pn->new_channels);
+
+ mutex_init(&pn->all_ppp_mutex);
+ spin_lock_init(&pn->all_channels_lock);
+
+ err = net_assign_generic(net, ppp_net_id, pn);
+ if (err) {
+ kfree(pn);
+ return err;
+ }
+
+ try_module_get(THIS_MODULE);
+ return 0;
+}
+
+static __net_exit void ppp_exit_net(struct net *net)
+{
+ struct ppp_net *pn;
+
+ pn = net_generic(net, ppp_net_id);
+ idr_destroy(&pn->units_idr);
+ /*
+ * if someone has cached our net then
+ * further net_generic call will return NULL
+ */
+ net_assign_generic(net, ppp_net_id, NULL);
+ kfree(pn);
+
+ module_put(THIS_MODULE);
+}
+
+static __net_initdata struct pernet_operations ppp_net_ops = {
+ .init = ppp_init_net,
+ .exit = ppp_exit_net,
+};
+
#define PPP_MAJOR 108
/* Called at boot time if ppp is compiled into the kernel,
@@ -842,25 +919,36 @@ static int __init ppp_init(void)
int err;
printk(KERN_INFO "PPP generic driver version " PPP_VERSION "\n");
- err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
- if (!err) {
- ppp_class = class_create(THIS_MODULE, "ppp");
- if (IS_ERR(ppp_class)) {
- err = PTR_ERR(ppp_class);
- goto out_chrdev;
- }
- device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL,
- "ppp");
+
+ err = register_pernet_gen_device(&ppp_net_id, &ppp_net_ops);
+ if (err) {
+ printk(KERN_ERR "failed to register PPP pernet device (%d)\n", err);
+ goto out;
}
-out:
- if (err)
+ err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
+ if (err) {
printk(KERN_ERR "failed to register PPP device (%d)\n", err);
- return err;
+ goto out_net;
+ }
+
+ ppp_class = class_create(THIS_MODULE, "ppp");
+ if (IS_ERR(ppp_class)) {
+ err = PTR_ERR(ppp_class);
+ goto out_chrdev;
+ }
+
+ /* not a big deal if we fail here :-) */
+ device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
+
+ return 0;
out_chrdev:
unregister_chrdev(PPP_MAJOR, "ppp");
- goto out;
+out_net:
+ unregister_pernet_gen_device(ppp_net_id, &ppp_net_ops);
+out:
+ return err;
}
/*
@@ -1992,10 +2080,14 @@ int
ppp_register_channel(struct ppp_channel *chan)
{
struct channel *pch;
+ struct ppp_net *pn;
pch = kzalloc(sizeof(struct channel), GFP_KERNEL);
if (!pch)
return -ENOMEM;
+
+ pn = ppp_pernet(current->nsproxy->net_ns);
+
pch->ppp = NULL;
pch->chan = chan;
chan->ppp = pch;
@@ -2007,11 +2099,11 @@ ppp_register_channel(struct ppp_channel
init_rwsem(&pch->chan_sem);
spin_lock_init(&pch->downl);
rwlock_init(&pch->upl);
- spin_lock_bh(&all_channels_lock);
- pch->file.index = ++last_channel_index;
- list_add(&pch->list, &new_channels);
+ spin_lock_bh(&pn->all_channels_lock);
+ pch->file.index = ++pn->last_channel_index;
+ list_add(&pch->list, &pn->new_channels);
atomic_inc(&channel_count);
- spin_unlock_bh(&all_channels_lock);
+ spin_unlock_bh(&pn->all_channels_lock);
return 0;
}
@@ -2052,11 +2144,17 @@ void
ppp_unregister_channel(struct ppp_channel *chan)
{
struct channel *pch = chan->ppp;
+ struct ppp_net *pn;
if (!pch)
return; /* should never happen */
chan->ppp = NULL;
+ if (pch->ppp->ppp_net)
+ pn = ppp_pernet(pch->ppp->ppp_net);
+ else
+ pn = ppp_pernet(current->nsproxy->net_ns);
+
/*
* This ensures that we have returned from any calls into the
* the channel's start_xmit or ioctl routine before we proceed.
@@ -2067,9 +2165,9 @@ ppp_unregister_channel(struct ppp_channe
spin_unlock_bh(&pch->downl);
up_write(&pch->chan_sem);
ppp_disconnect_channel(pch);
- spin_lock_bh(&all_channels_lock);
+ spin_lock_bh(&pn->all_channels_lock);
list_del(&pch->list);
- spin_unlock_bh(&all_channels_lock);
+ spin_unlock_bh(&pn->all_channels_lock);
pch->file.dead = 1;
wake_up_interruptible(&pch->file.rwait);
if (atomic_dec_and_test(&pch->file.refcnt))
@@ -2394,10 +2492,11 @@ ppp_get_stats(struct ppp *ppp, struct pp
* unit == -1 means allocate a new number.
*/
static struct ppp *
-ppp_create_interface(int unit, int *retp)
+ppp_create_interface(struct net *net, int unit, int *retp)
{
struct ppp *ppp;
- struct net_device *dev = NULL;
+ struct net_device *dev;
+ struct ppp_net *pn;
int ret = -ENOMEM;
int i;
@@ -2408,6 +2507,7 @@ ppp_create_interface(int unit, int *retp
ppp = netdev_priv(dev);
ppp->dev = dev;
ppp->mru = PPP_MRU;
+ ppp->ppp_net = net;
init_ppp_file(&ppp->file, INTERFACE);
ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */
for (i = 0; i < NUM_NP; ++i)
@@ -2421,19 +2521,21 @@ ppp_create_interface(int unit, int *retp
#endif /* CONFIG_PPP_MULTILINK */
ret = -EEXIST;
- mutex_lock(&all_ppp_mutex);
+
+ pn = ppp_pernet(net);
+ mutex_lock(&pn->all_ppp_mutex);
if (unit < 0) {
- unit = unit_get(&ppp_units_idr, ppp);
+ unit = unit_get(net, ppp);
if (unit < 0) {
*retp = unit;
goto out2;
}
} else {
- if (unit_find(&ppp_units_idr, unit))
+ if (unit_find(net, unit))
goto out2; /* unit already exists */
else {
- /* darn, someone is cheating us? */
+ /* darn, someone is cheatting us? */
*retp = -EINVAL;
goto out2;
}
@@ -2445,20 +2547,20 @@ ppp_create_interface(int unit, int *retp
ret = register_netdev(dev);
if (ret != 0) {
- unit_put(&ppp_units_idr, unit);
+ unit_put(net, unit);
printk(KERN_ERR "PPP: couldn't register device %s (%d)\n",
dev->name, ret);
goto out2;
}
atomic_inc(&ppp_unit_count);
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
*retp = 0;
return ppp;
out2:
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
free_netdev(dev);
out1:
*retp = ret;
@@ -2484,7 +2586,9 @@ init_ppp_file(struct ppp_file *pf, int k
*/
static void ppp_shutdown_interface(struct ppp *ppp)
{
- mutex_lock(&all_ppp_mutex);
+ struct ppp_net *pn = ppp_pernet(ppp->ppp_net);
+
+ mutex_lock(&pn->all_ppp_mutex);
/* This will call dev_close() for us. */
ppp_lock(ppp);
if (!ppp->closing) {
@@ -2494,11 +2598,11 @@ static void ppp_shutdown_interface(struc
} else
ppp_unlock(ppp);
- unit_put(&ppp_units_idr, ppp->file.index);
+ unit_put(ppp->ppp_net, ppp->file.index);
ppp->file.dead = 1;
ppp->owner = NULL;
wake_up_interruptible(&ppp->file.rwait);
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
}
/*
@@ -2542,16 +2646,6 @@ static void ppp_destroy_interface(struct
}
/*
- * Locate an existing ppp unit.
- * The caller should have locked the all_ppp_mutex.
- */
-static struct ppp *
-ppp_find_unit(int unit)
-{
- return unit_find(&ppp_units_idr, unit);
-}
-
-/*
* Locate an existing ppp channel.
* The caller should have locked the all_channels_lock.
* First we look in the new_channels list, then in the
@@ -2560,20 +2654,25 @@ ppp_find_unit(int unit)
* when we have a lot of channels in use.
*/
static struct channel *
-ppp_find_channel(int unit)
+ppp_find_channel(struct net *net, int unit)
{
struct channel *pch;
+ struct ppp_net *pn;
+
+ pn = ppp_pernet(net);
- list_for_each_entry(pch, &new_channels, list) {
+ list_for_each_entry(pch, &pn->new_channels, list) {
if (pch->file.index == unit) {
- list_move(&pch->list, &all_channels);
+ list_move(&pch->list, &pn->all_channels);
return pch;
}
}
- list_for_each_entry(pch, &all_channels, list) {
+
+ list_for_each_entry(pch, &pn->all_channels, list) {
if (pch->file.index == unit)
return pch;
}
+
return NULL;
}
@@ -2584,11 +2683,14 @@ static int
ppp_connect_channel(struct channel *pch, int unit)
{
struct ppp *ppp;
+ struct ppp_net *pn;
int ret = -ENXIO;
int hdrlen;
- mutex_lock(&all_ppp_mutex);
- ppp = ppp_find_unit(unit);
+ pn = ppp_pernet(current->nsproxy->net_ns);
+
+ mutex_lock(&pn->all_ppp_mutex);
+ ppp = unit_find(current->nsproxy->net_ns, unit);
if (!ppp)
goto out;
write_lock_bh(&pch->upl);
@@ -2612,7 +2714,7 @@ ppp_connect_channel(struct channel *pch,
outl:
write_unlock_bh(&pch->upl);
out:
- mutex_unlock(&all_ppp_mutex);
+ mutex_unlock(&pn->all_ppp_mutex);
return ret;
}
@@ -2669,7 +2771,7 @@ static void __exit ppp_cleanup(void)
unregister_chrdev(PPP_MAJOR, "ppp");
device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
class_destroy(ppp_class);
- idr_destroy(&ppp_units_idr);
+ unregister_pernet_gen_device(ppp_net_id, &ppp_net_ops);
}
/*
@@ -2678,9 +2780,14 @@ static void __exit ppp_cleanup(void)
*/
/* get new free unit number and associate pointer with it */
-static int unit_get(struct idr *p, void *ptr)
+static int unit_get(struct net *net, void *ptr)
{
int unit, err;
+ struct ppp_net *pn;
+ struct idr *p;
+
+ pn = ppp_pernet(net);
+ p = &pn->units_idr;
again:
if (idr_pre_get(p, GFP_KERNEL) == 0) {
@@ -2696,14 +2803,26 @@ again:
}
/* put unit number back to a pool */
-static void unit_put(struct idr *p, int n)
+static void unit_put(struct net *net, int n)
{
+ struct ppp_net *pn;
+ struct idr *p;
+
+ pn = ppp_pernet(net);
+ p = &pn->units_idr;
+
idr_remove(p, n);
}
/* get pointer associated with the number */
-static void *unit_find(struct idr *p, int n)
+static void *unit_find(struct net *net, int n)
{
+ struct ppp_net *pn;
+ struct idr *p;
+
+ pn = ppp_pernet(net);
+ p = &pn->units_idr;
+
return idr_find(p, n);
}
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
2009-01-10 9:28 ` Cyrill Gorcunov
@ 2009-01-11 0:33 ` Paul Mackerras
2009-01-11 7:39 ` David Miller
2009-01-11 7:46 ` Cyrill Gorcunov
0 siblings, 2 replies; 20+ messages in thread
From: Paul Mackerras @ 2009-01-11 0:33 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: davem, linux-kernel, netdev, devel, xemul
Cyrill Gorcunov writes:
> From: Cyrill Gorcunov <gorcunov@gmail.com>
> Subecjt: [RFC] net: ppp_generic - introduce net-namespace functionality
>
> - Each namespace contain ppp channels and units separately
> with appropriate locks
This looks like a lot of uglification to me. Why exactly do
individual network drivers need to know or care about namespaces?
Paul.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
2009-01-11 0:33 ` Paul Mackerras
@ 2009-01-11 7:39 ` David Miller
2009-01-11 7:46 ` Cyrill Gorcunov
1 sibling, 0 replies; 20+ messages in thread
From: David Miller @ 2009-01-11 7:39 UTC (permalink / raw)
To: paulus; +Cc: gorcunov, linux-kernel, netdev, devel, xemul
From: Paul Mackerras <paulus@samba.org>
Date: Sun, 11 Jan 2009 11:33:21 +1100
> Cyrill Gorcunov writes:
>
> > From: Cyrill Gorcunov <gorcunov@gmail.com>
> > Subecjt: [RFC] net: ppp_generic - introduce net-namespace functionality
> >
> > - Each namespace contain ppp channels and units separately
> > with appropriate locks
>
> This looks like a lot of uglification to me. Why exactly do
> individual network drivers need to know or care about namespaces?
They need to know if there is a lookup involved and the device
type internally has it's own realm of keys that identify such
devices.
PPP fits that particular case.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
2009-01-11 0:33 ` Paul Mackerras
2009-01-11 7:39 ` David Miller
@ 2009-01-11 7:46 ` Cyrill Gorcunov
2009-01-11 8:25 ` Cyrill Gorcunov
1 sibling, 1 reply; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-11 7:46 UTC (permalink / raw)
To: Paul Mackerras; +Cc: davem, linux-kernel, netdev, devel, xemul
[Paul Mackerras - Sun, Jan 11, 2009 at 11:33:21AM +1100]
| Cyrill Gorcunov writes:
|
| > From: Cyrill Gorcunov <gorcunov@gmail.com>
| > Subecjt: [RFC] net: ppp_generic - introduce net-namespace functionality
| >
| > - Each namespace contain ppp channels and units separately
| > with appropriate locks
|
| This looks like a lot of uglification to me. Why exactly do
| individual network drivers need to know or care about namespaces?
|
| Paul.
|
Unfortunately in the whole series ppp has been change more
then others and it's looks ugly indeed that is why it was RFC.
Namespaces imply isolation of data right? Including private
data being 'user related' -- ie units passed to user in one
namespace should not interfere with units passed to user in
another namespace. So if I will not 'bind' units pool to
namespaces it would be possible to steal unit from one namespace
proposed for another namespace. Right?
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC 4/4] net: ppp_generic - introduce net-namespace functionality
2009-01-11 7:46 ` Cyrill Gorcunov
@ 2009-01-11 8:25 ` Cyrill Gorcunov
0 siblings, 0 replies; 20+ messages in thread
From: Cyrill Gorcunov @ 2009-01-11 8:25 UTC (permalink / raw)
To: Paul Mackerras, davem, linux-kernel, netdev, devel, xemul; +Cc: James Chapman
[Cyrill Gorcunov - Sun, Jan 11, 2009 at 10:46:52AM +0300]
| [Paul Mackerras - Sun, Jan 11, 2009 at 11:33:21AM +1100]
| | Cyrill Gorcunov writes:
| |
| | > From: Cyrill Gorcunov <gorcunov@gmail.com>
| | > Subecjt: [RFC] net: ppp_generic - introduce net-namespace functionality
| | >
| | > - Each namespace contain ppp channels and units separately
| | > with appropriate locks
| |
| | This looks like a lot of uglification to me. Why exactly do
| | individual network drivers need to know or care about namespaces?
| |
| | Paul.
| |
|
| Unfortunately in the whole series ppp has been change more
| then others and it's looks ugly indeed that is why it was RFC.
| Namespaces imply isolation of data right? Including private
| data being 'user related' -- ie units passed to user in one
| namespace should not interfere with units passed to user in
| another namespace. So if I will not 'bind' units pool to
| namespaces it would be possible to steal unit from one namespace
| proposed for another namespace. Right?
|
| - Cyrill -
Anyway, thanks for review -- I'll check if I could make this
series less 'ugly'. I just wanna hear what people think about
this series 'in general' (or maybe even test it [James, thanks!] :) --
since the series is RFC and not to include in any kind of tree.
- Cyrill -
^ permalink raw reply [flat|nested] 20+ messages in thread