diff mbox series

[v2] net/pcap: Generate unique MAC addresses for interfaces

Message ID 1536594737-4341-1-git-send-email-cian.ferriter@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series [v2] net/pcap: Generate unique MAC addresses for interfaces | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Cian Ferriter Sept. 10, 2018, 3:52 p.m. UTC
The MAC addresses are generated in a similar manner as in the TAP PMD,
where the address is based on the number of PCAP ports created.

This is useful for the purposes of debugging DPDK applications using
PCAP devices instead of real devices where multiple devices should still
have unique MAC addresses. This method was chosen over randomly
assigning MAC addresses to make the creation of pcaps, specifically
matching the destination ethernet address field to an interface, easier.

Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>
---
v1->v2:
* Add a "struct ether_addr" to "pmd_internals" and set MAC address in
  "pmd_init_internals()"
* Set the fixed part of the MAC address more explicitly.
* Add the static "iface_idx" globally.

 drivers/net/pcap/rte_eth_pcap.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Ferruh Yigit Sept. 11, 2018, 11:36 a.m. UTC | #1
On 9/10/2018 4:52 PM, Cian Ferriter wrote:
> The MAC addresses are generated in a similar manner as in the TAP PMD,
> where the address is based on the number of PCAP ports created.
> 
> This is useful for the purposes of debugging DPDK applications using
> PCAP devices instead of real devices where multiple devices should still
> have unique MAC addresses. This method was chosen over randomly
> assigning MAC addresses to make the creation of pcaps, specifically
> matching the destination ethernet address field to an interface, easier.
> 
> Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
Ferruh Yigit Sept. 21, 2018, 12:39 a.m. UTC | #2
On 9/11/2018 12:36 PM, Ferruh Yigit wrote:
> On 9/10/2018 4:52 PM, Cian Ferriter wrote:
>> The MAC addresses are generated in a similar manner as in the TAP PMD,
>> where the address is based on the number of PCAP ports created.
>>
>> This is useful for the purposes of debugging DPDK applications using
>> PCAP devices instead of real devices where multiple devices should still
>> have unique MAC addresses. This method was chosen over randomly
>> assigning MAC addresses to make the creation of pcaps, specifically
>> matching the destination ethernet address field to an interface, easier.
>>
>> Signed-off-by: Cian Ferriter <cian.ferriter@intel.com>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/master, thanks.
diff mbox series

Patch

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index e8810a1..ec19d37 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -39,6 +39,7 @@  static unsigned char tx_pcap_data[RTE_ETH_PCAP_SNAPLEN];
 static struct timeval start_time;
 static uint64_t start_cycles;
 static uint64_t hz;
+static uint8_t iface_idx;
 
 struct queue_stat {
 	volatile unsigned long pkts;
@@ -66,6 +67,7 @@  struct pcap_tx_queue {
 struct pmd_internals {
 	struct pcap_rx_queue rx_queue[RTE_PMD_PCAP_MAX_QUEUES];
 	struct pcap_tx_queue tx_queue[RTE_PMD_PCAP_MAX_QUEUES];
+	struct ether_addr eth_addr;
 	int if_index;
 	int single_iface;
 };
@@ -90,10 +92,6 @@  static const char *valid_arguments[] = {
 	NULL
 };
 
-static struct ether_addr eth_addr = {
-	.addr_bytes = { 0, 0, 0, 0x1, 0x2, 0x3 }
-};
-
 static struct rte_eth_link pmd_link = {
 		.link_speed = ETH_SPEED_NUM_10G,
 		.link_duplex = ETH_LINK_FULL_DUPLEX,
@@ -889,11 +887,19 @@  pmd_init_internals(struct rte_vdev_device *vdev,
 	 * - and point eth_dev structure to new eth_dev_data structure
 	 */
 	*internals = (*eth_dev)->data->dev_private;
+	/*
+	 * Interface MAC = 02:70:63:61:70:<iface_idx>
+	 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
+	 * where the middle 4 characters are converted to hex.
+	 */
+	(*internals)->eth_addr = (struct ether_addr) {
+		.addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
+	};
 	data = (*eth_dev)->data;
 	data->nb_rx_queues = (uint16_t)nb_rx_queues;
 	data->nb_tx_queues = (uint16_t)nb_tx_queues;
 	data->dev_link = pmd_link;
-	data->mac_addrs = &eth_addr;
+	data->mac_addrs = &(*internals)->eth_addr;
 
 	/*
 	 * NOTE: we'll replace the data element, of originally allocated