From 1c306ffbf29e86781e99e8d0530981956348c204 Mon Sep 17 00:00:00 2001 From: Chas Williams Date: Thu, 25 Sep 2003 07:13:02 -0700 Subject: [PATCH] [ATM]: [ioctl][4/8] Use new code for mpoa (from levon@movementarian.org) --- net/atm/ioctl.c | 65 ++++--------------------------------------------- net/atm/mpc.c | 38 ++++++++++++++++++++++++----- net/atm/mpc.h | 12 --------- 3 files changed, 37 insertions(+), 78 deletions(-) diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c index 74f196e1dbe79..2810eb32f22be 100644 --- a/net/atm/ioctl.c +++ b/net/atm/ioctl.c @@ -14,6 +14,7 @@ #include /* manifest constants */ #include /* for ioctls */ #include +#include #include #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 -#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 #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); diff --git a/net/atm/mpc.c b/net/atm/mpc.c index 50c232216ae3e..f0d5dbe0e682f 100644 --- a/net/atm/mpc.c +++ b/net/atm/mpc.c @@ -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; diff --git a/net/atm/mpc.h b/net/atm/mpc.h index f0b33dbf469eb..1b9aee70d3f4b 100644 --- a/net/atm/mpc.h +++ b/net/atm/mpc.h @@ -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); -- 2.53.0