From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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: , X-List-Received-Date: Fri, 27 Feb 2015 13:42:59 -0000 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(-) diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_e= th_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[] =3D { @@ -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 =3D dev->data->dev_private; + + if (internals->if_name && (internals->if_fd !=3D -1)) { + /* get link status, speed and duplex from the underlying in= terface */ + + strncpy(ifr.ifr_name, internals->if_name, sizeof(ifr.ifr_na= me)-1); + ifr.ifr_name[sizeof(ifr.ifr_name)-1] =3D 0; + if (!ioctl(internals->if_fd, SIOCGIFFLAGS, &ifr)) + dev->data->dev_link.link_status =3D (ifr.ifr_flags = & IFF_UP) ? 1 : 0; + + cmd.cmd =3D ETHTOOL_GSET; + ifr.ifr_data =3D (void *)&cmd; + if (!ioctl(internals->if_fd, SIOCETHTOOL, &ifr)) { + dev->data->dev_link.link_speed =3D ethtool_cmd_spee= d(&cmd); + dev->data->dev_link.link_duplex =3D + cmd.duplex ? ETH_LINK_FULL_DUPLEX : ETH_LIN= K_HALF_DUPLEX; + } + } return 0; } @@ -736,11 +763,24 @@ rte_pmd_init_internals(const char *name, const unsign= ed nb_rx_queues, (*internals)->nb_rx_queues =3D nb_rx_queues; (*internals)->nb_tx_queues =3D nb_tx_queues; - if (pair =3D=3D NULL) + if (pair =3D=3D NULL) { (*internals)->if_index =3D 0; - else + } else { + /* use real inteface mac addr, save name and fd for eth_lin= k_update */ (*internals)->if_index =3D if_nametoindex(pair->value); - + (*internals)->if_name =3D strdup(pair->value); + (*internals)->if_fd =3D socket(AF_INET, SOCK_DGRAM, 0); + if ((*internals)->if_fd !=3D -1) { + struct ifreq ifr; + strncpy(ifr.ifr_name, pair->value, sizeof(ifr.ifr_n= ame)-1); + ifr.ifr_name[sizeof(ifr.ifr_name)-1] =3D 0; + if (!ioctl((*internals)->if_fd, SIOCGIFHWADDR, &ifr= )) { + data->mac_addrs =3D 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 =3D numa_node; data->dev_private =3D *internals; @@ -749,7 +789,8 @@ rte_pmd_init_internals(const char *name, const unsigned= nb_rx_queues, data->nb_rx_queues =3D (uint16_t)nb_rx_queues; data->nb_tx_queues =3D (uint16_t)nb_tx_queues; data->dev_link =3D pmd_link; - data->mac_addrs =3D ð_addr; + if (data->mac_addrs =3D=3D NULL) + data->mac_addrs =3D ð_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 =3D pci_dev; (*eth_dev)->driver =3D &rte_pcap_pmd; + eth_link_update((*eth_dev), 0); + return 0; error: if (data) -- 1.9.1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D