/* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
|
/* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
|
|
|
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
|
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
|
|
|
|
|
#include <linux/config.h>
|
#include <linux/config.h>
|
#include <linux/module.h>
|
#include <linux/module.h>
|
#include <linux/kmod.h>
|
#include <linux/kmod.h>
|
#include <linux/net.h> /* struct socket, struct net_proto, struct
|
#include <linux/net.h> /* struct socket, struct net_proto, struct
|
proto_ops */
|
proto_ops */
|
#include <linux/atm.h> /* ATM stuff */
|
#include <linux/atm.h> /* ATM stuff */
|
#include <linux/atmdev.h>
|
#include <linux/atmdev.h>
|
#include <linux/atmclip.h> /* CLIP_*ENCAP */
|
#include <linux/atmclip.h> /* CLIP_*ENCAP */
|
#include <linux/atmarp.h> /* manifest constants */
|
#include <linux/atmarp.h> /* manifest constants */
|
#include <linux/sonet.h> /* for ioctls */
|
#include <linux/sonet.h> /* for ioctls */
|
#include <linux/socket.h> /* SOL_SOCKET */
|
#include <linux/socket.h> /* SOL_SOCKET */
|
#include <linux/errno.h> /* error codes */
|
#include <linux/errno.h> /* error codes */
|
#include <linux/capability.h>
|
#include <linux/capability.h>
|
#include <linux/mm.h> /* verify_area */
|
#include <linux/mm.h> /* verify_area */
|
#include <linux/sched.h>
|
#include <linux/sched.h>
|
#include <linux/time.h> /* struct timeval */
|
#include <linux/time.h> /* struct timeval */
|
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
#include <linux/bitops.h>
|
#include <linux/bitops.h>
|
#include <linux/init.h>
|
#include <linux/init.h>
|
#include <net/sock.h> /* struct sock */
|
#include <net/sock.h> /* struct sock */
|
|
|
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
#include <asm/atomic.h>
|
#include <asm/atomic.h>
|
#include <asm/poll.h>
|
#include <asm/poll.h>
|
#include <asm/ioctls.h>
|
#include <asm/ioctls.h>
|
|
|
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
|
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
|
#include <linux/atmlec.h>
|
#include <linux/atmlec.h>
|
#include "lec.h"
|
#include "lec.h"
|
#include "lec_arpc.h"
|
#include "lec_arpc.h"
|
struct atm_lane_ops *atm_lane_ops;
|
struct atm_lane_ops *atm_lane_ops;
|
static DECLARE_MUTEX(atm_lane_ops_mutex);
|
static DECLARE_MUTEX(atm_lane_ops_mutex);
|
|
|
void atm_lane_ops_set(struct atm_lane_ops *hook)
|
void atm_lane_ops_set(struct atm_lane_ops *hook)
|
{
|
{
|
down(&atm_lane_ops_mutex);
|
down(&atm_lane_ops_mutex);
|
atm_lane_ops = hook;
|
atm_lane_ops = hook;
|
up(&atm_lane_ops_mutex);
|
up(&atm_lane_ops_mutex);
|
}
|
}
|
|
|
int try_atm_lane_ops(void)
|
int try_atm_lane_ops(void)
|
{
|
{
|
down(&atm_lane_ops_mutex);
|
down(&atm_lane_ops_mutex);
|
if (atm_lane_ops && try_inc_mod_count(atm_lane_ops->owner)) {
|
if (atm_lane_ops && try_inc_mod_count(atm_lane_ops->owner)) {
|
up(&atm_lane_ops_mutex);
|
up(&atm_lane_ops_mutex);
|
return 1;
|
return 1;
|
}
|
}
|
up(&atm_lane_ops_mutex);
|
up(&atm_lane_ops_mutex);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#if defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_ATM_MPOA_MODULE)
|
#if defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_ATM_MPOA_MODULE)
|
EXPORT_SYMBOL(atm_lane_ops);
|
EXPORT_SYMBOL(atm_lane_ops);
|
EXPORT_SYMBOL(try_atm_lane_ops);
|
EXPORT_SYMBOL(try_atm_lane_ops);
|
EXPORT_SYMBOL(atm_lane_ops_set);
|
EXPORT_SYMBOL(atm_lane_ops_set);
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
|
#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
|
#include <linux/atmmpc.h>
|
#include <linux/atmmpc.h>
|
#include "mpc.h"
|
#include "mpc.h"
|
struct atm_mpoa_ops *atm_mpoa_ops;
|
struct atm_mpoa_ops *atm_mpoa_ops;
|
static DECLARE_MUTEX(atm_mpoa_ops_mutex);
|
static DECLARE_MUTEX(atm_mpoa_ops_mutex);
|
|
|
void atm_mpoa_ops_set(struct atm_mpoa_ops *hook)
|
void atm_mpoa_ops_set(struct atm_mpoa_ops *hook)
|
{
|
{
|
down(&atm_mpoa_ops_mutex);
|
down(&atm_mpoa_ops_mutex);
|
atm_mpoa_ops = hook;
|
atm_mpoa_ops = hook;
|
up(&atm_mpoa_ops_mutex);
|
up(&atm_mpoa_ops_mutex);
|
}
|
}
|
|
|
int try_atm_mpoa_ops(void)
|
int try_atm_mpoa_ops(void)
|
{
|
{
|
down(&atm_mpoa_ops_mutex);
|
down(&atm_mpoa_ops_mutex);
|
if (atm_mpoa_ops && try_inc_mod_count(atm_mpoa_ops->owner)) {
|
if (atm_mpoa_ops && try_inc_mod_count(atm_mpoa_ops->owner)) {
|
up(&atm_mpoa_ops_mutex);
|
up(&atm_mpoa_ops_mutex);
|
return 1;
|
return 1;
|
}
|
}
|
up(&atm_mpoa_ops_mutex);
|
up(&atm_mpoa_ops_mutex);
|
return 0;
|
return 0;
|
}
|
}
|
#ifdef CONFIG_ATM_MPOA_MODULE
|
#ifdef CONFIG_ATM_MPOA_MODULE
|
EXPORT_SYMBOL(atm_mpoa_ops);
|
EXPORT_SYMBOL(atm_mpoa_ops);
|
EXPORT_SYMBOL(try_atm_mpoa_ops);
|
EXPORT_SYMBOL(try_atm_mpoa_ops);
|
EXPORT_SYMBOL(atm_mpoa_ops_set);
|
EXPORT_SYMBOL(atm_mpoa_ops_set);
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
|
#if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
|
#include <linux/atm_tcp.h>
|
#include <linux/atm_tcp.h>
|
#ifdef CONFIG_ATM_TCP_MODULE
|
#ifdef CONFIG_ATM_TCP_MODULE
|
struct atm_tcp_ops atm_tcp_ops;
|
struct atm_tcp_ops atm_tcp_ops;
|
EXPORT_SYMBOL(atm_tcp_ops);
|
EXPORT_SYMBOL(atm_tcp_ops);
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
|
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
|
#include <net/atmclip.h>
|
#include <net/atmclip.h>
|
struct atm_clip_ops *atm_clip_ops;
|
struct atm_clip_ops *atm_clip_ops;
|
static DECLARE_MUTEX(atm_clip_ops_mutex);
|
static DECLARE_MUTEX(atm_clip_ops_mutex);
|
|
|
void atm_clip_ops_set(struct atm_clip_ops *hook)
|
void atm_clip_ops_set(struct atm_clip_ops *hook)
|
{
|
{
|
down(&atm_clip_ops_mutex);
|
down(&atm_clip_ops_mutex);
|
atm_clip_ops = hook;
|
atm_clip_ops = hook;
|
up(&atm_clip_ops_mutex);
|
up(&atm_clip_ops_mutex);
|
}
|
}
|
|
|
int try_atm_clip_ops(void)
|
int try_atm_clip_ops(void)
|
{
|
{
|
down(&atm_clip_ops_mutex);
|
down(&atm_clip_ops_mutex);
|
if (atm_clip_ops && try_inc_mod_count(atm_clip_ops->owner)) {
|
if (atm_clip_ops && try_inc_mod_count(atm_clip_ops->owner)) {
|
up(&atm_clip_ops_mutex);
|
up(&atm_clip_ops_mutex);
|
return 1;
|
return 1;
|
}
|
}
|
up(&atm_clip_ops_mutex);
|
up(&atm_clip_ops_mutex);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#ifdef CONFIG_ATM_CLIP_MODULE
|
#ifdef CONFIG_ATM_CLIP_MODULE
|
EXPORT_SYMBOL(atm_clip_ops);
|
EXPORT_SYMBOL(atm_clip_ops);
|
EXPORT_SYMBOL(try_atm_clip_ops);
|
EXPORT_SYMBOL(try_atm_clip_ops);
|
EXPORT_SYMBOL(atm_clip_ops_set);
|
EXPORT_SYMBOL(atm_clip_ops_set);
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
|
#if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
|
static DECLARE_MUTEX(pppoatm_ioctl_mutex);
|
static DECLARE_MUTEX(pppoatm_ioctl_mutex);
|
|
|
static int (*pppoatm_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long);
|
static int (*pppoatm_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long);
|
|
|
void pppoatm_ioctl_set(int (*hook)(struct atm_vcc *, unsigned int, unsigned long))
|
void pppoatm_ioctl_set(int (*hook)(struct atm_vcc *, unsigned int, unsigned long))
|
{
|
{
|
down(&pppoatm_ioctl_mutex);
|
down(&pppoatm_ioctl_mutex);
|
pppoatm_ioctl_hook = hook;
|
pppoatm_ioctl_hook = hook;
|
up(&pppoatm_ioctl_mutex);
|
up(&pppoatm_ioctl_mutex);
|
}
|
}
|
#ifdef CONFIG_PPPOATM_MODULE
|
#ifdef CONFIG_PPPOATM_MODULE
|
EXPORT_SYMBOL(pppoatm_ioctl_set);
|
EXPORT_SYMBOL(pppoatm_ioctl_set);
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
|
#if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
|
static DECLARE_MUTEX(br2684_ioctl_mutex);
|
static DECLARE_MUTEX(br2684_ioctl_mutex);
|
|
|
static int (*br2684_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long);
|
static int (*br2684_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long);
|
|
|
void br2684_ioctl_set(int (*hook)(struct atm_vcc *, unsigned int, unsigned long))
|
void br2684_ioctl_set(int (*hook)(struct atm_vcc *, unsigned int, unsigned long))
|
{
|
{
|
down(&br2684_ioctl_mutex);
|
down(&br2684_ioctl_mutex);
|
br2684_ioctl_hook = hook;
|
br2684_ioctl_hook = hook;
|
up(&br2684_ioctl_mutex);
|
up(&br2684_ioctl_mutex);
|
}
|
}
|
#ifdef CONFIG_ATM_BR2684_MODULE
|
#ifdef CONFIG_ATM_BR2684_MODULE
|
EXPORT_SYMBOL(br2684_ioctl_set);
|
EXPORT_SYMBOL(br2684_ioctl_set);
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#include "resources.h" /* atm_find_dev */
|
#include "resources.h" /* atm_find_dev */
|
#include "common.h" /* prototypes */
|
#include "common.h" /* prototypes */
|
#include "protocols.h" /* atm_init_<transport> */
|
#include "protocols.h" /* atm_init_<transport> */
|
#include "addr.h" /* address registry */
|
#include "addr.h" /* address registry */
|
#ifdef CONFIG_ATM_CLIP
|
#ifdef CONFIG_ATM_CLIP
|
#include <net/atmclip.h> /* for clip_create */
|
#include <net/atmclip.h> /* for clip_create */
|
#endif
|
#endif
|
#include "signaling.h" /* for WAITING and sigd_attach */
|
#include "signaling.h" /* for WAITING and sigd_attach */
|
|
|
|
|
#if 0
|
#if 0
|
#define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
|
#define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
|
#else
|
#else
|
#define DPRINTK(format,args...)
|
#define DPRINTK(format,args...)
|
#endif
|
#endif
|
|
|
|
|
struct sock *vcc_sklist;
|
struct sock *vcc_sklist;
|
rwlock_t vcc_sklist_lock = RW_LOCK_UNLOCKED;
|
rwlock_t vcc_sklist_lock = RW_LOCK_UNLOCKED;
|
|
|
void __vcc_insert_socket(struct sock *sk)
|
void __vcc_insert_socket(struct sock *sk)
|
{
|
{
|
sk->next = vcc_sklist;
|
sk->next = vcc_sklist;
|
if (sk->next)
|
if (sk->next)
|
vcc_sklist->pprev = &sk->next;
|
vcc_sklist->pprev = &sk->next;
|
vcc_sklist = sk;
|
vcc_sklist = sk;
|
sk->pprev = &vcc_sklist;
|
sk->pprev = &vcc_sklist;
|
}
|
}
|
|
|
void vcc_insert_socket(struct sock *sk)
|
void vcc_insert_socket(struct sock *sk)
|
{
|
{
|
write_lock_irq(&vcc_sklist_lock);
|
write_lock_irq(&vcc_sklist_lock);
|
__vcc_insert_socket(sk);
|
__vcc_insert_socket(sk);
|
write_unlock_irq(&vcc_sklist_lock);
|
write_unlock_irq(&vcc_sklist_lock);
|
}
|
}
|
|
|
void vcc_remove_socket(struct sock *sk)
|
void vcc_remove_socket(struct sock *sk)
|
{
|
{
|
write_lock_irq(&vcc_sklist_lock);
|
write_lock_irq(&vcc_sklist_lock);
|
if (sk->pprev) {
|
if (sk->pprev) {
|
if (sk->next)
|
if (sk->next)
|
sk->next->pprev = sk->pprev;
|
sk->next->pprev = sk->pprev;
|
*sk->pprev = sk->next;
|
*sk->pprev = sk->next;
|
sk->pprev = NULL;
|
sk->pprev = NULL;
|
}
|
}
|
write_unlock_irq(&vcc_sklist_lock);
|
write_unlock_irq(&vcc_sklist_lock);
|
}
|
}
|
|
|
|
|
static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
|
static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
|
{
|
{
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
|
|
if (atomic_read(&vcc->sk->wmem_alloc) && !atm_may_send(vcc,size)) {
|
if (atomic_read(&vcc->sk->wmem_alloc) && !atm_may_send(vcc,size)) {
|
DPRINTK("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
|
DPRINTK("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
|
atomic_read(&vcc->sk->wmem_alloc),size,vcc->sk->sndbuf);
|
atomic_read(&vcc->sk->wmem_alloc),size,vcc->sk->sndbuf);
|
return NULL;
|
return NULL;
|
}
|
}
|
while (!(skb = alloc_skb(size,GFP_KERNEL))) schedule();
|
while (!(skb = alloc_skb(size,GFP_KERNEL))) schedule();
|
DPRINTK("AlTx %d += %d\n",atomic_read(&vcc->sk->wmem_alloc),skb->truesize);
|
DPRINTK("AlTx %d += %d\n",atomic_read(&vcc->sk->wmem_alloc),skb->truesize);
|
atomic_add(skb->truesize, &vcc->sk->wmem_alloc);
|
atomic_add(skb->truesize, &vcc->sk->wmem_alloc);
|
return skb;
|
return skb;
|
}
|
}
|
|
|
|
|
EXPORT_SYMBOL(vcc_sklist);
|
EXPORT_SYMBOL(vcc_sklist);
|
EXPORT_SYMBOL(vcc_sklist_lock);
|
EXPORT_SYMBOL(vcc_sklist_lock);
|
EXPORT_SYMBOL(vcc_insert_socket);
|
EXPORT_SYMBOL(vcc_insert_socket);
|
EXPORT_SYMBOL(vcc_remove_socket);
|
EXPORT_SYMBOL(vcc_remove_socket);
|
|
|
static void vcc_sock_destruct(struct sock *sk)
|
static void vcc_sock_destruct(struct sock *sk)
|
{
|
{
|
struct atm_vcc *vcc = sk->protinfo.af_atm;
|
struct atm_vcc *vcc = sk->protinfo.af_atm;
|
|
|
if (atomic_read(&vcc->sk->rmem_alloc))
|
if (atomic_read(&vcc->sk->rmem_alloc))
|
printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->rmem_alloc));
|
printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->rmem_alloc));
|
|
|
if (atomic_read(&vcc->sk->wmem_alloc))
|
if (atomic_read(&vcc->sk->wmem_alloc))
|
printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->wmem_alloc));
|
printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->wmem_alloc));
|
|
|
kfree(sk->protinfo.af_atm);
|
kfree(sk->protinfo.af_atm);
|
|
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
}
|
}
|
|
|
int vcc_create(struct socket *sock, int protocol, int family)
|
int vcc_create(struct socket *sock, int protocol, int family)
|
{
|
{
|
struct sock *sk;
|
struct sock *sk;
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
|
|
sock->sk = NULL;
|
sock->sk = NULL;
|
if (sock->type == SOCK_STREAM)
|
if (sock->type == SOCK_STREAM)
|
return -EINVAL;
|
return -EINVAL;
|
sk = sk_alloc(family, GFP_KERNEL, 1);
|
sk = sk_alloc(family, GFP_KERNEL, 1);
|
if (!sk)
|
if (!sk)
|
return -ENOMEM;
|
return -ENOMEM;
|
sock_init_data(NULL, sk);
|
sock_init_data(NULL, sk);
|
|
|
vcc = sk->protinfo.af_atm = kmalloc(sizeof(*vcc), GFP_KERNEL);
|
vcc = sk->protinfo.af_atm = kmalloc(sizeof(*vcc), GFP_KERNEL);
|
if (!vcc) {
|
if (!vcc) {
|
sk_free(sk);
|
sk_free(sk);
|
return -ENOMEM;
|
return -ENOMEM;
|
}
|
}
|
|
|
memset(vcc, 0, sizeof(*vcc));
|
memset(vcc, 0, sizeof(*vcc));
|
vcc->sk = sk;
|
vcc->sk = sk;
|
|
|
vcc->dev = NULL;
|
vcc->dev = NULL;
|
vcc->callback = NULL;
|
vcc->callback = NULL;
|
memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc));
|
memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc));
|
memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc));
|
memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc));
|
vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
|
vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
|
atomic_set(&vcc->sk->wmem_alloc,0);
|
atomic_set(&vcc->sk->wmem_alloc,0);
|
atomic_set(&vcc->sk->rmem_alloc,0);
|
atomic_set(&vcc->sk->rmem_alloc,0);
|
vcc->push = NULL;
|
vcc->push = NULL;
|
vcc->pop = NULL;
|
vcc->pop = NULL;
|
vcc->push_oam = NULL;
|
vcc->push_oam = NULL;
|
vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
|
vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
|
vcc->atm_options = vcc->aal_options = 0;
|
vcc->atm_options = vcc->aal_options = 0;
|
init_waitqueue_head(&vcc->sleep);
|
init_waitqueue_head(&vcc->sleep);
|
sk->sleep = &vcc->sleep;
|
sk->sleep = &vcc->sleep;
|
sk->destruct = vcc_sock_destruct;
|
sk->destruct = vcc_sock_destruct;
|
sock->sk = sk;
|
sock->sk = sk;
|
|
|
MOD_INC_USE_COUNT;
|
MOD_INC_USE_COUNT;
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
static void vcc_destroy_socket(struct sock *sk)
|
static void vcc_destroy_socket(struct sock *sk)
|
{
|
{
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
|
|
vcc = sk->protinfo.af_atm;
|
vcc = sk->protinfo.af_atm;
|
clear_bit(ATM_VF_READY, &vcc->flags);
|
clear_bit(ATM_VF_READY, &vcc->flags);
|
if (vcc->dev) {
|
if (vcc->dev) {
|
if (vcc->dev->ops->close)
|
if (vcc->dev->ops->close)
|
vcc->dev->ops->close(vcc);
|
vcc->dev->ops->close(vcc);
|
if (vcc->push)
|
if (vcc->push)
|
vcc->push(vcc, NULL); /* atmarpd has no push */
|
vcc->push(vcc, NULL); /* atmarpd has no push */
|
|
|
vcc_remove_socket(sk); /* no more receive */
|
vcc_remove_socket(sk); /* no more receive */
|
|
|
while ((skb = skb_dequeue(&vcc->sk->receive_queue))) {
|
while ((skb = skb_dequeue(&vcc->sk->receive_queue))) {
|
atm_return(vcc,skb->truesize);
|
atm_return(vcc,skb->truesize);
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
|
|
if (vcc->dev->ops->owner)
|
if (vcc->dev->ops->owner)
|
__MOD_DEC_USE_COUNT(vcc->dev->ops->owner);
|
__MOD_DEC_USE_COUNT(vcc->dev->ops->owner);
|
atm_dev_put(vcc->dev);
|
atm_dev_put(vcc->dev);
|
}
|
}
|
}
|
}
|
|
|
|
|
int vcc_release(struct socket *sock)
|
int vcc_release(struct socket *sock)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
|
|
if (sk) {
|
if (sk) {
|
lock_sock(sk);
|
lock_sock(sk);
|
vcc_destroy_socket(sock->sk);
|
vcc_destroy_socket(sock->sk);
|
release_sock(sk);
|
release_sock(sk);
|
sock_put(sk);
|
sock_put(sk);
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
void vcc_release_async(struct atm_vcc *vcc, int reply)
|
void vcc_release_async(struct atm_vcc *vcc, int reply)
|
{
|
{
|
set_bit(ATM_VF_CLOSE, &vcc->flags);
|
set_bit(ATM_VF_CLOSE, &vcc->flags);
|
vcc->reply = reply;
|
vcc->reply = reply;
|
vcc->sk->err = -reply;
|
vcc->sk->err = -reply;
|
wake_up(&vcc->sleep);
|
wake_up(&vcc->sleep);
|
}
|
}
|
|
|
|
|
EXPORT_SYMBOL(vcc_release_async);
|
EXPORT_SYMBOL(vcc_release_async);
|
|
|
|
|
static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
|
static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
|
{
|
{
|
int max_sdu;
|
int max_sdu;
|
|
|
if (!tp->traffic_class) return 0;
|
if (!tp->traffic_class) return 0;
|
switch (aal) {
|
switch (aal) {
|
case ATM_AAL0:
|
case ATM_AAL0:
|
max_sdu = ATM_CELL_SIZE-1;
|
max_sdu = ATM_CELL_SIZE-1;
|
break;
|
break;
|
case ATM_AAL34:
|
case ATM_AAL34:
|
max_sdu = ATM_MAX_AAL34_PDU;
|
max_sdu = ATM_MAX_AAL34_PDU;
|
break;
|
break;
|
default:
|
default:
|
printk(KERN_WARNING "ATM: AAL problems ... "
|
printk(KERN_WARNING "ATM: AAL problems ... "
|
"(%d)\n",aal);
|
"(%d)\n",aal);
|
/* fall through */
|
/* fall through */
|
case ATM_AAL5:
|
case ATM_AAL5:
|
max_sdu = ATM_MAX_AAL5_PDU;
|
max_sdu = ATM_MAX_AAL5_PDU;
|
}
|
}
|
if (!tp->max_sdu) tp->max_sdu = max_sdu;
|
if (!tp->max_sdu) tp->max_sdu = max_sdu;
|
else if (tp->max_sdu > max_sdu) return -EINVAL;
|
else if (tp->max_sdu > max_sdu) return -EINVAL;
|
if (!tp->max_cdv) tp->max_cdv = ATM_MAX_CDV;
|
if (!tp->max_cdv) tp->max_cdv = ATM_MAX_CDV;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, int vpi,
|
static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, int vpi,
|
int vci)
|
int vci)
|
{
|
{
|
int error;
|
int error;
|
|
|
if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
|
if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
|
vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
|
vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
|
vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
|
vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
|
return -EINVAL;
|
return -EINVAL;
|
if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
|
if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
|
return -EPERM;
|
return -EPERM;
|
error = 0;
|
error = 0;
|
if (!try_inc_mod_count(dev->ops->owner))
|
if (!try_inc_mod_count(dev->ops->owner))
|
return -ENODEV;
|
return -ENODEV;
|
vcc->dev = dev;
|
vcc->dev = dev;
|
vcc_insert_socket(vcc->sk);
|
vcc_insert_socket(vcc->sk);
|
switch (vcc->qos.aal) {
|
switch (vcc->qos.aal) {
|
case ATM_AAL0:
|
case ATM_AAL0:
|
error = atm_init_aal0(vcc);
|
error = atm_init_aal0(vcc);
|
vcc->stats = &dev->stats.aal0;
|
vcc->stats = &dev->stats.aal0;
|
break;
|
break;
|
case ATM_AAL34:
|
case ATM_AAL34:
|
error = atm_init_aal34(vcc);
|
error = atm_init_aal34(vcc);
|
vcc->stats = &dev->stats.aal34;
|
vcc->stats = &dev->stats.aal34;
|
break;
|
break;
|
case ATM_NO_AAL:
|
case ATM_NO_AAL:
|
/* ATM_AAL5 is also used in the "0 for default" case */
|
/* ATM_AAL5 is also used in the "0 for default" case */
|
vcc->qos.aal = ATM_AAL5;
|
vcc->qos.aal = ATM_AAL5;
|
/* fall through */
|
/* fall through */
|
case ATM_AAL5:
|
case ATM_AAL5:
|
error = atm_init_aal5(vcc);
|
error = atm_init_aal5(vcc);
|
vcc->stats = &dev->stats.aal5;
|
vcc->stats = &dev->stats.aal5;
|
break;
|
break;
|
default:
|
default:
|
error = -EPROTOTYPE;
|
error = -EPROTOTYPE;
|
}
|
}
|
if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal);
|
if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal);
|
if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal);
|
if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal);
|
if (error)
|
if (error)
|
goto fail;
|
goto fail;
|
DPRINTK("VCC %d.%d, AAL %d\n",vpi,vci,vcc->qos.aal);
|
DPRINTK("VCC %d.%d, AAL %d\n",vpi,vci,vcc->qos.aal);
|
DPRINTK(" TX: %d, PCR %d..%d, SDU %d\n",vcc->qos.txtp.traffic_class,
|
DPRINTK(" 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);
|
vcc->qos.txtp.min_pcr,vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu);
|
DPRINTK(" RX: %d, PCR %d..%d, SDU %d\n",vcc->qos.rxtp.traffic_class,
|
DPRINTK(" 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);
|
vcc->qos.rxtp.min_pcr,vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu);
|
if (dev->ops->open) {
|
if (dev->ops->open) {
|
if ((error = dev->ops->open(vcc,vpi,vci)))
|
if ((error = dev->ops->open(vcc,vpi,vci)))
|
goto fail;
|
goto fail;
|
}
|
}
|
return 0;
|
return 0;
|
|
|
fail:
|
fail:
|
vcc_remove_socket(vcc->sk);
|
vcc_remove_socket(vcc->sk);
|
if (dev->ops->owner)
|
if (dev->ops->owner)
|
__MOD_DEC_USE_COUNT(dev->ops->owner);
|
__MOD_DEC_USE_COUNT(dev->ops->owner);
|
/* ensure we get dev module ref count correct */
|
/* ensure we get dev module ref count correct */
|
vcc->dev = NULL;
|
vcc->dev = NULL;
|
return error;
|
return error;
|
|
|
}
|
}
|
|
|
|
|
int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
|
int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
|
{
|
{
|
struct atm_dev *dev;
|
struct atm_dev *dev;
|
struct atm_vcc *vcc = ATM_SD(sock);
|
struct atm_vcc *vcc = ATM_SD(sock);
|
int error;
|
int error;
|
|
|
DPRINTK("vcc_connect (vpi %d, vci %d)\n",vpi,vci);
|
DPRINTK("vcc_connect (vpi %d, vci %d)\n",vpi,vci);
|
if (sock->state == SS_CONNECTED)
|
if (sock->state == SS_CONNECTED)
|
return -EISCONN;
|
return -EISCONN;
|
if (sock->state != SS_UNCONNECTED)
|
if (sock->state != SS_UNCONNECTED)
|
return -EINVAL;
|
return -EINVAL;
|
if (!(vpi || vci))
|
if (!(vpi || vci))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
|
if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
|
clear_bit(ATM_VF_PARTIAL,&vcc->flags);
|
clear_bit(ATM_VF_PARTIAL,&vcc->flags);
|
else
|
else
|
if (test_bit(ATM_VF_PARTIAL,&vcc->flags))
|
if (test_bit(ATM_VF_PARTIAL,&vcc->flags))
|
return -EINVAL;
|
return -EINVAL;
|
DPRINTK("vcc_connect (TX: cl %d,bw %d-%d,sdu %d; "
|
DPRINTK("vcc_connect (TX: cl %d,bw %d-%d,sdu %d; "
|
"RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
|
"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.traffic_class,vcc->qos.txtp.min_pcr,
|
vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu,
|
vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu,
|
vcc->qos.rxtp.traffic_class,vcc->qos.rxtp.min_pcr,
|
vcc->qos.rxtp.traffic_class,vcc->qos.rxtp.min_pcr,
|
vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu,
|
vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu,
|
vcc->qos.aal == ATM_AAL5 ? "" : vcc->qos.aal == ATM_AAL0 ? "" :
|
vcc->qos.aal == ATM_AAL5 ? "" : vcc->qos.aal == ATM_AAL0 ? "" :
|
" ??? code ",vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
|
" ??? code ",vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
|
if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
|
if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
|
return -EBADFD;
|
return -EBADFD;
|
if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
|
if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
|
vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
|
vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
|
return -EINVAL;
|
return -EINVAL;
|
if (itf != ATM_ITF_ANY) {
|
if (itf != ATM_ITF_ANY) {
|
dev = atm_dev_lookup(itf);
|
dev = atm_dev_lookup(itf);
|
if (!dev)
|
if (!dev)
|
return -ENODEV;
|
return -ENODEV;
|
error = __vcc_connect(vcc, dev, vpi, vci);
|
error = __vcc_connect(vcc, dev, vpi, vci);
|
if (error) {
|
if (error) {
|
atm_dev_put(dev);
|
atm_dev_put(dev);
|
return error;
|
return error;
|
}
|
}
|
} else {
|
} else {
|
struct list_head *p, *next;
|
struct list_head *p, *next;
|
|
|
dev = NULL;
|
dev = NULL;
|
spin_lock(&atm_dev_lock);
|
spin_lock(&atm_dev_lock);
|
list_for_each_safe(p, next, &atm_devs) {
|
list_for_each_safe(p, next, &atm_devs) {
|
dev = list_entry(p, struct atm_dev, dev_list);
|
dev = list_entry(p, struct atm_dev, dev_list);
|
atm_dev_hold(dev);
|
atm_dev_hold(dev);
|
spin_unlock(&atm_dev_lock);
|
spin_unlock(&atm_dev_lock);
|
if (!__vcc_connect(vcc, dev, vpi, vci))
|
if (!__vcc_connect(vcc, dev, vpi, vci))
|
break;
|
break;
|
atm_dev_put(dev);
|
atm_dev_put(dev);
|
dev = NULL;
|
dev = NULL;
|
spin_lock(&atm_dev_lock);
|
spin_lock(&atm_dev_lock);
|
}
|
}
|
spin_unlock(&atm_dev_lock);
|
spin_unlock(&atm_dev_lock);
|
if (!dev)
|
if (!dev)
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
|
if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
|
set_bit(ATM_VF_PARTIAL,&vcc->flags);
|
set_bit(ATM_VF_PARTIAL,&vcc->flags);
|
if (test_bit(ATM_VF_READY,&ATM_SD(sock)->flags))
|
if (test_bit(ATM_VF_READY,&ATM_SD(sock)->flags))
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
int vcc_recvmsg(struct socket *sock, struct msghdr *msg,
|
int vcc_recvmsg(struct socket *sock, struct msghdr *msg,
|
int size, int flags, struct scm_cookie *scm)
|
int size, int flags, struct scm_cookie *scm)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
int copied, error = -EINVAL;
|
int copied, error = -EINVAL;
|
|
|
if (sock->state != SS_CONNECTED)
|
if (sock->state != SS_CONNECTED)
|
return -ENOTCONN;
|
return -ENOTCONN;
|
if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */
|
if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */
|
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
vcc = ATM_SD(sock);
|
vcc = ATM_SD(sock);
|
if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
|
if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
!test_bit(ATM_VF_READY, &vcc->flags))
|
!test_bit(ATM_VF_READY, &vcc->flags))
|
return 0;
|
return 0;
|
|
|
skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
|
skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
|
if (!skb)
|
if (!skb)
|
return error;
|
return error;
|
|
|
copied = skb->len;
|
copied = skb->len;
|
if (copied > size) {
|
if (copied > size) {
|
copied = size;
|
copied = size;
|
msg->msg_flags |= MSG_TRUNC;
|
msg->msg_flags |= MSG_TRUNC;
|
}
|
}
|
|
|
error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
|
error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
|
if (error)
|
if (error)
|
return error;
|
return error;
|
sock_recv_timestamp(msg, sk, skb);
|
sock_recv_timestamp(msg, sk, skb);
|
if (vcc->dev->ops->feedback)
|
if (vcc->dev->ops->feedback)
|
vcc->dev->ops->feedback(vcc, skb, (unsigned long) skb->data,
|
vcc->dev->ops->feedback(vcc, skb, (unsigned long) skb->data,
|
(unsigned long) msg->msg_iov->iov_base, copied);
|
(unsigned long) msg->msg_iov->iov_base, copied);
|
DPRINTK("RcvM %d -= %d\n", atomic_read(&vcc->sk->rmem_alloc), skb->truesize);
|
DPRINTK("RcvM %d -= %d\n", atomic_read(&vcc->sk->rmem_alloc), skb->truesize);
|
atm_return(vcc, skb->truesize);
|
atm_return(vcc, skb->truesize);
|
skb_free_datagram(sk, skb);
|
skb_free_datagram(sk, skb);
|
return copied;
|
return copied;
|
}
|
}
|
|
|
|
|
|
|
int vcc_sendmsg(struct socket *sock, struct msghdr *m, int total_len,
|
int vcc_sendmsg(struct socket *sock, struct msghdr *m, int total_len,
|
struct scm_cookie *scm)
|
struct scm_cookie *scm)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
DECLARE_WAITQUEUE(wait,current);
|
DECLARE_WAITQUEUE(wait,current);
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
int eff,error;
|
int eff,error;
|
const void *buff;
|
const void *buff;
|
int size;
|
int size;
|
|
|
lock_sock(sk);
|
lock_sock(sk);
|
if (sock->state != SS_CONNECTED) {
|
if (sock->state != SS_CONNECTED) {
|
error = -ENOTCONN;
|
error = -ENOTCONN;
|
goto out;
|
goto out;
|
}
|
}
|
if (m->msg_name) {
|
if (m->msg_name) {
|
error = -EISCONN;
|
error = -EISCONN;
|
goto out;
|
goto out;
|
}
|
}
|
if (m->msg_iovlen != 1) {
|
if (m->msg_iovlen != 1) {
|
error = -ENOSYS; /* fix this later @@@ */
|
error = -ENOSYS; /* fix this later @@@ */
|
goto out;
|
goto out;
|
}
|
}
|
buff = m->msg_iov->iov_base;
|
buff = m->msg_iov->iov_base;
|
size = m->msg_iov->iov_len;
|
size = m->msg_iov->iov_len;
|
vcc = ATM_SD(sock);
|
vcc = ATM_SD(sock);
|
if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
|
if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
error = -EPIPE;
|
error = -EPIPE;
|
send_sig(SIGPIPE, current, 0);
|
send_sig(SIGPIPE, current, 0);
|
goto out;
|
goto out;
|
}
|
}
|
if (!size) {
|
if (!size) {
|
error = 0;
|
error = 0;
|
goto out;
|
goto out;
|
}
|
}
|
if (size < 0 || size > vcc->qos.txtp.max_sdu) {
|
if (size < 0 || size > vcc->qos.txtp.max_sdu) {
|
error = -EMSGSIZE;
|
error = -EMSGSIZE;
|
goto out;
|
goto out;
|
}
|
}
|
/* verify_area is done by net/socket.c */
|
/* verify_area is done by net/socket.c */
|
eff = (size+3) & ~3; /* align to word boundary */
|
eff = (size+3) & ~3; /* align to word boundary */
|
add_wait_queue(&vcc->sleep,&wait);
|
add_wait_queue(&vcc->sleep,&wait);
|
set_current_state(TASK_INTERRUPTIBLE);
|
set_current_state(TASK_INTERRUPTIBLE);
|
error = 0;
|
error = 0;
|
while (!(skb = alloc_tx(vcc,eff))) {
|
while (!(skb = alloc_tx(vcc,eff))) {
|
if (m->msg_flags & MSG_DONTWAIT) {
|
if (m->msg_flags & MSG_DONTWAIT) {
|
error = -EAGAIN;
|
error = -EAGAIN;
|
break;
|
break;
|
}
|
}
|
schedule();
|
schedule();
|
set_current_state(TASK_INTERRUPTIBLE);
|
set_current_state(TASK_INTERRUPTIBLE);
|
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
error = -ERESTARTSYS;
|
error = -ERESTARTSYS;
|
break;
|
break;
|
}
|
}
|
if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
|
if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
test_bit(ATM_VF_CLOSE, &vcc->flags) ||
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
error = -EPIPE;
|
error = -EPIPE;
|
send_sig(SIGPIPE, current, 0);
|
send_sig(SIGPIPE, current, 0);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
set_current_state(TASK_RUNNING);
|
set_current_state(TASK_RUNNING);
|
remove_wait_queue(&vcc->sleep,&wait);
|
remove_wait_queue(&vcc->sleep,&wait);
|
if (error)
|
if (error)
|
goto out;
|
goto out;
|
skb->dev = NULL; /* for paths shared with net_device interfaces */
|
skb->dev = NULL; /* for paths shared with net_device interfaces */
|
ATM_SKB(skb)->atm_options = vcc->atm_options;
|
ATM_SKB(skb)->atm_options = vcc->atm_options;
|
if (copy_from_user(skb_put(skb,size),buff,size)) {
|
if (copy_from_user(skb_put(skb,size),buff,size)) {
|
kfree_skb(skb);
|
kfree_skb(skb);
|
error = -EFAULT;
|
error = -EFAULT;
|
goto out;
|
goto out;
|
}
|
}
|
if (eff != size) memset(skb->data+size,0,eff-size);
|
if (eff != size) memset(skb->data+size,0,eff-size);
|
error = vcc->dev->ops->send(vcc,skb);
|
error = vcc->dev->ops->send(vcc,skb);
|
error = error ? error : size;
|
error = error ? error : size;
|
out:
|
out:
|
release_sock(sk);
|
release_sock(sk);
|
return error;
|
return error;
|
}
|
}
|
|
|
|
|
unsigned int atm_poll(struct file *file,struct socket *sock,poll_table *wait)
|
unsigned int atm_poll(struct file *file,struct socket *sock,poll_table *wait)
|
{
|
{
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
unsigned int mask;
|
unsigned int mask;
|
|
|
vcc = ATM_SD(sock);
|
vcc = ATM_SD(sock);
|
poll_wait(file,&vcc->sleep,wait);
|
poll_wait(file,&vcc->sleep,wait);
|
mask = 0;
|
mask = 0;
|
if (skb_peek(&vcc->sk->receive_queue))
|
if (skb_peek(&vcc->sk->receive_queue))
|
mask |= POLLIN | POLLRDNORM;
|
mask |= POLLIN | POLLRDNORM;
|
if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
|
if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
|
test_bit(ATM_VF_CLOSE,&vcc->flags))
|
test_bit(ATM_VF_CLOSE,&vcc->flags))
|
mask |= POLLHUP;
|
mask |= POLLHUP;
|
if (sock->state != SS_CONNECTING) {
|
if (sock->state != SS_CONNECTING) {
|
if (vcc->qos.txtp.traffic_class != ATM_NONE &&
|
if (vcc->qos.txtp.traffic_class != ATM_NONE &&
|
vcc->qos.txtp.max_sdu+atomic_read(&vcc->sk->wmem_alloc) <= vcc->sk->sndbuf)
|
vcc->qos.txtp.max_sdu+atomic_read(&vcc->sk->wmem_alloc) <= vcc->sk->sndbuf)
|
mask |= POLLOUT | POLLWRNORM;
|
mask |= POLLOUT | POLLWRNORM;
|
}
|
}
|
else if (vcc->reply != WAITING) {
|
else if (vcc->reply != WAITING) {
|
mask |= POLLOUT | POLLWRNORM;
|
mask |= POLLOUT | POLLWRNORM;
|
if (vcc->reply) mask |= POLLERR;
|
if (vcc->reply) mask |= POLLERR;
|
}
|
}
|
return mask;
|
return mask;
|
}
|
}
|
|
|
|
|
int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
{
|
{
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
int error;
|
int error;
|
|
|
vcc = ATM_SD(sock);
|
vcc = ATM_SD(sock);
|
switch (cmd) {
|
switch (cmd) {
|
case SIOCOUTQ:
|
case SIOCOUTQ:
|
if (sock->state != SS_CONNECTED ||
|
if (sock->state != SS_CONNECTED ||
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
!test_bit(ATM_VF_READY, &vcc->flags)) {
|
error = -EINVAL;
|
error = -EINVAL;
|
goto done;
|
goto done;
|
}
|
}
|
error = put_user(vcc->sk->sndbuf-
|
error = put_user(vcc->sk->sndbuf-
|
atomic_read(&vcc->sk->wmem_alloc),
|
atomic_read(&vcc->sk->wmem_alloc),
|
(int *) arg) ? -EFAULT : 0;
|
(int *) arg) ? -EFAULT : 0;
|
goto done;
|
goto done;
|
case SIOCINQ:
|
case SIOCINQ:
|
{
|
{
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
|
|
if (sock->state != SS_CONNECTED) {
|
if (sock->state != SS_CONNECTED) {
|
error = -EINVAL;
|
error = -EINVAL;
|
goto done;
|
goto done;
|
}
|
}
|
skb = skb_peek(&vcc->sk->receive_queue);
|
skb = skb_peek(&vcc->sk->receive_queue);
|
error = put_user(skb ? skb->len : 0,
|
error = put_user(skb ? skb->len : 0,
|
(int *) arg) ? -EFAULT : 0;
|
(int *) arg) ? -EFAULT : 0;
|
goto done;
|
goto done;
|
}
|
}
|
case SIOCGSTAMP: /* borrowed from IP */
|
case SIOCGSTAMP: /* borrowed from IP */
|
if (!vcc->sk->stamp.tv_sec) {
|
if (!vcc->sk->stamp.tv_sec) {
|
error = -ENOENT;
|
error = -ENOENT;
|
goto done;
|
goto done;
|
}
|
}
|
error = copy_to_user((void *) arg, &vcc->sk->stamp,
|
error = copy_to_user((void *) arg, &vcc->sk->stamp,
|
sizeof(struct timeval)) ? -EFAULT : 0;
|
sizeof(struct timeval)) ? -EFAULT : 0;
|
goto done;
|
goto done;
|
case ATM_SETSC:
|
case ATM_SETSC:
|
printk(KERN_WARNING "ATM_SETSC is obsolete\n");
|
printk(KERN_WARNING "ATM_SETSC is obsolete\n");
|
error = 0;
|
error = 0;
|
goto done;
|
goto done;
|
case ATMSIGD_CTRL:
|
case ATMSIGD_CTRL:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
/*
|
/*
|
* The user/kernel protocol for exchanging signalling
|
* The user/kernel protocol for exchanging signalling
|
* info uses kernel pointers as opaque references,
|
* info uses kernel pointers as opaque references,
|
* so the holder of the file descriptor can scribble
|
* so the holder of the file descriptor can scribble
|
* on the kernel... so we should make sure that we
|
* on the kernel... so we should make sure that we
|
* have the same privledges that /proc/kcore needs
|
* have the same privledges that /proc/kcore needs
|
*/
|
*/
|
if (!capable(CAP_SYS_RAWIO)) {
|
if (!capable(CAP_SYS_RAWIO)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
error = sigd_attach(vcc);
|
error = sigd_attach(vcc);
|
if (!error)
|
if (!error)
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
goto done;
|
goto done;
|
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
|
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
|
case SIOCMKCLIP:
|
case SIOCMKCLIP:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_clip_ops()) {
|
if (try_atm_clip_ops()) {
|
error = atm_clip_ops->clip_create(arg);
|
error = atm_clip_ops->clip_create(arg);
|
if (atm_clip_ops->owner)
|
if (atm_clip_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMARPD_CTRL:
|
case ATMARPD_CTRL:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
#if defined(CONFIG_ATM_CLIP_MODULE)
|
#if defined(CONFIG_ATM_CLIP_MODULE)
|
if (!atm_clip_ops)
|
if (!atm_clip_ops)
|
request_module("clip");
|
request_module("clip");
|
#endif
|
#endif
|
if (try_atm_clip_ops()) {
|
if (try_atm_clip_ops()) {
|
error = atm_clip_ops->atm_init_atmarp(vcc);
|
error = atm_clip_ops->atm_init_atmarp(vcc);
|
if (atm_clip_ops->owner)
|
if (atm_clip_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
if (!error)
|
if (!error)
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMARP_MKIP:
|
case ATMARP_MKIP:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_clip_ops()) {
|
if (try_atm_clip_ops()) {
|
error = atm_clip_ops->clip_mkip(vcc, arg);
|
error = atm_clip_ops->clip_mkip(vcc, arg);
|
if (atm_clip_ops->owner)
|
if (atm_clip_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMARP_SETENTRY:
|
case ATMARP_SETENTRY:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_clip_ops()) {
|
if (try_atm_clip_ops()) {
|
error = atm_clip_ops->clip_setentry(vcc, arg);
|
error = atm_clip_ops->clip_setentry(vcc, arg);
|
if (atm_clip_ops->owner)
|
if (atm_clip_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMARP_ENCAP:
|
case ATMARP_ENCAP:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_clip_ops()) {
|
if (try_atm_clip_ops()) {
|
error = atm_clip_ops->clip_encap(vcc, arg);
|
error = atm_clip_ops->clip_encap(vcc, arg);
|
if (atm_clip_ops->owner)
|
if (atm_clip_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_clip_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
#endif
|
#endif
|
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
|
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
|
case ATMLEC_CTRL:
|
case ATMLEC_CTRL:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
#if defined(CONFIG_ATM_LANE_MODULE)
|
#if defined(CONFIG_ATM_LANE_MODULE)
|
if (!atm_lane_ops)
|
if (!atm_lane_ops)
|
request_module("lec");
|
request_module("lec");
|
#endif
|
#endif
|
if (try_atm_lane_ops()) {
|
if (try_atm_lane_ops()) {
|
error = atm_lane_ops->lecd_attach(vcc, (int) arg);
|
error = atm_lane_ops->lecd_attach(vcc, (int) arg);
|
if (atm_lane_ops->owner)
|
if (atm_lane_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_lane_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_lane_ops->owner);
|
if (error >= 0)
|
if (error >= 0)
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMLEC_MCAST:
|
case ATMLEC_MCAST:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_lane_ops()) {
|
if (try_atm_lane_ops()) {
|
error = atm_lane_ops->mcast_attach(vcc, (int) arg);
|
error = atm_lane_ops->mcast_attach(vcc, (int) arg);
|
if (atm_lane_ops->owner)
|
if (atm_lane_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_lane_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_lane_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMLEC_DATA:
|
case ATMLEC_DATA:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_lane_ops()) {
|
if (try_atm_lane_ops()) {
|
error = atm_lane_ops->vcc_attach(vcc, (void *) arg);
|
error = atm_lane_ops->vcc_attach(vcc, (void *) arg);
|
if (atm_lane_ops->owner)
|
if (atm_lane_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_lane_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_lane_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
#endif
|
#endif
|
#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
|
#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
|
case ATMMPC_CTRL:
|
case ATMMPC_CTRL:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
#if defined(CONFIG_ATM_MPOA_MODULE)
|
#if defined(CONFIG_ATM_MPOA_MODULE)
|
if (!atm_mpoa_ops)
|
if (!atm_mpoa_ops)
|
request_module("mpoa");
|
request_module("mpoa");
|
#endif
|
#endif
|
if (try_atm_mpoa_ops()) {
|
if (try_atm_mpoa_ops()) {
|
error = atm_mpoa_ops->mpoad_attach(vcc, (int) arg);
|
error = atm_mpoa_ops->mpoad_attach(vcc, (int) arg);
|
if (atm_mpoa_ops->owner)
|
if (atm_mpoa_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_mpoa_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_mpoa_ops->owner);
|
if (error >= 0)
|
if (error >= 0)
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
case ATMMPC_DATA:
|
case ATMMPC_DATA:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (try_atm_mpoa_ops()) {
|
if (try_atm_mpoa_ops()) {
|
error = atm_mpoa_ops->vcc_attach(vcc, arg);
|
error = atm_mpoa_ops->vcc_attach(vcc, arg);
|
if (atm_mpoa_ops->owner)
|
if (atm_mpoa_ops->owner)
|
__MOD_DEC_USE_COUNT(atm_mpoa_ops->owner);
|
__MOD_DEC_USE_COUNT(atm_mpoa_ops->owner);
|
} else
|
} else
|
error = -ENOSYS;
|
error = -ENOSYS;
|
goto done;
|
goto done;
|
#endif
|
#endif
|
#if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
|
#if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
|
case SIOCSIFATMTCP:
|
case SIOCSIFATMTCP:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (!atm_tcp_ops.attach) {
|
if (!atm_tcp_ops.attach) {
|
error = -ENOPKG;
|
error = -ENOPKG;
|
goto done;
|
goto done;
|
}
|
}
|
fops_get(&atm_tcp_ops);
|
fops_get(&atm_tcp_ops);
|
error = atm_tcp_ops.attach(vcc, (int) arg);
|
error = atm_tcp_ops.attach(vcc, (int) arg);
|
if (error >= 0)
|
if (error >= 0)
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
else
|
else
|
fops_put(&atm_tcp_ops);
|
fops_put(&atm_tcp_ops);
|
goto done;
|
goto done;
|
case ATMTCP_CREATE:
|
case ATMTCP_CREATE:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (!atm_tcp_ops.create_persistent) {
|
if (!atm_tcp_ops.create_persistent) {
|
error = -ENOPKG;
|
error = -ENOPKG;
|
goto done;
|
goto done;
|
}
|
}
|
error = atm_tcp_ops.create_persistent((int) arg);
|
error = atm_tcp_ops.create_persistent((int) arg);
|
if (error < 0)
|
if (error < 0)
|
fops_put(&atm_tcp_ops);
|
fops_put(&atm_tcp_ops);
|
goto done;
|
goto done;
|
case ATMTCP_REMOVE:
|
case ATMTCP_REMOVE:
|
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
error = -EPERM;
|
error = -EPERM;
|
goto done;
|
goto done;
|
}
|
}
|
if (!atm_tcp_ops.remove_persistent) {
|
if (!atm_tcp_ops.remove_persistent) {
|
error = -ENOPKG;
|
error = -ENOPKG;
|
goto done;
|
goto done;
|
}
|
}
|
error = atm_tcp_ops.remove_persistent((int) arg);
|
error = atm_tcp_ops.remove_persistent((int) arg);
|
fops_put(&atm_tcp_ops);
|
fops_put(&atm_tcp_ops);
|
goto done;
|
goto done;
|
#endif
|
#endif
|
default:
|
default:
|
break;
|
break;
|
}
|
}
|
error = -ENOIOCTLCMD;
|
error = -ENOIOCTLCMD;
|
#if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
|
#if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
|
down(&pppoatm_ioctl_mutex);
|
down(&pppoatm_ioctl_mutex);
|
if (pppoatm_ioctl_hook)
|
if (pppoatm_ioctl_hook)
|
error = pppoatm_ioctl_hook(vcc, cmd, arg);
|
error = pppoatm_ioctl_hook(vcc, cmd, arg);
|
up(&pppoatm_ioctl_mutex);
|
up(&pppoatm_ioctl_mutex);
|
if (error != -ENOIOCTLCMD)
|
if (error != -ENOIOCTLCMD)
|
goto done;
|
goto done;
|
#endif
|
#endif
|
#if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
|
#if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
|
down(&br2684_ioctl_mutex);
|
down(&br2684_ioctl_mutex);
|
if (br2684_ioctl_hook)
|
if (br2684_ioctl_hook)
|
error = br2684_ioctl_hook(vcc, cmd, arg);
|
error = br2684_ioctl_hook(vcc, cmd, arg);
|
up(&br2684_ioctl_mutex);
|
up(&br2684_ioctl_mutex);
|
if (error != -ENOIOCTLCMD)
|
if (error != -ENOIOCTLCMD)
|
goto done;
|
goto done;
|
#endif
|
#endif
|
|
|
error = atm_dev_ioctl(cmd, arg);
|
error = atm_dev_ioctl(cmd, arg);
|
|
|
done:
|
done:
|
return error;
|
return error;
|
}
|
}
|
|
|
|
|
static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
|
static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
|
{
|
{
|
int error;
|
int error;
|
|
|
/*
|
/*
|
* Don't let the QoS change the already connected AAL type nor the
|
* Don't let the QoS change the already connected AAL type nor the
|
* traffic class.
|
* traffic class.
|
*/
|
*/
|
if (qos->aal != vcc->qos.aal ||
|
if (qos->aal != vcc->qos.aal ||
|
qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
|
qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
|
qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
|
qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
|
return -EINVAL;
|
return -EINVAL;
|
error = adjust_tp(&qos->txtp,qos->aal);
|
error = adjust_tp(&qos->txtp,qos->aal);
|
if (!error) error = adjust_tp(&qos->rxtp,qos->aal);
|
if (!error) error = adjust_tp(&qos->rxtp,qos->aal);
|
if (error) return error;
|
if (error) return error;
|
if (!vcc->dev->ops->change_qos) return -EOPNOTSUPP;
|
if (!vcc->dev->ops->change_qos) return -EOPNOTSUPP;
|
if (vcc->sk->family == AF_ATMPVC)
|
if (vcc->sk->family == AF_ATMPVC)
|
return vcc->dev->ops->change_qos(vcc,qos,ATM_MF_SET);
|
return vcc->dev->ops->change_qos(vcc,qos,ATM_MF_SET);
|
return svc_change_qos(vcc,qos);
|
return svc_change_qos(vcc,qos);
|
}
|
}
|
|
|
|
|
static int check_tp(struct atm_trafprm *tp)
|
static int check_tp(struct atm_trafprm *tp)
|
{
|
{
|
/* @@@ Should be merged with adjust_tp */
|
/* @@@ Should be merged with adjust_tp */
|
if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) return 0;
|
if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) return 0;
|
if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
|
if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
|
!tp->max_pcr) return -EINVAL;
|
!tp->max_pcr) return -EINVAL;
|
if (tp->min_pcr == ATM_MAX_PCR) return -EINVAL;
|
if (tp->min_pcr == ATM_MAX_PCR) return -EINVAL;
|
if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
|
if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
|
tp->min_pcr > tp->max_pcr) return -EINVAL;
|
tp->min_pcr > tp->max_pcr) return -EINVAL;
|
/*
|
/*
|
* We allow pcr to be outside [min_pcr,max_pcr], because later
|
* We allow pcr to be outside [min_pcr,max_pcr], because later
|
* adjustment may still push it in the valid range.
|
* adjustment may still push it in the valid range.
|
*/
|
*/
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
static int check_qos(struct atm_qos *qos)
|
static int check_qos(struct atm_qos *qos)
|
{
|
{
|
int error;
|
int error;
|
|
|
if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
|
if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
|
return -EINVAL;
|
return -EINVAL;
|
if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
|
if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
|
qos->txtp.traffic_class && qos->rxtp.traffic_class &&
|
qos->txtp.traffic_class && qos->rxtp.traffic_class &&
|
qos->txtp.traffic_class != ATM_ANYCLASS &&
|
qos->txtp.traffic_class != ATM_ANYCLASS &&
|
qos->rxtp.traffic_class != ATM_ANYCLASS) return -EINVAL;
|
qos->rxtp.traffic_class != ATM_ANYCLASS) return -EINVAL;
|
error = check_tp(&qos->txtp);
|
error = check_tp(&qos->txtp);
|
if (error) return error;
|
if (error) return error;
|
return check_tp(&qos->rxtp);
|
return check_tp(&qos->rxtp);
|
}
|
}
|
|
|
int vcc_setsockopt(struct socket *sock, int level, int optname,
|
int vcc_setsockopt(struct socket *sock, int level, int optname,
|
char *optval, int optlen)
|
char *optval, int optlen)
|
{
|
{
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
unsigned long value;
|
unsigned long value;
|
int error;
|
int error;
|
|
|
if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
|
if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
vcc = ATM_SD(sock);
|
vcc = ATM_SD(sock);
|
switch (optname) {
|
switch (optname) {
|
case SO_ATMQOS:
|
case SO_ATMQOS:
|
{
|
{
|
struct atm_qos qos;
|
struct atm_qos qos;
|
|
|
if (copy_from_user(&qos,optval,sizeof(qos)))
|
if (copy_from_user(&qos,optval,sizeof(qos)))
|
return -EFAULT;
|
return -EFAULT;
|
error = check_qos(&qos);
|
error = check_qos(&qos);
|
if (error) return error;
|
if (error) return error;
|
if (sock->state == SS_CONNECTED)
|
if (sock->state == SS_CONNECTED)
|
return atm_change_qos(vcc,&qos);
|
return atm_change_qos(vcc,&qos);
|
if (sock->state != SS_UNCONNECTED)
|
if (sock->state != SS_UNCONNECTED)
|
return -EBADFD;
|
return -EBADFD;
|
vcc->qos = qos;
|
vcc->qos = qos;
|
set_bit(ATM_VF_HASQOS,&vcc->flags);
|
set_bit(ATM_VF_HASQOS,&vcc->flags);
|
return 0;
|
return 0;
|
}
|
}
|
case SO_SETCLP:
|
case SO_SETCLP:
|
if (get_user(value,(unsigned long *) optval))
|
if (get_user(value,(unsigned long *) optval))
|
return -EFAULT;
|
return -EFAULT;
|
if (value) vcc->atm_options |= ATM_ATMOPT_CLP;
|
if (value) vcc->atm_options |= ATM_ATMOPT_CLP;
|
else vcc->atm_options &= ~ATM_ATMOPT_CLP;
|
else vcc->atm_options &= ~ATM_ATMOPT_CLP;
|
return 0;
|
return 0;
|
default:
|
default:
|
if (level == SOL_SOCKET) return -EINVAL;
|
if (level == SOL_SOCKET) return -EINVAL;
|
break;
|
break;
|
}
|
}
|
if (!vcc->dev || !vcc->dev->ops->setsockopt) return -EINVAL;
|
if (!vcc->dev || !vcc->dev->ops->setsockopt) return -EINVAL;
|
return vcc->dev->ops->setsockopt(vcc,level,optname,optval,optlen);
|
return vcc->dev->ops->setsockopt(vcc,level,optname,optval,optlen);
|
}
|
}
|
|
|
|
|
int vcc_getsockopt(struct socket *sock, int level, int optname,
|
int vcc_getsockopt(struct socket *sock, int level, int optname,
|
char *optval, int *optlen)
|
char *optval, int *optlen)
|
{
|
{
|
struct atm_vcc *vcc;
|
struct atm_vcc *vcc;
|
int len;
|
int len;
|
|
|
if (get_user(len, optlen))
|
if (get_user(len, optlen))
|
return -EFAULT;
|
return -EFAULT;
|
if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
|
if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
vcc = ATM_SD(sock);
|
vcc = ATM_SD(sock);
|
switch (optname) {
|
switch (optname) {
|
case SO_ATMQOS:
|
case SO_ATMQOS:
|
if (!test_bit(ATM_VF_HASQOS,&vcc->flags))
|
if (!test_bit(ATM_VF_HASQOS,&vcc->flags))
|
return -EINVAL;
|
return -EINVAL;
|
return copy_to_user(optval,&vcc->qos,sizeof(vcc->qos)) ?
|
return copy_to_user(optval,&vcc->qos,sizeof(vcc->qos)) ?
|
-EFAULT : 0;
|
-EFAULT : 0;
|
case SO_SETCLP:
|
case SO_SETCLP:
|
return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 :
|
return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 :
|
0,(unsigned long *) optval) ? -EFAULT : 0;
|
0,(unsigned long *) optval) ? -EFAULT : 0;
|
case SO_ATMPVC:
|
case SO_ATMPVC:
|
{
|
{
|
struct sockaddr_atmpvc pvc;
|
struct sockaddr_atmpvc pvc;
|
|
|
if (!vcc->dev ||
|
if (!vcc->dev ||
|
!test_bit(ATM_VF_ADDR,&vcc->flags))
|
!test_bit(ATM_VF_ADDR,&vcc->flags))
|
return -ENOTCONN;
|
return -ENOTCONN;
|
pvc.sap_family = AF_ATMPVC;
|
pvc.sap_family = AF_ATMPVC;
|
pvc.sap_addr.itf = vcc->dev->number;
|
pvc.sap_addr.itf = vcc->dev->number;
|
pvc.sap_addr.vpi = vcc->vpi;
|
pvc.sap_addr.vpi = vcc->vpi;
|
pvc.sap_addr.vci = vcc->vci;
|
pvc.sap_addr.vci = vcc->vci;
|
return copy_to_user(optval,&pvc,sizeof(pvc)) ?
|
return copy_to_user(optval,&pvc,sizeof(pvc)) ?
|
-EFAULT : 0;
|
-EFAULT : 0;
|
}
|
}
|
default:
|
default:
|
if (level == SOL_SOCKET) return -EINVAL;
|
if (level == SOL_SOCKET) return -EINVAL;
|
break;
|
break;
|
}
|
}
|
if (!vcc->dev || !vcc->dev->ops->getsockopt) return -EINVAL;
|
if (!vcc->dev || !vcc->dev->ops->getsockopt) return -EINVAL;
|
return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
|
return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
|
}
|
}
|
|
|
|
|
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
|
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
|
#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
|
#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
|
struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
|
struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
|
unsigned char *addr) = NULL;
|
unsigned char *addr) = NULL;
|
void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent) = NULL;
|
void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent) = NULL;
|
#if defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE)
|
#if defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE)
|
EXPORT_SYMBOL(br_fdb_get_hook);
|
EXPORT_SYMBOL(br_fdb_get_hook);
|
EXPORT_SYMBOL(br_fdb_put_hook);
|
EXPORT_SYMBOL(br_fdb_put_hook);
|
#endif /* defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE) */
|
#endif /* defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE) */
|
#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
|
#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
|
#endif /* defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) */
|
#endif /* defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) */
|
|
|
|
|
static int __init atm_init(void)
|
static int __init atm_init(void)
|
{
|
{
|
int error;
|
int error;
|
|
|
if ((error = atmpvc_init()) < 0) {
|
if ((error = atmpvc_init()) < 0) {
|
printk(KERN_ERR "atmpvc_init() failed with %d\n", error);
|
printk(KERN_ERR "atmpvc_init() failed with %d\n", error);
|
goto failure;
|
goto failure;
|
}
|
}
|
if ((error = atmsvc_init()) < 0) {
|
if ((error = atmsvc_init()) < 0) {
|
printk(KERN_ERR "atmsvc_init() failed with %d\n", error);
|
printk(KERN_ERR "atmsvc_init() failed with %d\n", error);
|
goto failure;
|
goto failure;
|
}
|
}
|
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
if ((error = atm_proc_init()) < 0) {
|
if ((error = atm_proc_init()) < 0) {
|
printk(KERN_ERR "atm_proc_init() failed with %d\n",error);
|
printk(KERN_ERR "atm_proc_init() failed with %d\n",error);
|
goto failure;
|
goto failure;
|
}
|
}
|
#endif
|
#endif
|
return 0;
|
return 0;
|
|
|
failure:
|
failure:
|
atmsvc_exit();
|
atmsvc_exit();
|
atmpvc_exit();
|
atmpvc_exit();
|
return error;
|
return error;
|
}
|
}
|
|
|
static void __exit atm_exit(void)
|
static void __exit atm_exit(void)
|
{
|
{
|
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
atm_proc_exit();
|
atm_proc_exit();
|
#endif
|
#endif
|
atmsvc_exit();
|
atmsvc_exit();
|
atmpvc_exit();
|
atmpvc_exit();
|
}
|
}
|
|
|
module_init(atm_init);
|
module_init(atm_init);
|
module_exit(atm_exit);
|
module_exit(atm_exit);
|
|
|
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
|
|