[PATCH v20 06/25] net/pcap: avoid using rte_malloc and rte_memcpy

Bruce Richardson bruce.richardson at intel.com
Mon Mar 16 12:38:34 CET 2026


On Tue, Mar 10, 2026 at 09:09:44AM -0700, Stephen Hemminger wrote:
> No need to use rte_malloc or rte_memcpy in the short
> code to get MAC address.
> 
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---

Acked-by: Bruce Richardson <bruce.richardson at intel.com>

>  drivers/net/pcap/pcap_ethdev.c        |  3 ++-
>  drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
>  drivers/net/pcap/pcap_osdep_linux.c   |  6 +++---
>  3 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
> index fbd1021c39..806451dc99 100644
> --- a/drivers/net/pcap/pcap_ethdev.c
> +++ b/drivers/net/pcap/pcap_ethdev.c
> @@ -6,6 +6,7 @@
>  
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <string.h>
>  #include <time.h>
>  #include <inttypes.h>
>  #include <errno.h>
> @@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
>  		return -1;
>  
>  	PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
> -	rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
> +	memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
>  	eth_dev->data->mac_addrs = mac_addrs;
>  	return 0;
>  }
> diff --git a/drivers/net/pcap/pcap_osdep_freebsd.c b/drivers/net/pcap/pcap_osdep_freebsd.c
> index 20556b3e92..0185665f0b 100644
> --- a/drivers/net/pcap/pcap_osdep_freebsd.c
> +++ b/drivers/net/pcap/pcap_osdep_freebsd.c
> @@ -4,13 +4,11 @@
>   * All rights reserved.
>   */
>  
> +#include <string.h>
>  #include <net/if.h>
>  #include <net/if_dl.h>
>  #include <sys/sysctl.h>
>  
> -#include <rte_malloc.h>
> -#include <rte_memcpy.h>
> -
>  #include "pcap_osdep.h"
>  
>  int
> @@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
>  	if (len == 0)
>  		return -1;
>  
> -	buf = rte_malloc(NULL, len, 0);
> +	buf = malloc(len);
>  	if (!buf)
>  		return -1;
>  

It's a pity there is no defined max length here that we can use a static
buffer, but since there isn't using malloc rather than rte_malloc is best.

>  	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
> -		rte_free(buf);
> +		free(buf);
>  		return -1;
>  	}
>  	ifm = (struct if_msghdr *)buf;
>  	sdl = (struct sockaddr_dl *)(ifm + 1);
>  
> -	rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
> +	memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
>  
> -	rte_free(buf);
> +	free(buf);
>  	return 0;
>  }
> diff --git a/drivers/net/pcap/pcap_osdep_linux.c b/drivers/net/pcap/pcap_osdep_linux.c
> index 97033f57c5..df976417cb 100644
> --- a/drivers/net/pcap/pcap_osdep_linux.c
> +++ b/drivers/net/pcap/pcap_osdep_linux.c
> @@ -4,12 +4,12 @@
>   * All rights reserved.
>   */
>  
> +#include <string.h>
> +#include <unistd.h>
>  #include <net/if.h>
>  #include <sys/ioctl.h>
>  #include <sys/socket.h>
> -#include <unistd.h>
>  
> -#include <rte_memcpy.h>
>  #include <rte_string_fns.h>
>  
>  #include "pcap_osdep.h"
> @@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
>  		return -1;
>  	}
>  
> -	rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
> +	memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
>  
>  	close(if_fd);
>  	return 0;
> -- 
> 2.51.0
> 


More information about the dev mailing list