From: Cian Ferriter <cian.ferriter@intel.com>
To: Ferruh Yigit <ferruh.yigit@intel.com>
Cc: dev@dpdk.org, Cian Ferriter <cian.ferriter@intel.com>
Subject: [dpdk-dev] [PATCH v2] net/pcap: Generate unique MAC addresses for interfaces
Date: Mon, 10 Sep 2018 16:52:17 +0100 [thread overview]
Message-ID: <1536594737-4341-1-git-send-email-cian.ferriter@intel.com> (raw)
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 = ð_addr;
+ data->mac_addrs = &(*internals)->eth_addr;
/*
* NOTE: we'll replace the data element, of originally allocated
--
2.7.4
next reply other threads:[~2018-09-10 15:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-10 15:52 Cian Ferriter [this message]
2018-09-11 11:36 ` Ferruh Yigit
2018-09-21 0:39 ` Ferruh Yigit
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=1536594737-4341-1-git-send-email-cian.ferriter@intel.com \
--to=cian.ferriter@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).