2019-05-19 20:08:20 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 06:20:36 +08:00
|
|
|
/* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
|
|
|
|
|
|
|
|
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
|
|
|
|
|
2010-01-26 19:40:00 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/net.h> /* struct socket, struct proto_ops */
|
|
|
|
#include <linux/atm.h> /* ATM stuff */
|
|
|
|
#include <linux/atmdev.h>
|
|
|
|
#include <linux/socket.h> /* SOL_SOCKET */
|
|
|
|
#include <linux/errno.h> /* error codes */
|
|
|
|
#include <linux/capability.h>
|
2005-05-01 23:59:08 +08:00
|
|
|
#include <linux/mm.h>
|
2017-02-09 01:51:30 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2017-11-27 22:02:17 +08:00
|
|
|
#include <linux/time64.h> /* 64-bit time for seconds */
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/sock.h> /* struct sock */
|
2010-01-26 19:40:06 +08:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/poll.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "resources.h" /* atm_find_dev */
|
|
|
|
#include "common.h" /* prototypes */
|
|
|
|
#include "protocols.h" /* atm_init_<transport> */
|
|
|
|
#include "addr.h" /* address registry */
|
|
|
|
#include "signaling.h" /* for WAITING and sigd_attach */
|
|
|
|
|
|
|
|
struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
|
2010-01-26 19:40:06 +08:00
|
|
|
EXPORT_SYMBOL(vcc_hash);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
DEFINE_RWLOCK(vcc_sklist_lock);
|
2010-01-26 19:40:06 +08:00
|
|
|
EXPORT_SYMBOL(vcc_sklist_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-09 04:55:30 +08:00
|
|
|
static ATOMIC_NOTIFIER_HEAD(atm_dev_notify_chain);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void __vcc_insert_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct atm_vcc *vcc = atm_sk(sk);
|
2010-01-26 19:40:06 +08:00
|
|
|
struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)];
|
[INET]: speedup inet (tcp/dccp) lookups
Arnaldo and I agreed it could be applied now, because I have other
pending patches depending on this one (Thank you Arnaldo)
(The other important patch moves skc_refcnt in a separate cache line,
so that the SMP/NUMA performance doesnt suffer from cache line ping pongs)
1) First some performance data :
--------------------------------
tcp_v4_rcv() wastes a *lot* of time in __inet_lookup_established()
The most time critical code is :
sk_for_each(sk, node, &head->chain) {
if (INET_MATCH(sk, acookie, saddr, daddr, ports, dif))
goto hit; /* You sunk my battleship! */
}
The sk_for_each() does use prefetch() hints but only the begining of
"struct sock" is prefetched.
As INET_MATCH first comparison uses inet_sk(__sk)->daddr, wich is far
away from the begining of "struct sock", it has to bring into CPU
cache cold cache line. Each iteration has to use at least 2 cache
lines.
This can be problematic if some chains are very long.
2) The goal
-----------
The idea I had is to change things so that INET_MATCH() may return
FALSE in 99% of cases only using the data already in the CPU cache,
using one cache line per iteration.
3) Description of the patch
---------------------------
Adds a new 'unsigned int skc_hash' field in 'struct sock_common',
filling a 32 bits hole on 64 bits platform.
struct sock_common {
unsigned short skc_family;
volatile unsigned char skc_state;
unsigned char skc_reuse;
int skc_bound_dev_if;
struct hlist_node skc_node;
struct hlist_node skc_bind_node;
atomic_t skc_refcnt;
+ unsigned int skc_hash;
struct proto *skc_prot;
};
Store in this 32 bits field the full hash, not masked by (ehash_size -
1) Using this full hash as the first comparison done in INET_MATCH
permits us immediatly skip the element without touching a second cache
line in case of a miss.
Suppress the sk_hashent/tw_hashent fields since skc_hash (aliased to
sk_hash and tw_hash) already contains the slot number if we mask with
(ehash_size - 1)
File include/net/inet_hashtables.h
64 bits platforms :
#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash))
((*((__u64 *)&(inet_sk(__sk)->daddr)))== (__cookie)) && \
((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
32bits platforms:
#define TCP_IPV4_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash)) && \
(inet_sk(__sk)->daddr == (__saddr)) && \
(inet_sk(__sk)->rcv_saddr == (__daddr)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
- Adds a prefetch(head->chain.first) in
__inet_lookup_established()/__tcp_v4_check_established() and
__inet6_lookup_established()/__tcp_v6_check_established() and
__dccp_v4_check_established() to bring into cache the first element of the
list, before the {read|write}_lock(&head->lock);
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-10-04 05:13:38 +08:00
|
|
|
sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
sk_add_node(sk, head);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vcc_insert_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
write_lock_irq(&vcc_sklist_lock);
|
|
|
|
__vcc_insert_socket(sk);
|
|
|
|
write_unlock_irq(&vcc_sklist_lock);
|
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
EXPORT_SYMBOL(vcc_insert_socket);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void vcc_remove_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
write_lock_irq(&vcc_sklist_lock);
|
|
|
|
sk_del_node_init(sk);
|
|
|
|
write_unlock_irq(&vcc_sklist_lock);
|
|
|
|
}
|
|
|
|
|
2017-03-12 08:41:36 +08:00
|
|
|
static bool vcc_tx_ready(struct atm_vcc *vcc, unsigned int size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sk_atm(vcc);
|
|
|
|
|
2009-06-18 10:06:12 +08:00
|
|
|
if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
|
2007-08-29 06:22:09 +08:00
|
|
|
pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
|
2010-01-26 19:40:00 +08:00
|
|
|
sk_wmem_alloc_get(sk), size, sk->sk_sndbuf);
|
2017-03-12 08:41:36 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2017-03-12 08:41:36 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vcc_sock_destruct(struct sock *sk)
|
|
|
|
{
|
|
|
|
if (atomic_read(&sk->sk_rmem_alloc))
|
2010-01-26 19:40:06 +08:00
|
|
|
printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n",
|
|
|
|
__func__, atomic_read(&sk->sk_rmem_alloc));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-06-30 18:08:00 +08:00
|
|
|
if (refcount_read(&sk->sk_wmem_alloc))
|
2010-01-26 19:40:06 +08:00
|
|
|
printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n",
|
2017-06-30 18:08:00 +08:00
|
|
|
__func__, refcount_read(&sk->sk_wmem_alloc));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vcc_def_wakeup(struct sock *sk)
|
|
|
|
{
|
2010-04-29 19:01:49 +08:00
|
|
|
struct socket_wq *wq;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
wq = rcu_dereference(sk->sk_wq);
|
2015-11-26 13:55:39 +08:00
|
|
|
if (skwq_has_sleeper(wq))
|
2010-04-29 19:01:49 +08:00
|
|
|
wake_up(&wq->wait);
|
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int vcc_writable(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct atm_vcc *vcc = atm_sk(sk);
|
|
|
|
|
|
|
|
return (vcc->qos.txtp.max_sdu +
|
2017-06-30 18:08:00 +08:00
|
|
|
refcount_read(&sk->sk_wmem_alloc)) <= sk->sk_sndbuf;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vcc_write_space(struct sock *sk)
|
2007-02-09 22:24:29 +08:00
|
|
|
{
|
2010-04-29 19:01:49 +08:00
|
|
|
struct socket_wq *wq;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (vcc_writable(sk)) {
|
2010-04-29 19:01:49 +08:00
|
|
|
wq = rcu_dereference(sk->sk_wq);
|
2015-11-26 13:55:39 +08:00
|
|
|
if (skwq_has_sleeper(wq))
|
2010-04-29 19:01:49 +08:00
|
|
|
wake_up_interruptible(&wq->wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-26 20:10:50 +08:00
|
|
|
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-04-29 19:01:49 +08:00
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 08:03:11 +08:00
|
|
|
static void vcc_release_cb(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct atm_vcc *vcc = atm_sk(sk);
|
|
|
|
|
|
|
|
if (vcc->release_cb)
|
|
|
|
vcc->release_cb(vcc);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct proto vcc_proto = {
|
|
|
|
.name = "VCC",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.obj_size = sizeof(struct atm_vcc),
|
2012-11-28 08:03:11 +08:00
|
|
|
.release_cb = vcc_release_cb,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2007-02-09 22:24:29 +08:00
|
|
|
|
2015-05-09 10:09:13 +08:00
|
|
|
int vcc_create(struct net *net, struct socket *sock, int protocol, int family, int kern)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
struct atm_vcc *vcc;
|
|
|
|
|
|
|
|
sock->sk = NULL;
|
|
|
|
if (sock->type == SOCK_STREAM)
|
|
|
|
return -EINVAL;
|
2015-05-09 10:09:13 +08:00
|
|
|
sk = sk_alloc(net, family, GFP_KERNEL, &vcc_proto, kern);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sk)
|
|
|
|
return -ENOMEM;
|
|
|
|
sock_init_data(sock, sk);
|
|
|
|
sk->sk_state_change = vcc_def_wakeup;
|
|
|
|
sk->sk_write_space = vcc_write_space;
|
|
|
|
|
|
|
|
vcc = atm_sk(sk);
|
|
|
|
vcc->dev = NULL;
|
2010-01-26 19:40:06 +08:00
|
|
|
memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc));
|
|
|
|
memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc));
|
2005-04-17 06:20:36 +08:00
|
|
|
vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
|
2017-06-30 18:08:00 +08:00
|
|
|
refcount_set(&sk->sk_wmem_alloc, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_set(&sk->sk_rmem_alloc, 0);
|
|
|
|
vcc->push = NULL;
|
|
|
|
vcc->pop = NULL;
|
2012-11-07 06:16:57 +08:00
|
|
|
vcc->owner = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
vcc->push_oam = NULL;
|
2012-11-28 08:03:11 +08:00
|
|
|
vcc->release_cb = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
|
|
|
|
vcc->atm_options = vcc->aal_options = 0;
|
|
|
|
sk->sk_destruct = vcc_sock_destruct;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vcc_destroy_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct atm_vcc *vcc = atm_sk(sk);
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
set_bit(ATM_VF_CLOSE, &vcc->flags);
|
|
|
|
clear_bit(ATM_VF_READY, &vcc->flags);
|
2020-05-02 02:11:08 +08:00
|
|
|
if (vcc->dev && vcc->dev->ops->close)
|
|
|
|
vcc->dev->ops->close(vcc);
|
|
|
|
if (vcc->push)
|
|
|
|
vcc->push(vcc, NULL); /* atmarpd has no push */
|
|
|
|
module_put(vcc->owner);
|
|
|
|
|
|
|
|
while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
|
|
|
|
atm_return(vcc, skb->truesize);
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-05-02 02:11:08 +08:00
|
|
|
if (vcc->dev && vcc->dev->ops->owner) {
|
2005-04-17 06:20:36 +08:00
|
|
|
module_put(vcc->dev->ops->owner);
|
|
|
|
atm_dev_put(vcc->dev);
|
|
|
|
}
|
2005-09-29 07:35:01 +08:00
|
|
|
|
|
|
|
vcc_remove_socket(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int vcc_release(struct socket *sock)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
if (sk) {
|
|
|
|
lock_sock(sk);
|
|
|
|
vcc_destroy_socket(sock->sk);
|
|
|
|
release_sock(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vcc_release_async(struct atm_vcc *vcc, int reply)
|
|
|
|
{
|
|
|
|
struct sock *sk = sk_atm(vcc);
|
|
|
|
|
|
|
|
set_bit(ATM_VF_CLOSE, &vcc->flags);
|
|
|
|
sk->sk_shutdown |= RCV_SHUTDOWN;
|
|
|
|
sk->sk_err = -reply;
|
|
|
|
clear_bit(ATM_VF_WAITING, &vcc->flags);
|
|
|
|
sk->sk_state_change(sk);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vcc_release_async);
|
|
|
|
|
2011-11-21 18:25:57 +08:00
|
|
|
void vcc_process_recv_queue(struct atm_vcc *vcc)
|
|
|
|
{
|
|
|
|
struct sk_buff_head queue, *rq;
|
|
|
|
struct sk_buff *skb, *tmp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
__skb_queue_head_init(&queue);
|
|
|
|
rq = &sk_atm(vcc)->sk_receive_queue;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rq->lock, flags);
|
|
|
|
skb_queue_splice_init(rq, &queue);
|
|
|
|
spin_unlock_irqrestore(&rq->lock, flags);
|
|
|
|
|
|
|
|
skb_queue_walk_safe(&queue, skb, tmp) {
|
|
|
|
__skb_unlink(skb, &queue);
|
|
|
|
vcc->push(vcc, skb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vcc_process_recv_queue);
|
|
|
|
|
2010-07-09 04:55:30 +08:00
|
|
|
void atm_dev_signal_change(struct atm_dev *dev, char signal)
|
|
|
|
{
|
|
|
|
pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
|
|
|
|
__func__, signal, dev, dev->number, dev->signal);
|
|
|
|
|
|
|
|
/* atm driver sending invalid signal */
|
|
|
|
WARN_ON(signal < ATM_PHY_SIG_LOST || signal > ATM_PHY_SIG_FOUND);
|
|
|
|
|
|
|
|
if (dev->signal == signal)
|
|
|
|
return; /* no change */
|
|
|
|
|
|
|
|
dev->signal = signal;
|
|
|
|
|
|
|
|
atomic_notifier_call_chain(&atm_dev_notify_chain, signal, dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(atm_dev_signal_change);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-30 08:16:41 +08:00
|
|
|
void atm_dev_release_vccs(struct atm_dev *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
write_lock_irq(&vcc_sklist_lock);
|
|
|
|
for (i = 0; i < VCC_HTABLE_SIZE; i++) {
|
|
|
|
struct hlist_head *head = &vcc_hash[i];
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
struct hlist_node *tmp;
|
2005-11-30 08:16:41 +08:00
|
|
|
struct sock *s;
|
|
|
|
struct atm_vcc *vcc;
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
sk_for_each_safe(s, tmp, head) {
|
2005-11-30 08:16:41 +08:00
|
|
|
vcc = atm_sk(s);
|
|
|
|
if (vcc->dev == dev) {
|
|
|
|
vcc_release_async(vcc, -EPIPE);
|
|
|
|
sk_del_node_init(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_unlock_irq(&vcc_sklist_lock);
|
|
|
|
}
|
2011-03-30 21:17:04 +08:00
|
|
|
EXPORT_SYMBOL(atm_dev_release_vccs);
|
2005-11-30 08:16:41 +08:00
|
|
|
|
2010-01-26 19:40:06 +08:00
|
|
|
static int adjust_tp(struct atm_trafprm *tp, unsigned char aal)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int max_sdu;
|
|
|
|
|
2010-01-26 19:40:06 +08:00
|
|
|
if (!tp->traffic_class)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (aal) {
|
2010-01-26 19:40:06 +08:00
|
|
|
case ATM_AAL0:
|
|
|
|
max_sdu = ATM_CELL_SIZE-1;
|
|
|
|
break;
|
|
|
|
case ATM_AAL34:
|
|
|
|
max_sdu = ATM_MAX_AAL34_PDU;
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-10 12:17:28 +08:00
|
|
|
pr_warn("AAL problems ... (%d)\n", aal);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2010-01-26 19:40:06 +08:00
|
|
|
case ATM_AAL5:
|
|
|
|
max_sdu = ATM_MAX_AAL5_PDU;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
if (!tp->max_sdu)
|
|
|
|
tp->max_sdu = max_sdu;
|
|
|
|
else if (tp->max_sdu > max_sdu)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!tp->max_cdv)
|
|
|
|
tp->max_cdv = ATM_MAX_CDV;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-18 07:20:06 +08:00
|
|
|
static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-01-26 19:40:06 +08:00
|
|
|
struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)];
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sock *s;
|
|
|
|
struct atm_vcc *walk;
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
sk_for_each(s, head) {
|
2005-04-17 06:20:36 +08:00
|
|
|
walk = atm_sk(s);
|
|
|
|
if (walk->dev != vcc->dev)
|
|
|
|
continue;
|
|
|
|
if (test_bit(ATM_VF_ADDR, &walk->flags) && walk->vpi == vpi &&
|
|
|
|
walk->vci == vci && ((walk->qos.txtp.traffic_class !=
|
|
|
|
ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
|
|
|
|
(walk->qos.rxtp.traffic_class != ATM_NONE &&
|
|
|
|
vcc->qos.rxtp.traffic_class != ATM_NONE)))
|
|
|
|
return -EADDRINUSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allow VCCs with same VPI/VCI iff they don't collide on
|
|
|
|
TX/RX (but we may refuse such sharing for other reasons,
|
|
|
|
e.g. if protocol requires to have both channels) */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-18 07:20:06 +08:00
|
|
|
static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
static short p; /* poor man's per-device cache */
|
|
|
|
static int c;
|
|
|
|
short old_p;
|
|
|
|
int old_c;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
|
|
|
|
err = check_ci(vcc, *vpi, *vci);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/* last scan may have left values out of bounds for current device */
|
|
|
|
if (*vpi != ATM_VPI_ANY)
|
|
|
|
p = *vpi;
|
|
|
|
else if (p >= 1 << vcc->dev->ci_range.vpi_bits)
|
|
|
|
p = 0;
|
|
|
|
if (*vci != ATM_VCI_ANY)
|
|
|
|
c = *vci;
|
|
|
|
else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->dev->ci_range.vci_bits)
|
|
|
|
c = ATM_NOT_RSV_VCI;
|
|
|
|
old_p = p;
|
|
|
|
old_c = c;
|
|
|
|
do {
|
|
|
|
if (!check_ci(vcc, p, c)) {
|
|
|
|
*vpi = p;
|
|
|
|
*vci = c;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (*vci == ATM_VCI_ANY) {
|
|
|
|
c++;
|
|
|
|
if (c >= 1 << vcc->dev->ci_range.vci_bits)
|
|
|
|
c = ATM_NOT_RSV_VCI;
|
|
|
|
}
|
|
|
|
if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
|
|
|
|
*vpi == ATM_VPI_ANY) {
|
|
|
|
p++;
|
2010-01-26 19:40:06 +08:00
|
|
|
if (p >= 1 << vcc->dev->ci_range.vpi_bits)
|
|
|
|
p = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
} while (old_p != p || old_c != c);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EADDRINUSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
|
|
|
|
int vci)
|
|
|
|
{
|
|
|
|
struct sock *sk = sk_atm(vcc);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
|
|
|
|
vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
|
|
|
|
vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
|
|
|
|
return -EINVAL;
|
|
|
|
if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
|
|
|
|
return -EPERM;
|
2005-11-30 08:16:41 +08:00
|
|
|
error = -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!try_module_get(dev->ops->owner))
|
2005-11-30 08:16:41 +08:00
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
vcc->dev = dev;
|
|
|
|
write_lock_irq(&vcc_sklist_lock);
|
2007-02-09 22:24:29 +08:00
|
|
|
if (test_bit(ATM_DF_REMOVED, &dev->flags) ||
|
2005-11-30 08:16:41 +08:00
|
|
|
(error = find_ci(vcc, &vpi, &vci))) {
|
2005-04-17 06:20:36 +08:00
|
|
|
write_unlock_irq(&vcc_sklist_lock);
|
|
|
|
goto fail_module_put;
|
|
|
|
}
|
|
|
|
vcc->vpi = vpi;
|
|
|
|
vcc->vci = vci;
|
|
|
|
__vcc_insert_socket(sk);
|
|
|
|
write_unlock_irq(&vcc_sklist_lock);
|
|
|
|
switch (vcc->qos.aal) {
|
2010-01-26 19:40:06 +08:00
|
|
|
case ATM_AAL0:
|
|
|
|
error = atm_init_aal0(vcc);
|
|
|
|
vcc->stats = &dev->stats.aal0;
|
|
|
|
break;
|
|
|
|
case ATM_AAL34:
|
|
|
|
error = atm_init_aal34(vcc);
|
|
|
|
vcc->stats = &dev->stats.aal34;
|
|
|
|
break;
|
|
|
|
case ATM_NO_AAL:
|
|
|
|
/* ATM_AAL5 is also used in the "0 for default" case */
|
|
|
|
vcc->qos.aal = ATM_AAL5;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2010-01-26 19:40:06 +08:00
|
|
|
case ATM_AAL5:
|
|
|
|
error = atm_init_aal5(vcc);
|
|
|
|
vcc->stats = &dev->stats.aal5;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = -EPROTOTYPE;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
if (!error)
|
|
|
|
error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal);
|
|
|
|
if (!error)
|
|
|
|
error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (error)
|
|
|
|
goto fail;
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal);
|
|
|
|
pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
|
|
|
|
vcc->qos.txtp.traffic_class,
|
|
|
|
vcc->qos.txtp.min_pcr,
|
|
|
|
vcc->qos.txtp.max_pcr,
|
|
|
|
vcc->qos.txtp.max_sdu);
|
|
|
|
pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
|
|
|
|
vcc->qos.rxtp.traffic_class,
|
|
|
|
vcc->qos.rxtp.min_pcr,
|
|
|
|
vcc->qos.rxtp.max_pcr,
|
|
|
|
vcc->qos.rxtp.max_sdu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dev->ops->open) {
|
2010-01-26 19:40:06 +08:00
|
|
|
error = dev->ops->open(vcc);
|
|
|
|
if (error)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
vcc_remove_socket(sk);
|
|
|
|
fail_module_put:
|
|
|
|
module_put(dev->ops->owner);
|
|
|
|
/* ensure we get dev module ref count correct */
|
|
|
|
vcc->dev = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
|
|
|
|
{
|
|
|
|
struct atm_dev *dev;
|
|
|
|
struct atm_vcc *vcc = ATM_SD(sock);
|
|
|
|
int error;
|
|
|
|
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_debug("(vpi %d, vci %d)\n", vpi, vci);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sock->state == SS_CONNECTED)
|
|
|
|
return -EISCONN;
|
|
|
|
if (sock->state != SS_UNCONNECTED)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!(vpi || vci))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
|
2010-01-26 19:40:06 +08:00
|
|
|
clear_bit(ATM_VF_PARTIAL, &vcc->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-01-26 19:40:06 +08:00
|
|
|
if (test_bit(ATM_VF_PARTIAL, &vcc->flags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
|
|
|
|
"RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
|
|
|
|
vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr,
|
|
|
|
vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu,
|
|
|
|
vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr,
|
2010-01-26 19:40:06 +08:00
|
|
|
vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu,
|
2010-01-26 19:40:00 +08:00
|
|
|
vcc->qos.aal == ATM_AAL5 ? "" :
|
|
|
|
vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ",
|
|
|
|
vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
|
|
|
|
return -EBADFD;
|
|
|
|
if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
|
|
|
|
vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
|
|
|
|
return -EINVAL;
|
2005-11-30 08:13:32 +08:00
|
|
|
if (likely(itf != ATM_ITF_ANY)) {
|
2010-01-26 19:40:06 +08:00
|
|
|
dev = try_then_request_module(atm_dev_lookup(itf),
|
|
|
|
"atm-device-%d", itf);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
dev = NULL;
|
2006-03-21 14:35:41 +08:00
|
|
|
mutex_lock(&atm_dev_mutex);
|
2005-11-30 08:13:32 +08:00
|
|
|
if (!list_empty(&atm_devs)) {
|
2010-01-26 19:40:06 +08:00
|
|
|
dev = list_entry(atm_devs.next,
|
|
|
|
struct atm_dev, dev_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
atm_dev_hold(dev);
|
|
|
|
}
|
2006-03-21 14:35:41 +08:00
|
|
|
mutex_unlock(&atm_dev_mutex);
|
2005-11-30 08:13:32 +08:00
|
|
|
}
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
error = __vcc_connect(vcc, dev, vpi, vci);
|
|
|
|
if (error) {
|
|
|
|
atm_dev_put(dev);
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
|
2010-01-26 19:40:06 +08:00
|
|
|
set_bit(ATM_VF_PARTIAL, &vcc->flags);
|
|
|
|
if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags))
|
2005-04-17 06:20:36 +08:00
|
|
|
sock->state = SS_CONNECTED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:37:48 +08:00
|
|
|
int vcc_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
|
|
|
int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct atm_vcc *vcc;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int copied, error = -EINVAL;
|
|
|
|
|
|
|
|
if (sock->state != SS_CONNECTED)
|
|
|
|
return -ENOTCONN;
|
2011-11-21 18:25:58 +08:00
|
|
|
|
|
|
|
/* only handle MSG_DONTWAIT and MSG_PEEK */
|
|
|
|
if (flags & ~(MSG_DONTWAIT | MSG_PEEK))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EOPNOTSUPP;
|
2011-11-21 18:25:58 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
vcc = ATM_SD(sock);
|
2010-01-26 19:40:06 +08:00
|
|
|
if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
|
|
|
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
2005-04-17 06:20:36 +08:00
|
|
|
!test_bit(ATM_VF_READY, &vcc->flags))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
|
|
|
|
if (!skb)
|
|
|
|
return error;
|
|
|
|
|
2007-02-09 22:24:29 +08:00
|
|
|
copied = skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (copied > size) {
|
2007-02-09 22:24:29 +08:00
|
|
|
copied = size;
|
2005-04-17 06:20:36 +08:00
|
|
|
msg->msg_flags |= MSG_TRUNC;
|
|
|
|
}
|
|
|
|
|
2014-11-06 05:46:40 +08:00
|
|
|
error = skb_copy_datagram_msg(skb, 0, msg, copied);
|
2007-02-09 22:24:29 +08:00
|
|
|
if (error)
|
|
|
|
return error;
|
net: Generalize socket rx gap / receive queue overflow cmsg
Create a new socket level option to report number of queue overflows
Recently I augmented the AF_PACKET protocol to report the number of frames lost
on the socket receive queue between any two enqueued frames. This value was
exported via a SOL_PACKET level cmsg. AFter I completed that work it was
requested that this feature be generalized so that any datagram oriented socket
could make use of this option. As such I've created this patch, It creates a
new SOL_SOCKET level option called SO_RXQ_OVFL, which when enabled exports a
SOL_SOCKET level cmsg that reports the nubmer of times the sk_receive_queue
overflowed between any two given frames. It also augments the AF_PACKET
protocol to take advantage of this new feature (as it previously did not touch
sk->sk_drops, which this patch uses to record the overflow count). Tested
successfully by me.
Notes:
1) Unlike my previous patch, this patch simply records the sk_drops value, which
is not a number of drops between packets, but rather a total number of drops.
Deltas must be computed in user space.
2) While this patch currently works with datagram oriented protocols, it will
also be accepted by non-datagram oriented protocols. I'm not sure if thats
agreeable to everyone, but my argument in favor of doing so is that, for those
protocols which aren't applicable to this option, sk_drops will always be zero,
and reporting no drops on a receive queue that isn't used for those
non-participating protocols seems reasonable to me. This also saves us having
to code in a per-protocol opt in mechanism.
3) This applies cleanly to net-next assuming that commit
977750076d98c7ff6cbda51858bb5a5894a9d9ab (my af packet cmsg patch) is reverted
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-10-13 04:26:31 +08:00
|
|
|
sock_recv_ts_and_drops(msg, sk, skb);
|
2011-11-21 18:25:58 +08:00
|
|
|
|
|
|
|
if (!(flags & MSG_PEEK)) {
|
|
|
|
pr_debug("%d -= %d\n", atomic_read(&sk->sk_rmem_alloc),
|
|
|
|
skb->truesize);
|
|
|
|
atm_return(vcc, skb->truesize);
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:29 +08:00
|
|
|
skb_free_datagram(sk, skb);
|
|
|
|
return copied;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-03-02 15:37:48 +08:00
|
|
|
int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
struct atm_vcc *vcc;
|
|
|
|
struct sk_buff *skb;
|
2010-01-26 19:40:06 +08:00
|
|
|
int eff, error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
if (sock->state != SS_CONNECTED) {
|
|
|
|
error = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (m->msg_name) {
|
|
|
|
error = -EISCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
vcc = ATM_SD(sock);
|
|
|
|
if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
|
|
|
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
|
|
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
|
|
|
error = -EPIPE;
|
|
|
|
send_sig(SIGPIPE, current, 0);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!size) {
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-11-20 20:01:29 +08:00
|
|
|
if (size > vcc->qos.txtp.max_sdu) {
|
2005-04-17 06:20:36 +08:00
|
|
|
error = -EMSGSIZE;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-05-01 23:59:08 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
eff = (size+3) & ~3; /* align to word boundary */
|
2010-04-20 21:03:51 +08:00
|
|
|
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
error = 0;
|
2017-03-12 08:41:36 +08:00
|
|
|
while (!vcc_tx_ready(vcc, eff)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->msg_flags & MSG_DONTWAIT) {
|
|
|
|
error = -EAGAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
schedule();
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
error = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
|
|
|
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
|
|
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
error = -EPIPE;
|
|
|
|
send_sig(SIGPIPE, current, 0);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-20 21:03:51 +08:00
|
|
|
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-04-20 21:03:51 +08:00
|
|
|
finish_wait(sk_sleep(sk), &wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (error)
|
|
|
|
goto out;
|
2017-03-12 08:41:36 +08:00
|
|
|
|
|
|
|
skb = alloc_skb(eff, GFP_KERNEL);
|
|
|
|
if (!skb) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
|
atm: Preserve value of skb->truesize when accounting to vcc
ATM accounts for in-flight TX packets in sk_wmem_alloc of the VCC on
which they are to be sent. But it doesn't take ownership of those
packets from the sock (if any) which originally owned them. They should
remain owned by their actual sender until they've left the box.
There's a hack in pskb_expand_head() to avoid adjusting skb->truesize
for certain skbs, precisely to avoid messing up sk_wmem_alloc
accounting. Ideally that hack would cover the ATM use case too, but it
doesn't — skbs which aren't owned by any sock, for example PPP control
frames, still get their truesize adjusted when the low-level ATM driver
adds headroom.
This has always been an issue, it seems. The truesize of a packet
increases, and sk_wmem_alloc on the VCC goes negative. But this wasn't
for normal traffic, only for control frames. So I think we just got away
with it, and we probably needed to send 2GiB of LCP echo frames before
the misaccounting would ever have caused a problem and caused
atm_may_send() to start refusing packets.
Commit 14afee4b609 ("net: convert sock.sk_wmem_alloc from atomic_t to
refcount_t") did exactly what it was intended to do, and turned this
mostly-theoretical problem into a real one, causing PPPoATM to fail
immediately as sk_wmem_alloc underflows and atm_may_send() *immediately*
starts refusing to allow new packets.
The least intrusive solution to this problem is to stash the value of
skb->truesize that was accounted to the VCC, in a new member of the
ATM_SKB(skb) structure. Then in atm_pop_raw() subtract precisely that
value instead of the then-current value of skb->truesize.
Fixes: 158f323b9868 ("net: adjust skb->truesize in pskb_expand_head()")
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Tested-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-06-16 18:55:44 +08:00
|
|
|
atm_account_tx(vcc, skb);
|
2017-03-12 08:41:36 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
skb->dev = NULL; /* for paths shared with net_device interfaces */
|
2016-11-02 10:09:04 +08:00
|
|
|
if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
error = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
if (eff != size)
|
|
|
|
memset(skb->data + size, 0, eff-size);
|
|
|
|
error = vcc->dev->ops->send(vcc, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
error = error ? error : size;
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-06-29 00:43:44 +08:00
|
|
|
__poll_t vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
2018-06-29 00:43:44 +08:00
|
|
|
struct atm_vcc *vcc;
|
|
|
|
__poll_t mask;
|
|
|
|
|
2018-10-23 19:40:39 +08:00
|
|
|
sock_poll_wait(file, sock, wait);
|
2018-06-29 00:43:44 +08:00
|
|
|
mask = 0;
|
|
|
|
|
|
|
|
vcc = ATM_SD(sock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* exceptional events */
|
|
|
|
if (sk->sk_err)
|
2018-02-12 06:34:03 +08:00
|
|
|
mask = EPOLLERR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
|
|
|
|
test_bit(ATM_VF_CLOSE, &vcc->flags))
|
2018-02-12 06:34:03 +08:00
|
|
|
mask |= EPOLLHUP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* readable? */
|
2019-10-24 13:44:50 +08:00
|
|
|
if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
|
2018-02-12 06:34:03 +08:00
|
|
|
mask |= EPOLLIN | EPOLLRDNORM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* writable? */
|
|
|
|
if (sock->state == SS_CONNECTING &&
|
|
|
|
test_bit(ATM_VF_WAITING, &vcc->flags))
|
|
|
|
return mask;
|
|
|
|
|
|
|
|
if (vcc->qos.txtp.traffic_class != ATM_NONE &&
|
|
|
|
vcc_writable(sk))
|
2018-02-12 06:34:03 +08:00
|
|
|
mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2010-01-26 19:40:06 +08:00
|
|
|
static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't let the QoS change the already connected AAL type nor the
|
|
|
|
* traffic class.
|
|
|
|
*/
|
|
|
|
if (qos->aal != vcc->qos.aal ||
|
|
|
|
qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
|
|
|
|
qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
|
|
|
|
return -EINVAL;
|
2010-01-26 19:40:06 +08:00
|
|
|
error = adjust_tp(&qos->txtp, qos->aal);
|
|
|
|
if (!error)
|
|
|
|
error = adjust_tp(&qos->rxtp, qos->aal);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (!vcc->dev->ops->change_qos)
|
|
|
|
return -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sk_atm(vcc)->sk_family == AF_ATMPVC)
|
2010-01-26 19:40:06 +08:00
|
|
|
return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET);
|
|
|
|
return svc_change_qos(vcc, qos);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-06-18 07:20:06 +08:00
|
|
|
static int check_tp(const struct atm_trafprm *tp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* @@@ Should be merged with adjust_tp */
|
2010-01-26 19:40:06 +08:00
|
|
|
if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
|
2010-01-26 19:40:06 +08:00
|
|
|
!tp->max_pcr)
|
|
|
|
return -EINVAL;
|
|
|
|
if (tp->min_pcr == ATM_MAX_PCR)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
|
2010-01-26 19:40:06 +08:00
|
|
|
tp->min_pcr > tp->max_pcr)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We allow pcr to be outside [min_pcr,max_pcr], because later
|
|
|
|
* adjustment may still push it in the valid range.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-18 07:20:06 +08:00
|
|
|
static int check_qos(const struct atm_qos *qos)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
|
2007-02-09 22:24:29 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
|
|
|
|
qos->txtp.traffic_class && qos->rxtp.traffic_class &&
|
|
|
|
qos->txtp.traffic_class != ATM_ANYCLASS &&
|
2010-01-26 19:40:06 +08:00
|
|
|
qos->rxtp.traffic_class != ATM_ANYCLASS)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
error = check_tp(&qos->txtp);
|
2010-01-26 19:40:06 +08:00
|
|
|
if (error)
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
return check_tp(&qos->rxtp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int vcc_setsockopt(struct socket *sock, int level, int optname,
|
2020-07-23 14:09:07 +08:00
|
|
|
sockptr_t optval, unsigned int optlen)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct atm_vcc *vcc;
|
|
|
|
unsigned long value;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vcc = ATM_SD(sock);
|
|
|
|
switch (optname) {
|
2010-01-26 19:40:06 +08:00
|
|
|
case SO_ATMQOS:
|
|
|
|
{
|
|
|
|
struct atm_qos qos;
|
|
|
|
|
2020-07-23 14:09:07 +08:00
|
|
|
if (copy_from_sockptr(&qos, optval, sizeof(qos)))
|
2010-01-26 19:40:06 +08:00
|
|
|
return -EFAULT;
|
|
|
|
error = check_qos(&qos);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (sock->state == SS_CONNECTED)
|
|
|
|
return atm_change_qos(vcc, &qos);
|
|
|
|
if (sock->state != SS_UNCONNECTED)
|
|
|
|
return -EBADFD;
|
|
|
|
vcc->qos = qos;
|
|
|
|
set_bit(ATM_VF_HASQOS, &vcc->flags);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
case SO_SETCLP:
|
2020-07-23 14:09:07 +08:00
|
|
|
if (copy_from_sockptr(&value, optval, sizeof(value)))
|
2010-01-26 19:40:06 +08:00
|
|
|
return -EFAULT;
|
|
|
|
if (value)
|
|
|
|
vcc->atm_options |= ATM_ATMOPT_CLP;
|
|
|
|
else
|
|
|
|
vcc->atm_options &= ~ATM_ATMOPT_CLP;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2020-07-17 14:23:10 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int vcc_getsockopt(struct socket *sock, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen)
|
|
|
|
{
|
|
|
|
struct atm_vcc *vcc;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (get_user(len, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vcc = ATM_SD(sock);
|
|
|
|
switch (optname) {
|
2010-01-26 19:40:06 +08:00
|
|
|
case SO_ATMQOS:
|
|
|
|
if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
|
|
|
|
return -EINVAL;
|
|
|
|
return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos))
|
|
|
|
? -EFAULT : 0;
|
|
|
|
case SO_SETCLP:
|
|
|
|
return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0,
|
|
|
|
(unsigned long __user *)optval) ? -EFAULT : 0;
|
|
|
|
case SO_ATMPVC:
|
|
|
|
{
|
|
|
|
struct sockaddr_atmpvc pvc;
|
|
|
|
|
|
|
|
if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
|
|
|
|
return -ENOTCONN;
|
2012-08-15 19:31:44 +08:00
|
|
|
memset(&pvc, 0, sizeof(pvc));
|
2010-01-26 19:40:06 +08:00
|
|
|
pvc.sap_family = AF_ATMPVC;
|
|
|
|
pvc.sap_addr.itf = vcc->dev->number;
|
|
|
|
pvc.sap_addr.vpi = vcc->vpi;
|
|
|
|
pvc.sap_addr.vci = vcc->vci;
|
|
|
|
return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2020-07-17 14:23:10 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-07-09 04:55:30 +08:00
|
|
|
int register_atmdevice_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return atomic_notifier_chain_register(&atm_dev_notify_chain, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(register_atmdevice_notifier);
|
|
|
|
|
|
|
|
void unregister_atmdevice_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
atomic_notifier_chain_unregister(&atm_dev_notify_chain, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init atm_init(void)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2010-01-26 19:40:06 +08:00
|
|
|
error = proto_register(&vcc_proto, 0);
|
|
|
|
if (error < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
2010-01-26 19:40:06 +08:00
|
|
|
error = atmpvc_init();
|
|
|
|
if (error < 0) {
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_err("atmpvc_init() failed with %d\n", error);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out_unregister_vcc_proto;
|
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
error = atmsvc_init();
|
|
|
|
if (error < 0) {
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_err("atmsvc_init() failed with %d\n", error);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out_atmpvc_exit;
|
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
error = atm_proc_init();
|
|
|
|
if (error < 0) {
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_err("atm_proc_init() failed with %d\n", error);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out_atmsvc_exit;
|
|
|
|
}
|
2010-01-26 19:40:06 +08:00
|
|
|
error = atm_sysfs_init();
|
|
|
|
if (error < 0) {
|
2010-01-26 19:40:00 +08:00
|
|
|
pr_err("atm_sysfs_init() failed with %d\n", error);
|
2006-06-30 03:36:34 +08:00
|
|
|
goto out_atmproc_exit;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
|
|
|
return error;
|
2006-06-30 03:36:34 +08:00
|
|
|
out_atmproc_exit:
|
|
|
|
atm_proc_exit();
|
2005-04-17 06:20:36 +08:00
|
|
|
out_atmsvc_exit:
|
|
|
|
atmsvc_exit();
|
|
|
|
out_atmpvc_exit:
|
|
|
|
atmsvc_exit();
|
|
|
|
out_unregister_vcc_proto:
|
|
|
|
proto_unregister(&vcc_proto);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit atm_exit(void)
|
|
|
|
{
|
|
|
|
atm_proc_exit();
|
2006-06-30 03:36:34 +08:00
|
|
|
atm_sysfs_exit();
|
2005-04-17 06:20:36 +08:00
|
|
|
atmsvc_exit();
|
|
|
|
atmpvc_exit();
|
|
|
|
proto_unregister(&vcc_proto);
|
|
|
|
}
|
|
|
|
|
2007-02-06 10:04:06 +08:00
|
|
|
subsys_initcall(atm_init);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
module_exit(atm_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_NETPROTO(PF_ATMPVC);
|
|
|
|
MODULE_ALIAS_NETPROTO(PF_ATMSVC);
|