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/config.h>
33 #include <linux/if_arp.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
->nh
.raw
= skb
->h
.raw
= skb_put(skb
, sizeof(*eah
));
123 skb
->protocol
= htons(ETH_P_ATALK
);
128 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
129 eah
->pa_type
= htons(ETH_P_ATALK
);
130 eah
->hw_len
= ETH_ALEN
;
131 eah
->pa_len
= AARP_PA_ALEN
;
132 eah
->function
= htons(AARP_REQUEST
);
134 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
136 eah
->pa_src_zero
= 0;
137 eah
->pa_src_net
= sat
->s_net
;
138 eah
->pa_src_node
= sat
->s_node
;
140 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
142 eah
->pa_dst_zero
= 0;
143 eah
->pa_dst_net
= a
->target_addr
.s_net
;
144 eah
->pa_dst_node
= a
->target_addr
.s_node
;
147 aarp_dl
->request(aarp_dl
, skb
, aarp_eth_multicast
);
148 /* Update the sending count */
150 a
->last_sent
= jiffies
;
153 /* This runs under aarp_lock and in softint context, so only atomic memory
154 * allocations can be used. */
155 static void aarp_send_reply(struct net_device
*dev
, struct atalk_addr
*us
,
156 struct atalk_addr
*them
, unsigned char *sha
)
158 struct elapaarp
*eah
;
159 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
160 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
165 /* Set up the buffer */
166 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
167 skb
->nh
.raw
= skb
->h
.raw
= skb_put(skb
, sizeof(*eah
));
168 skb
->protocol
= htons(ETH_P_ATALK
);
173 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
174 eah
->pa_type
= htons(ETH_P_ATALK
);
175 eah
->hw_len
= ETH_ALEN
;
176 eah
->pa_len
= AARP_PA_ALEN
;
177 eah
->function
= htons(AARP_REPLY
);
179 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
181 eah
->pa_src_zero
= 0;
182 eah
->pa_src_net
= us
->s_net
;
183 eah
->pa_src_node
= us
->s_node
;
186 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
188 memcpy(eah
->hw_dst
, sha
, ETH_ALEN
);
190 eah
->pa_dst_zero
= 0;
191 eah
->pa_dst_net
= them
->s_net
;
192 eah
->pa_dst_node
= them
->s_node
;
195 aarp_dl
->request(aarp_dl
, skb
, sha
);
199 * Send probe frames. Called from aarp_probe_network and
200 * aarp_proxy_probe_network.
203 static void aarp_send_probe(struct net_device
*dev
, struct atalk_addr
*us
)
205 struct elapaarp
*eah
;
206 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
207 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
208 static unsigned char aarp_eth_multicast
[ETH_ALEN
] =
209 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
214 /* Set up the buffer */
215 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
216 skb
->nh
.raw
= skb
->h
.raw
= skb_put(skb
, sizeof(*eah
));
217 skb
->protocol
= htons(ETH_P_ATALK
);
222 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
223 eah
->pa_type
= htons(ETH_P_ATALK
);
224 eah
->hw_len
= ETH_ALEN
;
225 eah
->pa_len
= AARP_PA_ALEN
;
226 eah
->function
= htons(AARP_PROBE
);
228 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
230 eah
->pa_src_zero
= 0;
231 eah
->pa_src_net
= us
->s_net
;
232 eah
->pa_src_node
= us
->s_node
;
234 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
236 eah
->pa_dst_zero
= 0;
237 eah
->pa_dst_net
= us
->s_net
;
238 eah
->pa_dst_node
= us
->s_node
;
241 aarp_dl
->request(aarp_dl
, skb
, aarp_eth_multicast
);
245 * Handle an aarp timer expire
247 * Must run under the aarp_lock.
250 static void __aarp_expire_timer(struct aarp_entry
**n
)
252 struct aarp_entry
*t
;
256 if (time_after(jiffies
, (*n
)->expires_at
)) {
265 * Kick all pending requests 5 times a second.
267 * Must run under the aarp_lock.
269 static void __aarp_kick(struct aarp_entry
**n
)
271 struct aarp_entry
*t
;
274 /* Expired: if this will be the 11th tx, we delete instead. */
275 if ((*n
)->xmit_count
>= sysctl_aarp_retransmit_limit
) {
280 __aarp_send_query(*n
);
286 * A device has gone down. Take all entries referring to the device
289 * Must run under the aarp_lock.
291 static void __aarp_expire_device(struct aarp_entry
**n
, struct net_device
*dev
)
293 struct aarp_entry
*t
;
296 if ((*n
)->dev
== dev
) {
304 /* Handle the timer event */
305 static void aarp_expire_timeout(unsigned long unused
)
309 write_lock_bh(&aarp_lock
);
311 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
312 __aarp_expire_timer(&resolved
[ct
]);
313 __aarp_kick(&unresolved
[ct
]);
314 __aarp_expire_timer(&unresolved
[ct
]);
315 __aarp_expire_timer(&proxies
[ct
]);
318 write_unlock_bh(&aarp_lock
);
319 mod_timer(&aarp_timer
, jiffies
+
320 (unresolved_count
? sysctl_aarp_tick_time
:
321 sysctl_aarp_expiry_time
));
324 /* Network device notifier chain handler. */
325 static int aarp_device_event(struct notifier_block
*this, unsigned long event
,
330 if (event
== NETDEV_DOWN
) {
331 write_lock_bh(&aarp_lock
);
333 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
334 __aarp_expire_device(&resolved
[ct
], ptr
);
335 __aarp_expire_device(&unresolved
[ct
], ptr
);
336 __aarp_expire_device(&proxies
[ct
], ptr
);
339 write_unlock_bh(&aarp_lock
);
344 /* Expire all entries in a hash chain */
345 static void __aarp_expire_all(struct aarp_entry
**n
)
347 struct aarp_entry
*t
;
356 /* Cleanup all hash chains -- module unloading */
357 static void aarp_purge(void)
361 write_lock_bh(&aarp_lock
);
362 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
363 __aarp_expire_all(&resolved
[ct
]);
364 __aarp_expire_all(&unresolved
[ct
]);
365 __aarp_expire_all(&proxies
[ct
]);
367 write_unlock_bh(&aarp_lock
);
371 * Create a new aarp entry. This must use GFP_ATOMIC because it
372 * runs while holding spinlocks.
374 static struct aarp_entry
*aarp_alloc(void)
376 struct aarp_entry
*a
= kmalloc(sizeof(*a
), GFP_ATOMIC
);
379 skb_queue_head_init(&a
->packet_queue
);
384 * Find an entry. We might return an expired but not yet purged entry. We
385 * don't care as it will do no harm.
387 * This must run under the aarp_lock.
389 static struct aarp_entry
*__aarp_find_entry(struct aarp_entry
*list
,
390 struct net_device
*dev
,
391 struct atalk_addr
*sat
)
394 if (list
->target_addr
.s_net
== sat
->s_net
&&
395 list
->target_addr
.s_node
== sat
->s_node
&&
404 /* Called from the DDP code, and thus must be exported. */
405 void aarp_proxy_remove(struct net_device
*dev
, struct atalk_addr
*sa
)
407 int hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
408 struct aarp_entry
*a
;
410 write_lock_bh(&aarp_lock
);
412 a
= __aarp_find_entry(proxies
[hash
], dev
, sa
);
414 a
->expires_at
= jiffies
- 1;
416 write_unlock_bh(&aarp_lock
);
419 /* This must run under aarp_lock. */
420 static struct atalk_addr
*__aarp_proxy_find(struct net_device
*dev
,
421 struct atalk_addr
*sa
)
423 int hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
424 struct aarp_entry
*a
= __aarp_find_entry(proxies
[hash
], dev
, sa
);
426 return a
? sa
: NULL
;
430 * Probe a Phase 1 device or a device that requires its Net:Node to
431 * be set via an ioctl.
433 static void aarp_send_probe_phase1(struct atalk_iface
*iface
)
436 struct sockaddr_at
*sa
= (struct sockaddr_at
*)&atreq
.ifr_addr
;
438 sa
->sat_addr
.s_node
= iface
->address
.s_node
;
439 sa
->sat_addr
.s_net
= ntohs(iface
->address
.s_net
);
441 /* We pass the Net:Node to the drivers/cards by a Device ioctl. */
442 if (!(iface
->dev
->do_ioctl(iface
->dev
, &atreq
, SIOCSIFADDR
))) {
443 (void)iface
->dev
->do_ioctl(iface
->dev
, &atreq
, SIOCGIFADDR
);
444 if (iface
->address
.s_net
!= htons(sa
->sat_addr
.s_net
) ||
445 iface
->address
.s_node
!= sa
->sat_addr
.s_node
)
446 iface
->status
|= ATIF_PROBE_FAIL
;
448 iface
->address
.s_net
= htons(sa
->sat_addr
.s_net
);
449 iface
->address
.s_node
= sa
->sat_addr
.s_node
;
454 void aarp_probe_network(struct atalk_iface
*atif
)
456 if (atif
->dev
->type
== ARPHRD_LOCALTLK
||
457 atif
->dev
->type
== ARPHRD_PPP
)
458 aarp_send_probe_phase1(atif
);
462 for (count
= 0; count
< AARP_RETRANSMIT_LIMIT
; count
++) {
463 aarp_send_probe(atif
->dev
, &atif
->address
);
468 if (atif
->status
& ATIF_PROBE_FAIL
)
474 int aarp_proxy_probe_network(struct atalk_iface
*atif
, struct atalk_addr
*sa
)
476 int hash
, retval
= -EPROTONOSUPPORT
;
477 struct aarp_entry
*entry
;
481 * we don't currently support LocalTalk or PPP for proxy AARP;
482 * if someone wants to try and add it, have fun
484 if (atif
->dev
->type
== ARPHRD_LOCALTLK
||
485 atif
->dev
->type
== ARPHRD_PPP
)
489 * create a new AARP entry with the flags set to be published --
490 * we need this one to hang around even if it's in use
492 entry
= aarp_alloc();
497 entry
->expires_at
= -1;
498 entry
->status
= ATIF_PROBE
;
499 entry
->target_addr
.s_node
= sa
->s_node
;
500 entry
->target_addr
.s_net
= sa
->s_net
;
501 entry
->dev
= atif
->dev
;
503 write_lock_bh(&aarp_lock
);
505 hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
506 entry
->next
= proxies
[hash
];
507 proxies
[hash
] = entry
;
509 for (count
= 0; count
< AARP_RETRANSMIT_LIMIT
; count
++) {
510 aarp_send_probe(atif
->dev
, sa
);
513 write_unlock_bh(&aarp_lock
);
515 write_lock_bh(&aarp_lock
);
517 if (entry
->status
& ATIF_PROBE_FAIL
)
521 if (entry
->status
& ATIF_PROBE_FAIL
) {
522 entry
->expires_at
= jiffies
- 1; /* free the entry */
523 retval
= -EADDRINUSE
; /* return network full */
524 } else { /* clear the probing flag */
525 entry
->status
&= ~ATIF_PROBE
;
529 write_unlock_bh(&aarp_lock
);
534 /* Send a DDP frame */
535 int aarp_send_ddp(struct net_device
*dev
, struct sk_buff
*skb
,
536 struct atalk_addr
*sa
, void *hwaddr
)
538 static char ddp_eth_multicast
[ETH_ALEN
] =
539 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
541 struct aarp_entry
*a
;
543 skb
->nh
.raw
= skb
->data
;
545 /* Check for LocalTalk first */
546 if (dev
->type
== ARPHRD_LOCALTLK
) {
547 struct atalk_addr
*at
= atalk_find_dev_addr(dev
);
548 struct ddpehdr
*ddp
= (struct ddpehdr
*)skb
->data
;
554 * IFF: src_net == dest_net == device_net
555 * (zero matches anything)
558 if ((!ddp
->deh_snet
|| at
->s_net
== ddp
->deh_snet
) &&
559 (!ddp
->deh_dnet
|| at
->s_net
== ddp
->deh_dnet
)) {
560 skb_pull(skb
, sizeof(*ddp
) - 4);
563 * The upper two remaining bytes are the port
564 * numbers we just happen to need. Now put the
565 * length in the lower two.
567 *((__be16
*)skb
->data
) = htons(skb
->len
);
571 * Nice and easy. No AARP type protocols occur here so we can
572 * just shovel it out with a 3 byte LLAP header
576 skb
->data
[0] = sa
->s_node
;
577 skb
->data
[1] = at
->s_node
;
583 /* On a PPP link we neither compress nor aarp. */
584 if (dev
->type
== ARPHRD_PPP
) {
585 skb
->protocol
= htons(ETH_P_PPPTALK
);
590 /* Non ELAP we cannot do. */
591 if (dev
->type
!= ARPHRD_ETHER
)
595 skb
->protocol
= htons(ETH_P_ATALK
);
596 hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
598 /* Do we have a resolved entry? */
599 if (sa
->s_node
== ATADDR_BCAST
) {
601 ddp_dl
->request(ddp_dl
, skb
, ddp_eth_multicast
);
605 write_lock_bh(&aarp_lock
);
606 a
= __aarp_find_entry(resolved
[hash
], dev
, sa
);
608 if (a
) { /* Return 1 and fill in the address */
609 a
->expires_at
= jiffies
+ (sysctl_aarp_expiry_time
* 10);
610 ddp_dl
->request(ddp_dl
, skb
, a
->hwaddr
);
611 write_unlock_bh(&aarp_lock
);
615 /* Do we have an unresolved entry: This is the less common path */
616 a
= __aarp_find_entry(unresolved
[hash
], dev
, sa
);
617 if (a
) { /* Queue onto the unresolved queue */
618 skb_queue_tail(&a
->packet_queue
, skb
);
622 /* Allocate a new entry */
625 /* Whoops slipped... good job it's an unreliable protocol 8) */
626 write_unlock_bh(&aarp_lock
);
630 /* Set up the queue */
631 skb_queue_tail(&a
->packet_queue
, skb
);
632 a
->expires_at
= jiffies
+ sysctl_aarp_resolve_time
;
634 a
->next
= unresolved
[hash
];
635 a
->target_addr
= *sa
;
637 unresolved
[hash
] = a
;
640 /* Send an initial request for the address */
641 __aarp_send_query(a
);
644 * Switch to fast timer if needed (That is if this is the first
645 * unresolved entry to get added)
648 if (unresolved_count
== 1)
649 mod_timer(&aarp_timer
, jiffies
+ sysctl_aarp_tick_time
);
651 /* Now finally, it is safe to drop the lock. */
653 write_unlock_bh(&aarp_lock
);
655 /* Tell the ddp layer we have taken over for this frame. */
660 skb
->priority
= skb
->sk
->sk_priority
;
667 * An entry in the aarp unresolved queue has become resolved. Send
668 * all the frames queued under it.
670 * Must run under aarp_lock.
672 static void __aarp_resolved(struct aarp_entry
**list
, struct aarp_entry
*a
,
682 /* Move into the resolved list */
683 a
->next
= resolved
[hash
];
686 /* Kick frames off */
687 while ((skb
= skb_dequeue(&a
->packet_queue
)) != NULL
) {
688 a
->expires_at
= jiffies
+
689 sysctl_aarp_expiry_time
* 10;
690 ddp_dl
->request(ddp_dl
, skb
, a
->hwaddr
);
693 list
= &((*list
)->next
);
697 * This is called by the SNAP driver whenever we see an AARP SNAP
698 * frame. We currently only support Ethernet.
700 static int aarp_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
701 struct packet_type
*pt
, struct net_device
*orig_dev
)
703 struct elapaarp
*ea
= aarp_hdr(skb
);
706 struct aarp_entry
*a
;
707 struct atalk_addr sa
, *ma
, da
;
708 struct atalk_iface
*ifa
;
710 /* We only do Ethernet SNAP AARP. */
711 if (dev
->type
!= ARPHRD_ETHER
)
715 if (!skb_pull(skb
, sizeof(*ea
)))
718 function
= ntohs(ea
->function
);
720 /* Sanity check fields. */
721 if (function
< AARP_REQUEST
|| function
> AARP_PROBE
||
722 ea
->hw_len
!= ETH_ALEN
|| ea
->pa_len
!= AARP_PA_ALEN
||
723 ea
->pa_src_zero
|| ea
->pa_dst_zero
)
727 hash
= ea
->pa_src_node
% (AARP_HASH_SIZE
- 1);
729 /* Build an address. */
730 sa
.s_node
= ea
->pa_src_node
;
731 sa
.s_net
= ea
->pa_src_net
;
733 /* Process the packet. Check for replies of me. */
734 ifa
= atalk_find_dev(dev
);
738 if (ifa
->status
& ATIF_PROBE
&&
739 ifa
->address
.s_node
== ea
->pa_dst_node
&&
740 ifa
->address
.s_net
== ea
->pa_dst_net
) {
741 ifa
->status
|= ATIF_PROBE_FAIL
; /* Fail the probe (in use) */
745 /* Check for replies of proxy AARP entries */
746 da
.s_node
= ea
->pa_dst_node
;
747 da
.s_net
= ea
->pa_dst_net
;
749 write_lock_bh(&aarp_lock
);
750 a
= __aarp_find_entry(proxies
[hash
], dev
, &da
);
752 if (a
&& a
->status
& ATIF_PROBE
) {
753 a
->status
|= ATIF_PROBE_FAIL
;
755 * we do not respond to probe or request packets for
756 * this address while we are probing this address
763 if (!unresolved_count
) /* Speed up */
766 /* Find the entry. */
767 a
= __aarp_find_entry(unresolved
[hash
], dev
, &sa
);
768 if (!a
|| dev
!= a
->dev
)
771 /* We can fill one in - this is good. */
772 memcpy(a
->hwaddr
, ea
->hw_src
, ETH_ALEN
);
773 __aarp_resolved(&unresolved
[hash
], a
, hash
);
774 if (!unresolved_count
)
775 mod_timer(&aarp_timer
,
776 jiffies
+ sysctl_aarp_expiry_time
);
783 * If it is my address set ma to my address and reply.
784 * We can treat probe and request the same. Probe
785 * simply means we shouldn't cache the querying host,
786 * as in a probe they are proposing an address not
789 * Support for proxy-AARP added. We check if the
790 * address is one of our proxies before we toss the
794 sa
.s_node
= ea
->pa_dst_node
;
795 sa
.s_net
= ea
->pa_dst_net
;
797 /* See if we have a matching proxy. */
798 ma
= __aarp_proxy_find(dev
, &sa
);
801 else { /* We need to make a copy of the entry. */
802 da
.s_node
= sa
.s_node
;
807 if (function
== AARP_PROBE
) {
809 * A probe implies someone trying to get an
810 * address. So as a precaution flush any
811 * entries we have for this address.
813 struct aarp_entry
*a
;
815 a
= __aarp_find_entry(resolved
[sa
.s_node
%
816 (AARP_HASH_SIZE
- 1)],
820 * Make it expire next tick - that avoids us
821 * getting into a probe/flush/learn/probe/
822 * flush/learn cycle during probing of a slow
823 * to respond host addr.
826 a
->expires_at
= jiffies
- 1;
827 mod_timer(&aarp_timer
, jiffies
+
828 sysctl_aarp_tick_time
);
832 if (sa
.s_node
!= ma
->s_node
)
835 if (sa
.s_net
&& ma
->s_net
&& sa
.s_net
!= ma
->s_net
)
838 sa
.s_node
= ea
->pa_src_node
;
839 sa
.s_net
= ea
->pa_src_net
;
841 /* aarp_my_address has found the address to use for us.
843 aarp_send_reply(dev
, ma
, &sa
, ea
->hw_src
);
848 write_unlock_bh(&aarp_lock
);
856 static struct notifier_block aarp_notifier
= {
857 .notifier_call
= aarp_device_event
,
860 static unsigned char aarp_snap_id
[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
862 void __init
aarp_proto_init(void)
864 aarp_dl
= register_snap_client(aarp_snap_id
, aarp_rcv
);
866 printk(KERN_CRIT
"Unable to register AARP with SNAP.\n");
867 init_timer(&aarp_timer
);
868 aarp_timer
.function
= aarp_expire_timeout
;
870 aarp_timer
.expires
= jiffies
+ sysctl_aarp_expiry_time
;
871 add_timer(&aarp_timer
);
872 register_netdevice_notifier(&aarp_notifier
);
875 /* Remove the AARP entries associated with a device. */
876 void aarp_device_down(struct net_device
*dev
)
880 write_lock_bh(&aarp_lock
);
882 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
883 __aarp_expire_device(&resolved
[ct
], dev
);
884 __aarp_expire_device(&unresolved
[ct
], dev
);
885 __aarp_expire_device(&proxies
[ct
], dev
);
888 write_unlock_bh(&aarp_lock
);
891 #ifdef CONFIG_PROC_FS
892 struct aarp_iter_state
{
894 struct aarp_entry
**table
;
898 * Get the aarp entry that is in the chain described
900 * If pos is set then skip till that index.
901 * pos = 1 is the first entry
903 static struct aarp_entry
*iter_next(struct aarp_iter_state
*iter
, loff_t
*pos
)
905 int ct
= iter
->bucket
;
906 struct aarp_entry
**table
= iter
->table
;
908 struct aarp_entry
*entry
;
911 while(ct
< AARP_HASH_SIZE
) {
912 for (entry
= table
[ct
]; entry
; entry
= entry
->next
) {
913 if (!pos
|| ++off
== *pos
) {
922 if (table
== resolved
) {
927 if (table
== unresolved
) {
935 static void *aarp_seq_start(struct seq_file
*seq
, loff_t
*pos
)
937 struct aarp_iter_state
*iter
= seq
->private;
939 read_lock_bh(&aarp_lock
);
940 iter
->table
= resolved
;
943 return *pos
? iter_next(iter
, pos
) : SEQ_START_TOKEN
;
946 static void *aarp_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
948 struct aarp_entry
*entry
= v
;
949 struct aarp_iter_state
*iter
= seq
->private;
953 /* first line after header */
954 if (v
== SEQ_START_TOKEN
)
955 entry
= iter_next(iter
, NULL
);
957 /* next entry in current bucket */
958 else if (entry
->next
)
961 /* next bucket or table */
964 entry
= iter_next(iter
, NULL
);
969 static void aarp_seq_stop(struct seq_file
*seq
, void *v
)
971 read_unlock_bh(&aarp_lock
);
974 static const char *dt2str(unsigned long ticks
)
978 sprintf(buf
, "%ld.%02ld", ticks
/ HZ
, ((ticks
% HZ
) * 100 ) / HZ
);
983 static int aarp_seq_show(struct seq_file
*seq
, void *v
)
985 struct aarp_iter_state
*iter
= seq
->private;
986 struct aarp_entry
*entry
= v
;
987 unsigned long now
= jiffies
;
989 if (v
== SEQ_START_TOKEN
)
991 "Address Interface Hardware Address"
992 " Expires LastSend Retry Status\n");
994 seq_printf(seq
, "%04X:%02X %-12s",
995 ntohs(entry
->target_addr
.s_net
),
996 (unsigned int) entry
->target_addr
.s_node
,
997 entry
->dev
? entry
->dev
->name
: "????");
998 seq_printf(seq
, "%02X:%02X:%02X:%02X:%02X:%02X",
999 entry
->hwaddr
[0] & 0xFF,
1000 entry
->hwaddr
[1] & 0xFF,
1001 entry
->hwaddr
[2] & 0xFF,
1002 entry
->hwaddr
[3] & 0xFF,
1003 entry
->hwaddr
[4] & 0xFF,
1004 entry
->hwaddr
[5] & 0xFF);
1005 seq_printf(seq
, " %8s",
1006 dt2str((long)entry
->expires_at
- (long)now
));
1007 if (iter
->table
== unresolved
)
1008 seq_printf(seq
, " %8s %6hu",
1009 dt2str(now
- entry
->last_sent
),
1013 seq_printf(seq
, " %s\n",
1014 (iter
->table
== resolved
) ? "resolved"
1015 : (iter
->table
== unresolved
) ? "unresolved"
1016 : (iter
->table
== proxies
) ? "proxies"
1022 static struct seq_operations aarp_seq_ops
= {
1023 .start
= aarp_seq_start
,
1024 .next
= aarp_seq_next
,
1025 .stop
= aarp_seq_stop
,
1026 .show
= aarp_seq_show
,
1029 static int aarp_seq_open(struct inode
*inode
, struct file
*file
)
1031 struct seq_file
*seq
;
1033 struct aarp_iter_state
*s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
1038 rc
= seq_open(file
, &aarp_seq_ops
);
1042 seq
= file
->private_data
;
1044 memset(s
, 0, sizeof(*s
));
1052 struct file_operations atalk_seq_arp_fops
= {
1053 .owner
= THIS_MODULE
,
1054 .open
= aarp_seq_open
,
1056 .llseek
= seq_lseek
,
1057 .release
= seq_release_private
,
1061 /* General module cleanup. Called from cleanup_module() in ddp.c. */
1062 void aarp_cleanup_module(void)
1064 del_timer_sync(&aarp_timer
);
1065 unregister_netdevice_notifier(&aarp_notifier
);
1066 unregister_snap_client(aarp_dl
);