public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Robin Jarry" <rjarry@redhat.com>, <dev@dpdk.org>,
	"Stephen Hemminger" <stephen@networkplumber.org>
Subject: RE: [PATCH dpdk] net/tap: add software MAC address filtering
Date: Fri, 20 Mar 2026 11:10:31 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F657AB@smartserver.smartshare.dk> (raw)
In-Reply-To: <20260319221034.703656-2-rjarry@redhat.com>

> +static inline bool
> +tap_mac_filter_match(struct rx_queue *rxq, struct rte_mbuf *mbuf)
> +{
> +	struct pmd_internals *pmd = rxq->pmd;
> +	struct rte_eth_dev_data *data;
> +	struct rte_ether_addr *dst;
> +	uint32_t i;
> +
> +	if (!pmd->macfilter)
> +		return true;
> +
> +	data = pmd->dev->data;
> +	if (data->promiscuous)
> +		return true;
> +
> +	dst = rte_pktmbuf_mtod(mbuf, struct rte_ether_addr *);
> +
> +	if (rte_is_broadcast_ether_addr(dst))
> +		return true;
> +
> +	if (rte_is_multicast_ether_addr(dst)) {
> +		if (data->all_multicast)
> +			return true;
> +		for (i = 0; i < pmd->nb_mc_addrs; i++) {
> +			if (rte_is_same_ether_addr(dst, &pmd->mc_addrs[i]))
> +				return true;
> +		}
> +		return false;
> +	}
> +
> +	for (i = 0; i < TAP_MAX_MAC_ADDRS; i++) {
> +		if (rte_is_zero_ether_addr(&data->mac_addrs[i]))
> +			continue;
> +		if (rte_is_same_ether_addr(dst, &data->mac_addrs[i]))
> +			return true;
> +	}
> +	return false;
> +}

Performance optimization; the vast majority of packets are unicast:

if (likely(rte_is_unicast_ether_addr(dst)) {
    if (unlikely(rte_is_zero_ether_addr(dst)))
        return false; /* Invalid destination address in packet */
    /* Note: Compiler loop unrolls. */
    for (i = 0; i < TAP_MAX_MAC_ADDRS; i++) {
        if (rte_is_same_ether_addr(dst, &data->mac_addrs[i]))
            return true;
    }
}

if (data->all_multicast)
    return true;

for (i = 0; i < pmd->nb_mc_addrs; i++) {
    if (rte_is_same_ether_addr(dst, &pmd->mc_addrs[i]))
        return true;
}

if (rte_is_broadcast_ether_addr(dst))
    return true;

return false;

Also, all the variables and function parameters could be "const"; although I don't know if it makes any practical difference.


>  static int
> -tap_set_mc_addr_list(struct rte_eth_dev *dev __rte_unused,
> -		     struct rte_ether_addr *mc_addr_set __rte_unused,
> -		     uint32_t nb_mc_addr __rte_unused)
> +tap_set_mc_addr_list(struct rte_eth_dev *dev,
> +		     struct rte_ether_addr *mc_addr_set,
> +		     uint32_t nb_mc_addr)
>  {
> -	/*
> -	 * Nothing to do actually: the tap has no filtering whatsoever,
> every
> -	 * packet is received.
> -	 */
> +	struct pmd_internals *pmd = dev->data->dev_private;
> +
> +	if (nb_mc_addr == 0) {
> +		rte_free(pmd->mc_addrs);
> +		pmd->mc_addrs = NULL;
> +		pmd->nb_mc_addrs = 0;
> +		return 0;
> +	}
> +
> +	pmd->mc_addrs = rte_realloc(pmd->mc_addrs,
> +				    nb_mc_addr * sizeof(*pmd->mc_addrs), 0);
> +	if (pmd->mc_addrs == NULL) {
> +		pmd->nb_mc_addrs = 0;
> +		return -ENOMEM;
> +	}
> +
> +	memcpy(pmd->mc_addrs, mc_addr_set,
> +	       nb_mc_addr * sizeof(*pmd->mc_addrs));
> +	pmd->nb_mc_addrs = nb_mc_addr;
> +
>  	return 0;
>  }

This is not thread safe.
If it needs to be thread safe, you must ensure that tap_mac_filter_match() - running on another lcore - is done using the mc_addrs array before you free it here.


  parent reply	other threads:[~2026-03-20 10:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19 22:10 [PATCH dpdk] net/tap: add software MAC address filtering Robin Jarry
2026-03-19 22:43 ` Stephen Hemminger
2026-03-20  8:26   ` Robin Jarry
2026-03-20 10:10 ` Morten Brørup [this message]
2026-03-20 16:45 ` [PATCH dpdk v2] " Robin Jarry
2026-03-21  2:58   ` Stephen Hemminger
2026-03-21  5:48     ` Morten Brørup
2026-03-21 14:48 ` [PATCH dpdk v3] " Robin Jarry
2026-03-21 17:06   ` Stephen Hemminger
2026-03-21 23:20   ` Stephen Hemminger
2026-03-23  8:42 ` [PATCH dpdk v4] " Robin Jarry
2026-03-23 18:52   ` Stephen Hemminger
2026-03-24 19:09 ` [PATCH dpdk v5] " Robin Jarry
2026-03-25 16:40   ` Stephen Hemminger
2026-03-26  9:15     ` Robin Jarry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98CBD80474FA8B44BF855DF32C47DC35F657AB@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=dev@dpdk.org \
    --cc=rjarry@redhat.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox