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/capability.h>
23 #include <linux/ip.h> /* for net/route.h */
24 #include <linux/in.h> /* for struct sockaddr_in */
25 #include <linux/if.h> /* for IFF_UP */
26 #include <linux/inetdevice.h>
27 #include <linux/bitops.h>
28 #include <linux/proc_fs.h>
29 #include <linux/seq_file.h>
30 #include <linux/rcupdate.h>
31 #include <linux/jhash.h>
32 #include <net/route.h> /* for struct rtable and routing */
33 #include <net/icmp.h> /* icmp_send */
34 #include <asm/param.h> /* for HZ */
35 #include <asm/byteorder.h> /* for htons etc. */
36 #include <asm/system.h> /* save/restore_flags */
37 #include <asm/uaccess.h>
38 #include <asm/atomic.h>
41 #include "resources.h"
43 #include <net/atmclip.h>
47 #define DPRINTK(format,args...) printk(format,##args)
49 #define DPRINTK(format,args...)
53 static struct net_device
*clip_devs
;
54 static struct atm_vcc
*atmarpd
;
55 static struct neigh_table clip_tbl
;
56 static struct timer_list idle_timer
;
57 static int start_timer
= 1;
60 static int to_atmarpd(enum atmarp_ctrl_type type
,int itf
,unsigned long ip
)
63 struct atmarp_ctrl
*ctrl
;
66 DPRINTK("to_atmarpd(%d)\n",type
);
67 if (!atmarpd
) return -EUNATCH
;
68 skb
= alloc_skb(sizeof(struct atmarp_ctrl
),GFP_ATOMIC
);
69 if (!skb
) return -ENOMEM
;
70 ctrl
= (struct atmarp_ctrl
*) skb_put(skb
,sizeof(struct atmarp_ctrl
));
74 atm_force_charge(atmarpd
,skb
->truesize
);
77 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
78 sk
->sk_data_ready(sk
, skb
->len
);
83 static void link_vcc(struct clip_vcc
*clip_vcc
,struct atmarp_entry
*entry
)
85 DPRINTK("link_vcc %p to entry %p (neigh %p)\n",clip_vcc
,entry
,
87 clip_vcc
->entry
= entry
;
88 clip_vcc
->xoff
= 0; /* @@@ may overrun buffer by one packet */
89 clip_vcc
->next
= entry
->vccs
;
90 entry
->vccs
= clip_vcc
;
91 entry
->neigh
->used
= jiffies
;
95 static void unlink_clip_vcc(struct clip_vcc
*clip_vcc
)
97 struct atmarp_entry
*entry
= clip_vcc
->entry
;
98 struct clip_vcc
**walk
;
101 printk(KERN_CRIT
"!clip_vcc->entry (clip_vcc %p)\n",clip_vcc
);
104 spin_lock_bh(&entry
->neigh
->dev
->xmit_lock
); /* block clip_start_xmit() */
105 entry
->neigh
->used
= jiffies
;
106 for (walk
= &entry
->vccs
; *walk
; walk
= &(*walk
)->next
)
107 if (*walk
== clip_vcc
) {
110 *walk
= clip_vcc
->next
; /* atomic */
111 clip_vcc
->entry
= NULL
;
113 netif_wake_queue(entry
->neigh
->dev
);
116 entry
->expires
= jiffies
-1;
117 /* force resolution or expiration */
118 error
= neigh_update(entry
->neigh
, NULL
, NUD_NONE
,
119 NEIGH_UPDATE_F_ADMIN
);
121 printk(KERN_CRIT
"unlink_clip_vcc: "
122 "neigh_update failed with %d\n",error
);
125 printk(KERN_CRIT
"ATMARP: unlink_clip_vcc failed (entry %p, vcc "
126 "0x%p)\n",entry
,clip_vcc
);
128 spin_unlock_bh(&entry
->neigh
->dev
->xmit_lock
);
131 /* The neighbour entry n->lock is held. */
132 static int neigh_check_cb(struct neighbour
*n
)
134 struct atmarp_entry
*entry
= NEIGH2ENTRY(n
);
137 for (cv
= entry
->vccs
; cv
; cv
= cv
->next
) {
138 unsigned long exp
= cv
->last_use
+ cv
->idle_timeout
;
140 if (cv
->idle_timeout
&& time_after(jiffies
, exp
)) {
141 DPRINTK("releasing vcc %p->%p of entry %p\n",
143 vcc_release_async(cv
->vcc
, -ETIMEDOUT
);
147 if (entry
->vccs
|| time_before(jiffies
, entry
->expires
))
150 if (atomic_read(&n
->refcnt
) > 1) {
153 DPRINTK("destruction postponed with ref %d\n",
154 atomic_read(&n
->refcnt
));
156 while ((skb
= skb_dequeue(&n
->arp_queue
)) != NULL
)
162 DPRINTK("expired neigh %p\n",n
);
166 static void idle_timer_check(unsigned long dummy
)
168 write_lock(&clip_tbl
.lock
);
169 __neigh_for_each_release(&clip_tbl
, neigh_check_cb
);
170 mod_timer(&idle_timer
, jiffies
+CLIP_CHECK_INTERVAL
*HZ
);
171 write_unlock(&clip_tbl
.lock
);
174 static int clip_arp_rcv(struct sk_buff
*skb
)
178 DPRINTK("clip_arp_rcv\n");
179 vcc
= ATM_SKB(skb
)->vcc
;
180 if (!vcc
|| !atm_charge(vcc
,skb
->truesize
)) {
181 dev_kfree_skb_any(skb
);
184 DPRINTK("pushing to %p\n",vcc
);
185 DPRINTK("using %p\n",CLIP_VCC(vcc
)->old_push
);
186 CLIP_VCC(vcc
)->old_push(vcc
,skb
);
190 static const unsigned char llc_oui
[] = {
191 0xaa, /* DSAP: non-ISO */
192 0xaa, /* SSAP: non-ISO */
193 0x03, /* Ctrl: Unnumbered Information Command PDU */
194 0x00, /* OUI: EtherType */
198 static void clip_push(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
200 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
202 DPRINTK("clip push\n");
204 DPRINTK("removing VCC %p\n",clip_vcc
);
205 if (clip_vcc
->entry
) unlink_clip_vcc(clip_vcc
);
206 clip_vcc
->old_push(vcc
,NULL
); /* pass on the bad news */
210 atm_return(vcc
,skb
->truesize
);
211 skb
->dev
= clip_vcc
->entry
? clip_vcc
->entry
->neigh
->dev
: clip_devs
;
212 /* clip_vcc->entry == NULL if we don't have an IP address yet */
214 dev_kfree_skb_any(skb
);
217 ATM_SKB(skb
)->vcc
= vcc
;
218 skb
->mac
.raw
= skb
->data
;
219 if (!clip_vcc
->encap
|| skb
->len
< RFC1483LLC_LEN
|| memcmp(skb
->data
,
220 llc_oui
,sizeof(llc_oui
))) skb
->protocol
= htons(ETH_P_IP
);
222 skb
->protocol
= ((u16
*) 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
));
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.
245 static void clip_pop(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
247 struct clip_vcc
*clip_vcc
= CLIP_VCC(vcc
);
248 struct net_device
*dev
= skb
->dev
;
252 DPRINTK("clip_pop(vcc %p)\n",vcc
);
253 clip_vcc
->old_pop(vcc
,skb
);
254 /* 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);
259 if (old
) netif_wake_queue(dev
);
261 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;
274 static void clip_neigh_solicit(struct neighbour
*neigh
,struct sk_buff
*skb
)
276 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n",neigh
,skb
);
277 to_atmarpd(act_need
,PRIV(neigh
->dev
)->number
,NEIGH2ENTRY(neigh
)->ip
);
281 static void clip_neigh_error(struct neighbour
*neigh
,struct sk_buff
*skb
)
283 #ifndef CONFIG_ATM_CLIP_NO_ICMP
284 icmp_send(skb
,ICMP_DEST_UNREACH
,ICMP_HOST_UNREACH
,0);
290 static struct neigh_ops clip_neigh_ops
= {
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
= __in_dev_get_rcu(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 .neigh_destructor
= clip_neigh_destroy
,
350 .base_reachable_time
= 30 * HZ
,
351 .retrans_time
= 1 * HZ
,
352 .gc_staletime
= 60 * HZ
,
353 .reachable_time
= 30 * HZ
,
354 .delay_probe_time
= 5 * HZ
,
358 .anycast_delay
= 1 * HZ
,
359 .proxy_delay
= (8 * HZ
) / 10,
363 .gc_interval
= 30 * HZ
,
370 /* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
373 * We play with the resolve flag: 0 and 1 have the usual meaning, but -1 means
374 * to allocate the neighbour entry but not to ask atmarpd for resolution. Also,
375 * don't increment the usage count. This is used to create entries in
380 static int clip_encap(struct atm_vcc
*vcc
,int mode
)
382 CLIP_VCC(vcc
)->encap
= mode
;
387 static int clip_start_xmit(struct sk_buff
*skb
,struct net_device
*dev
)
389 struct clip_priv
*clip_priv
= PRIV(dev
);
390 struct atmarp_entry
*entry
;
395 DPRINTK("clip_start_xmit (skb %p)\n",skb
);
397 printk(KERN_ERR
"clip_start_xmit: skb->dst == NULL\n");
399 clip_priv
->stats
.tx_dropped
++;
402 if (!skb
->dst
->neighbour
) {
404 skb
->dst
->neighbour
= clip_find_neighbour(skb
->dst
,1);
405 if (!skb
->dst
->neighbour
) {
406 dev_kfree_skb(skb
); /* lost that one */
407 clip_priv
->stats
.tx_dropped
++;
411 printk(KERN_ERR
"clip_start_xmit: NO NEIGHBOUR !\n");
413 clip_priv
->stats
.tx_dropped
++;
416 entry
= NEIGH2ENTRY(skb
->dst
->neighbour
);
418 if (time_after(jiffies
, entry
->expires
)) {
419 /* should be resolved */
420 entry
->expires
= jiffies
+ATMARP_RETRY_DELAY
*HZ
;
421 to_atmarpd(act_need
,PRIV(dev
)->number
,entry
->ip
);
423 if (entry
->neigh
->arp_queue
.qlen
< ATMARP_MAX_UNRES_PACKETS
)
424 skb_queue_tail(&entry
->neigh
->arp_queue
,skb
);
427 clip_priv
->stats
.tx_dropped
++;
431 DPRINTK("neigh %p, vccs %p\n",entry
,entry
->vccs
);
432 ATM_SKB(skb
)->vcc
= vcc
= entry
->vccs
->vcc
;
433 DPRINTK("using neighbour %p, vcc %p\n",skb
->dst
->neighbour
,vcc
);
434 if (entry
->vccs
->encap
) {
437 here
= skb_push(skb
,RFC1483LLC_LEN
);
438 memcpy(here
,llc_oui
,sizeof(llc_oui
));
439 ((u16
*) here
)[3] = skb
->protocol
;
441 atomic_add(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
442 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
443 entry
->vccs
->last_use
= jiffies
;
444 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n",skb
,vcc
,vcc
->dev
);
445 old
= xchg(&entry
->vccs
->xoff
,1); /* assume XOFF ... */
447 printk(KERN_WARNING
"clip_start_xmit: XOFF->XOFF transition\n");
450 clip_priv
->stats
.tx_packets
++;
451 clip_priv
->stats
.tx_bytes
+= skb
->len
;
452 (void) vcc
->send(vcc
,skb
);
453 if (atm_may_send(vcc
,0)) {
454 entry
->vccs
->xoff
= 0;
457 spin_lock_irqsave(&clip_priv
->xoff_lock
,flags
);
458 netif_stop_queue(dev
); /* XOFF -> throttle immediately */
460 if (!entry
->vccs
->xoff
)
461 netif_start_queue(dev
);
462 /* Oh, we just raced with clip_pop. netif_start_queue should be
463 good enough, because nothing should really be asleep because
464 of the brief netif_stop_queue. If this isn't true or if it
465 changes, use netif_wake_queue instead. */
466 spin_unlock_irqrestore(&clip_priv
->xoff_lock
,flags
);
471 static struct net_device_stats
*clip_get_stats(struct net_device
*dev
)
473 return &PRIV(dev
)->stats
;
477 static int clip_mkip(struct atm_vcc
*vcc
,int timeout
)
479 struct clip_vcc
*clip_vcc
;
480 struct sk_buff_head copy
;
483 if (!vcc
->push
) return -EBADFD
;
484 clip_vcc
= kmalloc(sizeof(struct clip_vcc
),GFP_KERNEL
);
485 if (!clip_vcc
) return -ENOMEM
;
486 DPRINTK("mkip clip_vcc %p vcc %p\n",clip_vcc
,vcc
);
488 vcc
->user_back
= clip_vcc
;
489 set_bit(ATM_VF_IS_CLIP
, &vcc
->flags
);
490 clip_vcc
->entry
= NULL
;
493 clip_vcc
->last_use
= jiffies
;
494 clip_vcc
->idle_timeout
= timeout
*HZ
;
495 clip_vcc
->old_push
= vcc
->push
;
496 clip_vcc
->old_pop
= vcc
->pop
;
497 vcc
->push
= clip_push
;
499 skb_queue_head_init(©
);
500 skb_migrate(&sk_atm(vcc
)->sk_receive_queue
, ©
);
501 /* re-process everything received between connection setup and MKIP */
502 while ((skb
= skb_dequeue(©
)) != NULL
)
504 atm_return(vcc
,skb
->truesize
);
508 unsigned int len
= skb
->len
;
511 PRIV(skb
->dev
)->stats
.rx_packets
--;
512 PRIV(skb
->dev
)->stats
.rx_bytes
-= len
;
518 static int clip_setentry(struct atm_vcc
*vcc
,u32 ip
)
520 struct neighbour
*neigh
;
521 struct atmarp_entry
*entry
;
523 struct clip_vcc
*clip_vcc
;
524 struct flowi fl
= { .nl_u
= { .ip4_u
= { .daddr
= ip
, .tos
= 1 } } };
527 if (vcc
->push
!= clip_push
) {
528 printk(KERN_WARNING
"clip_setentry: non-CLIP VCC\n");
531 clip_vcc
= CLIP_VCC(vcc
);
533 if (!clip_vcc
->entry
) {
534 printk(KERN_ERR
"hiding hidden ATMARP entry\n");
537 DPRINTK("setentry: remove\n");
538 unlink_clip_vcc(clip_vcc
);
541 error
= ip_route_output_key(&rt
,&fl
);
542 if (error
) return error
;
543 neigh
= __neigh_lookup(&clip_tbl
,&ip
,rt
->u
.dst
.dev
,1);
547 entry
= NEIGH2ENTRY(neigh
);
548 if (entry
!= clip_vcc
->entry
) {
549 if (!clip_vcc
->entry
) DPRINTK("setentry: add\n");
551 DPRINTK("setentry: update\n");
552 unlink_clip_vcc(clip_vcc
);
554 link_vcc(clip_vcc
,entry
);
556 error
= neigh_update(neigh
, llc_oui
, NUD_PERMANENT
,
557 NEIGH_UPDATE_F_OVERRIDE
|NEIGH_UPDATE_F_ADMIN
);
558 neigh_release(neigh
);
563 static void clip_setup(struct net_device
*dev
)
565 dev
->hard_start_xmit
= clip_start_xmit
;
567 dev
->get_stats
= clip_get_stats
;
568 dev
->type
= ARPHRD_ATM
;
569 dev
->hard_header_len
= RFC1483LLC_LEN
;
570 dev
->mtu
= RFC1626_MTU
;
571 dev
->tx_queue_len
= 100; /* "normal" queue (packets) */
572 /* When using a "real" qdisc, the qdisc determines the queue */
573 /* length. tx_queue_len is only used for the default case, */
574 /* without any more elaborate queuing. 100 is a reasonable */
575 /* compromise between decent burst-tolerance and protection */
576 /* against memory hogs. */
580 static int clip_create(int number
)
582 struct net_device
*dev
;
583 struct clip_priv
*clip_priv
;
587 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
588 if (PRIV(dev
)->number
== number
) return -EEXIST
;
592 for (dev
= clip_devs
; dev
; dev
= PRIV(dev
)->next
)
593 if (PRIV(dev
)->number
>= number
)
594 number
= PRIV(dev
)->number
+1;
596 dev
= alloc_netdev(sizeof(struct clip_priv
), "", clip_setup
);
599 clip_priv
= PRIV(dev
);
600 sprintf(dev
->name
,"atm%d",number
);
601 spin_lock_init(&clip_priv
->xoff_lock
);
602 clip_priv
->number
= number
;
603 error
= register_netdev(dev
);
608 clip_priv
->next
= clip_devs
;
610 DPRINTK("registered (net:%s)\n",dev
->name
);
615 static int clip_device_event(struct notifier_block
*this,unsigned long event
,
618 /* ignore non-CLIP devices */
619 if (((struct net_device
*) dev
)->type
!= ARPHRD_ATM
||
620 ((struct net_device
*) dev
)->hard_start_xmit
!= clip_start_xmit
)
624 DPRINTK("clip_device_event NETDEV_UP\n");
625 (void) to_atmarpd(act_up
,PRIV(dev
)->number
,0);
627 case NETDEV_GOING_DOWN
:
628 DPRINTK("clip_device_event NETDEV_DOWN\n");
629 (void) to_atmarpd(act_down
,PRIV(dev
)->number
,0);
632 case NETDEV_CHANGEMTU
:
633 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
634 (void) to_atmarpd(act_change
,PRIV(dev
)->number
,0);
637 case NETDEV_REGISTER
:
639 DPRINTK("clip_device_event %ld\n",event
);
643 printk(KERN_WARNING
"clip_device_event: unknown event "
651 static int clip_inet_event(struct notifier_block
*this,unsigned long event
,
654 struct in_device
*in_dev
;
656 in_dev
= ((struct in_ifaddr
*) ifa
)->ifa_dev
;
657 if (!in_dev
|| !in_dev
->dev
) {
658 printk(KERN_WARNING
"clip_inet_event: no device\n");
662 * Transitions are of the down-change-up type, so it's sufficient to
663 * handle the change on up.
665 if (event
!= NETDEV_UP
) return NOTIFY_DONE
;
666 return clip_device_event(this,NETDEV_CHANGE
,in_dev
->dev
);
670 static struct notifier_block clip_dev_notifier
= {
678 static struct notifier_block clip_inet_notifier
= {
686 static void atmarpd_close(struct atm_vcc
*vcc
)
688 DPRINTK("atmarpd_close\n");
689 atmarpd
= NULL
; /* assumed to be atomic */
691 unregister_inetaddr_notifier(&clip_inet_notifier
);
692 unregister_netdevice_notifier(&clip_dev_notifier
);
693 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
694 printk(KERN_ERR
"atmarpd_close: closing with requests "
696 skb_queue_purge(&sk_atm(vcc
)->sk_receive_queue
);
698 module_put(THIS_MODULE
);
702 static struct atmdev_ops atmarpd_dev_ops
= {
703 .close
= atmarpd_close
707 static struct atm_dev atmarpd_dev
= {
708 .ops
= &atmarpd_dev_ops
,
711 .lock
= SPIN_LOCK_UNLOCKED
715 static int atm_init_atmarp(struct atm_vcc
*vcc
)
717 if (atmarpd
) return -EADDRINUSE
;
720 init_timer(&idle_timer
);
721 idle_timer
.expires
= jiffies
+CLIP_CHECK_INTERVAL
*HZ
;
722 idle_timer
.function
= idle_timer_check
;
723 add_timer(&idle_timer
);
726 set_bit(ATM_VF_META
,&vcc
->flags
);
727 set_bit(ATM_VF_READY
,&vcc
->flags
);
728 /* allow replies and avoid getting closed if signaling dies */
729 vcc
->dev
= &atmarpd_dev
;
730 vcc_insert_socket(sk_atm(vcc
));
732 vcc
->pop
= NULL
; /* crash */
733 vcc
->push_oam
= NULL
; /* crash */
734 if (register_netdevice_notifier(&clip_dev_notifier
))
735 printk(KERN_ERR
"register_netdevice_notifier failed\n");
736 if (register_inetaddr_notifier(&clip_inet_notifier
))
737 printk(KERN_ERR
"register_inetaddr_notifier failed\n");
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
, 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
) ||
834 if (clip_vcc
== SEQ_NO_VCC_TOKEN
)
835 exp
= entry
->neigh
->used
;
837 exp
= clip_vcc
->last_use
;
839 exp
= (jiffies
- exp
) / HZ
;
841 seq_printf(seq
, "%-6s%-4s%-4s%5ld ",
844 llc
? "LLC" : "NULL",
847 off
= scnprintf(buf
, sizeof(buf
) - 1, "%d.%d.%d.%d",
852 seq_printf(seq
, "%s", buf
);
854 if (clip_vcc
== SEQ_NO_VCC_TOKEN
) {
855 if (time_before(jiffies
, entry
->expires
))
856 seq_printf(seq
, "(resolving)\n");
858 seq_printf(seq
, "(expired, ref %d)\n",
859 atomic_read(&entry
->neigh
->refcnt
));
861 seq_printf(seq
, "%d.%d.%d\n",
862 clip_vcc
->vcc
->dev
->number
,
866 svc_addr(seq
, &clip_vcc
->vcc
->remote
);
871 struct clip_seq_state
{
872 /* This member must be first. */
873 struct neigh_seq_state ns
;
875 /* Local to clip specific iteration. */
876 struct clip_vcc
*vcc
;
879 static struct clip_vcc
*clip_seq_next_vcc(struct atmarp_entry
*e
,
880 struct clip_vcc
*curr
)
885 return SEQ_NO_VCC_TOKEN
;
888 if (curr
== SEQ_NO_VCC_TOKEN
)
896 static void *clip_seq_vcc_walk(struct clip_seq_state
*state
,
897 struct atmarp_entry
*e
, loff_t
*pos
)
899 struct clip_vcc
*vcc
= state
->vcc
;
901 vcc
= clip_seq_next_vcc(e
, vcc
);
902 if (vcc
&& pos
!= NULL
) {
904 vcc
= clip_seq_next_vcc(e
, vcc
);
915 static void *clip_seq_sub_iter(struct neigh_seq_state
*_state
,
916 struct neighbour
*n
, loff_t
*pos
)
918 struct clip_seq_state
*state
= (struct clip_seq_state
*) _state
;
920 return clip_seq_vcc_walk(state
, NEIGH2ENTRY(n
), pos
);
923 static void *clip_seq_start(struct seq_file
*seq
, loff_t
*pos
)
925 return neigh_seq_start(seq
, pos
, &clip_tbl
, NEIGH_SEQ_NEIGH_ONLY
);
928 static int clip_seq_show(struct seq_file
*seq
, void *v
)
930 static char atm_arp_banner
[] =
931 "IPitf TypeEncp Idle IP address ATM address\n";
933 if (v
== SEQ_START_TOKEN
) {
934 seq_puts(seq
, atm_arp_banner
);
936 struct clip_seq_state
*state
= seq
->private;
937 struct neighbour
*n
= v
;
938 struct clip_vcc
*vcc
= state
->vcc
;
940 atmarp_info(seq
, n
->dev
, NEIGH2ENTRY(n
), vcc
);
945 static struct seq_operations arp_seq_ops
= {
946 .start
= clip_seq_start
,
947 .next
= neigh_seq_next
,
948 .stop
= neigh_seq_stop
,
949 .show
= clip_seq_show
,
952 static int arp_seq_open(struct inode
*inode
, struct file
*file
)
954 struct clip_seq_state
*state
;
955 struct seq_file
*seq
;
958 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
963 memset(state
, 0, sizeof(*state
));
964 state
->ns
.neigh_sub_iter
= clip_seq_sub_iter
;
966 rc
= seq_open(file
, &arp_seq_ops
);
970 seq
= file
->private_data
;
971 seq
->private = state
;
980 static struct file_operations arp_seq_fops
= {
981 .open
= arp_seq_open
,
984 .release
= seq_release_private
,
989 static int __init
atm_clip_init(void)
991 neigh_table_init(&clip_tbl
);
993 clip_tbl_hook
= &clip_tbl
;
994 register_atm_ioctl(&clip_ioctl_ops
);
996 #ifdef CONFIG_PROC_FS
998 struct proc_dir_entry
*p
;
1000 p
= create_proc_entry("arp", S_IRUGO
, atm_proc_root
);
1002 p
->proc_fops
= &arp_seq_fops
;
1009 static void __exit
atm_clip_exit(void)
1011 struct net_device
*dev
, *next
;
1013 remove_proc_entry("arp", atm_proc_root
);
1015 deregister_atm_ioctl(&clip_ioctl_ops
);
1017 /* First, stop the idle timer, so it stops banging
1020 if (start_timer
== 0)
1021 del_timer(&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
);
1046 MODULE_LICENSE("GPL");