1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <linux/if_arp.h>
33#include <linux/slab.h>
34#include <net/sock.h>
35#include <net/datalink.h>
36#include <net/psnap.h>
37#include <linux/atalk.h>
38#include <linux/delay.h>
39#include <linux/init.h>
40#include <linux/proc_fs.h>
41#include <linux/seq_file.h>
42#include <linux/export.h>
43#include <linux/etherdevice.h>
44
45int sysctl_aarp_expiry_time = AARP_EXPIRY_TIME;
46int sysctl_aarp_tick_time = AARP_TICK_TIME;
47int sysctl_aarp_retransmit_limit = AARP_RETRANSMIT_LIMIT;
48int sysctl_aarp_resolve_time = AARP_RESOLVE_TIME;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63struct aarp_entry {
64
65 unsigned long last_sent;
66 struct sk_buff_head packet_queue;
67 int status;
68 unsigned long expires_at;
69 struct atalk_addr target_addr;
70 struct net_device *dev;
71 char hwaddr[ETH_ALEN];
72 unsigned short xmit_count;
73 struct aarp_entry *next;
74};
75
76
77static struct aarp_entry *resolved[AARP_HASH_SIZE];
78static struct aarp_entry *unresolved[AARP_HASH_SIZE];
79static struct aarp_entry *proxies[AARP_HASH_SIZE];
80static int unresolved_count;
81
82
83static DEFINE_RWLOCK(aarp_lock);
84
85
86static struct timer_list aarp_timer;
87
88
89
90
91
92
93static void __aarp_expire(struct aarp_entry *a)
94{
95 skb_queue_purge(&a->packet_queue);
96 kfree(a);
97}
98
99
100
101
102
103
104static void __aarp_send_query(struct aarp_entry *a)
105{
106 static unsigned char aarp_eth_multicast[ETH_ALEN] =
107 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
108 struct net_device *dev = a->dev;
109 struct elapaarp *eah;
110 int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length;
111 struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
112 struct atalk_addr *sat = atalk_find_dev_addr(dev);
113
114 if (!skb)
115 return;
116
117 if (!sat) {
118 kfree_skb(skb);
119 return;
120 }
121
122
123 skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
124 skb_reset_network_header(skb);
125 skb_reset_transport_header(skb);
126 skb_put(skb, sizeof(*eah));
127 skb->protocol = htons(ETH_P_ATALK);
128 skb->dev = dev;
129 eah = aarp_hdr(skb);
130
131
132 eah->hw_type = htons(AARP_HW_TYPE_ETHERNET);
133 eah->pa_type = htons(ETH_P_ATALK);
134 eah->hw_len = ETH_ALEN;
135 eah->pa_len = AARP_PA_ALEN;
136 eah->function = htons(AARP_REQUEST);
137
138 ether_addr_copy(eah->hw_src, dev->dev_addr);
139
140 eah->pa_src_zero = 0;
141 eah->pa_src_net = sat->s_net;
142 eah->pa_src_node = sat->s_node;
143
144 eth_zero_addr(eah->hw_dst);
145
146 eah->pa_dst_zero = 0;
147 eah->pa_dst_net = a->target_addr.s_net;
148 eah->pa_dst_node = a->target_addr.s_node;
149
150
151 aarp_dl->request(aarp_dl, skb, aarp_eth_multicast);
152
153 a->xmit_count++;
154 a->last_sent = jiffies;
155}
156
157
158
159static void aarp_send_reply(struct net_device *dev, struct atalk_addr *us,
160 struct atalk_addr *them, unsigned char *sha)
161{
162 struct elapaarp *eah;
163 int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length;
164 struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
165
166 if (!skb)
167 return;
168
169
170 skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
171 skb_reset_network_header(skb);
172 skb_reset_transport_header(skb);
173 skb_put(skb, sizeof(*eah));
174 skb->protocol = htons(ETH_P_ATALK);
175 skb->dev = dev;
176 eah = aarp_hdr(skb);
177
178
179 eah->hw_type = htons(AARP_HW_TYPE_ETHERNET);
180 eah->pa_type = htons(ETH_P_ATALK);
181 eah->hw_len = ETH_ALEN;
182 eah->pa_len = AARP_PA_ALEN;
183 eah->function = htons(AARP_REPLY);
184
185 ether_addr_copy(eah->hw_src, dev->dev_addr);
186
187 eah->pa_src_zero = 0;
188 eah->pa_src_net = us->s_net;
189 eah->pa_src_node = us->s_node;
190
191 if (!sha)
192 eth_zero_addr(eah->hw_dst);
193 else
194 ether_addr_copy(eah->hw_dst, sha);
195
196 eah->pa_dst_zero = 0;
197 eah->pa_dst_net = them->s_net;
198 eah->pa_dst_node = them->s_node;
199
200
201 aarp_dl->request(aarp_dl, skb, sha);
202}
203
204
205
206
207
208
209static void aarp_send_probe(struct net_device *dev, struct atalk_addr *us)
210{
211 struct elapaarp *eah;
212 int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length;
213 struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
214 static unsigned char aarp_eth_multicast[ETH_ALEN] =
215 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
216
217 if (!skb)
218 return;
219
220
221 skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
222 skb_reset_network_header(skb);
223 skb_reset_transport_header(skb);
224 skb_put(skb, sizeof(*eah));
225 skb->protocol = htons(ETH_P_ATALK);
226 skb->dev = dev;
227 eah = aarp_hdr(skb);
228
229
230 eah->hw_type = htons(AARP_HW_TYPE_ETHERNET);
231 eah->pa_type = htons(ETH_P_ATALK);
232 eah->hw_len = ETH_ALEN;
233 eah->pa_len = AARP_PA_ALEN;
234 eah->function = htons(AARP_PROBE);
235
236 ether_addr_copy(eah->hw_src, dev->dev_addr);
237
238 eah->pa_src_zero = 0;
239 eah->pa_src_net = us->s_net;
240 eah->pa_src_node = us->s_node;
241
242 eth_zero_addr(eah->hw_dst);
243
244 eah->pa_dst_zero = 0;
245 eah->pa_dst_net = us->s_net;
246 eah->pa_dst_node = us->s_node;
247
248
249 aarp_dl->request(aarp_dl, skb, aarp_eth_multicast);
250}
251
252
253
254
255
256
257
258static void __aarp_expire_timer(struct aarp_entry **n)
259{
260 struct aarp_entry *t;
261
262 while (*n)
263
264 if (time_after(jiffies, (*n)->expires_at)) {
265 t = *n;
266 *n = (*n)->next;
267 __aarp_expire(t);
268 } else
269 n = &((*n)->next);
270}
271
272
273
274
275
276
277static void __aarp_kick(struct aarp_entry **n)
278{
279 struct aarp_entry *t;
280
281 while (*n)
282
283 if ((*n)->xmit_count >= sysctl_aarp_retransmit_limit) {
284 t = *n;
285 *n = (*n)->next;
286 __aarp_expire(t);
287 } else {
288 __aarp_send_query(*n);
289 n = &((*n)->next);
290 }
291}
292
293
294
295
296
297
298
299static void __aarp_expire_device(struct aarp_entry **n, struct net_device *dev)
300{
301 struct aarp_entry *t;
302
303 while (*n)
304 if ((*n)->dev == dev) {
305 t = *n;
306 *n = (*n)->next;
307 __aarp_expire(t);
308 } else
309 n = &((*n)->next);
310}
311
312
313static void aarp_expire_timeout(struct timer_list *unused)
314{
315 int ct;
316
317 write_lock_bh(&aarp_lock);
318
319 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
320 __aarp_expire_timer(&resolved[ct]);
321 __aarp_kick(&unresolved[ct]);
322 __aarp_expire_timer(&unresolved[ct]);
323 __aarp_expire_timer(&proxies[ct]);
324 }
325
326 write_unlock_bh(&aarp_lock);
327 mod_timer(&aarp_timer, jiffies +
328 (unresolved_count ? sysctl_aarp_tick_time :
329 sysctl_aarp_expiry_time));
330}
331
332
333static int aarp_device_event(struct notifier_block *this, unsigned long event,
334 void *ptr)
335{
336 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
337 int ct;
338
339 if (!net_eq(dev_net(dev), &init_net))
340 return NOTIFY_DONE;
341
342 if (event == NETDEV_DOWN) {
343 write_lock_bh(&aarp_lock);
344
345 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
346 __aarp_expire_device(&resolved[ct], dev);
347 __aarp_expire_device(&unresolved[ct], dev);
348 __aarp_expire_device(&proxies[ct], dev);
349 }
350
351 write_unlock_bh(&aarp_lock);
352 }
353 return NOTIFY_DONE;
354}
355
356
357static void __aarp_expire_all(struct aarp_entry **n)
358{
359 struct aarp_entry *t;
360
361 while (*n) {
362 t = *n;
363 *n = (*n)->next;
364 __aarp_expire(t);
365 }
366}
367
368
369static void aarp_purge(void)
370{
371 int ct;
372
373 write_lock_bh(&aarp_lock);
374 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
375 __aarp_expire_all(&resolved[ct]);
376 __aarp_expire_all(&unresolved[ct]);
377 __aarp_expire_all(&proxies[ct]);
378 }
379 write_unlock_bh(&aarp_lock);
380}
381
382
383
384
385
386static struct aarp_entry *aarp_alloc(void)
387{
388 struct aarp_entry *a = kmalloc(sizeof(*a), GFP_ATOMIC);
389
390 if (a)
391 skb_queue_head_init(&a->packet_queue);
392 return a;
393}
394
395
396
397
398
399
400
401static struct aarp_entry *__aarp_find_entry(struct aarp_entry *list,
402 struct net_device *dev,
403 struct atalk_addr *sat)
404{
405 while (list) {
406 if (list->target_addr.s_net == sat->s_net &&
407 list->target_addr.s_node == sat->s_node &&
408 list->dev == dev)
409 break;
410 list = list->next;
411 }
412
413 return list;
414}
415
416
417void aarp_proxy_remove(struct net_device *dev, struct atalk_addr *sa)
418{
419 int hash = sa->s_node % (AARP_HASH_SIZE - 1);
420 struct aarp_entry *a;
421
422 write_lock_bh(&aarp_lock);
423
424 a = __aarp_find_entry(proxies[hash], dev, sa);
425 if (a)
426 a->expires_at = jiffies - 1;
427
428 write_unlock_bh(&aarp_lock);
429}
430
431
432static struct atalk_addr *__aarp_proxy_find(struct net_device *dev,
433 struct atalk_addr *sa)
434{
435 int hash = sa->s_node % (AARP_HASH_SIZE - 1);
436 struct aarp_entry *a = __aarp_find_entry(proxies[hash], dev, sa);
437
438 return a ? sa : NULL;
439}
440
441
442
443
444
445static void aarp_send_probe_phase1(struct atalk_iface *iface)
446{
447 struct ifreq atreq;
448 struct sockaddr_at *sa = (struct sockaddr_at *)&atreq.ifr_addr;
449 const struct net_device_ops *ops = iface->dev->netdev_ops;
450
451 sa->sat_addr.s_node = iface->address.s_node;
452 sa->sat_addr.s_net = ntohs(iface->address.s_net);
453
454
455 if (!(ops->ndo_do_ioctl(iface->dev, &atreq, SIOCSIFADDR))) {
456 ops->ndo_do_ioctl(iface->dev, &atreq, SIOCGIFADDR);
457 if (iface->address.s_net != htons(sa->sat_addr.s_net) ||
458 iface->address.s_node != sa->sat_addr.s_node)
459 iface->status |= ATIF_PROBE_FAIL;
460
461 iface->address.s_net = htons(sa->sat_addr.s_net);
462 iface->address.s_node = sa->sat_addr.s_node;
463 }
464}
465
466
467void aarp_probe_network(struct atalk_iface *atif)
468{
469 if (atif->dev->type == ARPHRD_LOCALTLK ||
470 atif->dev->type == ARPHRD_PPP)
471 aarp_send_probe_phase1(atif);
472 else {
473 unsigned int count;
474
475 for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) {
476 aarp_send_probe(atif->dev, &atif->address);
477
478
479 msleep(100);
480
481 if (atif->status & ATIF_PROBE_FAIL)
482 break;
483 }
484 }
485}
486
487int aarp_proxy_probe_network(struct atalk_iface *atif, struct atalk_addr *sa)
488{
489 int hash, retval = -EPROTONOSUPPORT;
490 struct aarp_entry *entry;
491 unsigned int count;
492
493
494
495
496
497 if (atif->dev->type == ARPHRD_LOCALTLK ||
498 atif->dev->type == ARPHRD_PPP)
499 goto out;
500
501
502
503
504
505 entry = aarp_alloc();
506 retval = -ENOMEM;
507 if (!entry)
508 goto out;
509
510 entry->expires_at = -1;
511 entry->status = ATIF_PROBE;
512 entry->target_addr.s_node = sa->s_node;
513 entry->target_addr.s_net = sa->s_net;
514 entry->dev = atif->dev;
515
516 write_lock_bh(&aarp_lock);
517
518 hash = sa->s_node % (AARP_HASH_SIZE - 1);
519 entry->next = proxies[hash];
520 proxies[hash] = entry;
521
522 for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) {
523 aarp_send_probe(atif->dev, sa);
524
525
526 write_unlock_bh(&aarp_lock);
527 msleep(100);
528 write_lock_bh(&aarp_lock);
529
530 if (entry->status & ATIF_PROBE_FAIL)
531 break;
532 }
533
534 if (entry->status & ATIF_PROBE_FAIL) {
535 entry->expires_at = jiffies - 1;
536 retval = -EADDRINUSE;
537 } else {
538 entry->status &= ~ATIF_PROBE;
539 retval = 1;
540 }
541
542 write_unlock_bh(&aarp_lock);
543out:
544 return retval;
545}
546
547
548int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb,
549 struct atalk_addr *sa, void *hwaddr)
550{
551 static char ddp_eth_multicast[ETH_ALEN] =
552 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
553 int hash;
554 struct aarp_entry *a;
555
556 skb_reset_network_header(skb);
557
558
559 if (dev->type == ARPHRD_LOCALTLK) {
560 struct atalk_addr *at = atalk_find_dev_addr(dev);
561 struct ddpehdr *ddp = (struct ddpehdr *)skb->data;
562 int ft = 2;
563
564
565
566
567
568
569
570
571 if ((!ddp->deh_snet || at->s_net == ddp->deh_snet) &&
572 (!ddp->deh_dnet || at->s_net == ddp->deh_dnet)) {
573 skb_pull(skb, sizeof(*ddp) - 4);
574
575
576
577
578
579
580 *((__be16 *)skb->data) = htons(skb->len);
581 ft = 1;
582 }
583
584
585
586
587
588 skb_push(skb, 3);
589 skb->data[0] = sa->s_node;
590 skb->data[1] = at->s_node;
591 skb->data[2] = ft;
592 skb->dev = dev;
593 goto sendit;
594 }
595
596
597 if (dev->type == ARPHRD_PPP) {
598 skb->protocol = htons(ETH_P_PPPTALK);
599 skb->dev = dev;
600 goto sendit;
601 }
602
603
604 if (dev->type != ARPHRD_ETHER)
605 goto free_it;
606
607 skb->dev = dev;
608 skb->protocol = htons(ETH_P_ATALK);
609 hash = sa->s_node % (AARP_HASH_SIZE - 1);
610
611
612 if (sa->s_node == ATADDR_BCAST) {
613
614 ddp_dl->request(ddp_dl, skb, ddp_eth_multicast);
615 goto sent;
616 }
617
618 write_lock_bh(&aarp_lock);
619 a = __aarp_find_entry(resolved[hash], dev, sa);
620
621 if (a) {
622 a->expires_at = jiffies + (sysctl_aarp_expiry_time * 10);
623 ddp_dl->request(ddp_dl, skb, a->hwaddr);
624 write_unlock_bh(&aarp_lock);
625 goto sent;
626 }
627
628
629 a = __aarp_find_entry(unresolved[hash], dev, sa);
630 if (a) {
631 skb_queue_tail(&a->packet_queue, skb);
632 goto out_unlock;
633 }
634
635
636 a = aarp_alloc();
637 if (!a) {
638
639 write_unlock_bh(&aarp_lock);
640 goto free_it;
641 }
642
643
644 skb_queue_tail(&a->packet_queue, skb);
645 a->expires_at = jiffies + sysctl_aarp_resolve_time;
646 a->dev = dev;
647 a->next = unresolved[hash];
648 a->target_addr = *sa;
649 a->xmit_count = 0;
650 unresolved[hash] = a;
651 unresolved_count++;
652
653
654 __aarp_send_query(a);
655
656
657
658
659
660
661 if (unresolved_count == 1)
662 mod_timer(&aarp_timer, jiffies + sysctl_aarp_tick_time);
663
664
665out_unlock:
666 write_unlock_bh(&aarp_lock);
667
668
669 goto sent;
670
671sendit:
672 if (skb->sk)
673 skb->priority = skb->sk->sk_priority;
674 if (dev_queue_xmit(skb))
675 goto drop;
676sent:
677 return NET_XMIT_SUCCESS;
678free_it:
679 kfree_skb(skb);
680drop:
681 return NET_XMIT_DROP;
682}
683EXPORT_SYMBOL(aarp_send_ddp);
684
685
686
687
688
689
690
691static void __aarp_resolved(struct aarp_entry **list, struct aarp_entry *a,
692 int hash)
693{
694 struct sk_buff *skb;
695
696 while (*list)
697 if (*list == a) {
698 unresolved_count--;
699 *list = a->next;
700
701
702 a->next = resolved[hash];
703 resolved[hash] = a;
704
705
706 while ((skb = skb_dequeue(&a->packet_queue)) != NULL) {
707 a->expires_at = jiffies +
708 sysctl_aarp_expiry_time * 10;
709 ddp_dl->request(ddp_dl, skb, a->hwaddr);
710 }
711 } else
712 list = &((*list)->next);
713}
714
715
716
717
718
719static int aarp_rcv(struct sk_buff *skb, struct net_device *dev,
720 struct packet_type *pt, struct net_device *orig_dev)
721{
722 struct elapaarp *ea = aarp_hdr(skb);
723 int hash, ret = 0;
724 __u16 function;
725 struct aarp_entry *a;
726 struct atalk_addr sa, *ma, da;
727 struct atalk_iface *ifa;
728
729 if (!net_eq(dev_net(dev), &init_net))
730 goto out0;
731
732
733 if (dev->type != ARPHRD_ETHER)
734 goto out0;
735
736
737 if (!skb_pull(skb, sizeof(*ea)))
738 goto out0;
739
740 function = ntohs(ea->function);
741
742
743 if (function < AARP_REQUEST || function > AARP_PROBE ||
744 ea->hw_len != ETH_ALEN || ea->pa_len != AARP_PA_ALEN ||
745 ea->pa_src_zero || ea->pa_dst_zero)
746 goto out0;
747
748
749 hash = ea->pa_src_node % (AARP_HASH_SIZE - 1);
750
751
752 sa.s_node = ea->pa_src_node;
753 sa.s_net = ea->pa_src_net;
754
755
756 ifa = atalk_find_dev(dev);
757 if (!ifa)
758 goto out1;
759
760 if (ifa->status & ATIF_PROBE &&
761 ifa->address.s_node == ea->pa_dst_node &&
762 ifa->address.s_net == ea->pa_dst_net) {
763 ifa->status |= ATIF_PROBE_FAIL;
764 goto out1;
765 }
766
767
768 da.s_node = ea->pa_dst_node;
769 da.s_net = ea->pa_dst_net;
770
771 write_lock_bh(&aarp_lock);
772 a = __aarp_find_entry(proxies[hash], dev, &da);
773
774 if (a && a->status & ATIF_PROBE) {
775 a->status |= ATIF_PROBE_FAIL;
776
777
778
779
780 goto unlock;
781 }
782
783 switch (function) {
784 case AARP_REPLY:
785 if (!unresolved_count)
786 break;
787
788
789 a = __aarp_find_entry(unresolved[hash], dev, &sa);
790 if (!a || dev != a->dev)
791 break;
792
793
794 ether_addr_copy(a->hwaddr, ea->hw_src);
795 __aarp_resolved(&unresolved[hash], a, hash);
796 if (!unresolved_count)
797 mod_timer(&aarp_timer,
798 jiffies + sysctl_aarp_expiry_time);
799 break;
800
801 case AARP_REQUEST:
802 case AARP_PROBE:
803
804
805
806
807
808
809
810
811
812
813
814
815
816 sa.s_node = ea->pa_dst_node;
817 sa.s_net = ea->pa_dst_net;
818
819
820 ma = __aarp_proxy_find(dev, &sa);
821 if (!ma)
822 ma = &ifa->address;
823 else {
824 da.s_node = sa.s_node;
825 da.s_net = sa.s_net;
826 ma = &da;
827 }
828
829 if (function == AARP_PROBE) {
830
831
832
833
834
835 a = __aarp_find_entry(resolved[sa.s_node %
836 (AARP_HASH_SIZE - 1)],
837 skb->dev, &sa);
838
839
840
841
842
843
844
845 if (a) {
846 a->expires_at = jiffies - 1;
847 mod_timer(&aarp_timer, jiffies +
848 sysctl_aarp_tick_time);
849 }
850 }
851
852 if (sa.s_node != ma->s_node)
853 break;
854
855 if (sa.s_net && ma->s_net && sa.s_net != ma->s_net)
856 break;
857
858 sa.s_node = ea->pa_src_node;
859 sa.s_net = ea->pa_src_net;
860
861
862
863 aarp_send_reply(dev, ma, &sa, ea->hw_src);
864 break;
865 }
866
867unlock:
868 write_unlock_bh(&aarp_lock);
869out1:
870 ret = 1;
871out0:
872 kfree_skb(skb);
873 return ret;
874}
875
876static struct notifier_block aarp_notifier = {
877 .notifier_call = aarp_device_event,
878};
879
880static unsigned char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
881
882void __init aarp_proto_init(void)
883{
884 aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
885 if (!aarp_dl)
886 printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
887 timer_setup(&aarp_timer, aarp_expire_timeout, 0);
888 aarp_timer.expires = jiffies + sysctl_aarp_expiry_time;
889 add_timer(&aarp_timer);
890 register_netdevice_notifier(&aarp_notifier);
891}
892
893
894void aarp_device_down(struct net_device *dev)
895{
896 int ct;
897
898 write_lock_bh(&aarp_lock);
899
900 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
901 __aarp_expire_device(&resolved[ct], dev);
902 __aarp_expire_device(&unresolved[ct], dev);
903 __aarp_expire_device(&proxies[ct], dev);
904 }
905
906 write_unlock_bh(&aarp_lock);
907}
908
909#ifdef CONFIG_PROC_FS
910
911
912
913
914
915
916static struct aarp_entry *iter_next(struct aarp_iter_state *iter, loff_t *pos)
917{
918 int ct = iter->bucket;
919 struct aarp_entry **table = iter->table;
920 loff_t off = 0;
921 struct aarp_entry *entry;
922
923 rescan:
924 while (ct < AARP_HASH_SIZE) {
925 for (entry = table[ct]; entry; entry = entry->next) {
926 if (!pos || ++off == *pos) {
927 iter->table = table;
928 iter->bucket = ct;
929 return entry;
930 }
931 }
932 ++ct;
933 }
934
935 if (table == resolved) {
936 ct = 0;
937 table = unresolved;
938 goto rescan;
939 }
940 if (table == unresolved) {
941 ct = 0;
942 table = proxies;
943 goto rescan;
944 }
945 return NULL;
946}
947
948static void *aarp_seq_start(struct seq_file *seq, loff_t *pos)
949 __acquires(aarp_lock)
950{
951 struct aarp_iter_state *iter = seq->private;
952
953 read_lock_bh(&aarp_lock);
954 iter->table = resolved;
955 iter->bucket = 0;
956
957 return *pos ? iter_next(iter, pos) : SEQ_START_TOKEN;
958}
959
960static void *aarp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
961{
962 struct aarp_entry *entry = v;
963 struct aarp_iter_state *iter = seq->private;
964
965 ++*pos;
966
967
968 if (v == SEQ_START_TOKEN)
969 entry = iter_next(iter, NULL);
970
971
972 else if (entry->next)
973 entry = entry->next;
974
975
976 else {
977 ++iter->bucket;
978 entry = iter_next(iter, NULL);
979 }
980 return entry;
981}
982
983static void aarp_seq_stop(struct seq_file *seq, void *v)
984 __releases(aarp_lock)
985{
986 read_unlock_bh(&aarp_lock);
987}
988
989static const char *dt2str(unsigned long ticks)
990{
991 static char buf[32];
992
993 sprintf(buf, "%ld.%02ld", ticks / HZ, ((ticks % HZ) * 100) / HZ);
994
995 return buf;
996}
997
998static int aarp_seq_show(struct seq_file *seq, void *v)
999{
1000 struct aarp_iter_state *iter = seq->private;
1001 struct aarp_entry *entry = v;
1002 unsigned long now = jiffies;
1003
1004 if (v == SEQ_START_TOKEN)
1005 seq_puts(seq,
1006 "Address Interface Hardware Address"
1007 " Expires LastSend Retry Status\n");
1008 else {
1009 seq_printf(seq, "%04X:%02X %-12s",
1010 ntohs(entry->target_addr.s_net),
1011 (unsigned int) entry->target_addr.s_node,
1012 entry->dev ? entry->dev->name : "????");
1013 seq_printf(seq, "%pM", entry->hwaddr);
1014 seq_printf(seq, " %8s",
1015 dt2str((long)entry->expires_at - (long)now));
1016 if (iter->table == unresolved)
1017 seq_printf(seq, " %8s %6hu",
1018 dt2str(now - entry->last_sent),
1019 entry->xmit_count);
1020 else
1021 seq_puts(seq, " ");
1022 seq_printf(seq, " %s\n",
1023 (iter->table == resolved) ? "resolved"
1024 : (iter->table == unresolved) ? "unresolved"
1025 : (iter->table == proxies) ? "proxies"
1026 : "unknown");
1027 }
1028 return 0;
1029}
1030
1031const struct seq_operations aarp_seq_ops = {
1032 .start = aarp_seq_start,
1033 .next = aarp_seq_next,
1034 .stop = aarp_seq_stop,
1035 .show = aarp_seq_show,
1036};
1037#endif
1038
1039
1040void aarp_cleanup_module(void)
1041{
1042 del_timer_sync(&aarp_timer);
1043 unregister_netdevice_notifier(&aarp_notifier);
1044 unregister_snap_client(aarp_dl);
1045 aarp_purge();
1046}
1047