Commit 171c62d7 authored by Chas Williams's avatar Chas Williams Committed by David S. Miller

[ATM]: Make clip modular.

parent 992c0e15
......@@ -55,13 +55,22 @@ struct clip_priv {
};
extern struct atm_vcc *atmarpd; /* ugly */
extern struct neigh_table clip_tbl;
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 atm_clip_init(void);
#ifdef __KERNEL__
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 module *owner;
};
void atm_clip_ops_set(struct atm_clip_ops *);
int try_atm_clip_ops(void);
extern struct neigh_table *clip_tbl_hook;
extern struct atm_clip_ops *atm_clip_ops;
#endif
#endif
......@@ -230,7 +230,7 @@ config ATM
further details.
config ATM_CLIP
bool "Classical IP over ATM (EXPERIMENTAL)"
tristate "Classical IP over ATM (EXPERIMENTAL)"
depends on ATM && INET
help
Classical IP over ATM for PVCs and SVCs, supporting InARP and
......
......@@ -2,13 +2,15 @@
# Makefile for the ATM Protocol Families.
#
atm-y := addr.o pvc.o signaling.o svc.o common.o atm_misc.o raw.o resources.o
mpoa-objs := mpc.o mpoa_caches.o mpoa_proc.o
obj-$(CONFIG_ATM) := addr.o pvc.o signaling.o svc.o common.o atm_misc.o raw.o resources.o
obj-$(CONFIG_ATM_CLIP) += clip.o ipcommon.o
obj-$(CONFIG_ATM_BR2684) += br2684.o ipcommon.o
obj-$(CONFIG_NET_SCH_ATM) += ipcommon.o
obj-$(CONFIG_ATM) += atm.o
obj-$(CONFIG_ATM_CLIP) += clip.o
atm-$(subst m,y,$(CONFIG_ATM_CLIP)) += ipcommon.o
obj-$(CONFIG_ATM_BR2684) += br2684.o
atm-$(subst m,y,$(CONFIG_ATM_BR2684)) += ipcommon.o
atm-$(subst m,y,$CONFIG_NET_SCH_ATM)) += ipcommon.o
obj-$(CONFIG_PROC_FS) += proc.o
obj-$(CONFIG_ATM_LANE) += lec.o
......
......@@ -7,6 +7,8 @@
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/kernel.h> /* for UINT_MAX */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/wait.h>
......@@ -45,6 +47,7 @@
struct net_device *clip_devs = NULL;
struct atm_vcc *atmarpd = NULL;
static struct neigh_table clip_tbl;
static struct timer_list idle_timer;
static int start_timer = 1;
......@@ -187,7 +190,7 @@ static int clip_arp_rcv(struct sk_buff *skb)
}
void clip_push(struct atm_vcc *vcc,struct sk_buff *skb)
static void clip_push(struct atm_vcc *vcc,struct sk_buff *skb)
{
struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
......@@ -325,7 +328,7 @@ static u32 clip_hash(const void *pkey, const struct net_device *dev)
}
struct neigh_table clip_tbl = {
static struct neigh_table clip_tbl = {
NULL, /* next */
AF_INET, /* family */
sizeof(struct neighbour)+sizeof(struct atmarp_entry), /* entry_size */
......@@ -371,7 +374,7 @@ struct neigh_table clip_tbl = {
*/
int clip_encap(struct atm_vcc *vcc,int mode)
static int clip_encap(struct atm_vcc *vcc,int mode)
{
CLIP_VCC(vcc)->encap = mode;
return 0;
......@@ -468,7 +471,7 @@ static struct net_device_stats *clip_get_stats(struct net_device *dev)
}
int clip_mkip(struct atm_vcc *vcc,int timeout)
static int clip_mkip(struct atm_vcc *vcc,int timeout)
{
struct clip_vcc *clip_vcc;
struct sk_buff_head copy;
......@@ -508,7 +511,7 @@ int clip_mkip(struct atm_vcc *vcc,int timeout)
}
int clip_setentry(struct atm_vcc *vcc,u32 ip)
static int clip_setentry(struct atm_vcc *vcc,u32 ip)
{
struct neighbour *neigh;
struct atmarp_entry *entry;
......@@ -581,7 +584,7 @@ static int clip_init(struct net_device *dev)
}
int clip_create(int number)
static int clip_create(int number)
{
struct net_device *dev;
struct clip_priv *clip_priv;
......@@ -701,28 +704,23 @@ static void atmarpd_close(struct atm_vcc *vcc)
"pending\n");
skb_queue_purge(&vcc->sk->receive_queue);
DPRINTK("(done)\n");
module_put(THIS_MODULE);
}
static struct atmdev_ops atmarpd_dev_ops = {
.close =atmarpd_close,
.close = atmarpd_close
};
static struct atm_dev atmarpd_dev = {
&atmarpd_dev_ops,
NULL, /* no PHY */
"arpd", /* type */
999, /* dummy device number */
NULL,NULL, /* pretend not to have any VCCs */
NULL,NULL, /* no data */
0, /* no flags */
NULL, /* no local address */
{ 0 } /* no ESI, no statistics */
.ops = &atmarpd_dev_ops,
.type = "arpd",
.number = 999,
};
int atm_init_atmarp(struct atm_vcc *vcc)
static int atm_init_atmarp(struct atm_vcc *vcc)
{
struct net_device *dev;
......@@ -752,10 +750,57 @@ int atm_init_atmarp(struct atm_vcc *vcc)
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,
.owner = THIS_MODULE
};
void atm_clip_init(void)
static int __init atm_clip_init(void)
{
/* we should use neigh_table_init() */
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);
/* so neigh_ifdown() doesn't complain */
clip_tbl.proxy_timer.data = 0;
clip_tbl.proxy_timer.function = 0;
init_timer(&clip_tbl.proxy_timer);
skb_queue_head_init(&clip_tbl.proxy_queue);
clip_tbl_hook = &clip_tbl;
atm_clip_ops_set(&__atm_clip_ops);
return 0;
}
static void __exit atm_clip_exit(void)
{
struct net_device *dev, *next;
atm_clip_ops_set(NULL);
neigh_ifdown(&clip_tbl, NULL);
dev = clip_devs;
while (dev) {
next = PRIV(dev)->next;
unregister_netdev(dev);
kfree(dev);
dev = next;
}
if (start_timer == 0) del_timer(&idle_timer);
kmem_cache_destroy(clip_tbl.kmem_cachep);
clip_tbl_hook = NULL;
}
module_init(atm_clip_init);
module_exit(atm_clip_exit);
MODULE_LICENSE("GPL");
......@@ -57,6 +57,36 @@ EXPORT_SYMBOL(atm_tcp_ops);
#endif
#endif
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
#include <net/atmclip.h>
struct atm_clip_ops *atm_clip_ops;
static DECLARE_MUTEX(atm_clip_ops_mutex);
void atm_clip_ops_set(struct atm_clip_ops *hook)
{
down(&atm_clip_ops_mutex);
atm_clip_ops = hook;
up(&atm_clip_ops_mutex);
}
int try_atm_clip_ops(void)
{
down(&atm_clip_ops_mutex);
if (atm_clip_ops && try_module_get(atm_clip_ops->owner)) {
up(&atm_clip_ops_mutex);
return 1;
}
up(&atm_clip_ops_mutex);
return 0;
}
#ifdef CONFIG_ATM_CLIP_MODULE
EXPORT_SYMBOL(atm_clip_ops);
EXPORT_SYMBOL(atm_clip_ops_mutex);
EXPORT_SYMBOL(atm_clip_ops_set);
#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);
......@@ -623,39 +653,67 @@ int atm_ioctl(struct socket *sock,unsigned int cmd,unsigned long arg)
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))
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
else
ret_val = clip_create(arg);
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_create(arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMARPD_CTRL:
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
goto done;
}
error = atm_init_atmarp(vcc);
if (!error) sock->state = SS_CONNECTED;
ret_val = error;
#if defined(CONFIG_ATM_CLIP_MODULE)
if (!atm_clip_ops)
request_module("clip");
#endif
if (try_atm_clip_ops()) {
error = atm_clip_ops->atm_init_atmarp(vcc);
if (!error)
sock->state = SS_CONNECTED;
ret_val = error;
} else
ret_val = -ENOSYS;
goto done;
case ATMARP_MKIP:
if (!capable(CAP_NET_ADMIN))
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
else
ret_val = clip_mkip(vcc,arg);
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_mkip(vcc, arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMARP_SETENTRY:
if (!capable(CAP_NET_ADMIN))
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
else
ret_val = clip_setentry(vcc,arg);
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_setentry(vcc, arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
case ATMARP_ENCAP:
if (!capable(CAP_NET_ADMIN))
if (!capable(CAP_NET_ADMIN)) {
ret_val = -EPERM;
else
ret_val = clip_encap(vcc,arg);
goto done;
}
if (try_atm_clip_ops()) {
ret_val = atm_clip_ops->clip_encap(vcc, arg);
module_put(atm_clip_ops->owner);
} else
ret_val = -ENOSYS;
goto done;
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
......
......@@ -67,4 +67,5 @@ void skb_migrate(struct sk_buff_head *from,struct sk_buff_head *to)
}
EXPORT_SYMBOL(llc_oui);
EXPORT_SYMBOL(skb_migrate);
......@@ -39,10 +39,9 @@
#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 <net/atmclip.h>
#include "ipcommon.h"
extern void clip_push(struct atm_vcc *vcc,struct sk_buff *skb);
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
......@@ -91,7 +90,7 @@ static void dev_info(const struct atm_dev *dev,char *buf)
}
#ifdef CONFIG_ATM_CLIP
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
static int svc_addr(char *buf,struct sockaddr_atmsvc *addr)
......@@ -180,16 +179,21 @@ static void pvc_info(struct atm_vcc *vcc,char *buf)
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) {
struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
struct net_device *dev;
dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL;
off += sprintf(buf+off,"CLIP, Itf:%s, Encap:",
dev ? dev->name : "none?");
if (clip_vcc->encap) off += sprintf(buf+off,"LLC/SNAP");
else off += sprintf(buf+off,"None");
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
if (try_atm_clip_ops()) {
if (vcc->push == atm_clip_ops->clip_push) {
struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
struct net_device *dev;
dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL;
off += sprintf(buf+off,"CLIP, Itf:%s, Encap:",
dev ? dev->name : "none?");
if (clip_vcc->encap)
off += sprintf(buf+off,"LLC/SNAP");
else
off += sprintf(buf+off,"None");
}
module_put(atm_clip_ops->owner);
}
#endif
strcpy(buf+off,"\n");
......@@ -409,7 +413,7 @@ static int atm_svc_info(loff_t pos,char *buf)
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;
......@@ -419,28 +423,33 @@ static int atm_arp_info(loff_t pos,char *buf)
return sprintf(buf,"IPitf TypeEncp Idle IP address "
"ATM address\n");
}
if (!try_atm_clip_ops())
return 0;
count = pos;
read_lock_bh(&clip_tbl.lock);
read_lock_bh(&clip_tbl_hook->lock);
for (i = 0; i <= NEIGH_HASHMASK; i++)
for (n = clip_tbl.hash_buckets[i]; n; n = n->next) {
for (n = clip_tbl_hook->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(&clip_tbl_hook->lock);
module_put(atm_clip_ops->owner);
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(&clip_tbl_hook->lock);
module_put(atm_clip_ops->owner);
return strlen(buf);
}
}
read_unlock_bh(&clip_tbl.lock);
read_unlock_bh(&clip_tbl_hook->lock);
module_put(atm_clip_ops->owner);
return 0;
}
#endif
......@@ -612,7 +621,7 @@ int __init atm_proc_init(void)
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)
......
......@@ -7,16 +7,12 @@
#include <linux/net.h> /* struct socket, struct proto_ops */
#include <linux/atm.h> /* ATM stuff */
#include <linux/atmdev.h> /* ATM devices */
#include <linux/atmclip.h> /* Classical IP over ATM */
#include <linux/errno.h> /* error codes */
#include <linux/kernel.h> /* printk */
#include <linux/init.h>
#include <linux/skbuff.h>
#include <linux/bitops.h>
#include <net/sock.h> /* for sock_no_* */
#ifdef CONFIG_ATM_CLIP
#include <net/atmclip.h>
#endif
#include "resources.h" /* devs and vccs */
#include "common.h" /* common for PVCs and SVCs */
......@@ -129,9 +125,6 @@ static int __init atmpvc_init(void)
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);
......
......@@ -108,8 +108,9 @@
#include <net/netrom.h>
#endif
#endif
#ifdef CONFIG_ATM_CLIP
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
#include <net/atmclip.h>
struct neigh_table *clip_tbl_hook;
#endif
#include <asm/system.h>
......@@ -443,8 +444,8 @@ int arp_bind_neighbour(struct dst_entry *dst)
if (dev->flags&(IFF_LOOPBACK|IFF_POINTOPOINT))
nexthop = 0;
n = __neigh_lookup_errno(
#ifdef CONFIG_ATM_CLIP
dev->type == ARPHRD_ATM ? &clip_tbl :
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
dev->type == ARPHRD_ATM ? clip_tbl_hook :
#endif
&arp_tbl, &nexthop, dev);
if (IS_ERR(n))
......
......@@ -45,6 +45,9 @@ extern __u32 sysctl_rmem_max;
#include <linux/ip.h>
#include <net/protocol.h>
#include <net/arp.h>
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
#include <net/atmclip.h>
#endif
#include <net/ip.h>
#include <net/udp.h>
#include <net/tcp.h>
......@@ -526,6 +529,9 @@ EXPORT_SYMBOL(xrlim_allow);
EXPORT_SYMBOL(ip_rcv);
EXPORT_SYMBOL(arp_rcv);
EXPORT_SYMBOL(arp_tbl);
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
EXPORT_SYMBOL(clip_tbl_hook);
#endif
EXPORT_SYMBOL(arp_find);
#endif /* CONFIG_INET */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment