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
)
61 struct atmarp_ctrl
*ctrl
;
64 DPRINTK("to_atmarpd(%d)\n",type
);
65 if (!atmarpd
) return -EUNATCH
;
66 skb
= alloc_skb(sizeof(struct atmarp_ctrl
),GFP_ATOMIC
);
67 if (!skb
) return -ENOMEM
;
68 ctrl
= (struct atmarp_ctrl
*) skb_put(skb
,sizeof(struct atmarp_ctrl
));
72 atm_force_charge(atmarpd
,skb
->truesize
);
73 skb_queue_tail(&atmarpd
->sk
->sk_receive_queue
, skb
);
74 atmarpd
->sk
->sk_data_ready(atmarpd
->sk
, skb
->len
);
79 static void link_vcc(struct clip_vcc
*clip_vcc
,struct atmarp_entry
*entry
)
81 DPRINTK("link_vcc %p to entry %p (neigh %p)\n",clip_vcc
,entry
,
83 clip_vcc
->entry
= entry
;
84 clip_vcc
->xoff
= 0; /* @@@ may overrun buffer by one packet */
85 clip_vcc
->next
= entry
->vccs
;
86 entry
->vccs
= clip_vcc
;
87 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 spin_lock_bh(&entry
->neigh
->dev
->xmit_lock
); /* 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 spin_unlock_bh(&entry
->neigh
->dev
->xmit_lock
);
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 */
194 static void clip_push(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
196 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
198 DPRINTK("clip push\n");
200 DPRINTK("removing VCC %p\n",clip_vcc
);
201 if (clip_vcc
->entry
) unlink_clip_vcc(clip_vcc
);
202 clip_vcc
->old_push(vcc
,NULL
); /* pass on the bad news */
206 atm_return(vcc
,skb
->truesize
);
207 skb
->dev
= clip_vcc
->entry
? clip_vcc
->entry
->neigh
->dev
: clip_devs
;
208 /* clip_vcc->entry == NULL if we don't have an IP address yet */
210 dev_kfree_skb_any(skb
);
213 ATM_SKB(skb
)->vcc
= vcc
;
214 skb
->mac
.raw
= skb
->data
;
215 if (!clip_vcc
->encap
|| skb
->len
< RFC1483LLC_LEN
|| memcmp(skb
->data
,
216 llc_oui
,sizeof(llc_oui
))) skb
->protocol
= htons(ETH_P_IP
);
218 skb
->protocol
= ((u16
*) skb
->data
)[3];
219 skb_pull(skb
,RFC1483LLC_LEN
);
220 if (skb
->protocol
== htons(ETH_P_ARP
)) {
221 PRIV(skb
->dev
)->stats
.rx_packets
++;
222 PRIV(skb
->dev
)->stats
.rx_bytes
+= skb
->len
;
227 clip_vcc
->last_use
= jiffies
;
228 PRIV(skb
->dev
)->stats
.rx_packets
++;
229 PRIV(skb
->dev
)->stats
.rx_bytes
+= skb
->len
;
230 memset(ATM_SKB(skb
), 0, sizeof(struct atm_skb_data
));
236 * Note: these spinlocks _must_not_ block on non-SMP. The only goal is that
237 * clip_pop is atomic with respect to the critical section in clip_start_xmit.
241 static void clip_pop(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
243 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
244 struct net_device
*dev
= skb
->dev
;
248 DPRINTK("clip_pop(vcc %p)\n",vcc
);
249 clip_vcc
->old_pop(vcc
,skb
);
250 /* skb->dev == NULL in outbound ARP packets */
252 spin_lock_irqsave(&PRIV(dev
)->xoff_lock
,flags
);
253 if (atm_may_send(vcc
,0)) {
254 old
= xchg(&clip_vcc
->xoff
,0);
255 if (old
) netif_wake_queue(dev
);
257 spin_unlock_irqrestore(&PRIV(dev
)->xoff_lock
,flags
);
261 static void clip_neigh_destroy(struct neighbour
*neigh
)
263 DPRINTK("clip_neigh_destroy (neigh %p)\n",neigh
);
264 if (NEIGH2ENTRY(neigh
)->vccs
)
265 printk(KERN_CRIT
"clip_neigh_destroy: vccs != NULL !!!\n");
266 NEIGH2ENTRY(neigh
)->vccs
= (void *) 0xdeadbeef;
270 static void clip_neigh_solicit(struct neighbour
*neigh
,struct sk_buff
*skb
)
272 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n",neigh
,skb
);
273 to_atmarpd(act_need
,PRIV(neigh
->dev
)->number
,NEIGH2ENTRY(neigh
)->ip
);
277 static void clip_neigh_error(struct neighbour
*neigh
,struct sk_buff
*skb
)
279 #ifndef CONFIG_ATM_CLIP_NO_ICMP
280 icmp_send(skb
,ICMP_DEST_UNREACH
,ICMP_HOST_UNREACH
,0);
286 static struct neigh_ops clip_neigh_ops
= {
288 .destructor
= clip_neigh_destroy
,
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
,
298 static int clip_constructor(struct neighbour
*neigh
)
300 struct atmarp_entry
*entry
= NEIGH2ENTRY(neigh
);
301 struct net_device
*dev
= neigh
->dev
;
302 struct in_device
*in_dev
;
303 struct neigh_parms
*parms
;
305 DPRINTK("clip_constructor (neigh %p, entry %p)\n",neigh
,entry
);
306 neigh
->type
= inet_addr_type(entry
->ip
);
307 if (neigh
->type
!= RTN_UNICAST
) return -EINVAL
;
310 in_dev
= rcu_dereference(__in_dev_get(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 .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
,
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
376 static int clip_encap(struct atm_vcc
*vcc
,int mode
)
378 CLIP_VCC(vcc
)->encap
= mode
;
383 static int clip_start_xmit(struct sk_buff
*skb
,struct net_device
*dev
)
385 struct clip_priv
*clip_priv
= PRIV(dev
);
386 struct atmarp_entry
*entry
;
391 DPRINTK("clip_start_xmit (skb %p)\n",skb
);
393 printk(KERN_ERR
"clip_start_xmit: skb->dst == NULL\n");
395 clip_priv
->stats
.tx_dropped
++;
398 if (!skb
->dst
->neighbour
) {
400 skb
->dst
->neighbour
= clip_find_neighbour(skb
->dst
,1);
401 if (!skb
->dst
->neighbour
) {
402 dev_kfree_skb(skb
); /* lost that one */
403 clip_priv
->stats
.tx_dropped
++;
407 printk(KERN_ERR
"clip_start_xmit: NO NEIGHBOUR !\n");
409 clip_priv
->stats
.tx_dropped
++;
412 entry
= NEIGH2ENTRY(skb
->dst
->neighbour
);
414 if (time_after(jiffies
, entry
->expires
)) {
415 /* should be resolved */
416 entry
->expires
= jiffies
+ATMARP_RETRY_DELAY
*HZ
;
417 to_atmarpd(act_need
,PRIV(dev
)->number
,entry
->ip
);
419 if (entry
->neigh
->arp_queue
.qlen
< ATMARP_MAX_UNRES_PACKETS
)
420 skb_queue_tail(&entry
->neigh
->arp_queue
,skb
);
423 clip_priv
->stats
.tx_dropped
++;
427 DPRINTK("neigh %p, vccs %p\n",entry
,entry
->vccs
);
428 ATM_SKB(skb
)->vcc
= vcc
= entry
->vccs
->vcc
;
429 DPRINTK("using neighbour %p, vcc %p\n",skb
->dst
->neighbour
,vcc
);
430 if (entry
->vccs
->encap
) {
433 here
= skb_push(skb
,RFC1483LLC_LEN
);
434 memcpy(here
,llc_oui
,sizeof(llc_oui
));
435 ((u16
*) here
)[3] = skb
->protocol
;
437 atomic_add(skb
->truesize
, &vcc
->sk
->sk_wmem_alloc
);
438 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
439 entry
->vccs
->last_use
= jiffies
;
440 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n",skb
,vcc
,vcc
->dev
);
441 old
= xchg(&entry
->vccs
->xoff
,1); /* assume XOFF ... */
443 printk(KERN_WARNING
"clip_start_xmit: XOFF->XOFF transition\n");
446 clip_priv
->stats
.tx_packets
++;
447 clip_priv
->stats
.tx_bytes
+= skb
->len
;
448 (void) vcc
->send(vcc
,skb
);
449 if (atm_may_send(vcc
,0)) {
450 entry
->vccs
->xoff
= 0;
453 spin_lock_irqsave(&clip_priv
->xoff_lock
,flags
);
454 netif_stop_queue(dev
); /* XOFF -> throttle immediately */
456 if (!entry
->vccs
->xoff
)
457 netif_start_queue(dev
);
458 /* Oh, we just raced with clip_pop. netif_start_queue should be
459 good enough, because nothing should really be asleep because
460 of the brief netif_stop_queue. If this isn't true or if it
461 changes, use netif_wake_queue instead. */
462 spin_unlock_irqrestore(&clip_priv
->xoff_lock
,flags
);
467 static struct net_device_stats
*clip_get_stats(struct net_device
*dev
)
469 return &PRIV(dev
)->stats
;
473 static int clip_mkip(struct atm_vcc
*vcc
,int timeout
)
475 struct clip_vcc
*clip_vcc
;
476 struct sk_buff_head copy
;
479 if (!vcc
->push
) return -EBADFD
;
480 clip_vcc
= kmalloc(sizeof(struct clip_vcc
),GFP_KERNEL
);
481 if (!clip_vcc
) return -ENOMEM
;
482 DPRINTK("mkip clip_vcc %p vcc %p\n",clip_vcc
,vcc
);
484 vcc
->user_back
= clip_vcc
;
485 set_bit(ATM_VF_IS_CLIP
, &vcc
->flags
);
486 clip_vcc
->entry
= NULL
;
489 clip_vcc
->last_use
= jiffies
;
490 clip_vcc
->idle_timeout
= timeout
*HZ
;
491 clip_vcc
->old_push
= vcc
->push
;
492 clip_vcc
->old_pop
= vcc
->pop
;
493 vcc
->push
= clip_push
;
495 skb_queue_head_init(©
);
496 skb_migrate(&vcc
->sk
->sk_receive_queue
, ©
);
497 /* re-process everything received between connection setup and MKIP */
498 while ((skb
= skb_dequeue(©
)) != NULL
)
500 atm_return(vcc
,skb
->truesize
);
504 unsigned int len
= skb
->len
;
507 PRIV(skb
->dev
)->stats
.rx_packets
--;
508 PRIV(skb
->dev
)->stats
.rx_bytes
-= len
;
514 static int clip_setentry(struct atm_vcc
*vcc
,u32 ip
)
516 struct neighbour
*neigh
;
517 struct atmarp_entry
*entry
;
519 struct clip_vcc
*clip_vcc
;
520 struct flowi fl
= { .nl_u
= { .ip4_u
= { .daddr
= ip
, .tos
= 1 } } };
523 if (vcc
->push
!= clip_push
) {
524 printk(KERN_WARNING
"clip_setentry: non-CLIP VCC\n");
527 clip_vcc
= CLIP_VCC(vcc
);
529 if (!clip_vcc
->entry
) {
530 printk(KERN_ERR
"hiding hidden ATMARP entry\n");
533 DPRINTK("setentry: remove\n");
534 unlink_clip_vcc(clip_vcc
);
537 error
= ip_route_output_key(&rt
,&fl
);
538 if (error
) return error
;
539 neigh
= __neigh_lookup(&clip_tbl
,&ip
,rt
->u
.dst
.dev
,1);
543 entry
= NEIGH2ENTRY(neigh
);
544 if (entry
!= clip_vcc
->entry
) {
545 if (!clip_vcc
->entry
) DPRINTK("setentry: add\n");
547 DPRINTK("setentry: update\n");
548 unlink_clip_vcc(clip_vcc
);
550 link_vcc(clip_vcc
,entry
);
552 error
= neigh_update(neigh
, llc_oui
, NUD_PERMANENT
,
553 NEIGH_UPDATE_F_OVERRIDE
|NEIGH_UPDATE_F_ADMIN
);
554 neigh_release(neigh
);
559 static void clip_setup(struct net_device
*dev
)
561 dev
->hard_start_xmit
= clip_start_xmit
;
563 dev
->get_stats
= clip_get_stats
;
564 dev
->type
= ARPHRD_ATM
;
565 dev
->hard_header_len
= RFC1483LLC_LEN
;
566 dev
->mtu
= RFC1626_MTU
;
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. */
576 static int clip_create(int number
)
578 struct net_device
*dev
;
579 struct clip_priv
*clip_priv
;
583 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
584 if (PRIV(dev
)->number
== number
) return -EEXIST
;
588 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
589 if (PRIV(dev
)->number
>= number
)
590 number
= PRIV(dev
)->number
+1;
592 dev
= alloc_netdev(sizeof(struct clip_priv
), "", clip_setup
);
595 clip_priv
= PRIV(dev
);
596 sprintf(dev
->name
,"atm%d",number
);
597 spin_lock_init(&clip_priv
->xoff_lock
);
598 clip_priv
->number
= number
;
599 error
= register_netdev(dev
);
604 clip_priv
->next
= clip_devs
;
606 DPRINTK("registered (net:%s)\n",dev
->name
);
611 static int clip_device_event(struct notifier_block
*this,unsigned long event
,
614 /* ignore non-CLIP devices */
615 if (((struct net_device
*) dev
)->type
!= ARPHRD_ATM
||
616 ((struct net_device
*) dev
)->hard_start_xmit
!= clip_start_xmit
)
620 DPRINTK("clip_device_event NETDEV_UP\n");
621 (void) to_atmarpd(act_up
,PRIV(dev
)->number
,0);
623 case NETDEV_GOING_DOWN
:
624 DPRINTK("clip_device_event NETDEV_DOWN\n");
625 (void) to_atmarpd(act_down
,PRIV(dev
)->number
,0);
628 case NETDEV_CHANGEMTU
:
629 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
630 (void) to_atmarpd(act_change
,PRIV(dev
)->number
,0);
633 case NETDEV_REGISTER
:
635 DPRINTK("clip_device_event %ld\n",event
);
639 printk(KERN_WARNING
"clip_device_event: unknown event "
647 static int clip_inet_event(struct notifier_block
*this,unsigned long event
,
650 struct in_device
*in_dev
;
652 in_dev
= ((struct in_ifaddr
*) ifa
)->ifa_dev
;
653 if (!in_dev
|| !in_dev
->dev
) {
654 printk(KERN_WARNING
"clip_inet_event: no device\n");
658 * Transitions are of the down-change-up type, so it's sufficient to
659 * handle the change on up.
661 if (event
!= NETDEV_UP
) return NOTIFY_DONE
;
662 return clip_device_event(this,NETDEV_CHANGE
,in_dev
->dev
);
666 static struct notifier_block clip_dev_notifier
= {
674 static struct notifier_block clip_inet_notifier
= {
682 static void atmarpd_close(struct atm_vcc
*vcc
)
684 DPRINTK("atmarpd_close\n");
685 atmarpd
= NULL
; /* assumed to be atomic */
687 unregister_inetaddr_notifier(&clip_inet_notifier
);
688 unregister_netdevice_notifier(&clip_dev_notifier
);
689 if (skb_peek(&vcc
->sk
->sk_receive_queue
))
690 printk(KERN_ERR
"atmarpd_close: closing with requests "
692 skb_queue_purge(&vcc
->sk
->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
)
713 if (atmarpd
) return -EADDRINUSE
;
716 init_timer(&idle_timer
);
717 idle_timer
.expires
= jiffies
+CLIP_CHECK_INTERVAL
*HZ
;
718 idle_timer
.function
= idle_timer_check
;
719 add_timer(&idle_timer
);
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(vcc
->sk
);
728 vcc
->pop
= NULL
; /* crash */
729 vcc
->push_oam
= NULL
; /* crash */
730 if (register_netdevice_notifier(&clip_dev_notifier
))
731 printk(KERN_ERR
"register_netdevice_notifier failed\n");
732 if (register_inetaddr_notifier(&clip_inet_notifier
))
733 printk(KERN_ERR
"register_inetaddr_notifier failed\n");
737 static int clip_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
739 struct atm_vcc
*vcc
= ATM_SD(sock
);
746 case ATMARP_SETENTRY
:
748 if (!capable(CAP_NET_ADMIN
))
757 err
= clip_create(arg
);
760 err
= atm_init_atmarp(vcc
);
762 sock
->state
= SS_CONNECTED
;
763 __module_get(THIS_MODULE
);
767 err
= clip_mkip(vcc
,arg
);
769 case ATMARP_SETENTRY
:
770 err
= clip_setentry(vcc
, arg
);
773 err
= clip_encap(vcc
, arg
);
779 static struct atm_ioctl clip_ioctl_ops
= {
780 .owner
= THIS_MODULE
,
784 #ifdef CONFIG_PROC_FS
786 static void svc_addr(struct seq_file
*seq
, struct sockaddr_atmsvc
*addr
)
788 static int code
[] = { 1,2,10,6,1,0 };
789 static int e164
[] = { 1,8,4,6,1,0 };
791 if (*addr
->sas_addr
.pub
) {
792 seq_printf(seq
, "%s", addr
->sas_addr
.pub
);
793 if (*addr
->sas_addr
.prv
)
795 } else if (!*addr
->sas_addr
.prv
) {
796 seq_printf(seq
, "%s", "(none)");
799 if (*addr
->sas_addr
.prv
) {
800 unsigned char *prv
= addr
->sas_addr
.prv
;
804 fields
= *prv
== ATM_AFI_E164
? e164
: code
;
805 for (i
= 0; fields
[i
]; i
++) {
806 for (j
= fields
[i
]; j
; j
--)
807 seq_printf(seq
, "%02X", *prv
++);
814 /* This means the neighbour entry has no attached VCC objects. */
815 #define SEQ_NO_VCC_TOKEN ((void *) 2)
817 static void atmarp_info(struct seq_file
*seq
, struct net_device
*dev
,
818 struct atmarp_entry
*entry
, struct clip_vcc
*clip_vcc
)
824 svc
= ((clip_vcc
== SEQ_NO_VCC_TOKEN
) ||
825 (clip_vcc
->vcc
->sk
->sk_family
== AF_ATMSVC
));
827 llc
= ((clip_vcc
== SEQ_NO_VCC_TOKEN
) ||
830 if (clip_vcc
== SEQ_NO_VCC_TOKEN
)
831 exp
= entry
->neigh
->used
;
833 exp
= clip_vcc
->last_use
;
835 exp
= (jiffies
- exp
) / HZ
;
837 seq_printf(seq
, "%-6s%-4s%-4s%5ld ",
840 llc
? "LLC" : "NULL",
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
,
862 svc_addr(seq
, &clip_vcc
->vcc
->remote
);
867 struct clip_seq_state
{
868 /* This member must be first. */
869 struct neigh_seq_state ns
;
871 /* Local to clip specific iteration. */
872 struct clip_vcc
*vcc
;
875 static struct clip_vcc
*clip_seq_next_vcc(struct atmarp_entry
*e
,
876 struct clip_vcc
*curr
)
881 return SEQ_NO_VCC_TOKEN
;
884 if (curr
== SEQ_NO_VCC_TOKEN
)
892 static void *clip_seq_vcc_walk(struct clip_seq_state
*state
,
893 struct atmarp_entry
*e
, loff_t
*pos
)
895 struct clip_vcc
*vcc
= state
->vcc
;
897 vcc
= clip_seq_next_vcc(e
, vcc
);
898 if (vcc
&& pos
!= NULL
) {
900 vcc
= clip_seq_next_vcc(e
, vcc
);
911 static void *clip_seq_sub_iter(struct neigh_seq_state
*_state
,
912 struct neighbour
*n
, loff_t
*pos
)
914 struct clip_seq_state
*state
= (struct clip_seq_state
*) _state
;
916 return clip_seq_vcc_walk(state
, NEIGH2ENTRY(n
), pos
);
919 static void *clip_seq_start(struct seq_file
*seq
, loff_t
*pos
)
921 return neigh_seq_start(seq
, pos
, &clip_tbl
, NEIGH_SEQ_NEIGH_ONLY
);
924 static int clip_seq_show(struct seq_file
*seq
, void *v
)
926 static char atm_arp_banner
[] =
927 "IPitf TypeEncp Idle IP address ATM address\n";
929 if (v
== SEQ_START_TOKEN
) {
930 seq_puts(seq
, atm_arp_banner
);
932 struct clip_seq_state
*state
= seq
->private;
933 struct neighbour
*n
= v
;
934 struct clip_vcc
*vcc
= state
->vcc
;
936 atmarp_info(seq
, n
->dev
, NEIGH2ENTRY(n
), vcc
);
941 static struct seq_operations arp_seq_ops
= {
942 .start
= clip_seq_start
,
943 .next
= neigh_seq_next
,
944 .stop
= neigh_seq_stop
,
945 .show
= clip_seq_show
,
948 static int arp_seq_open(struct inode
*inode
, struct file
*file
)
950 struct clip_seq_state
*state
;
951 struct seq_file
*seq
;
954 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
959 memset(state
, 0, sizeof(*state
));
960 state
->ns
.neigh_sub_iter
= clip_seq_sub_iter
;
962 rc
= seq_open(file
, &arp_seq_ops
);
966 seq
= file
->private_data
;
967 seq
->private = state
;
976 static struct file_operations arp_seq_fops
= {
977 .open
= arp_seq_open
,
980 .release
= seq_release_private
,
985 static int __init
atm_clip_init(void)
987 neigh_table_init(&clip_tbl
);
989 clip_tbl_hook
= &clip_tbl
;
990 register_atm_ioctl(&clip_ioctl_ops
);
992 #ifdef CONFIG_PROC_FS
994 struct proc_dir_entry
*p
;
996 p
= create_proc_entry("arp", S_IRUGO
, atm_proc_root
);
998 p
->proc_fops
= &arp_seq_fops
;
1005 static void __exit
atm_clip_exit(void)
1007 struct net_device
*dev
, *next
;
1009 remove_proc_entry("arp", atm_proc_root
);
1011 deregister_atm_ioctl(&clip_ioctl_ops
);
1013 /* First, stop the idle timer, so it stops banging
1016 if (start_timer
== 0)
1017 del_timer(&idle_timer
);
1019 /* Next, purge the table, so that the device
1020 * unregister loop below does not hang due to
1021 * device references remaining in the table.
1023 neigh_ifdown(&clip_tbl
, NULL
);
1027 next
= PRIV(dev
)->next
;
1028 unregister_netdev(dev
);
1033 /* Now it is safe to fully shutdown whole table. */
1034 neigh_table_clear(&clip_tbl
);
1036 clip_tbl_hook
= NULL
;
1039 module_init(atm_clip_init
);
1040 module_exit(atm_clip_exit
);
1042 MODULE_LICENSE("GPL");