]> git.hungrycats.org Git - linux/commitdiff
[ATM]: [ioctl][4/8] Use new code for mpoa (from levon@movementarian.org)
authorChas Williams <chas@cmf.nrl.navy.mil>
Thu, 25 Sep 2003 14:13:02 +0000 (07:13 -0700)
committerDavid S. Miller <davem@nuts.ninka.net>
Thu, 25 Sep 2003 14:13:02 +0000 (07:13 -0700)
net/atm/ioctl.c
net/atm/mpc.c
net/atm/mpc.h

index 74f196e1dbe79165b23974b9736176f065d250b7..2810eb32f22be07868d55782f13cdf48b1781739 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/atmarp.h>      /* manifest constants */
 #include <linux/sonet.h>       /* for ioctls */
 #include <linux/atmsvc.h>
+#include <linux/atmmpc.h>
 #include <asm/ioctls.h>
 
 #ifdef CONFIG_ATM_CLIP
@@ -54,36 +55,6 @@ EXPORT_SYMBOL(atm_lane_ops_set);
 #endif
 #endif
 
-#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
-#include <linux/atmmpc.h>
-#include "mpc.h"
-struct atm_mpoa_ops *atm_mpoa_ops;
-static DECLARE_MUTEX(atm_mpoa_ops_mutex);
-
-void atm_mpoa_ops_set(struct atm_mpoa_ops *hook)
-{
-       down(&atm_mpoa_ops_mutex);
-       atm_mpoa_ops = hook;
-       up(&atm_mpoa_ops_mutex);
-}
-
-int try_atm_mpoa_ops(void)
-{
-       down(&atm_mpoa_ops_mutex);
-       if (atm_mpoa_ops && try_module_get(atm_mpoa_ops->owner)) {
-               up(&atm_mpoa_ops_mutex);
-               return 1;
-       }
-       up(&atm_mpoa_ops_mutex);
-       return 0;
-}
-#ifdef CONFIG_ATM_MPOA_MODULE
-EXPORT_SYMBOL(atm_mpoa_ops);
-EXPORT_SYMBOL(try_atm_mpoa_ops);
-EXPORT_SYMBOL(atm_mpoa_ops_set);
-#endif
-#endif
-
 #if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
 #include <linux/atm_tcp.h>
 #ifdef CONFIG_ATM_TCP_MODULE
@@ -309,36 +280,6 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                                error = -ENOSYS;
                        goto done;
 #endif
-#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
-               case ATMMPC_CTRL:
-                       if (!capable(CAP_NET_ADMIN)) {
-                               error = -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;
-                       } else
-                               error = -ENOSYS;
-                       goto done;
-               case ATMMPC_DATA:
-                       if (!capable(CAP_NET_ADMIN)) {
-                               error = -EPERM;
-                               goto done;
-                       }
-                       if (try_atm_mpoa_ops()) {
-                               error = atm_mpoa_ops->vcc_attach(vcc, arg);
-                               module_put(atm_mpoa_ops->owner);
-                       } else
-                               error = -ENOSYS;
-                       goto done;
-#endif
 #if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
                case SIOCSIFATMTCP:
                        if (!capable(CAP_NET_ADMIN)) {
@@ -385,6 +326,10 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                default:
                        break;
        }
+
+       if (cmd == ATMMPC_CTRL || cmd == ATMMPC_DATA)
+               request_module("mpoa");
+
        error = -ENOIOCTLCMD;
 
        down(&ioctl_mutex);
index 50c232216ae3e1bd6abba57a7a8310237ab573b2..f0d5dbe0e682f9c98e072977fbeb55c4577d3d25 100644 (file)
@@ -1400,15 +1400,41 @@ static void mpc_cache_check( unsigned long checking_time  )
        return;
 }
 
-static struct atm_mpoa_ops __atm_mpoa_ops = {
-       .mpoad_attach = atm_mpoa_mpoad_attach,
-       .vcc_attach =   atm_mpoa_vcc_attach,
-       .owner = THIS_MODULE
+static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       int err = 0;
+       struct atm_vcc *vcc = ATM_SD(sock);
+
+       if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA)
+               return -ENOIOCTLCMD;
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       switch (cmd) {
+               case ATMMPC_CTRL:
+                       err = atm_mpoa_mpoad_attach(vcc, (int)arg);
+                       if (err >= 0)
+                               sock->state = SS_CONNECTED;
+                       break;
+               case ATMMPC_DATA:
+                       err = atm_mpoa_vcc_attach(vcc, arg);
+                       break;
+               default:
+                       break;
+       }
+       return err;
+}
+
+
+static struct atm_ioctl atm_ioctl_ops = {
+       .owner  = THIS_MODULE,
+       .ioctl  = atm_mpoa_ioctl,
 };
 
 static __init int atm_mpoa_init(void)
 {
-       atm_mpoa_ops_set(&__atm_mpoa_ops);
+       register_atm_ioctl(&atm_ioctl_ops);
 
 #ifdef CONFIG_PROC_FS
        if (mpc_proc_init() != 0)
@@ -1434,7 +1460,7 @@ void __exit atm_mpoa_cleanup(void)
 
        del_timer(&mpc_timer);
        unregister_netdevice_notifier(&mpoa_notifier);
-       atm_mpoa_ops_set(NULL);
+       deregister_atm_ioctl(&atm_ioctl_ops);
 
        mpc = mpcs;
        mpcs = NULL;
index f0b33dbf469eb682afc6cb570124837bbcde99e7..1b9aee70d3f4b759df0384685c1d7724694d637e 100644 (file)
@@ -44,18 +44,6 @@ struct atm_mpoa_qos {
 };
 
 
-/* Functions to call during ioctl(ATMMPC, ) */
-struct atm_mpoa_ops {
-        int (*mpoad_attach)(struct atm_vcc *vcc, int arg);  /* attach mpoa daemon  */
-        int (*vcc_attach)(struct atm_vcc *vcc, long arg);   /* attach shortcut vcc */
-       struct module *owner;
-};
-
-/* Boot/module initialization function */
-extern struct atm_mpoa_ops *atm_mpoa_ops;
-int try_atm_mpoa_ops(void);
-void atm_mpoa_ops_set(struct atm_mpoa_ops *hook);
-
 /* MPOA QoS operations */
 struct atm_mpoa_qos *atm_mpoa_add_qos(uint32_t dst_ip, struct atm_qos *qos);
 struct atm_mpoa_qos *atm_mpoa_search_qos(uint32_t dst_ip);