aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi.denis-courmont@nokia.com>2008-12-03 18:42:56 -0500
committerDavid S. Miller <davem@davemloft.net>2008-12-03 18:42:56 -0500
commit52404881984e2d447f920a23e3bb63262dfc77f3 (patch)
tree531b4ac50fe372d26bf950c77d31f2ddcb40153c
parentd81d228567f55af517796638075dbbce9b40d7af (diff)
Phonet: basic net namespace support
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/phonet/phonet.h2
-rw-r--r--include/net/phonet/pn_dev.h2
-rw-r--r--net/phonet/af_phonet.c8
-rw-r--r--net/phonet/pn_dev.c6
-rw-r--r--net/phonet/socket.c11
5 files changed, 14 insertions, 15 deletions
diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h
index c6a24518446..057b0a8a288 100644
--- a/include/net/phonet/phonet.h
+++ b/include/net/phonet/phonet.h
@@ -46,7 +46,7 @@ static inline struct pn_sock *pn_sk(struct sock *sk)
46 46
47extern const struct proto_ops phonet_dgram_ops; 47extern const struct proto_ops phonet_dgram_ops;
48 48
49struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *sa); 49struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa);
50void phonet_get_local_port_range(int *min, int *max); 50void phonet_get_local_port_range(int *min, int *max);
51void pn_sock_hash(struct sock *sk); 51void pn_sock_hash(struct sock *sk);
52void pn_sock_unhash(struct sock *sk); 52void pn_sock_unhash(struct sock *sk);
diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index bbd2a836e04..aa1c59a1d33 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -43,7 +43,7 @@ struct net_device *phonet_device_get(struct net *net);
43int phonet_address_add(struct net_device *dev, u8 addr); 43int phonet_address_add(struct net_device *dev, u8 addr);
44int phonet_address_del(struct net_device *dev, u8 addr); 44int phonet_address_del(struct net_device *dev, u8 addr);
45u8 phonet_address_get(struct net_device *dev, u8 addr); 45u8 phonet_address_get(struct net_device *dev, u8 addr);
46int phonet_address_lookup(u8 addr); 46int phonet_address_lookup(struct net *net, u8 addr);
47 47
48#define PN_NO_ADDR 0xff 48#define PN_NO_ADDR 0xff
49 49
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 9d211f12582..13cb323f8c3 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -67,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
67 struct phonet_protocol *pnp; 67 struct phonet_protocol *pnp;
68 int err; 68 int err;
69 69
70 if (net != &init_net)
71 return -EAFNOSUPPORT;
72
73 if (!capable(CAP_SYS_ADMIN)) 70 if (!capable(CAP_SYS_ADMIN))
74 return -EPERM; 71 return -EPERM;
75 72
@@ -352,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
352 struct sockaddr_pn sa; 349 struct sockaddr_pn sa;
353 u16 len; 350 u16 len;
354 351
355 if (dev_net(dev) != &init_net)
356 goto out;
357
358 /* check we have at least a full Phonet header */ 352 /* check we have at least a full Phonet header */
359 if (!pskb_pull(skb, sizeof(struct phonethdr))) 353 if (!pskb_pull(skb, sizeof(struct phonethdr)))
360 goto out; 354 goto out;
@@ -373,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
373 if (pn_sockaddr_get_addr(&sa) == 0) 367 if (pn_sockaddr_get_addr(&sa) == 0)
374 goto out; /* currently, we cannot be device 0 */ 368 goto out; /* currently, we cannot be device 0 */
375 369
376 sk = pn_find_sock_by_sa(&sa); 370 sk = pn_find_sock_by_sa(dev_net(dev), &sa);
377 if (sk == NULL) { 371 if (sk == NULL) {
378 if (can_respond(skb)) { 372 if (can_respond(skb)) {
379 send_obj_unreachable(skb); 373 send_obj_unreachable(skb);
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index f93ff8ef47d..5491bf5e354 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -76,7 +76,7 @@ struct net_device *phonet_device_get(struct net *net)
76 dev = pnd->netdev; 76 dev = pnd->netdev;
77 BUG_ON(!dev); 77 BUG_ON(!dev);
78 78
79 if (dev_net(dev) == net && 79 if (net_eq(dev_net(dev), net) &&
80 (dev->reg_state == NETREG_REGISTERED) && 80 (dev->reg_state == NETREG_REGISTERED) &&
81 ((pnd->netdev->flags & IFF_UP)) == IFF_UP) 81 ((pnd->netdev->flags & IFF_UP)) == IFF_UP)
82 break; 82 break;
@@ -140,12 +140,14 @@ u8 phonet_address_get(struct net_device *dev, u8 addr)
140 return addr; 140 return addr;
141} 141}
142 142
143int phonet_address_lookup(u8 addr) 143int phonet_address_lookup(struct net *net, u8 addr)
144{ 144{
145 struct phonet_device *pnd; 145 struct phonet_device *pnd;
146 146
147 spin_lock_bh(&pndevs.lock); 147 spin_lock_bh(&pndevs.lock);
148 list_for_each_entry(pnd, &pndevs.list, list) { 148 list_for_each_entry(pnd, &pndevs.list, list) {
149 if (!net_eq(dev_net(pnd->netdev), net))
150 continue;
149 /* Don't allow unregistering devices! */ 151 /* Don't allow unregistering devices! */
150 if ((pnd->netdev->reg_state != NETREG_REGISTERED) || 152 if ((pnd->netdev->reg_state != NETREG_REGISTERED) ||
151 ((pnd->netdev->flags & IFF_UP)) != IFF_UP) 153 ((pnd->netdev->flags & IFF_UP)) != IFF_UP)
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index d81740187fb..c75aa5cdead 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -57,7 +57,7 @@ static struct {
57 * Find address based on socket address, match only certain fields. 57 * Find address based on socket address, match only certain fields.
58 * Also grab sock if it was found. Remember to sock_put it later. 58 * Also grab sock if it was found. Remember to sock_put it later.
59 */ 59 */
60struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn) 60struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
61{ 61{
62 struct hlist_node *node; 62 struct hlist_node *node;
63 struct sock *sknode; 63 struct sock *sknode;
@@ -71,6 +71,8 @@ struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn)
71 struct pn_sock *pn = pn_sk(sknode); 71 struct pn_sock *pn = pn_sk(sknode);
72 BUG_ON(!pn->sobject); /* unbound socket */ 72 BUG_ON(!pn->sobject); /* unbound socket */
73 73
74 if (!net_eq(sock_net(sknode), net))
75 continue;
74 if (pn_port(obj)) { 76 if (pn_port(obj)) {
75 /* Look up socket by port */ 77 /* Look up socket by port */
76 if (pn_port(pn->sobject) != pn_port(obj)) 78 if (pn_port(pn->sobject) != pn_port(obj))
@@ -130,7 +132,7 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
130 132
131 handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr); 133 handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr);
132 saddr = pn_addr(handle); 134 saddr = pn_addr(handle);
133 if (saddr && phonet_address_lookup(saddr)) 135 if (saddr && phonet_address_lookup(sock_net(sk), saddr))
134 return -EADDRNOTAVAIL; 136 return -EADDRNOTAVAIL;
135 137
136 lock_sock(sk); 138 lock_sock(sk);
@@ -361,6 +363,7 @@ static DEFINE_MUTEX(port_mutex);
361int pn_sock_get_port(struct sock *sk, unsigned short sport) 363int pn_sock_get_port(struct sock *sk, unsigned short sport)
362{ 364{
363 static int port_cur; 365 static int port_cur;
366 struct net *net = sock_net(sk);
364 struct pn_sock *pn = pn_sk(sk); 367 struct pn_sock *pn = pn_sk(sk);
365 struct sockaddr_pn try_sa; 368 struct sockaddr_pn try_sa;
366 struct sock *tmpsk; 369 struct sock *tmpsk;
@@ -381,7 +384,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
381 port_cur = pmin; 384 port_cur = pmin;
382 385
383 pn_sockaddr_set_port(&try_sa, port_cur); 386 pn_sockaddr_set_port(&try_sa, port_cur);
384 tmpsk = pn_find_sock_by_sa(&try_sa); 387 tmpsk = pn_find_sock_by_sa(net, &try_sa);
385 if (tmpsk == NULL) { 388 if (tmpsk == NULL) {
386 sport = port_cur; 389 sport = port_cur;
387 goto found; 390 goto found;
@@ -391,7 +394,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
391 } else { 394 } else {
392 /* try to find specific port */ 395 /* try to find specific port */
393 pn_sockaddr_set_port(&try_sa, sport); 396 pn_sockaddr_set_port(&try_sa, sport);
394 tmpsk = pn_find_sock_by_sa(&try_sa); 397 tmpsk = pn_find_sock_by_sa(net, &try_sa);
395 if (tmpsk == NULL) 398 if (tmpsk == NULL)
396 /* No sock there! We can use that port... */ 399 /* No sock there! We can use that port... */
397 goto found; 400 goto found;