From patchwork Fri Feb 27 13:42:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Aho X-Patchwork-Id: 3791 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 81BA65A73; Fri, 27 Feb 2015 14:43:00 +0100 (CET) Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0088.outbound.protection.outlook.com [157.55.234.88]) by dpdk.org (Postfix) with ESMTP id D650D959 for ; Fri, 27 Feb 2015 14:42:58 +0100 (CET) Received: from DB4PR04CA0032.eurprd04.prod.outlook.com (25.160.41.42) by HE1PR04MB1100.eurprd04.prod.outlook.com (25.162.26.24) with Microsoft SMTP Server (TLS) id 15.1.93.16; Fri, 27 Feb 2015 13:42:57 +0000 Received: from AM1FFO11FD053.protection.gbl (2a01:111:f400:7e00::117) by DB4PR04CA0032.outlook.office365.com (2a01:111:e400:9852::42) with Microsoft SMTP Server (TLS) id 15.1.99.14 via Frontend Transport; Fri, 27 Feb 2015 13:42:56 +0000 Received: from usnvwwmspedge01.tellabs-west.tellabsinc.net (204.154.129.192) by AM1FFO11FD053.mail.protection.outlook.com (10.174.65.72) with Microsoft SMTP Server (TLS) id 15.1.99.6 via Frontend Transport; Fri, 27 Feb 2015 13:42:56 +0000 Received: from usnvwwmspht02.tellabs-west.tellabsinc.net (172.23.211.70) by usnvwwmspedge01.tellabs-west.tellabsinc.net (204.154.131.192) with Microsoft SMTP Server (TLS) id 8.3.377.0; Fri, 27 Feb 2015 07:41:42 -0600 Received: from T430.tellabs-east.tellabsinc.net (172.23.229.50) by usnvwwmspht02.tellabs-west.tellabsinc.net (172.23.211.70) with Microsoft SMTP Server id 8.3.298.1; Fri, 27 Feb 2015 07:42:54 -0600 From: Tero Aho To: Date: Fri, 27 Feb 2015 15:42:38 +0200 Message-ID: <1425044560-23397-2-git-send-email-tero.aho@coriant.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425044560-23397-1-git-send-email-tero.aho@coriant.com> References: <1425044560-23397-1-git-send-email-tero.aho@coriant.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 Received-SPF: Pass (protection.outlook.com: domain of coriant.com designates 204.154.129.192 as permitted sender) receiver=protection.outlook.com; client-ip=204.154.129.192; helo=usnvwwmspedge01.tellabs-west.tellabsinc.net; Authentication-Results: spf=pass (sender IP is 204.154.129.192) smtp.mailfrom=Tero.Aho@coriant.com; dpdk.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:204.154.129.192; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(36756003)(47776003)(77096005)(19580395003)(2950100001)(106466001)(48376002)(92566002)(110136001)(2351001)(6806004)(19580405001)(86362001)(450100001)(16796002)(87936001)(50226001)(46102003)(62966003)(50986999)(50466002)(77156002)(229853001)(33646002)(76176999)(107886001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB1100; H:usnvwwmspedge01.tellabs-west.tellabsinc.net; FPR:; SPF:Pass; MLV:sfv; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:HE1PR04MB1100; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006); SRVR:HE1PR04MB1100; X-Forefront-PRVS: 05009853EF X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB1100; X-OriginatorOrg: coriant.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2015 13:42:56.4380 (UTC) X-MS-Exchange-CrossTenant-Id: 76595477-907e-4695-988b-a6b39087332d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=76595477-907e-4695-988b-a6b39087332d; Ip=[204.154.129.192] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB1100 Subject: [dpdk-dev] [PATCH 1/3] pcap: utilize underlying real interface properties X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" These changes set pcap interface mac address to the real underlying interface address instead of the default one. Also real interface link status, speed and duplex are reported when eth_link_update is called for the pcap interface. Signed-off-by: Tero Aho --- lib/librte_pmd_pcap/rte_eth_pcap.c | 51 +++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) -- 1.9.1 ============================================================ The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any reproduction, dissemination or distribution of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. Coriant-Tellabs ============================================================ diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c index 5e94930..289af28 100644 --- a/lib/librte_pmd_pcap/rte_eth_pcap.c +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c @@ -43,6 +43,11 @@ #include #include +#include +#include +#include +#include +#include #include @@ -102,6 +107,8 @@ struct pmd_internals { unsigned nb_tx_queues; int if_index; int single_iface; + const char *if_name; + int if_fd; }; const char *valid_arguments[] = { @@ -451,6 +458,26 @@ static int eth_link_update(struct rte_eth_dev *dev __rte_unused, int wait_to_complete __rte_unused) { + struct ifreq ifr; + struct ethtool_cmd cmd; + struct pmd_internals *internals = dev->data->dev_private; + + if (internals->if_name && (internals->if_fd != -1)) { + /* get link status, speed and duplex from the underlying interface */ + + strncpy(ifr.ifr_name, internals->if_name, sizeof(ifr.ifr_name)-1); + ifr.ifr_name[sizeof(ifr.ifr_name)-1] = 0; + if (!ioctl(internals->if_fd, SIOCGIFFLAGS, &ifr)) + dev->data->dev_link.link_status = (ifr.ifr_flags & IFF_UP) ? 1 : 0; + + cmd.cmd = ETHTOOL_GSET; + ifr.ifr_data = (void *)&cmd; + if (!ioctl(internals->if_fd, SIOCETHTOOL, &ifr)) { + dev->data->dev_link.link_speed = ethtool_cmd_speed(&cmd); + dev->data->dev_link.link_duplex = + cmd.duplex ? ETH_LINK_FULL_DUPLEX : ETH_LINK_HALF_DUPLEX; + } + } return 0; } @@ -736,11 +763,24 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues, (*internals)->nb_rx_queues = nb_rx_queues; (*internals)->nb_tx_queues = nb_tx_queues; - if (pair == NULL) + if (pair == NULL) { (*internals)->if_index = 0; - else + } else { + /* use real inteface mac addr, save name and fd for eth_link_update */ (*internals)->if_index = if_nametoindex(pair->value); - + (*internals)->if_name = strdup(pair->value); + (*internals)->if_fd = socket(AF_INET, SOCK_DGRAM, 0); + if ((*internals)->if_fd != -1) { + struct ifreq ifr; + strncpy(ifr.ifr_name, pair->value, sizeof(ifr.ifr_name)-1); + ifr.ifr_name[sizeof(ifr.ifr_name)-1] = 0; + if (!ioctl((*internals)->if_fd, SIOCGIFHWADDR, &ifr)) { + data->mac_addrs = rte_zmalloc_socket(NULL, ETHER_ADDR_LEN, 0, numa_node); + if (data->mac_addrs) + rte_memcpy(data->mac_addrs, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); + } + } + } pci_dev->numa_node = numa_node; data->dev_private = *internals; @@ -749,7 +789,8 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues, 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; + if (data->mac_addrs == NULL) + data->mac_addrs = ð_addr; strncpy(data->name, (*eth_dev)->data->name, strlen((*eth_dev)->data->name)); @@ -758,6 +799,8 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues, (*eth_dev)->pci_dev = pci_dev; (*eth_dev)->driver = &rte_pcap_pmd; + eth_link_update((*eth_dev), 0); + return 0; error: if (data)