ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / decnet / dn_neigh.c
1 /*
2  * DECnet       An implementation of the DECnet protocol suite for the LINUX
3  *              operating system.  DECnet is implemented using the  BSD Socket
4  *              interface as the means of communication with the user level.
5  *
6  *              DECnet Neighbour Functions (Adjacency Database and 
7  *                                                        On-Ethernet Cache)
8  *
9  * Author:      Steve Whitehouse <SteveW@ACM.org>
10  *
11  *
12  * Changes:
13  *     Steve Whitehouse     : Fixed router listing routine
14  *     Steve Whitehouse     : Added error_report functions
15  *     Steve Whitehouse     : Added default router detection
16  *     Steve Whitehouse     : Hop counts in outgoing messages
17  *     Steve Whitehouse     : Fixed src/dst in outgoing messages so
18  *                            forwarding now stands a good chance of
19  *                            working.
20  *     Steve Whitehouse     : Fixed neighbour states (for now anyway).
21  *     Steve Whitehouse     : Made error_report functions dummies. This
22  *                            is not the right place to return skbs.
23  *     Steve Whitehouse     : Convert to seq_file
24  *
25  */
26
27 #include <linux/config.h>
28 #include <linux/net.h>
29 #include <linux/socket.h>
30 #include <linux/if_arp.h>
31 #include <linux/if_ether.h>
32 #include <linux/init.h>
33 #include <linux/proc_fs.h>
34 #include <linux/string.h>
35 #include <linux/netfilter_decnet.h>
36 #include <linux/spinlock.h>
37 #include <linux/seq_file.h>
38 #include <asm/atomic.h>
39 #include <net/neighbour.h>
40 #include <net/dst.h>
41 #include <net/flow.h>
42 #include <net/dn.h>
43 #include <net/dn_dev.h>
44 #include <net/dn_neigh.h>
45 #include <net/dn_route.h>
46
47 static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev);
48 static int dn_neigh_construct(struct neighbour *);
49 static void dn_long_error_report(struct neighbour *, struct sk_buff *);
50 static void dn_short_error_report(struct neighbour *, struct sk_buff *);
51 static int dn_long_output(struct sk_buff *);
52 static int dn_short_output(struct sk_buff *);
53 static int dn_phase3_output(struct sk_buff *);
54
55
56 /*
57  * For talking to broadcast devices: Ethernet & PPP
58  */
59 static struct neigh_ops dn_long_ops = {
60         .family =               AF_DECnet,
61         .error_report =         dn_long_error_report,
62         .output =               dn_long_output,
63         .connected_output =     dn_long_output,
64         .hh_output =            dev_queue_xmit,
65         .queue_xmit =           dev_queue_xmit,
66 };
67
68 /*
69  * For talking to pointopoint and multidrop devices: DDCMP and X.25
70  */
71 static struct neigh_ops dn_short_ops = {
72         .family =               AF_DECnet,
73         .error_report =         dn_short_error_report,
74         .output =               dn_short_output,
75         .connected_output =     dn_short_output,
76         .hh_output =            dev_queue_xmit,
77         .queue_xmit =           dev_queue_xmit,
78 };
79
80 /*
81  * For talking to DECnet phase III nodes
82  */
83 static struct neigh_ops dn_phase3_ops = {
84         .family =               AF_DECnet,
85         .error_report =         dn_short_error_report, /* Can use short version here */
86         .output =               dn_phase3_output,
87         .connected_output =     dn_phase3_output,
88         .hh_output =            dev_queue_xmit,
89         .queue_xmit =           dev_queue_xmit
90 };
91
92 struct neigh_table dn_neigh_table = {
93         .family =                       PF_DECnet,
94         .entry_size =                   sizeof(struct dn_neigh),
95         .key_len =                      sizeof(dn_address),
96         .hash =                         dn_neigh_hash,
97         .constructor =                  dn_neigh_construct,
98         .id =                           "dn_neigh_cache",
99         .parms ={
100                 .tbl =                  &dn_neigh_table,
101                 .entries =              0,
102                 .base_reachable_time =  30 * HZ,
103                 .retrans_time = 1 * HZ,
104                 .gc_staletime = 60 * HZ,
105                 .reachable_time =               30 * HZ,
106                 .delay_probe_time =     5 * HZ,
107                 .queue_len =            3,
108                 .ucast_probes = 0,
109                 .app_probes =           0,
110                 .mcast_probes = 0,
111                 .anycast_delay =        0,
112                 .proxy_delay =          0,
113                 .proxy_qlen =           0,
114                 .locktime =             1 * HZ,
115         },
116         .gc_interval =                  30 * HZ,
117         .gc_thresh1 =                   128,
118         .gc_thresh2 =                   512,
119         .gc_thresh3 =                   1024,
120 };
121
122 static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev)
123 {
124         u32 hash_val;
125
126         hash_val = *(dn_address *)pkey;
127         hash_val ^= (hash_val >> 10);
128         hash_val ^= (hash_val >> 3);
129
130         return hash_val & NEIGH_HASHMASK;
131 }
132
133 static int dn_neigh_construct(struct neighbour *neigh)
134 {
135         struct net_device *dev = neigh->dev;
136         struct dn_neigh *dn = (struct dn_neigh *)neigh;
137         struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
138
139         if (dn_db == NULL)
140                 return -EINVAL;
141
142         if (dn_db->neigh_parms)
143                 neigh->parms = dn_db->neigh_parms;
144
145         if (dn_db->use_long)
146                 neigh->ops = &dn_long_ops;
147         else
148                 neigh->ops = &dn_short_ops;
149
150         if (dn->flags & DN_NDFLAG_P3)
151                 neigh->ops = &dn_phase3_ops;
152
153         neigh->nud_state = NUD_NOARP;
154         neigh->output = neigh->ops->connected_output;
155
156         if ((dev->type == ARPHRD_IPGRE) || (dev->flags & IFF_POINTOPOINT))
157                 memcpy(neigh->ha, dev->broadcast, dev->addr_len);
158         else if ((dev->type == ARPHRD_ETHER) || (dev->type == ARPHRD_LOOPBACK))
159                 dn_dn2eth(neigh->ha, dn->addr);
160         else {
161                 if (net_ratelimit())
162                         printk(KERN_DEBUG "Trying to create neigh for hw %d\n",  dev->type);
163                 return -EINVAL;
164         }
165
166         /*
167          * Make an estimate of the remote block size by assuming that its
168          * two less then the device mtu, which it true for ethernet (and
169          * other things which support long format headers) since there is
170          * an extra length field (of 16 bits) which isn't part of the
171          * ethernet headers and which the DECnet specs won't admit is part
172          * of the DECnet routing headers either.
173          *
174          * If we over estimate here its no big deal, the NSP negotiations
175          * will prevent us from sending packets which are too large for the
176          * remote node to handle. In any case this figure is normally updated
177          * by a hello message in most cases.
178          */
179         dn->blksize = dev->mtu - 2;
180
181         return 0;
182 }
183
184 static void dn_long_error_report(struct neighbour *neigh, struct sk_buff *skb)
185 {
186         printk(KERN_DEBUG "dn_long_error_report: called\n");
187         kfree_skb(skb);
188 }
189
190
191 static void dn_short_error_report(struct neighbour *neigh, struct sk_buff *skb)
192 {
193         printk(KERN_DEBUG "dn_short_error_report: called\n");
194         kfree_skb(skb);
195 }
196
197 static int dn_neigh_output_packet(struct sk_buff *skb)
198 {
199         struct dst_entry *dst = skb->dst;
200         struct dn_route *rt = (struct dn_route *)dst;
201         struct neighbour *neigh = dst->neighbour;
202         struct net_device *dev = neigh->dev;
203         char mac_addr[ETH_ALEN];
204
205         dn_dn2eth(mac_addr, rt->rt_local_src);
206         if (!dev->hard_header || dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha, mac_addr, skb->len) >= 0)
207                 return neigh->ops->queue_xmit(skb);
208
209         if (net_ratelimit())
210                 printk(KERN_DEBUG "dn_neigh_output_packet: oops, can't send packet\n");
211
212         kfree_skb(skb);
213         return -EINVAL;
214 }
215
216 static int dn_long_output(struct sk_buff *skb)
217 {
218         struct dst_entry *dst = skb->dst;
219         struct neighbour *neigh = dst->neighbour;
220         struct net_device *dev = neigh->dev;
221         int headroom = dev->hard_header_len + sizeof(struct dn_long_packet) + 3;
222         unsigned char *data;
223         struct dn_long_packet *lp;
224         struct dn_skb_cb *cb = DN_SKB_CB(skb);
225
226
227         if (skb_headroom(skb) < headroom) {
228                 struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
229                 if (skb2 == NULL) {
230                         if (net_ratelimit())
231                                 printk(KERN_CRIT "dn_long_output: no memory\n");
232                         kfree_skb(skb);
233                         return -ENOBUFS;
234                 }
235                 kfree_skb(skb);
236                 skb = skb2;
237                 if (net_ratelimit())
238                         printk(KERN_INFO "dn_long_output: Increasing headroom\n");
239         }
240
241         data = skb_push(skb, sizeof(struct dn_long_packet) + 3);
242         lp = (struct dn_long_packet *)(data+3);
243
244         *((unsigned short *)data) = dn_htons(skb->len - 2);
245         *(data + 2) = 1 | DN_RT_F_PF; /* Padding */
246
247         lp->msgflg   = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS));
248         lp->d_area   = lp->d_subarea = 0;
249         dn_dn2eth(lp->d_id, dn_ntohs(cb->dst));
250         lp->s_area   = lp->s_subarea = 0;
251         dn_dn2eth(lp->s_id, dn_ntohs(cb->src));
252         lp->nl2      = 0;
253         lp->visit_ct = cb->hops & 0x3f;
254         lp->s_class  = 0;
255         lp->pt       = 0;
256
257         skb->nh.raw = skb->data;
258
259         return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
260 }
261
262 static int dn_short_output(struct sk_buff *skb)
263 {
264         struct dst_entry *dst = skb->dst;
265         struct neighbour *neigh = dst->neighbour;
266         struct net_device *dev = neigh->dev;
267         int headroom = dev->hard_header_len + sizeof(struct dn_short_packet) + 2;
268         struct dn_short_packet *sp;
269         unsigned char *data;
270         struct dn_skb_cb *cb = DN_SKB_CB(skb);
271
272
273         if (skb_headroom(skb) < headroom) {
274                 struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
275                 if (skb2 == NULL) {
276                         if (net_ratelimit())
277                                 printk(KERN_CRIT "dn_short_output: no memory\n");
278                         kfree_skb(skb);
279                         return -ENOBUFS;
280                 }
281                 kfree_skb(skb);
282                 skb = skb2;
283                 if (net_ratelimit())
284                         printk(KERN_INFO "dn_short_output: Increasing headroom\n");
285         }
286
287         data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
288         *((unsigned short *)data) = dn_htons(skb->len - 2);
289         sp = (struct dn_short_packet *)(data+2);
290
291         sp->msgflg     = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
292         sp->dstnode    = cb->dst;
293         sp->srcnode    = cb->src;
294         sp->forward    = cb->hops & 0x3f;
295
296         skb->nh.raw = skb->data;
297
298         return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
299 }
300
301 /*
302  * Phase 3 output is the same is short output, execpt that
303  * it clears the area bits before transmission.
304  */
305 static int dn_phase3_output(struct sk_buff *skb)
306 {
307         struct dst_entry *dst = skb->dst;
308         struct neighbour *neigh = dst->neighbour;
309         struct net_device *dev = neigh->dev;
310         int headroom = dev->hard_header_len + sizeof(struct dn_short_packet) + 2;
311         struct dn_short_packet *sp;
312         unsigned char *data;
313         struct dn_skb_cb *cb = DN_SKB_CB(skb);
314
315         if (skb_headroom(skb) < headroom) {
316                 struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
317                 if (skb2 == NULL) {
318                         if (net_ratelimit())
319                                 printk(KERN_CRIT "dn_phase3_output: no memory\n");
320                         kfree_skb(skb);
321                         return -ENOBUFS;
322                 }
323                 kfree_skb(skb);
324                 skb = skb2;
325                 if (net_ratelimit())
326                         printk(KERN_INFO "dn_phase3_output: Increasing headroom\n");
327         }
328
329         data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
330         *((unsigned short *)data) = dn_htons(skb->len - 2);
331         sp = (struct dn_short_packet *)(data + 2);
332
333         sp->msgflg   = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
334         sp->dstnode  = cb->dst & dn_htons(0x03ff);
335         sp->srcnode  = cb->src & dn_htons(0x03ff);
336         sp->forward  = cb->hops & 0x3f;
337
338         skb->nh.raw = skb->data;
339
340         return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
341 }
342
343 /*
344  * Unfortunately, the neighbour code uses the device in its hash
345  * function, so we don't get any advantage from it. This function
346  * basically does a neigh_lookup(), but without comparing the device
347  * field. This is required for the On-Ethernet cache
348  */
349 struct neighbour *dn_neigh_lookup(struct neigh_table *tbl, const void *ptr)
350 {
351         struct neighbour *neigh;
352         u32 hash_val;
353
354         hash_val = tbl->hash(ptr, NULL);
355
356         read_lock_bh(&tbl->lock);
357         for(neigh = tbl->hash_buckets[hash_val]; neigh != NULL; neigh = neigh->next) {
358                 if (memcmp(neigh->primary_key, ptr, tbl->key_len) == 0) {
359                         atomic_inc(&neigh->refcnt);
360                         read_unlock_bh(&tbl->lock);
361                         return neigh;
362                 }
363         }
364         read_unlock_bh(&tbl->lock);
365
366         return NULL;
367 }
368
369
370 /*
371  * Any traffic on a pointopoint link causes the timer to be reset
372  * for the entry in the neighbour table.
373  */
374 void dn_neigh_pointopoint_notify(struct sk_buff *skb)
375 {
376         return;
377 }
378
379 /*
380  * Pointopoint link receives a hello message
381  */
382 void dn_neigh_pointopoint_hello(struct sk_buff *skb)
383 {
384         kfree_skb(skb);
385 }
386
387 /*
388  * Ethernet router hello message received
389  */
390 int dn_neigh_router_hello(struct sk_buff *skb)
391 {
392         struct rtnode_hello_message *msg = (struct rtnode_hello_message *)skb->data;
393
394         struct neighbour *neigh;
395         struct dn_neigh *dn;
396         struct dn_dev *dn_db;
397         dn_address src;
398
399         src = dn_htons(dn_eth2dn(msg->id));
400
401         neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
402
403         dn = (struct dn_neigh *)neigh;
404
405         if (neigh) {
406                 write_lock(&neigh->lock);
407
408                 neigh->used = jiffies;
409                 dn_db = (struct dn_dev *)neigh->dev->dn_ptr;
410
411                 if (!(neigh->nud_state & NUD_PERMANENT)) {
412                         neigh->updated = jiffies;
413
414                         if (neigh->dev->type == ARPHRD_ETHER)
415                                 memcpy(neigh->ha, &skb->mac.ethernet->h_source, ETH_ALEN);
416
417                         dn->blksize  = dn_ntohs(msg->blksize);
418                         dn->priority = msg->priority;
419
420                         dn->flags &= ~DN_NDFLAG_P3;
421
422                         switch(msg->iinfo & DN_RT_INFO_TYPE) {
423                                 case DN_RT_INFO_L1RT:
424                                         dn->flags &=~DN_NDFLAG_R2;
425                                         dn->flags |= DN_NDFLAG_R1;
426                                         break;
427                                 case DN_RT_INFO_L2RT:
428                                         dn->flags |= DN_NDFLAG_R2;
429                         }
430                 }
431
432                 if (!dn_db->router) {
433                         dn_db->router = neigh_clone(neigh);
434                 } else {
435                         if (msg->priority > ((struct dn_neigh *)dn_db->router)->priority)
436                                 neigh_release(xchg(&dn_db->router, neigh_clone(neigh)));
437                 }
438                 write_unlock(&neigh->lock);
439                 neigh_release(neigh);
440         }
441
442         kfree_skb(skb);
443         return 0;
444 }
445
446 /*
447  * Endnode hello message received
448  */
449 int dn_neigh_endnode_hello(struct sk_buff *skb)
450 {
451         struct endnode_hello_message *msg = (struct endnode_hello_message *)skb->data;
452         struct neighbour *neigh;
453         struct dn_neigh *dn;
454         dn_address src;
455
456         src = dn_htons(dn_eth2dn(msg->id));
457
458         neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
459
460         dn = (struct dn_neigh *)neigh;
461
462         if (neigh) {
463                 write_lock(&neigh->lock);
464
465                 neigh->used = jiffies;
466
467                 if (!(neigh->nud_state & NUD_PERMANENT)) {
468                         neigh->updated = jiffies;
469
470                         if (neigh->dev->type == ARPHRD_ETHER)
471                                 memcpy(neigh->ha, &skb->mac.ethernet->h_source, ETH_ALEN);
472                         dn->flags   &= ~(DN_NDFLAG_R1 | DN_NDFLAG_R2);
473                         dn->blksize  = dn_ntohs(msg->blksize);
474                         dn->priority = 0;
475                 }
476
477                 write_unlock(&neigh->lock);
478                 neigh_release(neigh);
479         }
480
481         kfree_skb(skb);
482         return 0;
483 }
484
485 static char *dn_find_slot(char *base, int max, int priority)
486 {
487         int i;
488         unsigned char *min = NULL;
489
490         base += 6; /* skip first id */
491
492         for(i = 0; i < max; i++) {
493                 if (!min || (*base < *min))
494                         min = base;
495                 base += 7; /* find next priority */
496         }
497
498         if (!min)
499                 return NULL;
500
501         return (*min < priority) ? (min - 6) : NULL;
502 }
503
504 int dn_neigh_elist(struct net_device *dev, unsigned char *ptr, int n)
505 {
506         int t = 0;
507         int i;
508         struct neighbour *neigh;
509         struct dn_neigh *dn;
510         struct neigh_table *tbl = &dn_neigh_table;
511         unsigned char *rs = ptr;
512         struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
513
514         read_lock_bh(&tbl->lock);
515
516         for(i = 0; i < NEIGH_HASHMASK; i++) {
517                 for(neigh = tbl->hash_buckets[i]; neigh != NULL; neigh = neigh->next) {
518                         if (neigh->dev != dev)
519                                 continue;
520                         dn = (struct dn_neigh *)neigh;
521                         if (!(dn->flags & (DN_NDFLAG_R1|DN_NDFLAG_R2)))
522                                 continue;
523                         if (dn_db->parms.forwarding == 1 && (dn->flags & DN_NDFLAG_R2))
524                                 continue;
525                         if (t == n)
526                                 rs = dn_find_slot(ptr, n, dn->priority);
527                         else
528                                 t++;
529                         if (rs == NULL)
530                                 continue;
531                         dn_dn2eth(rs, dn->addr);
532                         rs += 6;
533                         *rs = neigh->nud_state & NUD_CONNECTED ? 0x80 : 0x0;
534                         *rs |= dn->priority;
535                         rs++;
536                 }
537         }
538
539         read_unlock_bh(&tbl->lock);
540
541         return t;
542 }
543
544
545 #ifdef CONFIG_PROC_FS
546
547 struct dn_neigh_iter_state {
548         int bucket;
549 };
550
551 static struct neighbour *neigh_get_first(struct seq_file *seq)
552 {
553         struct dn_neigh_iter_state *state = seq->private;
554         struct neighbour *n = NULL;
555
556         for(state->bucket = 0;
557             state->bucket <= NEIGH_HASHMASK;
558             ++state->bucket) {
559                 n = dn_neigh_table.hash_buckets[state->bucket];
560                 if (n)
561                         break;
562         }
563
564         return n;
565 }
566
567 static struct neighbour *neigh_get_next(struct seq_file *seq,
568                                         struct neighbour *n)
569 {
570         struct dn_neigh_iter_state *state = seq->private;
571
572         n = n->next;
573 try_again:
574         if (n)
575                 goto out;
576         if (++state->bucket > NEIGH_HASHMASK)
577                 goto out;
578         n = dn_neigh_table.hash_buckets[state->bucket];
579         goto try_again;
580 out:
581         return n;
582 }
583
584 static struct neighbour *neigh_get_idx(struct seq_file *seq, loff_t *pos)
585 {
586         struct neighbour *n = neigh_get_first(seq);
587
588         if (n)
589                 while(*pos && (n = neigh_get_next(seq, n)))
590                         --*pos;
591         return *pos ? NULL : n;
592 }
593
594 static void *dn_neigh_get_idx(struct seq_file *seq, loff_t pos)
595 {
596         void *rc;
597         read_lock_bh(&dn_neigh_table.lock);
598         rc = neigh_get_idx(seq, &pos);
599         if (!rc) {
600                 read_unlock_bh(&dn_neigh_table.lock);
601         }
602         return rc;
603 }
604
605 static void *dn_neigh_seq_start(struct seq_file *seq, loff_t *pos)
606 {
607         return *pos ? dn_neigh_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
608 }
609
610 static void *dn_neigh_seq_next(struct seq_file *seq, void *v, loff_t *pos)
611 {
612         void *rc;
613
614
615         if (v == SEQ_START_TOKEN) {
616                 rc = dn_neigh_get_idx(seq, 0);
617                 goto out;
618         }
619
620         rc = neigh_get_next(seq, v);
621         if (rc)
622                 goto out;
623         read_unlock_bh(&dn_neigh_table.lock);
624 out:
625         ++*pos;
626         return rc;
627 }
628
629 static void dn_neigh_seq_stop(struct seq_file *seq, void *v)
630 {
631         if (v && v != SEQ_START_TOKEN)
632                 read_unlock_bh(&dn_neigh_table.lock);
633 }
634
635 static inline void dn_neigh_format_entry(struct seq_file *seq,
636                                          struct neighbour *n)
637 {
638         struct dn_neigh *dn = (struct dn_neigh *)n;
639         char buf[DN_ASCBUF_LEN];
640
641         read_lock(&n->lock);
642         seq_printf(seq, "%-7s %s%s%s   %02x    %02d  %07ld %-8s\n",
643                    dn_addr2asc(dn_ntohs(dn->addr), buf),
644                    (dn->flags&DN_NDFLAG_R1) ? "1" : "-",
645                    (dn->flags&DN_NDFLAG_R2) ? "2" : "-",
646                    (dn->flags&DN_NDFLAG_P3) ? "3" : "-",
647                    dn->n.nud_state,
648                    atomic_read(&dn->n.refcnt),
649                    dn->blksize,
650                    (dn->n.dev) ? dn->n.dev->name : "?");
651         read_unlock(&n->lock);
652 }
653
654 static int dn_neigh_seq_show(struct seq_file *seq, void *v)
655 {
656         if (v == SEQ_START_TOKEN) {
657                 seq_puts(seq, "Addr    Flags State Use Blksize Dev\n");
658         } else {
659                 dn_neigh_format_entry(seq, v);
660         }
661
662         return 0;
663 }
664
665 static struct seq_operations dn_neigh_seq_ops = {
666         .start = dn_neigh_seq_start,
667         .next  = dn_neigh_seq_next,
668         .stop  = dn_neigh_seq_stop,
669         .show  = dn_neigh_seq_show,
670 };
671
672 static int dn_neigh_seq_open(struct inode *inode, struct file *file)
673 {
674         struct seq_file *seq;
675         int rc = -ENOMEM;
676         struct dn_neigh_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
677
678         if (!s)
679                 goto out;
680
681         rc = seq_open(file, &dn_neigh_seq_ops);
682         if (rc)
683                 goto out_kfree;
684
685         seq          = file->private_data;
686         seq->private = s;
687         memset(s, 0, sizeof(*s));
688 out:
689         return rc;
690 out_kfree:
691         kfree(s);
692         goto out;
693 }
694
695 static struct file_operations dn_neigh_seq_fops = {
696         .owner          = THIS_MODULE,
697         .open           = dn_neigh_seq_open,
698         .read           = seq_read,
699         .llseek         = seq_lseek,
700         .release        = seq_release_private,
701 };
702
703 #endif
704
705 void __init dn_neigh_init(void)
706 {
707         neigh_table_init(&dn_neigh_table);
708         proc_net_fops_create("decnet_neigh", S_IRUGO, &dn_neigh_seq_fops);
709 }
710
711 void __exit dn_neigh_cleanup(void)
712 {
713         proc_net_remove("decnet_neigh");
714         neigh_table_clear(&dn_neigh_table);
715 }