2019-05-27 14:55:21 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-27 07:54:58 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Author Karsten Keil <kkeil@novell.com>
|
|
|
|
*
|
|
|
|
* Copyright 2008 by Karsten Keil <kkeil@novell.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mISDNif.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>
|
2011-07-11 00:23:16 +08:00
|
|
|
#include <linux/export.h>
|
2008-07-27 07:54:58 +08:00
|
|
|
#include "core.h"
|
|
|
|
|
2008-12-13 13:13:45 +08:00
|
|
|
static u_int *debug;
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
static struct proto mISDN_proto = {
|
|
|
|
.name = "misdn",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.obj_size = sizeof(struct mISDN_sock)
|
|
|
|
};
|
|
|
|
|
|
|
|
#define _pms(sk) ((struct mISDN_sock *)sk)
|
|
|
|
|
|
|
|
static struct mISDN_sock_list data_sockets = {
|
|
|
|
.lock = __RW_LOCK_UNLOCKED(data_sockets.lock)
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mISDN_sock_list base_sockets = {
|
|
|
|
.lock = __RW_LOCK_UNLOCKED(base_sockets.lock)
|
|
|
|
};
|
|
|
|
|
|
|
|
#define L2_HEADER_LEN 4
|
|
|
|
|
|
|
|
static inline struct sk_buff *
|
|
|
|
_l2_alloc_skb(unsigned int len, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
skb = alloc_skb(len + L2_HEADER_LEN, gfp_mask);
|
|
|
|
if (likely(skb))
|
|
|
|
skb_reserve(skb, L2_HEADER_LEN);
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mISDN_sock_link(struct mISDN_sock_list *l, struct sock *sk)
|
|
|
|
{
|
|
|
|
write_lock_bh(&l->lock);
|
|
|
|
sk_add_node(sk, &l->head);
|
|
|
|
write_unlock_bh(&l->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mISDN_sock_unlink(struct mISDN_sock_list *l, struct sock *sk)
|
|
|
|
{
|
|
|
|
write_lock_bh(&l->lock);
|
|
|
|
sk_del_node_init(sk);
|
|
|
|
write_unlock_bh(&l->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mISDN_send(struct mISDNchannel *ch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct mISDN_sock *msk;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
msk = container_of(ch, struct mISDN_sock, ch);
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s len %d %p\n", __func__, skb->len, skb);
|
|
|
|
if (msk->sk.sk_state == MISDN_CLOSED)
|
|
|
|
return -EUNATCH;
|
|
|
|
__net_timestamp(skb);
|
|
|
|
err = sock_queue_rcv_skb(&msk->sk, skb);
|
|
|
|
if (err)
|
|
|
|
printk(KERN_WARNING "%s: error %d\n", __func__, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mISDN_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
|
|
|
|
{
|
|
|
|
struct mISDN_sock *msk;
|
|
|
|
|
|
|
|
msk = container_of(ch, struct mISDN_sock, ch);
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s(%p, %x, %p)\n", __func__, ch, cmd, arg);
|
|
|
|
switch (cmd) {
|
|
|
|
case CLOSE_CHANNEL:
|
|
|
|
msk->sk.sk_state = MISDN_CLOSED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
mISDN_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb)
|
|
|
|
{
|
2019-02-02 23:34:48 +08:00
|
|
|
struct __kernel_old_timeval tv;
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
if (_pms(sk)->cmask & MISDN_TIME_STAMP) {
|
|
|
|
skb_get_timestamp(skb, &tv);
|
|
|
|
put_cmsg(msg, SOL_MISDN, MISDN_TIME_STAMP, sizeof(tv), &tv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-03-02 15:37:48 +08:00
|
|
|
mISDN_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
|
|
|
|
int flags)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
int copied, err;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: len %d, flags %x ch.nr %d, proto %x\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, (int)len, flags, _pms(sk)->ch.nr,
|
|
|
|
sk->sk_protocol);
|
2008-07-27 07:54:58 +08:00
|
|
|
if (flags & (MSG_OOB))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (sk->sk_state == MISDN_CLOSED)
|
|
|
|
return 0;
|
|
|
|
|
2022-04-05 00:30:22 +08:00
|
|
|
skb = skb_recv_datagram(sk, flags, &err);
|
2008-07-27 07:54:58 +08:00
|
|
|
if (!skb)
|
|
|
|
return err;
|
|
|
|
|
2013-11-21 10:14:22 +08:00
|
|
|
if (msg->msg_name) {
|
2014-01-18 05:53:15 +08:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_mISDN *, maddr, msg->msg_name);
|
2013-11-21 10:14:22 +08:00
|
|
|
|
2008-07-27 07:54:58 +08:00
|
|
|
maddr->family = AF_ISDN;
|
|
|
|
maddr->dev = _pms(sk)->dev->id;
|
|
|
|
if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
|
|
|
|
(sk->sk_protocol == ISDN_P_LAPD_NT)) {
|
|
|
|
maddr->channel = (mISDN_HEAD_ID(skb) >> 16) & 0xff;
|
|
|
|
maddr->tei = (mISDN_HEAD_ID(skb) >> 8) & 0xff;
|
|
|
|
maddr->sapi = mISDN_HEAD_ID(skb) & 0xff;
|
|
|
|
} else {
|
|
|
|
maddr->channel = _pms(sk)->ch.nr;
|
|
|
|
maddr->sapi = _pms(sk)->ch.addr & 0xFF;
|
|
|
|
maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xFF;
|
|
|
|
}
|
2013-11-21 10:14:22 +08:00
|
|
|
msg->msg_namelen = sizeof(*maddr);
|
2008-07-27 07:54:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
copied = skb->len + MISDN_HEADER_LEN;
|
|
|
|
if (len < copied) {
|
|
|
|
if (flags & MSG_PEEK)
|
2017-06-30 18:07:58 +08:00
|
|
|
refcount_dec(&skb->users);
|
2008-07-27 07:54:58 +08:00
|
|
|
else
|
|
|
|
skb_queue_head(&sk->sk_receive_queue, skb);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
memcpy(skb_push(skb, MISDN_HEADER_LEN), mISDN_HEAD_P(skb),
|
2012-02-20 11:52:38 +08:00
|
|
|
MISDN_HEADER_LEN);
|
2008-07-27 07:54:58 +08:00
|
|
|
|
2014-11-06 05:46:40 +08:00
|
|
|
err = skb_copy_datagram_msg(skb, 0, msg, copied);
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
mISDN_sock_cmsg(sk, msg, skb);
|
|
|
|
|
|
|
|
skb_free_datagram(sk, skb);
|
|
|
|
|
|
|
|
return err ? : copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-03-02 15:37:48 +08:00
|
|
|
mISDN_sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int err = -ENOMEM;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: len %d flags %x ch %d proto %x\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, (int)len, msg->msg_flags, _pms(sk)->ch.nr,
|
|
|
|
sk->sk_protocol);
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
if (msg->msg_flags & MSG_OOB)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_NOSIGNAL | MSG_ERRQUEUE))
|
2008-07-27 07:54:58 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (len < MISDN_HEADER_LEN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (sk->sk_state != MISDN_BOUND)
|
|
|
|
return -EBADFD;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
skb = _l2_alloc_skb(len, GFP_KERNEL);
|
|
|
|
if (!skb)
|
|
|
|
goto done;
|
|
|
|
|
2014-04-07 09:25:44 +08:00
|
|
|
if (memcpy_from_msg(skb_put(skb, len), msg, len)) {
|
2008-07-27 07:54:58 +08:00
|
|
|
err = -EFAULT;
|
2009-05-22 19:04:52 +08:00
|
|
|
goto done;
|
2008-07-27 07:54:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(mISDN_HEAD_P(skb), skb->data, MISDN_HEADER_LEN);
|
|
|
|
skb_pull(skb, MISDN_HEADER_LEN);
|
|
|
|
|
|
|
|
if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) {
|
|
|
|
/* if we have a address, we use it */
|
2014-01-18 05:53:15 +08:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_mISDN *, maddr, msg->msg_name);
|
2008-07-27 07:54:58 +08:00
|
|
|
mISDN_HEAD_ID(skb) = maddr->channel;
|
|
|
|
} else { /* use default for L2 messages */
|
|
|
|
if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
|
|
|
|
(sk->sk_protocol == ISDN_P_LAPD_NT))
|
2009-05-22 19:04:56 +08:00
|
|
|
mISDN_HEAD_ID(skb) = _pms(sk)->ch.nr;
|
2008-07-27 07:54:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: ID:%x\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, mISDN_HEAD_ID(skb));
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
err = -ENODEV;
|
2009-05-22 19:04:52 +08:00
|
|
|
if (!_pms(sk)->ch.peer)
|
|
|
|
goto done;
|
|
|
|
err = _pms(sk)->ch.recv(_pms(sk)->ch.peer, skb);
|
|
|
|
if (err)
|
|
|
|
goto done;
|
|
|
|
else {
|
|
|
|
skb = NULL;
|
|
|
|
err = len;
|
|
|
|
}
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
done:
|
2018-09-20 22:27:28 +08:00
|
|
|
kfree_skb(skb);
|
2008-07-27 07:54:58 +08:00
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
data_sock_release(struct socket *sock)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
|
|
|
|
if (!sk)
|
|
|
|
return 0;
|
|
|
|
switch (sk->sk_protocol) {
|
|
|
|
case ISDN_P_TE_S0:
|
|
|
|
case ISDN_P_NT_S0:
|
|
|
|
case ISDN_P_TE_E1:
|
|
|
|
case ISDN_P_NT_E1:
|
|
|
|
if (sk->sk_state == MISDN_BOUND)
|
|
|
|
delete_channel(&_pms(sk)->ch);
|
|
|
|
else
|
|
|
|
mISDN_sock_unlink(&data_sockets, sk);
|
|
|
|
break;
|
|
|
|
case ISDN_P_LAPD_TE:
|
|
|
|
case ISDN_P_LAPD_NT:
|
|
|
|
case ISDN_P_B_RAW:
|
|
|
|
case ISDN_P_B_HDLC:
|
|
|
|
case ISDN_P_B_X75SLP:
|
|
|
|
case ISDN_P_B_L2DTMF:
|
|
|
|
case ISDN_P_B_L2DSP:
|
|
|
|
case ISDN_P_B_L2DSPHDLC:
|
|
|
|
delete_channel(&_pms(sk)->ch);
|
|
|
|
mISDN_sock_unlink(&data_sockets, sk);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
sock_orphan(sk);
|
|
|
|
skb_queue_purge(&sk->sk_receive_queue);
|
|
|
|
|
|
|
|
release_sock(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
data_sock_ioctl_bound(struct sock *sk, unsigned int cmd, void __user *p)
|
|
|
|
{
|
|
|
|
struct mISDN_ctrl_req cq;
|
2009-05-22 19:04:48 +08:00
|
|
|
int err = -EINVAL, val[2];
|
2008-07-27 07:54:58 +08:00
|
|
|
struct mISDNchannel *bchan, *next;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
if (!_pms(sk)->dev) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
switch (cmd) {
|
|
|
|
case IMCTRLREQ:
|
|
|
|
if (copy_from_user(&cq, p, sizeof(cq))) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((sk->sk_protocol & ~ISDN_P_B_MASK) == ISDN_P_B_START) {
|
|
|
|
list_for_each_entry_safe(bchan, next,
|
2012-02-20 11:52:38 +08:00
|
|
|
&_pms(sk)->dev->bchannels, list) {
|
2008-07-27 07:54:58 +08:00
|
|
|
if (bchan->nr == cq.channel) {
|
|
|
|
err = bchan->ctrl(bchan,
|
2012-02-20 11:52:38 +08:00
|
|
|
CONTROL_CHANNEL, &cq);
|
2008-07-27 07:54:58 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
err = _pms(sk)->dev->D.ctrl(&_pms(sk)->dev->D,
|
2012-02-20 11:52:38 +08:00
|
|
|
CONTROL_CHANNEL, &cq);
|
2008-07-27 07:54:58 +08:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
if (copy_to_user(p, &cq, sizeof(cq)))
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IMCLEAR_L2:
|
|
|
|
if (sk->sk_protocol != ISDN_P_LAPD_NT) {
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-05-22 19:04:48 +08:00
|
|
|
val[0] = cmd;
|
|
|
|
if (get_user(val[1], (int __user *)p)) {
|
2008-07-27 07:54:58 +08:00
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
|
2012-02-20 11:52:38 +08:00
|
|
|
CONTROL_CHANNEL, val);
|
2009-05-22 19:04:48 +08:00
|
|
|
break;
|
|
|
|
case IMHOLD_L1:
|
|
|
|
if (sk->sk_protocol != ISDN_P_LAPD_NT
|
2012-02-20 11:52:38 +08:00
|
|
|
&& sk->sk_protocol != ISDN_P_LAPD_TE) {
|
2009-05-22 19:04:48 +08:00
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
val[0] = cmd;
|
|
|
|
if (get_user(val[1], (int __user *)p)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
|
2012-02-20 11:52:38 +08:00
|
|
|
CONTROL_CHANNEL, val);
|
2008-07-27 07:54:58 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2012-02-20 11:52:38 +08:00
|
|
|
int err = 0, id;
|
2008-07-27 07:54:58 +08:00
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct mISDNdevice *dev;
|
|
|
|
struct mISDNversion ver;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IMGETVERSION:
|
|
|
|
ver.major = MISDN_MAJOR_VERSION;
|
|
|
|
ver.minor = MISDN_MINOR_VERSION;
|
|
|
|
ver.release = MISDN_RELEASE;
|
|
|
|
if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IMGETCOUNT:
|
|
|
|
id = get_mdevice_count();
|
|
|
|
if (put_user(id, (int __user *)arg))
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IMGETDEVINFO:
|
|
|
|
if (get_user(id, (int __user *)arg)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dev = get_mdevice(id);
|
|
|
|
if (dev) {
|
|
|
|
struct mISDN_devinfo di;
|
|
|
|
|
2010-10-30 07:04:33 +08:00
|
|
|
memset(&di, 0, sizeof(di));
|
2008-07-27 07:54:58 +08:00
|
|
|
di.id = dev->id;
|
|
|
|
di.Dprotocols = dev->Dprotocols;
|
|
|
|
di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
|
|
|
|
di.protocol = dev->D.protocol;
|
|
|
|
memcpy(di.channelmap, dev->channelmap,
|
2012-02-20 11:52:38 +08:00
|
|
|
sizeof(di.channelmap));
|
2008-07-27 07:54:58 +08:00
|
|
|
di.nrbchan = dev->nrbchan;
|
2019-05-22 16:45:13 +08:00
|
|
|
strscpy(di.name, dev_name(&dev->dev), sizeof(di.name));
|
2008-07-27 07:54:58 +08:00
|
|
|
if (copy_to_user((void __user *)arg, &di, sizeof(di)))
|
|
|
|
err = -EFAULT;
|
|
|
|
} else
|
|
|
|
err = -ENODEV;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (sk->sk_state == MISDN_BOUND)
|
|
|
|
err = data_sock_ioctl_bound(sk, cmd,
|
2012-02-20 11:52:38 +08:00
|
|
|
(void __user *)arg);
|
2008-07-27 07:54:58 +08:00
|
|
|
else
|
|
|
|
err = -ENOTCONN;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int data_sock_setsockopt(struct socket *sock, int level, int optname,
|
2020-07-23 14:09:07 +08:00
|
|
|
sockptr_t optval, unsigned int len)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
int err = 0, opt = 0;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
mISDN: Don't try to print a sockptr_t from debug logging code.
drivers/isdn/mISDN/socket.c: In function ‘data_sock_setsockopt’:
./include/linux/kern_levels.h:5:18: warning: format ‘%p’ expects argument of type ‘void *’, but argument 6 has type ‘sockptr_t’ [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
./include/linux/kern_levels.h:15:20: note: in expansion of macro ‘KERN_SOH’
15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
| ^~~~~~~~
drivers/isdn/mISDN/socket.c:410:10: note: in expansion of macro ‘KERN_DEBUG’
410 | printk(KERN_DEBUG "%s(%p, %d, %x, %p, %d)\n", __func__, sock,
| ^~~~~~~~~~
drivers/isdn/mISDN/socket.c:410:38: note: format string is defined here
410 | printk(KERN_DEBUG "%s(%p, %d, %x, %p, %d)\n", __func__, sock,
| ~^
| |
| void *
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-07-25 07:36:13 +08:00
|
|
|
printk(KERN_DEBUG "%s(%p, %d, %x, optval, %d)\n", __func__, sock,
|
|
|
|
level, optname, len);
|
2008-07-27 07:54:58 +08:00
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case MISDN_TIME_STAMP:
|
2020-07-23 14:09:07 +08:00
|
|
|
if (copy_from_sockptr(&opt, optval, sizeof(int))) {
|
2008-07-27 07:54:58 +08:00
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt)
|
|
|
|
_pms(sk)->cmask |= MISDN_TIME_STAMP;
|
|
|
|
else
|
|
|
|
_pms(sk)->cmask &= ~MISDN_TIME_STAMP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -ENOPROTOOPT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int data_sock_getsockopt(struct socket *sock, int level, int optname,
|
2012-02-20 11:52:38 +08:00
|
|
|
char __user *optval, int __user *optlen)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
int len, opt;
|
|
|
|
|
|
|
|
if (get_user(len, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2011-04-18 07:48:53 +08:00
|
|
|
if (len != sizeof(char))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-07-27 07:54:58 +08:00
|
|
|
switch (optname) {
|
|
|
|
case MISDN_TIME_STAMP:
|
|
|
|
if (_pms(sk)->cmask & MISDN_TIME_STAMP)
|
|
|
|
opt = 1;
|
|
|
|
else
|
|
|
|
opt = 0;
|
|
|
|
|
|
|
|
if (put_user(opt, optval))
|
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
data_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
|
|
|
|
{
|
|
|
|
struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
|
|
|
|
struct sock *sk = sock->sk;
|
2008-09-14 18:30:18 +08:00
|
|
|
struct sock *csk;
|
2008-07-27 07:54:58 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
|
|
|
|
if (addr_len != sizeof(struct sockaddr_mISDN))
|
|
|
|
return -EINVAL;
|
|
|
|
if (!maddr || maddr->family != AF_ISDN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
if (_pms(sk)->dev) {
|
|
|
|
err = -EALREADY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
_pms(sk)->dev = get_mdevice(maddr->dev);
|
|
|
|
if (!_pms(sk)->dev) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-09-14 18:30:18 +08:00
|
|
|
|
2008-09-14 20:42:18 +08:00
|
|
|
if (sk->sk_protocol < ISDN_P_B_START) {
|
|
|
|
read_lock_bh(&data_sockets.lock);
|
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(csk, &data_sockets.head) {
|
2008-09-14 20:42:18 +08:00
|
|
|
if (sk == csk)
|
|
|
|
continue;
|
|
|
|
if (_pms(csk)->dev != _pms(sk)->dev)
|
|
|
|
continue;
|
|
|
|
if (csk->sk_protocol >= ISDN_P_B_START)
|
|
|
|
continue;
|
|
|
|
if (IS_ISDN_P_TE(csk->sk_protocol)
|
2012-02-20 11:52:38 +08:00
|
|
|
== IS_ISDN_P_TE(sk->sk_protocol))
|
2008-09-14 20:42:18 +08:00
|
|
|
continue;
|
|
|
|
read_unlock_bh(&data_sockets.lock);
|
|
|
|
err = -EBUSY;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-09-14 18:30:18 +08:00
|
|
|
read_unlock_bh(&data_sockets.lock);
|
|
|
|
}
|
|
|
|
|
2008-07-27 07:54:58 +08:00
|
|
|
_pms(sk)->ch.send = mISDN_send;
|
|
|
|
_pms(sk)->ch.ctrl = mISDN_ctrl;
|
|
|
|
|
|
|
|
switch (sk->sk_protocol) {
|
|
|
|
case ISDN_P_TE_S0:
|
|
|
|
case ISDN_P_NT_S0:
|
|
|
|
case ISDN_P_TE_E1:
|
|
|
|
case ISDN_P_NT_E1:
|
|
|
|
mISDN_sock_unlink(&data_sockets, sk);
|
|
|
|
err = connect_layer1(_pms(sk)->dev, &_pms(sk)->ch,
|
2012-02-20 11:52:38 +08:00
|
|
|
sk->sk_protocol, maddr);
|
2008-07-27 07:54:58 +08:00
|
|
|
if (err)
|
|
|
|
mISDN_sock_link(&data_sockets, sk);
|
|
|
|
break;
|
|
|
|
case ISDN_P_LAPD_TE:
|
|
|
|
case ISDN_P_LAPD_NT:
|
|
|
|
err = create_l2entity(_pms(sk)->dev, &_pms(sk)->ch,
|
2012-02-20 11:52:38 +08:00
|
|
|
sk->sk_protocol, maddr);
|
2008-07-27 07:54:58 +08:00
|
|
|
break;
|
|
|
|
case ISDN_P_B_RAW:
|
|
|
|
case ISDN_P_B_HDLC:
|
|
|
|
case ISDN_P_B_X75SLP:
|
|
|
|
case ISDN_P_B_L2DTMF:
|
|
|
|
case ISDN_P_B_L2DSP:
|
|
|
|
case ISDN_P_B_L2DSPHDLC:
|
|
|
|
err = connect_Bstack(_pms(sk)->dev, &_pms(sk)->ch,
|
2012-02-20 11:52:38 +08:00
|
|
|
sk->sk_protocol, maddr);
|
2008-07-27 07:54:58 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EPROTONOSUPPORT;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto done;
|
|
|
|
sk->sk_state = MISDN_BOUND;
|
|
|
|
_pms(sk)->ch.protocol = sk->sk_protocol;
|
|
|
|
|
|
|
|
done:
|
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
data_sock_getname(struct socket *sock, struct sockaddr *addr,
|
2018-02-13 03:00:20 +08:00
|
|
|
int peer)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
2012-02-20 11:52:38 +08:00
|
|
|
struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
|
2008-07-27 07:54:58 +08:00
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
if (!_pms(sk)->dev)
|
|
|
|
return -EBADFD;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
2013-04-23 04:24:14 +08:00
|
|
|
maddr->family = AF_ISDN;
|
2008-07-27 07:54:58 +08:00
|
|
|
maddr->dev = _pms(sk)->dev->id;
|
|
|
|
maddr->channel = _pms(sk)->ch.nr;
|
|
|
|
maddr->sapi = _pms(sk)->ch.addr & 0xff;
|
|
|
|
maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xff;
|
|
|
|
release_sock(sk);
|
2018-02-13 03:00:20 +08:00
|
|
|
return sizeof(*maddr);
|
2008-07-27 07:54:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct proto_ops data_sock_ops = {
|
|
|
|
.family = PF_ISDN,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.release = data_sock_release,
|
|
|
|
.ioctl = data_sock_ioctl,
|
|
|
|
.bind = data_sock_bind,
|
|
|
|
.getname = data_sock_getname,
|
|
|
|
.sendmsg = mISDN_sock_sendmsg,
|
|
|
|
.recvmsg = mISDN_sock_recvmsg,
|
2018-06-29 00:43:44 +08:00
|
|
|
.poll = datagram_poll,
|
2008-07-27 07:54:58 +08:00
|
|
|
.listen = sock_no_listen,
|
|
|
|
.shutdown = sock_no_shutdown,
|
|
|
|
.setsockopt = data_sock_setsockopt,
|
|
|
|
.getsockopt = data_sock_getsockopt,
|
|
|
|
.connect = sock_no_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.accept = sock_no_accept,
|
|
|
|
.mmap = sock_no_mmap
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2015-05-09 10:09:13 +08:00
|
|
|
data_sock_create(struct net *net, struct socket *sock, int protocol, int kern)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
|
|
|
|
if (sock->type != SOCK_DGRAM)
|
|
|
|
return -ESOCKTNOSUPPORT;
|
|
|
|
|
2015-05-09 10:09:13 +08:00
|
|
|
sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto, kern);
|
2008-07-27 07:54:58 +08:00
|
|
|
if (!sk)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sock_init_data(sock, sk);
|
|
|
|
|
|
|
|
sock->ops = &data_sock_ops;
|
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
sock_reset_flag(sk, SOCK_ZAPPED);
|
|
|
|
|
|
|
|
sk->sk_protocol = protocol;
|
|
|
|
sk->sk_state = MISDN_OPEN;
|
|
|
|
mISDN_sock_link(&data_sockets, sk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
base_sock_release(struct socket *sock)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
|
|
|
|
if (!sk)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mISDN_sock_unlink(&base_sockets, sk);
|
|
|
|
sock_orphan(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2012-02-20 11:52:38 +08:00
|
|
|
int err = 0, id;
|
2008-07-27 07:54:58 +08:00
|
|
|
struct mISDNdevice *dev;
|
|
|
|
struct mISDNversion ver;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IMGETVERSION:
|
|
|
|
ver.major = MISDN_MAJOR_VERSION;
|
|
|
|
ver.minor = MISDN_MINOR_VERSION;
|
|
|
|
ver.release = MISDN_RELEASE;
|
|
|
|
if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IMGETCOUNT:
|
|
|
|
id = get_mdevice_count();
|
|
|
|
if (put_user(id, (int __user *)arg))
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
case IMGETDEVINFO:
|
|
|
|
if (get_user(id, (int __user *)arg)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dev = get_mdevice(id);
|
|
|
|
if (dev) {
|
|
|
|
struct mISDN_devinfo di;
|
|
|
|
|
2010-10-30 07:04:33 +08:00
|
|
|
memset(&di, 0, sizeof(di));
|
2008-07-27 07:54:58 +08:00
|
|
|
di.id = dev->id;
|
|
|
|
di.Dprotocols = dev->Dprotocols;
|
|
|
|
di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
|
|
|
|
di.protocol = dev->D.protocol;
|
|
|
|
memcpy(di.channelmap, dev->channelmap,
|
2012-02-20 11:52:38 +08:00
|
|
|
sizeof(di.channelmap));
|
2008-07-27 07:54:58 +08:00
|
|
|
di.nrbchan = dev->nrbchan;
|
2019-05-22 16:45:13 +08:00
|
|
|
strscpy(di.name, dev_name(&dev->dev), sizeof(di.name));
|
2008-07-27 07:54:58 +08:00
|
|
|
if (copy_to_user((void __user *)arg, &di, sizeof(di)))
|
|
|
|
err = -EFAULT;
|
|
|
|
} else
|
|
|
|
err = -ENODEV;
|
|
|
|
break;
|
2008-08-12 16:12:09 +08:00
|
|
|
case IMSETDEVNAME:
|
2012-02-20 11:52:38 +08:00
|
|
|
{
|
|
|
|
struct mISDN_devrename dn;
|
|
|
|
if (copy_from_user(&dn, (void __user *)arg,
|
|
|
|
sizeof(dn))) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
2008-08-12 16:12:09 +08:00
|
|
|
}
|
2019-05-22 16:45:13 +08:00
|
|
|
dn.name[sizeof(dn.name) - 1] = '\0';
|
2012-02-20 11:52:38 +08:00
|
|
|
dev = get_mdevice(dn.id);
|
|
|
|
if (dev)
|
|
|
|
err = device_rename(&dev->dev, dn.name);
|
|
|
|
else
|
|
|
|
err = -ENODEV;
|
|
|
|
}
|
|
|
|
break;
|
2008-07-27 07:54:58 +08:00
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
base_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
|
|
|
|
{
|
|
|
|
struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
int err = 0;
|
|
|
|
|
2019-04-12 18:52:36 +08:00
|
|
|
if (addr_len < sizeof(struct sockaddr_mISDN))
|
2008-07-27 07:54:58 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-04-12 18:52:36 +08:00
|
|
|
if (!maddr || maddr->family != AF_ISDN)
|
2016-04-09 03:16:11 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2008-07-27 07:54:58 +08:00
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
if (_pms(sk)->dev) {
|
|
|
|
err = -EALREADY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
_pms(sk)->dev = get_mdevice(maddr->dev);
|
|
|
|
if (!_pms(sk)->dev) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
sk->sk_state = MISDN_BOUND;
|
|
|
|
|
|
|
|
done:
|
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct proto_ops base_sock_ops = {
|
|
|
|
.family = PF_ISDN,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.release = base_sock_release,
|
|
|
|
.ioctl = base_sock_ioctl,
|
|
|
|
.bind = base_sock_bind,
|
|
|
|
.getname = sock_no_getname,
|
|
|
|
.sendmsg = sock_no_sendmsg,
|
|
|
|
.recvmsg = sock_no_recvmsg,
|
|
|
|
.listen = sock_no_listen,
|
|
|
|
.shutdown = sock_no_shutdown,
|
|
|
|
.connect = sock_no_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.accept = sock_no_accept,
|
|
|
|
.mmap = sock_no_mmap
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2015-05-09 10:09:13 +08:00
|
|
|
base_sock_create(struct net *net, struct socket *sock, int protocol, int kern)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
|
|
|
|
if (sock->type != SOCK_RAW)
|
|
|
|
return -ESOCKTNOSUPPORT;
|
2019-09-20 15:35:45 +08:00
|
|
|
if (!capable(CAP_NET_RAW))
|
|
|
|
return -EPERM;
|
2008-07-27 07:54:58 +08:00
|
|
|
|
2015-05-09 10:09:13 +08:00
|
|
|
sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto, kern);
|
2008-07-27 07:54:58 +08:00
|
|
|
if (!sk)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sock_init_data(sock, sk);
|
|
|
|
sock->ops = &base_sock_ops;
|
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
sock_reset_flag(sk, SOCK_ZAPPED);
|
|
|
|
sk->sk_protocol = protocol;
|
|
|
|
sk->sk_state = MISDN_OPEN;
|
|
|
|
mISDN_sock_link(&base_sockets, sk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-11-06 14:18:14 +08:00
|
|
|
mISDN_sock_create(struct net *net, struct socket *sock, int proto, int kern)
|
2008-07-27 07:54:58 +08:00
|
|
|
{
|
|
|
|
int err = -EPROTONOSUPPORT;
|
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
switch (proto) {
|
2008-07-27 07:54:58 +08:00
|
|
|
case ISDN_P_BASE:
|
2015-05-09 10:09:13 +08:00
|
|
|
err = base_sock_create(net, sock, proto, kern);
|
2008-07-27 07:54:58 +08:00
|
|
|
break;
|
|
|
|
case ISDN_P_TE_S0:
|
|
|
|
case ISDN_P_NT_S0:
|
|
|
|
case ISDN_P_TE_E1:
|
|
|
|
case ISDN_P_NT_E1:
|
|
|
|
case ISDN_P_LAPD_TE:
|
|
|
|
case ISDN_P_LAPD_NT:
|
|
|
|
case ISDN_P_B_RAW:
|
|
|
|
case ISDN_P_B_HDLC:
|
|
|
|
case ISDN_P_B_X75SLP:
|
|
|
|
case ISDN_P_B_L2DTMF:
|
|
|
|
case ISDN_P_B_L2DSP:
|
|
|
|
case ISDN_P_B_L2DSPHDLC:
|
2015-05-09 10:09:13 +08:00
|
|
|
err = data_sock_create(net, sock, proto, kern);
|
2008-07-27 07:54:58 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-10-05 13:58:39 +08:00
|
|
|
static const struct net_proto_family mISDN_sock_family_ops = {
|
2008-07-27 07:54:58 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.family = PF_ISDN,
|
|
|
|
.create = mISDN_sock_create,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
misdn_sock_init(u_int *deb)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
debug = deb;
|
|
|
|
err = sock_register(&mISDN_sock_family_ops);
|
|
|
|
if (err)
|
|
|
|
printk(KERN_ERR "%s: error(%d)\n", __func__, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
misdn_sock_cleanup(void)
|
|
|
|
{
|
|
|
|
sock_unregister(PF_ISDN);
|
|
|
|
}
|