All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/pcap: Generate unique MAC addresses for interfaces
@ 2018-09-03 14:08 Cian Ferriter
  2018-09-03 15:00 ` Ferruh Yigit
  0 siblings, 1 reply; 2+ messages in thread
From: Cian Ferriter @ 2018-09-03 14:08 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Cian Ferriter

The MAC addresses are generated in the same manner as in the TAP PMD,
where the address is based on the number of PCAP ports created.

Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>
---
 drivers/net/pcap/rte_eth_pcap.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index e8810a1..ced9cd9 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -417,11 +417,17 @@ struct pmd_devargs {
 static int
 eth_dev_start(struct rte_eth_dev *dev)
 {
+	static int iface_idx;
 	unsigned int i;
 	struct pmd_internals *internals = dev->data->dev_private;
 	struct pcap_tx_queue *tx;
 	struct pcap_rx_queue *rx;
 
+	/* Interface MAC = 00:70:63:61:70:<iface_idx> */
+	memcpy((char *)dev->data->mac_addrs->addr_bytes, "\0pcap",
+		ETHER_ADDR_LEN);
+	dev->data->mac_addrs->addr_bytes[ETHER_ADDR_LEN - 1] = iface_idx++;
+
 	/* Special iface case. Single pcap is open and shared between tx/rx. */
 	if (internals->single_iface) {
 		tx = &internals->tx_queue[0];
-- 
1.7.0.7

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/pcap: Generate unique MAC addresses for interfaces
  2018-09-03 14:08 [PATCH] net/pcap: Generate unique MAC addresses for interfaces Cian Ferriter
@ 2018-09-03 15:00 ` Ferruh Yigit
  0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2018-09-03 15:00 UTC (permalink / raw)
  To: Cian Ferriter; +Cc: dev

On 9/3/2018 3:08 PM, Cian Ferriter wrote:
> The MAC addresses are generated in the same manner as in the TAP PMD,
> where the address is based on the number of PCAP ports created.
> 
> Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>
> ---
>  drivers/net/pcap/rte_eth_pcap.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
> index e8810a1..ced9cd9 100644
> --- a/drivers/net/pcap/rte_eth_pcap.c
> +++ b/drivers/net/pcap/rte_eth_pcap.c
> @@ -417,11 +417,17 @@ struct pmd_devargs {
>  static int
>  eth_dev_start(struct rte_eth_dev *dev)
>  {
> +	static int iface_idx;
>  	unsigned int i;
>  	struct pmd_internals *internals = dev->data->dev_private;
>  	struct pcap_tx_queue *tx;
>  	struct pcap_rx_queue *rx;
>  
> +	/* Interface MAC = 00:70:63:61:70:<iface_idx> */
> +	memcpy((char *)dev->data->mac_addrs->addr_bytes, "\0pcap",
> +		ETHER_ADDR_LEN);
> +	dev->data->mac_addrs->addr_bytes[ETHER_ADDR_LEN - 1] = iface_idx++;

This won't work as you expected, you will end up having same MAC for pcap
interfaces because data->mac_addrs points to same memory for all instances.

It is better to have "struct ether_addr" in "pmd_internals" and set the MAC
address for that interface in "pmd_init_internals()".
It can be good to set fixed part of the MAC as macro and add static variable
(iface_idx) where other global variables are declared.

And it would be nice if you can add why you need this, what is enabled by having
this update, in commit log.

Thanks,
ferruh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-03 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 14:08 [PATCH] net/pcap: Generate unique MAC addresses for interfaces Cian Ferriter
2018-09-03 15:00 ` Ferruh Yigit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.