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>
33 #include <linux/slab.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>
43 int sysctl_aarp_expiry_time
= AARP_EXPIRY_TIME
;
44 int sysctl_aarp_tick_time
= AARP_TICK_TIME
;
45 int sysctl_aarp_retransmit_limit
= AARP_RETRANSMIT_LIMIT
;
46 int sysctl_aarp_resolve_time
= AARP_RESOLVE_TIME
;
48 /* Lists of aarp entries */
50 * struct aarp_entry - AARP entry
51 * @last_sent - Last time we xmitted the aarp request
52 * @packet_queue - Queue of frames wait for resolution
53 * @status - Used for proxy AARP
54 * expires_at - Entry expiry time
55 * target_addr - DDP Address
57 * hwaddr - Physical i/f address of target/router
58 * xmit_count - When this hits 10 we give up
59 * next - Next entry in chain
62 /* These first two are only used for unresolved entries */
63 unsigned long last_sent
;
64 struct sk_buff_head packet_queue
;
66 unsigned long expires_at
;
67 struct atalk_addr target_addr
;
68 struct net_device
*dev
;
70 unsigned short xmit_count
;
71 struct aarp_entry
*next
;
74 /* Hashed list of resolved, unresolved and proxy entries */
75 static struct aarp_entry
*resolved
[AARP_HASH_SIZE
];
76 static struct aarp_entry
*unresolved
[AARP_HASH_SIZE
];
77 static struct aarp_entry
*proxies
[AARP_HASH_SIZE
];
78 static int unresolved_count
;
80 /* One lock protects it all. */
81 static DEFINE_RWLOCK(aarp_lock
);
83 /* Used to walk the list and purge/kick entries. */
84 static struct timer_list aarp_timer
;
87 * Delete an aarp queue
89 * Must run under aarp_lock.
91 static void __aarp_expire(struct aarp_entry
*a
)
93 skb_queue_purge(&a
->packet_queue
);
98 * Send an aarp queue entry request
100 * Must run under aarp_lock.
102 static void __aarp_send_query(struct aarp_entry
*a
)
104 static unsigned char aarp_eth_multicast
[ETH_ALEN
] =
105 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
106 struct net_device
*dev
= a
->dev
;
107 struct elapaarp
*eah
;
108 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
109 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
110 struct atalk_addr
*sat
= atalk_find_dev_addr(dev
);
120 /* Set up the buffer */
121 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
122 skb_reset_network_header(skb
);
123 skb_reset_transport_header(skb
);
124 skb_put(skb
, sizeof(*eah
));
125 skb
->protocol
= htons(ETH_P_ATALK
);
130 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
131 eah
->pa_type
= htons(ETH_P_ATALK
);
132 eah
->hw_len
= ETH_ALEN
;
133 eah
->pa_len
= AARP_PA_ALEN
;
134 eah
->function
= htons(AARP_REQUEST
);
136 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
138 eah
->pa_src_zero
= 0;
139 eah
->pa_src_net
= sat
->s_net
;
140 eah
->pa_src_node
= sat
->s_node
;
142 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
144 eah
->pa_dst_zero
= 0;
145 eah
->pa_dst_net
= a
->target_addr
.s_net
;
146 eah
->pa_dst_node
= a
->target_addr
.s_node
;
149 aarp_dl
->request(aarp_dl
, skb
, aarp_eth_multicast
);
150 /* Update the sending count */
152 a
->last_sent
= jiffies
;
155 /* This runs under aarp_lock and in softint context, so only atomic memory
156 * allocations can be used. */
157 static void aarp_send_reply(struct net_device
*dev
, struct atalk_addr
*us
,
158 struct atalk_addr
*them
, unsigned char *sha
)
160 struct elapaarp
*eah
;
161 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
162 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
167 /* Set up the buffer */
168 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
169 skb_reset_network_header(skb
);
170 skb_reset_transport_header(skb
);
171 skb_put(skb
, sizeof(*eah
));
172 skb
->protocol
= htons(ETH_P_ATALK
);
177 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
178 eah
->pa_type
= htons(ETH_P_ATALK
);
179 eah
->hw_len
= ETH_ALEN
;
180 eah
->pa_len
= AARP_PA_ALEN
;
181 eah
->function
= htons(AARP_REPLY
);
183 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
185 eah
->pa_src_zero
= 0;
186 eah
->pa_src_net
= us
->s_net
;
187 eah
->pa_src_node
= us
->s_node
;
190 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
192 memcpy(eah
->hw_dst
, sha
, ETH_ALEN
);
194 eah
->pa_dst_zero
= 0;
195 eah
->pa_dst_net
= them
->s_net
;
196 eah
->pa_dst_node
= them
->s_node
;
199 aarp_dl
->request(aarp_dl
, skb
, sha
);
203 * Send probe frames. Called from aarp_probe_network and
204 * aarp_proxy_probe_network.
207 static void aarp_send_probe(struct net_device
*dev
, struct atalk_addr
*us
)
209 struct elapaarp
*eah
;
210 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
211 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
212 static unsigned char aarp_eth_multicast
[ETH_ALEN
] =
213 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
218 /* Set up the buffer */
219 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
220 skb_reset_network_header(skb
);
221 skb_reset_transport_header(skb
);
222 skb_put(skb
, sizeof(*eah
));
223 skb
->protocol
= htons(ETH_P_ATALK
);
228 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
229 eah
->pa_type
= htons(ETH_P_ATALK
);
230 eah
->hw_len
= ETH_ALEN
;
231 eah
->pa_len
= AARP_PA_ALEN
;
232 eah
->function
= htons(AARP_PROBE
);
234 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
236 eah
->pa_src_zero
= 0;
237 eah
->pa_src_net
= us
->s_net
;
238 eah
->pa_src_node
= us
->s_node
;
240 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
242 eah
->pa_dst_zero
= 0;
243 eah
->pa_dst_net
= us
->s_net
;
244 eah
->pa_dst_node
= us
->s_node
;
247 aarp_dl
->request(aarp_dl
, skb
, aarp_eth_multicast
);
251 * Handle an aarp timer expire
253 * Must run under the aarp_lock.
256 static void __aarp_expire_timer(struct aarp_entry
**n
)
258 struct aarp_entry
*t
;
262 if (time_after(jiffies
, (*n
)->expires_at
)) {
271 * Kick all pending requests 5 times a second.
273 * Must run under the aarp_lock.
275 static void __aarp_kick(struct aarp_entry
**n
)
277 struct aarp_entry
*t
;
280 /* Expired: if this will be the 11th tx, we delete instead. */
281 if ((*n
)->xmit_count
>= sysctl_aarp_retransmit_limit
) {
286 __aarp_send_query(*n
);
292 * A device has gone down. Take all entries referring to the device
295 * Must run under the aarp_lock.
297 static void __aarp_expire_device(struct aarp_entry
**n
, struct net_device
*dev
)
299 struct aarp_entry
*t
;
302 if ((*n
)->dev
== dev
) {
310 /* Handle the timer event */
311 static void aarp_expire_timeout(unsigned long unused
)
315 write_lock_bh(&aarp_lock
);
317 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
318 __aarp_expire_timer(&resolved
[ct
]);
319 __aarp_kick(&unresolved
[ct
]);
320 __aarp_expire_timer(&unresolved
[ct
]);
321 __aarp_expire_timer(&proxies
[ct
]);
324 write_unlock_bh(&aarp_lock
);
325 mod_timer(&aarp_timer
, jiffies
+
326 (unresolved_count
? sysctl_aarp_tick_time
:
327 sysctl_aarp_expiry_time
));
330 /* Network device notifier chain handler. */
331 static int aarp_device_event(struct notifier_block
*this, unsigned long event
,
334 struct net_device
*dev
= ptr
;
337 if (!net_eq(dev_net(dev
), &init_net
))
340 if (event
== NETDEV_DOWN
) {
341 write_lock_bh(&aarp_lock
);
343 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
344 __aarp_expire_device(&resolved
[ct
], dev
);
345 __aarp_expire_device(&unresolved
[ct
], dev
);
346 __aarp_expire_device(&proxies
[ct
], dev
);
349 write_unlock_bh(&aarp_lock
);
354 /* Expire all entries in a hash chain */
355 static void __aarp_expire_all(struct aarp_entry
**n
)
357 struct aarp_entry
*t
;
366 /* Cleanup all hash chains -- module unloading */
367 static void aarp_purge(void)
371 write_lock_bh(&aarp_lock
);
372 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
373 __aarp_expire_all(&resolved
[ct
]);
374 __aarp_expire_all(&unresolved
[ct
]);
375 __aarp_expire_all(&proxies
[ct
]);
377 write_unlock_bh(&aarp_lock
);
381 * Create a new aarp entry. This must use GFP_ATOMIC because it
382 * runs while holding spinlocks.
384 static struct aarp_entry
*aarp_alloc(void)
386 struct aarp_entry
*a
= kmalloc(sizeof(*a
), GFP_ATOMIC
);
389 skb_queue_head_init(&a
->packet_queue
);
394 * Find an entry. We might return an expired but not yet purged entry. We
395 * don't care as it will do no harm.
397 * This must run under the aarp_lock.
399 static struct aarp_entry
*__aarp_find_entry(struct aarp_entry
*list
,
400 struct net_device
*dev
,
401 struct atalk_addr
*sat
)
404 if (list
->target_addr
.s_net
== sat
->s_net
&&
405 list
->target_addr
.s_node
== sat
->s_node
&&
414 /* Called from the DDP code, and thus must be exported. */
415 void aarp_proxy_remove(struct net_device
*dev
, struct atalk_addr
*sa
)
417 int hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
418 struct aarp_entry
*a
;
420 write_lock_bh(&aarp_lock
);
422 a
= __aarp_find_entry(proxies
[hash
], dev
, sa
);
424 a
->expires_at
= jiffies
- 1;
426 write_unlock_bh(&aarp_lock
);
429 /* This must run under aarp_lock. */
430 static struct atalk_addr
*__aarp_proxy_find(struct net_device
*dev
,
431 struct atalk_addr
*sa
)
433 int hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
434 struct aarp_entry
*a
= __aarp_find_entry(proxies
[hash
], dev
, sa
);
436 return a
? sa
: NULL
;
440 * Probe a Phase 1 device or a device that requires its Net:Node to
441 * be set via an ioctl.
443 static void aarp_send_probe_phase1(struct atalk_iface
*iface
)
446 struct sockaddr_at
*sa
= (struct sockaddr_at
*)&atreq
.ifr_addr
;
447 const struct net_device_ops
*ops
= iface
->dev
->netdev_ops
;
449 sa
->sat_addr
.s_node
= iface
->address
.s_node
;
450 sa
->sat_addr
.s_net
= ntohs(iface
->address
.s_net
);
452 /* We pass the Net:Node to the drivers/cards by a Device ioctl. */
453 if (!(ops
->ndo_do_ioctl(iface
->dev
, &atreq
, SIOCSIFADDR
))) {
454 ops
->ndo_do_ioctl(iface
->dev
, &atreq
, SIOCGIFADDR
);
455 if (iface
->address
.s_net
!= htons(sa
->sat_addr
.s_net
) ||
456 iface
->address
.s_node
!= sa
->sat_addr
.s_node
)
457 iface
->status
|= ATIF_PROBE_FAIL
;
459 iface
->address
.s_net
= htons(sa
->sat_addr
.s_net
);
460 iface
->address
.s_node
= sa
->sat_addr
.s_node
;
465 void aarp_probe_network(struct atalk_iface
*atif
)
467 if (atif
->dev
->type
== ARPHRD_LOCALTLK
||
468 atif
->dev
->type
== ARPHRD_PPP
)
469 aarp_send_probe_phase1(atif
);
473 for (count
= 0; count
< AARP_RETRANSMIT_LIMIT
; count
++) {
474 aarp_send_probe(atif
->dev
, &atif
->address
);
479 if (atif
->status
& ATIF_PROBE_FAIL
)
485 int aarp_proxy_probe_network(struct atalk_iface
*atif
, struct atalk_addr
*sa
)
487 int hash
, retval
= -EPROTONOSUPPORT
;
488 struct aarp_entry
*entry
;
492 * we don't currently support LocalTalk or PPP for proxy AARP;
493 * if someone wants to try and add it, have fun
495 if (atif
->dev
->type
== ARPHRD_LOCALTLK
||
496 atif
->dev
->type
== ARPHRD_PPP
)
500 * create a new AARP entry with the flags set to be published --
501 * we need this one to hang around even if it's in use
503 entry
= aarp_alloc();
508 entry
->expires_at
= -1;
509 entry
->status
= ATIF_PROBE
;
510 entry
->target_addr
.s_node
= sa
->s_node
;
511 entry
->target_addr
.s_net
= sa
->s_net
;
512 entry
->dev
= atif
->dev
;
514 write_lock_bh(&aarp_lock
);
516 hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
517 entry
->next
= proxies
[hash
];
518 proxies
[hash
] = entry
;
520 for (count
= 0; count
< AARP_RETRANSMIT_LIMIT
; count
++) {
521 aarp_send_probe(atif
->dev
, sa
);
524 write_unlock_bh(&aarp_lock
);
526 write_lock_bh(&aarp_lock
);
528 if (entry
->status
& ATIF_PROBE_FAIL
)
532 if (entry
->status
& ATIF_PROBE_FAIL
) {
533 entry
->expires_at
= jiffies
- 1; /* free the entry */
534 retval
= -EADDRINUSE
; /* return network full */
535 } else { /* clear the probing flag */
536 entry
->status
&= ~ATIF_PROBE
;
540 write_unlock_bh(&aarp_lock
);
545 /* Send a DDP frame */
546 int aarp_send_ddp(struct net_device
*dev
, struct sk_buff
*skb
,
547 struct atalk_addr
*sa
, void *hwaddr
)
549 static char ddp_eth_multicast
[ETH_ALEN
] =
550 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
552 struct aarp_entry
*a
;
554 skb_reset_network_header(skb
);
556 /* Check for LocalTalk first */
557 if (dev
->type
== ARPHRD_LOCALTLK
) {
558 struct atalk_addr
*at
= atalk_find_dev_addr(dev
);
559 struct ddpehdr
*ddp
= (struct ddpehdr
*)skb
->data
;
565 * IFF: src_net == dest_net == device_net
566 * (zero matches anything)
569 if ((!ddp
->deh_snet
|| at
->s_net
== ddp
->deh_snet
) &&
570 (!ddp
->deh_dnet
|| at
->s_net
== ddp
->deh_dnet
)) {
571 skb_pull(skb
, sizeof(*ddp
) - 4);
574 * The upper two remaining bytes are the port
575 * numbers we just happen to need. Now put the
576 * length in the lower two.
578 *((__be16
*)skb
->data
) = htons(skb
->len
);
582 * Nice and easy. No AARP type protocols occur here so we can
583 * just shovel it out with a 3 byte LLAP header
587 skb
->data
[0] = sa
->s_node
;
588 skb
->data
[1] = at
->s_node
;
594 /* On a PPP link we neither compress nor aarp. */
595 if (dev
->type
== ARPHRD_PPP
) {
596 skb
->protocol
= htons(ETH_P_PPPTALK
);
601 /* Non ELAP we cannot do. */
602 if (dev
->type
!= ARPHRD_ETHER
)
606 skb
->protocol
= htons(ETH_P_ATALK
);
607 hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
609 /* Do we have a resolved entry? */
610 if (sa
->s_node
== ATADDR_BCAST
) {
612 ddp_dl
->request(ddp_dl
, skb
, ddp_eth_multicast
);
616 write_lock_bh(&aarp_lock
);
617 a
= __aarp_find_entry(resolved
[hash
], dev
, sa
);
619 if (a
) { /* Return 1 and fill in the address */
620 a
->expires_at
= jiffies
+ (sysctl_aarp_expiry_time
* 10);
621 ddp_dl
->request(ddp_dl
, skb
, a
->hwaddr
);
622 write_unlock_bh(&aarp_lock
);
626 /* Do we have an unresolved entry: This is the less common path */
627 a
= __aarp_find_entry(unresolved
[hash
], dev
, sa
);
628 if (a
) { /* Queue onto the unresolved queue */
629 skb_queue_tail(&a
->packet_queue
, skb
);
633 /* Allocate a new entry */
636 /* Whoops slipped... good job it's an unreliable protocol 8) */
637 write_unlock_bh(&aarp_lock
);
641 /* Set up the queue */
642 skb_queue_tail(&a
->packet_queue
, skb
);
643 a
->expires_at
= jiffies
+ sysctl_aarp_resolve_time
;
645 a
->next
= unresolved
[hash
];
646 a
->target_addr
= *sa
;
648 unresolved
[hash
] = a
;
651 /* Send an initial request for the address */
652 __aarp_send_query(a
);
655 * Switch to fast timer if needed (That is if this is the first
656 * unresolved entry to get added)
659 if (unresolved_count
== 1)
660 mod_timer(&aarp_timer
, jiffies
+ sysctl_aarp_tick_time
);
662 /* Now finally, it is safe to drop the lock. */
664 write_unlock_bh(&aarp_lock
);
666 /* Tell the ddp layer we have taken over for this frame. */
671 skb
->priority
= skb
->sk
->sk_priority
;
672 if (dev_queue_xmit(skb
))
675 return NET_XMIT_SUCCESS
;
679 return NET_XMIT_DROP
;
681 EXPORT_SYMBOL(aarp_send_ddp
);
684 * An entry in the aarp unresolved queue has become resolved. Send
685 * all the frames queued under it.
687 * Must run under aarp_lock.
689 static void __aarp_resolved(struct aarp_entry
**list
, struct aarp_entry
*a
,
699 /* Move into the resolved list */
700 a
->next
= resolved
[hash
];
703 /* Kick frames off */
704 while ((skb
= skb_dequeue(&a
->packet_queue
)) != NULL
) {
705 a
->expires_at
= jiffies
+
706 sysctl_aarp_expiry_time
* 10;
707 ddp_dl
->request(ddp_dl
, skb
, a
->hwaddr
);
710 list
= &((*list
)->next
);
714 * This is called by the SNAP driver whenever we see an AARP SNAP
715 * frame. We currently only support Ethernet.
717 static int aarp_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
718 struct packet_type
*pt
, struct net_device
*orig_dev
)
720 struct elapaarp
*ea
= aarp_hdr(skb
);
723 struct aarp_entry
*a
;
724 struct atalk_addr sa
, *ma
, da
;
725 struct atalk_iface
*ifa
;
727 if (!net_eq(dev_net(dev
), &init_net
))
730 /* We only do Ethernet SNAP AARP. */
731 if (dev
->type
!= ARPHRD_ETHER
)
735 if (!skb_pull(skb
, sizeof(*ea
)))
738 function
= ntohs(ea
->function
);
740 /* Sanity check fields. */
741 if (function
< AARP_REQUEST
|| function
> AARP_PROBE
||
742 ea
->hw_len
!= ETH_ALEN
|| ea
->pa_len
!= AARP_PA_ALEN
||
743 ea
->pa_src_zero
|| ea
->pa_dst_zero
)
747 hash
= ea
->pa_src_node
% (AARP_HASH_SIZE
- 1);
749 /* Build an address. */
750 sa
.s_node
= ea
->pa_src_node
;
751 sa
.s_net
= ea
->pa_src_net
;
753 /* Process the packet. Check for replies of me. */
754 ifa
= atalk_find_dev(dev
);
758 if (ifa
->status
& ATIF_PROBE
&&
759 ifa
->address
.s_node
== ea
->pa_dst_node
&&
760 ifa
->address
.s_net
== ea
->pa_dst_net
) {
761 ifa
->status
|= ATIF_PROBE_FAIL
; /* Fail the probe (in use) */
765 /* Check for replies of proxy AARP entries */
766 da
.s_node
= ea
->pa_dst_node
;
767 da
.s_net
= ea
->pa_dst_net
;
769 write_lock_bh(&aarp_lock
);
770 a
= __aarp_find_entry(proxies
[hash
], dev
, &da
);
772 if (a
&& a
->status
& ATIF_PROBE
) {
773 a
->status
|= ATIF_PROBE_FAIL
;
775 * we do not respond to probe or request packets for
776 * this address while we are probing this address
783 if (!unresolved_count
) /* Speed up */
786 /* Find the entry. */
787 a
= __aarp_find_entry(unresolved
[hash
], dev
, &sa
);
788 if (!a
|| dev
!= a
->dev
)
791 /* We can fill one in - this is good. */
792 memcpy(a
->hwaddr
, ea
->hw_src
, ETH_ALEN
);
793 __aarp_resolved(&unresolved
[hash
], a
, hash
);
794 if (!unresolved_count
)
795 mod_timer(&aarp_timer
,
796 jiffies
+ sysctl_aarp_expiry_time
);
803 * If it is my address set ma to my address and reply.
804 * We can treat probe and request the same. Probe
805 * simply means we shouldn't cache the querying host,
806 * as in a probe they are proposing an address not
809 * Support for proxy-AARP added. We check if the
810 * address is one of our proxies before we toss the
814 sa
.s_node
= ea
->pa_dst_node
;
815 sa
.s_net
= ea
->pa_dst_net
;
817 /* See if we have a matching proxy. */
818 ma
= __aarp_proxy_find(dev
, &sa
);
821 else { /* We need to make a copy of the entry. */
822 da
.s_node
= sa
.s_node
;
827 if (function
== AARP_PROBE
) {
829 * A probe implies someone trying to get an
830 * address. So as a precaution flush any
831 * entries we have for this address.
833 a
= __aarp_find_entry(resolved
[sa
.s_node
%
834 (AARP_HASH_SIZE
- 1)],
838 * Make it expire next tick - that avoids us
839 * getting into a probe/flush/learn/probe/
840 * flush/learn cycle during probing of a slow
841 * to respond host addr.
844 a
->expires_at
= jiffies
- 1;
845 mod_timer(&aarp_timer
, jiffies
+
846 sysctl_aarp_tick_time
);
850 if (sa
.s_node
!= ma
->s_node
)
853 if (sa
.s_net
&& ma
->s_net
&& sa
.s_net
!= ma
->s_net
)
856 sa
.s_node
= ea
->pa_src_node
;
857 sa
.s_net
= ea
->pa_src_net
;
859 /* aarp_my_address has found the address to use for us.
861 aarp_send_reply(dev
, ma
, &sa
, ea
->hw_src
);
866 write_unlock_bh(&aarp_lock
);
874 static struct notifier_block aarp_notifier
= {
875 .notifier_call
= aarp_device_event
,
878 static unsigned char aarp_snap_id
[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
880 void __init
aarp_proto_init(void)
882 aarp_dl
= register_snap_client(aarp_snap_id
, aarp_rcv
);
884 printk(KERN_CRIT
"Unable to register AARP with SNAP.\n");
885 setup_timer(&aarp_timer
, aarp_expire_timeout
, 0);
886 aarp_timer
.expires
= jiffies
+ sysctl_aarp_expiry_time
;
887 add_timer(&aarp_timer
);
888 register_netdevice_notifier(&aarp_notifier
);
891 /* Remove the AARP entries associated with a device. */
892 void aarp_device_down(struct net_device
*dev
)
896 write_lock_bh(&aarp_lock
);
898 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
899 __aarp_expire_device(&resolved
[ct
], dev
);
900 __aarp_expire_device(&unresolved
[ct
], dev
);
901 __aarp_expire_device(&proxies
[ct
], dev
);
904 write_unlock_bh(&aarp_lock
);
907 #ifdef CONFIG_PROC_FS
908 struct aarp_iter_state
{
910 struct aarp_entry
**table
;
914 * Get the aarp entry that is in the chain described
916 * If pos is set then skip till that index.
917 * pos = 1 is the first entry
919 static struct aarp_entry
*iter_next(struct aarp_iter_state
*iter
, loff_t
*pos
)
921 int ct
= iter
->bucket
;
922 struct aarp_entry
**table
= iter
->table
;
924 struct aarp_entry
*entry
;
927 while(ct
< AARP_HASH_SIZE
) {
928 for (entry
= table
[ct
]; entry
; entry
= entry
->next
) {
929 if (!pos
|| ++off
== *pos
) {
938 if (table
== resolved
) {
943 if (table
== unresolved
) {
951 static void *aarp_seq_start(struct seq_file
*seq
, loff_t
*pos
)
952 __acquires(aarp_lock
)
954 struct aarp_iter_state
*iter
= seq
->private;
956 read_lock_bh(&aarp_lock
);
957 iter
->table
= resolved
;
960 return *pos
? iter_next(iter
, pos
) : SEQ_START_TOKEN
;
963 static void *aarp_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
965 struct aarp_entry
*entry
= v
;
966 struct aarp_iter_state
*iter
= seq
->private;
970 /* first line after header */
971 if (v
== SEQ_START_TOKEN
)
972 entry
= iter_next(iter
, NULL
);
974 /* next entry in current bucket */
975 else if (entry
->next
)
978 /* next bucket or table */
981 entry
= iter_next(iter
, NULL
);
986 static void aarp_seq_stop(struct seq_file
*seq
, void *v
)
987 __releases(aarp_lock
)
989 read_unlock_bh(&aarp_lock
);
992 static const char *dt2str(unsigned long ticks
)
996 sprintf(buf
, "%ld.%02ld", ticks
/ HZ
, ((ticks
% HZ
) * 100 ) / HZ
);
1001 static int aarp_seq_show(struct seq_file
*seq
, void *v
)
1003 struct aarp_iter_state
*iter
= seq
->private;
1004 struct aarp_entry
*entry
= v
;
1005 unsigned long now
= jiffies
;
1007 if (v
== SEQ_START_TOKEN
)
1009 "Address Interface Hardware Address"
1010 " Expires LastSend Retry Status\n");
1012 seq_printf(seq
, "%04X:%02X %-12s",
1013 ntohs(entry
->target_addr
.s_net
),
1014 (unsigned int) entry
->target_addr
.s_node
,
1015 entry
->dev
? entry
->dev
->name
: "????");
1016 seq_printf(seq
, "%pM", entry
->hwaddr
);
1017 seq_printf(seq
, " %8s",
1018 dt2str((long)entry
->expires_at
- (long)now
));
1019 if (iter
->table
== unresolved
)
1020 seq_printf(seq
, " %8s %6hu",
1021 dt2str(now
- entry
->last_sent
),
1025 seq_printf(seq
, " %s\n",
1026 (iter
->table
== resolved
) ? "resolved"
1027 : (iter
->table
== unresolved
) ? "unresolved"
1028 : (iter
->table
== proxies
) ? "proxies"
1034 static const struct seq_operations aarp_seq_ops
= {
1035 .start
= aarp_seq_start
,
1036 .next
= aarp_seq_next
,
1037 .stop
= aarp_seq_stop
,
1038 .show
= aarp_seq_show
,
1041 static int aarp_seq_open(struct inode
*inode
, struct file
*file
)
1043 return seq_open_private(file
, &aarp_seq_ops
,
1044 sizeof(struct aarp_iter_state
));
1047 const struct file_operations atalk_seq_arp_fops
= {
1048 .owner
= THIS_MODULE
,
1049 .open
= aarp_seq_open
,
1051 .llseek
= seq_lseek
,
1052 .release
= seq_release_private
,
1056 /* General module cleanup. Called from cleanup_module() in ddp.c. */
1057 void aarp_cleanup_module(void)
1059 del_timer_sync(&aarp_timer
);
1060 unregister_netdevice_notifier(&aarp_notifier
);
1061 unregister_snap_client(aarp_dl
);