* Pad an mbuf to ensure a minimum ethernet frame size. * min_frame_size is the frame size (less CRC) to pad the mbuf to */
| 3346 | * min_frame_size is the frame size (less CRC) to pad the mbuf to |
| 3347 | */ |
| 3348 | static __noinline int |
| 3349 | iflib_ether_pad(device_t dev, struct mbuf **m_head, uint16_t min_frame_size) |
| 3350 | { |
| 3351 | /* |
| 3352 | * 18 is enough bytes to pad an ARP packet to 46 bytes, and |
| 3353 | * and ARP message is the smallest common payload I can think of |
| 3354 | */ |
| 3355 | static char pad[18]; /* just zeros */ |
| 3356 | int n; |
| 3357 | struct mbuf *new_head; |
| 3358 | |
| 3359 | if (!M_WRITABLE(*m_head)) { |
| 3360 | new_head = m_dup(*m_head, M_NOWAIT); |
| 3361 | if (new_head == NULL) { |
| 3362 | m_freem(*m_head); |
| 3363 | device_printf(dev, "cannot pad short frame, m_dup() failed"); |
| 3364 | DBG_COUNTER_INC(encap_pad_mbuf_fail); |
| 3365 | DBG_COUNTER_INC(tx_frees); |
| 3366 | return ENOMEM; |
| 3367 | } |
| 3368 | m_freem(*m_head); |
| 3369 | *m_head = new_head; |
| 3370 | } |
| 3371 | |
| 3372 | for (n = min_frame_size - (*m_head)->m_pkthdr.len; |
| 3373 | n > 0; n -= sizeof(pad)) |
| 3374 | if (!m_append(*m_head, min(n, sizeof(pad)), pad)) |
| 3375 | break; |
| 3376 | |
| 3377 | if (n > 0) { |
| 3378 | m_freem(*m_head); |
| 3379 | device_printf(dev, "cannot pad short frame\n"); |
| 3380 | DBG_COUNTER_INC(encap_pad_mbuf_fail); |
| 3381 | DBG_COUNTER_INC(tx_frees); |
| 3382 | return (ENOBUFS); |
| 3383 | } |
| 3384 | |
| 3385 | return 0; |
| 3386 | } |
| 3387 | |
| 3388 | static int |
| 3389 | iflib_encap(iflib_txq_t txq, struct mbuf **m_headp) |
no test coverage detected