blob: 121bf6f4914897713f0c9672e41b39f54501fd3b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* net/atm/clip.c - RFC1577 Classical IP over ATM */
2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#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>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080020#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#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>
Randy Dunlap4bdbf6c2006-07-03 19:47:27 -070026#include <linux/poison.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#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>
38
39#include "common.h"
40#include "resources.h"
41#include "ipcommon.h"
42#include <net/atmclip.h>
43
44
45#if 0
46#define DPRINTK(format,args...) printk(format,##args)
47#else
48#define DPRINTK(format,args...)
49#endif
50
51
52static struct net_device *clip_devs;
53static struct atm_vcc *atmarpd;
54static struct neigh_table clip_tbl;
55static struct timer_list idle_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070057static int to_atmarpd(enum atmarp_ctrl_type type, int itf, unsigned long ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 struct sock *sk;
60 struct atmarp_ctrl *ctrl;
61 struct sk_buff *skb;
62
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070063 DPRINTK("to_atmarpd(%d)\n", type);
64 if (!atmarpd)
65 return -EUNATCH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 skb = alloc_skb(sizeof(struct atmarp_ctrl),GFP_ATOMIC);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070067 if (!skb)
68 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 ctrl = (struct atmarp_ctrl *) skb_put(skb,sizeof(struct atmarp_ctrl));
70 ctrl->type = type;
71 ctrl->itf_num = itf;
72 ctrl->ip = ip;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070073 atm_force_charge(atmarpd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 sk = sk_atm(atmarpd);
76 skb_queue_tail(&sk->sk_receive_queue, skb);
77 sk->sk_data_ready(sk, skb->len);
78 return 0;
79}
80
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070081static void link_vcc(struct clip_vcc *clip_vcc, struct atmarp_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070083 DPRINTK("link_vcc %p to entry %p (neigh %p)\n", clip_vcc, entry,
84 entry->neigh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 clip_vcc->entry = entry;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070086 clip_vcc->xoff = 0; /* @@@ may overrun buffer by one packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 clip_vcc->next = entry->vccs;
88 entry->vccs = clip_vcc;
89 entry->neigh->used = jiffies;
90}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static void unlink_clip_vcc(struct clip_vcc *clip_vcc)
93{
94 struct atmarp_entry *entry = clip_vcc->entry;
95 struct clip_vcc **walk;
96
97 if (!entry) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -070098 printk(KERN_CRIT "!clip_vcc->entry (clip_vcc %p)\n", clip_vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return;
100 }
Herbert Xu932ff272006-06-09 12:20:56 -0700101 netif_tx_lock_bh(entry->neigh->dev); /* block clip_start_xmit() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 entry->neigh->used = jiffies;
103 for (walk = &entry->vccs; *walk; walk = &(*walk)->next)
104 if (*walk == clip_vcc) {
105 int error;
106
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700107 *walk = clip_vcc->next; /* atomic */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 clip_vcc->entry = NULL;
109 if (clip_vcc->xoff)
110 netif_wake_queue(entry->neigh->dev);
111 if (entry->vccs)
112 goto out;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700113 entry->expires = jiffies - 1;
114 /* force resolution or expiration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 error = neigh_update(entry->neigh, NULL, NUD_NONE,
116 NEIGH_UPDATE_F_ADMIN);
117 if (error)
118 printk(KERN_CRIT "unlink_clip_vcc: "
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700119 "neigh_update failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 goto out;
121 }
122 printk(KERN_CRIT "ATMARP: unlink_clip_vcc failed (entry %p, vcc "
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700123 "0x%p)\n", entry, clip_vcc);
124 out:
Herbert Xu932ff272006-06-09 12:20:56 -0700125 netif_tx_unlock_bh(entry->neigh->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
128/* The neighbour entry n->lock is held. */
129static int neigh_check_cb(struct neighbour *n)
130{
131 struct atmarp_entry *entry = NEIGH2ENTRY(n);
132 struct clip_vcc *cv;
133
134 for (cv = entry->vccs; cv; cv = cv->next) {
135 unsigned long exp = cv->last_use + cv->idle_timeout;
136
137 if (cv->idle_timeout && time_after(jiffies, exp)) {
138 DPRINTK("releasing vcc %p->%p of entry %p\n",
139 cv, cv->vcc, entry);
140 vcc_release_async(cv->vcc, -ETIMEDOUT);
141 }
142 }
143
144 if (entry->vccs || time_before(jiffies, entry->expires))
145 return 0;
146
147 if (atomic_read(&n->refcnt) > 1) {
148 struct sk_buff *skb;
149
150 DPRINTK("destruction postponed with ref %d\n",
151 atomic_read(&n->refcnt));
152
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700153 while ((skb = skb_dequeue(&n->arp_queue)) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 dev_kfree_skb(skb);
155
156 return 0;
157 }
158
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700159 DPRINTK("expired neigh %p\n", n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return 1;
161}
162
163static void idle_timer_check(unsigned long dummy)
164{
165 write_lock(&clip_tbl.lock);
166 __neigh_for_each_release(&clip_tbl, neigh_check_cb);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700167 mod_timer(&idle_timer, jiffies + CLIP_CHECK_INTERVAL * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 write_unlock(&clip_tbl.lock);
169}
170
171static int clip_arp_rcv(struct sk_buff *skb)
172{
173 struct atm_vcc *vcc;
174
175 DPRINTK("clip_arp_rcv\n");
176 vcc = ATM_SKB(skb)->vcc;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700177 if (!vcc || !atm_charge(vcc, skb->truesize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 dev_kfree_skb_any(skb);
179 return 0;
180 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700181 DPRINTK("pushing to %p\n", vcc);
182 DPRINTK("using %p\n", CLIP_VCC(vcc)->old_push);
183 CLIP_VCC(vcc)->old_push(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return 0;
185}
186
187static const unsigned char llc_oui[] = {
188 0xaa, /* DSAP: non-ISO */
189 0xaa, /* SSAP: non-ISO */
190 0x03, /* Ctrl: Unnumbered Information Command PDU */
191 0x00, /* OUI: EtherType */
192 0x00,
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700193 0x00
194};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700196static void clip_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
199
200 DPRINTK("clip push\n");
201 if (!skb) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700202 DPRINTK("removing VCC %p\n", clip_vcc);
203 if (clip_vcc->entry)
204 unlink_clip_vcc(clip_vcc);
205 clip_vcc->old_push(vcc, NULL); /* pass on the bad news */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 kfree(clip_vcc);
207 return;
208 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700209 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 skb->dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : clip_devs;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700211 /* clip_vcc->entry == NULL if we don't have an IP address yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 if (!skb->dev) {
213 dev_kfree_skb_any(skb);
214 return;
215 }
216 ATM_SKB(skb)->vcc = vcc;
217 skb->mac.raw = skb->data;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700218 if (!clip_vcc->encap
219 || skb->len < RFC1483LLC_LEN
220 || memcmp(skb->data, llc_oui, sizeof (llc_oui)))
221 skb->protocol = htons(ETH_P_IP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 else {
223 skb->protocol = ((u16 *) skb->data)[3];
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700224 skb_pull(skb, RFC1483LLC_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (skb->protocol == htons(ETH_P_ARP)) {
226 PRIV(skb->dev)->stats.rx_packets++;
227 PRIV(skb->dev)->stats.rx_bytes += skb->len;
228 clip_arp_rcv(skb);
229 return;
230 }
231 }
232 clip_vcc->last_use = jiffies;
233 PRIV(skb->dev)->stats.rx_packets++;
234 PRIV(skb->dev)->stats.rx_bytes += skb->len;
235 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
236 netif_rx(skb);
237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
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.
242 */
243
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700244static void clip_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
247 struct net_device *dev = skb->dev;
248 int old;
249 unsigned long flags;
250
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700251 DPRINTK("clip_pop(vcc %p)\n", vcc);
252 clip_vcc->old_pop(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* skb->dev == NULL in outbound ARP packets */
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700254 if (!dev)
255 return;
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)
260 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700262 spin_unlock_irqrestore(&PRIV(dev)->xoff_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265static void clip_neigh_destroy(struct neighbour *neigh)
266{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700267 DPRINTK("clip_neigh_destroy (neigh %p)\n", neigh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (NEIGH2ENTRY(neigh)->vccs)
269 printk(KERN_CRIT "clip_neigh_destroy: vccs != NULL !!!\n");
Randy Dunlap4bdbf6c2006-07-03 19:47:27 -0700270 NEIGH2ENTRY(neigh)->vccs = (void *) NEIGHBOR_DEAD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700273static void clip_neigh_solicit(struct neighbour *neigh, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700275 DPRINTK("clip_neigh_solicit (neigh %p, skb %p)\n", neigh, skb);
276 to_atmarpd(act_need, PRIV(neigh->dev)->number, NEIGH2ENTRY(neigh)->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700279static void clip_neigh_error(struct neighbour *neigh, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281#ifndef CONFIG_ATM_CLIP_NO_ICMP
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700282 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#endif
284 kfree_skb(skb);
285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287static struct neigh_ops clip_neigh_ops = {
288 .family = AF_INET,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 .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,
295};
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static int clip_constructor(struct neighbour *neigh)
298{
299 struct atmarp_entry *entry = NEIGH2ENTRY(neigh);
300 struct net_device *dev = neigh->dev;
301 struct in_device *in_dev;
302 struct neigh_parms *parms;
303
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700304 DPRINTK("clip_constructor (neigh %p, entry %p)\n", neigh, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 neigh->type = inet_addr_type(entry->ip);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700306 if (neigh->type != RTN_UNICAST)
307 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -0700310 in_dev = __in_dev_get_rcu(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (!in_dev) {
312 rcu_read_unlock();
313 return -EINVAL;
314 }
315
316 parms = in_dev->arp_parms;
317 __neigh_parms_put(neigh->parms);
318 neigh->parms = neigh_parms_clone(parms);
319 rcu_read_unlock();
320
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;
325 entry->vccs = NULL;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700326 entry->expires = jiffies - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return 0;
328}
329
330static u32 clip_hash(const void *pkey, const struct net_device *dev)
331{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700332 return jhash_2words(*(u32 *) pkey, dev->ifindex, clip_tbl.hash_rnd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
335static struct neigh_table clip_tbl = {
336 .family = AF_INET,
337 .entry_size = sizeof(struct neighbour)+sizeof(struct atmarp_entry),
338 .key_len = 4,
339 .hash = clip_hash,
340 .constructor = clip_constructor,
341 .id = "clip_arp_cache",
342
343 /* parameters are copied from ARP ... */
344 .parms = {
345 .tbl = &clip_tbl,
David S. Milleraa837b52006-03-20 22:30:23 -0800346 .neigh_destructor = clip_neigh_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 .base_reachable_time = 30 * HZ,
348 .retrans_time = 1 * HZ,
349 .gc_staletime = 60 * HZ,
350 .reachable_time = 30 * HZ,
351 .delay_probe_time = 5 * HZ,
352 .queue_len = 3,
353 .ucast_probes = 3,
354 .mcast_probes = 3,
355 .anycast_delay = 1 * HZ,
356 .proxy_delay = (8 * HZ) / 10,
357 .proxy_qlen = 64,
358 .locktime = 1 * HZ,
359 },
360 .gc_interval = 30 * HZ,
361 .gc_thresh1 = 128,
362 .gc_thresh2 = 512,
363 .gc_thresh3 = 1024,
364};
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/* @@@ copy bh locking from arp.c -- need to bh-enable atm code before */
367
368/*
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
372 * clip_setentry.
373 */
374
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700375static int clip_encap(struct atm_vcc *vcc, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 CLIP_VCC(vcc)->encap = mode;
378 return 0;
379}
380
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700381static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383 struct clip_priv *clip_priv = PRIV(dev);
384 struct atmarp_entry *entry;
385 struct atm_vcc *vcc;
386 int old;
387 unsigned long flags;
388
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700389 DPRINTK("clip_start_xmit (skb %p)\n", skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (!skb->dst) {
391 printk(KERN_ERR "clip_start_xmit: skb->dst == NULL\n");
392 dev_kfree_skb(skb);
393 clip_priv->stats.tx_dropped++;
394 return 0;
395 }
396 if (!skb->dst->neighbour) {
397#if 0
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700398 skb->dst->neighbour = clip_find_neighbour(skb->dst, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!skb->dst->neighbour) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700400 dev_kfree_skb(skb); /* lost that one */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 clip_priv->stats.tx_dropped++;
402 return 0;
403 }
404#endif
405 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n");
406 dev_kfree_skb(skb);
407 clip_priv->stats.tx_dropped++;
408 return 0;
409 }
410 entry = NEIGH2ENTRY(skb->dst->neighbour);
411 if (!entry->vccs) {
412 if (time_after(jiffies, entry->expires)) {
413 /* should be resolved */
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700414 entry->expires = jiffies + ATMARP_RETRY_DELAY * HZ;
415 to_atmarpd(act_need, PRIV(dev)->number, entry->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417 if (entry->neigh->arp_queue.qlen < ATMARP_MAX_UNRES_PACKETS)
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700418 skb_queue_tail(&entry->neigh->arp_queue, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 else {
420 dev_kfree_skb(skb);
421 clip_priv->stats.tx_dropped++;
422 }
423 return 0;
424 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700425 DPRINTK("neigh %p, vccs %p\n", entry, entry->vccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700427 DPRINTK("using neighbour %p, vcc %p\n", skb->dst->neighbour, vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 if (entry->vccs->encap) {
429 void *here;
430
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700431 here = skb_push(skb, RFC1483LLC_LEN);
432 memcpy(here, llc_oui, sizeof(llc_oui));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 ((u16 *) here)[3] = skb->protocol;
434 }
435 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
436 ATM_SKB(skb)->atm_options = vcc->atm_options;
437 entry->vccs->last_use = jiffies;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700438 DPRINTK("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev);
439 old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 if (old) {
441 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n");
442 return 0;
443 }
444 clip_priv->stats.tx_packets++;
445 clip_priv->stats.tx_bytes += skb->len;
Stephen Hemminger5ff765f2006-04-14 16:00:59 -0700446 vcc->send(vcc, skb);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700447 if (atm_may_send(vcc, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 entry->vccs->xoff = 0;
449 return 0;
450 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700451 spin_lock_irqsave(&clip_priv->xoff_lock, flags);
452 netif_stop_queue(dev); /* XOFF -> throttle immediately */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 barrier();
454 if (!entry->vccs->xoff)
455 netif_start_queue(dev);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700456 /* Oh, we just raced with clip_pop. netif_start_queue should be
457 good enough, because nothing should really be asleep because
458 of the brief netif_stop_queue. If this isn't true or if it
459 changes, use netif_wake_queue instead. */
460 spin_unlock_irqrestore(&clip_priv->xoff_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return 0;
462}
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464static struct net_device_stats *clip_get_stats(struct net_device *dev)
465{
466 return &PRIV(dev)->stats;
467}
468
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700469static int clip_mkip(struct atm_vcc *vcc, int timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 struct clip_vcc *clip_vcc;
472 struct sk_buff_head copy;
473 struct sk_buff *skb;
474
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700475 if (!vcc->push)
476 return -EBADFD;
477 clip_vcc = kmalloc(sizeof(struct clip_vcc), GFP_KERNEL);
478 if (!clip_vcc)
479 return -ENOMEM;
480 DPRINTK("mkip clip_vcc %p vcc %p\n", clip_vcc, vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 clip_vcc->vcc = vcc;
482 vcc->user_back = clip_vcc;
483 set_bit(ATM_VF_IS_CLIP, &vcc->flags);
484 clip_vcc->entry = NULL;
485 clip_vcc->xoff = 0;
486 clip_vcc->encap = 1;
487 clip_vcc->last_use = jiffies;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700488 clip_vcc->idle_timeout = timeout * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 clip_vcc->old_push = vcc->push;
490 clip_vcc->old_pop = vcc->pop;
491 vcc->push = clip_push;
492 vcc->pop = clip_pop;
493 skb_queue_head_init(&copy);
494 skb_migrate(&sk_atm(vcc)->sk_receive_queue, &copy);
495 /* re-process everything received between connection setup and MKIP */
496 while ((skb = skb_dequeue(&copy)) != NULL)
497 if (!clip_devs) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700498 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 kfree_skb(skb);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700500 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 unsigned int len = skb->len;
502
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700503 clip_push(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 PRIV(skb->dev)->stats.rx_packets--;
505 PRIV(skb->dev)->stats.rx_bytes -= len;
506 }
507 return 0;
508}
509
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700510static int clip_setentry(struct atm_vcc *vcc, u32 ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
512 struct neighbour *neigh;
513 struct atmarp_entry *entry;
514 int error;
515 struct clip_vcc *clip_vcc;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700516 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = ip, .tos = 1}} };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 struct rtable *rt;
518
519 if (vcc->push != clip_push) {
520 printk(KERN_WARNING "clip_setentry: non-CLIP VCC\n");
521 return -EBADF;
522 }
523 clip_vcc = CLIP_VCC(vcc);
524 if (!ip) {
525 if (!clip_vcc->entry) {
526 printk(KERN_ERR "hiding hidden ATMARP entry\n");
527 return 0;
528 }
529 DPRINTK("setentry: remove\n");
530 unlink_clip_vcc(clip_vcc);
531 return 0;
532 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700533 error = ip_route_output_key(&rt, &fl);
534 if (error)
535 return error;
536 neigh = __neigh_lookup(&clip_tbl, &ip, rt->u.dst.dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 ip_rt_put(rt);
538 if (!neigh)
539 return -ENOMEM;
540 entry = NEIGH2ENTRY(neigh);
541 if (entry != clip_vcc->entry) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700542 if (!clip_vcc->entry)
543 DPRINTK("setentry: add\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 else {
545 DPRINTK("setentry: update\n");
546 unlink_clip_vcc(clip_vcc);
547 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700548 link_vcc(clip_vcc, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700550 error = neigh_update(neigh, llc_oui, NUD_PERMANENT,
551 NEIGH_UPDATE_F_OVERRIDE | NEIGH_UPDATE_F_ADMIN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 neigh_release(neigh);
553 return error;
554}
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556static void clip_setup(struct net_device *dev)
557{
558 dev->hard_start_xmit = clip_start_xmit;
559 /* sg_xmit ... */
560 dev->get_stats = clip_get_stats;
561 dev->type = ARPHRD_ATM;
562 dev->hard_header_len = RFC1483LLC_LEN;
563 dev->mtu = RFC1626_MTU;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700564 dev->tx_queue_len = 100; /* "normal" queue (packets) */
565 /* When using a "real" qdisc, the qdisc determines the queue */
566 /* length. tx_queue_len is only used for the default case, */
567 /* without any more elaborate queuing. 100 is a reasonable */
568 /* compromise between decent burst-tolerance and protection */
569 /* against memory hogs. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572static int clip_create(int number)
573{
574 struct net_device *dev;
575 struct clip_priv *clip_priv;
576 int error;
577
578 if (number != -1) {
579 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700580 if (PRIV(dev)->number == number)
581 return -EEXIST;
582 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 number = 0;
584 for (dev = clip_devs; dev; dev = PRIV(dev)->next)
585 if (PRIV(dev)->number >= number)
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700586 number = PRIV(dev)->number + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588 dev = alloc_netdev(sizeof(struct clip_priv), "", clip_setup);
589 if (!dev)
590 return -ENOMEM;
591 clip_priv = PRIV(dev);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700592 sprintf(dev->name, "atm%d", number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 spin_lock_init(&clip_priv->xoff_lock);
594 clip_priv->number = number;
595 error = register_netdev(dev);
596 if (error) {
597 free_netdev(dev);
598 return error;
599 }
600 clip_priv->next = clip_devs;
601 clip_devs = dev;
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700602 DPRINTK("registered (net:%s)\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 return number;
604}
605
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700606static int clip_device_event(struct notifier_block *this, unsigned long event,
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700607 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700609 struct net_device *dev = arg;
610
611 if (event == NETDEV_UNREGISTER) {
612 neigh_ifdown(&clip_tbl, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return NOTIFY_DONE;
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700614 }
615
616 /* ignore non-CLIP devices */
617 if (dev->type != ARPHRD_ATM || dev->hard_start_xmit != clip_start_xmit)
618 return NOTIFY_DONE;
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 switch (event) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700621 case NETDEV_UP:
622 DPRINTK("clip_device_event NETDEV_UP\n");
Stephen Hemminger5ff765f2006-04-14 16:00:59 -0700623 to_atmarpd(act_up, PRIV(dev)->number, 0);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700624 break;
625 case NETDEV_GOING_DOWN:
626 DPRINTK("clip_device_event NETDEV_DOWN\n");
Stephen Hemminger5ff765f2006-04-14 16:00:59 -0700627 to_atmarpd(act_down, PRIV(dev)->number, 0);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700628 break;
629 case NETDEV_CHANGE:
630 case NETDEV_CHANGEMTU:
631 DPRINTK("clip_device_event NETDEV_CHANGE*\n");
Stephen Hemminger5ff765f2006-04-14 16:00:59 -0700632 to_atmarpd(act_change, PRIV(dev)->number, 0);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700633 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635 return NOTIFY_DONE;
636}
637
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700638static int clip_inet_event(struct notifier_block *this, unsigned long event,
639 void *ifa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
641 struct in_device *in_dev;
642
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700643 in_dev = ((struct in_ifaddr *)ifa)->ifa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (!in_dev || !in_dev->dev) {
645 printk(KERN_WARNING "clip_inet_event: no device\n");
646 return NOTIFY_DONE;
647 }
648 /*
649 * Transitions are of the down-change-up type, so it's sufficient to
650 * handle the change on up.
651 */
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700652 if (event != NETDEV_UP)
653 return NOTIFY_DONE;
654 return clip_device_event(this, NETDEV_CHANGE, in_dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657
658static struct notifier_block clip_dev_notifier = {
Stephen Hemminger5ff765f2006-04-14 16:00:59 -0700659 .notifier_call = clip_device_event,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660};
661
662
663
664static struct notifier_block clip_inet_notifier = {
Stephen Hemminger5ff765f2006-04-14 16:00:59 -0700665 .notifier_call = clip_inet_event,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666};
667
668
669
670static void atmarpd_close(struct atm_vcc *vcc)
671{
672 DPRINTK("atmarpd_close\n");
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700673
674 rtnl_lock();
675 atmarpd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700677 rtnl_unlock();
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 DPRINTK("(done)\n");
680 module_put(THIS_MODULE);
681}
682
683
684static struct atmdev_ops atmarpd_dev_ops = {
685 .close = atmarpd_close
686};
687
688
689static struct atm_dev atmarpd_dev = {
690 .ops = &atmarpd_dev_ops,
691 .type = "arpd",
692 .number = 999,
693 .lock = SPIN_LOCK_UNLOCKED
694};
695
696
697static int atm_init_atmarp(struct atm_vcc *vcc)
698{
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700699 rtnl_lock();
700 if (atmarpd) {
701 rtnl_unlock();
702 return -EADDRINUSE;
703 }
704
Stephen Hemminger2d907392006-04-14 15:56:02 -0700705 mod_timer(&idle_timer, jiffies+CLIP_CHECK_INTERVAL*HZ);
706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 atmarpd = vcc;
708 set_bit(ATM_VF_META,&vcc->flags);
709 set_bit(ATM_VF_READY,&vcc->flags);
710 /* allow replies and avoid getting closed if signaling dies */
711 vcc->dev = &atmarpd_dev;
712 vcc_insert_socket(sk_atm(vcc));
713 vcc->push = NULL;
714 vcc->pop = NULL; /* crash */
715 vcc->push_oam = NULL; /* crash */
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700716 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return 0;
718}
719
720static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
721{
722 struct atm_vcc *vcc = ATM_SD(sock);
723 int err = 0;
724
725 switch (cmd) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700726 case SIOCMKCLIP:
727 case ATMARPD_CTRL:
728 case ATMARP_MKIP:
729 case ATMARP_SETENTRY:
730 case ATMARP_ENCAP:
731 if (!capable(CAP_NET_ADMIN))
732 return -EPERM;
733 break;
734 default:
735 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737
738 switch (cmd) {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700739 case SIOCMKCLIP:
740 err = clip_create(arg);
741 break;
742 case ATMARPD_CTRL:
743 err = atm_init_atmarp(vcc);
744 if (!err) {
745 sock->state = SS_CONNECTED;
746 __module_get(THIS_MODULE);
747 }
748 break;
749 case ATMARP_MKIP:
750 err = clip_mkip(vcc, arg);
751 break;
752 case ATMARP_SETENTRY:
753 err = clip_setentry(vcc, arg);
754 break;
755 case ATMARP_ENCAP:
756 err = clip_encap(vcc, arg);
757 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759 return err;
760}
761
762static struct atm_ioctl clip_ioctl_ops = {
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700763 .owner = THIS_MODULE,
764 .ioctl = clip_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765};
766
767#ifdef CONFIG_PROC_FS
768
769static void svc_addr(struct seq_file *seq, struct sockaddr_atmsvc *addr)
770{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700771 static int code[] = { 1, 2, 10, 6, 1, 0 };
772 static int e164[] = { 1, 8, 4, 6, 1, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 if (*addr->sas_addr.pub) {
775 seq_printf(seq, "%s", addr->sas_addr.pub);
776 if (*addr->sas_addr.prv)
777 seq_putc(seq, '+');
778 } else if (!*addr->sas_addr.prv) {
779 seq_printf(seq, "%s", "(none)");
780 return;
781 }
782 if (*addr->sas_addr.prv) {
783 unsigned char *prv = addr->sas_addr.prv;
784 int *fields;
785 int i, j;
786
787 fields = *prv == ATM_AFI_E164 ? e164 : code;
788 for (i = 0; fields[i]; i++) {
789 for (j = fields[i]; j; j--)
790 seq_printf(seq, "%02X", *prv++);
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700791 if (fields[i + 1])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 seq_putc(seq, '.');
793 }
794 }
795}
796
797/* This means the neighbour entry has no attached VCC objects. */
798#define SEQ_NO_VCC_TOKEN ((void *) 2)
799
800static void atmarp_info(struct seq_file *seq, struct net_device *dev,
801 struct atmarp_entry *entry, struct clip_vcc *clip_vcc)
802{
803 unsigned long exp;
804 char buf[17];
805 int svc, llc, off;
806
807 svc = ((clip_vcc == SEQ_NO_VCC_TOKEN) ||
808 (sk_atm(clip_vcc->vcc)->sk_family == AF_ATMSVC));
809
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700810 llc = ((clip_vcc == SEQ_NO_VCC_TOKEN) || clip_vcc->encap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (clip_vcc == SEQ_NO_VCC_TOKEN)
813 exp = entry->neigh->used;
814 else
815 exp = clip_vcc->last_use;
816
817 exp = (jiffies - exp) / HZ;
818
819 seq_printf(seq, "%-6s%-4s%-4s%5ld ",
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700820 dev->name, svc ? "SVC" : "PVC", llc ? "LLC" : "NULL", exp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 off = scnprintf(buf, sizeof(buf) - 1, "%d.%d.%d.%d",
823 NIPQUAD(entry->ip));
824 while (off < 16)
825 buf[off++] = ' ';
826 buf[off] = '\0';
827 seq_printf(seq, "%s", buf);
828
829 if (clip_vcc == SEQ_NO_VCC_TOKEN) {
830 if (time_before(jiffies, entry->expires))
831 seq_printf(seq, "(resolving)\n");
832 else
833 seq_printf(seq, "(expired, ref %d)\n",
834 atomic_read(&entry->neigh->refcnt));
835 } else if (!svc) {
836 seq_printf(seq, "%d.%d.%d\n",
837 clip_vcc->vcc->dev->number,
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700838 clip_vcc->vcc->vpi, clip_vcc->vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 } else {
840 svc_addr(seq, &clip_vcc->vcc->remote);
841 seq_putc(seq, '\n');
842 }
843}
844
845struct clip_seq_state {
846 /* This member must be first. */
847 struct neigh_seq_state ns;
848
849 /* Local to clip specific iteration. */
850 struct clip_vcc *vcc;
851};
852
853static struct clip_vcc *clip_seq_next_vcc(struct atmarp_entry *e,
854 struct clip_vcc *curr)
855{
856 if (!curr) {
857 curr = e->vccs;
858 if (!curr)
859 return SEQ_NO_VCC_TOKEN;
860 return curr;
861 }
862 if (curr == SEQ_NO_VCC_TOKEN)
863 return NULL;
864
865 curr = curr->next;
866
867 return curr;
868}
869
870static void *clip_seq_vcc_walk(struct clip_seq_state *state,
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700871 struct atmarp_entry *e, loff_t * pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
873 struct clip_vcc *vcc = state->vcc;
874
875 vcc = clip_seq_next_vcc(e, vcc);
876 if (vcc && pos != NULL) {
877 while (*pos) {
878 vcc = clip_seq_next_vcc(e, vcc);
879 if (!vcc)
880 break;
881 --(*pos);
882 }
883 }
884 state->vcc = vcc;
885
886 return vcc;
887}
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889static void *clip_seq_sub_iter(struct neigh_seq_state *_state,
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700890 struct neighbour *n, loff_t * pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700892 struct clip_seq_state *state = (struct clip_seq_state *)_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 return clip_seq_vcc_walk(state, NEIGH2ENTRY(n), pos);
895}
896
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700897static void *clip_seq_start(struct seq_file *seq, loff_t * pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 return neigh_seq_start(seq, pos, &clip_tbl, NEIGH_SEQ_NEIGH_ONLY);
900}
901
902static int clip_seq_show(struct seq_file *seq, void *v)
903{
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700904 static char atm_arp_banner[] =
905 "IPitf TypeEncp Idle IP address ATM address\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907 if (v == SEQ_START_TOKEN) {
908 seq_puts(seq, atm_arp_banner);
909 } else {
910 struct clip_seq_state *state = seq->private;
911 struct neighbour *n = v;
912 struct clip_vcc *vcc = state->vcc;
913
914 atmarp_info(seq, n->dev, NEIGH2ENTRY(n), vcc);
915 }
Stephen Hemmingere49e76d2006-04-14 15:59:37 -0700916 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917}
918
919static struct seq_operations arp_seq_ops = {
920 .start = clip_seq_start,
921 .next = neigh_seq_next,
922 .stop = neigh_seq_stop,
923 .show = clip_seq_show,
924};
925
926static int arp_seq_open(struct inode *inode, struct file *file)
927{
928 struct clip_seq_state *state;
929 struct seq_file *seq;
930 int rc = -EAGAIN;
931
932 state = kmalloc(sizeof(*state), GFP_KERNEL);
933 if (!state) {
934 rc = -ENOMEM;
935 goto out_kfree;
936 }
937 memset(state, 0, sizeof(*state));
938 state->ns.neigh_sub_iter = clip_seq_sub_iter;
939
940 rc = seq_open(file, &arp_seq_ops);
941 if (rc)
942 goto out_kfree;
943
944 seq = file->private_data;
945 seq->private = state;
946out:
947 return rc;
948
949out_kfree:
950 kfree(state);
951 goto out;
952}
953
954static struct file_operations arp_seq_fops = {
955 .open = arp_seq_open,
956 .read = seq_read,
957 .llseek = seq_lseek,
958 .release = seq_release_private,
959 .owner = THIS_MODULE
960};
961#endif
962
963static int __init atm_clip_init(void)
964{
Stephen Hemmingerdcdb0272006-04-14 16:00:25 -0700965 struct proc_dir_entry *p;
Simon Kelleybd89efc2006-05-12 14:56:08 -0700966 neigh_table_init_no_netlink(&clip_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 clip_tbl_hook = &clip_tbl;
969 register_atm_ioctl(&clip_ioctl_ops);
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700970 register_netdevice_notifier(&clip_dev_notifier);
971 register_inetaddr_notifier(&clip_inet_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Stephen Hemminger2d907392006-04-14 15:56:02 -0700973 setup_timer(&idle_timer, idle_timer_check, 0);
974
Stephen Hemmingerdcdb0272006-04-14 16:00:25 -0700975 p = create_proc_entry("arp", S_IRUGO, atm_proc_root);
976 if (p)
977 p->proc_fops = &arp_seq_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 return 0;
980}
981
982static void __exit atm_clip_exit(void)
983{
984 struct net_device *dev, *next;
985
986 remove_proc_entry("arp", atm_proc_root);
987
Stephen Hemmingerf3a05922006-04-14 15:07:27 -0700988 unregister_inetaddr_notifier(&clip_inet_notifier);
989 unregister_netdevice_notifier(&clip_dev_notifier);
990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 deregister_atm_ioctl(&clip_ioctl_ops);
992
993 /* First, stop the idle timer, so it stops banging
994 * on the table.
995 */
Stephen Hemminger2d907392006-04-14 15:56:02 -0700996 del_timer_sync(&idle_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998 /* Next, purge the table, so that the device
999 * unregister loop below does not hang due to
1000 * device references remaining in the table.
1001 */
1002 neigh_ifdown(&clip_tbl, NULL);
1003
1004 dev = clip_devs;
1005 while (dev) {
1006 next = PRIV(dev)->next;
1007 unregister_netdev(dev);
1008 free_netdev(dev);
1009 dev = next;
1010 }
1011
1012 /* Now it is safe to fully shutdown whole table. */
1013 neigh_table_clear(&clip_tbl);
1014
1015 clip_tbl_hook = NULL;
1016}
1017
1018module_init(atm_clip_init);
1019module_exit(atm_clip_exit);
Stephen Hemminger4909e4882006-04-14 16:01:26 -07001020MODULE_AUTHOR("Werner Almesberger");
1021MODULE_DESCRIPTION("Classical/IP over ATM interface");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022MODULE_LICENSE("GPL");