From patchwork Mon Sep 10 15:52:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cian Ferriter X-Patchwork-Id: 44518 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4815A378B; Mon, 10 Sep 2018 17:52:27 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 460B01041 for ; Mon, 10 Sep 2018 17:52:25 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 08:52:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,356,1531810800"; d="scan'208";a="84673082" Received: from silpixa00393943.ir.intel.com ([10.237.222.21]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2018 08:52:23 -0700 From: Cian Ferriter To: Ferruh Yigit Cc: dev@dpdk.org, Cian Ferriter Date: Mon, 10 Sep 2018 16:52:17 +0100 Message-Id: <1536594737-4341-1-git-send-email-cian.ferriter@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH v2] net/pcap: Generate unique MAC addresses for interfaces X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Ferruh Yigit --- 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: + * 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