1 /* net/atm/clip.c - RFC1577 Classical IP over ATM */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5 #include <linux/config.h>
6 #include <linux/string.h>
7 #include <linux/errno.h>
8 #include <linux/kernel.h> /* for UINT_MAX */
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/netdevice.h>
12 #include <linux/skbuff.h>
13 #include <linux/wait.h>
14 #include <linux/timer.h>
15 #include <linux/if_arp.h> /* for some manifest constants */
16 #include <linux/notifier.h>
17 #include <linux/atm.h>
18 #include <linux/atmdev.h>
19 #include <linux/atmclip.h>
20 #include <linux/atmarp.h>
21 #include <linux/capability.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 <linux/rcupdate.h>
30 #include <linux/jhash.h>
31 #include <net/route.h> /* for struct rtable and routing */
32 #include <net/icmp.h> /* icmp_send */
33 #include <asm/param.h> /* for HZ */
34 #include <asm/byteorder.h> /* for htons etc. */
35 #include <asm/system.h> /* save/restore_flags */
36 #include <asm/uaccess.h>
37 #include <asm/atomic.h>
40 #include "resources.h"
42 #include <net/atmclip.h>
46 #define DPRINTK(format,args...) printk(format,##args)
48 #define DPRINTK(format,args...)
52 static struct net_device *clip_devs;
53 static struct atm_vcc *atmarpd;
54 static struct neigh_table clip_tbl;
55 static struct timer_list idle_timer;
57 static int to_atmarpd(enum atmarp_ctrl_type type, int itf, unsigned long ip)
60 struct atmarp_ctrl *ctrl;
63 DPRINTK("to_atmarpd(%d)\n", type);
66 skb = alloc_skb(sizeof(struct atmarp_ctrl),GFP_ATOMIC);
69 ctrl = (struct atmarp_ctrl *) skb_put(skb,sizeof(struct atmarp_ctrl));
73 atm_force_charge(atmarpd, skb->truesize);
76 skb_queue_tail(&sk->sk_receive_queue, skb);
77 sk->sk_data_ready(sk, skb->len);
81 static void link_vcc(struct clip_vcc *clip_vcc, struct atmarp_entry *entry)
83 DPRINTK("link_vcc %p to entry %p (neigh %p)\n", clip_vcc, entry,
85 clip_vcc->entry = entry;
86 clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
87 clip_vcc->next = entry->vccs;
88 entry->vccs = clip_vcc;
89 entry->neigh->used = jiffies;
92 static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
94 struct atmarp_entry *entry = clip_vcc->entry;
95 struct clip_vcc **walk;
98 printk(KERN_CRIT "!clip_vcc->entry (clip_vcc %p)\n", clip_vcc);
101 spin_lock_bh(&entry->neigh->dev->xmit_lock); /* block clip_start_xmit() */
102 entry->neigh->used = jiffies;
103 for (walk = &entry->vccs; *walk; walk = &(*walk)->next)
104 if (*walk == clip_vcc) {
107 *walk = clip_vcc->next; /* atomic */
108 clip_vcc->entry = NULL;
110 netif_wake_queue(entry->neigh->dev);
113 entry->expires = jiffies - 1;
114 /* force resolution or expiration */
115 error = neigh_update(entry->neigh, NULL, NUD_NONE,
116 NEIGH_UPDATE_F_ADMIN);
118 printk(KERN_CRIT "unlink_clip_vcc: "
119 "neigh_update failed with %d\n", error);
122 printk(KERN_CRIT "ATMARP: unlink_clip_vcc failed (entry %p, vcc "
123 "0x%p)\n", entry, clip_vcc);
125 spin_unlock_bh(&entry->neigh->dev->xmit_lock);
128 /* The neighbour entry n->lock is held. */
129 static int neigh_check_cb(struct neighbour *n)
131 struct atmarp_entry *entry = NEIGH2ENTRY(n);
134 for (cv = entry->vccs; cv; cv = cv->next) {
135 unsigned long exp = cv->last_use + cv->idle_timeout;
137 if (cv->idle_timeout && time_after(jiffies, exp)) {
138 DPRINTK("releasing vcc %p->%p of entry %p\n",
140 vcc_release_async(cv->vcc, -ETIMEDOUT);
144 if (entry->vccs || time_before(jiffies, entry->expires))
147 if (atomic_read(&n->refcnt) > 1) {
150 DPRINTK("destruction postponed with ref %d\n",
151 atomic_read(&n->refcnt));
153 while ((skb = skb_dequeue(&n->arp_queue)) != NULL)
159 DPRINTK("expired neigh %p\n", n);
163 static void idle_timer_check(unsigned long dummy)
165 write_lock(&clip_tbl.lock);
166 __neigh_for_each_release(&clip_tbl, neigh_check_cb);
167 mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ);
168 write_unlock(&clip_tbl.lock);
171 static int clip_arp_rcv(struct sk_buff *skb)
175 DPRINTK("clip_arp_rcv\n");
176 vcc = ATM_SKB(skb)->vcc;
177 if (!vcc || !atm_charge(vcc, skb->truesize)) {
178 dev_kfree_skb_any(skb);
181 DPRINTK("pushing to %p\n", vcc);
182 DPRINTK("using %p\n", CLIP_VCC(vcc)->old_push);
183 CLIP_VCC(vcc)->old_push(vcc, skb);
187 static const unsigned char llc_oui[] = {
188 0xaa, /* DSAP: non-ISO */
189 0xaa, /* SSAP: non-ISO */
190 0x03, /* Ctrl: Unnumbered Information Command PDU */
191 0x00, /* OUI: EtherType */
196 static void clip_push(struct atm_vcc *vcc, struct sk_buff *skb)
198 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
200 DPRINTK("clip push\n");
202 DPRINTK("removing VCC %p\n", clip_vcc);
204 unlink_clip_vcc(clip_vcc);
205 clip_vcc->old_push(vcc, NULL); /* pass on the bad news */
209 atm_return(vcc, skb->truesize);
210 skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs;
211 /* clip_vcc->entry == NULL if we don't have an IP address yet */
213 dev_kfree_skb_any(skb);
216 ATM_SKB(skb)->vcc = vcc;
217 skb->mac.raw = skb->data;
219 || skb->len < RFC1483LLC_LEN
220 || memcmp(skb->data, llc_oui, sizeof (llc_oui)))
221 skb->protocol = htons(ETH_P_IP);
223 skb->protocol = ((u16 *) skb->data)[3];
224 skb_pull(skb, RFC1483LLC_LEN);
225 if (skb->protocol == htons(ETH_P_ARP)) {
226 PRIV(skb->dev)->stats.rx_packets++;
227 PRIV(skb->dev)->stats.rx_bytes += skb->len;
232 clip_vcc->last_use = jiffies;
233 PRIV(skb->dev)->stats.rx_packets++;
234 PRIV(skb->dev)->stats.rx_bytes += skb->len;
235 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
240 * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
241 * clip_pop is atomic with respect to the critical section in clip_start_xmit.
244 static void clip_pop(struct atm_vcc *vcc, struct sk_buff *skb)
246 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
247 struct net_device *dev = skb->dev;
251 DPRINTK("clip_pop(vcc %p)\n", vcc);
252 clip_vcc->old_pop(vcc, skb);
253 /* skb->dev == NULL in outbound ARP packets */
256 spin_lock_irqsave(&PRIV(dev)->xoff_lock, flags);
257 if (atm_may_send(vcc, 0)) {
258 old = xchg(&clip_vcc->xoff, 0);
260 netif_wake_queue(dev);
262 spin_unlock_irqrestore(&PRIV(dev)->xoff_lock, flags);
265 static void clip_neigh_destroy(struct neighbour *neigh)
267 DPRINTK("clip_neigh_destroy (neigh %p)\n", neigh);
268 if (NEIGH2ENTRY(neigh)->vccs)
269 printk(KERN_CRIT "clip_neigh_destroy: vccs != NULL !!!\n");
270 NEIGH2ENTRY(neigh)->vccs = (void *) 0xdeadbeef;
273 static void clip_neigh_solicit(struct neighbour *neigh, struct sk_buff *skb)
275 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n", neigh, skb);
276 to_atmarpd(act_need, PRIV(neigh->dev)->number, NEIGH2ENTRY(neigh)->ip);
279 static void clip_neigh_error(struct neighbour *neigh, struct sk_buff *skb)
281 #ifndef CONFIG_ATM_CLIP_NO_ICMP
282 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
287 static struct neigh_ops clip_neigh_ops = {
289 .solicit = clip_neigh_solicit,
290 .error_report = clip_neigh_error,
291 .output = dev_queue_xmit,
292 .connected_output = dev_queue_xmit,
293 .hh_output = dev_queue_xmit,
294 .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;
302 struct neigh_parms *parms;
304 DPRINTK("clip_constructor (neigh %p, entry %p)\n", neigh, entry);
305 neigh->type = inet_addr_type(entry->ip);
306 if (neigh->type != RTN_UNICAST)
310 in_dev = __in_dev_get_rcu(dev);
316 parms = in_dev->arp_parms;
317 __neigh_parms_put(neigh->parms);
318 neigh->parms = neigh_parms_clone(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)
332 return jhash_2words(*(u32 *) pkey, dev->ifindex, clip_tbl.hash_rnd);
335 static struct neigh_table clip_tbl = {
337 .entry_size = sizeof(struct neighbour)+sizeof(struct atmarp_entry),
340 .constructor = clip_constructor,
341 .id = "clip_arp_cache",
343 /* parameters are copied from ARP ... */
346 .neigh_destructor = clip_neigh_destroy,
347 .base_reachable_time = 30 * HZ,
348 .retrans_time = 1 * HZ,
349 .gc_staletime = 60 * HZ,
350 .reachable_time = 30 * HZ,
351 .delay_probe_time = 5 * HZ,
355 .anycast_delay = 1 * HZ,
356 .proxy_delay = (8 * HZ) / 10,
360 .gc_interval = 30 * HZ,
366 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
369 * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
370 * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
371 * don't increment the usage count. This is used to create entries in
375 static int clip_encap(struct atm_vcc *vcc, int mode)
377 CLIP_VCC(vcc)->encap = mode;
381 static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
383 struct clip_priv *clip_priv = PRIV(dev);
384 struct atmarp_entry *entry;
389 DPRINTK("clip_start_xmit (skb %p)\n", skb);
391 printk(KERN_ERR "clip_start_xmit: skb->dst == NULL\n");
393 clip_priv->stats.tx_dropped++;
396 if (!skb->dst->neighbour) {
398 skb->dst->neighbour = clip_find_neighbour(skb->dst, 1);
399 if (!skb->dst->neighbour) {
400 dev_kfree_skb(skb); /* lost that one */
401 clip_priv->stats.tx_dropped++;
405 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n");
407 clip_priv->stats.tx_dropped++;
410 entry = NEIGH2ENTRY(skb->dst->neighbour);
412 if (time_after(jiffies, entry->expires)) {
413 /* should be resolved */
414 entry->expires = jiffies + ATMARP_RETRY_DELAY * HZ;
415 to_atmarpd(act_need, PRIV(dev)->number, entry->ip);
417 if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS)
418 skb_queue_tail(&entry->neigh->arp_queue, skb);
421 clip_priv->stats.tx_dropped++;
425 DPRINTK("neigh %p, vccs %p\n", entry, entry->vccs);
426 ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
427 DPRINTK("using neighbour %p, vcc %p\n", skb->dst->neighbour, vcc);
428 if (entry->vccs->encap) {
431 here = skb_push(skb, RFC1483LLC_LEN);
432 memcpy(here, llc_oui, sizeof(llc_oui));
433 ((u16 *) here)[3] = skb->protocol;
435 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
436 ATM_SKB(skb)->atm_options = vcc->atm_options;
437 entry->vccs->last_use = jiffies;
438 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev);
439 old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */
441 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n");
444 clip_priv->stats.tx_packets++;
445 clip_priv->stats.tx_bytes += skb->len;
446 (void)vcc->send(vcc, skb);
447 if (atm_may_send(vcc, 0)) {
448 entry->vccs->xoff = 0;
451 spin_lock_irqsave(&clip_priv->xoff_lock, flags);
452 netif_stop_queue(dev); /* XOFF -> throttle immediately */
454 if (!entry->vccs->xoff)
455 netif_start_queue(dev);
456 /* Oh, we just raced with clip_pop. netif_start_queue should be
457 good enough, because nothing should really be asleep because
458 of the brief netif_stop_queue. If this isn't true or if it
459 changes, use netif_wake_queue instead. */
460 spin_unlock_irqrestore(&clip_priv->xoff_lock, flags);
464 static struct net_device_stats *clip_get_stats(struct net_device *dev)
466 return &PRIV(dev)->stats;
469 static int clip_mkip(struct atm_vcc *vcc, int timeout)
471 struct clip_vcc *clip_vcc;
472 struct sk_buff_head copy;
477 clip_vcc = kmalloc(sizeof(struct clip_vcc), GFP_KERNEL);
480 DPRINTK("mkip clip_vcc %p vcc %p\n", clip_vcc, vcc);
482 vcc->user_back = clip_vcc;
483 set_bit(ATM_VF_IS_CLIP, &vcc->flags);
484 clip_vcc->entry = NULL;
487 clip_vcc->last_use = jiffies;
488 clip_vcc->idle_timeout = timeout * HZ;
489 clip_vcc->old_push = vcc->push;
490 clip_vcc->old_pop = vcc->pop;
491 vcc->push = clip_push;
493 skb_queue_head_init(©);
494 skb_migrate(&sk_atm(vcc)->sk_receive_queue, ©);
495 /* re-process everything received between connection setup and MKIP */
496 while ((skb = skb_dequeue(©)) != NULL)
498 atm_return(vcc, skb->truesize);
501 unsigned int len = skb->len;
504 PRIV(skb->dev)->stats.rx_packets--;
505 PRIV(skb->dev)->stats.rx_bytes -= len;
510 static int clip_setentry(struct atm_vcc *vcc, u32 ip)
512 struct neighbour *neigh;
513 struct atmarp_entry *entry;
515 struct clip_vcc *clip_vcc;
516 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = ip, .tos = 1}} };
519 if (vcc->push != clip_push) {
520 printk(KERN_WARNING "clip_setentry: non-CLIP VCC\n");
523 clip_vcc = CLIP_VCC(vcc);
525 if (!clip_vcc->entry) {
526 printk(KERN_ERR "hiding hidden ATMARP entry\n");
529 DPRINTK("setentry: remove\n");
530 unlink_clip_vcc(clip_vcc);
533 error = ip_route_output_key(&rt, &fl);
536 neigh = __neigh_lookup(&clip_tbl, &ip, rt->u.dst.dev, 1);
540 entry = NEIGH2ENTRY(neigh);
541 if (entry != clip_vcc->entry) {
542 if (!clip_vcc->entry)
543 DPRINTK("setentry: add\n");
545 DPRINTK("setentry: update\n");
546 unlink_clip_vcc(clip_vcc);
548 link_vcc(clip_vcc, entry);
550 error = neigh_update(neigh, llc_oui, NUD_PERMANENT,
551 NEIGH_UPDATE_F_OVERRIDE | NEIGH_UPDATE_F_ADMIN);
552 neigh_release(neigh);
556 static void clip_setup(struct net_device *dev)
558 dev->hard_start_xmit = clip_start_xmit;
560 dev->get_stats = clip_get_stats;
561 dev->type = ARPHRD_ATM;
562 dev->hard_header_len = RFC1483LLC_LEN;
563 dev->mtu = RFC1626_MTU;
564 dev->tx_queue_len = 100; /* "normal" queue (packets) */
565 /* When using a "real" qdisc, the qdisc determines the queue */
566 /* length. tx_queue_len is only used for the default case, */
567 /* without any more elaborate queuing. 100 is a reasonable */
568 /* compromise between decent burst-tolerance and protection */
569 /* against memory hogs. */
572 static int clip_create(int number)
574 struct net_device *dev;
575 struct clip_priv *clip_priv;
579 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
580 if (PRIV(dev)->number == number)
584 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
585 if (PRIV(dev)->number >= number)
586 number = PRIV(dev)->number + 1;
588 dev = alloc_netdev(sizeof(struct clip_priv), "", clip_setup);
591 clip_priv = PRIV(dev);
592 sprintf(dev->name, "atm%d", number);
593 spin_lock_init(&clip_priv->xoff_lock);
594 clip_priv->number = number;
595 error = register_netdev(dev);
600 clip_priv->next = clip_devs;
602 DPRINTK("registered (net:%s)\n", dev->name);
606 static int clip_device_event(struct notifier_block *this, unsigned long event,
609 struct net_device *dev = arg;
611 if (event == NETDEV_UNREGISTER) {
612 neigh_ifdown(&clip_tbl, dev);
616 /* ignore non-CLIP devices */
617 if (dev->type != ARPHRD_ATM || dev->hard_start_xmit != clip_start_xmit)
622 DPRINTK("clip_device_event NETDEV_UP\n");
623 (void)to_atmarpd(act_up, PRIV(dev)->number, 0);
625 case NETDEV_GOING_DOWN:
626 DPRINTK("clip_device_event NETDEV_DOWN\n");
627 (void)to_atmarpd(act_down, PRIV(dev)->number, 0);
630 case NETDEV_CHANGEMTU:
631 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
632 (void)to_atmarpd(act_change, PRIV(dev)->number, 0);
635 case NETDEV_REGISTER:
637 DPRINTK("clip_device_event %ld\n", event);
641 printk(KERN_WARNING "clip_device_event: unknown event "
648 static int clip_inet_event(struct notifier_block *this, unsigned long event,
651 struct in_device *in_dev;
653 in_dev = ((struct in_ifaddr *)ifa)->ifa_dev;
654 if (!in_dev || !in_dev->dev) {
655 printk(KERN_WARNING "clip_inet_event: no device\n");
659 * Transitions are of the down-change-up type, so it's sufficient to
660 * handle the change on up.
662 if (event != NETDEV_UP)
664 return clip_device_event(this, NETDEV_CHANGE, in_dev->dev);
668 static struct notifier_block clip_dev_notifier = {
676 static struct notifier_block clip_inet_notifier = {
684 static void atmarpd_close(struct atm_vcc *vcc)
686 DPRINTK("atmarpd_close\n");
690 skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
694 module_put(THIS_MODULE);
698 static struct atmdev_ops atmarpd_dev_ops = {
699 .close = atmarpd_close
703 static struct atm_dev atmarpd_dev = {
704 .ops = &atmarpd_dev_ops,
707 .lock = SPIN_LOCK_UNLOCKED
711 static int atm_init_atmarp(struct atm_vcc *vcc)
719 mod_timer(&idle_timer, jiffies+CLIP_CHECK_INTERVAL*HZ);
722 set_bit(ATM_VF_META,&vcc->flags);
723 set_bit(ATM_VF_READY,&vcc->flags);
724 /* allow replies and avoid getting closed if signaling dies */
725 vcc->dev = &atmarpd_dev;
726 vcc_insert_socket(sk_atm(vcc));
728 vcc->pop = NULL; /* crash */
729 vcc->push_oam = NULL; /* crash */
734 static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
736 struct atm_vcc *vcc = ATM_SD(sock);
743 case ATMARP_SETENTRY:
745 if (!capable(CAP_NET_ADMIN))
754 err = clip_create(arg);
757 err = atm_init_atmarp(vcc);
759 sock->state = SS_CONNECTED;
760 __module_get(THIS_MODULE);
764 err = clip_mkip(vcc, arg);
766 case ATMARP_SETENTRY:
767 err = clip_setentry(vcc, arg);
770 err = clip_encap(vcc, arg);
776 static struct atm_ioctl clip_ioctl_ops = {
777 .owner = THIS_MODULE,
781 #ifdef CONFIG_PROC_FS
783 static void svc_addr(struct seq_file *seq, struct sockaddr_atmsvc *addr)
785 static int code[] = { 1, 2, 10, 6, 1, 0 };
786 static int e164[] = { 1, 8, 4, 6, 1, 0 };
788 if (*addr->sas_addr.pub) {
789 seq_printf(seq, "%s", addr->sas_addr.pub);
790 if (*addr->sas_addr.prv)
792 } else if (!*addr->sas_addr.prv) {
793 seq_printf(seq, "%s", "(none)");
796 if (*addr->sas_addr.prv) {
797 unsigned char *prv = addr->sas_addr.prv;
801 fields = *prv == ATM_AFI_E164 ? e164 : code;
802 for (i = 0; fields[i]; i++) {
803 for (j = fields[i]; j; j--)
804 seq_printf(seq, "%02X", *prv++);
811 /* This means the neighbour entry has no attached VCC objects. */
812 #define SEQ_NO_VCC_TOKEN ((void *) 2)
814 static void atmarp_info(struct seq_file *seq, struct net_device *dev,
815 struct atmarp_entry *entry, struct clip_vcc *clip_vcc)
821 svc = ((clip_vcc == SEQ_NO_VCC_TOKEN) ||
822 (sk_atm(clip_vcc->vcc)->sk_family == AF_ATMSVC));
824 llc = ((clip_vcc == SEQ_NO_VCC_TOKEN) || clip_vcc->encap);
826 if (clip_vcc == SEQ_NO_VCC_TOKEN)
827 exp = entry->neigh->used;
829 exp = clip_vcc->last_use;
831 exp = (jiffies - exp) / HZ;
833 seq_printf(seq, "%-6s%-4s%-4s%5ld ",
834 dev->name, svc ? "SVC" : "PVC", llc ? "LLC" : "NULL", exp);
836 off = scnprintf(buf, sizeof(buf) - 1, "%d.%d.%d.%d",
841 seq_printf(seq, "%s", buf);
843 if (clip_vcc == SEQ_NO_VCC_TOKEN) {
844 if (time_before(jiffies, entry->expires))
845 seq_printf(seq, "(resolving)\n");
847 seq_printf(seq, "(expired, ref %d)\n",
848 atomic_read(&entry->neigh->refcnt));
850 seq_printf(seq, "%d.%d.%d\n",
851 clip_vcc->vcc->dev->number,
852 clip_vcc->vcc->vpi, clip_vcc->vcc->vci);
854 svc_addr(seq, &clip_vcc->vcc->remote);
859 struct clip_seq_state {
860 /* This member must be first. */
861 struct neigh_seq_state ns;
863 /* Local to clip specific iteration. */
864 struct clip_vcc *vcc;
867 static struct clip_vcc *clip_seq_next_vcc(struct atmarp_entry *e,
868 struct clip_vcc *curr)
873 return SEQ_NO_VCC_TOKEN;
876 if (curr == SEQ_NO_VCC_TOKEN)
884 static void *clip_seq_vcc_walk(struct clip_seq_state *state,
885 struct atmarp_entry *e, loff_t * pos)
887 struct clip_vcc *vcc = state->vcc;
889 vcc = clip_seq_next_vcc(e, vcc);
890 if (vcc && pos != NULL) {
892 vcc = clip_seq_next_vcc(e, vcc);
903 static void *clip_seq_sub_iter(struct neigh_seq_state *_state,
904 struct neighbour *n, loff_t * pos)
906 struct clip_seq_state *state = (struct clip_seq_state *)_state;
908 return clip_seq_vcc_walk(state, NEIGH2ENTRY(n), pos);
911 static void *clip_seq_start(struct seq_file *seq, loff_t * pos)
913 return neigh_seq_start(seq, pos, &clip_tbl, NEIGH_SEQ_NEIGH_ONLY);
916 static int clip_seq_show(struct seq_file *seq, void *v)
918 static char atm_arp_banner[] =
919 "IPitf TypeEncp Idle IP address ATM address\n";
921 if (v == SEQ_START_TOKEN) {
922 seq_puts(seq, atm_arp_banner);
924 struct clip_seq_state *state = seq->private;
925 struct neighbour *n = v;
926 struct clip_vcc *vcc = state->vcc;
928 atmarp_info(seq, n->dev, NEIGH2ENTRY(n), vcc);
933 static struct seq_operations arp_seq_ops = {
934 .start = clip_seq_start,
935 .next = neigh_seq_next,
936 .stop = neigh_seq_stop,
937 .show = clip_seq_show,
940 static int arp_seq_open(struct inode *inode, struct file *file)
942 struct clip_seq_state *state;
943 struct seq_file *seq;
946 state = kmalloc(sizeof(*state), GFP_KERNEL);
951 memset(state, 0, sizeof(*state));
952 state->ns.neigh_sub_iter = clip_seq_sub_iter;
954 rc = seq_open(file, &arp_seq_ops);
958 seq = file->private_data;
959 seq->private = state;
968 static struct file_operations arp_seq_fops = {
969 .open = arp_seq_open,
972 .release = seq_release_private,
977 static int __init atm_clip_init(void)
979 neigh_table_init(&clip_tbl);
981 clip_tbl_hook = &clip_tbl;
982 register_atm_ioctl(&clip_ioctl_ops);
983 register_netdevice_notifier(&clip_dev_notifier);
984 register_inetaddr_notifier(&clip_inet_notifier);
986 setup_timer(&idle_timer, idle_timer_check, 0);
988 #ifdef CONFIG_PROC_FS
990 struct proc_dir_entry *p;
992 p = create_proc_entry("arp", S_IRUGO, atm_proc_root);
994 p->proc_fops = &arp_seq_fops;
1001 static void __exit atm_clip_exit(void)
1003 struct net_device *dev, *next;
1005 remove_proc_entry("arp", atm_proc_root);
1007 unregister_inetaddr_notifier(&clip_inet_notifier);
1008 unregister_netdevice_notifier(&clip_dev_notifier);
1010 deregister_atm_ioctl(&clip_ioctl_ops);
1012 /* First, stop the idle timer, so it stops banging
1015 del_timer_sync(&idle_timer);
1017 /* Next, purge the table, so that the device
1018 * unregister loop below does not hang due to
1019 * device references remaining in the table.
1021 neigh_ifdown(&clip_tbl, NULL);
1025 next = PRIV(dev)->next;
1026 unregister_netdev(dev);
1031 /* Now it is safe to fully shutdown whole table. */
1032 neigh_table_clear(&clip_tbl);
1034 clip_tbl_hook = NULL;
1037 module_init(atm_clip_init);
1038 module_exit(atm_clip_exit);
1040 MODULE_LICENSE("GPL");