From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Mon, 3 Mar 2003 17:10:56 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Mon, 3 Mar 2003 17:10:56 -0500 Received: from locutus.cmf.nrl.navy.mil ([134.207.10.66]:64402 "EHLO locutus.cmf.nrl.navy.mil") by vger.kernel.org with ESMTP id ; Mon, 3 Mar 2003 17:10:27 -0500 Message-Id: <200303032220.h23MKVGi028878@locutus.cmf.nrl.navy.mil> To: "David S. Miller" cc: linux-kernel@vger.kernel.org Subject: [PATCH][ATM] make atm (and clip) modular + try_module_get() X-url: http://www.nrl.navy.mil/CCS/people/chas/index.html X-mailer: nmh 1.0 Date: Mon, 03 Mar 2003 17:20:31 -0500 From: chas williams Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org the following patch makes atm a module. this patch also fixes a number of other problems: MOD_INC/MOD_DEC are gone in lec and mpc (however i needed to use module_put() inside lec, mpc and clip due to the way the user space 'clients' unregister from the modules), clip is a module (i wrote the clip module_exit() function -- its *probably* correct), structs are now exported as pointers (if someone has a compelling reason it should remain the old way let me know), ipcommon.c is included by clip.c and doesnt export symbols -- it should probably just be split eventually with only llc_oui residing in the kernel (and exported) and skb_migrate moved to clip -- this really depends on the status of CONFIG_NET_SCH_ATM. Index: linux/net/atm/Makefile =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/Makefile,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 Makefile --- linux/net/atm/Makefile 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/Makefile 3 Mar 2003 16:51:03 -0000 @@ -3,12 +3,15 @@ # mpoa-objs := mpc.o mpoa_caches.o mpoa_proc.o +atm-objs := addr.o pvc.o signaling.o svc.o common.o atm_misc.o raw.o resources.o -obj-$(CONFIG_ATM) := addr.o pvc.o signaling.o svc.o common.o atm_misc.o raw.o resources.o +obj-$(CONFIG_ATM) += atm.o -obj-$(CONFIG_ATM_CLIP) += clip.o ipcommon.o -obj-$(CONFIG_NET_SCH_ATM) += ipcommon.o -obj-$(CONFIG_PROC_FS) += proc.o +obj-$(CONFIG_ATM_CLIP) += clip.o +# obj-$(CONFIG_NET_SCH_ATM) += ipcommon.o +ifeq ($(CONFIG_PROC_FS),y) +atm-objs += proc.o +endif obj-$(CONFIG_ATM_LANE) += lec.o obj-$(CONFIG_ATM_MPOA) += mpoa.o Index: linux/net/atm/clip.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/clip.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 clip.c --- linux/net/atm/clip.c 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/clip.c 3 Mar 2003 19:33:38 -0000 @@ -7,6 +7,7 @@ #include #include #include /* for UINT_MAX */ +#include #include #include #include @@ -48,6 +49,7 @@ static struct timer_list idle_timer; static int start_timer = 1; +#include "ipcommon.c" static int to_atmarpd(enum atmarp_ctrl_type type,int itf,unsigned long ip) { @@ -696,11 +698,12 @@ "pending\n"); skb_queue_purge(&vcc->recvq); DPRINTK("(done)\n"); + module_put(THIS_MODULE); } static struct atmdev_ops atmarpd_dev_ops = { - .close =atmarpd_close, + .close = atmarpd_close, }; @@ -747,10 +750,50 @@ return 0; } +static struct atm_clip_ops __atm_clip_ops = { + .clip_create = clip_create, + .clip_mkip = clip_mkip, + .clip_setentry = clip_setentry, + .clip_encap = clip_encap, + .clip_push = clip_push, + .atm_init_atmarp = atm_init_atmarp, + .clip_tbl = &clip_tbl, + .owner = THIS_MODULE +}; -void atm_clip_init(void) +static int __init atm_clip_init(void) { + extern struct atm_clip_ops *atm_clip_ops; + clip_tbl.lock = RW_LOCK_UNLOCKED; clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id, clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL); + + atm_clip_ops = &__atm_clip_ops; + + return 0; } + +static void __exit atm_clip_exit(void) +{ + extern struct atm_clip_ops *atm_clip_ops; + struct net_device *dev, *next; + + atm_clip_ops = NULL; + + next = clip_devs; + while (next) { + dev = next; + next = PRIV(dev)->next; + unregister_netdev(dev); + kfree(dev); + } + if (start_timer == 0) del_timer(&idle_timer); + + kmem_cache_destroy(clip_tbl.kmem_cachep); +} + +module_init(atm_clip_init); +module_exit(atm_clip_exit); + +MODULE_LICENSE("GPL"); Index: linux/net/atm/common.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/common.c,v retrieving revision 1.5 diff -u -r1.5 common.c --- linux/net/atm/common.c 26 Feb 2003 15:52:44 -0000 1.5 +++ linux/net/atm/common.c 3 Mar 2003 19:41:21 -0000 @@ -33,16 +33,16 @@ #include #include "lec.h" #include "lec_arpc.h" -struct atm_lane_ops atm_lane_ops; -#endif +struct atm_lane_ops *atm_lane_ops = NULL; #ifdef CONFIG_ATM_LANE_MODULE EXPORT_SYMBOL(atm_lane_ops); #endif +#endif #if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE) #include #include "mpc.h" -struct atm_mpoa_ops atm_mpoa_ops; +struct atm_mpoa_ops *atm_mpoa_ops = NULL; #endif #ifdef CONFIG_ATM_MPOA_MODULE EXPORT_SYMBOL(atm_mpoa_ops); @@ -59,6 +59,14 @@ #endif #endif +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) +#include +struct atm_clip_ops *atm_clip_ops = NULL; +#ifdef CONFIG_ATM_CLIP_MODULE +EXPORT_SYMBOL(atm_clip_ops); +#endif +#endif + #if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE) int (*pppoatm_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long); EXPORT_SYMBOL(pppoatm_ioctl_hook); @@ -68,9 +76,6 @@ #include "common.h" /* prototypes */ #include "protocols.h" /* atm_init_ */ #include "addr.h" /* address registry */ -#ifdef CONFIG_ATM_CLIP -#include /* for clip_create */ -#endif #include "signaling.h" /* for WAITING and sigd_attach */ @@ -642,39 +647,50 @@ if (!error) sock->state = SS_CONNECTED; ret_val = error; goto done; -#ifdef CONFIG_ATM_CLIP +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) case SIOCMKCLIP: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = clip_create(arg); + ret_val = atm_clip_ops->clip_create(arg); goto done; case ATMARPD_CTRL: if (!capable(CAP_NET_ADMIN)) { ret_val = -EPERM; goto done; } - error = atm_init_atmarp(vcc); - if (!error) sock->state = SS_CONNECTED; +#if defined(CONFIG_ATM_CLIP_MODULE) + if (atm_clip_ops == NULL) + request_module("clip"); +#endif + if (atm_clip_ops && !try_module_get(atm_clip_ops->owner)) { + ret_val = -ENOSYS; + goto done; + } + error = atm_clip_ops->atm_init_atmarp(vcc); + if (!error) + sock->state = SS_CONNECTED; + else + module_put(atm_clip_ops->owner); ret_val = error; goto done; case ATMARP_MKIP: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = clip_mkip(vcc,arg); + ret_val = atm_clip_ops->clip_mkip(vcc,arg); goto done; case ATMARP_SETENTRY: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = clip_setentry(vcc,arg); + ret_val = atm_clip_ops->clip_setentry(vcc,arg); goto done; case ATMARP_ENCAP: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = clip_encap(vcc,arg); + ret_val = atm_clip_ops->clip_encap(vcc,arg); goto done; #endif #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) @@ -683,30 +699,32 @@ ret_val = -EPERM; goto done; } - if (atm_lane_ops.lecd_attach == NULL) - atm_lane_init(); - if (!try_module_get(atm_lane_ops.owner)) { /* try again */ +#if defined(CONFIG_ATM_LANE_MODULE) + if (atm_lane_ops == NULL) + request_module("lec"); +#endif + if (atm_lane_ops && !try_module_get(atm_lane_ops->owner)) { ret_val = -ENOSYS; goto done; } - error = atm_lane_ops.lecd_attach(vcc, (int)arg); + error = atm_lane_ops->lecd_attach(vcc, (int)arg); if (error >= 0) sock->state = SS_CONNECTED; else - module_put(atm_lane_ops.owner); + module_put(atm_lane_ops->owner); ret_val = error; goto done; case ATMLEC_MCAST: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = atm_lane_ops.mcast_attach(vcc, (int)arg); + ret_val = atm_lane_ops->mcast_attach(vcc, (int)arg); goto done; case ATMLEC_DATA: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = atm_lane_ops.vcc_attach(vcc, (void*)arg); + ret_val = atm_lane_ops->vcc_attach(vcc, (void*)arg); goto done; #endif #if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE) @@ -715,21 +733,26 @@ ret_val = -EPERM; goto done; } - if (atm_mpoa_ops.mpoad_attach == NULL) - atm_mpoa_init(); - if (atm_mpoa_ops.mpoad_attach == NULL) { /* try again */ +#if defined(CONFIG_ATM_MPOA_MODULE) + if (atm_mpoa_ops == NULL) + request_module("mpoa"); +#endif + if (atm_mpoa_ops && !try_module_get(atm_mpoa_ops->owner)) { ret_val = -ENOSYS; goto done; } - error = atm_mpoa_ops.mpoad_attach(vcc, (int)arg); - if (error >= 0) sock->state = SS_CONNECTED; + error = atm_mpoa_ops->mpoad_attach(vcc, (int)arg); + if (error >= 0) + sock->state = SS_CONNECTED; + else + module_put(atm_mpoa_ops->owner); ret_val = error; goto done; case ATMMPC_DATA: if (!capable(CAP_NET_ADMIN)) ret_val = -EPERM; else - ret_val = atm_mpoa_ops.vcc_attach(vcc, arg); + ret_val = atm_mpoa_ops->vcc_attach(vcc, arg); goto done; #endif #if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE) @@ -1105,40 +1128,6 @@ } -/* - * lane_mpoa_init.c: A couple of helper functions - * to make modular LANE and MPOA client easier to implement - */ - -/* - * This is how it goes: - * - * if xxxx is not compiled as module, call atm_xxxx_init_ops() - * from here - * else call atm_mpoa_init_ops() from init_module() within - * the kernel when xxxx module is loaded - * - * In either case function pointers in struct atm_xxxx_ops - * are initialized to their correct values. Either they - * point to functions in the module or in the kernel - */ - -extern struct atm_mpoa_ops atm_mpoa_ops; /* in common.c */ -extern struct atm_lane_ops atm_lane_ops; /* in common.c */ - -#if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE) -void atm_mpoa_init(void) -{ -#ifndef CONFIG_ATM_MPOA_MODULE /* not module */ - atm_mpoa_init_ops(&atm_mpoa_ops); -#else - request_module("mpoa"); -#endif - - return; -} -#endif - #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br, @@ -1149,15 +1138,33 @@ EXPORT_SYMBOL(br_fdb_put_hook); #endif /* defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE) */ #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */ +#endif /* defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) */ + -void atm_lane_init(void) +static int __init atm_init(void) { -#ifndef CONFIG_ATM_LANE_MODULE /* not module */ - atm_lane_init_ops(&atm_lane_ops); -#else - request_module("lec"); + int error = 0; + + if (atmpvc_init() < 0) + return -1; + if (atmsvc_init() < 0) + return -1; +#ifdef CONFIG_PROC_FS + error = atm_proc_init(); + if (error) printk("atm_proc_init fails with %d\n",error); #endif + return error; +} - return; -} +static void __exit atm_exit(void) +{ +#ifdef CONFIG_PROC_FS + atm_proc_exit(); #endif + atmsvc_exit(); + atmpvc_exit(); +} + +module_init(atm_init); +module_exit(atm_exit); +MODULE_LICENSE("GPL"); Index: linux/net/atm/common.h =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/common.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 common.h --- linux/net/atm/common.h 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/common.h 27 Feb 2003 16:47:15 -0000 @@ -28,7 +28,14 @@ void atm_release_vcc_sk(struct sock *sk,int free_sk); void atm_shutdown_dev(struct atm_dev *dev); +int atmsvc_init(void); +void atmsvc_exit(void); + +int atmpvc_init(void); +void atmpvc_exit(void); + int atm_proc_init(void); +void atm_proc_exit(void); /* SVC */ Index: linux/net/atm/ipcommon.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/ipcommon.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ipcommon.c --- linux/net/atm/ipcommon.c 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/ipcommon.c 3 Mar 2003 16:51:32 -0000 @@ -65,6 +65,3 @@ from->qlen = 0; spin_unlock_irqrestore(&from->lock,flags); } - - -EXPORT_SYMBOL(skb_migrate); Index: linux/net/atm/ipcommon.h =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/ipcommon.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ipcommon.h --- linux/net/atm/ipcommon.h 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/ipcommon.h 3 Mar 2003 16:52:24 -0000 @@ -13,8 +13,6 @@ #include -extern struct net_device *clip_devs; - /* * Appends all skbs from "from" to "to". The operation is atomic with respect * to all other skb operations on "from" or "to". Index: linux/net/atm/lec.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/lec.c,v retrieving revision 1.11 diff -u -r1.11 lec.c --- linux/net/atm/lec.c 3 Mar 2003 21:25:05 -0000 1.11 +++ linux/net/atm/lec.c 3 Mar 2003 21:27:05 -0000 @@ -541,14 +541,14 @@ atm_return(vcc, skb->truesize); dev_kfree_skb(skb); } - + printk("%s: Shut down!\n", dev->name); - MOD_DEC_USE_COUNT; + module_put(THIS_MODULE); } static struct atmdev_ops lecdev_ops = { .close = lec_atm_close, - .send = lec_atm_send + .send = lec_atm_send, }; static struct atm_dev lecatm_dev = { @@ -790,7 +790,6 @@ dev_lec[i] = init_etherdev(NULL, size); if (!dev_lec[i]) return -ENOMEM; - priv = dev_lec[i]->priv; priv->is_trdev = is_trdev; sprintf(dev_lec[i]->name, "lec%d", i); @@ -824,27 +823,23 @@ if (dev_lec[i]->flags & IFF_UP) { netif_start_queue(dev_lec[i]); } - MOD_INC_USE_COUNT; return i; } -void atm_lane_init_ops(struct atm_lane_ops *ops) -{ - ops->lecd_attach = lecd_attach; - ops->mcast_attach = lec_mcast_attach; - ops->vcc_attach = lec_vcc_attach; - ops->get_lecs = get_dev_lec; - - printk("lec.c: " __DATE__ " " __TIME__ " initialized\n"); - - return; -} +static struct atm_lane_ops __atm_lane_ops = { + .lecd_attach = lecd_attach, + .mcast_attach = lec_mcast_attach, + .vcc_attach = lec_vcc_attach, + .get_lecs = get_dev_lec, + .owner = THIS_MODULE +}; static int __init lane_module_init(void) { - extern struct atm_lane_ops atm_lane_ops; + extern struct atm_lane_ops *atm_lane_ops; - atm_lane_init_ops(&atm_lane_ops); + atm_lane_ops = &__atm_lane_ops; + printk("lec.c: " __DATE__ " " __TIME__ " initialized\n"); return 0; } @@ -852,13 +847,10 @@ static void __exit lane_module_cleanup(void) { int i; - extern struct atm_lane_ops atm_lane_ops; + extern struct atm_lane_ops *atm_lane_ops; struct lec_priv *priv; - atm_lane_ops.lecd_attach = NULL; - atm_lane_ops.mcast_attach = NULL; - atm_lane_ops.vcc_attach = NULL; - atm_lane_ops.get_lecs = NULL; + atm_lane_ops = NULL; for (i = 0; i < MAX_LEC_ITF; i++) { if (dev_lec[i] != NULL) { @@ -871,7 +863,7 @@ unregister_netdev(dev_lec[i]); kfree(dev_lec[i]); dev_lec[i] = NULL; - } + } } return; @@ -1021,7 +1013,7 @@ #include #include #include -#include +#include #include Index: linux/net/atm/lec.h =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/lec.h,v retrieving revision 1.5 diff -u -r1.5 lec.h --- linux/net/atm/lec.h 3 Mar 2003 21:25:05 -0000 1.5 +++ linux/net/atm/lec.h 3 Mar 2003 21:25:17 -0000 @@ -65,6 +65,7 @@ int (*mcast_attach)(struct atm_vcc *vcc, int arg); int (*vcc_attach)(struct atm_vcc *vcc, void *arg); struct net_device **(*get_lecs)(void); + struct module *owner; }; /* @@ -155,7 +156,5 @@ unsigned char *atm_addr, struct sk_buff *data); void lec_push(struct atm_vcc *vcc, struct sk_buff *skb); -void atm_lane_init(void); -void atm_lane_init_ops(struct atm_lane_ops *ops); #endif /* _LEC_H_ */ Index: linux/net/atm/mpc.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/mpc.c,v retrieving revision 1.3 diff -u -r1.3 mpc.c --- linux/net/atm/mpc.c 3 Mar 2003 21:25:05 -0000 1.3 +++ linux/net/atm/mpc.c 3 Mar 2003 21:25:19 -0000 @@ -799,7 +799,6 @@ send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc); } - MOD_INC_USE_COUNT; return arg; } @@ -848,7 +847,7 @@ printk("mpoa: (%s) going down\n", (mpc->dev) ? mpc->dev->name : ""); - MOD_DEC_USE_COUNT; + module_put(THIS_MODULE); return; } @@ -1390,11 +1389,17 @@ return; } -void atm_mpoa_init_ops(struct atm_mpoa_ops *ops) +struct atm_mpoa_ops __atm_mpoa_ops = { + .mpoad_attach = atm_mpoa_mpoad_attach, + .vcc_attach = atm_mpoa_vcc_attach, + .owner = THIS_MODULE +}; + +static int __init atm_mpoa_init(void) { - ops->mpoad_attach = atm_mpoa_mpoad_attach; - ops->vcc_attach = atm_mpoa_vcc_attach; + extern struct atm_mpoa_ops *atm_mpoa_ops; + atm_mpoa_ops = &__atm_mpoa_ops; #ifdef CONFIG_PROC_FS if(mpc_proc_init() != 0) printk(KERN_INFO "mpoa: failed to initialize /proc/mpoa\n"); @@ -1404,22 +1409,12 @@ printk("mpc.c: " __DATE__ " " __TIME__ " initialized\n"); - return; -} - -#ifdef MODULE -int init_module(void) -{ - extern struct atm_mpoa_ops atm_mpoa_ops; - - atm_mpoa_init_ops(&atm_mpoa_ops); - return 0; } -void cleanup_module(void) +static void __exit atm_mpoa_cleanup(void) { - extern struct atm_mpoa_ops atm_mpoa_ops; + extern struct atm_mpoa_ops *atm_mpoa_ops; struct mpoa_client *mpc, *tmp; struct atm_mpoa_qos *qos, *nextqos; struct lec_priv *priv; @@ -1430,8 +1425,7 @@ del_timer(&mpc_timer); unregister_netdevice_notifier(&mpoa_notifier); - atm_mpoa_ops.mpoad_attach = NULL; - atm_mpoa_ops.vcc_attach = NULL; + atm_mpoa_ops = NULL; mpc = mpcs; mpcs = NULL; @@ -1463,8 +1457,9 @@ kfree(qos); qos = nextqos; } - - return; } -#endif /* MODULE */ + +module_init(atm_mpoa_init); +module_exit(atm_mpoa_cleanup); + MODULE_LICENSE("GPL"); Index: linux/net/atm/mpc.h =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/mpc.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 mpc.h --- linux/net/atm/mpc.h 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/mpc.h 1 Mar 2003 13:37:05 -0000 @@ -48,11 +48,8 @@ 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 */ -void atm_mpoa_init(void); -void atm_mpoa_init_ops(struct atm_mpoa_ops *ops); /* MPOA QoS operations */ struct atm_mpoa_qos *atm_mpoa_add_qos(uint32_t dst_ip, struct atm_qos *qos); Index: linux/net/atm/proc.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/proc.c,v retrieving revision 1.2 diff -u -r1.2 proc.c --- linux/net/atm/proc.c 26 Feb 2003 15:52:44 -0000 1.2 +++ linux/net/atm/proc.c 1 Mar 2003 14:39:12 -0000 @@ -39,16 +39,15 @@ #include "common.h" /* atm_proc_init prototype */ #include "signaling.h" /* to get sigd - ugly too */ -#ifdef CONFIG_ATM_CLIP +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) #include -#include "ipcommon.h" -extern void clip_push(struct atm_vcc *vcc,struct sk_buff *skb); +extern struct atm_clip_ops *atm_clip_ops; /* in common.c */ #endif #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) #include "lec.h" #include "lec_arpc.h" -extern struct atm_lane_ops atm_lane_ops; /* in common.c */ +extern struct atm_lane_ops *atm_lane_ops; /* in common.c */ #endif static ssize_t proc_dev_atm_read(struct file *file,char *buf,size_t count, @@ -89,7 +88,7 @@ } -#ifdef CONFIG_ATM_CLIP +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) static int svc_addr(char *buf,struct sockaddr_atmsvc *addr) @@ -178,8 +177,8 @@ aal_name[vcc->qos.aal],vcc->qos.rxtp.min_pcr, class_name[vcc->qos.rxtp.traffic_class],vcc->qos.txtp.min_pcr, class_name[vcc->qos.txtp.traffic_class]); -#ifdef CONFIG_ATM_CLIP - if (vcc->push == clip_push) { +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) + if (atm_clip_ops && (vcc->push == atm_clip_ops->clip_push)) { struct clip_vcc *clip_vcc = CLIP_VCC(vcc); struct net_device *dev; @@ -393,7 +392,7 @@ return 0; } -#ifdef CONFIG_ATM_CLIP +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) static int atm_arp_info(loff_t pos,char *buf) { struct neighbour *n; @@ -403,28 +402,30 @@ return sprintf(buf,"IPitf TypeEncp Idle IP address " "ATM address\n"); } + if (!atm_clip_ops) + return 0; count = pos; - read_lock_bh(&clip_tbl.lock); + read_lock_bh(&atm_clip_ops->clip_tbl->lock); for (i = 0; i <= NEIGH_HASHMASK; i++) - for (n = clip_tbl.hash_buckets[i]; n; n = n->next) { + for (n = atm_clip_ops->clip_tbl->hash_buckets[i]; n; n = n->next) { struct atmarp_entry *entry = NEIGH2ENTRY(n); struct clip_vcc *vcc; if (!entry->vccs) { if (--count) continue; atmarp_info(n->dev,entry,NULL,buf); - read_unlock_bh(&clip_tbl.lock); + read_unlock_bh(&atm_clip_ops->clip_tbl->lock); return strlen(buf); } for (vcc = entry->vccs; vcc; vcc = vcc->next) { if (--count) continue; atmarp_info(n->dev,entry,vcc,buf); - read_unlock_bh(&clip_tbl.lock); + read_unlock_bh(&atm_clip_ops->clip_tbl->lock); return strlen(buf); } } - read_unlock_bh(&clip_tbl.lock); + read_unlock_bh(&atm_clip_ops->clip_tbl->lock); return 0; } #endif @@ -442,13 +443,13 @@ " Status Flags " "VPI/VCI Recv VPI/VCI\n"); } - if (atm_lane_ops.get_lecs == NULL) + if (!atm_lane_ops) return 0; /* the lane module is not there yet */ - if (!try_module_get(atm_lane_ops.owner)) + if (!try_module_get(atm_lane_ops->owner)) return 0; - dev_lec = atm_lane_ops.get_lecs(); + dev_lec = atm_lane_ops->get_lecs(); count = pos; for(d=0;dname); lec_info(entry,buf+e); - module_put(atm_lane_ops.owner); + module_put(atm_lane_ops->owner); return strlen(buf); } } @@ -470,7 +471,7 @@ if (--count) continue; e=sprintf(buf,"%s ",dev_lec[d]->name); lec_info(entry, buf+e); - module_put(atm_lane_ops.owner); + module_put(atm_lane_ops->owner); return strlen(buf); } for(entry=priv->lec_no_forward; entry; @@ -478,7 +479,7 @@ if (--count) continue; e=sprintf(buf,"%s ",dev_lec[d]->name); lec_info(entry, buf+e); - module_put(atm_lane_ops.owner); + module_put(atm_lane_ops->owner); return strlen(buf); } for(entry=priv->mcast_fwds; entry; @@ -486,11 +487,11 @@ if (--count) continue; e=sprintf(buf,"%s ",dev_lec[d]->name); lec_info(entry, buf+e); - module_put(atm_lane_ops.owner); + module_put(atm_lane_ops->owner); return strlen(buf); } } - module_put(atm_lane_ops.owner); + module_put(atm_lane_ops->owner); return 0; } #endif @@ -591,12 +592,11 @@ name->proc_fops = &proc_spec_atm_operations; \ name->owner = THIS_MODULE +struct proc_dir_entry *devices = NULL, *pvc = NULL, *svc = NULL; +struct proc_dir_entry *arp = NULL, *lec = NULL, *vc = NULL; int __init atm_proc_init(void) { - struct proc_dir_entry *devices = NULL,*pvc = NULL,*svc = NULL; - struct proc_dir_entry *arp = NULL,*lec = NULL,*vc = NULL; - atm_proc_root = proc_mkdir("net/atm",NULL); if (!atm_proc_root) return -ENOMEM; @@ -604,7 +604,7 @@ CREATE_ENTRY(pvc); CREATE_ENTRY(svc); CREATE_ENTRY(vc); -#ifdef CONFIG_ATM_CLIP +#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) CREATE_ENTRY(arp); #endif #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) @@ -621,4 +621,15 @@ if (vc) remove_proc_entry("vc",atm_proc_root); remove_proc_entry("net/atm",NULL); return -ENOMEM; +} + +void __exit atm_proc_exit(void) +{ + if (vc) remove_proc_entry("vc",atm_proc_root); + if (lec) remove_proc_entry("lec",atm_proc_root); + if (arp) remove_proc_entry("arp",atm_proc_root); + if (svc) remove_proc_entry("svc",atm_proc_root); + if (pvc) remove_proc_entry("pvc",atm_proc_root); + if (devices) remove_proc_entry("devices",atm_proc_root); + remove_proc_entry("net/atm",NULL); } Index: linux/net/atm/pvc.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/pvc.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 pvc.c --- linux/net/atm/pvc.c 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/pvc.c 1 Mar 2003 14:11:17 -0000 @@ -15,9 +15,6 @@ #include #include #include /* for sock_no_* */ -#ifdef CONFIG_ATM_CLIP -#include -#endif #include "resources.h" /* devs and vccs */ #include "common.h" /* common for PVCs and SVCs */ @@ -111,8 +108,8 @@ static struct net_proto_family pvc_family_ops = { - .family =PF_ATMPVC, - .create =pvc_create, + .family = PF_ATMPVC, + .create = pvc_create, }; @@ -121,23 +118,20 @@ */ -static int __init atmpvc_init(void) +int __init atmpvc_init(void) { int error; error = sock_register(&pvc_family_ops); if (error < 0) { - printk(KERN_ERR "ATMPVC: can't register (%d)",error); + printk(KERN_ERR "ATMPVC: can't register (%d)", error); return error; } -#ifdef CONFIG_ATM_CLIP - atm_clip_init(); -#endif -#ifdef CONFIG_PROC_FS - error = atm_proc_init(); - if (error) printk("atm_proc_init fails with %d\n",error); -#endif - return 0; + + return error; } -module_init(atmpvc_init); +void __exit atmpvc_exit(void) +{ + sock_unregister(PF_ATMPVC); +} Index: linux/net/atm/svc.c =================================================================== RCS file: /home/chas/CVSROOT/linux/net/atm/svc.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 svc.c --- linux/net/atm/svc.c 20 Feb 2003 13:46:30 -0000 1.1.1.1 +++ linux/net/atm/svc.c 27 Feb 2003 16:48:54 -0000 @@ -430,8 +430,8 @@ static struct net_proto_family svc_family_ops = { - .family =PF_ATMSVC, - .create =svc_create, + .family = PF_ATMSVC, + .create = svc_create, }; @@ -439,13 +439,19 @@ * Initialize the ATM SVC protocol family */ -static int __init atmsvc_init(void) +int __init atmsvc_init(void) { - if (sock_register(&svc_family_ops) < 0) { - printk(KERN_ERR "ATMSVC: can't register"); + int error; + + error = sock_register(&svc_family_ops); + if (error < 0) { + printk(KERN_ERR "ATMSVC: can't register (%d)\n", error); return -1; } return 0; } -module_init(atmsvc_init); +void __exit atmsvc_exit(void) +{ + sock_unregister(PF_ATMSVC); +} Index: linux/include/net/atmclip.h =================================================================== RCS file: /home/chas/CVSROOT/linux/include/net/atmclip.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 atmclip.h --- linux/include/net/atmclip.h 20 Feb 2003 13:45:58 -0000 1.1.1.1 +++ linux/include/net/atmclip.h 1 Mar 2003 13:59:31 -0000 @@ -62,6 +62,16 @@ int clip_mkip(struct atm_vcc *vcc,int timeout); int clip_setentry(struct atm_vcc *vcc,u32 ip); int clip_encap(struct atm_vcc *vcc,int mode); -void atm_clip_init(void); + +struct atm_clip_ops { + int (*clip_create)(int number); + int (*clip_mkip)(struct atm_vcc *vcc,int timeout); + int (*clip_setentry)(struct atm_vcc *vcc,u32 ip); + int (*clip_encap)(struct atm_vcc *vcc,int mode); + void (*clip_push)(struct atm_vcc *vcc,struct sk_buff *skb); + int (*atm_init_atmarp)(struct atm_vcc *vcc); + struct neigh_table *clip_tbl; + struct module *owner; +}; #endif