[PATCH v3 12/18] net/r8169: implement Tx path
Stephen Hemminger
stephen at networkplumber.org
Wed Oct 23 07:22:53 CEST 2024
On Wed, 23 Oct 2024 11:33:22 +0800
Howard Wang <howard_wang at realsil.com.cn> wrote:
> +static uint32_t
> +rtl8125_get_patch_pad_len(struct rte_mbuf *tx_pkt)
> +{
> + uint16_t dest_port = 0;
> + uint32_t pad_len = 0;
> + int udp_hdr_len = 8;
> + int trans_data_len, l4_offset;
> +
> + if (!(tx_pkt->l4_len && (tx_pkt->data_len < 175)))
> + goto no_padding;
> +
> + l4_offset = tx_pkt->l2_len + tx_pkt->l3_len;
> + trans_data_len = tx_pkt->data_len - l4_offset;
> +
> + if (trans_data_len > 3 && trans_data_len < MIN_PATCH_LENGTH) {
> + rte_memcpy(&dest_port, rte_pktmbuf_mtod(tx_pkt,
> + struct rte_ether_hdr *) + l4_offset + 2, 2);
> + dest_port = ntohs(dest_port);
A couple things here.
1. Use the function rte_pktmbuf_mtod_offset to pick up the header.
2. Don't use hard coded offset from that use a local pointer to the type
3. Don't hard code the size of uint16.
4. Don't use rte_memcpy() for trivially small fixed size objects.
5. Avoid useless initializations (like dest_port)
6. Don't hard code size of UDP header.
More information about the dev
mailing list