DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] net/pcap: Generate unique MAC addresses for interfaces
@ 2018-09-10 15:52 Cian Ferriter
  2018-09-11 11:36 ` Ferruh Yigit
  0 siblings, 1 reply; 3+ messages in thread
From: Cian Ferriter @ 2018-09-10 15:52 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Cian Ferriter

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(-)

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
-- 
2.7.4

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

end of thread, other threads:[~2018-09-21  0:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-10 15:52 [dpdk-dev] [PATCH v2] net/pcap: Generate unique MAC addresses for interfaces Cian Ferriter
2018-09-11 11:36 ` Ferruh Yigit
2018-09-21  0:39   ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).