From patchwork Wed May 15 22:19:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 53452 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 01CF15F20; Thu, 16 May 2019 00:20:07 +0200 (CEST) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by dpdk.org (Postfix) with ESMTP id C66AF5B40 for ; Thu, 16 May 2019 00:20:03 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id g9so533652plm.6 for ; Wed, 15 May 2019 15:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jbwl7Sd8my/F397rS6pt6XtuQsuPaXlJF2bq508V2S4=; b=p/rwcphDQOMRGMFxhSJR0g7DqHqUnZJkI+gZIcKoxK1CFt2Tp+mPmC27yGtraPsb3q 8zvRShXDVJiNqbrEtKscCxRtO/XVbcJzXUS6TrM6gfs+4gpmH1fMrBLSGPeaESj0Xvj3 WSoIit6TqdeD9pElQ5XN1+FH4wlJYduCNsT1+8Lp1hNjOAD6d/YvUSqL918OAsyDWxTD gereixDtoT/XFqwR9IihGluIob2boeV95OPARpFvcguWw9atWfXnfhhW2m9qxY7E3+9/ jGMwk/ssyZ1icD7rUG2o2Yha2SvieoZvZreT3dXQOkPwxVOH/yM+MEntgm8NPzNxnHab 2a7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jbwl7Sd8my/F397rS6pt6XtuQsuPaXlJF2bq508V2S4=; b=afRnahWLS9RdP5PfikIRKY6XUokyU5Ixn0UdMR0wmiD7c5w6Mg4v53mXPvmwHdsjKt MKEF2RZ31fWdsd8C3e2UvpRQXBqvIB8RlYyjlXJ//d4S/MTZ97jdMb68yIP7b7L89amQ hiDyxJLOYSIbthGKXkAS2QdSks10yZn2/d9Ene2vjPOR0MEzZPH2WtYmzJXOj+OBz9SD 6+MYROYxWGfV5nnMMgQhlmrgPVrjpI154aqhANVwBoZNdoTo+1gLQjjijvyFNkigMgds 2GzxzsVGrG8dWQJSey78ZtmnU/OO08RrZjh3sQ2LZGJBqmpr6QQh7CCutF1OA798X6v9 x+4Q== X-Gm-Message-State: APjAAAUaL1Ph0ep9N3RT+wSxo9YhGLk9M3mkSE/zrJLkwxJnY1PhGp4p 214fdYsXAn3jAhXoq2kMYME2EfUiusI= X-Google-Smtp-Source: APXvYqyvGemc6HjmlGn/9ppL0NsHxZ6vg0doPObIcJKSD+Ul5BKLRcqAE/G19FR6PsPt6QAUzFYzww== X-Received: by 2002:a17:902:7406:: with SMTP id g6mr44872040pll.328.1557958802492; Wed, 15 May 2019 15:20:02 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id d5sm3549964pgb.33.2019.05.15.15.20.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 May 2019 15:20:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Wed, 15 May 2019 15:19:50 -0700 Message-Id: <20190515221952.21959-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190515221952.21959-1-stephen@networkplumber.org> References: <20190515221952.21959-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [RFC 2/4] net/ether: add eth_unformat_addr 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" Make a function that coresponds with eth_aton_r which can be used to convert string to ether_addr. This also allows rte_ethdev to no longer depend on the cmdline library. Signed-off-by: Stephen Hemminger --- lib/librte_net/rte_ether.c | 12 ++++++++++++ lib/librte_net/rte_ether.h | 14 ++++++++++++++ lib/librte_net/rte_net_version.map | 1 + 3 files changed, 27 insertions(+) diff --git a/lib/librte_net/rte_ether.c b/lib/librte_net/rte_ether.c index d4b41f122a16..ca7c841db197 100644 --- a/lib/librte_net/rte_ether.c +++ b/lib/librte_net/rte_ether.c @@ -27,3 +27,15 @@ ether_format_addr(char *buf, uint16_t size, eth_addr->addr_bytes[4], eth_addr->addr_bytes[5]); } + +int __rte_experimental +ether_unformat_addr(const char *str, struct ether_addr *eth_addr) +{ + return (sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + ð_addr->addr_bytes[0], + ð_addr->addr_bytes[1], + ð_addr->addr_bytes[2], + ð_addr->addr_bytes[3], + ð_addr->addr_bytes[4], + ð_addr->addr_bytes[5]) == 6) ? 0 : -1; +} diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 46d40412763c..b94e64b2195e 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -248,6 +248,20 @@ void ether_format_addr(char *buf, uint16_t size, const struct ether_addr *eth_addr); +/** + * Convert string with Ethernet address to an ether_addr. + * + * @param str + * A pointer to buffer contains the formatted MAC address. + * @param eth_addr + * A pointer to a ether_addr structure. + * @return + * 0 if successful + * -1 and sets rte_errno if invalid string + */ +int __rte_experimental +ether_unformat_addr(const char *str, struct ether_addr *eth_addr); + /** * Ethernet header: Contains the destination address, source address * and frame type. diff --git a/lib/librte_net/rte_net_version.map b/lib/librte_net/rte_net_version.map index 49d34093781c..bbf14ff1cdfa 100644 --- a/lib/librte_net/rte_net_version.map +++ b/lib/librte_net/rte_net_version.map @@ -26,4 +26,5 @@ EXPERIMENTAL { rte_net_make_rarp_packet; rte_net_skip_ip6_ext; + eth_unformat_addr; };