|
@@ -28,11 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
28
|
28
|
#include <ipxe/if_arp.h>
|
29
|
29
|
#include <ipxe/iobuf.h>
|
30
|
30
|
#include <ipxe/netdevice.h>
|
31
|
|
-#include <ipxe/list.h>
|
32
|
|
-#include <ipxe/retry.h>
|
33
|
|
-#include <ipxe/timer.h>
|
34
|
|
-#include <ipxe/malloc.h>
|
35
|
|
-#include <ipxe/refcnt.h>
|
|
31
|
+#include <ipxe/neighbour.h>
|
36
|
32
|
#include <ipxe/arp.h>
|
37
|
33
|
|
38
|
34
|
/** @file
|
|
@@ -45,291 +41,30 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
45
|
41
|
*
|
46
|
42
|
*/
|
47
|
43
|
|
48
|
|
-/** ARP minimum timeout */
|
49
|
|
-#define ARP_MIN_TIMEOUT ( TICKS_PER_SEC / 8 )
|
50
|
|
-
|
51
|
|
-/** ARP maximum timeout */
|
52
|
|
-#define ARP_MAX_TIMEOUT ( TICKS_PER_SEC * 3 )
|
53
|
|
-
|
54
|
|
-/** An ARP cache entry */
|
55
|
|
-struct arp_entry {
|
56
|
|
- /** Reference count */
|
57
|
|
- struct refcnt refcnt;
|
58
|
|
- /** List of ARP cache entries */
|
59
|
|
- struct list_head list;
|
60
|
|
- /** Network device */
|
61
|
|
- struct net_device *netdev;
|
62
|
|
- /** Network-layer protocol */
|
63
|
|
- struct net_protocol *net_protocol;
|
64
|
|
- /** Network-layer destination address */
|
65
|
|
- uint8_t net_dest[MAX_NET_ADDR_LEN];
|
66
|
|
- /** Network-layer source address */
|
67
|
|
- uint8_t net_source[MAX_NET_ADDR_LEN];
|
68
|
|
- /** Link-layer destination address */
|
69
|
|
- uint8_t ll_dest[MAX_LL_ADDR_LEN];
|
70
|
|
- /** Retransmission timer */
|
71
|
|
- struct retry_timer timer;
|
72
|
|
- /** Pending I/O buffers */
|
73
|
|
- struct list_head tx_queue;
|
74
|
|
-};
|
75
|
|
-
|
76
|
|
-/** The ARP cache */
|
77
|
|
-static LIST_HEAD ( arp_entries );
|
78
|
|
-
|
79
|
44
|
struct net_protocol arp_protocol __net_protocol;
|
80
|
45
|
|
81
|
|
-static void arp_expired ( struct retry_timer *timer, int over );
|
82
|
|
-
|
83
|
|
-/**
|
84
|
|
- * Free ARP cache entry
|
85
|
|
- *
|
86
|
|
- * @v refcnt Reference count
|
87
|
|
- */
|
88
|
|
-static void arp_free ( struct refcnt *refcnt ) {
|
89
|
|
- struct arp_entry *arp =
|
90
|
|
- container_of ( refcnt, struct arp_entry, refcnt );
|
91
|
|
-
|
92
|
|
- /* Sanity check */
|
93
|
|
- assert ( list_empty ( &arp->tx_queue ) );
|
94
|
|
-
|
95
|
|
- /* Drop reference to network device */
|
96
|
|
- netdev_put ( arp->netdev );
|
97
|
|
-
|
98
|
|
- /* Free entry */
|
99
|
|
- free ( arp );
|
100
|
|
-}
|
101
|
|
-
|
102
|
|
-/**
|
103
|
|
- * Create ARP cache entry
|
104
|
|
- *
|
105
|
|
- * @v netdev Network device
|
106
|
|
- * @v net_protocol Network-layer protocol
|
107
|
|
- * @v net_dest Destination network-layer address
|
108
|
|
- * @v net_source Source network-layer address
|
109
|
|
- * @ret arp ARP cache entry, or NULL if allocation failed
|
110
|
|
- */
|
111
|
|
-static struct arp_entry * arp_create ( struct net_device *netdev,
|
112
|
|
- struct net_protocol *net_protocol,
|
113
|
|
- const void *net_dest,
|
114
|
|
- const void *net_source ) {
|
115
|
|
- struct arp_entry *arp;
|
116
|
|
-
|
117
|
|
- /* Allocate and initialise entry */
|
118
|
|
- arp = zalloc ( sizeof ( *arp ) );
|
119
|
|
- if ( ! arp )
|
120
|
|
- return NULL;
|
121
|
|
- ref_init ( &arp->refcnt, arp_free );
|
122
|
|
- arp->netdev = netdev_get ( netdev );
|
123
|
|
- arp->net_protocol = net_protocol;
|
124
|
|
- memcpy ( arp->net_dest, net_dest,
|
125
|
|
- net_protocol->net_addr_len );
|
126
|
|
- memcpy ( arp->net_source, net_source,
|
127
|
|
- net_protocol->net_addr_len );
|
128
|
|
- timer_init ( &arp->timer, arp_expired, &arp->refcnt );
|
129
|
|
- arp->timer.min_timeout = ARP_MIN_TIMEOUT;
|
130
|
|
- arp->timer.max_timeout = ARP_MAX_TIMEOUT;
|
131
|
|
- INIT_LIST_HEAD ( &arp->tx_queue );
|
132
|
|
-
|
133
|
|
- /* Start timer running to trigger initial transmission */
|
134
|
|
- start_timer_nodelay ( &arp->timer );
|
135
|
|
-
|
136
|
|
- /* Transfer ownership to cache */
|
137
|
|
- list_add ( &arp->list, &arp_entries );
|
138
|
|
-
|
139
|
|
- DBGC ( arp, "ARP %p %s %s %s created\n", arp, netdev->name,
|
140
|
|
- net_protocol->name, net_protocol->ntoa ( net_dest ) );
|
141
|
|
- return arp;
|
142
|
|
-}
|
143
|
|
-
|
144
|
|
-/**
|
145
|
|
- * Find entry in the ARP cache
|
146
|
|
- *
|
147
|
|
- * @v netdev Network device
|
148
|
|
- * @v net_protocol Network-layer protocol
|
149
|
|
- * @v net_dest Destination network-layer address
|
150
|
|
- * @ret arp ARP cache entry, or NULL if not found
|
151
|
|
- */
|
152
|
|
-static struct arp_entry * arp_find ( struct net_device *netdev,
|
153
|
|
- struct net_protocol *net_protocol,
|
154
|
|
- const void *net_dest ) {
|
155
|
|
- struct arp_entry *arp;
|
156
|
|
-
|
157
|
|
- list_for_each_entry ( arp, &arp_entries, list ) {
|
158
|
|
- if ( ( arp->netdev == netdev ) &&
|
159
|
|
- ( arp->net_protocol == net_protocol ) &&
|
160
|
|
- ( memcmp ( arp->net_dest, net_dest,
|
161
|
|
- net_protocol->net_addr_len ) == 0 ) ) {
|
162
|
|
-
|
163
|
|
- /* Move to start of cache */
|
164
|
|
- list_del ( &arp->list );
|
165
|
|
- list_add ( &arp->list, &arp_entries );
|
166
|
|
-
|
167
|
|
- return arp;
|
168
|
|
- }
|
169
|
|
- }
|
170
|
|
- return NULL;
|
171
|
|
-}
|
172
|
|
-
|
173
|
|
-/**
|
174
|
|
- * Destroy ARP cache entry
|
175
|
|
- *
|
176
|
|
- * @v arp ARP cache entry
|
177
|
|
- * @v rc Reason for destruction
|
178
|
|
- */
|
179
|
|
-static void arp_destroy ( struct arp_entry *arp, int rc ) {
|
180
|
|
- struct net_device *netdev = arp->netdev;
|
181
|
|
- struct net_protocol *net_protocol = arp->net_protocol;
|
182
|
|
- struct io_buffer *iobuf;
|
183
|
|
-
|
184
|
|
- /* Take ownership from cache */
|
185
|
|
- list_del ( &arp->list );
|
186
|
|
-
|
187
|
|
- /* Stop timer */
|
188
|
|
- stop_timer ( &arp->timer );
|
189
|
|
-
|
190
|
|
- /* Discard any outstanding I/O buffers */
|
191
|
|
- while ( ( iobuf = list_first_entry ( &arp->tx_queue, struct io_buffer,
|
192
|
|
- list ) ) != NULL ) {
|
193
|
|
- DBGC2 ( arp, "ARP %p %s %s %s discarding deferred packet: "
|
194
|
|
- "%s\n", arp, netdev->name, net_protocol->name,
|
195
|
|
- net_protocol->ntoa ( arp->net_dest ), strerror ( rc ) );
|
196
|
|
- list_del ( &iobuf->list );
|
197
|
|
- netdev_tx_err ( arp->netdev, iobuf, rc );
|
198
|
|
- }
|
199
|
|
-
|
200
|
|
- DBGC ( arp, "ARP %p %s %s %s destroyed: %s\n", arp, netdev->name,
|
201
|
|
- net_protocol->name, net_protocol->ntoa ( arp->net_dest ),
|
202
|
|
- strerror ( rc ) );
|
203
|
|
-
|
204
|
|
- /* Drop remaining reference */
|
205
|
|
- ref_put ( &arp->refcnt );
|
206
|
|
-}
|
207
|
|
-
|
208
|
46
|
/**
|
209
|
|
- * Test if ARP cache entry has a valid link-layer address
|
|
47
|
+ * Transmit ARP request
|
210
|
48
|
*
|
211
|
|
- * @v arp ARP cache entry
|
212
|
|
- * @ret resolved ARP cache entry is resolved
|
213
|
|
- */
|
214
|
|
-static inline int arp_resolved ( struct arp_entry *arp ) {
|
215
|
|
- return ( ! timer_running ( &arp->timer ) );
|
216
|
|
-}
|
217
|
|
-
|
218
|
|
-/**
|
219
|
|
- * Transmit packet, determining link-layer address via ARP
|
220
|
|
- *
|
221
|
|
- * @v iobuf I/O buffer
|
222
|
49
|
* @v netdev Network device
|
223
|
50
|
* @v net_protocol Network-layer protocol
|
224
|
51
|
* @v net_dest Destination network-layer address
|
225
|
52
|
* @v net_source Source network-layer address
|
226
|
|
- * @v ll_source Source link-layer address
|
227
|
53
|
* @ret rc Return status code
|
228
|
54
|
*/
|
229
|
|
-int arp_tx ( struct io_buffer *iobuf, struct net_device *netdev,
|
230
|
|
- struct net_protocol *net_protocol, const void *net_dest,
|
231
|
|
- const void *net_source, const void *ll_source ) {
|
232
|
|
- struct arp_entry *arp;
|
233
|
|
-
|
234
|
|
- /* Find or create ARP cache entry */
|
235
|
|
- arp = arp_find ( netdev, net_protocol, net_dest );
|
236
|
|
- if ( ! arp ) {
|
237
|
|
- arp = arp_create ( netdev, net_protocol, net_dest,
|
238
|
|
- net_source );
|
239
|
|
- if ( ! arp )
|
240
|
|
- return -ENOMEM;
|
241
|
|
- }
|
242
|
|
-
|
243
|
|
- /* If a link-layer address is available then transmit
|
244
|
|
- * immediately, otherwise queue for later transmission.
|
245
|
|
- */
|
246
|
|
- if ( arp_resolved ( arp ) ) {
|
247
|
|
- return net_tx ( iobuf, netdev, net_protocol, arp->ll_dest,
|
248
|
|
- ll_source );
|
249
|
|
- } else {
|
250
|
|
- DBGC2 ( arp, "ARP %p %s %s %s deferring packet\n",
|
251
|
|
- arp, netdev->name, net_protocol->name,
|
252
|
|
- net_protocol->ntoa ( net_dest ) );
|
253
|
|
- list_add_tail ( &iobuf->list, &arp->tx_queue );
|
254
|
|
- return -EAGAIN;
|
255
|
|
- }
|
256
|
|
-}
|
257
|
|
-
|
258
|
|
-/**
|
259
|
|
- * Update ARP cache entry
|
260
|
|
- *
|
261
|
|
- * @v arp ARP cache entry
|
262
|
|
- * @v ll_dest Destination link-layer address
|
263
|
|
- */
|
264
|
|
-static void arp_update ( struct arp_entry *arp, const void *ll_dest ) {
|
265
|
|
- struct net_device *netdev = arp->netdev;
|
266
|
|
- struct ll_protocol *ll_protocol = netdev->ll_protocol;
|
267
|
|
- struct net_protocol *net_protocol = arp->net_protocol;
|
268
|
|
- struct io_buffer *iobuf;
|
269
|
|
- int rc;
|
270
|
|
-
|
271
|
|
- DBGC ( arp, "ARP %p %s %s %s updated => %s\n", arp, netdev->name,
|
272
|
|
- net_protocol->name, net_protocol->ntoa ( arp->net_dest ),
|
273
|
|
- ll_protocol->ntoa ( ll_dest ) );
|
274
|
|
-
|
275
|
|
- /* Fill in link-layer address */
|
276
|
|
- memcpy ( arp->ll_dest, ll_dest, ll_protocol->ll_addr_len );
|
277
|
|
-
|
278
|
|
- /* Stop retransmission timer */
|
279
|
|
- stop_timer ( &arp->timer );
|
280
|
|
-
|
281
|
|
- /* Transmit any packets in queue. Take out a temporary
|
282
|
|
- * reference on the entry to prevent it from going out of
|
283
|
|
- * scope during the call to net_tx().
|
284
|
|
- */
|
285
|
|
- ref_get ( &arp->refcnt );
|
286
|
|
- while ( ( iobuf = list_first_entry ( &arp->tx_queue, struct io_buffer,
|
287
|
|
- list ) ) != NULL ) {
|
288
|
|
- DBGC2 ( arp, "ARP %p %s %s %s transmitting deferred packet\n",
|
289
|
|
- arp, netdev->name, net_protocol->name,
|
290
|
|
- net_protocol->ntoa ( arp->net_dest ) );
|
291
|
|
- list_del ( &iobuf->list );
|
292
|
|
- if ( ( rc = net_tx ( iobuf, netdev, net_protocol, ll_dest,
|
293
|
|
- netdev->ll_addr ) ) != 0 ) {
|
294
|
|
- DBGC ( arp, "ARP %p could not transmit deferred "
|
295
|
|
- "packet: %s\n", arp, strerror ( rc ) );
|
296
|
|
- /* Ignore error and continue */
|
297
|
|
- }
|
298
|
|
- }
|
299
|
|
- ref_put ( &arp->refcnt );
|
300
|
|
-}
|
301
|
|
-
|
302
|
|
-/**
|
303
|
|
- * Handle ARP timer expiry
|
304
|
|
- *
|
305
|
|
- * @v timer Retry timer
|
306
|
|
- * @v fail Failure indicator
|
307
|
|
- */
|
308
|
|
-static void arp_expired ( struct retry_timer *timer, int fail ) {
|
309
|
|
- struct arp_entry *arp = container_of ( timer, struct arp_entry, timer );
|
310
|
|
- struct net_device *netdev = arp->netdev;
|
|
55
|
+static int arp_tx_request ( struct net_device *netdev,
|
|
56
|
+ struct net_protocol *net_protocol,
|
|
57
|
+ const void *net_dest, const void *net_source ) {
|
311
|
58
|
struct ll_protocol *ll_protocol = netdev->ll_protocol;
|
312
|
|
- struct net_protocol *net_protocol = arp->net_protocol;
|
313
|
59
|
struct io_buffer *iobuf;
|
314
|
60
|
struct arphdr *arphdr;
|
315
|
61
|
int rc;
|
316
|
62
|
|
317
|
|
- /* If we have failed, destroy the cache entry */
|
318
|
|
- if ( fail ) {
|
319
|
|
- arp_destroy ( arp, -ETIMEDOUT );
|
320
|
|
- return;
|
321
|
|
- }
|
322
|
|
-
|
323
|
|
- /* Restart the timer */
|
324
|
|
- start_timer ( &arp->timer );
|
325
|
|
-
|
326
|
63
|
/* Allocate ARP packet */
|
327
|
64
|
iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *arphdr ) +
|
328
|
65
|
( 2 * ( MAX_LL_ADDR_LEN + MAX_NET_ADDR_LEN ) ) );
|
329
|
|
- if ( ! iobuf ) {
|
330
|
|
- /* Leave timer running and try again later */
|
331
|
|
- return;
|
332
|
|
- }
|
|
66
|
+ if ( ! iobuf )
|
|
67
|
+ return -ENOMEM;
|
333
|
68
|
iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
|
334
|
69
|
|
335
|
70
|
/* Build up ARP request */
|
|
@@ -342,21 +77,30 @@ static void arp_expired ( struct retry_timer *timer, int fail ) {
|
342
|
77
|
memcpy ( iob_put ( iobuf, ll_protocol->ll_addr_len ),
|
343
|
78
|
netdev->ll_addr, ll_protocol->ll_addr_len );
|
344
|
79
|
memcpy ( iob_put ( iobuf, net_protocol->net_addr_len ),
|
345
|
|
- arp->net_source, net_protocol->net_addr_len );
|
|
80
|
+ net_source, net_protocol->net_addr_len );
|
346
|
81
|
memset ( iob_put ( iobuf, ll_protocol->ll_addr_len ),
|
347
|
82
|
0, ll_protocol->ll_addr_len );
|
348
|
83
|
memcpy ( iob_put ( iobuf, net_protocol->net_addr_len ),
|
349
|
|
- arp->net_dest, net_protocol->net_addr_len );
|
|
84
|
+ net_dest, net_protocol->net_addr_len );
|
350
|
85
|
|
351
|
86
|
/* Transmit ARP request */
|
352
|
87
|
if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol,
|
353
|
88
|
netdev->ll_broadcast, netdev->ll_addr ) ) != 0 ) {
|
354
|
|
- DBGC ( arp, "ARP %p could not transmit request: %s\n",
|
355
|
|
- arp, strerror ( rc ) );
|
356
|
|
- return;
|
|
89
|
+ DBGC ( netdev, "ARP %s %s %s could not transmit request: %s\n",
|
|
90
|
+ netdev->name, net_protocol->name,
|
|
91
|
+ net_protocol->ntoa ( net_dest ), strerror ( rc ) );
|
|
92
|
+ return rc;
|
357
|
93
|
}
|
|
94
|
+
|
|
95
|
+ return 0;
|
358
|
96
|
}
|
359
|
97
|
|
|
98
|
+/** ARP neighbour discovery protocol */
|
|
99
|
+struct neighbour_discovery arp_discovery = {
|
|
100
|
+ .name = "ARP",
|
|
101
|
+ .tx_request = arp_tx_request,
|
|
102
|
+};
|
|
103
|
+
|
360
|
104
|
/**
|
361
|
105
|
* Identify ARP protocol
|
362
|
106
|
*
|
|
@@ -368,9 +112,8 @@ static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
|
368
|
112
|
struct arp_net_protocol *arp_net_protocol;
|
369
|
113
|
|
370
|
114
|
for_each_table_entry ( arp_net_protocol, ARP_NET_PROTOCOLS ) {
|
371
|
|
- if ( arp_net_protocol->net_protocol->net_proto == net_proto ) {
|
|
115
|
+ if ( arp_net_protocol->net_protocol->net_proto == net_proto )
|
372
|
116
|
return arp_net_protocol;
|
373
|
|
- }
|
374
|
117
|
}
|
375
|
118
|
return NULL;
|
376
|
119
|
}
|
|
@@ -392,7 +135,6 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
|
392
|
135
|
struct arp_net_protocol *arp_net_protocol;
|
393
|
136
|
struct net_protocol *net_protocol;
|
394
|
137
|
struct ll_protocol *ll_protocol;
|
395
|
|
- struct arp_entry *arp;
|
396
|
138
|
int rc;
|
397
|
139
|
|
398
|
140
|
/* Identify network-layer and link-layer protocols */
|
|
@@ -412,11 +154,9 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
|
412
|
154
|
goto done;
|
413
|
155
|
}
|
414
|
156
|
|
415
|
|
- /* See if we have an entry for this sender, and update it if so */
|
416
|
|
- arp = arp_find ( netdev, net_protocol, arp_sender_pa ( arphdr ) );
|
417
|
|
- if ( arp ) {
|
418
|
|
- arp_update ( arp, arp_sender_ha ( arphdr ) );
|
419
|
|
- }
|
|
157
|
+ /* Update neighbour cache entry for this sender, if any */
|
|
158
|
+ neighbour_update ( netdev, net_protocol, arp_sender_pa ( arphdr ),
|
|
159
|
+ arp_sender_ha ( arphdr ) );
|
420
|
160
|
|
421
|
161
|
/* If it's not a request, there's nothing more to do */
|
422
|
162
|
if ( arphdr->ar_op != htons ( ARPOP_REQUEST ) ) {
|
|
@@ -431,10 +171,10 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
|
431
|
171
|
}
|
432
|
172
|
|
433
|
173
|
/* Change request to a reply */
|
434
|
|
- DBGC ( netdev, "ARP reply %s %s %s => %s %s\n",
|
435
|
|
- netdev->name, net_protocol->name,
|
436
|
|
- net_protocol->ntoa ( arp_target_pa ( arphdr ) ),
|
437
|
|
- ll_protocol->name, ll_protocol->ntoa ( netdev->ll_addr ) );
|
|
174
|
+ DBGC2 ( netdev, "ARP %s %s %s reply => %s %s\n",
|
|
175
|
+ netdev->name, net_protocol->name,
|
|
176
|
+ net_protocol->ntoa ( arp_target_pa ( arphdr ) ),
|
|
177
|
+ ll_protocol->name, ll_protocol->ntoa ( netdev->ll_addr ) );
|
438
|
178
|
arphdr->ar_op = htons ( ARPOP_REPLY );
|
439
|
179
|
memswap ( arp_sender_ha ( arphdr ), arp_target_ha ( arphdr ),
|
440
|
180
|
arphdr->ar_hln + arphdr->ar_pln );
|
|
@@ -444,8 +184,10 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
|
444
|
184
|
if ( ( rc = net_tx ( iob_disown ( iobuf ), netdev, &arp_protocol,
|
445
|
185
|
arp_target_ha ( arphdr ),
|
446
|
186
|
netdev->ll_addr ) ) != 0 ) {
|
447
|
|
- DBGC ( netdev, "ARP could not transmit reply via %s: %s\n",
|
448
|
|
- netdev->name, strerror ( rc ) );
|
|
187
|
+ DBGC ( netdev, "ARP %s %s %s could not transmit reply: %s\n",
|
|
188
|
+ netdev->name, net_protocol->name,
|
|
189
|
+ net_protocol->ntoa ( arp_target_pa ( arphdr ) ),
|
|
190
|
+ strerror ( rc ) );
|
449
|
191
|
goto done;
|
450
|
192
|
}
|
451
|
193
|
|
|
@@ -469,72 +211,10 @@ static const char * arp_ntoa ( const void *net_addr __unused ) {
|
469
|
211
|
return "<ARP>";
|
470
|
212
|
}
|
471
|
213
|
|
472
|
|
-/** ARP protocol */
|
|
214
|
+/** ARP network protocol */
|
473
|
215
|
struct net_protocol arp_protocol __net_protocol = {
|
474
|
216
|
.name = "ARP",
|
475
|
217
|
.net_proto = htons ( ETH_P_ARP ),
|
476
|
218
|
.rx = arp_rx,
|
477
|
219
|
.ntoa = arp_ntoa,
|
478
|
220
|
};
|
479
|
|
-
|
480
|
|
-/**
|
481
|
|
- * Update ARP cache on network device creation
|
482
|
|
- *
|
483
|
|
- * @v netdev Network device
|
484
|
|
- */
|
485
|
|
-static int arp_probe ( struct net_device *netdev __unused ) {
|
486
|
|
- /* Nothing to do */
|
487
|
|
- return 0;
|
488
|
|
-}
|
489
|
|
-
|
490
|
|
-/**
|
491
|
|
- * Update ARP cache on network device state change or removal
|
492
|
|
- *
|
493
|
|
- * @v netdev Network device
|
494
|
|
- */
|
495
|
|
-static void arp_flush ( struct net_device *netdev ) {
|
496
|
|
- struct arp_entry *arp;
|
497
|
|
- struct arp_entry *tmp;
|
498
|
|
-
|
499
|
|
- /* Remove all ARP cache entries when a network device is closed */
|
500
|
|
- if ( ! netdev_is_open ( netdev ) ) {
|
501
|
|
- list_for_each_entry_safe ( arp, tmp, &arp_entries, list )
|
502
|
|
- arp_destroy ( arp, -ENODEV );
|
503
|
|
- }
|
504
|
|
-}
|
505
|
|
-
|
506
|
|
-/** ARP driver (for net device notifications) */
|
507
|
|
-struct net_driver arp_net_driver __net_driver = {
|
508
|
|
- .name = "ARP",
|
509
|
|
- .probe = arp_probe,
|
510
|
|
- .notify = arp_flush,
|
511
|
|
- .remove = arp_flush,
|
512
|
|
-};
|
513
|
|
-
|
514
|
|
-/**
|
515
|
|
- * Discard some cached ARP entries
|
516
|
|
- *
|
517
|
|
- * @ret discarded Number of cached items discarded
|
518
|
|
- */
|
519
|
|
-static unsigned int arp_discard ( void ) {
|
520
|
|
- struct arp_entry *arp;
|
521
|
|
-
|
522
|
|
- /* Drop oldest cache entry, if any */
|
523
|
|
- arp = list_last_entry ( &arp_entries, struct arp_entry, list );
|
524
|
|
- if ( arp ) {
|
525
|
|
- arp_destroy ( arp, -ENOBUFS );
|
526
|
|
- return 1;
|
527
|
|
- } else {
|
528
|
|
- return 0;
|
529
|
|
- }
|
530
|
|
-}
|
531
|
|
-
|
532
|
|
-/** ARP cache discarder
|
533
|
|
- *
|
534
|
|
- * ARP cache entries are deemed to have a high replacement cost, since
|
535
|
|
- * flushing an active ARP cache entry midway through a TCP transfer
|
536
|
|
- * will cause substantial disruption.
|
537
|
|
- */
|
538
|
|
-struct cache_discarder arp_discarder __cache_discarder ( CACHE_EXPENSIVE ) = {
|
539
|
|
- .discard = arp_discard,
|
540
|
|
-};
|