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 <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
;
56 static int start_timer
= 1;
59 static int to_atmarpd(enum atmarp_ctrl_type type
,int itf
,unsigned long ip
)
62 struct atmarp_ctrl
*ctrl
;
65 DPRINTK("to_atmarpd(%d)\n",type
);
66 if (!atmarpd
) return -EUNATCH
;
67 skb
= alloc_skb(sizeof(struct atmarp_ctrl
),GFP_ATOMIC
);
68 if (!skb
) return -ENOMEM
;
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
);
82 static void link_vcc(struct clip_vcc
*clip_vcc
,struct atmarp_entry
*entry
)
84 DPRINTK("link_vcc %p to entry %p (neigh %p)\n",clip_vcc
,entry
,
86 clip_vcc
->entry
= entry
;
87 clip_vcc
->xoff
= 0; /* @@@ may overrun buffer by one packet */
88 clip_vcc
->next
= entry
->vccs
;
89 entry
->vccs
= clip_vcc
;
90 entry
->neigh
->used
= jiffies
;
94 static void unlink_clip_vcc(struct clip_vcc
*clip_vcc
)
96 struct atmarp_entry
*entry
= clip_vcc
->entry
;
97 struct clip_vcc
**walk
;
100 printk(KERN_CRIT
"!clip_vcc->entry (clip_vcc %p)\n",clip_vcc
);
103 spin_lock_bh(&entry
->neigh
->dev
->xmit_lock
); /* block clip_start_xmit() */
104 entry
->neigh
->used
= jiffies
;
105 for (walk
= &entry
->vccs
; *walk
; walk
= &(*walk
)->next
)
106 if (*walk
== clip_vcc
) {
109 *walk
= clip_vcc
->next
; /* atomic */
110 clip_vcc
->entry
= NULL
;
112 netif_wake_queue(entry
->neigh
->dev
);
115 entry
->expires
= jiffies
-1;
116 /* force resolution or expiration */
117 error
= neigh_update(entry
->neigh
, NULL
, NUD_NONE
,
118 NEIGH_UPDATE_F_ADMIN
);
120 printk(KERN_CRIT
"unlink_clip_vcc: "
121 "neigh_update failed with %d\n",error
);
124 printk(KERN_CRIT
"ATMARP: unlink_clip_vcc failed (entry %p, vcc "
125 "0x%p)\n",entry
,clip_vcc
);
127 spin_unlock_bh(&entry
->neigh
->dev
->xmit_lock
);
130 /* The neighbour entry n->lock is held. */
131 static int neigh_check_cb(struct neighbour
*n
)
133 struct atmarp_entry
*entry
= NEIGH2ENTRY(n
);
136 for (cv
= entry
->vccs
; cv
; cv
= cv
->next
) {
137 unsigned long exp
= cv
->last_use
+ cv
->idle_timeout
;
139 if (cv
->idle_timeout
&& time_after(jiffies
, exp
)) {
140 DPRINTK("releasing vcc %p->%p of entry %p\n",
142 vcc_release_async(cv
->vcc
, -ETIMEDOUT
);
146 if (entry
->vccs
|| time_before(jiffies
, entry
->expires
))
149 if (atomic_read(&n
->refcnt
) > 1) {
152 DPRINTK("destruction postponed with ref %d\n",
153 atomic_read(&n
->refcnt
));
155 while ((skb
= skb_dequeue(&n
->arp_queue
)) != NULL
)
161 DPRINTK("expired neigh %p\n",n
);
165 static void idle_timer_check(unsigned long dummy
)
167 write_lock(&clip_tbl
.lock
);
168 __neigh_for_each_release(&clip_tbl
, neigh_check_cb
);
169 mod_timer(&idle_timer
, jiffies
+CLIP_CHECK_INTERVAL
*HZ
);
170 write_unlock(&clip_tbl
.lock
);
173 static int clip_arp_rcv(struct sk_buff
*skb
)
177 DPRINTK("clip_arp_rcv\n");
178 vcc
= ATM_SKB(skb
)->vcc
;
179 if (!vcc
|| !atm_charge(vcc
,skb
->truesize
)) {
180 dev_kfree_skb_any(skb
);
183 DPRINTK("pushing to %p\n",vcc
);
184 DPRINTK("using %p\n",CLIP_VCC(vcc
)->old_push
);
185 CLIP_VCC(vcc
)->old_push(vcc
,skb
);
189 static const unsigned char llc_oui
[] = {
190 0xaa, /* DSAP: non-ISO */
191 0xaa, /* SSAP: non-ISO */
192 0x03, /* Ctrl: Unnumbered Information Command PDU */
193 0x00, /* OUI: EtherType */
197 static void clip_push(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
199 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
201 DPRINTK("clip push\n");
203 DPRINTK("removing VCC %p\n",clip_vcc
);
204 if (clip_vcc
->entry
) 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
;
218 if (!clip_vcc
->encap
|| skb
->len
< RFC1483LLC_LEN
|| memcmp(skb
->data
,
219 llc_oui
,sizeof(llc_oui
))) skb
->protocol
= htons(ETH_P_IP
);
221 skb
->protocol
= ((u16
*) skb
->data
)[3];
222 skb_pull(skb
,RFC1483LLC_LEN
);
223 if (skb
->protocol
== htons(ETH_P_ARP
)) {
224 PRIV(skb
->dev
)->stats
.rx_packets
++;
225 PRIV(skb
->dev
)->stats
.rx_bytes
+= skb
->len
;
230 clip_vcc
->last_use
= jiffies
;
231 PRIV(skb
->dev
)->stats
.rx_packets
++;
232 PRIV(skb
->dev
)->stats
.rx_bytes
+= skb
->len
;
233 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.
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 */
255 spin_lock_irqsave(&PRIV(dev
)->xoff_lock
,flags
);
256 if (atm_may_send(vcc
,0)) {
257 old
= xchg(&clip_vcc
->xoff
,0);
258 if (old
) netif_wake_queue(dev
);
260 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 *) 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
);
280 static void clip_neigh_error(struct neighbour
*neigh
,struct sk_buff
*skb
)
282 #ifndef CONFIG_ATM_CLIP_NO_ICMP
283 icmp_send(skb
,ICMP_DEST_UNREACH
,ICMP_HOST_UNREACH
,0);
289 static struct neigh_ops clip_neigh_ops
= {
291 .destructor
= clip_neigh_destroy
,
292 .solicit
= clip_neigh_solicit
,
293 .error_report
= clip_neigh_error
,
294 .output
= dev_queue_xmit
,
295 .connected_output
= dev_queue_xmit
,
296 .hh_output
= dev_queue_xmit
,
297 .queue_xmit
= dev_queue_xmit
,
301 static int clip_constructor(struct neighbour
*neigh
)
303 struct atmarp_entry
*entry
= NEIGH2ENTRY(neigh
);
304 struct net_device
*dev
= neigh
->dev
;
305 struct in_device
*in_dev
;
306 struct neigh_parms
*parms
;
308 DPRINTK("clip_constructor (neigh %p, entry %p)\n",neigh
,entry
);
309 neigh
->type
= inet_addr_type(entry
->ip
);
310 if (neigh
->type
!= RTN_UNICAST
) return -EINVAL
;
313 in_dev
= rcu_dereference(__in_dev_get(dev
));
319 parms
= in_dev
->arp_parms
;
320 __neigh_parms_put(neigh
->parms
);
321 neigh
->parms
= neigh_parms_clone(parms
);
324 neigh
->ops
= &clip_neigh_ops
;
325 neigh
->output
= neigh
->nud_state
& NUD_VALID
?
326 neigh
->ops
->connected_output
: neigh
->ops
->output
;
327 entry
->neigh
= neigh
;
329 entry
->expires
= jiffies
-1;
333 static u32
clip_hash(const void *pkey
, const struct net_device
*dev
)
335 return jhash_2words(*(u32
*)pkey
, dev
->ifindex
, clip_tbl
.hash_rnd
);
338 static struct neigh_table clip_tbl
= {
340 .entry_size
= sizeof(struct neighbour
)+sizeof(struct atmarp_entry
),
343 .constructor
= clip_constructor
,
344 .id
= "clip_arp_cache",
346 /* parameters are copied from ARP ... */
349 .base_reachable_time
= 30 * HZ
,
350 .retrans_time
= 1 * HZ
,
351 .gc_staletime
= 60 * HZ
,
352 .reachable_time
= 30 * HZ
,
353 .delay_probe_time
= 5 * HZ
,
357 .anycast_delay
= 1 * HZ
,
358 .proxy_delay
= (8 * HZ
) / 10,
362 .gc_interval
= 30 * HZ
,
369 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
372 * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
373 * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
374 * don't increment the usage count. This is used to create entries in
379 static int clip_encap(struct atm_vcc
*vcc
,int mode
)
381 CLIP_VCC(vcc
)->encap
= mode
;
386 static int clip_start_xmit(struct sk_buff
*skb
,struct net_device
*dev
)
388 struct clip_priv
*clip_priv
= PRIV(dev
);
389 struct atmarp_entry
*entry
;
394 DPRINTK("clip_start_xmit (skb %p)\n",skb
);
396 printk(KERN_ERR
"clip_start_xmit: skb->dst == NULL\n");
398 clip_priv
->stats
.tx_dropped
++;
401 if (!skb
->dst
->neighbour
) {
403 skb
->dst
->neighbour
= clip_find_neighbour(skb
->dst
,1);
404 if (!skb
->dst
->neighbour
) {
405 dev_kfree_skb(skb
); /* lost that one */
406 clip_priv
->stats
.tx_dropped
++;
410 printk(KERN_ERR
"clip_start_xmit: NO NEIGHBOUR !\n");
412 clip_priv
->stats
.tx_dropped
++;
415 entry
= NEIGH2ENTRY(skb
->dst
->neighbour
);
417 if (time_after(jiffies
, entry
->expires
)) {
418 /* should be resolved */
419 entry
->expires
= jiffies
+ATMARP_RETRY_DELAY
*HZ
;
420 to_atmarpd(act_need
,PRIV(dev
)->number
,entry
->ip
);
422 if (entry
->neigh
->arp_queue
.qlen
< ATMARP_MAX_UNRES_PACKETS
)
423 skb_queue_tail(&entry
->neigh
->arp_queue
,skb
);
426 clip_priv
->stats
.tx_dropped
++;
430 DPRINTK("neigh %p, vccs %p\n",entry
,entry
->vccs
);
431 ATM_SKB(skb
)->vcc
= vcc
= entry
->vccs
->vcc
;
432 DPRINTK("using neighbour %p, vcc %p\n",skb
->dst
->neighbour
,vcc
);
433 if (entry
->vccs
->encap
) {
436 here
= skb_push(skb
,RFC1483LLC_LEN
);
437 memcpy(here
,llc_oui
,sizeof(llc_oui
));
438 ((u16
*) here
)[3] = skb
->protocol
;
440 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
441 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
442 entry
->vccs
->last_use
= jiffies
;
443 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n",skb
,vcc
,vcc
->dev
);
444 old
= xchg(&entry
->vccs
->xoff
,1); /* assume XOFF ... */
446 printk(KERN_WARNING
"clip_start_xmit: XOFF->XOFF transition\n");
449 clip_priv
->stats
.tx_packets
++;
450 clip_priv
->stats
.tx_bytes
+= skb
->len
;
451 (void) vcc
->send(vcc
,skb
);
452 if (atm_may_send(vcc
,0)) {
453 entry
->vccs
->xoff
= 0;
456 spin_lock_irqsave(&clip_priv
->xoff_lock
,flags
);
457 netif_stop_queue(dev
); /* XOFF -> throttle immediately */
459 if (!entry
->vccs
->xoff
)
460 netif_start_queue(dev
);
461 /* Oh, we just raced with clip_pop. netif_start_queue should be
462 good enough, because nothing should really be asleep because
463 of the brief netif_stop_queue. If this isn't true or if it
464 changes, use netif_wake_queue instead. */
465 spin_unlock_irqrestore(&clip_priv
->xoff_lock
,flags
);
470 static struct net_device_stats
*clip_get_stats(struct net_device
*dev
)
472 return &PRIV(dev
)->stats
;
476 static int clip_mkip(struct atm_vcc
*vcc
,int timeout
)
478 struct clip_vcc
*clip_vcc
;
479 struct sk_buff_head copy
;
482 if (!vcc
->push
) return -EBADFD
;
483 clip_vcc
= kmalloc(sizeof(struct clip_vcc
),GFP_KERNEL
);
484 if (!clip_vcc
) return -ENOMEM
;
485 DPRINTK("mkip clip_vcc %p vcc %p\n",clip_vcc
,vcc
);
487 vcc
->user_back
= clip_vcc
;
488 set_bit(ATM_VF_IS_CLIP
, &vcc
->flags
);
489 clip_vcc
->entry
= NULL
;
492 clip_vcc
->last_use
= jiffies
;
493 clip_vcc
->idle_timeout
= timeout
*HZ
;
494 clip_vcc
->old_push
= vcc
->push
;
495 clip_vcc
->old_pop
= vcc
->pop
;
496 vcc
->push
= clip_push
;
498 skb_queue_head_init(©
);
499 skb_migrate(&sk_atm(vcc
)->sk_receive_queue
, ©
);
500 /* re-process everything received between connection setup and MKIP */
501 while ((skb
= skb_dequeue(©
)) != NULL
)
503 atm_return(vcc
,skb
->truesize
);
507 unsigned int len
= skb
->len
;
510 PRIV(skb
->dev
)->stats
.rx_packets
--;
511 PRIV(skb
->dev
)->stats
.rx_bytes
-= len
;
517 static int clip_setentry(struct atm_vcc
*vcc
,u32 ip
)
519 struct neighbour
*neigh
;
520 struct atmarp_entry
*entry
;
522 struct clip_vcc
*clip_vcc
;
523 struct flowi fl
= { .nl_u
= { .ip4_u
= { .daddr
= ip
, .tos
= 1 } } };
526 if (vcc
->push
!= clip_push
) {
527 printk(KERN_WARNING
"clip_setentry: non-CLIP VCC\n");
530 clip_vcc
= CLIP_VCC(vcc
);
532 if (!clip_vcc
->entry
) {
533 printk(KERN_ERR
"hiding hidden ATMARP entry\n");
536 DPRINTK("setentry: remove\n");
537 unlink_clip_vcc(clip_vcc
);
540 error
= ip_route_output_key(&rt
,&fl
);
541 if (error
) return error
;
542 neigh
= __neigh_lookup(&clip_tbl
,&ip
,rt
->u
.dst
.dev
,1);
546 entry
= NEIGH2ENTRY(neigh
);
547 if (entry
!= clip_vcc
->entry
) {
548 if (!clip_vcc
->entry
) DPRINTK("setentry: add\n");
550 DPRINTK("setentry: update\n");
551 unlink_clip_vcc(clip_vcc
);
553 link_vcc(clip_vcc
,entry
);
555 error
= neigh_update(neigh
, llc_oui
, NUD_PERMANENT
,
556 NEIGH_UPDATE_F_OVERRIDE
|NEIGH_UPDATE_F_ADMIN
);
557 neigh_release(neigh
);
562 static void clip_setup(struct net_device
*dev
)
564 dev
->hard_start_xmit
= clip_start_xmit
;
566 dev
->get_stats
= clip_get_stats
;
567 dev
->type
= ARPHRD_ATM
;
568 dev
->hard_header_len
= RFC1483LLC_LEN
;
569 dev
->mtu
= RFC1626_MTU
;
570 dev
->tx_queue_len
= 100; /* "normal" queue (packets) */
571 /* When using a "real" qdisc, the qdisc determines the queue */
572 /* length. tx_queue_len is only used for the default case, */
573 /* without any more elaborate queuing. 100 is a reasonable */
574 /* compromise between decent burst-tolerance and protection */
575 /* against memory hogs. */
579 static int clip_create(int number
)
581 struct net_device
*dev
;
582 struct clip_priv
*clip_priv
;
586 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
587 if (PRIV(dev
)->number
== number
) return -EEXIST
;
591 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
592 if (PRIV(dev
)->number
>= number
)
593 number
= PRIV(dev
)->number
+1;
595 dev
= alloc_netdev(sizeof(struct clip_priv
), "", clip_setup
);
598 clip_priv
= PRIV(dev
);
599 sprintf(dev
->name
,"atm%d",number
);
600 spin_lock_init(&clip_priv
->xoff_lock
);
601 clip_priv
->number
= number
;
602 error
= register_netdev(dev
);
607 clip_priv
->next
= clip_devs
;
609 DPRINTK("registered (net:%s)\n",dev
->name
);
614 static int clip_device_event(struct notifier_block
*this,unsigned long event
,
617 /* ignore non-CLIP devices */
618 if (((struct net_device
*) dev
)->type
!= ARPHRD_ATM
||
619 ((struct net_device
*) dev
)->hard_start_xmit
!= clip_start_xmit
)
623 DPRINTK("clip_device_event NETDEV_UP\n");
624 (void) to_atmarpd(act_up
,PRIV(dev
)->number
,0);
626 case NETDEV_GOING_DOWN
:
627 DPRINTK("clip_device_event NETDEV_DOWN\n");
628 (void) to_atmarpd(act_down
,PRIV(dev
)->number
,0);
631 case NETDEV_CHANGEMTU
:
632 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
633 (void) to_atmarpd(act_change
,PRIV(dev
)->number
,0);
636 case NETDEV_REGISTER
:
638 DPRINTK("clip_device_event %ld\n",event
);
642 printk(KERN_WARNING
"clip_device_event: unknown event "
650 static int clip_inet_event(struct notifier_block
*this,unsigned long event
,
653 struct in_device
*in_dev
;
655 in_dev
= ((struct in_ifaddr
*) ifa
)->ifa_dev
;
656 if (!in_dev
|| !in_dev
->dev
) {
657 printk(KERN_WARNING
"clip_inet_event: no device\n");
661 * Transitions are of the down-change-up type, so it's sufficient to
662 * handle the change on up.
664 if (event
!= NETDEV_UP
) return NOTIFY_DONE
;
665 return clip_device_event(this,NETDEV_CHANGE
,in_dev
->dev
);
669 static struct notifier_block clip_dev_notifier
= {
677 static struct notifier_block clip_inet_notifier
= {
685 static void atmarpd_close(struct atm_vcc
*vcc
)
687 DPRINTK("atmarpd_close\n");
688 atmarpd
= NULL
; /* assumed to be atomic */
690 unregister_inetaddr_notifier(&clip_inet_notifier
);
691 unregister_netdevice_notifier(&clip_dev_notifier
);
692 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
693 printk(KERN_ERR
"atmarpd_close: closing with requests "
695 skb_queue_purge(&sk_atm(vcc
)->sk_receive_queue
);
697 module_put(THIS_MODULE
);
701 static struct atmdev_ops atmarpd_dev_ops
= {
702 .close
= atmarpd_close
706 static struct atm_dev atmarpd_dev
= {
707 .ops
= &atmarpd_dev_ops
,
710 .lock
= SPIN_LOCK_UNLOCKED
714 static int atm_init_atmarp(struct atm_vcc
*vcc
)
716 if (atmarpd
) return -EADDRINUSE
;
719 init_timer(&idle_timer
);
720 idle_timer
.expires
= jiffies
+CLIP_CHECK_INTERVAL
*HZ
;
721 idle_timer
.function
= idle_timer_check
;
722 add_timer(&idle_timer
);
725 set_bit(ATM_VF_META
,&vcc
->flags
);
726 set_bit(ATM_VF_READY
,&vcc
->flags
);
727 /* allow replies and avoid getting closed if signaling dies */
728 vcc
->dev
= &atmarpd_dev
;
729 vcc_insert_socket(sk_atm(vcc
));
731 vcc
->pop
= NULL
; /* crash */
732 vcc
->push_oam
= NULL
; /* crash */
733 if (register_netdevice_notifier(&clip_dev_notifier
))
734 printk(KERN_ERR
"register_netdevice_notifier failed\n");
735 if (register_inetaddr_notifier(&clip_inet_notifier
))
736 printk(KERN_ERR
"register_inetaddr_notifier failed\n");
740 static int clip_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
742 struct atm_vcc
*vcc
= ATM_SD(sock
);
749 case ATMARP_SETENTRY
:
751 if (!capable(CAP_NET_ADMIN
))
760 err
= clip_create(arg
);
763 err
= atm_init_atmarp(vcc
);
765 sock
->state
= SS_CONNECTED
;
766 __module_get(THIS_MODULE
);
770 err
= clip_mkip(vcc
,arg
);
772 case ATMARP_SETENTRY
:
773 err
= clip_setentry(vcc
, arg
);
776 err
= clip_encap(vcc
, arg
);
782 static struct atm_ioctl clip_ioctl_ops
= {
783 .owner
= THIS_MODULE
,
787 #ifdef CONFIG_PROC_FS
789 static void svc_addr(struct seq_file
*seq
, struct sockaddr_atmsvc
*addr
)
791 static int code
[] = { 1,2,10,6,1,0 };
792 static int e164
[] = { 1,8,4,6,1,0 };
794 if (*addr
->sas_addr
.pub
) {
795 seq_printf(seq
, "%s", addr
->sas_addr
.pub
);
796 if (*addr
->sas_addr
.prv
)
798 } else if (!*addr
->sas_addr
.prv
) {
799 seq_printf(seq
, "%s", "(none)");
802 if (*addr
->sas_addr
.prv
) {
803 unsigned char *prv
= addr
->sas_addr
.prv
;
807 fields
= *prv
== ATM_AFI_E164
? e164
: code
;
808 for (i
= 0; fields
[i
]; i
++) {
809 for (j
= fields
[i
]; j
; j
--)
810 seq_printf(seq
, "%02X", *prv
++);
817 /* This means the neighbour entry has no attached VCC objects. */
818 #define SEQ_NO_VCC_TOKEN ((void *) 2)
820 static void atmarp_info(struct seq_file
*seq
, struct net_device
*dev
,
821 struct atmarp_entry
*entry
, struct clip_vcc
*clip_vcc
)
827 svc
= ((clip_vcc
== SEQ_NO_VCC_TOKEN
) ||
828 (sk_atm(clip_vcc
->vcc
)->sk_family
== AF_ATMSVC
));
830 llc
= ((clip_vcc
== SEQ_NO_VCC_TOKEN
) ||
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 ",
843 llc
? "LLC" : "NULL",
846 off
= scnprintf(buf
, sizeof(buf
) - 1, "%d.%d.%d.%d",
851 seq_printf(seq
, "%s", buf
);
853 if (clip_vcc
== SEQ_NO_VCC_TOKEN
) {
854 if (time_before(jiffies
, entry
->expires
))
855 seq_printf(seq
, "(resolving)\n");
857 seq_printf(seq
, "(expired, ref %d)\n",
858 atomic_read(&entry
->neigh
->refcnt
));
860 seq_printf(seq
, "%d.%d.%d\n",
861 clip_vcc
->vcc
->dev
->number
,
865 svc_addr(seq
, &clip_vcc
->vcc
->remote
);
870 struct clip_seq_state
{
871 /* This member must be first. */
872 struct neigh_seq_state ns
;
874 /* Local to clip specific iteration. */
875 struct clip_vcc
*vcc
;
878 static struct clip_vcc
*clip_seq_next_vcc(struct atmarp_entry
*e
,
879 struct clip_vcc
*curr
)
884 return SEQ_NO_VCC_TOKEN
;
887 if (curr
== SEQ_NO_VCC_TOKEN
)
895 static void *clip_seq_vcc_walk(struct clip_seq_state
*state
,
896 struct atmarp_entry
*e
, loff_t
*pos
)
898 struct clip_vcc
*vcc
= state
->vcc
;
900 vcc
= clip_seq_next_vcc(e
, vcc
);
901 if (vcc
&& pos
!= NULL
) {
903 vcc
= clip_seq_next_vcc(e
, vcc
);
914 static void *clip_seq_sub_iter(struct neigh_seq_state
*_state
,
915 struct neighbour
*n
, loff_t
*pos
)
917 struct clip_seq_state
*state
= (struct clip_seq_state
*) _state
;
919 return clip_seq_vcc_walk(state
, NEIGH2ENTRY(n
), pos
);
922 static void *clip_seq_start(struct seq_file
*seq
, loff_t
*pos
)
924 return neigh_seq_start(seq
, pos
, &clip_tbl
, NEIGH_SEQ_NEIGH_ONLY
);
927 static int clip_seq_show(struct seq_file
*seq
, void *v
)
929 static char atm_arp_banner
[] =
930 "IPitf TypeEncp Idle IP address ATM address\n";
932 if (v
== SEQ_START_TOKEN
) {
933 seq_puts(seq
, atm_arp_banner
);
935 struct clip_seq_state
*state
= seq
->private;
936 struct neighbour
*n
= v
;
937 struct clip_vcc
*vcc
= state
->vcc
;
939 atmarp_info(seq
, n
->dev
, NEIGH2ENTRY(n
), vcc
);
944 static struct seq_operations arp_seq_ops
= {
945 .start
= clip_seq_start
,
946 .next
= neigh_seq_next
,
947 .stop
= neigh_seq_stop
,
948 .show
= clip_seq_show
,
951 static int arp_seq_open(struct inode
*inode
, struct file
*file
)
953 struct clip_seq_state
*state
;
954 struct seq_file
*seq
;
957 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
962 memset(state
, 0, sizeof(*state
));
963 state
->ns
.neigh_sub_iter
= clip_seq_sub_iter
;
965 rc
= seq_open(file
, &arp_seq_ops
);
969 seq
= file
->private_data
;
970 seq
->private = state
;
979 static struct file_operations arp_seq_fops
= {
980 .open
= arp_seq_open
,
983 .release
= seq_release_private
,
988 static int __init
atm_clip_init(void)
990 neigh_table_init(&clip_tbl
);
992 clip_tbl_hook
= &clip_tbl
;
993 register_atm_ioctl(&clip_ioctl_ops
);
995 #ifdef CONFIG_PROC_FS
997 struct proc_dir_entry
*p
;
999 p
= create_proc_entry("arp", S_IRUGO
, atm_proc_root
);
1001 p
->proc_fops
= &arp_seq_fops
;
1008 static void __exit
atm_clip_exit(void)
1010 struct net_device
*dev
, *next
;
1012 remove_proc_entry("arp", atm_proc_root
);
1014 deregister_atm_ioctl(&clip_ioctl_ops
);
1016 /* First, stop the idle timer, so it stops banging
1019 if (start_timer
== 0)
1020 del_timer(&idle_timer
);
1022 /* Next, purge the table, so that the device
1023 * unregister loop below does not hang due to
1024 * device references remaining in the table.
1026 neigh_ifdown(&clip_tbl
, NULL
);
1030 next
= PRIV(dev
)->next
;
1031 unregister_netdev(dev
);
1036 /* Now it is safe to fully shutdown whole table. */
1037 neigh_table_clear(&clip_tbl
);
1039 clip_tbl_hook
= NULL
;
1042 module_init(atm_clip_init
);
1043 module_exit(atm_clip_exit
);
1045 MODULE_LICENSE("GPL");