extractedLnx/linux-2.5.72/net/atm/common.c_atm_ioctl.c
int atm_ioctl(struct socket *sock,unsigned int cmd,unsigned long arg)
{
struct atm_dev *dev;
struct list_head *p;
struct atm_vcc *vcc;
int *tmp_buf, *tmp_p;
void *buf;
int error,len,size,number, ret_val;
ret_val = 0;
vcc = ATM_SD(sock);
switch (cmd) {
case SIOCOUTQ:
if (sock->state != SS_CONNECTED ||
!test_bit(ATM_VF_READY,&vcc->flags)) {
ret_val = -EINVAL;
goto done;
}
ret_val = put_user(vcc->sk->sk_sndbuf -
atomic_read(&vcc->sk->sk_wmem_alloc),
(int *) arg) ? -EFAULT : 0;
goto done;
case SIOCINQ:
{
struct sk_buff *skb;
if (sock->state != SS_CONNECTED) {
ret_val = -EINVAL;
goto done;
}
skb = skb_peek(&vcc->sk->sk_receive_queue);
ret_val = put_user(skb ? skb->len : 0,(int *) arg)
? -EFAULT : 0;
goto done;
}
case ATM_GETNAMES:
if (get_user(buf,
&((struct atm_iobuf *) arg)->buffer)) {
ret_val = -EFAULT;
goto done;
}
if (get_user(len,
&((struct atm_iobuf *) arg)->length)) {
ret_val = -EFAULT;
goto done;
}
size = 0;
spin_lock(&atm_dev_lock);
list_for_each(p, &atm_devs)
size += sizeof(int);
if (size > len) {
spin_unlock(&atm_dev_lock);
ret_val = -E2BIG;
goto done;
}
tmp_buf = kmalloc(size, GFP_ATOMIC);
if (!tmp_buf) {
spin_unlock(&atm_dev_lock);
ret_val = -ENOMEM;
goto done;
}
tmp_p = tmp_buf;
list_for_each(p, &atm_devs) {
dev = list_entry(p, struct atm_dev, dev_list);
*tmp_p++ = dev->number;
}
spin_unlock(&atm_dev_lock);
ret_val = ((copy_to_user(buf, tmp_buf, size)) ||
put_user(size, &((struct atm_iobuf *) arg)->length)
) ? -EFAULT : 0;
kfree(tmp_buf);
goto done;
case SIOCGSTAMP: /* borrowed from IP */
if (!vcc->sk->sk_stamp.tv_sec) {
ret_val = -ENOENT;
goto done;
}
ret_val = copy_to_user((void *)arg, &vcc->sk->sk_stamp,
sizeof(struct timeval)) ? -EFAULT : 0;
goto done;
case ATM_SETSC:
printk(KERN_WARNING "ATM_SETSC is obsolete\n");
ret_val = 0;
goto done;
case ATMSIGD_CTRL:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
/*
* The user/kernel protocol for exchanging signalling
* info uses kernel pointers as opaque references,
* so the holder of the file descriptor can scribble
* on the kernel... so we should make sure that we
* have the same privledges that /proc/kcore needs
*/
if (!capable(CAP_SYS_RAWIO)) {
ret_val = -EPERM;
goto done;
}
error = sigd_attach(vcc);
if (!error) sock->state = SS_CONNECTED;
ret_val = error;
goto done;
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
case SIOCMKCLIP:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_create(arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMARPD_CTRL:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
#if defined(CONFIG_ATM_CLIP_MODULE)
if (!atm_clip_ops)
request_module("clip");
#endif
if (try_atm_clip_ops()) {
error = atm_clip_ops->atm_init_atmarp(vcc);
if (!error)
sock->state = SS_CONNECTED;
ret_val = error;
} else
ret_val = -ENOSYS;
goto done;
case ATMARP_MKIP:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_mkip(vcc, arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMARP_SETENTRY:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_setentry(vcc, arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMARP_ENCAP:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_encap(vcc, arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
case ATMLEC_CTRL:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
#if defined(CONFIG_ATM_LANE_MODULE)
if (!atm_lane_ops)
request_module("lec");
#endif
if (try_atm_lane_ops()) {
error = atm_lane_ops->lecd_attach(vcc, (int) arg);
module_put(atm_lane_ops->owner);
if (error >= 0)
sock->state = SS_CONNECTED;
ret_val = error;
} else
ret_val = -ENOSYS;
goto done;
case ATMLEC_MCAST:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_lane_ops()) {
ret_val = atm_lane_ops->mcast_attach(vcc, (int) arg);
module_put(atm_lane_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMLEC_DATA:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_lane_ops()) {
ret_val = atm_lane_ops->vcc_attach(vcc, (void *) arg);
module_put(atm_lane_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
#endif
#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
case ATMMPC_CTRL:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
#if defined(CONFIG_ATM_MPOA_MODULE)
if (!atm_mpoa_ops)
request_module("mpoa");
#endif
if (try_atm_mpoa_ops()) {
error = atm_mpoa_ops->mpoad_attach(vcc, (int) arg);
module_put(atm_mpoa_ops->owner);
if (error >= 0)
sock->state = SS_CONNECTED;
ret_val = error;
} else
ret_val = -ENOSYS;
goto done;
case ATMMPC_DATA:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (try_atm_mpoa_ops()) {
ret_val = atm_mpoa_ops->vcc_attach(vcc, arg);
module_put(atm_mpoa_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
#endif
#if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
case SIOCSIFATMTCP:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (!atm_tcp_ops.attach) {
ret_val = -ENOPKG;
goto done;
}
fops_get (&atm_tcp_ops);
error = atm_tcp_ops.attach(vcc,(int) arg);
if (error >= 0) sock->state = SS_CONNECTED;
else fops_put (&atm_tcp_ops);
ret_val = error;
goto done;
case ATMTCP_CREATE:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (!atm_tcp_ops.create_persistent) {
ret_val = -ENOPKG;
goto done;
}
error = atm_tcp_ops.create_persistent((int) arg);
if (error < 0) fops_put (&atm_tcp_ops);
ret_val = error;
goto done;
case ATMTCP_REMOVE:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
if (!atm_tcp_ops.remove_persistent) {
ret_val = -ENOPKG;
goto done;
}
error = atm_tcp_ops.remove_persistent((int) arg);
fops_put (&atm_tcp_ops);
ret_val = error;
goto done;
#endif
default:
break;
}
#if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
if (pppoatm_ioctl_hook) {
ret_val = pppoatm_ioctl_hook(vcc, cmd, arg);
if (ret_val != -ENOIOCTLCMD)
goto done;
}
#endif
#if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
if (br2684_ioctl_hook) {
ret_val = br2684_ioctl_hook(vcc, cmd, arg);
if (ret_val != -ENOIOCTLCMD)
goto done;
}
#endif
if (get_user(buf,&((struct atmif_sioc *) arg)->arg)) {
ret_val = -EFAULT;
goto done;
}
if (get_user(len,&((struct atmif_sioc *) arg)->length)) {
ret_val = -EFAULT;
goto done;
}
if (get_user(number,&((struct atmif_sioc *) arg)->number)) {
ret_val = -EFAULT;
goto done;
}
if (!(dev = atm_dev_lookup(number))) {
ret_val = -ENODEV;
goto done;
}
size = 0;
switch (cmd) {
case ATM_GETTYPE:
size = strlen(dev->type)+1;
if (copy_to_user(buf,dev->type,size)) {
ret_val = -EFAULT;
goto done_release;
}
break;
case ATM_GETESI:
size = ESI_LEN;
if (copy_to_user(buf,dev->esi,size)) {
ret_val = -EFAULT;
goto done_release;
}
break;
case ATM_SETESI:
{
int i;
for (i = 0; i < ESI_LEN; i++)
if (dev->esi[i]) {
ret_val = -EEXIST;
goto done_release;
}
}
/* fall through */
case ATM_SETESIF:
{
unsigned char esi[ESI_LEN];
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done_release;
}
if (copy_from_user(esi,buf,ESI_LEN)) {
ret_val = -EFAULT;
goto done_release;
}
memcpy(dev->esi,esi,ESI_LEN);
ret_val = ESI_LEN;
goto done_release;
}
case ATM_GETSTATZ:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done_release;
}
/* fall through */
case ATM_GETSTAT:
size = sizeof(struct atm_dev_stats);
error = fetch_stats(dev,buf,cmd == ATM_GETSTATZ);
if (error) {
ret_val = error;
goto done_release;
}
break;
case ATM_GETCIRANGE:
size = sizeof(struct atm_cirange);
if (copy_to_user(buf,&dev->ci_range,size)) {
ret_val = -EFAULT;
goto done_release;
}
break;
case ATM_GETLINKRATE:
size = sizeof(int);
if (copy_to_user(buf,&dev->link_rate,size)) {
ret_val = -EFAULT;
goto done_release;
}
break;
case ATM_RSTADDR:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done_release;
}
atm_reset_addr(dev);
break;
case ATM_ADDADDR:
case ATM_DELADDR:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done_release;
}
{
struct sockaddr_atmsvc addr;
if (copy_from_user(&addr,buf,sizeof(addr))) {
ret_val = -EFAULT;
goto done_release;
}
if (cmd == ATM_ADDADDR)
ret_val = atm_add_addr(dev,&addr);
else
ret_val = atm_del_addr(dev,&addr);
goto done_release;
}
case ATM_GETADDR:
size = atm_get_addr(dev,buf,len);
if (size < 0)
ret_val = size;
else
/* may return 0, but later on size == 0 means "don't
write the length" */
ret_val = put_user(size,
&((struct atmif_sioc *) arg)->length) ? -EFAULT : 0;
goto done_release;
case ATM_SETLOOP:
if (__ATM_LM_XTRMT((int) (long) buf) &&
__ATM_LM_XTLOC((int) (long) buf) >
__ATM_LM_XTRMT((int) (long) buf)) {
ret_val = -EINVAL;
goto done_release;
}
/* fall through */
case ATM_SETCIRANGE:
case SONET_GETSTATZ:
case SONET_SETDIAG:
case SONET_CLRDIAG:
case SONET_SETFRAMING:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done_release;
}
/* fall through */
default:
if (!dev->ops->ioctl) {
ret_val = -EINVAL;
goto done_release;
}
size = dev->ops->ioctl(dev,cmd,buf);
if (size < 0) {
ret_val = (size == -ENOIOCTLCMD ? -EINVAL : size);
goto done_release;
}
}
if (size)
ret_val = put_user(size,&((struct atmif_sioc *) arg)->length) ?
-EFAULT : 0;
else
ret_val = 0;
done_release:
atm_dev_release(dev);
done:
return ret_val;
}
Generated by GNU enscript 1.6.4.