Lines 52-57
Link Here
|
52 |
|
52 |
|
53 |
#include <dev/aoe/aoe.h> |
53 |
#include <dev/aoe/aoe.h> |
54 |
|
54 |
|
|
|
55 |
#ifdef VIMAGE |
56 |
#include <sys/jail.h> |
57 |
#define _aoenet_ifnet V_ifnet |
58 |
#else |
59 |
#define _aoenet_ifnet ifnet |
60 |
#endif |
61 |
|
55 |
/* |
62 |
/* |
56 |
* FORCE_NETWORK_HOOK is defined to support kernels that have not been patched |
63 |
* FORCE_NETWORK_HOOK is defined to support kernels that have not been patched |
57 |
* to recognize AoE packets. |
64 |
* to recognize AoE packets. |
Lines 77-84
Link Here
|
77 |
#define NECODES (sizeof(aoe_errlist) / sizeof(char *) - 1) |
84 |
#define NECODES (sizeof(aoe_errlist) / sizeof(char *) - 1) |
78 |
#if (__FreeBSD_version < 600000) |
85 |
#if (__FreeBSD_version < 600000) |
79 |
#define IFPADDR(ifp) (((struct arpcom *) (ifp))->ac_enaddr) |
86 |
#define IFPADDR(ifp) (((struct arpcom *) (ifp))->ac_enaddr) |
80 |
#else |
87 |
#elif (__FreeBSD_version < 700000) |
81 |
#define IFPADDR(ifp) IFP2ENADDR(ifp) |
88 |
#define IFPADDR(ifp) IFP2ENADDR(ifp) |
|
|
89 |
#else |
90 |
#include <net/if_dl.h> |
91 |
#define IFPADDR(ifp) IF_LLADDR(ifp) |
82 |
#endif |
92 |
#endif |
83 |
#define IFLISTSZ 1024 |
93 |
#define IFLISTSZ 1024 |
84 |
|
94 |
|
Lines 160-166
Link Here
|
160 |
register char *p, *q; |
170 |
register char *p, *q; |
161 |
register int len; |
171 |
register int len; |
162 |
|
172 |
|
|
|
173 |
#if __FreeBSD_version >= 1100030 |
174 |
switch (ifp->if_type) { |
175 |
#else |
163 |
switch (ifp->if_data.ifi_type) { |
176 |
switch (ifp->if_data.ifi_type) { |
|
|
177 |
#endif |
164 |
default: |
178 |
default: |
165 |
return (FALSE); |
179 |
return (FALSE); |
166 |
case IFT_ETHER: |
180 |
case IFT_ETHER: |
Lines 190-199
Link Here
|
190 |
/* |
204 |
/* |
191 |
* a dummy "free" function for mbuf ext buffer |
205 |
* a dummy "free" function for mbuf ext buffer |
192 |
*/ |
206 |
*/ |
|
|
207 |
#if __FreeBSD_version >= 1000050 |
208 |
#if __FreeBSD_version >= 1100028 |
209 |
static void |
210 |
#else |
211 |
static int |
212 |
#endif |
213 |
nilfn(struct mbuf *m, void *a, void *b) |
214 |
{ |
215 |
#if __FreeBSD_version < 1100028 |
216 |
return EXT_FREE_OK; |
217 |
#endif |
218 |
} |
219 |
#else |
193 |
static void |
220 |
static void |
194 |
nilfn(void *a, void *b) |
221 |
nilfn(void *a, void *b) |
195 |
{ |
222 |
{ |
196 |
} |
223 |
} |
|
|
224 |
#endif |
197 |
|
225 |
|
198 |
/* Create a mbuf chain and point to our data section(s). */ |
226 |
/* Create a mbuf chain and point to our data section(s). */ |
199 |
static struct mbuf * |
227 |
static struct mbuf * |
Lines 201-207
Link Here
|
201 |
{ |
229 |
{ |
202 |
struct mbuf *m; |
230 |
struct mbuf *m; |
203 |
|
231 |
|
204 |
if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL) |
232 |
if ((m = m_gethdr(M_NOWAIT, MT_DATA)) == NULL) |
205 |
return (NULL); |
233 |
return (NULL); |
206 |
m->m_len = AOEHDRSZ; |
234 |
m->m_len = AOEHDRSZ; |
207 |
m->m_pkthdr.len = f->f_mlen; |
235 |
m->m_pkthdr.len = f->f_mlen; |
Lines 215-228
Link Here
|
215 |
u_int len; |
243 |
u_int len; |
216 |
|
244 |
|
217 |
len = f->f_mlen - AOEHDRSZ; |
245 |
len = f->f_mlen - AOEHDRSZ; |
218 |
if ((m1 = m_get(M_DONTWAIT, MT_DATA)) == NULL) { |
246 |
if ((m1 = m_get(M_NOWAIT, MT_DATA)) == NULL) { |
219 |
m_freem(m); |
247 |
m_freem(m); |
220 |
return (NULL); |
248 |
return (NULL); |
221 |
} |
249 |
} |
222 |
m->m_next = m1; |
250 |
m->m_next = m1; |
223 |
|
251 |
|
|
|
252 |
#if __FreeBSD_version >= 1100028 |
253 |
m1->m_ext.ext_cnt = NULL; |
254 |
#else |
224 |
m1->m_ext.ref_cnt = NULL; |
255 |
m1->m_ext.ref_cnt = NULL; |
|
|
256 |
#endif |
225 |
MEXTADD(m1, f->f_data, len, nilfn, |
257 |
MEXTADD(m1, f->f_data, len, nilfn, |
|
|
258 |
#if (__FreeBSD_version >= 800000) |
259 |
f->f_data, |
260 |
#endif |
226 |
NULL, 0, EXT_NET_DRV); |
261 |
NULL, 0, EXT_NET_DRV); |
227 |
m1->m_len = len; |
262 |
m1->m_len = len; |
228 |
m1->m_next = NULL; |
263 |
m1->m_next = NULL; |
Lines 235-246
Link Here
|
235 |
aoenet_xmitframe(struct aoedev *d, struct frame *f) |
270 |
aoenet_xmitframe(struct aoedev *d, struct frame *f) |
236 |
{ |
271 |
{ |
237 |
struct mbuf *m; |
272 |
struct mbuf *m; |
238 |
|
273 |
|
239 |
m = frame_mbufinit(f); |
274 |
m = frame_mbufinit(f); |
240 |
if (m == NULL) |
275 |
if (m == NULL) |
241 |
return (ENOMEM); |
276 |
return (ENOMEM); |
242 |
|
277 |
|
243 |
return (ether_output_frame(d->ad_ifp, m)); |
278 |
#ifdef VIMAGE |
|
|
279 |
CURVNET_SET_QUIET(d->ad_ifp->if_vnet); |
280 |
#endif |
281 |
int ret = ether_output_frame(d->ad_ifp, m); |
282 |
#ifdef VIMAGE |
283 |
CURVNET_RESTORE(); |
284 |
#endif |
285 |
|
286 |
return ret; |
244 |
} |
287 |
} |
245 |
|
288 |
|
246 |
void |
289 |
void |
Lines 250-255
Link Here
|
250 |
struct aoe_cfghdr *ch; |
293 |
struct aoe_cfghdr *ch; |
251 |
struct mbuf *m, *m0; |
294 |
struct mbuf *m, *m0; |
252 |
struct ifnet *ifp; |
295 |
struct ifnet *ifp; |
|
|
296 |
|
253 |
|
297 |
|
254 |
m0 = m_gethdr(M_NOWAIT, MT_DATA); |
298 |
m0 = m_gethdr(M_NOWAIT, MT_DATA); |
255 |
if (m0 == NULL) { |
299 |
if (m0 == NULL) { |
Lines 264-269
Link Here
|
264 |
bzero(h, sizeof(*h) + sizeof(*ch)); |
308 |
bzero(h, sizeof(*h) + sizeof(*ch)); |
265 |
m0->m_flags |= M_BCAST; |
309 |
m0->m_flags |= M_BCAST; |
266 |
|
310 |
|
|
|
311 |
|
267 |
memset(h->ah_dst, 0xff, sizeof(h->ah_dst)); |
312 |
memset(h->ah_dst, 0xff, sizeof(h->ah_dst)); |
268 |
h->ah_type = htons(ETHERTYPE_AOE); |
313 |
h->ah_type = htons(ETHERTYPE_AOE); |
269 |
h->ah_verfl = AOE_HVER; |
314 |
h->ah_verfl = AOE_HVER; |
Lines 271-290
Link Here
|
271 |
h->ah_minor = aoeminor; |
316 |
h->ah_minor = aoeminor; |
272 |
h->ah_cmd = AOECMD_CFG; |
317 |
h->ah_cmd = AOECMD_CFG; |
273 |
|
318 |
|
|
|
319 |
#ifdef VIMAGE |
320 |
CURVNET_SET_QUIET(CRED_TO_VNET(curthread->td_ucred)); |
321 |
#endif |
322 |
|
274 |
IFNET_RLOCK(); |
323 |
IFNET_RLOCK(); |
275 |
TAILQ_FOREACH(ifp, &ifnet, if_link) { |
324 |
TAILQ_FOREACH(ifp, &_aoenet_ifnet, if_link) { |
276 |
if (!is_aoe_netif(ifp)) |
325 |
if (!is_aoe_netif(ifp)) |
277 |
continue; |
326 |
continue; |
278 |
memcpy(h->ah_src, IFPADDR(ifp), sizeof(h->ah_src)); |
327 |
memcpy(h->ah_src, IFPADDR(ifp), sizeof(h->ah_src)); |
279 |
m = m_copypacket(m0, M_DONTWAIT); |
328 |
m = m_copypacket(m0, M_NOWAIT); |
280 |
if (m == NULL) { |
329 |
if (m == NULL) { |
281 |
IPRINTK("m_copypacket failure\n"); |
330 |
IPRINTK("m_copypacket failure\n"); |
282 |
continue; |
331 |
continue; |
283 |
} |
332 |
} |
284 |
ether_output_frame(ifp, m); |
333 |
ether_output_frame(ifp, m); |
|
|
334 |
|
285 |
} |
335 |
} |
286 |
IFNET_RUNLOCK(); |
336 |
IFNET_RUNLOCK(); |
287 |
|
337 |
|
|
|
338 |
#ifdef VIMAGE |
339 |
CURVNET_RESTORE(); |
340 |
#endif |
341 |
|
288 |
m_freem(m0); |
342 |
m_freem(m0); |
289 |
} |
343 |
} |
290 |
|
344 |
|
Lines 298-304
Link Here
|
298 |
aoenet_maxsize(struct ifnet *ifp) |
352 |
aoenet_maxsize(struct ifnet *ifp) |
299 |
{ |
353 |
{ |
300 |
/* max payload size of packet based on interface mtu setting */ |
354 |
/* max payload size of packet based on interface mtu setting */ |
|
|
355 |
#if __FreeBSD_version >= 1100030 |
356 |
return ((ifp->if_mtu - AOEHDRSZ) & ~(DEV_BSIZE - 1)); |
357 |
#else |
301 |
return ((ifp->if_data.ifi_mtu - AOEHDRSZ) & ~(DEV_BSIZE - 1)); |
358 |
return ((ifp->if_data.ifi_mtu - AOEHDRSZ) & ~(DEV_BSIZE - 1)); |
|
|
359 |
#endif |
302 |
} |
360 |
} |
303 |
|
361 |
|
304 |
|
362 |
|
Lines 362-368
Link Here
|
362 |
*/ |
420 |
*/ |
363 |
if ((m->m_flags & M_PKTHDR) == 0) { |
421 |
if ((m->m_flags & M_PKTHDR) == 0) { |
364 |
if_printf(ifp, "discard frame w/o packet header\n"); |
422 |
if_printf(ifp, "discard frame w/o packet header\n"); |
|
|
423 |
#if __FreeBSD_version >= 1100036 |
424 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
425 |
#else |
365 |
ifp->if_ierrors++; |
426 |
ifp->if_ierrors++; |
|
|
427 |
#endif |
366 |
m_freem(m); |
428 |
m_freem(m); |
367 |
return; |
429 |
return; |
368 |
} |
430 |
} |
Lines 371-377
Link Here
|
371 |
if_printf(ifp, "discard frame w/o leading ethernet " |
433 |
if_printf(ifp, "discard frame w/o leading ethernet " |
372 |
"header (len %u pkt len %u)\n", |
434 |
"header (len %u pkt len %u)\n", |
373 |
m->m_len, m->m_pkthdr.len); |
435 |
m->m_len, m->m_pkthdr.len); |
|
|
436 |
#if __FreeBSD_version >= 1100036 |
437 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
438 |
#else |
374 |
ifp->if_ierrors++; |
439 |
ifp->if_ierrors++; |
|
|
440 |
#endif |
375 |
m_freem(m); |
441 |
m_freem(m); |
376 |
return; |
442 |
return; |
377 |
} |
443 |
} |
Lines 384-400
Link Here
|
384 |
if (m->m_pkthdr.len > |
450 |
if (m->m_pkthdr.len > |
385 |
ETHER_MAX_FRAME(ifp, etype, m->m_flags & M_HASFCS)) { |
451 |
ETHER_MAX_FRAME(ifp, etype, m->m_flags & M_HASFCS)) { |
386 |
if_printf(ifp, "discard oversize frame " |
452 |
if_printf(ifp, "discard oversize frame " |
387 |
"(ether type %x flags %x len %u > max %lu)\n", |
453 |
"(ether type %x flags %x len %u > max %u)\n", |
388 |
etype, m->m_flags, m->m_pkthdr.len, |
454 |
etype, m->m_flags, m->m_pkthdr.len, |
389 |
ETHER_MAX_FRAME(ifp, etype, |
455 |
(int) ETHER_MAX_FRAME(ifp, etype, |
390 |
m->m_flags & M_HASFCS)); |
456 |
m->m_flags & M_HASFCS)); |
|
|
457 |
#if __FreeBSD_version >= 1100036 |
458 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
459 |
#else |
391 |
ifp->if_ierrors++; |
460 |
ifp->if_ierrors++; |
|
|
461 |
#endif |
392 |
m_freem(m); |
462 |
m_freem(m); |
393 |
return; |
463 |
return; |
394 |
} |
464 |
} |
395 |
if (m->m_pkthdr.rcvif == NULL) { |
465 |
if (m->m_pkthdr.rcvif == NULL) { |
396 |
if_printf(ifp, "discard frame w/o interface pointer\n"); |
466 |
if_printf(ifp, "discard frame w/o interface pointer\n"); |
|
|
467 |
#if __FreeBSD_version >= 1100036 |
468 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
469 |
#else |
397 |
ifp->if_ierrors++; |
470 |
ifp->if_ierrors++; |
|
|
471 |
#endif |
398 |
m_freem(m); |
472 |
m_freem(m); |
399 |
return; |
473 |
return; |
400 |
} |
474 |
} |
Lines 417-423
Link Here
|
417 |
m->m_flags &= ~M_HASFCS; |
491 |
m->m_flags &= ~M_HASFCS; |
418 |
} |
492 |
} |
419 |
|
493 |
|
|
|
494 |
#if __FreeBSD_version >= 1100036 |
495 |
if_inc_counter(ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len); |
496 |
#else |
420 |
ifp->if_ibytes += m->m_pkthdr.len; |
497 |
ifp->if_ibytes += m->m_pkthdr.len; |
|
|
498 |
#endif |
421 |
|
499 |
|
422 |
if (ETHER_IS_MULTICAST(eh->ether_dhost)) { |
500 |
if (ETHER_IS_MULTICAST(eh->ether_dhost)) { |
423 |
if (bcmp(etherbroadcastaddr, eh->ether_dhost, |
501 |
if (bcmp(etherbroadcastaddr, eh->ether_dhost, |
Lines 427-433
Link Here
|
427 |
m->m_flags |= M_MCAST; |
505 |
m->m_flags |= M_MCAST; |
428 |
} |
506 |
} |
429 |
if (m->m_flags & (M_BCAST|M_MCAST)) |
507 |
if (m->m_flags & (M_BCAST|M_MCAST)) |
|
|
508 |
#if __FreeBSD_version >= 1100036 |
509 |
if_inc_counter(ifp, IFCOUNTER_IMCASTS, 1); |
510 |
#else |
430 |
ifp->if_imcasts++; |
511 |
ifp->if_imcasts++; |
|
|
512 |
#endif |
431 |
|
513 |
|
432 |
aoeintr(m); |
514 |
aoeintr(m); |
433 |
/* netisr_dispatch(NETISR_AOE, m); */ |
515 |
/* netisr_dispatch(NETISR_AOE, m); */ |
Lines 440-452
Link Here
|
440 |
int error; |
522 |
int error; |
441 |
#ifdef FORCE_NETWORK_HOOK |
523 |
#ifdef FORCE_NETWORK_HOOK |
442 |
struct ifnet *ifp; |
524 |
struct ifnet *ifp; |
443 |
#endif |
525 |
#endif |
444 |
|
526 |
|
445 |
error = sysctl_handle_string(oidp, arg1, arg2, req); |
527 |
error = sysctl_handle_string(oidp, arg1, arg2, req); |
446 |
|
528 |
|
447 |
#ifdef FORCE_NETWORK_HOOK |
529 |
#ifdef FORCE_NETWORK_HOOK |
448 |
IFNET_RLOCK(); |
530 |
IFNET_RLOCK(); |
449 |
TAILQ_FOREACH(ifp, &ifnet, if_link) { |
531 |
TAILQ_FOREACH(ifp, &_aoenet_ifnet, if_link) { |
450 |
if (!is_aoe_netif(ifp)) { |
532 |
if (!is_aoe_netif(ifp)) { |
451 |
if (ifp->if_input == aoe_ether_input) |
533 |
if (ifp->if_input == aoe_ether_input) |
452 |
ifp->if_input = old_ether_input; |
534 |
ifp->if_input = old_ether_input; |
Lines 471-478
Link Here
|
471 |
struct ifnet *ifp; |
553 |
struct ifnet *ifp; |
472 |
|
554 |
|
473 |
IFNET_RLOCK(); |
555 |
IFNET_RLOCK(); |
474 |
TAILQ_FOREACH(ifp, &ifnet, if_link) { |
556 |
TAILQ_FOREACH(ifp, &_aoenet_ifnet, if_link) { |
|
|
557 |
#if __FreeBSD_version >= 1100030 |
558 |
switch (ifp->if_type) { |
559 |
#else |
475 |
switch (ifp->if_data.ifi_type) { |
560 |
switch (ifp->if_data.ifi_type) { |
|
|
561 |
#endif |
476 |
case IFT_ETHER: |
562 |
case IFT_ETHER: |
477 |
case IFT_FASTETHER: |
563 |
case IFT_FASTETHER: |
478 |
case IFT_GIGABITETHERNET: |
564 |
case IFT_GIGABITETHERNET: |
Lines 480-489
Link Here
|
480 |
default: |
566 |
default: |
481 |
continue; |
567 |
continue; |
482 |
} |
568 |
} |
483 |
if (old_ether_input == NULL) |
569 |
if (old_ether_input == NULL) { |
484 |
old_ether_input = ifp->if_input; |
570 |
old_ether_input = ifp->if_input; |
|
|
571 |
} |
485 |
else if (old_ether_input != ifp->if_input) |
572 |
else if (old_ether_input != ifp->if_input) |
486 |
IPRINTK("ifp->if_input != ether_input\n"); |
573 |
IPRINTK("ifp->if_input != ether_input, %s ignored\n", ifp->if_xname); |
487 |
} |
574 |
} |
488 |
IFNET_RUNLOCK(); |
575 |
IFNET_RUNLOCK(); |
489 |
#else |
576 |
#else |
Lines 500-507
Link Here
|
500 |
struct ifnet *ifp; |
587 |
struct ifnet *ifp; |
501 |
|
588 |
|
502 |
IFNET_RLOCK(); |
589 |
IFNET_RLOCK(); |
503 |
TAILQ_FOREACH(ifp, &ifnet, if_link) { |
590 |
TAILQ_FOREACH(ifp, &_aoenet_ifnet, if_link) { |
|
|
591 |
#if __FreeBSD_version >= 1100030 |
592 |
switch (ifp->if_type) { |
593 |
#else |
504 |
switch (ifp->if_data.ifi_type) { |
594 |
switch (ifp->if_data.ifi_type) { |
|
|
595 |
#endif |
505 |
case IFT_ETHER: |
596 |
case IFT_ETHER: |
506 |
case IFT_FASTETHER: |
597 |
case IFT_FASTETHER: |
507 |
case IFT_GIGABITETHERNET: |
598 |
case IFT_GIGABITETHERNET: |