aboutsummaryrefslogtreecommitdiff
path: root/net/phonet
diff options
context:
space:
mode:
authormerge <null@invalid>2009-01-22 13:55:32 +0000
committerAndy Green <agreen@octopus.localdomain>2009-01-22 13:55:32 +0000
commitaa6f5ffbdba45aa8e19e5048648fc6c7b25376d3 (patch)
treefbb786d0ac6f8a774fd834e9ce951197e60fbffa /net/phonet
parentf2d78193eae5dccd3d588d2c8ea0866efc368332 (diff)
MERGE-via-pending-tracking-hist-MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141
pending-tracking-hist top was MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141 / fdf777a63bcb59e0dfd78bfe2c6242e01f6d4eb9 ... parent commitmessage: From: merge <null@invalid> MERGE-via-stable-tracking-hist-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 stable-tracking-hist top was MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 / 90463bfd2d5a3c8b52f6e6d71024a00e052b0ced ... parent commitmessage: From: merge <null@invalid> MERGE-via-mokopatches-tracking-hist-fix-stray-endmenu-patch mokopatches-tracking-hist top was fix-stray-endmenu-patch / 3630e0be570de8057e7f8d2fe501ed353cdf34e6 ... parent commitmessage: From: Andy Green <andy@openmoko.com> fix-stray-endmenu.patch Signed-off-by: Andy Green <andy@openmoko.com>
Diffstat (limited to 'net/phonet')
-rw-r--r--net/phonet/af_phonet.c64
-rw-r--r--net/phonet/pep-gprs.c229
-rw-r--r--net/phonet/pep.c38
-rw-r--r--net/phonet/pn_dev.c8
-rw-r--r--net/phonet/pn_netlink.c3
-rw-r--r--net/phonet/socket.c13
-rw-r--r--net/phonet/sysctl.c4
7 files changed, 171 insertions, 188 deletions
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index defeb7a0d50..13cb323f8c3 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -33,9 +33,30 @@
#include <net/phonet/phonet.h>
#include <net/phonet/pn_dev.h>
-static struct net_proto_family phonet_proto_family;
-static struct phonet_protocol *phonet_proto_get(int protocol);
-static inline void phonet_proto_put(struct phonet_protocol *pp);
+/* Transport protocol registration */
+static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
+static DEFINE_SPINLOCK(proto_tab_lock);
+
+static struct phonet_protocol *phonet_proto_get(int protocol)
+{
+ struct phonet_protocol *pp;
+
+ if (protocol >= PHONET_NPROTO)
+ return NULL;
+
+ spin_lock(&proto_tab_lock);
+ pp = proto_tab[protocol];
+ if (pp && !try_module_get(pp->prot->owner))
+ pp = NULL;
+ spin_unlock(&proto_tab_lock);
+
+ return pp;
+}
+
+static inline void phonet_proto_put(struct phonet_protocol *pp)
+{
+ module_put(pp->prot->owner);
+}
/* protocol family functions */
@@ -46,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
struct phonet_protocol *pnp;
int err;
- if (net != &init_net)
- return -EAFNOSUPPORT;
-
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -144,8 +162,8 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
struct phonethdr *ph;
int err;
- if (skb->len + 2 > 0xffff) {
- /* Phonet length field would overflow */
+ if (skb->len + 2 > 0xffff /* Phonet length field limit */ ||
+ skb->len + sizeof(struct phonethdr) > dev->mtu) {
err = -EMSGSIZE;
goto drop;
}
@@ -331,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
struct sockaddr_pn sa;
u16 len;
- if (dev_net(dev) != &init_net)
- goto out;
-
/* check we have at least a full Phonet header */
if (!pskb_pull(skb, sizeof(struct phonethdr)))
goto out;
@@ -352,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
if (pn_sockaddr_get_addr(&sa) == 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 (can_respond(skb)) {
send_obj_unreachable(skb);
@@ -375,10 +390,6 @@ static struct packet_type phonet_packet_type = {
.func = phonet_rcv,
};
-/* Transport protocol registration */
-static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
-static DEFINE_SPINLOCK(proto_tab_lock);
-
int __init_or_module phonet_proto_register(int protocol,
struct phonet_protocol *pp)
{
@@ -412,27 +423,6 @@ void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)
}
EXPORT_SYMBOL(phonet_proto_unregister);
-static struct phonet_protocol *phonet_proto_get(int protocol)
-{
- struct phonet_protocol *pp;
-
- if (protocol >= PHONET_NPROTO)
- return NULL;
-
- spin_lock(&proto_tab_lock);
- pp = proto_tab[protocol];
- if (pp && !try_module_get(pp->prot->owner))
- pp = NULL;
- spin_unlock(&proto_tab_lock);
-
- return pp;
-}
-
-static inline void phonet_proto_put(struct phonet_protocol *pp)
-{
- module_put(pp->prot->owner);
-}
-
/* Module registration */
static int __init phonet_init(void)
{
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c
index 9978afbd9f2..6a91a32a80c 100644
--- a/net/phonet/pep-gprs.c
+++ b/net/phonet/pep-gprs.c
@@ -40,23 +40,17 @@ struct gprs_dev {
void (*old_data_ready)(struct sock *, int);
void (*old_write_space)(struct sock *);
- struct net_device *net;
- struct net_device_stats stats;
-
- struct sk_buff_head tx_queue;
- struct work_struct tx_work;
- spinlock_t tx_lock;
- unsigned tx_max;
+ struct net_device *dev;
};
-static int gprs_type_trans(struct sk_buff *skb)
+static __be16 gprs_type_trans(struct sk_buff *skb)
{
const u8 *pvfc;
u8 buf;
pvfc = skb_header_pointer(skb, 0, 1, &buf);
if (!pvfc)
- return 0;
+ return htons(0);
/* Look at IP version field */
switch (*pvfc >> 4) {
case 4:
@@ -64,7 +58,15 @@ static int gprs_type_trans(struct sk_buff *skb)
case 6:
return htons(ETH_P_IPV6);
}
- return 0;
+ return htons(0);
+}
+
+static void gprs_writeable(struct gprs_dev *gp)
+{
+ struct net_device *dev = gp->dev;
+
+ if (pep_writeable(gp->sk))
+ netif_wake_queue(dev);
}
/*
@@ -73,18 +75,21 @@ static int gprs_type_trans(struct sk_buff *skb)
static void gprs_state_change(struct sock *sk)
{
- struct gprs_dev *dev = sk->sk_user_data;
+ struct gprs_dev *gp = sk->sk_user_data;
if (sk->sk_state == TCP_CLOSE_WAIT) {
- netif_stop_queue(dev->net);
- netif_carrier_off(dev->net);
+ struct net_device *dev = gp->dev;
+
+ netif_stop_queue(dev);
+ netif_carrier_off(dev);
}
}
-static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
+static int gprs_recv(struct gprs_dev *gp, struct sk_buff *skb)
{
+ struct net_device *dev = gp->dev;
int err = 0;
- u16 protocol = gprs_type_trans(skb);
+ __be16 protocol = gprs_type_trans(skb);
if (!protocol) {
err = -EINVAL;
@@ -99,7 +104,7 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
* so wrap the IP packet as a single fragment of an head-less
* socket buffer. The network stack will pull what it needs,
* but at least, the whole IP payload is not memcpy'd. */
- rskb = netdev_alloc_skb(dev->net, 0);
+ rskb = netdev_alloc_skb(dev, 0);
if (!rskb) {
err = -ENOBUFS;
goto drop;
@@ -123,9 +128,9 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
skb->protocol = protocol;
skb_reset_mac_header(skb);
- skb->dev = dev->net;
+ skb->dev = dev;
- if (likely(dev->net->flags & IFF_UP)) {
+ if (likely(dev->flags & IFF_UP)) {
dev->stats.rx_packets++;
dev->stats.rx_bytes += skb->len;
netif_rx(skb);
@@ -143,34 +148,46 @@ drop:
static void gprs_data_ready(struct sock *sk, int len)
{
- struct gprs_dev *dev = sk->sk_user_data;
+ struct gprs_dev *gp = sk->sk_user_data;
struct sk_buff *skb;
while ((skb = pep_read(sk)) != NULL) {
skb_orphan(skb);
- gprs_recv(dev, skb);
+ gprs_recv(gp, skb);
}
}
static void gprs_write_space(struct sock *sk)
{
- struct gprs_dev *dev = sk->sk_user_data;
- unsigned credits = pep_writeable(sk);
-
- spin_lock_bh(&dev->tx_lock);
- dev->tx_max = credits;
- if (credits > skb_queue_len(&dev->tx_queue))
- netif_wake_queue(dev->net);
- spin_unlock_bh(&dev->tx_lock);
+ struct gprs_dev *gp = sk->sk_user_data;
+
+ if (netif_running(gp->dev))
+ gprs_writeable(gp);
}
/*
* Network device callbacks
*/
-static int gprs_xmit(struct sk_buff *skb, struct net_device *net)
+static int gprs_open(struct net_device *dev)
{
- struct gprs_dev *dev = netdev_priv(net);
+ struct gprs_dev *gp = netdev_priv(dev);
+
+ gprs_writeable(gp);
+ return 0;
+}
+
+static int gprs_close(struct net_device *dev)
+{
+ netif_stop_queue(dev);
+ return 0;
+}
+
+static int gprs_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+ struct gprs_dev *gp = netdev_priv(dev);
+ struct sock *sk = gp->sk;
+ int len, err;
switch (skb->protocol) {
case htons(ETH_P_IP):
@@ -181,82 +198,54 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *net)
return 0;
}
- spin_lock(&dev->tx_lock);
- if (likely(skb_queue_len(&dev->tx_queue) < dev->tx_max)) {
- skb_queue_tail(&dev->tx_queue, skb);
- skb = NULL;
- }
- if (skb_queue_len(&dev->tx_queue) >= dev->tx_max)
- netif_stop_queue(net);
- spin_unlock(&dev->tx_lock);
-
- schedule_work(&dev->tx_work);
- if (unlikely(skb))
+ skb_orphan(skb);
+ skb_set_owner_w(skb, sk);
+ len = skb->len;
+ err = pep_write(sk, skb);
+ if (err) {
+ LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
+ dev->name, err);
+ dev->stats.tx_aborted_errors++;
+ dev->stats.tx_errors++;
dev_kfree_skb(skb);
- return 0;
-}
-
-static void gprs_tx(struct work_struct *work)
-{
- struct gprs_dev *dev = container_of(work, struct gprs_dev, tx_work);
- struct sock *sk = dev->sk;
- struct sk_buff *skb;
-
- while ((skb = skb_dequeue(&dev->tx_queue)) != NULL) {
- int err;
-
- dev->stats.tx_bytes += skb->len;
+ } else {
dev->stats.tx_packets++;
-
- skb_orphan(skb);
- skb_set_owner_w(skb, sk);
-
- lock_sock(sk);
- err = pep_write(sk, skb);
- if (err) {
- LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
- dev->net->name, err);
- dev->stats.tx_aborted_errors++;
- dev->stats.tx_errors++;
- }
- release_sock(sk);
+ dev->stats.tx_bytes += len;
}
- lock_sock(sk);
- gprs_write_space(sk);
- release_sock(sk);
+ if (!pep_writeable(sk))
+ netif_stop_queue(dev);
+ return 0;
}
-static int gprs_set_mtu(struct net_device *net, int new_mtu)
+static int gprs_set_mtu(struct net_device *dev, int new_mtu)
{
if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11)))
return -EINVAL;
- net->mtu = new_mtu;
+ dev->mtu = new_mtu;
return 0;
}
-static struct net_device_stats *gprs_get_stats(struct net_device *net)
-{
- struct gprs_dev *dev = netdev_priv(net);
-
- return &dev->stats;
-}
+static const struct net_device_ops gprs_netdev_ops = {
+ .ndo_open = gprs_open,
+ .ndo_stop = gprs_close,
+ .ndo_start_xmit = gprs_xmit,
+ .ndo_change_mtu = gprs_set_mtu,
+};
-static void gprs_setup(struct net_device *net)
+static void gprs_setup(struct net_device *dev)
{
- net->features = NETIF_F_FRAGLIST;
- net->type = ARPHRD_NONE;
- net->flags = IFF_POINTOPOINT | IFF_NOARP;
- net->mtu = GPRS_DEFAULT_MTU;
- net->hard_header_len = 0;
- net->addr_len = 0;
- net->tx_queue_len = 10;
-
- net->destructor = free_netdev;
- net->hard_start_xmit = gprs_xmit; /* mandatory */
- net->change_mtu = gprs_set_mtu;
- net->get_stats = gprs_get_stats;
+ dev->features = NETIF_F_FRAGLIST;
+ dev->type = ARPHRD_PHONET_PIPE;
+ dev->flags = IFF_POINTOPOINT | IFF_NOARP;
+ dev->mtu = GPRS_DEFAULT_MTU;
+ dev->hard_header_len = 0;
+ dev->addr_len = 0;
+ dev->tx_queue_len = 10;
+
+ dev->netdev_ops = &gprs_netdev_ops;
+ dev->destructor = free_netdev;
}
/*
@@ -270,28 +259,25 @@ static void gprs_setup(struct net_device *net)
int gprs_attach(struct sock *sk)
{
static const char ifname[] = "gprs%d";
- struct gprs_dev *dev;
- struct net_device *net;
+ struct gprs_dev *gp;
+ struct net_device *dev;
int err;
if (unlikely(sk->sk_type == SOCK_STREAM))
return -EINVAL; /* need packet boundaries */
/* Create net device */
- net = alloc_netdev(sizeof(*dev), ifname, gprs_setup);
- if (!net)
+ dev = alloc_netdev(sizeof(*gp), ifname, gprs_setup);
+ if (!dev)
return -ENOMEM;
- dev = netdev_priv(net);
- dev->net = net;
- dev->tx_max = 0;
- spin_lock_init(&dev->tx_lock);
- skb_queue_head_init(&dev->tx_queue);
- INIT_WORK(&dev->tx_work, gprs_tx);
-
- netif_stop_queue(net);
- err = register_netdev(net);
+ gp = netdev_priv(dev);
+ gp->sk = sk;
+ gp->dev = dev;
+
+ netif_stop_queue(dev);
+ err = register_netdev(dev);
if (err) {
- free_netdev(net);
+ free_netdev(dev);
return err;
}
@@ -305,43 +291,38 @@ int gprs_attach(struct sock *sk)
err = -EINVAL;
goto out_rel;
}
- sk->sk_user_data = dev;
- dev->old_state_change = sk->sk_state_change;
- dev->old_data_ready = sk->sk_data_ready;
- dev->old_write_space = sk->sk_write_space;
+ sk->sk_user_data = gp;
+ gp->old_state_change = sk->sk_state_change;
+ gp->old_data_ready = sk->sk_data_ready;
+ gp->old_write_space = sk->sk_write_space;
sk->sk_state_change = gprs_state_change;
sk->sk_data_ready = gprs_data_ready;
sk->sk_write_space = gprs_write_space;
release_sock(sk);
-
sock_hold(sk);
- dev->sk = sk;
- printk(KERN_DEBUG"%s: attached\n", net->name);
- gprs_write_space(sk); /* kick off TX */
- return net->ifindex;
+ printk(KERN_DEBUG"%s: attached\n", dev->name);
+ return dev->ifindex;
out_rel:
release_sock(sk);
- unregister_netdev(net);
+ unregister_netdev(dev);
return err;
}
void gprs_detach(struct sock *sk)
{
- struct gprs_dev *dev = sk->sk_user_data;
- struct net_device *net = dev->net;
+ struct gprs_dev *gp = sk->sk_user_data;
+ struct net_device *dev = gp->dev;
lock_sock(sk);
sk->sk_user_data = NULL;
- sk->sk_state_change = dev->old_state_change;
- sk->sk_data_ready = dev->old_data_ready;
- sk->sk_write_space = dev->old_write_space;
+ sk->sk_state_change = gp->old_state_change;
+ sk->sk_data_ready = gp->old_data_ready;
+ sk->sk_write_space = gp->old_write_space;
release_sock(sk);
- printk(KERN_DEBUG"%s: detached\n", net->name);
- unregister_netdev(net);
- flush_scheduled_work();
+ printk(KERN_DEBUG"%s: detached\n", dev->name);
+ unregister_netdev(dev);
sock_put(sk);
- skb_queue_purge(&dev->tx_queue);
}
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index bc6d50f8324..bb3e67849b3 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -225,6 +225,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
{
struct pep_sock *pn = pep_sk(sk);
struct pnpipehdr *hdr = pnp_hdr(skb);
+ int wake = 0;
if (!pskb_may_pull(skb, sizeof(*hdr) + 4))
return -EINVAL;
@@ -241,16 +242,16 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
case PN_LEGACY_FLOW_CONTROL:
switch (hdr->data[4]) {
case PEP_IND_BUSY:
- pn->tx_credits = 0;
+ atomic_set(&pn->tx_credits, 0);
break;
case PEP_IND_READY:
- pn->tx_credits = 1;
+ atomic_set(&pn->tx_credits, wake = 1);
break;
}
break;
case PN_ONE_CREDIT_FLOW_CONTROL:
if (hdr->data[4] == PEP_IND_READY)
- pn->tx_credits = 1;
+ atomic_set(&pn->tx_credits, wake = 1);
break;
}
break;
@@ -258,10 +259,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
case PN_PEP_IND_ID_MCFC_GRANT_CREDITS:
if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL)
break;
- if (pn->tx_credits + hdr->data[4] > 0xff)
- pn->tx_credits = 0xff;
- else
- pn->tx_credits += hdr->data[4];
+ atomic_add(wake = hdr->data[4], &pn->tx_credits);
break;
default:
@@ -269,7 +267,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
(unsigned)hdr->data[1]);
return -EOPNOTSUPP;
}
- if (pn->tx_credits)
+ if (wake)
sk->sk_write_space(sk);
return 0;
}
@@ -343,7 +341,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
}
/* fall through */
case PNS_PEP_DISABLE_REQ:
- pn->tx_credits = 0;
+ atomic_set(&pn->tx_credits, 0);
pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
break;
@@ -390,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
/* fall through */
case PNS_PIPE_ENABLED_IND:
if (!pn_flow_safe(pn->tx_fc)) {
- pn->tx_credits = 1;
+ atomic_set(&pn->tx_credits, 1);
sk->sk_write_space(sk);
}
if (sk->sk_state == TCP_ESTABLISHED)
@@ -504,8 +502,9 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
newpn->pn_sk.resource = pn->pn_sk.resource;
skb_queue_head_init(&newpn->ctrlreq_queue);
newpn->pipe_handle = pipe_handle;
+ atomic_set(&newpn->tx_credits, 0);
newpn->peer_type = peer_type;
- newpn->rx_credits = newpn->tx_credits = 0;
+ newpn->rx_credits = 0;
newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
newpn->init_enable = enabled;
@@ -821,14 +820,18 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
struct pep_sock *pn = pep_sk(sk);
struct pnpipehdr *ph;
+ if (pn_flow_safe(pn->tx_fc) &&
+ !atomic_add_unless(&pn->tx_credits, -1, 0)) {
+ kfree_skb(skb);
+ return -ENOBUFS;
+ }
+
skb_push(skb, 3);
skb_reset_transport_header(skb);
ph = pnp_hdr(skb);
ph->utid = 0;
ph->message_id = PNS_PIPE_DATA;
ph->pipe_handle = pn->pipe_handle;
- if (pn_flow_safe(pn->tx_fc) && pn->tx_credits)
- pn->tx_credits--;
return pn_skb_send(sk, skb, &pipe_srv);
}
@@ -866,7 +869,7 @@ disabled:
BUG_ON(sk->sk_state != TCP_ESTABLISHED);
/* Wait until flow control allows TX */
- done = pn->tx_credits > 0;
+ done = atomic_read(&pn->tx_credits);
while (!done) {
DEFINE_WAIT(wait);
@@ -881,7 +884,7 @@ disabled:
prepare_to_wait(&sk->sk_socket->wait, &wait,
TASK_INTERRUPTIBLE);
- done = sk_wait_event(sk, &timeo, pn->tx_credits > 0);
+ done = sk_wait_event(sk, &timeo, atomic_read(&pn->tx_credits));
finish_wait(&sk->sk_socket->wait, &wait);
if (sk->sk_state != TCP_ESTABLISHED)
@@ -895,7 +898,8 @@ disabled:
goto out;
skb_reserve(skb, MAX_PHONET_HEADER + 3);
- if (sk->sk_state != TCP_ESTABLISHED || !pn->tx_credits)
+ if (sk->sk_state != TCP_ESTABLISHED ||
+ !atomic_read(&pn->tx_credits))
goto disabled; /* sock_alloc_send_skb might sleep */
}
@@ -917,7 +921,7 @@ int pep_writeable(struct sock *sk)
{
struct pep_sock *pn = pep_sk(sk);
- return (sk->sk_state == TCP_ESTABLISHED) ? pn->tx_credits : 0;
+ return atomic_read(&pn->tx_credits);
}
int pep_write(struct sock *sk, struct sk_buff *skb)
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 53be9fc82aa..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)
dev = pnd->netdev;
BUG_ON(!dev);
- if (dev_net(dev) == net &&
+ if (net_eq(dev_net(dev), net) &&
(dev->reg_state == NETREG_REGISTERED) &&
((pnd->netdev->flags & IFF_UP)) == IFF_UP)
break;
@@ -115,7 +115,7 @@ int phonet_address_del(struct net_device *dev, u8 addr)
pnd = __phonet_get(dev);
if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs))
err = -EADDRNOTAVAIL;
- if (bitmap_empty(pnd->addrs, 64))
+ else if (bitmap_empty(pnd->addrs, 64))
__phonet_device_free(pnd);
spin_unlock_bh(&pndevs.lock);
return err;
@@ -140,12 +140,14 @@ u8 phonet_address_get(struct net_device *dev, u8 addr)
return addr;
}
-int phonet_address_lookup(u8 addr)
+int phonet_address_lookup(struct net *net, u8 addr)
{
struct phonet_device *pnd;
spin_lock_bh(&pndevs.lock);
list_for_each_entry(pnd, &pndevs.list, list) {
+ if (!net_eq(dev_net(pnd->netdev), net))
+ continue;
/* Don't allow unregistering devices! */
if ((pnd->netdev->reg_state != NETREG_REGISTERED) ||
((pnd->netdev->flags & IFF_UP)) != IFF_UP)
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index b1770d66bc8..242fe8f8c32 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -123,6 +123,7 @@ nla_put_failure:
static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
{
+ struct net *net = sock_net(skb->sk);
struct phonet_device *pnd;
int dev_idx = 0, dev_start_idx = cb->args[0];
int addr_idx = 0, addr_start_idx = cb->args[1];
@@ -131,6 +132,8 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
list_for_each_entry(pnd, &pndevs.list, list) {
u8 addr;
+ if (!net_eq(dev_net(pnd->netdev), net))
+ continue;
if (dev_idx > dev_start_idx)
addr_start_idx = 0;
if (dev_idx++ < dev_start_idx)
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index d81740187fb..ada2a35bf7a 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -57,7 +57,7 @@ static struct {
* Find address based on socket address, match only certain fields.
* 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 sock *sknode;
@@ -71,6 +71,8 @@ struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn)
struct pn_sock *pn = pn_sk(sknode);
BUG_ON(!pn->sobject); /* unbound socket */
+ if (!net_eq(sock_net(sknode), net))
+ continue;
if (pn_port(obj)) {
/* Look up socket by port */
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)
handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr);
saddr = pn_addr(handle);
- if (saddr && phonet_address_lookup(saddr))
+ if (saddr && phonet_address_lookup(sock_net(sk), saddr))
return -EADDRNOTAVAIL;
lock_sock(sk);
@@ -225,7 +227,7 @@ static unsigned int pn_socket_poll(struct file *file, struct socket *sock,
if (!mask && sk->sk_state == TCP_CLOSE_WAIT)
return POLLHUP;
- if (sk->sk_state == TCP_ESTABLISHED && pn->tx_credits)
+ if (sk->sk_state == TCP_ESTABLISHED && atomic_read(&pn->tx_credits))
mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
return mask;
@@ -361,6 +363,7 @@ static DEFINE_MUTEX(port_mutex);
int pn_sock_get_port(struct sock *sk, unsigned short sport)
{
static int port_cur;
+ struct net *net = sock_net(sk);
struct pn_sock *pn = pn_sk(sk);
struct sockaddr_pn try_sa;
struct sock *tmpsk;
@@ -381,7 +384,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
port_cur = pmin;
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) {
sport = port_cur;
goto found;
@@ -391,7 +394,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
} else {
/* try to find specific port */
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)
/* No sock there! We can use that port... */
goto found;
diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
index 600a4309b8c..7b5749ee276 100644
--- a/net/phonet/sysctl.c
+++ b/net/phonet/sysctl.c
@@ -89,13 +89,13 @@ static struct ctl_table phonet_table[] = {
.data = &local_port_range,
.maxlen = sizeof(local_port_range),
.mode = 0644,
- .proc_handler = &proc_local_port_range,
+ .proc_handler = proc_local_port_range,
.strategy = NULL,
},
{ .ctl_name = 0 }
};
-struct ctl_path phonet_ctl_path[] = {
+static struct ctl_path phonet_ctl_path[] = {
{ .procname = "net", .ctl_name = CTL_NET, },
{ .procname = "phonet", .ctl_name = CTL_UNNUMBERED, },
{ },