2 * AARP: An implementation of the AppleTalk AARP protocol for
5 * Alan Cox <Alan.Cox@linux.org>
7 * This doesn't fit cleanly with the IP arp. Potentially we can use
8 * the generic neighbour discovery code to clean this up.
11 * We ought to handle the retransmits with a single list and a
12 * separate fast timer for when it is needed.
13 * Use neighbour discovery code.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
23 * Inside AppleTalk (2nd Ed).
25 * Jaume Grau - flush caches on AARP_PROBE
26 * Rob Newberry - Added proxy AARP and AARP proc fs,
27 * moved probing from DDP module.
28 * Arnaldo C. Melo - don't mangle rx packets
32 #include <linux/if_arp.h>
34 #include <net/datalink.h>
35 #include <net/psnap.h>
36 #include <linux/atalk.h>
37 #include <linux/delay.h>
38 #include <linux/init.h>
39 #include <linux/proc_fs.h>
40 #include <linux/seq_file.h>
42 int sysctl_aarp_expiry_time = AARP_EXPIRY_TIME;
43 int sysctl_aarp_tick_time = AARP_TICK_TIME;
44 int sysctl_aarp_retransmit_limit = AARP_RETRANSMIT_LIMIT;
45 int sysctl_aarp_resolve_time = AARP_RESOLVE_TIME;
47 /* Lists of aarp entries */
49 * struct aarp_entry - AARP entry
50 * @last_sent - Last time we xmitted the aarp request
51 * @packet_queue - Queue of frames wait for resolution
52 * @status - Used for proxy AARP
53 * expires_at - Entry expiry time
54 * target_addr - DDP Address
56 * hwaddr - Physical i/f address of target/router
57 * xmit_count - When this hits 10 we give up
58 * next - Next entry in chain
61 /* These first two are only used for unresolved entries */
62 unsigned long last_sent;
63 struct sk_buff_head packet_queue;
65 unsigned long expires_at;
66 struct atalk_addr target_addr;
67 struct net_device *dev;
69 unsigned short xmit_count;
70 struct aarp_entry *next;
73 /* Hashed list of resolved, unresolved and proxy entries */
74 static struct aarp_entry *resolved[AARP_HASH_SIZE];
75 static struct aarp_entry *unresolved[AARP_HASH_SIZE];
76 static struct aarp_entry *proxies[AARP_HASH_SIZE];
77 static int unresolved_count;
79 /* One lock protects it all. */
80 static DEFINE_RWLOCK(aarp_lock);
82 /* Used to walk the list and purge/kick entries. */
83 static struct timer_list aarp_timer;
86 * Delete an aarp queue
88 * Must run under aarp_lock.
90 static void __aarp_expire(struct aarp_entry *a)
92 skb_queue_purge(&a->packet_queue);
97 * Send an aarp queue entry request
99 * Must run under aarp_lock.
101 static void __aarp_send_query(struct aarp_entry *a)
103 static unsigned char aarp_eth_multicast[ETH_ALEN] =
104 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
105 struct net_device *dev = a->dev;
106 struct elapaarp *eah;
107 int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length;
108 struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
109 struct atalk_addr *sat = atalk_find_dev_addr(dev);
119 /* Set up the buffer */
120 skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
121 skb_reset_network_header(skb);
122 skb_reset_transport_header(skb);
123 skb_put(skb, sizeof(*eah));
124 skb->protocol = htons(ETH_P_ATALK);
129 eah->hw_type = htons(AARP_HW_TYPE_ETHERNET);
130 eah->pa_type = htons(ETH_P_ATALK);
131 eah->hw_len = ETH_ALEN;
132 eah->pa_len = AARP_PA_ALEN;
133 eah->function = htons(AARP_REQUEST);
135 memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN);
137 eah->pa_src_zero = 0;
138 eah->pa_src_net = sat->s_net;
139 eah->pa_src_node = sat->s_node;
141 memset(eah->hw_dst, '\0', ETH_ALEN);
143 eah->pa_dst_zero = 0;
144 eah->pa_dst_net = a->target_addr.s_net;
145 eah->pa_dst_node = a->target_addr.s_node;
148 aarp_dl->request(aarp_dl, skb, aarp_eth_multicast);
149 /* Update the sending count */
151 a->last_sent = jiffies;
154 /* This runs under aarp_lock and in softint context, so only atomic memory
155 * allocations can be used. */
156 static void aarp_send_reply(struct net_device *dev, struct atalk_addr *us,
157 struct atalk_addr *them, unsigned char *sha)
159 struct elapaarp *eah;
160 int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length;
161 struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
166 /* Set up the buffer */
167 skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
168 skb_reset_network_header(skb);
169 skb_reset_transport_header(skb);
170 skb_put(skb, sizeof(*eah));
171 skb->protocol = htons(ETH_P_ATALK);
176 eah->hw_type = htons(AARP_HW_TYPE_ETHERNET);
177 eah->pa_type = htons(ETH_P_ATALK);
178 eah->hw_len = ETH_ALEN;
179 eah->pa_len = AARP_PA_ALEN;
180 eah->function = htons(AARP_REPLY);
182 memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN);
184 eah->pa_src_zero = 0;
185 eah->pa_src_net = us->s_net;
186 eah->pa_src_node = us->s_node;
189 memset(eah->hw_dst, '\0', ETH_ALEN);
191 memcpy(eah->hw_dst, sha, ETH_ALEN);
193 eah->pa_dst_zero = 0;
194 eah->pa_dst_net = them->s_net;
195 eah->pa_dst_node = them->s_node;
198 aarp_dl->request(aarp_dl, skb, sha);
202 * Send probe frames. Called from aarp_probe_network and
203 * aarp_proxy_probe_network.
206 static void aarp_send_probe(struct net_device *dev, struct atalk_addr *us)
208 struct elapaarp *eah;
209 int len = dev->hard_header_len + sizeof(*eah) + aarp_dl->header_length;
210 struct sk_buff *skb = alloc_skb(len, GFP_ATOMIC);
211 static unsigned char aarp_eth_multicast[ETH_ALEN] =
212 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
217 /* Set up the buffer */
218 skb_reserve(skb, dev->hard_header_len + aarp_dl->header_length);
219 skb_reset_network_header(skb);
220 skb_reset_transport_header(skb);
221 skb_put(skb, sizeof(*eah));
222 skb->protocol = htons(ETH_P_ATALK);
227 eah->hw_type = htons(AARP_HW_TYPE_ETHERNET);
228 eah->pa_type = htons(ETH_P_ATALK);
229 eah->hw_len = ETH_ALEN;
230 eah->pa_len = AARP_PA_ALEN;
231 eah->function = htons(AARP_PROBE);
233 memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN);
235 eah->pa_src_zero = 0;
236 eah->pa_src_net = us->s_net;
237 eah->pa_src_node = us->s_node;
239 memset(eah->hw_dst, '\0', ETH_ALEN);
241 eah->pa_dst_zero = 0;
242 eah->pa_dst_net = us->s_net;
243 eah->pa_dst_node = us->s_node;
246 aarp_dl->request(aarp_dl, skb, aarp_eth_multicast);
250 * Handle an aarp timer expire
252 * Must run under the aarp_lock.
255 static void __aarp_expire_timer(struct aarp_entry **n)
257 struct aarp_entry *t;
261 if (time_after(jiffies, (*n)->expires_at)) {
270 * Kick all pending requests 5 times a second.
272 * Must run under the aarp_lock.
274 static void __aarp_kick(struct aarp_entry **n)
276 struct aarp_entry *t;
279 /* Expired: if this will be the 11th tx, we delete instead. */
280 if ((*n)->xmit_count >= sysctl_aarp_retransmit_limit) {
285 __aarp_send_query(*n);
291 * A device has gone down. Take all entries referring to the device
294 * Must run under the aarp_lock.
296 static void __aarp_expire_device(struct aarp_entry **n, struct net_device *dev)
298 struct aarp_entry *t;
301 if ((*n)->dev == dev) {
309 /* Handle the timer event */
310 static void aarp_expire_timeout(unsigned long unused)
314 write_lock_bh(&aarp_lock);
316 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
317 __aarp_expire_timer(&resolved[ct]);
318 __aarp_kick(&unresolved[ct]);
319 __aarp_expire_timer(&unresolved[ct]);
320 __aarp_expire_timer(&proxies[ct]);
323 write_unlock_bh(&aarp_lock);
324 mod_timer(&aarp_timer, jiffies +
325 (unresolved_count ? sysctl_aarp_tick_time :
326 sysctl_aarp_expiry_time));
329 /* Network device notifier chain handler. */
330 static int aarp_device_event(struct notifier_block *this, unsigned long event,
333 struct net_device *dev = ptr;
336 if (event == NETDEV_DOWN) {
337 write_lock_bh(&aarp_lock);
339 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
340 __aarp_expire_device(&resolved[ct], dev);
341 __aarp_expire_device(&unresolved[ct], dev);
342 __aarp_expire_device(&proxies[ct], dev);
345 write_unlock_bh(&aarp_lock);
350 /* Expire all entries in a hash chain */
351 static void __aarp_expire_all(struct aarp_entry **n)
353 struct aarp_entry *t;
362 /* Cleanup all hash chains -- module unloading */
363 static void aarp_purge(void)
367 write_lock_bh(&aarp_lock);
368 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
369 __aarp_expire_all(&resolved[ct]);
370 __aarp_expire_all(&unresolved[ct]);
371 __aarp_expire_all(&proxies[ct]);
373 write_unlock_bh(&aarp_lock);
377 * Create a new aarp entry. This must use GFP_ATOMIC because it
378 * runs while holding spinlocks.
380 static struct aarp_entry *aarp_alloc(void)
382 struct aarp_entry *a = kmalloc(sizeof(*a), GFP_ATOMIC);
385 skb_queue_head_init(&a->packet_queue);
390 * Find an entry. We might return an expired but not yet purged entry. We
391 * don't care as it will do no harm.
393 * This must run under the aarp_lock.
395 static struct aarp_entry *__aarp_find_entry(struct aarp_entry *list,
396 struct net_device *dev,
397 struct atalk_addr *sat)
400 if (list->target_addr.s_net == sat->s_net &&
401 list->target_addr.s_node == sat->s_node &&
410 /* Called from the DDP code, and thus must be exported. */
411 void aarp_proxy_remove(struct net_device *dev, struct atalk_addr *sa)
413 int hash = sa->s_node % (AARP_HASH_SIZE - 1);
414 struct aarp_entry *a;
416 write_lock_bh(&aarp_lock);
418 a = __aarp_find_entry(proxies[hash], dev, sa);
420 a->expires_at = jiffies - 1;
422 write_unlock_bh(&aarp_lock);
425 /* This must run under aarp_lock. */
426 static struct atalk_addr *__aarp_proxy_find(struct net_device *dev,
427 struct atalk_addr *sa)
429 int hash = sa->s_node % (AARP_HASH_SIZE - 1);
430 struct aarp_entry *a = __aarp_find_entry(proxies[hash], dev, sa);
432 return a ? sa : NULL;
436 * Probe a Phase 1 device or a device that requires its Net:Node to
437 * be set via an ioctl.
439 static void aarp_send_probe_phase1(struct atalk_iface *iface)
442 struct sockaddr_at *sa = (struct sockaddr_at *)&atreq.ifr_addr;
444 sa->sat_addr.s_node = iface->address.s_node;
445 sa->sat_addr.s_net = ntohs(iface->address.s_net);
447 /* We pass the Net:Node to the drivers/cards by a Device ioctl. */
448 if (!(iface->dev->do_ioctl(iface->dev, &atreq, SIOCSIFADDR))) {
449 (void)iface->dev->do_ioctl(iface->dev, &atreq, SIOCGIFADDR);
450 if (iface->address.s_net != htons(sa->sat_addr.s_net) ||
451 iface->address.s_node != sa->sat_addr.s_node)
452 iface->status |= ATIF_PROBE_FAIL;
454 iface->address.s_net = htons(sa->sat_addr.s_net);
455 iface->address.s_node = sa->sat_addr.s_node;
460 void aarp_probe_network(struct atalk_iface *atif)
462 if (atif->dev->type == ARPHRD_LOCALTLK ||
463 atif->dev->type == ARPHRD_PPP)
464 aarp_send_probe_phase1(atif);
468 for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) {
469 aarp_send_probe(atif->dev, &atif->address);
474 if (atif->status & ATIF_PROBE_FAIL)
480 int aarp_proxy_probe_network(struct atalk_iface *atif, struct atalk_addr *sa)
482 int hash, retval = -EPROTONOSUPPORT;
483 struct aarp_entry *entry;
487 * we don't currently support LocalTalk or PPP for proxy AARP;
488 * if someone wants to try and add it, have fun
490 if (atif->dev->type == ARPHRD_LOCALTLK ||
491 atif->dev->type == ARPHRD_PPP)
495 * create a new AARP entry with the flags set to be published --
496 * we need this one to hang around even if it's in use
498 entry = aarp_alloc();
503 entry->expires_at = -1;
504 entry->status = ATIF_PROBE;
505 entry->target_addr.s_node = sa->s_node;
506 entry->target_addr.s_net = sa->s_net;
507 entry->dev = atif->dev;
509 write_lock_bh(&aarp_lock);
511 hash = sa->s_node % (AARP_HASH_SIZE - 1);
512 entry->next = proxies[hash];
513 proxies[hash] = entry;
515 for (count = 0; count < AARP_RETRANSMIT_LIMIT; count++) {
516 aarp_send_probe(atif->dev, sa);
519 write_unlock_bh(&aarp_lock);
521 write_lock_bh(&aarp_lock);
523 if (entry->status & ATIF_PROBE_FAIL)
527 if (entry->status & ATIF_PROBE_FAIL) {
528 entry->expires_at = jiffies - 1; /* free the entry */
529 retval = -EADDRINUSE; /* return network full */
530 } else { /* clear the probing flag */
531 entry->status &= ~ATIF_PROBE;
535 write_unlock_bh(&aarp_lock);
540 /* Send a DDP frame */
541 int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb,
542 struct atalk_addr *sa, void *hwaddr)
544 static char ddp_eth_multicast[ETH_ALEN] =
545 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
547 struct aarp_entry *a;
549 skb_reset_network_header(skb);
551 /* Check for LocalTalk first */
552 if (dev->type == ARPHRD_LOCALTLK) {
553 struct atalk_addr *at = atalk_find_dev_addr(dev);
554 struct ddpehdr *ddp = (struct ddpehdr *)skb->data;
560 * IFF: src_net == dest_net == device_net
561 * (zero matches anything)
564 if ((!ddp->deh_snet || at->s_net == ddp->deh_snet) &&
565 (!ddp->deh_dnet || at->s_net == ddp->deh_dnet)) {
566 skb_pull(skb, sizeof(*ddp) - 4);
569 * The upper two remaining bytes are the port
570 * numbers we just happen to need. Now put the
571 * length in the lower two.
573 *((__be16 *)skb->data) = htons(skb->len);
577 * Nice and easy. No AARP type protocols occur here so we can
578 * just shovel it out with a 3 byte LLAP header
582 skb->data[0] = sa->s_node;
583 skb->data[1] = at->s_node;
589 /* On a PPP link we neither compress nor aarp. */
590 if (dev->type == ARPHRD_PPP) {
591 skb->protocol = htons(ETH_P_PPPTALK);
596 /* Non ELAP we cannot do. */
597 if (dev->type != ARPHRD_ETHER)
601 skb->protocol = htons(ETH_P_ATALK);
602 hash = sa->s_node % (AARP_HASH_SIZE - 1);
604 /* Do we have a resolved entry? */
605 if (sa->s_node == ATADDR_BCAST) {
607 ddp_dl->request(ddp_dl, skb, ddp_eth_multicast);
611 write_lock_bh(&aarp_lock);
612 a = __aarp_find_entry(resolved[hash], dev, sa);
614 if (a) { /* Return 1 and fill in the address */
615 a->expires_at = jiffies + (sysctl_aarp_expiry_time * 10);
616 ddp_dl->request(ddp_dl, skb, a->hwaddr);
617 write_unlock_bh(&aarp_lock);
621 /* Do we have an unresolved entry: This is the less common path */
622 a = __aarp_find_entry(unresolved[hash], dev, sa);
623 if (a) { /* Queue onto the unresolved queue */
624 skb_queue_tail(&a->packet_queue, skb);
628 /* Allocate a new entry */
631 /* Whoops slipped... good job it's an unreliable protocol 8) */
632 write_unlock_bh(&aarp_lock);
636 /* Set up the queue */
637 skb_queue_tail(&a->packet_queue, skb);
638 a->expires_at = jiffies + sysctl_aarp_resolve_time;
640 a->next = unresolved[hash];
641 a->target_addr = *sa;
643 unresolved[hash] = a;
646 /* Send an initial request for the address */
647 __aarp_send_query(a);
650 * Switch to fast timer if needed (That is if this is the first
651 * unresolved entry to get added)
654 if (unresolved_count == 1)
655 mod_timer(&aarp_timer, jiffies + sysctl_aarp_tick_time);
657 /* Now finally, it is safe to drop the lock. */
659 write_unlock_bh(&aarp_lock);
661 /* Tell the ddp layer we have taken over for this frame. */
666 skb->priority = skb->sk->sk_priority;
673 * An entry in the aarp unresolved queue has become resolved. Send
674 * all the frames queued under it.
676 * Must run under aarp_lock.
678 static void __aarp_resolved(struct aarp_entry **list, struct aarp_entry *a,
688 /* Move into the resolved list */
689 a->next = resolved[hash];
692 /* Kick frames off */
693 while ((skb = skb_dequeue(&a->packet_queue)) != NULL) {
694 a->expires_at = jiffies +
695 sysctl_aarp_expiry_time * 10;
696 ddp_dl->request(ddp_dl, skb, a->hwaddr);
699 list = &((*list)->next);
703 * This is called by the SNAP driver whenever we see an AARP SNAP
704 * frame. We currently only support Ethernet.
706 static int aarp_rcv(struct sk_buff *skb, struct net_device *dev,
707 struct packet_type *pt, struct net_device *orig_dev)
709 struct elapaarp *ea = aarp_hdr(skb);
712 struct aarp_entry *a;
713 struct atalk_addr sa, *ma, da;
714 struct atalk_iface *ifa;
716 if (dev->nd_net != &init_net)
719 /* We only do Ethernet SNAP AARP. */
720 if (dev->type != ARPHRD_ETHER)
724 if (!skb_pull(skb, sizeof(*ea)))
727 function = ntohs(ea->function);
729 /* Sanity check fields. */
730 if (function < AARP_REQUEST || function > AARP_PROBE ||
731 ea->hw_len != ETH_ALEN || ea->pa_len != AARP_PA_ALEN ||
732 ea->pa_src_zero || ea->pa_dst_zero)
736 hash = ea->pa_src_node % (AARP_HASH_SIZE - 1);
738 /* Build an address. */
739 sa.s_node = ea->pa_src_node;
740 sa.s_net = ea->pa_src_net;
742 /* Process the packet. Check for replies of me. */
743 ifa = atalk_find_dev(dev);
747 if (ifa->status & ATIF_PROBE &&
748 ifa->address.s_node == ea->pa_dst_node &&
749 ifa->address.s_net == ea->pa_dst_net) {
750 ifa->status |= ATIF_PROBE_FAIL; /* Fail the probe (in use) */
754 /* Check for replies of proxy AARP entries */
755 da.s_node = ea->pa_dst_node;
756 da.s_net = ea->pa_dst_net;
758 write_lock_bh(&aarp_lock);
759 a = __aarp_find_entry(proxies[hash], dev, &da);
761 if (a && a->status & ATIF_PROBE) {
762 a->status |= ATIF_PROBE_FAIL;
764 * we do not respond to probe or request packets for
765 * this address while we are probing this address
772 if (!unresolved_count) /* Speed up */
775 /* Find the entry. */
776 a = __aarp_find_entry(unresolved[hash], dev, &sa);
777 if (!a || dev != a->dev)
780 /* We can fill one in - this is good. */
781 memcpy(a->hwaddr, ea->hw_src, ETH_ALEN);
782 __aarp_resolved(&unresolved[hash], a, hash);
783 if (!unresolved_count)
784 mod_timer(&aarp_timer,
785 jiffies + sysctl_aarp_expiry_time);
792 * If it is my address set ma to my address and reply.
793 * We can treat probe and request the same. Probe
794 * simply means we shouldn't cache the querying host,
795 * as in a probe they are proposing an address not
798 * Support for proxy-AARP added. We check if the
799 * address is one of our proxies before we toss the
803 sa.s_node = ea->pa_dst_node;
804 sa.s_net = ea->pa_dst_net;
806 /* See if we have a matching proxy. */
807 ma = __aarp_proxy_find(dev, &sa);
810 else { /* We need to make a copy of the entry. */
811 da.s_node = sa.s_node;
816 if (function == AARP_PROBE) {
818 * A probe implies someone trying to get an
819 * address. So as a precaution flush any
820 * entries we have for this address.
822 struct aarp_entry *a;
824 a = __aarp_find_entry(resolved[sa.s_node %
825 (AARP_HASH_SIZE - 1)],
829 * Make it expire next tick - that avoids us
830 * getting into a probe/flush/learn/probe/
831 * flush/learn cycle during probing of a slow
832 * to respond host addr.
835 a->expires_at = jiffies - 1;
836 mod_timer(&aarp_timer, jiffies +
837 sysctl_aarp_tick_time);
841 if (sa.s_node != ma->s_node)
844 if (sa.s_net && ma->s_net && sa.s_net != ma->s_net)
847 sa.s_node = ea->pa_src_node;
848 sa.s_net = ea->pa_src_net;
850 /* aarp_my_address has found the address to use for us.
852 aarp_send_reply(dev, ma, &sa, ea->hw_src);
857 write_unlock_bh(&aarp_lock);
865 static struct notifier_block aarp_notifier = {
866 .notifier_call = aarp_device_event,
869 static unsigned char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
871 void __init aarp_proto_init(void)
873 aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
875 printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
876 init_timer(&aarp_timer);
877 aarp_timer.function = aarp_expire_timeout;
879 aarp_timer.expires = jiffies + sysctl_aarp_expiry_time;
880 add_timer(&aarp_timer);
881 register_netdevice_notifier(&aarp_notifier);
884 /* Remove the AARP entries associated with a device. */
885 void aarp_device_down(struct net_device *dev)
889 write_lock_bh(&aarp_lock);
891 for (ct = 0; ct < AARP_HASH_SIZE; ct++) {
892 __aarp_expire_device(&resolved[ct], dev);
893 __aarp_expire_device(&unresolved[ct], dev);
894 __aarp_expire_device(&proxies[ct], dev);
897 write_unlock_bh(&aarp_lock);
900 #ifdef CONFIG_PROC_FS
901 struct aarp_iter_state {
903 struct aarp_entry **table;
907 * Get the aarp entry that is in the chain described
909 * If pos is set then skip till that index.
910 * pos = 1 is the first entry
912 static struct aarp_entry *iter_next(struct aarp_iter_state *iter, loff_t *pos)
914 int ct = iter->bucket;
915 struct aarp_entry **table = iter->table;
917 struct aarp_entry *entry;
920 while(ct < AARP_HASH_SIZE) {
921 for (entry = table[ct]; entry; entry = entry->next) {
922 if (!pos || ++off == *pos) {
931 if (table == resolved) {
936 if (table == unresolved) {
944 static void *aarp_seq_start(struct seq_file *seq, loff_t *pos)
946 struct aarp_iter_state *iter = seq->private;
948 read_lock_bh(&aarp_lock);
949 iter->table = resolved;
952 return *pos ? iter_next(iter, pos) : SEQ_START_TOKEN;
955 static void *aarp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
957 struct aarp_entry *entry = v;
958 struct aarp_iter_state *iter = seq->private;
962 /* first line after header */
963 if (v == SEQ_START_TOKEN)
964 entry = iter_next(iter, NULL);
966 /* next entry in current bucket */
967 else if (entry->next)
970 /* next bucket or table */
973 entry = iter_next(iter, NULL);
978 static void aarp_seq_stop(struct seq_file *seq, void *v)
980 read_unlock_bh(&aarp_lock);
983 static const char *dt2str(unsigned long ticks)
987 sprintf(buf, "%ld.%02ld", ticks / HZ, ((ticks % HZ) * 100 ) / HZ);
992 static int aarp_seq_show(struct seq_file *seq, void *v)
994 struct aarp_iter_state *iter = seq->private;
995 struct aarp_entry *entry = v;
996 unsigned long now = jiffies;
998 if (v == SEQ_START_TOKEN)
1000 "Address Interface Hardware Address"
1001 " Expires LastSend Retry Status\n");
1003 seq_printf(seq, "%04X:%02X %-12s",
1004 ntohs(entry->target_addr.s_net),
1005 (unsigned int) entry->target_addr.s_node,
1006 entry->dev ? entry->dev->name : "????");
1007 seq_printf(seq, "%02X:%02X:%02X:%02X:%02X:%02X",
1008 entry->hwaddr[0] & 0xFF,
1009 entry->hwaddr[1] & 0xFF,
1010 entry->hwaddr[2] & 0xFF,
1011 entry->hwaddr[3] & 0xFF,
1012 entry->hwaddr[4] & 0xFF,
1013 entry->hwaddr[5] & 0xFF);
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),
1022 seq_printf(seq, " %s\n",
1023 (iter->table == resolved) ? "resolved"
1024 : (iter->table == unresolved) ? "unresolved"
1025 : (iter->table == proxies) ? "proxies"
1031 static const 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,
1038 static int aarp_seq_open(struct inode *inode, struct file *file)
1040 struct seq_file *seq;
1042 struct aarp_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
1047 rc = seq_open(file, &aarp_seq_ops);
1051 seq = file->private_data;
1053 memset(s, 0, sizeof(*s));
1061 const struct file_operations atalk_seq_arp_fops = {
1062 .owner = THIS_MODULE,
1063 .open = aarp_seq_open,
1065 .llseek = seq_lseek,
1066 .release = seq_release_private,
1070 /* General module cleanup. Called from cleanup_module() in ddp.c. */
1071 void aarp_cleanup_module(void)
1073 del_timer_sync(&aarp_timer);
1074 unregister_netdevice_notifier(&aarp_notifier);
1075 unregister_snap_client(aarp_dl);