1 /* net/atm/clip.c - RFC1577 Classical IP over ATM */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5 #include <linux/string.h>
6 #include <linux/errno.h>
7 #include <linux/kernel.h> /* for UINT_MAX */
8 #include <linux/module.h>
9 #include <linux/init.h>
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/capability.h>
21 #include <linux/ip.h> /* for net/route.h */
22 #include <linux/in.h> /* for struct sockaddr_in */
23 #include <linux/if.h> /* for IFF_UP */
24 #include <linux/inetdevice.h>
25 #include <linux/bitops.h>
26 #include <linux/poison.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"
41 #include <net/atmclip.h>
45 #define DPRINTK(format,args...) printk(format,##args)
47 #define DPRINTK(format,args...)
51 static struct net_device
*clip_devs
;
52 static struct atm_vcc
*atmarpd
;
53 static struct neigh_table clip_tbl
;
54 static struct timer_list idle_timer
;
56 static int to_atmarpd(enum atmarp_ctrl_type type
, int itf
, __be32 ip
)
59 struct atmarp_ctrl
*ctrl
;
62 DPRINTK("to_atmarpd(%d)\n", type
);
65 skb
= alloc_skb(sizeof(struct atmarp_ctrl
),GFP_ATOMIC
);
68 ctrl
= (struct atmarp_ctrl
*) skb_put(skb
,sizeof(struct atmarp_ctrl
));
72 atm_force_charge(atmarpd
, skb
->truesize
);
75 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
76 sk
->sk_data_ready(sk
, skb
->len
);
80 static void link_vcc(struct clip_vcc
*clip_vcc
, struct atmarp_entry
*entry
)
82 DPRINTK("link_vcc %p to entry %p (neigh %p)\n", clip_vcc
, entry
,
84 clip_vcc
->entry
= entry
;
85 clip_vcc
->xoff
= 0; /* @@@ may overrun buffer by one packet */
86 clip_vcc
->next
= entry
->vccs
;
87 entry
->vccs
= clip_vcc
;
88 entry
->neigh
->used
= jiffies
;
91 static void unlink_clip_vcc(struct clip_vcc
*clip_vcc
)
93 struct atmarp_entry
*entry
= clip_vcc
->entry
;
94 struct clip_vcc
**walk
;
97 printk(KERN_CRIT
"!clip_vcc->entry (clip_vcc %p)\n", clip_vcc
);
100 netif_tx_lock_bh(entry
->neigh
->dev
); /* block clip_start_xmit() */
101 entry
->neigh
->used
= jiffies
;
102 for (walk
= &entry
->vccs
; *walk
; walk
= &(*walk
)->next
)
103 if (*walk
== clip_vcc
) {
106 *walk
= clip_vcc
->next
; /* atomic */
107 clip_vcc
->entry
= NULL
;
109 netif_wake_queue(entry
->neigh
->dev
);
112 entry
->expires
= jiffies
- 1;
113 /* force resolution or expiration */
114 error
= neigh_update(entry
->neigh
, NULL
, NUD_NONE
,
115 NEIGH_UPDATE_F_ADMIN
);
117 printk(KERN_CRIT
"unlink_clip_vcc: "
118 "neigh_update failed with %d\n", error
);
121 printk(KERN_CRIT
"ATMARP: unlink_clip_vcc failed (entry %p, vcc "
122 "0x%p)\n", entry
, clip_vcc
);
124 netif_tx_unlock_bh(entry
->neigh
->dev
);
127 /* The neighbour entry n->lock is held. */
128 static int neigh_check_cb(struct neighbour
*n
)
130 struct atmarp_entry
*entry
= NEIGH2ENTRY(n
);
133 for (cv
= entry
->vccs
; cv
; cv
= cv
->next
) {
134 unsigned long exp
= cv
->last_use
+ cv
->idle_timeout
;
136 if (cv
->idle_timeout
&& time_after(jiffies
, exp
)) {
137 DPRINTK("releasing vcc %p->%p of entry %p\n",
139 vcc_release_async(cv
->vcc
, -ETIMEDOUT
);
143 if (entry
->vccs
|| time_before(jiffies
, entry
->expires
))
146 if (atomic_read(&n
->refcnt
) > 1) {
149 DPRINTK("destruction postponed with ref %d\n",
150 atomic_read(&n
->refcnt
));
152 while ((skb
= skb_dequeue(&n
->arp_queue
)) != NULL
)
158 DPRINTK("expired neigh %p\n", n
);
162 static void idle_timer_check(unsigned long dummy
)
164 write_lock(&clip_tbl
.lock
);
165 __neigh_for_each_release(&clip_tbl
, neigh_check_cb
);
166 mod_timer(&idle_timer
, jiffies
+ CLIP_CHECK_INTERVAL
* HZ
);
167 write_unlock(&clip_tbl
.lock
);
170 static int clip_arp_rcv(struct sk_buff
*skb
)
174 DPRINTK("clip_arp_rcv\n");
175 vcc
= ATM_SKB(skb
)->vcc
;
176 if (!vcc
|| !atm_charge(vcc
, skb
->truesize
)) {
177 dev_kfree_skb_any(skb
);
180 DPRINTK("pushing to %p\n", vcc
);
181 DPRINTK("using %p\n", CLIP_VCC(vcc
)->old_push
);
182 CLIP_VCC(vcc
)->old_push(vcc
, skb
);
186 static const unsigned char llc_oui
[] = {
187 0xaa, /* DSAP: non-ISO */
188 0xaa, /* SSAP: non-ISO */
189 0x03, /* Ctrl: Unnumbered Information Command PDU */
190 0x00, /* OUI: EtherType */
195 static void clip_push(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
197 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
199 DPRINTK("clip push\n");
201 DPRINTK("removing VCC %p\n", clip_vcc
);
203 unlink_clip_vcc(clip_vcc
);
204 clip_vcc
->old_push(vcc
, NULL
); /* pass on the bad news */
208 atm_return(vcc
, skb
->truesize
);
209 skb
->dev
= clip_vcc
->entry
? clip_vcc
->entry
->neigh
->dev
: clip_devs
;
210 /* clip_vcc->entry == NULL if we don't have an IP address yet */
212 dev_kfree_skb_any(skb
);
215 ATM_SKB(skb
)->vcc
= vcc
;
216 skb
->mac
.raw
= skb
->data
;
218 || skb
->len
< RFC1483LLC_LEN
219 || memcmp(skb
->data
, llc_oui
, sizeof (llc_oui
)))
220 skb
->protocol
= htons(ETH_P_IP
);
222 skb
->protocol
= ((__be16
*) skb
->data
)[3];
223 skb_pull(skb
, RFC1483LLC_LEN
);
224 if (skb
->protocol
== htons(ETH_P_ARP
)) {
225 PRIV(skb
->dev
)->stats
.rx_packets
++;
226 PRIV(skb
->dev
)->stats
.rx_bytes
+= skb
->len
;
231 clip_vcc
->last_use
= jiffies
;
232 PRIV(skb
->dev
)->stats
.rx_packets
++;
233 PRIV(skb
->dev
)->stats
.rx_bytes
+= skb
->len
;
234 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
239 * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
240 * clip_pop is atomic with respect to the critical section in clip_start_xmit.
243 static void clip_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
245 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
246 struct net_device
*dev
= skb
->dev
;
250 DPRINTK("clip_pop(vcc %p)\n", vcc
);
251 clip_vcc
->old_pop(vcc
, skb
);
252 /* skb->dev == NULL in outbound ARP packets */
255 spin_lock_irqsave(&PRIV(dev
)->xoff_lock
, flags
);
256 if (atm_may_send(vcc
, 0)) {
257 old
= xchg(&clip_vcc
->xoff
, 0);
259 netif_wake_queue(dev
);
261 spin_unlock_irqrestore(&PRIV(dev
)->xoff_lock
, flags
);
264 static void clip_neigh_destroy(struct neighbour
*neigh
)
266 DPRINTK("clip_neigh_destroy (neigh %p)\n", neigh
);
267 if (NEIGH2ENTRY(neigh
)->vccs
)
268 printk(KERN_CRIT
"clip_neigh_destroy: vccs != NULL !!!\n");
269 NEIGH2ENTRY(neigh
)->vccs
= (void *) NEIGHBOR_DEAD
;
272 static void clip_neigh_solicit(struct neighbour
*neigh
, struct sk_buff
*skb
)
274 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n", neigh
, skb
);
275 to_atmarpd(act_need
, PRIV(neigh
->dev
)->number
, NEIGH2ENTRY(neigh
)->ip
);
278 static void clip_neigh_error(struct neighbour
*neigh
, struct sk_buff
*skb
)
280 #ifndef CONFIG_ATM_CLIP_NO_ICMP
281 icmp_send(skb
, ICMP_DEST_UNREACH
, ICMP_HOST_UNREACH
, 0);
286 static struct neigh_ops clip_neigh_ops
= {
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
,
296 static int clip_constructor(struct neighbour
*neigh
)
298 struct atmarp_entry
*entry
= NEIGH2ENTRY(neigh
);
299 struct net_device
*dev
= neigh
->dev
;
300 struct in_device
*in_dev
;
301 struct neigh_parms
*parms
;
303 DPRINTK("clip_constructor (neigh %p, entry %p)\n", neigh
, entry
);
304 neigh
->type
= inet_addr_type(entry
->ip
);
305 if (neigh
->type
!= RTN_UNICAST
)
309 in_dev
= __in_dev_get_rcu(dev
);
315 parms
= in_dev
->arp_parms
;
316 __neigh_parms_put(neigh
->parms
);
317 neigh
->parms
= neigh_parms_clone(parms
);
320 neigh
->ops
= &clip_neigh_ops
;
321 neigh
->output
= neigh
->nud_state
& NUD_VALID
?
322 neigh
->ops
->connected_output
: neigh
->ops
->output
;
323 entry
->neigh
= neigh
;
325 entry
->expires
= jiffies
- 1;
329 static u32
clip_hash(const void *pkey
, const struct net_device
*dev
)
331 return jhash_2words(*(u32
*) pkey
, dev
->ifindex
, clip_tbl
.hash_rnd
);
334 static struct neigh_table clip_tbl
= {
336 .entry_size
= sizeof(struct neighbour
)+sizeof(struct atmarp_entry
),
339 .constructor
= clip_constructor
,
340 .id
= "clip_arp_cache",
342 /* parameters are copied from ARP ... */
345 .neigh_destructor
= clip_neigh_destroy
,
346 .base_reachable_time
= 30 * HZ
,
347 .retrans_time
= 1 * HZ
,
348 .gc_staletime
= 60 * HZ
,
349 .reachable_time
= 30 * HZ
,
350 .delay_probe_time
= 5 * HZ
,
354 .anycast_delay
= 1 * HZ
,
355 .proxy_delay
= (8 * HZ
) / 10,
359 .gc_interval
= 30 * HZ
,
365 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
368 * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
369 * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
370 * don't increment the usage count. This is used to create entries in
374 static int clip_encap(struct atm_vcc
*vcc
, int mode
)
376 CLIP_VCC(vcc
)->encap
= mode
;
380 static int clip_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
382 struct clip_priv
*clip_priv
= PRIV(dev
);
383 struct atmarp_entry
*entry
;
388 DPRINTK("clip_start_xmit (skb %p)\n", skb
);
390 printk(KERN_ERR
"clip_start_xmit: skb->dst == NULL\n");
392 clip_priv
->stats
.tx_dropped
++;
395 if (!skb
->dst
->neighbour
) {
397 skb
->dst
->neighbour
= clip_find_neighbour(skb
->dst
, 1);
398 if (!skb
->dst
->neighbour
) {
399 dev_kfree_skb(skb
); /* lost that one */
400 clip_priv
->stats
.tx_dropped
++;
404 printk(KERN_ERR
"clip_start_xmit: NO NEIGHBOUR !\n");
406 clip_priv
->stats
.tx_dropped
++;
409 entry
= NEIGH2ENTRY(skb
->dst
->neighbour
);
411 if (time_after(jiffies
, entry
->expires
)) {
412 /* should be resolved */
413 entry
->expires
= jiffies
+ ATMARP_RETRY_DELAY
* HZ
;
414 to_atmarpd(act_need
, PRIV(dev
)->number
, entry
->ip
);
416 if (entry
->neigh
->arp_queue
.qlen
< ATMARP_MAX_UNRES_PACKETS
)
417 skb_queue_tail(&entry
->neigh
->arp_queue
, skb
);
420 clip_priv
->stats
.tx_dropped
++;
424 DPRINTK("neigh %p, vccs %p\n", entry
, entry
->vccs
);
425 ATM_SKB(skb
)->vcc
= vcc
= entry
->vccs
->vcc
;
426 DPRINTK("using neighbour %p, vcc %p\n", skb
->dst
->neighbour
, vcc
);
427 if (entry
->vccs
->encap
) {
430 here
= skb_push(skb
, RFC1483LLC_LEN
);
431 memcpy(here
, llc_oui
, sizeof(llc_oui
));
432 ((__be16
*) here
)[3] = skb
->protocol
;
434 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
435 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
436 entry
->vccs
->last_use
= jiffies
;
437 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb
, vcc
, vcc
->dev
);
438 old
= xchg(&entry
->vccs
->xoff
, 1); /* assume XOFF ... */
440 printk(KERN_WARNING
"clip_start_xmit: XOFF->XOFF transition\n");
443 clip_priv
->stats
.tx_packets
++;
444 clip_priv
->stats
.tx_bytes
+= skb
->len
;
446 if (atm_may_send(vcc
, 0)) {
447 entry
->vccs
->xoff
= 0;
450 spin_lock_irqsave(&clip_priv
->xoff_lock
, flags
);
451 netif_stop_queue(dev
); /* XOFF -> throttle immediately */
453 if (!entry
->vccs
->xoff
)
454 netif_start_queue(dev
);
455 /* Oh, we just raced with clip_pop. netif_start_queue should be
456 good enough, because nothing should really be asleep because
457 of the brief netif_stop_queue. If this isn't true or if it
458 changes, use netif_wake_queue instead. */
459 spin_unlock_irqrestore(&clip_priv
->xoff_lock
, flags
);
463 static struct net_device_stats
*clip_get_stats(struct net_device
*dev
)
465 return &PRIV(dev
)->stats
;
468 static int clip_mkip(struct atm_vcc
*vcc
, int timeout
)
470 struct clip_vcc
*clip_vcc
;
472 struct sk_buff_head
*rq
;
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
;
494 rq
= &sk_atm(vcc
)->sk_receive_queue
;
496 spin_lock_irqsave(&rq
->lock
, flags
);
497 if (skb_queue_empty(rq
)) {
500 /* NULL terminate the list. */
501 rq
->prev
->next
= NULL
;
504 rq
->prev
= rq
->next
= (struct sk_buff
*)rq
;
506 spin_unlock_irqrestore(&rq
->lock
, flags
);
508 /* re-process everything received between connection setup and MKIP */
510 struct sk_buff
*next
= skb
->next
;
512 skb
->next
= skb
->prev
= NULL
;
514 atm_return(vcc
, skb
->truesize
);
517 unsigned int len
= skb
->len
;
521 PRIV(skb
->dev
)->stats
.rx_packets
--;
522 PRIV(skb
->dev
)->stats
.rx_bytes
-= len
;
531 static int clip_setentry(struct atm_vcc
*vcc
, __be32 ip
)
533 struct neighbour
*neigh
;
534 struct atmarp_entry
*entry
;
536 struct clip_vcc
*clip_vcc
;
537 struct flowi fl
= { .nl_u
= { .ip4_u
= { .daddr
= ip
, .tos
= 1}} };
540 if (vcc
->push
!= clip_push
) {
541 printk(KERN_WARNING
"clip_setentry: non-CLIP VCC\n");
544 clip_vcc
= CLIP_VCC(vcc
);
546 if (!clip_vcc
->entry
) {
547 printk(KERN_ERR
"hiding hidden ATMARP entry\n");
550 DPRINTK("setentry: remove\n");
551 unlink_clip_vcc(clip_vcc
);
554 error
= ip_route_output_key(&rt
, &fl
);
557 neigh
= __neigh_lookup(&clip_tbl
, &ip
, rt
->u
.dst
.dev
, 1);
561 entry
= NEIGH2ENTRY(neigh
);
562 if (entry
!= clip_vcc
->entry
) {
563 if (!clip_vcc
->entry
)
564 DPRINTK("setentry: add\n");
566 DPRINTK("setentry: update\n");
567 unlink_clip_vcc(clip_vcc
);
569 link_vcc(clip_vcc
, entry
);
571 error
= neigh_update(neigh
, llc_oui
, NUD_PERMANENT
,
572 NEIGH_UPDATE_F_OVERRIDE
| NEIGH_UPDATE_F_ADMIN
);
573 neigh_release(neigh
);
577 static void clip_setup(struct net_device
*dev
)
579 dev
->hard_start_xmit
= clip_start_xmit
;
581 dev
->get_stats
= clip_get_stats
;
582 dev
->type
= ARPHRD_ATM
;
583 dev
->hard_header_len
= RFC1483LLC_LEN
;
584 dev
->mtu
= RFC1626_MTU
;
585 dev
->tx_queue_len
= 100; /* "normal" queue (packets) */
586 /* When using a "real" qdisc, the qdisc determines the queue */
587 /* length. tx_queue_len is only used for the default case, */
588 /* without any more elaborate queuing. 100 is a reasonable */
589 /* compromise between decent burst-tolerance and protection */
590 /* against memory hogs. */
593 static int clip_create(int number
)
595 struct net_device
*dev
;
596 struct clip_priv
*clip_priv
;
600 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
601 if (PRIV(dev
)->number
== number
)
605 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
606 if (PRIV(dev
)->number
>= number
)
607 number
= PRIV(dev
)->number
+ 1;
609 dev
= alloc_netdev(sizeof(struct clip_priv
), "", clip_setup
);
612 clip_priv
= PRIV(dev
);
613 sprintf(dev
->name
, "atm%d", number
);
614 spin_lock_init(&clip_priv
->xoff_lock
);
615 clip_priv
->number
= number
;
616 error
= register_netdev(dev
);
621 clip_priv
->next
= clip_devs
;
623 DPRINTK("registered (net:%s)\n", dev
->name
);
627 static int clip_device_event(struct notifier_block
*this, unsigned long event
,
630 struct net_device
*dev
= arg
;
632 if (event
== NETDEV_UNREGISTER
) {
633 neigh_ifdown(&clip_tbl
, dev
);
637 /* ignore non-CLIP devices */
638 if (dev
->type
!= ARPHRD_ATM
|| dev
->hard_start_xmit
!= clip_start_xmit
)
643 DPRINTK("clip_device_event NETDEV_UP\n");
644 to_atmarpd(act_up
, PRIV(dev
)->number
, 0);
646 case NETDEV_GOING_DOWN
:
647 DPRINTK("clip_device_event NETDEV_DOWN\n");
648 to_atmarpd(act_down
, PRIV(dev
)->number
, 0);
651 case NETDEV_CHANGEMTU
:
652 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
653 to_atmarpd(act_change
, PRIV(dev
)->number
, 0);
659 static int clip_inet_event(struct notifier_block
*this, unsigned long event
,
662 struct in_device
*in_dev
;
664 in_dev
= ((struct in_ifaddr
*)ifa
)->ifa_dev
;
665 if (!in_dev
|| !in_dev
->dev
) {
666 printk(KERN_WARNING
"clip_inet_event: no device\n");
670 * Transitions are of the down-change-up type, so it's sufficient to
671 * handle the change on up.
673 if (event
!= NETDEV_UP
)
675 return clip_device_event(this, NETDEV_CHANGE
, in_dev
->dev
);
679 static struct notifier_block clip_dev_notifier
= {
680 .notifier_call
= clip_device_event
,
685 static struct notifier_block clip_inet_notifier
= {
686 .notifier_call
= clip_inet_event
,
691 static void atmarpd_close(struct atm_vcc
*vcc
)
693 DPRINTK("atmarpd_close\n");
697 skb_queue_purge(&sk_atm(vcc
)->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
)
726 mod_timer(&idle_timer
, jiffies
+CLIP_CHECK_INTERVAL
*HZ
);
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(sk_atm(vcc
));
735 vcc
->pop
= NULL
; /* crash */
736 vcc
->push_oam
= NULL
; /* crash */
741 static int clip_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
743 struct atm_vcc
*vcc
= ATM_SD(sock
);
750 case ATMARP_SETENTRY
:
752 if (!capable(CAP_NET_ADMIN
))
761 err
= clip_create(arg
);
764 err
= atm_init_atmarp(vcc
);
766 sock
->state
= SS_CONNECTED
;
767 __module_get(THIS_MODULE
);
771 err
= clip_mkip(vcc
, arg
);
773 case ATMARP_SETENTRY
:
774 err
= clip_setentry(vcc
, (__force __be32
)arg
);
777 err
= clip_encap(vcc
, arg
);
783 static struct atm_ioctl clip_ioctl_ops
= {
784 .owner
= THIS_MODULE
,
788 #ifdef CONFIG_PROC_FS
790 static void svc_addr(struct seq_file
*seq
, struct sockaddr_atmsvc
*addr
)
792 static int code
[] = { 1, 2, 10, 6, 1, 0 };
793 static int e164
[] = { 1, 8, 4, 6, 1, 0 };
795 if (*addr
->sas_addr
.pub
) {
796 seq_printf(seq
, "%s", addr
->sas_addr
.pub
);
797 if (*addr
->sas_addr
.prv
)
799 } else if (!*addr
->sas_addr
.prv
) {
800 seq_printf(seq
, "%s", "(none)");
803 if (*addr
->sas_addr
.prv
) {
804 unsigned char *prv
= addr
->sas_addr
.prv
;
808 fields
= *prv
== ATM_AFI_E164
? e164
: code
;
809 for (i
= 0; fields
[i
]; i
++) {
810 for (j
= fields
[i
]; j
; j
--)
811 seq_printf(seq
, "%02X", *prv
++);
818 /* This means the neighbour entry has no attached VCC objects. */
819 #define SEQ_NO_VCC_TOKEN ((void *) 2)
821 static void atmarp_info(struct seq_file
*seq
, struct net_device
*dev
,
822 struct atmarp_entry
*entry
, struct clip_vcc
*clip_vcc
)
828 svc
= ((clip_vcc
== SEQ_NO_VCC_TOKEN
) ||
829 (sk_atm(clip_vcc
->vcc
)->sk_family
== AF_ATMSVC
));
831 llc
= ((clip_vcc
== SEQ_NO_VCC_TOKEN
) || clip_vcc
->encap
);
833 if (clip_vcc
== SEQ_NO_VCC_TOKEN
)
834 exp
= entry
->neigh
->used
;
836 exp
= clip_vcc
->last_use
;
838 exp
= (jiffies
- exp
) / HZ
;
840 seq_printf(seq
, "%-6s%-4s%-4s%5ld ",
841 dev
->name
, svc
? "SVC" : "PVC", llc
? "LLC" : "NULL", exp
);
843 off
= scnprintf(buf
, sizeof(buf
) - 1, "%d.%d.%d.%d",
848 seq_printf(seq
, "%s", buf
);
850 if (clip_vcc
== SEQ_NO_VCC_TOKEN
) {
851 if (time_before(jiffies
, entry
->expires
))
852 seq_printf(seq
, "(resolving)\n");
854 seq_printf(seq
, "(expired, ref %d)\n",
855 atomic_read(&entry
->neigh
->refcnt
));
857 seq_printf(seq
, "%d.%d.%d\n",
858 clip_vcc
->vcc
->dev
->number
,
859 clip_vcc
->vcc
->vpi
, clip_vcc
->vcc
->vci
);
861 svc_addr(seq
, &clip_vcc
->vcc
->remote
);
866 struct clip_seq_state
{
867 /* This member must be first. */
868 struct neigh_seq_state ns
;
870 /* Local to clip specific iteration. */
871 struct clip_vcc
*vcc
;
874 static struct clip_vcc
*clip_seq_next_vcc(struct atmarp_entry
*e
,
875 struct clip_vcc
*curr
)
880 return SEQ_NO_VCC_TOKEN
;
883 if (curr
== SEQ_NO_VCC_TOKEN
)
891 static void *clip_seq_vcc_walk(struct clip_seq_state
*state
,
892 struct atmarp_entry
*e
, loff_t
* pos
)
894 struct clip_vcc
*vcc
= state
->vcc
;
896 vcc
= clip_seq_next_vcc(e
, vcc
);
897 if (vcc
&& pos
!= NULL
) {
899 vcc
= clip_seq_next_vcc(e
, vcc
);
910 static void *clip_seq_sub_iter(struct neigh_seq_state
*_state
,
911 struct neighbour
*n
, loff_t
* pos
)
913 struct clip_seq_state
*state
= (struct clip_seq_state
*)_state
;
915 return clip_seq_vcc_walk(state
, NEIGH2ENTRY(n
), pos
);
918 static void *clip_seq_start(struct seq_file
*seq
, loff_t
* pos
)
920 return neigh_seq_start(seq
, pos
, &clip_tbl
, NEIGH_SEQ_NEIGH_ONLY
);
923 static int clip_seq_show(struct seq_file
*seq
, void *v
)
925 static char atm_arp_banner
[] =
926 "IPitf TypeEncp Idle IP address ATM address\n";
928 if (v
== SEQ_START_TOKEN
) {
929 seq_puts(seq
, atm_arp_banner
);
931 struct clip_seq_state
*state
= seq
->private;
932 struct neighbour
*n
= v
;
933 struct clip_vcc
*vcc
= state
->vcc
;
935 atmarp_info(seq
, n
->dev
, NEIGH2ENTRY(n
), vcc
);
940 static struct seq_operations arp_seq_ops
= {
941 .start
= clip_seq_start
,
942 .next
= neigh_seq_next
,
943 .stop
= neigh_seq_stop
,
944 .show
= clip_seq_show
,
947 static int arp_seq_open(struct inode
*inode
, struct file
*file
)
949 struct clip_seq_state
*state
;
950 struct seq_file
*seq
;
953 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
958 state
->ns
.neigh_sub_iter
= clip_seq_sub_iter
;
960 rc
= seq_open(file
, &arp_seq_ops
);
964 seq
= file
->private_data
;
965 seq
->private = state
;
974 static struct file_operations arp_seq_fops
= {
975 .open
= arp_seq_open
,
978 .release
= seq_release_private
,
983 static int __init
atm_clip_init(void)
985 neigh_table_init_no_netlink(&clip_tbl
);
987 clip_tbl_hook
= &clip_tbl
;
988 register_atm_ioctl(&clip_ioctl_ops
);
989 register_netdevice_notifier(&clip_dev_notifier
);
990 register_inetaddr_notifier(&clip_inet_notifier
);
992 setup_timer(&idle_timer
, idle_timer_check
, 0);
994 #ifdef CONFIG_PROC_FS
996 struct proc_dir_entry
*p
;
998 p
= create_proc_entry("arp", S_IRUGO
, atm_proc_root
);
1000 p
->proc_fops
= &arp_seq_fops
;
1007 static void __exit
atm_clip_exit(void)
1009 struct net_device
*dev
, *next
;
1011 remove_proc_entry("arp", atm_proc_root
);
1013 unregister_inetaddr_notifier(&clip_inet_notifier
);
1014 unregister_netdevice_notifier(&clip_dev_notifier
);
1016 deregister_atm_ioctl(&clip_ioctl_ops
);
1018 /* First, stop the idle timer, so it stops banging
1021 del_timer_sync(&idle_timer
);
1023 /* Next, purge the table, so that the device
1024 * unregister loop below does not hang due to
1025 * device references remaining in the table.
1027 neigh_ifdown(&clip_tbl
, NULL
);
1031 next
= PRIV(dev
)->next
;
1032 unregister_netdev(dev
);
1037 /* Now it is safe to fully shutdown whole table. */
1038 neigh_table_clear(&clip_tbl
);
1040 clip_tbl_hook
= NULL
;
1043 module_init(atm_clip_init
);
1044 module_exit(atm_clip_exit
);
1045 MODULE_AUTHOR("Werner Almesberger");
1046 MODULE_DESCRIPTION("Classical/IP over ATM interface");
1047 MODULE_LICENSE("GPL");