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 <linux/proc_fs.h>
28 #include <linux/seq_file.h>
29 #include <net/route.h> /* for struct rtable and routing */
30 #include <net/icmp.h> /* icmp_send */
31 #include <asm/param.h> /* for HZ */
32 #include <asm/byteorder.h> /* for htons etc. */
33 #include <asm/system.h> /* save/restore_flags */
34 #include <asm/uaccess.h>
35 #include <asm/atomic.h>
38 #include "resources.h"
40 #include <net/atmclip.h>
44 #define DPRINTK(format,args...) printk(format,##args)
46 #define DPRINTK(format,args...)
50 struct net_device *clip_devs = NULL;
51 struct atm_vcc *atmarpd = NULL;
52 static struct neigh_table clip_tbl;
53 static struct timer_list idle_timer;
54 static int start_timer = 1;
57 static int to_atmarpd(enum atmarp_ctrl_type type,int itf,unsigned long ip)
59 struct atmarp_ctrl *ctrl;
62 DPRINTK("to_atmarpd(%d)\n",type);
63 if (!atmarpd) return -EUNATCH;
64 skb = alloc_skb(sizeof(struct atmarp_ctrl),GFP_ATOMIC);
65 if (!skb) return -ENOMEM;
66 ctrl = (struct atmarp_ctrl *) skb_put(skb,sizeof(struct atmarp_ctrl));
70 atm_force_charge(atmarpd,skb->truesize);
71 skb_queue_tail(&atmarpd->sk->sk_receive_queue, skb);
72 atmarpd->sk->sk_data_ready(atmarpd->sk, skb->len);
77 static void link_vcc(struct clip_vcc *clip_vcc,struct atmarp_entry *entry)
79 DPRINTK("link_vcc %p to entry %p (neigh %p)\n",clip_vcc,entry,
81 clip_vcc->entry = entry;
82 clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
83 clip_vcc->next = entry->vccs;
84 entry->vccs = clip_vcc;
85 entry->neigh->used = jiffies;
89 static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
91 struct atmarp_entry *entry = clip_vcc->entry;
92 struct clip_vcc **walk;
95 printk(KERN_CRIT "!clip_vcc->entry (clip_vcc %p)\n",clip_vcc);
98 spin_lock_bh(&entry->neigh->dev->xmit_lock); /* block clip_start_xmit() */
99 entry->neigh->used = jiffies;
100 for (walk = &entry->vccs; *walk; walk = &(*walk)->next)
101 if (*walk == clip_vcc) {
104 *walk = clip_vcc->next; /* atomic */
105 clip_vcc->entry = NULL;
107 netif_wake_queue(entry->neigh->dev);
110 entry->expires = jiffies-1;
111 /* force resolution or expiration */
112 error = neigh_update(entry->neigh,NULL,NUD_NONE,0,0);
114 printk(KERN_CRIT "unlink_clip_vcc: "
115 "neigh_update failed with %d\n",error);
118 printk(KERN_CRIT "ATMARP: unlink_clip_vcc failed (entry %p, vcc "
119 "0x%p)\n",entry,clip_vcc);
121 spin_unlock_bh(&entry->neigh->dev->xmit_lock);
125 static void idle_timer_check(unsigned long dummy)
129 /*DPRINTK("idle_timer_check\n");*/
130 write_lock(&clip_tbl.lock);
131 for (i = 0; i <= NEIGH_HASHMASK; i++) {
132 struct neighbour **np;
134 for (np = &clip_tbl.hash_buckets[i]; *np;) {
135 struct neighbour *n = *np;
136 struct atmarp_entry *entry = NEIGH2ENTRY(n);
137 struct clip_vcc *clip_vcc;
139 write_lock(&n->lock);
141 for (clip_vcc = entry->vccs; clip_vcc;
142 clip_vcc = clip_vcc->next)
143 if (clip_vcc->idle_timeout &&
144 time_after(jiffies, clip_vcc->last_use+
145 clip_vcc->idle_timeout)) {
146 DPRINTK("releasing vcc %p->%p of "
147 "entry %p\n",clip_vcc,clip_vcc->vcc,
149 vcc_release_async(clip_vcc->vcc,
153 time_before(jiffies, entry->expires)) {
155 write_unlock(&n->lock);
158 if (atomic_read(&n->refcnt) > 1) {
161 DPRINTK("destruction postponed with ref %d\n",
162 atomic_read(&n->refcnt));
163 while ((skb = skb_dequeue(&n->arp_queue)) !=
167 write_unlock(&n->lock);
171 DPRINTK("expired neigh %p\n",n);
173 write_unlock(&n->lock);
177 mod_timer(&idle_timer, jiffies+CLIP_CHECK_INTERVAL*HZ);
178 write_unlock(&clip_tbl.lock);
182 static int clip_arp_rcv(struct sk_buff *skb)
186 DPRINTK("clip_arp_rcv\n");
187 vcc = ATM_SKB(skb)->vcc;
188 if (!vcc || !atm_charge(vcc,skb->truesize)) {
189 dev_kfree_skb_any(skb);
192 DPRINTK("pushing to %p\n",vcc);
193 DPRINTK("using %p\n",CLIP_VCC(vcc)->old_push);
194 CLIP_VCC(vcc)->old_push(vcc,skb);
198 static const unsigned char llc_oui[] = {
199 0xaa, /* DSAP: non-ISO */
200 0xaa, /* SSAP: non-ISO */
201 0x03, /* Ctrl: Unnumbered Information Command PDU */
202 0x00, /* OUI: EtherType */
206 static void clip_push(struct atm_vcc *vcc,struct sk_buff *skb)
208 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
210 DPRINTK("clip push\n");
212 DPRINTK("removing VCC %p\n",clip_vcc);
213 if (clip_vcc->entry) unlink_clip_vcc(clip_vcc);
214 clip_vcc->old_push(vcc,NULL); /* pass on the bad news */
218 atm_return(vcc,skb->truesize);
219 skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs;
220 /* clip_vcc->entry == NULL if we don't have an IP address yet */
222 dev_kfree_skb_any(skb);
225 ATM_SKB(skb)->vcc = vcc;
226 skb->mac.raw = skb->data;
227 if (!clip_vcc->encap || skb->len < RFC1483LLC_LEN || memcmp(skb->data,
228 llc_oui,sizeof(llc_oui))) skb->protocol = htons(ETH_P_IP);
230 skb->protocol = ((u16 *) skb->data)[3];
231 skb_pull(skb,RFC1483LLC_LEN);
232 if (skb->protocol == htons(ETH_P_ARP)) {
233 PRIV(skb->dev)->stats.rx_packets++;
234 PRIV(skb->dev)->stats.rx_bytes += skb->len;
239 clip_vcc->last_use = jiffies;
240 PRIV(skb->dev)->stats.rx_packets++;
241 PRIV(skb->dev)->stats.rx_bytes += skb->len;
242 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
248 * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
249 * clip_pop is atomic with respect to the critical section in clip_start_xmit.
253 static void clip_pop(struct atm_vcc *vcc,struct sk_buff *skb)
255 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
256 struct net_device *dev = skb->dev;
260 DPRINTK("clip_pop(vcc %p)\n",vcc);
261 clip_vcc->old_pop(vcc,skb);
262 /* skb->dev == NULL in outbound ARP packets */
264 spin_lock_irqsave(&PRIV(dev)->xoff_lock,flags);
265 if (atm_may_send(vcc,0)) {
266 old = xchg(&clip_vcc->xoff,0);
267 if (old) netif_wake_queue(dev);
269 spin_unlock_irqrestore(&PRIV(dev)->xoff_lock,flags);
273 static void clip_neigh_destroy(struct neighbour *neigh)
275 DPRINTK("clip_neigh_destroy (neigh %p)\n",neigh);
276 if (NEIGH2ENTRY(neigh)->vccs)
277 printk(KERN_CRIT "clip_neigh_destroy: vccs != NULL !!!\n");
278 NEIGH2ENTRY(neigh)->vccs = (void *) 0xdeadbeef;
282 static void clip_neigh_solicit(struct neighbour *neigh,struct sk_buff *skb)
284 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n",neigh,skb);
285 to_atmarpd(act_need,PRIV(neigh->dev)->number,NEIGH2ENTRY(neigh)->ip);
289 static void clip_neigh_error(struct neighbour *neigh,struct sk_buff *skb)
291 #ifndef CONFIG_ATM_CLIP_NO_ICMP
292 icmp_send(skb,ICMP_DEST_UNREACH,ICMP_HOST_UNREACH,0);
298 static struct neigh_ops clip_neigh_ops = {
300 .destructor = clip_neigh_destroy,
301 .solicit = clip_neigh_solicit,
302 .error_report = clip_neigh_error,
303 .output = dev_queue_xmit,
304 .connected_output = dev_queue_xmit,
305 .hh_output = dev_queue_xmit,
306 .queue_xmit = dev_queue_xmit,
310 static int clip_constructor(struct neighbour *neigh)
312 struct atmarp_entry *entry = NEIGH2ENTRY(neigh);
313 struct net_device *dev = neigh->dev;
314 struct in_device *in_dev = dev->ip_ptr;
316 DPRINTK("clip_constructor (neigh %p, entry %p)\n",neigh,entry);
317 if (!in_dev) return -EINVAL;
318 neigh->type = inet_addr_type(entry->ip);
319 if (neigh->type != RTN_UNICAST) return -EINVAL;
320 if (in_dev->arp_parms) neigh->parms = in_dev->arp_parms;
321 neigh->ops = &clip_neigh_ops;
322 neigh->output = neigh->nud_state & NUD_VALID ?
323 neigh->ops->connected_output : neigh->ops->output;
324 entry->neigh = neigh;
326 entry->expires = jiffies-1;
330 static u32 clip_hash(const void *pkey, const struct net_device *dev)
334 hash_val = *(u32*)pkey;
335 hash_val ^= (hash_val>>16);
336 hash_val ^= hash_val>>8;
337 hash_val ^= hash_val>>3;
338 hash_val = (hash_val^dev->ifindex)&NEIGH_HASHMASK;
343 static struct neigh_table clip_tbl = {
345 .entry_size = sizeof(struct neighbour)+sizeof(struct atmarp_entry),
348 .constructor = clip_constructor,
349 .id = "clip_arp_cache",
351 /* parameters are copied from ARP ... */
354 .base_reachable_time = 30 * HZ,
355 .retrans_time = 1 * HZ,
356 .gc_staletime = 60 * HZ,
357 .reachable_time = 30 * HZ,
358 .delay_probe_time = 5 * HZ,
362 .anycast_delay = 1 * HZ,
363 .proxy_delay = (8 * HZ) / 10,
367 .gc_interval = 30 * HZ,
374 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
377 * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
378 * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
379 * don't increment the usage count. This is used to create entries in
384 static int clip_encap(struct atm_vcc *vcc,int mode)
386 CLIP_VCC(vcc)->encap = mode;
391 static int clip_start_xmit(struct sk_buff *skb,struct net_device *dev)
393 struct clip_priv *clip_priv = PRIV(dev);
394 struct atmarp_entry *entry;
399 DPRINTK("clip_start_xmit (skb %p)\n",skb);
401 printk(KERN_ERR "clip_start_xmit: skb->dst == NULL\n");
403 clip_priv->stats.tx_dropped++;
406 if (!skb->dst->neighbour) {
408 skb->dst->neighbour = clip_find_neighbour(skb->dst,1);
409 if (!skb->dst->neighbour) {
410 dev_kfree_skb(skb); /* lost that one */
411 clip_priv->stats.tx_dropped++;
415 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n");
417 clip_priv->stats.tx_dropped++;
420 entry = NEIGH2ENTRY(skb->dst->neighbour);
422 if (time_after(jiffies, entry->expires)) {
423 /* should be resolved */
424 entry->expires = jiffies+ATMARP_RETRY_DELAY*HZ;
425 to_atmarpd(act_need,PRIV(dev)->number,entry->ip);
427 if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS)
428 skb_queue_tail(&entry->neigh->arp_queue,skb);
431 clip_priv->stats.tx_dropped++;
435 DPRINTK("neigh %p, vccs %p\n",entry,entry->vccs);
436 ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
437 DPRINTK("using neighbour %p, vcc %p\n",skb->dst->neighbour,vcc);
438 if (entry->vccs->encap) {
441 here = skb_push(skb,RFC1483LLC_LEN);
442 memcpy(here,llc_oui,sizeof(llc_oui));
443 ((u16 *) here)[3] = skb->protocol;
445 atomic_add(skb->truesize, &vcc->sk->sk_wmem_alloc);
446 ATM_SKB(skb)->atm_options = vcc->atm_options;
447 entry->vccs->last_use = jiffies;
448 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n",skb,vcc,vcc->dev);
449 old = xchg(&entry->vccs->xoff,1); /* assume XOFF ... */
451 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n");
454 clip_priv->stats.tx_packets++;
455 clip_priv->stats.tx_bytes += skb->len;
456 (void) vcc->send(vcc,skb);
457 if (atm_may_send(vcc,0)) {
458 entry->vccs->xoff = 0;
461 spin_lock_irqsave(&clip_priv->xoff_lock,flags);
462 netif_stop_queue(dev); /* XOFF -> throttle immediately */
464 if (!entry->vccs->xoff)
465 netif_start_queue(dev);
466 /* Oh, we just raced with clip_pop. netif_start_queue should be
467 good enough, because nothing should really be asleep because
468 of the brief netif_stop_queue. If this isn't true or if it
469 changes, use netif_wake_queue instead. */
470 spin_unlock_irqrestore(&clip_priv->xoff_lock,flags);
475 static struct net_device_stats *clip_get_stats(struct net_device *dev)
477 return &PRIV(dev)->stats;
481 static int clip_mkip(struct atm_vcc *vcc,int timeout)
483 struct clip_vcc *clip_vcc;
484 struct sk_buff_head copy;
487 if (!vcc->push) return -EBADFD;
488 clip_vcc = kmalloc(sizeof(struct clip_vcc),GFP_KERNEL);
489 if (!clip_vcc) return -ENOMEM;
490 DPRINTK("mkip clip_vcc %p vcc %p\n",clip_vcc,vcc);
492 vcc->user_back = clip_vcc;
493 set_bit(ATM_VF_IS_CLIP, &vcc->flags);
494 clip_vcc->entry = NULL;
497 clip_vcc->last_use = jiffies;
498 clip_vcc->idle_timeout = timeout*HZ;
499 clip_vcc->old_push = vcc->push;
500 clip_vcc->old_pop = vcc->pop;
501 vcc->push = clip_push;
503 skb_queue_head_init(©);
504 skb_migrate(&vcc->sk->sk_receive_queue, ©);
505 /* re-process everything received between connection setup and MKIP */
506 while ((skb = skb_dequeue(©)))
508 atm_return(vcc,skb->truesize);
512 unsigned int len = skb->len;
515 PRIV(skb->dev)->stats.rx_packets--;
516 PRIV(skb->dev)->stats.rx_bytes -= len;
522 static int clip_setentry(struct atm_vcc *vcc,u32 ip)
524 struct neighbour *neigh;
525 struct atmarp_entry *entry;
527 struct clip_vcc *clip_vcc;
528 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = ip, .tos = 1 } } };
531 if (vcc->push != clip_push) {
532 printk(KERN_WARNING "clip_setentry: non-CLIP VCC\n");
535 clip_vcc = CLIP_VCC(vcc);
537 if (!clip_vcc->entry) {
538 printk(KERN_ERR "hiding hidden ATMARP entry\n");
541 DPRINTK("setentry: remove\n");
542 unlink_clip_vcc(clip_vcc);
545 error = ip_route_output_key(&rt,&fl);
546 if (error) return error;
547 neigh = __neigh_lookup(&clip_tbl,&ip,rt->u.dst.dev,1);
551 entry = NEIGH2ENTRY(neigh);
552 if (entry != clip_vcc->entry) {
553 if (!clip_vcc->entry) DPRINTK("setentry: add\n");
555 DPRINTK("setentry: update\n");
556 unlink_clip_vcc(clip_vcc);
558 link_vcc(clip_vcc,entry);
560 error = neigh_update(neigh,llc_oui,NUD_PERMANENT,1,0);
561 neigh_release(neigh);
566 static void clip_setup(struct net_device *dev)
568 dev->hard_start_xmit = clip_start_xmit;
570 dev->get_stats = clip_get_stats;
571 dev->type = ARPHRD_ATM;
572 dev->hard_header_len = RFC1483LLC_LEN;
573 dev->mtu = RFC1626_MTU;
574 dev->tx_queue_len = 100; /* "normal" queue (packets) */
575 /* When using a "real" qdisc, the qdisc determines the queue */
576 /* length. tx_queue_len is only used for the default case, */
577 /* without any more elaborate queuing. 100 is a reasonable */
578 /* compromise between decent burst-tolerance and protection */
579 /* against memory hogs. */
583 static int clip_create(int number)
585 struct net_device *dev;
586 struct clip_priv *clip_priv;
590 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
591 if (PRIV(dev)->number == number) return -EEXIST;
595 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
596 if (PRIV(dev)->number >= number)
597 number = PRIV(dev)->number+1;
599 dev = alloc_netdev(sizeof(struct clip_priv), "", clip_setup);
602 clip_priv = PRIV(dev);
603 sprintf(dev->name,"atm%d",number);
604 spin_lock_init(&clip_priv->xoff_lock);
605 clip_priv->number = number;
606 error = register_netdev(dev);
611 clip_priv->next = clip_devs;
613 DPRINTK("registered (net:%s)\n",dev->name);
618 static int clip_device_event(struct notifier_block *this,unsigned long event,
621 /* ignore non-CLIP devices */
622 if (((struct net_device *) dev)->type != ARPHRD_ATM ||
623 ((struct net_device *) dev)->hard_start_xmit != clip_start_xmit)
627 DPRINTK("clip_device_event NETDEV_UP\n");
628 (void) to_atmarpd(act_up,PRIV(dev)->number,0);
630 case NETDEV_GOING_DOWN:
631 DPRINTK("clip_device_event NETDEV_DOWN\n");
632 (void) to_atmarpd(act_down,PRIV(dev)->number,0);
635 case NETDEV_CHANGEMTU:
636 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
637 (void) to_atmarpd(act_change,PRIV(dev)->number,0);
640 case NETDEV_REGISTER:
642 DPRINTK("clip_device_event %ld\n",event);
646 printk(KERN_WARNING "clip_device_event: unknown event "
654 static int clip_inet_event(struct notifier_block *this,unsigned long event,
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");
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 = {
681 static struct notifier_block clip_inet_notifier = {
689 static void atmarpd_close(struct atm_vcc *vcc)
691 DPRINTK("atmarpd_close\n");
692 atmarpd = NULL; /* assumed to be atomic */
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 "
699 skb_queue_purge(&vcc->sk->sk_receive_queue);
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,
714 .lock = SPIN_LOCK_UNLOCKED
718 static int atm_init_atmarp(struct atm_vcc *vcc)
720 if (atmarpd) return -EADDRINUSE;
723 init_timer(&idle_timer);
724 idle_timer.expires = jiffies+CLIP_CHECK_INTERVAL*HZ;
725 idle_timer.function = idle_timer_check;
726 add_timer(&idle_timer);
729 set_bit(ATM_VF_META,&vcc->flags);
730 set_bit(ATM_VF_READY,&vcc->flags);
731 /* allow replies and avoid getting closed if signaling dies */
732 vcc->dev = &atmarpd_dev;
733 vcc_insert_socket(vcc->sk);
735 vcc->pop = NULL; /* crash */
736 vcc->push_oam = NULL; /* crash */
737 if (register_netdevice_notifier(&clip_dev_notifier))
738 printk(KERN_ERR "register_netdevice_notifier failed\n");
739 if (register_inetaddr_notifier(&clip_inet_notifier))
740 printk(KERN_ERR "register_inetaddr_notifier failed\n");
744 static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
746 struct atm_vcc *vcc = ATM_SD(sock);
753 case ATMARP_SETENTRY:
755 if (!capable(CAP_NET_ADMIN))
764 err = clip_create(arg);
767 err = atm_init_atmarp(vcc);
769 sock->state = SS_CONNECTED;
770 __module_get(THIS_MODULE);
774 err = clip_mkip(vcc ,arg);
776 case ATMARP_SETENTRY:
777 err = clip_setentry(vcc, arg);
780 err = clip_encap(vcc, arg);
786 static struct atm_ioctl clip_ioctl_ops = {
787 .owner = THIS_MODULE,
791 #ifdef CONFIG_PROC_FS
793 static void svc_addr(struct seq_file *seq, struct sockaddr_atmsvc *addr)
795 static int code[] = { 1,2,10,6,1,0 };
796 static int e164[] = { 1,8,4,6,1,0 };
798 if (*addr->sas_addr.pub) {
799 seq_printf(seq, "%s", addr->sas_addr.pub);
800 if (*addr->sas_addr.prv)
802 } else if (!*addr->sas_addr.prv) {
803 seq_printf(seq, "%s", "(none)");
806 if (*addr->sas_addr.prv) {
807 unsigned char *prv = addr->sas_addr.prv;
811 fields = *prv == ATM_AFI_E164 ? e164 : code;
812 for (i = 0; fields[i]; i++) {
813 for (j = fields[i]; j; j--)
814 seq_printf(seq, "%02X", *prv++);
821 static void atmarp_info(struct seq_file *seq, struct net_device *dev,
822 struct atmarp_entry *entry, struct clip_vcc *clip_vcc)
827 svc = !clip_vcc || clip_vcc->vcc->sk->sk_family == AF_ATMSVC;
828 seq_printf(seq, "%-6s%-4s%-4s%5ld ", dev->name, svc ? "SVC" : "PVC",
829 !clip_vcc || clip_vcc->encap ? "LLC" : "NULL",
830 (jiffies-(clip_vcc ? clip_vcc->last_use : entry->neigh->used))/HZ);
832 off = scnprintf(buf, sizeof(buf) - 1, "%d.%d.%d.%d", NIPQUAD(entry->ip));
836 seq_printf(seq, "%s", buf);
839 if (time_before(jiffies, entry->expires))
840 seq_printf(seq, "(resolving)\n");
842 seq_printf(seq, "(expired, ref %d)\n",
843 atomic_read(&entry->neigh->refcnt));
845 seq_printf(seq, "%d.%d.%d\n", clip_vcc->vcc->dev->number,
846 clip_vcc->vcc->vpi, clip_vcc->vcc->vci);
848 svc_addr(seq, &clip_vcc->vcc->remote);
856 struct clip_vcc *vcc;
859 static void *arp_vcc_walk(struct arp_state *state,
860 struct atmarp_entry *e, loff_t *l)
862 struct clip_vcc *vcc = state->vcc;
866 if (vcc == (void *)1) {
870 for (; vcc; vcc = vcc->next) {
875 return (*l < 0) ? state : NULL;
878 static void *arp_get_idx(struct arp_state *state, loff_t l)
882 for (; state->bucket <= NEIGH_HASHMASK; state->bucket++) {
883 for (; state->n; state->n = state->n->next) {
884 v = arp_vcc_walk(state, NEIGH2ENTRY(state->n), &l);
888 state->n = clip_tbl.hash_buckets[state->bucket + 1];
894 static void *arp_seq_start(struct seq_file *seq, loff_t *pos)
896 struct arp_state *state = seq->private;
897 void *ret = (void *)1;
899 read_lock_bh(&clip_tbl.lock);
901 state->n = clip_tbl.hash_buckets[0];
902 state->vcc = (void *)1;
904 ret = arp_get_idx(state, *pos);
908 static void arp_seq_stop(struct seq_file *seq, void *v)
910 struct arp_state *state = seq->private;
912 if (state->bucket != -1)
913 read_unlock_bh(&clip_tbl.lock);
916 static void *arp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
918 struct arp_state *state = seq->private;
920 v = arp_get_idx(state, 1);
921 *pos += !!PTR_ERR(v);
925 static int arp_seq_show(struct seq_file *seq, void *v)
927 static char atm_arp_banner[] =
928 "IPitf TypeEncp Idle IP address ATM address\n";
931 seq_puts(seq, atm_arp_banner);
933 struct arp_state *state = seq->private;
934 struct neighbour *n = state->n;
935 struct clip_vcc *vcc = state->vcc;
937 atmarp_info(seq, n->dev, NEIGH2ENTRY(n), vcc);
942 static struct seq_operations arp_seq_ops = {
943 .start = arp_seq_start,
944 .next = arp_seq_next,
945 .stop = arp_seq_stop,
946 .show = arp_seq_show,
949 static int arp_seq_open(struct inode *inode, struct file *file)
951 struct arp_state *state;
952 struct seq_file *seq;
955 state = kmalloc(sizeof(*state), GFP_KERNEL);
961 rc = seq_open(file, &arp_seq_ops);
965 seq = file->private_data;
966 seq->private = state;
975 static int arp_seq_release(struct inode *inode, struct file *file)
977 return seq_release_private(inode, file);
980 static struct file_operations arp_seq_fops = {
981 .open = arp_seq_open,
984 .release = arp_seq_release,
989 static int __init atm_clip_init(void)
991 /* we should use neigh_table_init() */
992 clip_tbl.lock = RW_LOCK_UNLOCKED;
993 clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
994 clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
996 if (!clip_tbl.kmem_cachep)
999 /* so neigh_ifdown() doesn't complain */
1000 clip_tbl.proxy_timer.data = 0;
1001 clip_tbl.proxy_timer.function = 0;
1002 init_timer(&clip_tbl.proxy_timer);
1003 skb_queue_head_init(&clip_tbl.proxy_queue);
1005 clip_tbl_hook = &clip_tbl;
1006 register_atm_ioctl(&clip_ioctl_ops);
1008 #ifdef CONFIG_PROC_FS
1010 struct proc_dir_entry *p;
1012 p = create_proc_entry("arp", S_IRUGO, atm_proc_root);
1014 p->proc_fops = &arp_seq_fops;
1021 static void __exit atm_clip_exit(void)
1023 struct net_device *dev, *next;
1025 remove_proc_entry("arp", atm_proc_root);
1027 deregister_atm_ioctl(&clip_ioctl_ops);
1029 neigh_ifdown(&clip_tbl, NULL);
1032 next = PRIV(dev)->next;
1033 unregister_netdev(dev);
1037 if (start_timer == 0) del_timer(&idle_timer);
1039 kmem_cache_destroy(clip_tbl.kmem_cachep);
1041 clip_tbl_hook = NULL;
1044 module_init(atm_clip_init);
1045 module_exit(atm_clip_exit);
1047 MODULE_LICENSE("GPL");