[PATCH] cryptoloop
[linux-2.6/history.git] / net / atm / clip.c
blob7b3514fee6d90d90ad01b2d9748e350c23f8946a
1 /* net/atm/clip.c - RFC1577 Classical IP over ATM */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
6 #include <linux/config.h>
7 #include <linux/string.h>
8 #include <linux/errno.h>
9 #include <linux/kernel.h> /* for UINT_MAX */
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/netdevice.h>
13 #include <linux/skbuff.h>
14 #include <linux/wait.h>
15 #include <linux/timer.h>
16 #include <linux/if_arp.h> /* for some manifest constants */
17 #include <linux/notifier.h>
18 #include <linux/atm.h>
19 #include <linux/atmdev.h>
20 #include <linux/atmclip.h>
21 #include <linux/atmarp.h>
22 #include <linux/ip.h> /* for net/route.h */
23 #include <linux/in.h> /* for struct sockaddr_in */
24 #include <linux/if.h> /* for IFF_UP */
25 #include <linux/inetdevice.h>
26 #include <linux/bitops.h>
27 #include <net/route.h> /* for struct rtable and routing */
28 #include <net/icmp.h> /* icmp_send */
29 #include <asm/param.h> /* for HZ */
30 #include <asm/byteorder.h> /* for htons etc. */
31 #include <asm/system.h> /* save/restore_flags */
32 #include <asm/uaccess.h>
33 #include <asm/atomic.h>
35 #include "common.h"
36 #include "resources.h"
37 #include "ipcommon.h"
38 #include <net/atmclip.h>
41 #if 0
42 #define DPRINTK(format,args...) printk(format,##args)
43 #else
44 #define DPRINTK(format,args...)
45 #endif
48 struct net_device *clip_devs = NULL;
49 struct atm_vcc *atmarpd = NULL;
50 static struct neigh_table clip_tbl;
51 static struct timer_list idle_timer;
52 static int start_timer = 1;
55 static int to_atmarpd(enum atmarp_ctrl_type type,int itf,unsigned long ip)
57 struct atmarp_ctrl *ctrl;
58 struct sk_buff *skb;
60 DPRINTK("to_atmarpd(%d)\n",type);
61 if (!atmarpd) return -EUNATCH;
62 skb = alloc_skb(sizeof(struct atmarp_ctrl),GFP_ATOMIC);
63 if (!skb) return -ENOMEM;
64 ctrl = (struct atmarp_ctrl *) skb_put(skb,sizeof(struct atmarp_ctrl));
65 ctrl->type = type;
66 ctrl->itf_num = itf;
67 ctrl->ip = ip;
68 atm_force_charge(atmarpd,skb->truesize);
69 skb_queue_tail(&atmarpd->sk->sk_receive_queue, skb);
70 wake_up(&atmarpd->sleep);
71 return 0;
75 static void link_vcc(struct clip_vcc *clip_vcc,struct atmarp_entry *entry)
77 DPRINTK("link_vcc %p to entry %p (neigh %p)\n",clip_vcc,entry,
78 entry->neigh);
79 clip_vcc->entry = entry;
80 clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
81 clip_vcc->next = entry->vccs;
82 entry->vccs = clip_vcc;
83 entry->neigh->used = jiffies;
87 static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
89 struct atmarp_entry *entry = clip_vcc->entry;
90 struct clip_vcc **walk;
92 if (!entry) {
93 printk(KERN_CRIT "!clip_vcc->entry (clip_vcc %p)\n",clip_vcc);
94 return;
96 entry->neigh->used = jiffies;
97 for (walk = &entry->vccs; *walk; walk = &(*walk)->next)
98 if (*walk == clip_vcc) {
99 int error;
101 *walk = clip_vcc->next; /* atomic */
102 clip_vcc->entry = NULL;
103 if (clip_vcc->xoff)
104 netif_wake_queue(entry->neigh->dev);
105 if (entry->vccs) return;
106 entry->expires = jiffies-1;
107 /* force resolution or expiration */
108 error = neigh_update(entry->neigh,NULL,NUD_NONE,0,0);
109 if (error)
110 printk(KERN_CRIT "unlink_clip_vcc: "
111 "neigh_update failed with %d\n",error);
112 return;
114 printk(KERN_CRIT "ATMARP: unlink_clip_vcc failed (entry %p, vcc "
115 "0x%p)\n",entry,clip_vcc);
119 static void idle_timer_check(unsigned long dummy)
121 int i;
123 /*DPRINTK("idle_timer_check\n");*/
124 write_lock(&clip_tbl.lock);
125 for (i = 0; i <= NEIGH_HASHMASK; i++) {
126 struct neighbour **np;
128 for (np = &clip_tbl.hash_buckets[i]; *np;) {
129 struct neighbour *n = *np;
130 struct atmarp_entry *entry = NEIGH2ENTRY(n);
131 struct clip_vcc *clip_vcc;
133 write_lock(&n->lock);
135 for (clip_vcc = entry->vccs; clip_vcc;
136 clip_vcc = clip_vcc->next)
137 if (clip_vcc->idle_timeout &&
138 time_after(jiffies, clip_vcc->last_use+
139 clip_vcc->idle_timeout)) {
140 DPRINTK("releasing vcc %p->%p of "
141 "entry %p\n",clip_vcc,clip_vcc->vcc,
142 entry);
143 vcc_release_async(clip_vcc->vcc,
144 -ETIMEDOUT);
146 if (entry->vccs ||
147 time_before(jiffies, entry->expires)) {
148 np = &n->next;
149 write_unlock(&n->lock);
150 continue;
152 if (atomic_read(&n->refcnt) > 1) {
153 struct sk_buff *skb;
155 DPRINTK("destruction postponed with ref %d\n",
156 atomic_read(&n->refcnt));
157 while ((skb = skb_dequeue(&n->arp_queue)) !=
158 NULL)
159 dev_kfree_skb(skb);
160 np = &n->next;
161 write_unlock(&n->lock);
162 continue;
164 *np = n->next;
165 DPRINTK("expired neigh %p\n",n);
166 n->dead = 1;
167 write_unlock(&n->lock);
168 neigh_release(n);
171 mod_timer(&idle_timer, jiffies+CLIP_CHECK_INTERVAL*HZ);
172 write_unlock(&clip_tbl.lock);
176 static int clip_arp_rcv(struct sk_buff *skb)
178 struct atm_vcc *vcc;
180 DPRINTK("clip_arp_rcv\n");
181 vcc = ATM_SKB(skb)->vcc;
182 if (!vcc || !atm_charge(vcc,skb->truesize)) {
183 dev_kfree_skb_any(skb);
184 return 0;
186 DPRINTK("pushing to %p\n",vcc);
187 DPRINTK("using %p\n",CLIP_VCC(vcc)->old_push);
188 CLIP_VCC(vcc)->old_push(vcc,skb);
189 return 0;
193 static void clip_push(struct atm_vcc *vcc,struct sk_buff *skb)
195 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
197 DPRINTK("clip push\n");
198 if (!skb) {
199 DPRINTK("removing VCC %p\n",clip_vcc);
200 if (clip_vcc->entry) unlink_clip_vcc(clip_vcc);
201 clip_vcc->old_push(vcc,NULL); /* pass on the bad news */
202 kfree(clip_vcc);
203 return;
205 atm_return(vcc,skb->truesize);
206 skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs;
207 /* clip_vcc->entry == NULL if we don't have an IP address yet */
208 if (!skb->dev) {
209 dev_kfree_skb_any(skb);
210 return;
212 ATM_SKB(skb)->vcc = vcc;
213 skb->mac.raw = skb->data;
214 if (!clip_vcc->encap || skb->len < RFC1483LLC_LEN || memcmp(skb->data,
215 llc_oui,sizeof(llc_oui))) skb->protocol = htons(ETH_P_IP);
216 else {
217 skb->protocol = ((u16 *) skb->data)[3];
218 skb_pull(skb,RFC1483LLC_LEN);
219 if (skb->protocol == htons(ETH_P_ARP)) {
220 PRIV(skb->dev)->stats.rx_packets++;
221 PRIV(skb->dev)->stats.rx_bytes += skb->len;
222 clip_arp_rcv(skb);
223 return;
226 clip_vcc->last_use = jiffies;
227 PRIV(skb->dev)->stats.rx_packets++;
228 PRIV(skb->dev)->stats.rx_bytes += skb->len;
229 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
230 netif_rx(skb);
235 * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
236 * clip_pop is atomic with respect to the critical section in clip_start_xmit.
240 static void clip_pop(struct atm_vcc *vcc,struct sk_buff *skb)
242 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
243 struct net_device *dev = skb->dev;
244 int old;
245 unsigned long flags;
247 DPRINTK("clip_pop(vcc %p)\n",vcc);
248 clip_vcc->old_pop(vcc,skb);
249 /* skb->dev == NULL in outbound ARP packets */
250 if (!dev) return;
251 spin_lock_irqsave(&PRIV(dev)->xoff_lock,flags);
252 if (atm_may_send(vcc,0)) {
253 old = xchg(&clip_vcc->xoff,0);
254 if (old) netif_wake_queue(dev);
256 spin_unlock_irqrestore(&PRIV(dev)->xoff_lock,flags);
260 static void clip_neigh_destroy(struct neighbour *neigh)
262 DPRINTK("clip_neigh_destroy (neigh %p)\n",neigh);
263 if (NEIGH2ENTRY(neigh)->vccs)
264 printk(KERN_CRIT "clip_neigh_destroy: vccs != NULL !!!\n");
265 NEIGH2ENTRY(neigh)->vccs = (void *) 0xdeadbeef;
269 static void clip_neigh_solicit(struct neighbour *neigh,struct sk_buff *skb)
271 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n",neigh,skb);
272 to_atmarpd(act_need,PRIV(neigh->dev)->number,NEIGH2ENTRY(neigh)->ip);
276 static void clip_neigh_error(struct neighbour *neigh,struct sk_buff *skb)
278 #ifndef CONFIG_ATM_CLIP_NO_ICMP
279 icmp_send(skb,ICMP_DEST_UNREACH,ICMP_HOST_UNREACH,0);
280 #endif
281 kfree_skb(skb);
285 static struct neigh_ops clip_neigh_ops = {
286 .family = AF_INET,
287 .destructor = clip_neigh_destroy,
288 .solicit = clip_neigh_solicit,
289 .error_report = clip_neigh_error,
290 .output = dev_queue_xmit,
291 .connected_output = dev_queue_xmit,
292 .hh_output = dev_queue_xmit,
293 .queue_xmit = dev_queue_xmit,
297 static int clip_constructor(struct neighbour *neigh)
299 struct atmarp_entry *entry = NEIGH2ENTRY(neigh);
300 struct net_device *dev = neigh->dev;
301 struct in_device *in_dev = dev->ip_ptr;
303 DPRINTK("clip_constructor (neigh %p, entry %p)\n",neigh,entry);
304 if (!in_dev) return -EINVAL;
305 neigh->type = inet_addr_type(entry->ip);
306 if (neigh->type != RTN_UNICAST) return -EINVAL;
307 if (in_dev->arp_parms) neigh->parms = in_dev->arp_parms;
308 neigh->ops = &clip_neigh_ops;
309 neigh->output = neigh->nud_state & NUD_VALID ?
310 neigh->ops->connected_output : neigh->ops->output;
311 entry->neigh = neigh;
312 entry->vccs = NULL;
313 entry->expires = jiffies-1;
314 return 0;
317 static u32 clip_hash(const void *pkey, const struct net_device *dev)
319 u32 hash_val;
321 hash_val = *(u32*)pkey;
322 hash_val ^= (hash_val>>16);
323 hash_val ^= hash_val>>8;
324 hash_val ^= hash_val>>3;
325 hash_val = (hash_val^dev->ifindex)&NEIGH_HASHMASK;
327 return hash_val;
330 static struct neigh_table clip_tbl = {
331 .family = AF_INET,
332 .entry_size = sizeof(struct neighbour)+sizeof(struct atmarp_entry),
333 .key_len = 4,
334 .hash = clip_hash,
335 .constructor = clip_constructor,
336 .id = "clip_arp_cache",
338 /* parameters are copied from ARP ... */
339 .parms = {
340 .tbl = &clip_tbl,
341 .base_reachable_time = 30 * HZ,
342 .retrans_time = 1 * HZ,
343 .gc_staletime = 60 * HZ,
344 .reachable_time = 30 * HZ,
345 .delay_probe_time = 5 * HZ,
346 .queue_len = 3,
347 .ucast_probes = 3,
348 .mcast_probes = 3,
349 .anycast_delay = 1 * HZ,
350 .proxy_delay = (8 * HZ) / 10,
351 .proxy_qlen = 64,
352 .locktime = 1 * HZ,
354 .gc_interval = 30 * HZ,
355 .gc_thresh1 = 128,
356 .gc_thresh2 = 512,
357 .gc_thresh3 = 1024,
361 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
364 * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
365 * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
366 * don't increment the usage count. This is used to create entries in
367 * clip_setentry.
371 static int clip_encap(struct atm_vcc *vcc,int mode)
373 CLIP_VCC(vcc)->encap = mode;
374 return 0;
378 static int clip_start_xmit(struct sk_buff *skb,struct net_device *dev)
380 struct clip_priv *clip_priv = PRIV(dev);
381 struct atmarp_entry *entry;
382 struct atm_vcc *vcc;
383 int old;
384 unsigned long flags;
386 DPRINTK("clip_start_xmit (skb %p)\n",skb);
387 if (!skb->dst) {
388 printk(KERN_ERR "clip_start_xmit: skb->dst == NULL\n");
389 dev_kfree_skb(skb);
390 clip_priv->stats.tx_dropped++;
391 return 0;
393 if (!skb->dst->neighbour) {
394 #if 0
395 skb->dst->neighbour = clip_find_neighbour(skb->dst,1);
396 if (!skb->dst->neighbour) {
397 dev_kfree_skb(skb); /* lost that one */
398 clip_priv->stats.tx_dropped++;
399 return 0;
401 #endif
402 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n");
403 dev_kfree_skb(skb);
404 clip_priv->stats.tx_dropped++;
405 return 0;
407 entry = NEIGH2ENTRY(skb->dst->neighbour);
408 if (!entry->vccs) {
409 if (time_after(jiffies, entry->expires)) {
410 /* should be resolved */
411 entry->expires = jiffies+ATMARP_RETRY_DELAY*HZ;
412 to_atmarpd(act_need,PRIV(dev)->number,entry->ip);
414 if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS)
415 skb_queue_tail(&entry->neigh->arp_queue,skb);
416 else {
417 dev_kfree_skb(skb);
418 clip_priv->stats.tx_dropped++;
420 return 0;
422 DPRINTK("neigh %p, vccs %p\n",entry,entry->vccs);
423 ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
424 DPRINTK("using neighbour %p, vcc %p\n",skb->dst->neighbour,vcc);
425 if (entry->vccs->encap) {
426 void *here;
428 here = skb_push(skb,RFC1483LLC_LEN);
429 memcpy(here,llc_oui,sizeof(llc_oui));
430 ((u16 *) here)[3] = skb->protocol;
432 atomic_add(skb->truesize, &vcc->sk->sk_wmem_alloc);
433 ATM_SKB(skb)->atm_options = vcc->atm_options;
434 entry->vccs->last_use = jiffies;
435 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n",skb,vcc,vcc->dev);
436 old = xchg(&entry->vccs->xoff,1); /* assume XOFF ... */
437 if (old) {
438 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n");
439 return 0;
441 clip_priv->stats.tx_packets++;
442 clip_priv->stats.tx_bytes += skb->len;
443 (void) vcc->send(vcc,skb);
444 if (atm_may_send(vcc,0)) {
445 entry->vccs->xoff = 0;
446 return 0;
448 spin_lock_irqsave(&clip_priv->xoff_lock,flags);
449 netif_stop_queue(dev); /* XOFF -> throttle immediately */
450 barrier();
451 if (!entry->vccs->xoff)
452 netif_start_queue(dev);
453 /* Oh, we just raced with clip_pop. netif_start_queue should be
454 good enough, because nothing should really be asleep because
455 of the brief netif_stop_queue. If this isn't true or if it
456 changes, use netif_wake_queue instead. */
457 spin_unlock_irqrestore(&clip_priv->xoff_lock,flags);
458 return 0;
462 static struct net_device_stats *clip_get_stats(struct net_device *dev)
464 return &PRIV(dev)->stats;
468 static int clip_mkip(struct atm_vcc *vcc,int timeout)
470 struct clip_vcc *clip_vcc;
471 struct sk_buff_head copy;
472 struct sk_buff *skb;
474 if (!vcc->push) return -EBADFD;
475 clip_vcc = kmalloc(sizeof(struct clip_vcc),GFP_KERNEL);
476 if (!clip_vcc) return -ENOMEM;
477 DPRINTK("mkip clip_vcc %p vcc %p\n",clip_vcc,vcc);
478 clip_vcc->vcc = vcc;
479 vcc->user_back = clip_vcc;
480 clip_vcc->entry = NULL;
481 clip_vcc->xoff = 0;
482 clip_vcc->encap = 1;
483 clip_vcc->last_use = jiffies;
484 clip_vcc->idle_timeout = timeout*HZ;
485 clip_vcc->old_push = vcc->push;
486 clip_vcc->old_pop = vcc->pop;
487 vcc->push = clip_push;
488 vcc->pop = clip_pop;
489 skb_queue_head_init(&copy);
490 skb_migrate(&vcc->sk->sk_receive_queue, &copy);
491 /* re-process everything received between connection setup and MKIP */
492 while ((skb = skb_dequeue(&copy)))
493 if (!clip_devs) {
494 atm_return(vcc,skb->truesize);
495 kfree_skb(skb);
497 else {
498 unsigned int len = skb->len;
500 clip_push(vcc,skb);
501 PRIV(skb->dev)->stats.rx_packets--;
502 PRIV(skb->dev)->stats.rx_bytes -= len;
504 return 0;
508 static int clip_setentry(struct atm_vcc *vcc,u32 ip)
510 struct neighbour *neigh;
511 struct atmarp_entry *entry;
512 int error;
513 struct clip_vcc *clip_vcc;
514 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = ip, .tos = 1 } } };
515 struct rtable *rt;
517 if (vcc->push != clip_push) {
518 printk(KERN_WARNING "clip_setentry: non-CLIP VCC\n");
519 return -EBADF;
521 clip_vcc = CLIP_VCC(vcc);
522 if (!ip) {
523 if (!clip_vcc->entry) {
524 printk(KERN_ERR "hiding hidden ATMARP entry\n");
525 return 0;
527 DPRINTK("setentry: remove\n");
528 unlink_clip_vcc(clip_vcc);
529 return 0;
531 error = ip_route_output_key(&rt,&fl);
532 if (error) return error;
533 neigh = __neigh_lookup(&clip_tbl,&ip,rt->u.dst.dev,1);
534 ip_rt_put(rt);
535 if (!neigh)
536 return -ENOMEM;
537 entry = NEIGH2ENTRY(neigh);
538 if (entry != clip_vcc->entry) {
539 if (!clip_vcc->entry) DPRINTK("setentry: add\n");
540 else {
541 DPRINTK("setentry: update\n");
542 unlink_clip_vcc(clip_vcc);
544 link_vcc(clip_vcc,entry);
546 error = neigh_update(neigh,llc_oui,NUD_PERMANENT,1,0);
547 neigh_release(neigh);
548 return error;
552 static int clip_init(struct net_device *dev)
554 DPRINTK("clip_init %s\n",dev->name);
555 dev->hard_start_xmit = clip_start_xmit;
556 /* sg_xmit ... */
557 dev->hard_header = NULL;
558 dev->rebuild_header = NULL;
559 dev->set_mac_address = NULL;
560 dev->hard_header_parse = NULL;
561 dev->hard_header_cache = NULL;
562 dev->header_cache_update = NULL;
563 dev->change_mtu = NULL;
564 dev->do_ioctl = NULL;
565 dev->get_stats = clip_get_stats;
566 dev->type = ARPHRD_ATM;
567 dev->hard_header_len = RFC1483LLC_LEN;
568 dev->mtu = RFC1626_MTU;
569 dev->addr_len = 0;
570 dev->tx_queue_len = 100; /* "normal" queue (packets) */
571 /* When using a "real" qdisc, the qdisc determines the queue */
572 /* length. tx_queue_len is only used for the default case, */
573 /* without any more elaborate queuing. 100 is a reasonable */
574 /* compromise between decent burst-tolerance and protection */
575 /* against memory hogs. */
576 dev->flags = 0;
577 return 0;
581 static int clip_create(int number)
583 struct net_device *dev;
584 struct clip_priv *clip_priv;
585 int error;
587 if (number != -1) {
588 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
589 if (PRIV(dev)->number == number) return -EEXIST;
591 else {
592 number = 0;
593 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
594 if (PRIV(dev)->number >= number)
595 number = PRIV(dev)->number+1;
597 dev = kmalloc(sizeof(struct net_device)+sizeof(struct clip_priv),
598 GFP_KERNEL);
599 if (!dev) return -ENOMEM;
600 memset(dev,0,sizeof(struct net_device)+sizeof(struct clip_priv));
601 clip_priv = PRIV(dev);
602 sprintf(dev->name,"atm%d",number);
603 dev->init = clip_init;
604 spin_lock_init(&clip_priv->xoff_lock);
605 clip_priv->number = number;
606 error = register_netdev(dev);
607 if (error) {
608 kfree(dev);
609 return error;
611 clip_priv->next = clip_devs;
612 clip_devs = dev;
613 DPRINTK("registered (net:%s)\n",dev->name);
614 return number;
618 static int clip_device_event(struct notifier_block *this,unsigned long event,
619 void *dev)
621 /* ignore non-CLIP devices */
622 if (((struct net_device *) dev)->type != ARPHRD_ATM ||
623 ((struct net_device *) dev)->init != clip_init)
624 return NOTIFY_DONE;
625 switch (event) {
626 case NETDEV_UP:
627 DPRINTK("clip_device_event NETDEV_UP\n");
628 (void) to_atmarpd(act_up,PRIV(dev)->number,0);
629 break;
630 case NETDEV_GOING_DOWN:
631 DPRINTK("clip_device_event NETDEV_DOWN\n");
632 (void) to_atmarpd(act_down,PRIV(dev)->number,0);
633 break;
634 case NETDEV_CHANGE:
635 case NETDEV_CHANGEMTU:
636 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
637 (void) to_atmarpd(act_change,PRIV(dev)->number,0);
638 break;
639 case NETDEV_REBOOT:
640 case NETDEV_REGISTER:
641 case NETDEV_DOWN:
642 DPRINTK("clip_device_event %ld\n",event);
643 /* ignore */
644 break;
645 default:
646 printk(KERN_WARNING "clip_device_event: unknown event "
647 "%ld\n",event);
648 break;
650 return NOTIFY_DONE;
654 static int clip_inet_event(struct notifier_block *this,unsigned long event,
655 void *ifa)
657 struct in_device *in_dev;
659 in_dev = ((struct in_ifaddr *) ifa)->ifa_dev;
660 if (!in_dev || !in_dev->dev) {
661 printk(KERN_WARNING "clip_inet_event: no device\n");
662 return NOTIFY_DONE;
665 * Transitions are of the down-change-up type, so it's sufficient to
666 * handle the change on up.
668 if (event != NETDEV_UP) return NOTIFY_DONE;
669 return clip_device_event(this,NETDEV_CHANGE,in_dev->dev);
673 static struct notifier_block clip_dev_notifier = {
674 clip_device_event,
675 NULL,
681 static struct notifier_block clip_inet_notifier = {
682 clip_inet_event,
683 NULL,
689 static void atmarpd_close(struct atm_vcc *vcc)
691 DPRINTK("atmarpd_close\n");
692 atmarpd = NULL; /* assumed to be atomic */
693 barrier();
694 unregister_inetaddr_notifier(&clip_inet_notifier);
695 unregister_netdevice_notifier(&clip_dev_notifier);
696 if (skb_peek(&vcc->sk->sk_receive_queue))
697 printk(KERN_ERR "atmarpd_close: closing with requests "
698 "pending\n");
699 skb_queue_purge(&vcc->sk->sk_receive_queue);
700 DPRINTK("(done)\n");
701 module_put(THIS_MODULE);
705 static struct atmdev_ops atmarpd_dev_ops = {
706 .close = atmarpd_close
710 static struct atm_dev atmarpd_dev = {
711 .ops = &atmarpd_dev_ops,
712 .type = "arpd",
713 .number = 999,
714 .lock = SPIN_LOCK_UNLOCKED
718 static int atm_init_atmarp(struct atm_vcc *vcc)
720 struct net_device *dev;
722 if (atmarpd) return -EADDRINUSE;
723 if (start_timer) {
724 start_timer = 0;
725 init_timer(&idle_timer);
726 idle_timer.expires = jiffies+CLIP_CHECK_INTERVAL*HZ;
727 idle_timer.function = idle_timer_check;
728 add_timer(&idle_timer);
730 atmarpd = vcc;
731 set_bit(ATM_VF_META,&vcc->flags);
732 set_bit(ATM_VF_READY,&vcc->flags);
733 /* allow replies and avoid getting closed if signaling dies */
734 vcc->dev = &atmarpd_dev;
735 vcc_insert_socket(vcc->sk);
736 vcc->push = NULL;
737 vcc->pop = NULL; /* crash */
738 vcc->push_oam = NULL; /* crash */
739 if (register_netdevice_notifier(&clip_dev_notifier))
740 printk(KERN_ERR "register_netdevice_notifier failed\n");
741 if (register_inetaddr_notifier(&clip_inet_notifier))
742 printk(KERN_ERR "register_inetaddr_notifier failed\n");
743 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
744 if (dev->flags & IFF_UP)
745 (void) to_atmarpd(act_up,PRIV(dev)->number,0);
746 return 0;
749 static struct atm_clip_ops __atm_clip_ops = {
750 .clip_create = clip_create,
751 .clip_mkip = clip_mkip,
752 .clip_setentry = clip_setentry,
753 .clip_encap = clip_encap,
754 .clip_push = clip_push,
755 .atm_init_atmarp = atm_init_atmarp,
756 .owner = THIS_MODULE
759 static int __init atm_clip_init(void)
761 /* we should use neigh_table_init() */
762 clip_tbl.lock = RW_LOCK_UNLOCKED;
763 clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
764 clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
766 /* so neigh_ifdown() doesn't complain */
767 clip_tbl.proxy_timer.data = 0;
768 clip_tbl.proxy_timer.function = 0;
769 init_timer(&clip_tbl.proxy_timer);
770 skb_queue_head_init(&clip_tbl.proxy_queue);
772 clip_tbl_hook = &clip_tbl;
773 atm_clip_ops_set(&__atm_clip_ops);
775 return 0;
778 static void __exit atm_clip_exit(void)
780 struct net_device *dev, *next;
782 atm_clip_ops_set(NULL);
784 neigh_ifdown(&clip_tbl, NULL);
785 dev = clip_devs;
786 while (dev) {
787 next = PRIV(dev)->next;
788 unregister_netdev(dev);
789 kfree(dev);
790 dev = next;
792 if (start_timer == 0) del_timer(&idle_timer);
794 kmem_cache_destroy(clip_tbl.kmem_cachep);
796 clip_tbl_hook = NULL;
799 module_init(atm_clip_init);
800 module_exit(atm_clip_exit);
802 MODULE_LICENSE("GPL");