~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/net/atm/clip.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* net/atm/clip.c - RFC1577 Classical IP over ATM */
  2 
  3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  4 
  5 
  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/netdevice.h>
 11 #include <linux/skbuff.h>
 12 #include <linux/wait.h>
 13 #include <linux/timer.h>
 14 #include <linux/if_arp.h> /* for some manifest constants */
 15 #include <linux/notifier.h>
 16 #include <linux/atm.h>
 17 #include <linux/atmdev.h>
 18 #include <linux/atmclip.h>
 19 #include <linux/atmarp.h>
 20 #include <linux/ip.h> /* for net/route.h */
 21 #include <linux/in.h> /* for struct sockaddr_in */
 22 #include <linux/if.h> /* for IFF_UP */
 23 #include <linux/inetdevice.h>
 24 #include <linux/bitops.h>
 25 #include <net/route.h> /* for struct rtable and routing */
 26 #include <net/icmp.h> /* icmp_send */
 27 #include <asm/param.h> /* for HZ */
 28 #include <asm/byteorder.h> /* for htons etc. */
 29 #include <asm/system.h> /* save/restore_flags */
 30 #include <asm/uaccess.h>
 31 #include <asm/atomic.h>
 32 
 33 #include "common.h"
 34 #include "resources.h"
 35 #include "ipcommon.h"
 36 #include <net/atmclip.h>
 37 
 38 
 39 #if 0
 40 #define DPRINTK(format,args...) printk(format,##args)
 41 #else
 42 #define DPRINTK(format,args...)
 43 #endif
 44 
 45 
 46 struct net_device *clip_devs = NULL;
 47 struct atm_vcc *atmarpd = NULL;
 48 static struct timer_list idle_timer;
 49 static int start_timer = 1;
 50 
 51 
 52 static int to_atmarpd(enum atmarp_ctrl_type type,int itf,unsigned long ip)
 53 {
 54         struct atmarp_ctrl *ctrl;
 55         struct sk_buff *skb;
 56 
 57         DPRINTK("to_atmarpd(%d)\n",type);
 58         if (!atmarpd) return -EUNATCH;
 59         skb = alloc_skb(sizeof(struct atmarp_ctrl),GFP_ATOMIC);
 60         if (!skb) return -ENOMEM;
 61         ctrl = (struct atmarp_ctrl *) skb_put(skb,sizeof(struct atmarp_ctrl));
 62         ctrl->type = type;
 63         ctrl->itf_num = itf;
 64         ctrl->ip = ip;
 65         atm_force_charge(atmarpd,skb->truesize);
 66         skb_queue_tail(&atmarpd->recvq,skb);
 67         wake_up(&atmarpd->sleep);
 68         return 0;
 69 }
 70 
 71 
 72 static void link_vcc(struct clip_vcc *clip_vcc,struct atmarp_entry *entry)
 73 {
 74         DPRINTK("link_vcc %p to entry %p (neigh %p)\n",clip_vcc,entry,
 75             entry->neigh);
 76         clip_vcc->entry = entry;
 77         clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
 78         clip_vcc->next = entry->vccs;
 79         entry->vccs = clip_vcc;
 80         entry->neigh->used = jiffies;
 81 }
 82 
 83 
 84 static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
 85 {
 86         struct atmarp_entry *entry = clip_vcc->entry;
 87         struct clip_vcc **walk;
 88 
 89         if (!entry) {
 90                 printk(KERN_CRIT "!clip_vcc->entry (clip_vcc %p)\n",clip_vcc);
 91                 return;
 92         }
 93         entry->neigh->used = jiffies;
 94         for (walk = &entry->vccs; *walk; walk = &(*walk)->next)
 95                 if (*walk == clip_vcc) {
 96                         int error;
 97 
 98                         *walk = clip_vcc->next; /* atomic */
 99                         clip_vcc->entry = NULL;
100                         if (clip_vcc->xoff)
101                                 netif_wake_queue(entry->neigh->dev);
102                         if (entry->vccs) return;
103                         entry->expires = jiffies-1;
104                                 /* force resolution or expiration */
105                         error = neigh_update(entry->neigh,NULL,NUD_NONE,0,0);
106                         if (error)
107                                 printk(KERN_CRIT "unlink_clip_vcc: "
108                                     "neigh_update failed with %d\n",error);
109                         return;
110                 }
111         printk(KERN_CRIT "ATMARP: unlink_clip_vcc failed (entry %p, vcc "
112           "0x%p)\n",entry,clip_vcc);
113 }
114 
115 
116 static void idle_timer_check(unsigned long dummy)
117 {
118         int i;
119 
120         /*DPRINTK("idle_timer_check\n");*/
121         write_lock(&clip_tbl.lock);
122         for (i = 0; i <= NEIGH_HASHMASK; i++) {
123                 struct neighbour **np;
124 
125                 for (np = &clip_tbl.hash_buckets[i]; *np;) {
126                         struct neighbour *n = *np;
127                         struct atmarp_entry *entry = NEIGH2ENTRY(n);
128                         struct clip_vcc *clip_vcc;
129 
130                         for (clip_vcc = entry->vccs; clip_vcc;
131                             clip_vcc = clip_vcc->next)
132                                 if (clip_vcc->idle_timeout &&
133                                     time_after(jiffies, clip_vcc->last_use+
134                                     clip_vcc->idle_timeout)) {
135                                         DPRINTK("releasing vcc %p->%p of "
136                                             "entry %p\n",clip_vcc,clip_vcc->vcc,
137                                             entry);
138                                         atm_async_release_vcc(clip_vcc->vcc,
139                                             -ETIMEDOUT);
140                                 }
141                         if (entry->vccs ||
142                             time_before(jiffies, entry->expires)) {
143                                 np = &n->next;
144                                 continue;
145                         }
146                         if (atomic_read(&n->refcnt) > 1) {
147                                 struct sk_buff *skb;
148 
149                                 DPRINTK("destruction postponed with ref %d\n",
150                                     atomic_read(&n->refcnt));
151                                 while ((skb = skb_dequeue(&n->arp_queue)) !=
152                                      NULL) 
153                                         dev_kfree_skb(skb);
154                                 np = &n->next;
155                                 continue;
156                         }
157                         *np = n->next;
158                         DPRINTK("expired neigh %p\n",n);
159                         n->dead = 1;
160                         neigh_release(n);
161                 }
162         }
163         mod_timer(&idle_timer, jiffies+CLIP_CHECK_INTERVAL*HZ);
164         write_unlock(&clip_tbl.lock);
165 }
166 
167 
168 static int clip_arp_rcv(struct sk_buff *skb)
169 {
170         struct atm_vcc *vcc;
171 
172         DPRINTK("clip_arp_rcv\n");
173         vcc = ATM_SKB(skb)->vcc;
174         if (!vcc || !atm_charge(vcc,skb->truesize)) {
175                 dev_kfree_skb_any(skb);
176                 return 0;
177         }
178         DPRINTK("pushing to %p\n",vcc);
179         DPRINTK("using %p\n",CLIP_VCC(vcc)->old_push);
180         CLIP_VCC(vcc)->old_push(vcc,skb);
181         return 0;
182 }
183 
184 
185 void clip_push(struct atm_vcc *vcc,struct sk_buff *skb)
186 {
187         struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
188 
189         DPRINTK("clip push\n");
190         if (!skb) {
191                 DPRINTK("removing VCC %p\n",clip_vcc);
192                 if (clip_vcc->entry) unlink_clip_vcc(clip_vcc);
193                 clip_vcc->old_push(vcc,NULL); /* pass on the bad news */
194                 kfree(clip_vcc);
195                 return;
196         }
197         atm_return(vcc,skb->truesize);
198         skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs;
199                 /* clip_vcc->entry == NULL if we don't have an IP address yet */
200         if (!skb->dev) {
201                 dev_kfree_skb_any(skb);
202                 return;
203         }
204         ATM_SKB(skb)->vcc = vcc;
205         skb->mac.raw = skb->data;
206         if (!clip_vcc->encap || skb->len < RFC1483LLC_LEN || memcmp(skb->data,
207             llc_oui,sizeof(llc_oui))) skb->protocol = htons(ETH_P_IP);
208         else {
209                 skb->protocol = ((u16 *) skb->data)[3];
210                 skb_pull(skb,RFC1483LLC_LEN);
211                 if (skb->protocol == htons(ETH_P_ARP)) {
212                         PRIV(skb->dev)->stats.rx_packets++;
213                         PRIV(skb->dev)->stats.rx_bytes += skb->len;
214                         clip_arp_rcv(skb);
215                         return;
216                 }
217         }
218         clip_vcc->last_use = jiffies;
219         PRIV(skb->dev)->stats.rx_packets++;
220         PRIV(skb->dev)->stats.rx_bytes += skb->len;
221         netif_rx(skb);
222 }
223 
224 
225 /*
226  * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
227  * clip_pop is atomic with respect to the critical section in clip_start_xmit.
228  */
229 
230 
231 static void clip_pop(struct atm_vcc *vcc,struct sk_buff *skb)
232 {
233         struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
234         struct net_device *dev = skb->dev;
235         int old;
236         unsigned long flags;
237 
238         DPRINTK("clip_pop(vcc %p)\n",vcc);
239         clip_vcc->old_pop(vcc,skb);
240         /* skb->dev == NULL in outbound ARP packets */
241         if (!dev) return;
242         spin_lock_irqsave(&PRIV(dev)->xoff_lock,flags);
243         if (atm_may_send(vcc,0)) {
244                 old = xchg(&clip_vcc->xoff,0);
245                 if (old) netif_wake_queue(dev);
246         }
247         spin_unlock_irqrestore(&PRIV(dev)->xoff_lock,flags);
248 }
249 
250 
251 static void clip_neigh_destroy(struct neighbour *neigh)
252 {
253         DPRINTK("clip_neigh_destroy (neigh %p)\n",neigh);
254         if (NEIGH2ENTRY(neigh)->vccs)
255                 printk(KERN_CRIT "clip_neigh_destroy: vccs != NULL !!!\n");
256         NEIGH2ENTRY(neigh)->vccs = (void *) 0xdeadbeef;
257 }
258 
259 
260 static void clip_neigh_solicit(struct neighbour *neigh,struct sk_buff *skb)
261 {
262         DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n",neigh,skb);
263         to_atmarpd(act_need,PRIV(neigh->dev)->number,NEIGH2ENTRY(neigh)->ip);
264 }
265 
266 
267 static void clip_neigh_error(struct neighbour *neigh,struct sk_buff *skb)
268 {
269 #ifndef CONFIG_ATM_CLIP_NO_ICMP
270         icmp_send(skb,ICMP_DEST_UNREACH,ICMP_HOST_UNREACH,0);
271 #endif
272         kfree_skb(skb);
273 }
274 
275 
276 static struct neigh_ops clip_neigh_ops = {
277         family:                 AF_INET,
278         destructor:             clip_neigh_destroy,
279         solicit:                clip_neigh_solicit,
280         error_report:           clip_neigh_error,
281         output:                 dev_queue_xmit,
282         connected_output:       dev_queue_xmit,
283         hh_output:              dev_queue_xmit,
284         queue_xmit:             dev_queue_xmit,
285 };
286 
287 
288 static int clip_constructor(struct neighbour *neigh)
289 {
290         struct atmarp_entry *entry = NEIGH2ENTRY(neigh);
291         struct net_device *dev = neigh->dev;
292         struct in_device *in_dev = dev->ip_ptr;
293 
294         DPRINTK("clip_constructor (neigh %p, entry %p)\n",neigh,entry);
295         if (!in_dev) return -EINVAL;
296         neigh->type = inet_addr_type(entry->ip);
297         if (neigh->type != RTN_UNICAST) return -EINVAL;
298         if (in_dev->arp_parms) neigh->parms = in_dev->arp_parms;
299         neigh->ops = &clip_neigh_ops;
300         neigh->output = neigh->nud_state & NUD_VALID ?
301             neigh->ops->connected_output : neigh->ops->output;
302         entry->neigh = neigh;
303         entry->vccs = NULL;
304         entry->expires = jiffies-1;
305         return 0;
306 }
307 
308 static u32 clip_hash(const void *pkey, const struct net_device *dev)
309 {
310         u32 hash_val;
311 
312         hash_val = *(u32*)pkey;
313         hash_val ^= (hash_val>>16);
314         hash_val ^= hash_val>>8;
315         hash_val ^= hash_val>>3;
316         hash_val = (hash_val^dev->ifindex)&NEIGH_HASHMASK;
317 
318         return hash_val;
319 }
320 
321 
322 struct neigh_table clip_tbl = {
323         NULL,                   /* next */
324         AF_INET,                /* family */
325         sizeof(struct neighbour)+sizeof(struct atmarp_entry), /* entry_size */
326         4,                      /* key_len */
327         clip_hash,
328         clip_constructor,       /* constructor */
329         NULL,                   /* pconstructor */
330         NULL,                   /* pdestructor */
331         NULL,                   /* proxy_redo */
332         "clip_arp_cache",
333         {                       /* neigh_parms */
334                 NULL,           /* next */
335                 NULL,           /* neigh_setup */
336                 &clip_tbl,      /* tbl */
337                 0,              /* entries */
338                 NULL,           /* priv */
339                 NULL,           /* sysctl_table */
340                 30*HZ,          /* base_reachable_time */
341                 1*HZ,           /* retrans_time */
342                 60*HZ,          /* gc_staletime */
343                 30*HZ,          /* reachable_time */
344                 5*HZ,           /* delay_probe_time */
345                 3,              /* queue_len */
346                 3,              /* ucast_probes */
347                 0,              /* app_probes */
348                 3,              /* mcast_probes */
349                 1*HZ,           /* anycast_delay */
350                 (8*HZ)/10,      /* proxy_delay */
351                 1*HZ,           /* proxy_qlen */
352                 64              /* locktime */
353         },
354         30*HZ,128,512,1024      /* copied from ARP ... */
355 };
356 
357 
358 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
359 
360 /*
361  * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
362  * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
363  * don't increment the usage count. This is used to create entries in
364  * clip_setentry.
365  */
366 
367 
368 int clip_encap(struct atm_vcc *vcc,int mode)
369 {
370         CLIP_VCC(vcc)->encap = mode;
371         return 0;
372 }
373 
374 
375 static int clip_start_xmit(struct sk_buff *skb,struct net_device *dev)
376 {
377         struct clip_priv *clip_priv = PRIV(dev);
378         struct atmarp_entry *entry;
379         struct atm_vcc *vcc;
380         int old;
381         unsigned long flags;
382 
383         DPRINTK("clip_start_xmit (skb %p)\n",skb);
384         if (!skb->dst) {
385                 printk(KERN_ERR "clip_start_xmit: skb->dst == NULL\n");
386                 dev_kfree_skb(skb);
387                 clip_priv->stats.tx_dropped++;
388                 return 0;
389         }
390         if (!skb->dst->neighbour) {
391 #if 0
392                 skb->dst->neighbour = clip_find_neighbour(skb->dst,1);
393                 if (!skb->dst->neighbour) {
394                         dev_kfree_skb(skb); /* lost that one */
395                         clip_priv->stats.tx_dropped++;
396                         return 0;
397                 }
398 #endif
399                 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n");
400                 dev_kfree_skb(skb);
401                 clip_priv->stats.tx_dropped++;
402                 return 0;
403         }
404         entry = NEIGH2ENTRY(skb->dst->neighbour);
405         if (!entry->vccs) {
406                 if (time_after(jiffies, entry->expires)) {
407                         /* should be resolved */
408                         entry->expires = jiffies+ATMARP_RETRY_DELAY*HZ;
409                         to_atmarpd(act_need,PRIV(dev)->number,entry->ip);
410                 }
411                 if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS)
412                         skb_queue_tail(&entry->neigh->arp_queue,skb);
413                 else {
414                         dev_kfree_skb(skb);
415                         clip_priv->stats.tx_dropped++;
416                 }
417                 return 0;
418         }
419         DPRINTK("neigh %p, vccs %p\n",entry,entry->vccs);
420         ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
421         DPRINTK("using neighbour %p, vcc %p\n",skb->dst->neighbour,vcc);
422         if (entry->vccs->encap) {
423                 void *here;
424 
425                 here = skb_push(skb,RFC1483LLC_LEN);
426                 memcpy(here,llc_oui,sizeof(llc_oui));
427                 ((u16 *) here)[3] = skb->protocol;
428         }
429         atomic_add(skb->truesize,&vcc->tx_inuse);
430         ATM_SKB(skb)->iovcnt = 0;
431         ATM_SKB(skb)->atm_options = vcc->atm_options;
432         entry->vccs->last_use = jiffies;
433         DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n",skb,vcc,vcc->dev);
434         old = xchg(&entry->vccs->xoff,1); /* assume XOFF ... */
435         if (old) {
436                 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n");
437                 return 0;
438         }
439         clip_priv->stats.tx_packets++;
440         clip_priv->stats.tx_bytes += skb->len;
441         (void) vcc->send(vcc,skb);
442         if (atm_may_send(vcc,0)) {
443                 entry->vccs->xoff = 0;
444                 return 0;
445         }
446         spin_lock_irqsave(&clip_priv->xoff_lock,flags);
447         netif_stop_queue(dev); /* XOFF -> throttle immediately */
448         barrier();
449         if (!entry->vccs->xoff)
450                 netif_start_queue(dev);
451                 /* Oh, we just raced with clip_pop. netif_start_queue should be
452                    good enough, because nothing should really be asleep because
453                    of the brief netif_stop_queue. If this isn't true or if it
454                    changes, use netif_wake_queue instead. */
455         spin_unlock_irqrestore(&clip_priv->xoff_lock,flags);
456         return 0;
457 }
458 
459 
460 static struct net_device_stats *clip_get_stats(struct net_device *dev)
461 {
462         return &PRIV(dev)->stats;
463 }
464 
465 
466 int clip_mkip(struct atm_vcc *vcc,int timeout)
467 {
468         struct clip_vcc *clip_vcc;
469         struct sk_buff_head copy;
470         struct sk_buff *skb;
471 
472         if (!vcc->push) return -EBADFD;
473         clip_vcc = kmalloc(sizeof(struct clip_vcc),GFP_KERNEL);
474         if (!clip_vcc) return -ENOMEM;
475         DPRINTK("mkip clip_vcc %p vcc %p\n",clip_vcc,vcc);
476         clip_vcc->vcc = vcc;
477         vcc->user_back = clip_vcc;
478         clip_vcc->entry = NULL;
479         clip_vcc->xoff = 0;
480         clip_vcc->encap = 1;
481         clip_vcc->last_use = jiffies;
482         clip_vcc->idle_timeout = timeout*HZ;
483         clip_vcc->old_push = vcc->push;
484         clip_vcc->old_pop = vcc->pop;
485         vcc->push = clip_push;
486         vcc->pop = clip_pop;
487         skb_queue_head_init(&copy);
488         skb_migrate(&vcc->recvq,&copy);
489         /* re-process everything received between connection setup and MKIP */
490         while ((skb = skb_dequeue(&copy)))
491                 if (!clip_devs) {
492                         atm_return(vcc,skb->truesize);
493                         kfree_skb(skb);
494                 }
495                 else {
496                         unsigned int len = skb->len;
497 
498                         clip_push(vcc,skb);
499                         PRIV(skb->dev)->stats.rx_packets--;
500                         PRIV(skb->dev)->stats.rx_bytes -= len;
501                 }
502         return 0;
503 }
504 
505 
506 int clip_setentry(struct atm_vcc *vcc,u32 ip)
507 {
508         struct neighbour *neigh;
509         struct atmarp_entry *entry;
510         int error;
511         struct clip_vcc *clip_vcc;
512         struct rtable *rt;
513 
514         if (vcc->push != clip_push) {
515                 printk(KERN_WARNING "clip_setentry: non-CLIP VCC\n");
516                 return -EBADF;
517         }
518         clip_vcc = CLIP_VCC(vcc);
519         if (!ip) {
520                 if (!clip_vcc->entry) {
521                         printk(KERN_ERR "hiding hidden ATMARP entry\n");
522                         return 0;
523                 }
524                 DPRINTK("setentry: remove\n");
525                 unlink_clip_vcc(clip_vcc);
526                 return 0;
527         }
528         error = ip_route_output(&rt,ip,0,1,0);
529         if (error) return error;
530         neigh = __neigh_lookup(&clip_tbl,&ip,rt->u.dst.dev,1);
531         ip_rt_put(rt);
532         if (!neigh)
533                 return -ENOMEM;
534         entry = NEIGH2ENTRY(neigh);
535         if (entry != clip_vcc->entry) {
536                 if (!clip_vcc->entry) DPRINTK("setentry: add\n");
537                 else {
538                         DPRINTK("setentry: update\n");
539                         unlink_clip_vcc(clip_vcc);
540                 }
541                 link_vcc(clip_vcc,entry);
542         }
543         error = neigh_update(neigh,llc_oui,NUD_PERMANENT,1,0);
544         neigh_release(neigh);
545         return error;
546 }
547 
548 
549 static int clip_init(struct net_device *dev)
550 {
551         DPRINTK("clip_init %s\n",dev->name);
552         dev->hard_start_xmit = clip_start_xmit;
553         /* sg_xmit ... */
554         dev->hard_header = NULL;
555         dev->rebuild_header = NULL;
556         dev->set_mac_address = NULL;
557         dev->hard_header_parse = NULL;
558         dev->hard_header_cache = NULL;
559         dev->header_cache_update = NULL;
560         dev->change_mtu = NULL;
561         dev->do_ioctl = NULL;
562         dev->get_stats = clip_get_stats;
563         dev->type = ARPHRD_ATM;
564         dev->hard_header_len = RFC1483LLC_LEN;
565         dev->mtu = RFC1626_MTU;
566         dev->addr_len = 0;
567         dev->tx_queue_len = 100; /* "normal" queue (packets) */
568             /* When using a "real" qdisc, the qdisc determines the queue */
569             /* length. tx_queue_len is only used for the default case, */
570             /* without any more elaborate queuing. 100 is a reasonable */
571             /* compromise between decent burst-tolerance and protection */
572             /* against memory hogs. */
573         dev->flags = 0;
574         dev_init_buffers(dev); /* is this ever supposed to be used ? */
575         return 0;
576 }
577 
578 
579 int clip_create(int number)
580 {
581         struct net_device *dev;
582         struct clip_priv *clip_priv;
583         int error;
584 
585         if (number != -1) {
586                 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
587                         if (PRIV(dev)->number == number) return -EEXIST;
588         }
589         else {
590                 number = 0;
591                 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
592                         if (PRIV(dev)->number >= number)
593                                 number = PRIV(dev)->number+1;
594         }
595         dev = kmalloc(sizeof(struct net_device)+sizeof(struct clip_priv),
596             GFP_KERNEL); 
597         if (!dev) return -ENOMEM;
598         memset(dev,0,sizeof(struct net_device)+sizeof(struct clip_priv));
599         clip_priv = PRIV(dev);
600         sprintf(dev->name,"atm%d",number);
601         dev->init = clip_init;
602         spin_lock_init(&clip_priv->xoff_lock);
603         clip_priv->number = number;
604         error = register_netdev(dev);
605         if (error) {
606                 kfree(dev);
607                 return error;
608         }
609         clip_priv->next = clip_devs;
610         clip_devs = dev;
611         DPRINTK("registered (net:%s)\n",dev->name);
612         return number;
613 }
614 
615 
616 static int clip_device_event(struct notifier_block *this,unsigned long event,
617     void *dev)
618 {
619         /* ignore non-CLIP devices */
620         if (((struct net_device *) dev)->type != ARPHRD_ATM ||
621             ((struct net_device *) dev)->init != clip_init)
622                 return NOTIFY_DONE;
623         switch (event) {
624                 case NETDEV_UP:
625                         DPRINTK("clip_device_event NETDEV_UP\n");
626                         (void) to_atmarpd(act_up,PRIV(dev)->number,0);
627                         break;
628                 case NETDEV_GOING_DOWN:
629                         DPRINTK("clip_device_event NETDEV_DOWN\n");
630                         (void) to_atmarpd(act_down,PRIV(dev)->number,0);
631                         break;
632                 case NETDEV_CHANGE:
633                 case NETDEV_CHANGEMTU:
634                         DPRINTK("clip_device_event NETDEV_CHANGE*\n");
635                         (void) to_atmarpd(act_change,PRIV(dev)->number,0);
636                         break;
637                 case NETDEV_REBOOT:
638                 case NETDEV_REGISTER:
639                 case NETDEV_DOWN:
640                         DPRINTK("clip_device_event %ld\n",event);
641                         /* ignore */
642                         break;
643                 default:
644                         printk(KERN_WARNING "clip_device_event: unknown event "
645                             "%ld\n",event);
646                         break;
647         }
648         return NOTIFY_DONE;
649 }
650 
651 
652 static int clip_inet_event(struct notifier_block *this,unsigned long event,
653     void *ifa)
654 {
655         struct in_device *in_dev;
656 
657         in_dev = ((struct in_ifaddr *) ifa)->ifa_dev;
658         if (!in_dev || !in_dev->dev) {
659                 printk(KERN_WARNING "clip_inet_event: no device\n");
660                 return NOTIFY_DONE;
661         }
662         /*
663          * Transitions are of the down-change-up type, so it's sufficient to
664          * handle the change on up.
665          */
666         if (event != NETDEV_UP) return NOTIFY_DONE;
667         return clip_device_event(this,NETDEV_CHANGE,in_dev->dev);
668 }
669 
670 
671 static struct notifier_block clip_dev_notifier = {
672         clip_device_event,
673         NULL,
674         0
675 };
676 
677 
678 
679 static struct notifier_block clip_inet_notifier = {
680         clip_inet_event,
681         NULL,
682         0
683 };
684 
685 
686 
687 static void atmarpd_close(struct atm_vcc *vcc)
688 {
689         struct sk_buff *skb;
690 
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->recvq))
697                 printk(KERN_ERR "atmarpd_close: closing with requests "
698                     "pending\n");
699         while ((skb = skb_dequeue(&vcc->recvq))) kfree_skb(skb);
700         DPRINTK("(done)\n");
701 }
702 
703 
704 static struct atmdev_ops atmarpd_dev_ops = {
705         close:  atmarpd_close,
706 };
707 
708 
709 static struct atm_dev atmarpd_dev = {
710         &atmarpd_dev_ops,
711         NULL,           /* no PHY */
712         "arpd",         /* type */
713         999,            /* dummy device number */
714         NULL,NULL,      /* pretend not to have any VCCs */
715         NULL,NULL,      /* no data */
716         { 0 },          /* no flags */
717         NULL,           /* no local address */
718         { 0 }           /* no ESI, no statistics */
719 };
720 
721 
722 int atm_init_atmarp(struct atm_vcc *vcc)
723 {
724         struct net_device *dev;
725 
726         if (atmarpd) return -EADDRINUSE;
727         if (start_timer) {
728                 start_timer = 0;
729                 init_timer(&idle_timer);
730                 idle_timer.expires = jiffies+CLIP_CHECK_INTERVAL*HZ;
731                 idle_timer.function = idle_timer_check;
732                 add_timer(&idle_timer);
733         }
734         atmarpd = vcc;
735         set_bit(ATM_VF_META,&vcc->flags);
736         set_bit(ATM_VF_READY,&vcc->flags);
737             /* allow replies and avoid getting closed if signaling dies */
738         bind_vcc(vcc,&atmarpd_dev);
739         vcc->push = NULL;
740         vcc->pop = NULL; /* crash */
741         vcc->push_oam = NULL; /* crash */
742         if (register_netdevice_notifier(&clip_dev_notifier))
743                 printk(KERN_ERR "register_netdevice_notifier failed\n");
744         if (register_inetaddr_notifier(&clip_inet_notifier))
745                 printk(KERN_ERR "register_inetaddr_notifier failed\n");
746         for (dev = clip_devs; dev; dev = PRIV(dev)->next)
747                 if (dev->flags & IFF_UP)
748                         (void) to_atmarpd(act_up,PRIV(dev)->number,0);
749         return 0;
750 }
751 
752 
753 void atm_clip_init(void)
754 {
755         clip_tbl.lock = RW_LOCK_UNLOCKED;
756         clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
757             clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
758 }
759 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.