From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 3937DA0096 for ; Wed, 5 Jun 2019 03:09:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 421C41B9B5; Wed, 5 Jun 2019 03:09:10 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 857141B997 for ; Wed, 5 Jun 2019 03:09:03 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id a3so3999970pgb.3 for ; Tue, 04 Jun 2019 18:09: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=iD/Dw8Anlva+fq8NJaGiCiulPCa4csyong+GQ964PtQ=; b=UESemRqBTl/0LFcCaEHD+X5uIonZ5zn1ASPMLjIzuKAxaJ7nzwGQyG5iMAYbSSvPg7 smcotuUMKwmL+0NKO3/7FWTc33Yise7yRVXVvBrqVI8JtOprSunfzakda1lkFYlClhf5 YGOCVyawak+j23VdhKLBp5GkbQO279bD1lkPjfMoK0Xph2P8cHmACOS0lNaxV04mbqkb kGhjug2H3952eXxKvXS3FO6/EjqXfha7C0IC9mjtolSiX7Qn9ll9kVTBb93ZjBoENtum HJbFXvDNphaoS6TGzNvDkBiy+xR7HRBp0rpmBvDobcerc2h3T9hUsXg3oyKzrpX9EoPA ikvw== 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=iD/Dw8Anlva+fq8NJaGiCiulPCa4csyong+GQ964PtQ=; b=RPWUkAcgUQSHGMA3rF2xizajAAluKxwCR7+zsVKF9qZ/F/GXoAxNQFH7Usb+9+cLxj uGRXmTJKDzEMLb/KPsITPODIjQsnclTz5MxMyZvnNpk6oPADxtWdZ6r8r7Hn2BUS+qPd /jB2McJTcpmFtr9RYCfdPVvOeUu47DjLl2Z/U5bq64kvVrUGK1qob8RTMirBUggior7S V0c5BgQiFEE8N+zBZdrkaWlTURSG+yElSWCdbW0Zi1znO6wq8O52JOAABek9XhsKzEwh HTuepTVODvPN8KGPX/L1+O44ai5R3Ma+vp6qqLczIn2/BDafFngbSyrN0eK0TX3sh7Nm F6qQ== X-Gm-Message-State: APjAAAWnrPbZ4LTK9hGCs0xUg6C5HQeXGbvF4ZQY2hNy4kk3NKrK20f+ xllj3npm01LkovEAY/a9JWxdBVamLuI= X-Google-Smtp-Source: APXvYqz+jBmQtpBxYlHmY6dHeDZHr/b0xeXtp4DUisdkyhAsjH1QHearDjAmtT3gKaTjZ9KK/O8Etw== X-Received: by 2002:a17:90b:904:: with SMTP id bo4mr13277893pjb.60.1559696942393; Tue, 04 Jun 2019 18:09:02 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 12sm8645936pfi.60.2019.06.04.18.09.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 18:09:01 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 4 Jun 2019 18:08:52 -0700 Message-Id: <20190605010852.28395-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605010852.28395-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190605010852.28395-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 6/6] cmdline: use rte_ether_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" Now that there is a version of ether_aton in rte_ether, it can be used by the cmdline ethernet address parser. Signed-off-by: Stephen Hemminger --- lib/Makefile | 2 +- lib/librte_cmdline/Makefile | 3 +- lib/librte_cmdline/cmdline_parse_etheraddr.c | 71 +++----------------- lib/librte_cmdline/meson.build | 3 + 4 files changed, 14 insertions(+), 65 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 82b2c4bfa8ea..cc36fe7591f0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer DEPDIRS-librte_timer := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline -DEPDIRS-librte_cmdline := librte_eal +DEPDIRS-librte_cmdline := librte_eal librte_net DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring DEPDIRS-librte_ethdev += librte_mbuf diff --git a/lib/librte_cmdline/Makefile b/lib/librte_cmdline/Makefile index c64142b8d5a0..04057d7c671f 100644 --- a/lib/librte_cmdline/Makefile +++ b/lib/librte_cmdline/Makefile @@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk LIB = librte_cmdline.a CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 +CFLAGS += -DALLOW_EXPERIMENTAL_API EXPORT_MAP := rte_cmdline_version.map @@ -25,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c -LDLIBS += -lrte_eal +LDLIBS += -lrte_net -lrte_eal # install includes INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c index 24e04755cd9e..2cb8dd2a1267 100644 --- a/lib/librte_cmdline/cmdline_parse_etheraddr.c +++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c @@ -12,9 +12,9 @@ #include #include #include -#include #include +#include #include "cmdline_parse.h" #include "cmdline_parse_etheraddr.h" @@ -26,69 +26,15 @@ struct cmdline_token_ops cmdline_token_etheraddr_ops = { .get_help = cmdline_get_help_etheraddr, }; -/* the format can be either XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX */ -#define ETHER_ADDRSTRLENLONG 18 -#define ETHER_ADDRSTRLENSHORT 15 - -#ifdef __linux__ -#define ea_oct ether_addr_octet -#else -#define ea_oct octet -#endif - - -static struct ether_addr * -my_ether_aton(const char *a) -{ - int i; - char *end; - unsigned long o[ETHER_ADDR_LEN]; - static struct ether_addr ether_addr; - - i = 0; - do { - errno = 0; - o[i] = strtoul(a, &end, 16); - if (errno != 0 || end == a || (end[0] != ':' && end[0] != 0)) - return NULL; - a = end + 1; - } while (++i != sizeof (o) / sizeof (o[0]) && end[0] != 0); - - /* Junk at the end of line */ - if (end[0] != 0) - return NULL; - - /* Support the format XX:XX:XX:XX:XX:XX */ - if (i == ETHER_ADDR_LEN) { - while (i-- != 0) { - if (o[i] > UINT8_MAX) - return NULL; - ether_addr.ea_oct[i] = (uint8_t)o[i]; - } - /* Support the format XXXX:XXXX:XXXX */ - } else if (i == ETHER_ADDR_LEN / 2) { - while (i-- != 0) { - if (o[i] > UINT16_MAX) - return NULL; - ether_addr.ea_oct[i * 2] = (uint8_t)(o[i] >> 8); - ether_addr.ea_oct[i * 2 + 1] = (uint8_t)(o[i] & 0xff); - } - /* unknown format */ - } else - return NULL; - - return (struct ether_addr *)ðer_addr; -} - int cmdline_parse_etheraddr(__attribute__((unused)) cmdline_parse_token_hdr_t *tk, const char *buf, void *res, unsigned ressize) { unsigned int token_len = 0; - char ether_str[ETHER_ADDRSTRLENLONG+1]; - struct ether_addr *tmp; + char ether_str[RTE_ETHER_ADDR_FMT_SIZE]; + struct rte_ether_addr tmp; - if (res && ressize < sizeof(struct ether_addr)) + if (res && ressize < sizeof(tmp)) return -1; if (!buf || ! *buf) @@ -98,17 +44,16 @@ cmdline_parse_etheraddr(__attribute__((unused)) cmdline_parse_token_hdr_t *tk, token_len++; /* if token doesn't match possible string lengths... */ - if ((token_len != ETHER_ADDRSTRLENLONG - 1) && - (token_len != ETHER_ADDRSTRLENSHORT - 1)) + if (token_len >= RTE_ETHER_ADDR_FMT_SIZE) return -1; strlcpy(ether_str, buf, token_len + 1); - tmp = my_ether_aton(ether_str); - if (tmp == NULL) + if (rte_ether_unformat_addr(ether_str, &tmp) < 0) return -1; + if (res) - memcpy(res, tmp, sizeof(struct ether_addr)); + memcpy(res, &tmp, sizeof(tmp)); return token_len; } diff --git a/lib/librte_cmdline/meson.build b/lib/librte_cmdline/meson.build index 0fa61385fccf..c01033fd796f 100644 --- a/lib/librte_cmdline/meson.build +++ b/lib/librte_cmdline/meson.build @@ -4,6 +4,8 @@ # This library is processed before EAL includes = [global_inc] +cflags += '-DALLOW_EXPERIMENTAL_API' + version = 2 sources = files('cmdline.c', 'cmdline_cirbuf.c', @@ -28,3 +30,4 @@ headers = files('cmdline.h', 'cmdline_socket.h', 'cmdline_cirbuf.h', 'cmdline_parse_portlist.h') +deps += ['net'] -- 2.20.1