3 #include <linux/if_arp.h>
4 #include <linux/slab.h>
6 #include <net/datalink.h>
8 #include <linux/atalk.h>
9 #include <linux/delay.h>
10 #include <linux/init.h>
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
14 int sysctl_aarp_expiry_time
= AARP_EXPIRY_TIME
;
15 int sysctl_aarp_tick_time
= AARP_TICK_TIME
;
16 int sysctl_aarp_retransmit_limit
= AARP_RETRANSMIT_LIMIT
;
17 int sysctl_aarp_resolve_time
= AARP_RESOLVE_TIME
;
19 /* Lists of aarp entries */
21 * struct aarp_entry - AARP entry
22 * @last_sent - Last time we xmitted the aarp request
23 * @packet_queue - Queue of frames wait for resolution
24 * @status - Used for proxy AARP
25 * expires_at - Entry expiry time
26 * target_addr - DDP Address
28 * hwaddr - Physical i/f address of target/router
29 * xmit_count - When this hits 10 we give up
30 * next - Next entry in chain
33 /* These first two are only used for unresolved entries */
34 unsigned long last_sent
;
35 struct sk_buff_head packet_queue
;
37 unsigned long expires_at
;
38 struct atalk_addr target_addr
;
39 struct net_device
*dev
;
41 unsigned short xmit_count
;
42 struct aarp_entry
*next
;
45 /* Hashed list of resolved, unresolved and proxy entries */
46 static struct aarp_entry
*resolved
[AARP_HASH_SIZE
];
47 static struct aarp_entry
*unresolved
[AARP_HASH_SIZE
];
48 static struct aarp_entry
*proxies
[AARP_HASH_SIZE
];
49 static int unresolved_count
;
51 /* One lock protects it all. */
52 static DEFINE_RWLOCK(aarp_lock
);
54 /* Used to walk the list and purge/kick entries. */
55 static struct timer_list aarp_timer
;
58 * Delete an aarp queue
60 * Must run under aarp_lock.
62 static void __aarp_expire(struct aarp_entry
*a
)
64 skb_queue_purge(&a
->packet_queue
);
69 * Send an aarp queue entry request
71 * Must run under aarp_lock.
73 static void __aarp_send_query(struct aarp_entry
*a
)
75 static unsigned char aarp_eth_multicast
[ETH_ALEN
] =
76 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
77 struct net_device
*dev
= a
->dev
;
79 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
80 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
81 struct atalk_addr
*sat
= atalk_find_dev_addr(dev
);
91 /* Set up the buffer */
92 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
93 skb_reset_network_header(skb
);
94 skb_reset_transport_header(skb
);
95 skb_put(skb
, sizeof(*eah
));
96 skb
->protocol
= htons(ETH_P_ATALK
);
101 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
102 eah
->pa_type
= htons(ETH_P_ATALK
);
103 eah
->hw_len
= ETH_ALEN
;
104 eah
->pa_len
= AARP_PA_ALEN
;
105 eah
->function
= htons(AARP_REQUEST
);
107 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
109 eah
->pa_src_zero
= 0;
110 eah
->pa_src_net
= sat
->s_net
;
111 eah
->pa_src_node
= sat
->s_node
;
113 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
115 eah
->pa_dst_zero
= 0;
116 eah
->pa_dst_net
= a
->target_addr
.s_net
;
117 eah
->pa_dst_node
= a
->target_addr
.s_node
;
120 aarp_dl
->request(aarp_dl
, skb
, aarp_eth_multicast
);
121 /* Update the sending count */
123 a
->last_sent
= jiffies
;
126 /* This runs under aarp_lock and in softint context, so only atomic memory
127 * allocations can be used. */
128 static void aarp_send_reply(struct net_device
*dev
, struct atalk_addr
*us
,
129 struct atalk_addr
*them
, unsigned char *sha
)
131 struct elapaarp
*eah
;
132 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
133 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
138 /* Set up the buffer */
139 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
140 skb_reset_network_header(skb
);
141 skb_reset_transport_header(skb
);
142 skb_put(skb
, sizeof(*eah
));
143 skb
->protocol
= htons(ETH_P_ATALK
);
148 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
149 eah
->pa_type
= htons(ETH_P_ATALK
);
150 eah
->hw_len
= ETH_ALEN
;
151 eah
->pa_len
= AARP_PA_ALEN
;
152 eah
->function
= htons(AARP_REPLY
);
154 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
156 eah
->pa_src_zero
= 0;
157 eah
->pa_src_net
= us
->s_net
;
158 eah
->pa_src_node
= us
->s_node
;
161 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
163 memcpy(eah
->hw_dst
, sha
, ETH_ALEN
);
165 eah
->pa_dst_zero
= 0;
166 eah
->pa_dst_net
= them
->s_net
;
167 eah
->pa_dst_node
= them
->s_node
;
170 aarp_dl
->request(aarp_dl
, skb
, sha
);
174 * Send probe frames. Called from aarp_probe_network and
175 * aarp_proxy_probe_network.
178 static void aarp_send_probe(struct net_device
*dev
, struct atalk_addr
*us
)
180 struct elapaarp
*eah
;
181 int len
= dev
->hard_header_len
+ sizeof(*eah
) + aarp_dl
->header_length
;
182 struct sk_buff
*skb
= alloc_skb(len
, GFP_ATOMIC
);
183 static unsigned char aarp_eth_multicast
[ETH_ALEN
] =
184 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
189 /* Set up the buffer */
190 skb_reserve(skb
, dev
->hard_header_len
+ aarp_dl
->header_length
);
191 skb_reset_network_header(skb
);
192 skb_reset_transport_header(skb
);
193 skb_put(skb
, sizeof(*eah
));
194 skb
->protocol
= htons(ETH_P_ATALK
);
199 eah
->hw_type
= htons(AARP_HW_TYPE_ETHERNET
);
200 eah
->pa_type
= htons(ETH_P_ATALK
);
201 eah
->hw_len
= ETH_ALEN
;
202 eah
->pa_len
= AARP_PA_ALEN
;
203 eah
->function
= htons(AARP_PROBE
);
205 memcpy(eah
->hw_src
, dev
->dev_addr
, ETH_ALEN
);
207 eah
->pa_src_zero
= 0;
208 eah
->pa_src_net
= us
->s_net
;
209 eah
->pa_src_node
= us
->s_node
;
211 memset(eah
->hw_dst
, '\0', ETH_ALEN
);
213 eah
->pa_dst_zero
= 0;
214 eah
->pa_dst_net
= us
->s_net
;
215 eah
->pa_dst_node
= us
->s_node
;
218 aarp_dl
->request(aarp_dl
, skb
, aarp_eth_multicast
);
222 * Handle an aarp timer expire
224 * Must run under the aarp_lock.
227 static void __aarp_expire_timer(struct aarp_entry
**n
)
229 struct aarp_entry
*t
;
233 if (time_after(jiffies
, (*n
)->expires_at
)) {
242 * Kick all pending requests 5 times a second.
244 * Must run under the aarp_lock.
246 static void __aarp_kick(struct aarp_entry
**n
)
248 struct aarp_entry
*t
;
251 /* Expired: if this will be the 11th tx, we delete instead. */
252 if ((*n
)->xmit_count
>= sysctl_aarp_retransmit_limit
) {
257 __aarp_send_query(*n
);
263 * A device has gone down. Take all entries referring to the device
266 * Must run under the aarp_lock.
268 static void __aarp_expire_device(struct aarp_entry
**n
, struct net_device
*dev
)
270 struct aarp_entry
*t
;
273 if ((*n
)->dev
== dev
) {
281 /* Handle the timer event */
282 static void aarp_expire_timeout(unsigned long unused
)
286 write_lock_bh(&aarp_lock
);
288 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
289 __aarp_expire_timer(&resolved
[ct
]);
290 __aarp_kick(&unresolved
[ct
]);
291 __aarp_expire_timer(&unresolved
[ct
]);
292 __aarp_expire_timer(&proxies
[ct
]);
295 write_unlock_bh(&aarp_lock
);
296 mod_timer(&aarp_timer
, jiffies
+
297 (unresolved_count
? sysctl_aarp_tick_time
:
298 sysctl_aarp_expiry_time
));
301 /* Network device notifier chain handler. */
302 static int aarp_device_event(struct notifier_block
*this, unsigned long event
,
305 struct net_device
*dev
= ptr
;
308 if (!net_eq(dev_net(dev
), &init_net
))
311 if (event
== NETDEV_DOWN
) {
312 write_lock_bh(&aarp_lock
);
314 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
315 __aarp_expire_device(&resolved
[ct
], dev
);
316 __aarp_expire_device(&unresolved
[ct
], dev
);
317 __aarp_expire_device(&proxies
[ct
], dev
);
320 write_unlock_bh(&aarp_lock
);
325 /* Expire all entries in a hash chain */
326 static void __aarp_expire_all(struct aarp_entry
**n
)
328 struct aarp_entry
*t
;
337 /* Cleanup all hash chains -- module unloading */
338 static void aarp_purge(void)
342 write_lock_bh(&aarp_lock
);
343 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
344 __aarp_expire_all(&resolved
[ct
]);
345 __aarp_expire_all(&unresolved
[ct
]);
346 __aarp_expire_all(&proxies
[ct
]);
348 write_unlock_bh(&aarp_lock
);
352 * Create a new aarp entry. This must use GFP_ATOMIC because it
353 * runs while holding spinlocks.
355 static struct aarp_entry
*aarp_alloc(void)
357 struct aarp_entry
*a
= kmalloc(sizeof(*a
), GFP_ATOMIC
);
360 skb_queue_head_init(&a
->packet_queue
);
365 * Find an entry. We might return an expired but not yet purged entry. We
366 * don't care as it will do no harm.
368 * This must run under the aarp_lock.
370 static struct aarp_entry
*__aarp_find_entry(struct aarp_entry
*list
,
371 struct net_device
*dev
,
372 struct atalk_addr
*sat
)
375 if (list
->target_addr
.s_net
== sat
->s_net
&&
376 list
->target_addr
.s_node
== sat
->s_node
&&
385 /* Called from the DDP code, and thus must be exported. */
386 void aarp_proxy_remove(struct net_device
*dev
, struct atalk_addr
*sa
)
388 int hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
389 struct aarp_entry
*a
;
391 write_lock_bh(&aarp_lock
);
393 a
= __aarp_find_entry(proxies
[hash
], dev
, sa
);
395 a
->expires_at
= jiffies
- 1;
397 write_unlock_bh(&aarp_lock
);
400 /* This must run under aarp_lock. */
401 static struct atalk_addr
*__aarp_proxy_find(struct net_device
*dev
,
402 struct atalk_addr
*sa
)
404 int hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
405 struct aarp_entry
*a
= __aarp_find_entry(proxies
[hash
], dev
, sa
);
407 return a
? sa
: NULL
;
411 * Probe a Phase 1 device or a device that requires its Net:Node to
412 * be set via an ioctl.
414 static void aarp_send_probe_phase1(struct atalk_iface
*iface
)
417 struct sockaddr_at
*sa
= (struct sockaddr_at
*)&atreq
.ifr_addr
;
418 const struct net_device_ops
*ops
= iface
->dev
->netdev_ops
;
420 sa
->sat_addr
.s_node
= iface
->address
.s_node
;
421 sa
->sat_addr
.s_net
= ntohs(iface
->address
.s_net
);
423 /* We pass the Net:Node to the drivers/cards by a Device ioctl. */
424 if (!(ops
->ndo_do_ioctl(iface
->dev
, &atreq
, SIOCSIFADDR
))) {
425 ops
->ndo_do_ioctl(iface
->dev
, &atreq
, SIOCGIFADDR
);
426 if (iface
->address
.s_net
!= htons(sa
->sat_addr
.s_net
) ||
427 iface
->address
.s_node
!= sa
->sat_addr
.s_node
)
428 iface
->status
|= ATIF_PROBE_FAIL
;
430 iface
->address
.s_net
= htons(sa
->sat_addr
.s_net
);
431 iface
->address
.s_node
= sa
->sat_addr
.s_node
;
436 void aarp_probe_network(struct atalk_iface
*atif
)
438 if (atif
->dev
->type
== ARPHRD_LOCALTLK
||
439 atif
->dev
->type
== ARPHRD_PPP
)
440 aarp_send_probe_phase1(atif
);
444 for (count
= 0; count
< AARP_RETRANSMIT_LIMIT
; count
++) {
445 aarp_send_probe(atif
->dev
, &atif
->address
);
450 if (atif
->status
& ATIF_PROBE_FAIL
)
456 int aarp_proxy_probe_network(struct atalk_iface
*atif
, struct atalk_addr
*sa
)
458 int hash
, retval
= -EPROTONOSUPPORT
;
459 struct aarp_entry
*entry
;
463 * we don't currently support LocalTalk or PPP for proxy AARP;
464 * if someone wants to try and add it, have fun
466 if (atif
->dev
->type
== ARPHRD_LOCALTLK
||
467 atif
->dev
->type
== ARPHRD_PPP
)
471 * create a new AARP entry with the flags set to be published --
472 * we need this one to hang around even if it's in use
474 entry
= aarp_alloc();
479 entry
->expires_at
= -1;
480 entry
->status
= ATIF_PROBE
;
481 entry
->target_addr
.s_node
= sa
->s_node
;
482 entry
->target_addr
.s_net
= sa
->s_net
;
483 entry
->dev
= atif
->dev
;
485 write_lock_bh(&aarp_lock
);
487 hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
488 entry
->next
= proxies
[hash
];
489 proxies
[hash
] = entry
;
491 for (count
= 0; count
< AARP_RETRANSMIT_LIMIT
; count
++) {
492 aarp_send_probe(atif
->dev
, sa
);
495 write_unlock_bh(&aarp_lock
);
497 write_lock_bh(&aarp_lock
);
499 if (entry
->status
& ATIF_PROBE_FAIL
)
503 if (entry
->status
& ATIF_PROBE_FAIL
) {
504 entry
->expires_at
= jiffies
- 1; /* free the entry */
505 retval
= -EADDRINUSE
; /* return network full */
506 } else { /* clear the probing flag */
507 entry
->status
&= ~ATIF_PROBE
;
511 write_unlock_bh(&aarp_lock
);
516 /* Send a DDP frame */
517 int aarp_send_ddp(struct net_device
*dev
, struct sk_buff
*skb
,
518 struct atalk_addr
*sa
, void *hwaddr
)
520 static char ddp_eth_multicast
[ETH_ALEN
] =
521 { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
523 struct aarp_entry
*a
;
525 skb_reset_network_header(skb
);
527 /* Check for LocalTalk first */
528 if (dev
->type
== ARPHRD_LOCALTLK
) {
529 struct atalk_addr
*at
= atalk_find_dev_addr(dev
);
530 struct ddpehdr
*ddp
= (struct ddpehdr
*)skb
->data
;
536 * IFF: src_net == dest_net == device_net
537 * (zero matches anything)
540 if ((!ddp
->deh_snet
|| at
->s_net
== ddp
->deh_snet
) &&
541 (!ddp
->deh_dnet
|| at
->s_net
== ddp
->deh_dnet
)) {
542 skb_pull(skb
, sizeof(*ddp
) - 4);
545 * The upper two remaining bytes are the port
546 * numbers we just happen to need. Now put the
547 * length in the lower two.
549 *((__be16
*)skb
->data
) = htons(skb
->len
);
553 * Nice and easy. No AARP type protocols occur here so we can
554 * just shovel it out with a 3 byte LLAP header
558 skb
->data
[0] = sa
->s_node
;
559 skb
->data
[1] = at
->s_node
;
565 /* On a PPP link we neither compress nor aarp. */
566 if (dev
->type
== ARPHRD_PPP
) {
567 skb
->protocol
= htons(ETH_P_PPPTALK
);
572 /* Non ELAP we cannot do. */
573 if (dev
->type
!= ARPHRD_ETHER
)
577 skb
->protocol
= htons(ETH_P_ATALK
);
578 hash
= sa
->s_node
% (AARP_HASH_SIZE
- 1);
580 /* Do we have a resolved entry? */
581 if (sa
->s_node
== ATADDR_BCAST
) {
583 ddp_dl
->request(ddp_dl
, skb
, ddp_eth_multicast
);
587 write_lock_bh(&aarp_lock
);
588 a
= __aarp_find_entry(resolved
[hash
], dev
, sa
);
590 if (a
) { /* Return 1 and fill in the address */
591 a
->expires_at
= jiffies
+ (sysctl_aarp_expiry_time
* 10);
592 ddp_dl
->request(ddp_dl
, skb
, a
->hwaddr
);
593 write_unlock_bh(&aarp_lock
);
597 /* Do we have an unresolved entry: This is the less common path */
598 a
= __aarp_find_entry(unresolved
[hash
], dev
, sa
);
599 if (a
) { /* Queue onto the unresolved queue */
600 skb_queue_tail(&a
->packet_queue
, skb
);
604 /* Allocate a new entry */
607 /* Whoops slipped... good job it's an unreliable protocol 8) */
608 write_unlock_bh(&aarp_lock
);
612 /* Set up the queue */
613 skb_queue_tail(&a
->packet_queue
, skb
);
614 a
->expires_at
= jiffies
+ sysctl_aarp_resolve_time
;
616 a
->next
= unresolved
[hash
];
617 a
->target_addr
= *sa
;
619 unresolved
[hash
] = a
;
622 /* Send an initial request for the address */
623 __aarp_send_query(a
);
626 * Switch to fast timer if needed (That is if this is the first
627 * unresolved entry to get added)
630 if (unresolved_count
== 1)
631 mod_timer(&aarp_timer
, jiffies
+ sysctl_aarp_tick_time
);
633 /* Now finally, it is safe to drop the lock. */
635 write_unlock_bh(&aarp_lock
);
637 /* Tell the ddp layer we have taken over for this frame. */
642 skb
->priority
= skb
->sk
->sk_priority
;
643 if (dev_queue_xmit(skb
))
646 return NET_XMIT_SUCCESS
;
650 return NET_XMIT_DROP
;
652 EXPORT_SYMBOL(aarp_send_ddp
);
655 * An entry in the aarp unresolved queue has become resolved. Send
656 * all the frames queued under it.
658 * Must run under aarp_lock.
660 static void __aarp_resolved(struct aarp_entry
**list
, struct aarp_entry
*a
,
670 /* Move into the resolved list */
671 a
->next
= resolved
[hash
];
674 /* Kick frames off */
675 while ((skb
= skb_dequeue(&a
->packet_queue
)) != NULL
) {
676 a
->expires_at
= jiffies
+
677 sysctl_aarp_expiry_time
* 10;
678 ddp_dl
->request(ddp_dl
, skb
, a
->hwaddr
);
681 list
= &((*list
)->next
);
685 * This is called by the SNAP driver whenever we see an AARP SNAP
686 * frame. We currently only support Ethernet.
688 static int aarp_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
689 struct packet_type
*pt
, struct net_device
*orig_dev
)
691 struct elapaarp
*ea
= aarp_hdr(skb
);
694 struct aarp_entry
*a
;
695 struct atalk_addr sa
, *ma
, da
;
696 struct atalk_iface
*ifa
;
698 if (!net_eq(dev_net(dev
), &init_net
))
701 /* We only do Ethernet SNAP AARP. */
702 if (dev
->type
!= ARPHRD_ETHER
)
706 if (!skb_pull(skb
, sizeof(*ea
)))
709 function
= ntohs(ea
->function
);
711 /* Sanity check fields. */
712 if (function
< AARP_REQUEST
|| function
> AARP_PROBE
||
713 ea
->hw_len
!= ETH_ALEN
|| ea
->pa_len
!= AARP_PA_ALEN
||
714 ea
->pa_src_zero
|| ea
->pa_dst_zero
)
718 hash
= ea
->pa_src_node
% (AARP_HASH_SIZE
- 1);
720 /* Build an address. */
721 sa
.s_node
= ea
->pa_src_node
;
722 sa
.s_net
= ea
->pa_src_net
;
724 /* Process the packet. Check for replies of me. */
725 ifa
= atalk_find_dev(dev
);
729 if (ifa
->status
& ATIF_PROBE
&&
730 ifa
->address
.s_node
== ea
->pa_dst_node
&&
731 ifa
->address
.s_net
== ea
->pa_dst_net
) {
732 ifa
->status
|= ATIF_PROBE_FAIL
; /* Fail the probe (in use) */
736 /* Check for replies of proxy AARP entries */
737 da
.s_node
= ea
->pa_dst_node
;
738 da
.s_net
= ea
->pa_dst_net
;
740 write_lock_bh(&aarp_lock
);
741 a
= __aarp_find_entry(proxies
[hash
], dev
, &da
);
743 if (a
&& a
->status
& ATIF_PROBE
) {
744 a
->status
|= ATIF_PROBE_FAIL
;
746 * we do not respond to probe or request packets for
747 * this address while we are probing this address
754 if (!unresolved_count
) /* Speed up */
757 /* Find the entry. */
758 a
= __aarp_find_entry(unresolved
[hash
], dev
, &sa
);
759 if (!a
|| dev
!= a
->dev
)
762 /* We can fill one in - this is good. */
763 memcpy(a
->hwaddr
, ea
->hw_src
, ETH_ALEN
);
764 __aarp_resolved(&unresolved
[hash
], a
, hash
);
765 if (!unresolved_count
)
766 mod_timer(&aarp_timer
,
767 jiffies
+ sysctl_aarp_expiry_time
);
774 * If it is my address set ma to my address and reply.
775 * We can treat probe and request the same. Probe
776 * simply means we shouldn't cache the querying host,
777 * as in a probe they are proposing an address not
780 * Support for proxy-AARP added. We check if the
781 * address is one of our proxies before we toss the
785 sa
.s_node
= ea
->pa_dst_node
;
786 sa
.s_net
= ea
->pa_dst_net
;
788 /* See if we have a matching proxy. */
789 ma
= __aarp_proxy_find(dev
, &sa
);
792 else { /* We need to make a copy of the entry. */
793 da
.s_node
= sa
.s_node
;
798 if (function
== AARP_PROBE
) {
800 * A probe implies someone trying to get an
801 * address. So as a precaution flush any
802 * entries we have for this address.
804 a
= __aarp_find_entry(resolved
[sa
.s_node
%
805 (AARP_HASH_SIZE
- 1)],
809 * Make it expire next tick - that avoids us
810 * getting into a probe/flush/learn/probe/
811 * flush/learn cycle during probing of a slow
812 * to respond host addr.
815 a
->expires_at
= jiffies
- 1;
816 mod_timer(&aarp_timer
, jiffies
+
817 sysctl_aarp_tick_time
);
821 if (sa
.s_node
!= ma
->s_node
)
824 if (sa
.s_net
&& ma
->s_net
&& sa
.s_net
!= ma
->s_net
)
827 sa
.s_node
= ea
->pa_src_node
;
828 sa
.s_net
= ea
->pa_src_net
;
830 /* aarp_my_address has found the address to use for us.
832 aarp_send_reply(dev
, ma
, &sa
, ea
->hw_src
);
837 write_unlock_bh(&aarp_lock
);
845 static struct notifier_block aarp_notifier
= {
846 .notifier_call
= aarp_device_event
,
849 static unsigned char aarp_snap_id
[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
851 void __init
aarp_proto_init(void)
853 aarp_dl
= register_snap_client(aarp_snap_id
, aarp_rcv
);
855 printk(KERN_CRIT
"Unable to register AARP with SNAP.\n");
856 setup_timer(&aarp_timer
, aarp_expire_timeout
, 0);
857 aarp_timer
.expires
= jiffies
+ sysctl_aarp_expiry_time
;
858 add_timer(&aarp_timer
);
859 register_netdevice_notifier(&aarp_notifier
);
862 /* Remove the AARP entries associated with a device. */
863 void aarp_device_down(struct net_device
*dev
)
867 write_lock_bh(&aarp_lock
);
869 for (ct
= 0; ct
< AARP_HASH_SIZE
; ct
++) {
870 __aarp_expire_device(&resolved
[ct
], dev
);
871 __aarp_expire_device(&unresolved
[ct
], dev
);
872 __aarp_expire_device(&proxies
[ct
], dev
);
875 write_unlock_bh(&aarp_lock
);
878 #ifdef CONFIG_PROC_FS
879 struct aarp_iter_state
{
881 struct aarp_entry
**table
;
885 * Get the aarp entry that is in the chain described
887 * If pos is set then skip till that index.
888 * pos = 1 is the first entry
890 static struct aarp_entry
*iter_next(struct aarp_iter_state
*iter
, loff_t
*pos
)
892 int ct
= iter
->bucket
;
893 struct aarp_entry
**table
= iter
->table
;
895 struct aarp_entry
*entry
;
898 while(ct
< AARP_HASH_SIZE
) {
899 for (entry
= table
[ct
]; entry
; entry
= entry
->next
) {
900 if (!pos
|| ++off
== *pos
) {
909 if (table
== resolved
) {
914 if (table
== unresolved
) {
922 static void *aarp_seq_start(struct seq_file
*seq
, loff_t
*pos
)
923 __acquires(aarp_lock
)
925 struct aarp_iter_state
*iter
= seq
->private;
927 read_lock_bh(&aarp_lock
);
928 iter
->table
= resolved
;
931 return *pos
? iter_next(iter
, pos
) : SEQ_START_TOKEN
;
934 static void *aarp_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
936 struct aarp_entry
*entry
= v
;
937 struct aarp_iter_state
*iter
= seq
->private;
941 /* first line after header */
942 if (v
== SEQ_START_TOKEN
)
943 entry
= iter_next(iter
, NULL
);
945 /* next entry in current bucket */
946 else if (entry
->next
)
949 /* next bucket or table */
952 entry
= iter_next(iter
, NULL
);
957 static void aarp_seq_stop(struct seq_file
*seq
, void *v
)
958 __releases(aarp_lock
)
960 read_unlock_bh(&aarp_lock
);
963 static const char *dt2str(unsigned long ticks
)
967 sprintf(buf
, "%ld.%02ld", ticks
/ HZ
, ((ticks
% HZ
) * 100 ) / HZ
);
972 static int aarp_seq_show(struct seq_file
*seq
, void *v
)
974 struct aarp_iter_state
*iter
= seq
->private;
975 struct aarp_entry
*entry
= v
;
976 unsigned long now
= jiffies
;
978 if (v
== SEQ_START_TOKEN
)
980 "Address Interface Hardware Address"
981 " Expires LastSend Retry Status\n");
983 seq_printf(seq
, "%04X:%02X %-12s",
984 ntohs(entry
->target_addr
.s_net
),
985 (unsigned int) entry
->target_addr
.s_node
,
986 entry
->dev
? entry
->dev
->name
: "????");
987 seq_printf(seq
, "%pM", entry
->hwaddr
);
988 seq_printf(seq
, " %8s",
989 dt2str((long)entry
->expires_at
- (long)now
));
990 if (iter
->table
== unresolved
)
991 seq_printf(seq
, " %8s %6hu",
992 dt2str(now
- entry
->last_sent
),
996 seq_printf(seq
, " %s\n",
997 (iter
->table
== resolved
) ? "resolved"
998 : (iter
->table
== unresolved
) ? "unresolved"
999 : (iter
->table
== proxies
) ? "proxies"
1005 static const struct seq_operations aarp_seq_ops
= {
1006 .start
= aarp_seq_start
,
1007 .next
= aarp_seq_next
,
1008 .stop
= aarp_seq_stop
,
1009 .show
= aarp_seq_show
,
1012 static int aarp_seq_open(struct inode
*inode
, struct file
*file
)
1014 return seq_open_private(file
, &aarp_seq_ops
,
1015 sizeof(struct aarp_iter_state
));
1018 const struct file_operations atalk_seq_arp_fops
= {
1019 .owner
= THIS_MODULE
,
1020 .open
= aarp_seq_open
,
1022 .llseek
= seq_lseek
,
1023 .release
= seq_release_private
,
1027 /* General module cleanup. Called from cleanup_module() in ddp.c. */
1028 void aarp_cleanup_module(void)
1030 del_timer_sync(&aarp_timer
);
1031 unregister_netdevice_notifier(&aarp_notifier
);
1032 unregister_snap_client(aarp_dl
);