Commit 52404881 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont Committed by David S. Miller

Phonet: basic net namespace support

Signed-off-by: default avatarRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d81d2285
...@@ -46,7 +46,7 @@ static inline struct pn_sock *pn_sk(struct sock *sk) ...@@ -46,7 +46,7 @@ static inline struct pn_sock *pn_sk(struct sock *sk)
extern const struct proto_ops phonet_dgram_ops; extern const struct proto_ops phonet_dgram_ops;
struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *sa); struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa);
void phonet_get_local_port_range(int *min, int *max); void phonet_get_local_port_range(int *min, int *max);
void pn_sock_hash(struct sock *sk); void pn_sock_hash(struct sock *sk);
void pn_sock_unhash(struct sock *sk); void pn_sock_unhash(struct sock *sk);
......
...@@ -43,7 +43,7 @@ struct net_device *phonet_device_get(struct net *net); ...@@ -43,7 +43,7 @@ struct net_device *phonet_device_get(struct net *net);
int phonet_address_add(struct net_device *dev, u8 addr); int phonet_address_add(struct net_device *dev, u8 addr);
int phonet_address_del(struct net_device *dev, u8 addr); int phonet_address_del(struct net_device *dev, u8 addr);
u8 phonet_address_get(struct net_device *dev, u8 addr); u8 phonet_address_get(struct net_device *dev, u8 addr);
int phonet_address_lookup(u8 addr); int phonet_address_lookup(struct net *net, u8 addr);
#define PN_NO_ADDR 0xff #define PN_NO_ADDR 0xff
......
...@@ -67,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol) ...@@ -67,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
struct phonet_protocol *pnp; struct phonet_protocol *pnp;
int err; int err;
if (net != &init_net)
return -EAFNOSUPPORT;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
...@@ -352,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -352,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
struct sockaddr_pn sa; struct sockaddr_pn sa;
u16 len; u16 len;
if (dev_net(dev) != &init_net)
goto out;
/* check we have at least a full Phonet header */ /* check we have at least a full Phonet header */
if (!pskb_pull(skb, sizeof(struct phonethdr))) if (!pskb_pull(skb, sizeof(struct phonethdr)))
goto out; goto out;
...@@ -373,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -373,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
if (pn_sockaddr_get_addr(&sa) == 0) if (pn_sockaddr_get_addr(&sa) == 0)
goto out; /* currently, we cannot be device 0 */ goto out; /* currently, we cannot be device 0 */
sk = pn_find_sock_by_sa(&sa); sk = pn_find_sock_by_sa(dev_net(dev), &sa);
if (sk == NULL) { if (sk == NULL) {
if (can_respond(skb)) { if (can_respond(skb)) {
send_obj_unreachable(skb); send_obj_unreachable(skb);
......
...@@ -76,7 +76,7 @@ struct net_device *phonet_device_get(struct net *net) ...@@ -76,7 +76,7 @@ struct net_device *phonet_device_get(struct net *net)
dev = pnd->netdev; dev = pnd->netdev;
BUG_ON(!dev); BUG_ON(!dev);
if (dev_net(dev) == net && if (net_eq(dev_net(dev), net) &&
(dev->reg_state == NETREG_REGISTERED) && (dev->reg_state == NETREG_REGISTERED) &&
((pnd->netdev->flags & IFF_UP)) == IFF_UP) ((pnd->netdev->flags & IFF_UP)) == IFF_UP)
break; break;
...@@ -140,12 +140,14 @@ u8 phonet_address_get(struct net_device *dev, u8 addr) ...@@ -140,12 +140,14 @@ u8 phonet_address_get(struct net_device *dev, u8 addr)
return addr; return addr;
} }
int phonet_address_lookup(u8 addr) int phonet_address_lookup(struct net *net, u8 addr)
{ {
struct phonet_device *pnd; struct phonet_device *pnd;
spin_lock_bh(&pndevs.lock); spin_lock_bh(&pndevs.lock);
list_for_each_entry(pnd, &pndevs.list, list) { list_for_each_entry(pnd, &pndevs.list, list) {
if (!net_eq(dev_net(pnd->netdev), net))
continue;
/* Don't allow unregistering devices! */ /* Don't allow unregistering devices! */
if ((pnd->netdev->reg_state != NETREG_REGISTERED) || if ((pnd->netdev->reg_state != NETREG_REGISTERED) ||
((pnd->netdev->flags & IFF_UP)) != IFF_UP) ((pnd->netdev->flags & IFF_UP)) != IFF_UP)
......
...@@ -57,7 +57,7 @@ static struct { ...@@ -57,7 +57,7 @@ static struct {
* Find address based on socket address, match only certain fields. * Find address based on socket address, match only certain fields.
* Also grab sock if it was found. Remember to sock_put it later. * Also grab sock if it was found. Remember to sock_put it later.
*/ */
struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn) struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
{ {
struct hlist_node *node; struct hlist_node *node;
struct sock *sknode; struct sock *sknode;
...@@ -71,6 +71,8 @@ struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn) ...@@ -71,6 +71,8 @@ struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn)
struct pn_sock *pn = pn_sk(sknode); struct pn_sock *pn = pn_sk(sknode);
BUG_ON(!pn->sobject); /* unbound socket */ BUG_ON(!pn->sobject); /* unbound socket */
if (!net_eq(sock_net(sknode), net))
continue;
if (pn_port(obj)) { if (pn_port(obj)) {
/* Look up socket by port */ /* Look up socket by port */
if (pn_port(pn->sobject) != pn_port(obj)) 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,7 +132,7 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr); handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr);
saddr = pn_addr(handle); saddr = pn_addr(handle);
if (saddr && phonet_address_lookup(saddr)) if (saddr && phonet_address_lookup(sock_net(sk), saddr))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
lock_sock(sk); lock_sock(sk);
...@@ -361,6 +363,7 @@ static DEFINE_MUTEX(port_mutex); ...@@ -361,6 +363,7 @@ static DEFINE_MUTEX(port_mutex);
int pn_sock_get_port(struct sock *sk, unsigned short sport) int pn_sock_get_port(struct sock *sk, unsigned short sport)
{ {
static int port_cur; static int port_cur;
struct net *net = sock_net(sk);
struct pn_sock *pn = pn_sk(sk); struct pn_sock *pn = pn_sk(sk);
struct sockaddr_pn try_sa; struct sockaddr_pn try_sa;
struct sock *tmpsk; struct sock *tmpsk;
...@@ -381,7 +384,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport) ...@@ -381,7 +384,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
port_cur = pmin; port_cur = pmin;
pn_sockaddr_set_port(&try_sa, port_cur); pn_sockaddr_set_port(&try_sa, port_cur);
tmpsk = pn_find_sock_by_sa(&try_sa); tmpsk = pn_find_sock_by_sa(net, &try_sa);
if (tmpsk == NULL) { if (tmpsk == NULL) {
sport = port_cur; sport = port_cur;
goto found; goto found;
...@@ -391,7 +394,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport) ...@@ -391,7 +394,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
} else { } else {
/* try to find specific port */ /* try to find specific port */
pn_sockaddr_set_port(&try_sa, sport); pn_sockaddr_set_port(&try_sa, sport);
tmpsk = pn_find_sock_by_sa(&try_sa); tmpsk = pn_find_sock_by_sa(net, &try_sa);
if (tmpsk == NULL) if (tmpsk == NULL)
/* No sock there! We can use that port... */ /* No sock there! We can use that port... */
goto found; goto found;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment