From patchwork Mon Jun 24 20:44:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55268 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 5F0031BC7D; Mon, 24 Jun 2019 22:44:49 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 81F951BC00 for ; Mon, 24 Jun 2019 22:44:45 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id q10so8173551pff.9 for ; Mon, 24 Jun 2019 13:44:45 -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=j/c+ewlm2tKY5YTeBCf1pQHycxEMdrRChnVoFr1WJtg=; b=iZa5+qI/peNs7p0s8HkicHQ0aAe1Pc+ZOqIJ7g7nJDZMiDj9w6AeQaMt1/u56nqraG pUtKWj0g2Tf0kR3mwM14V3inG/VuEUdcYm4WGk56D84kwlR6iomjepBnW2+AXEOjcHTC cUGyCGtCccF9oGqVEhbj8/L2/yVUtHhDzsy82xnJTYaU9Jso8Uyuz+jS82isMMP/xYQO DGsJ21KkEXlZulpyabuGw4zskp8AAQy1ojJxgHQJ93EQonLiMn5Gi2WA2l86WQxyuqnR PLP8gzLXMN9Gn25P8k1JsJzQXcEpWQv7uKqk4g43163+zZbBzWajrtmjyvzQ3nt+OYq7 kyLA== 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=j/c+ewlm2tKY5YTeBCf1pQHycxEMdrRChnVoFr1WJtg=; b=OULZAE35uVom61dj0zJy/TtNjUWYyXf4EUr0N+DyoF4xgTSY2YxhqrJ3JXbLaa0zkf RWMiXYeiLkGaS6xAvz+oG5IgrQrk0/OyE5c3/v1YKeihNaV6BWDytcOfT4jIf4HW/E2Q 8gdy0my2Rt+CJd0b6d0QPG6Y13XBvtHk/eJ323VW8fud4D6ThaGd/rH1DeVD0P7aE3SL 9sMmRrPEtolHL8BfkTr1tdX8SzJR3dka9w8KgZGBnGjxq4X3XDnFqF9fbKfwMjLvd4Em yv1W2XAhRMlh6C7FzWZLUFfjRV+BI3x4vwRHbTSxEzYieWc4C7b7+9HX9oXJvQd7lYFv Ybfg== X-Gm-Message-State: APjAAAVcgoDmGy58gLrjqi/MNWWgrToarI7Kr2vVOuqX8mpPOJyQU7Ur KmHj2cAOiqHnMUlBPeXCvdUeif/AbiM= X-Google-Smtp-Source: APXvYqxPTieLxfy7CtVqOxWX3ncw3tqypvYsmFhK9tUEuLaE5YTriwwfbsdPia1rv8g8TBEdRAVa0w== X-Received: by 2002:a63:8dc2:: with SMTP id z185mr23102062pgd.287.1561409084031; Mon, 24 Jun 2019 13:44:44 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Rami Rosen , Andrew Rybchenko Date: Mon, 24 Jun 2019 13:44:28 -0700 Message-Id: <20190624204435.29452-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 1/8] net/rte_ether: deinline non-critical functions 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" Formatting Ethernet address and getting a random value are not in critical path so they should not be inlined. Signed-off-by: Stephen Hemminger Acked-by: Rami Rosen Reviewed-by: Andrew Rybchenko --- lib/librte_net/Makefile | 1 + lib/librte_net/meson.build | 2 +- lib/librte_net/rte_ether.c | 29 +++++++++++++++++++++++++++++ lib/librte_net/rte_ether.h | 25 ++++--------------------- lib/librte_net/rte_net_version.map | 7 +++++++ 5 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 lib/librte_net/rte_ether.c diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile index c3082069ab50..1244c9fd54c9 100644 --- a/lib/librte_net/Makefile +++ b/lib/librte_net/Makefile @@ -14,6 +14,7 @@ LIBABIVER := 1 SRCS-$(CONFIG_RTE_LIBRTE_NET) := rte_net.c SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_net_crc.c +SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_ether.c SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c # install includes diff --git a/lib/librte_net/meson.build b/lib/librte_net/meson.build index 7d66f693cbf3..868a93fd6b6b 100644 --- a/lib/librte_net/meson.build +++ b/lib/librte_net/meson.build @@ -16,5 +16,5 @@ headers = files('rte_ip.h', 'rte_net_crc.h', 'rte_mpls.h') -sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c') +sources = files('rte_arp.c', 'rte_ether.c', 'rte_net.c', 'rte_net_crc.c') deps += ['mbuf'] diff --git a/lib/librte_net/rte_ether.c b/lib/librte_net/rte_ether.c new file mode 100644 index 000000000000..974fe815b335 --- /dev/null +++ b/lib/librte_net/rte_ether.c @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include + +void +rte_eth_random_addr(uint8_t *addr) +{ + uint64_t rand = rte_rand(); + uint8_t *p = (uint8_t *)&rand; + + rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN); + addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR; /* clear multicast bit */ + addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit */ +} + +void +rte_ether_format_addr(char *buf, uint16_t size, + const struct rte_ether_addr *eth_addr) +{ + snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X", + eth_addr->addr_bytes[0], + eth_addr->addr_bytes[1], + eth_addr->addr_bytes[2], + eth_addr->addr_bytes[3], + eth_addr->addr_bytes[4], + eth_addr->addr_bytes[5]); +} diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 7be9b4890af7..3caae0d98f6d 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -207,15 +207,8 @@ static inline int rte_is_valid_assigned_ether_addr(const struct rte_ether_addr * * @param addr * A pointer to Ethernet address. */ -static inline void rte_eth_random_addr(uint8_t *addr) -{ - uint64_t rand = rte_rand(); - uint8_t *p = (uint8_t *)&rand; - - rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN); - addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR; /* clear multicast bit */ - addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit */ -} +void +rte_eth_random_addr(uint8_t *addr); /** * Fast copy an Ethernet address. @@ -254,19 +247,9 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from, * @param eth_addr * A pointer to a ether_addr structure. */ -static inline void +void rte_ether_format_addr(char *buf, uint16_t size, - const struct rte_ether_addr *eth_addr) -{ - snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X", - eth_addr->addr_bytes[0], - eth_addr->addr_bytes[1], - eth_addr->addr_bytes[2], - eth_addr->addr_bytes[3], - eth_addr->addr_bytes[4], - eth_addr->addr_bytes[5]); -} - + const struct rte_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 26c06e7c7ae7..f1e1b84ab491 100644 --- a/lib/librte_net/rte_net_version.map +++ b/lib/librte_net/rte_net_version.map @@ -13,6 +13,13 @@ DPDK_17.05 { } DPDK_16.11; +DPDK_19.08 { + global: + + rte_eth_random_addr; + rte_ether_format_addr; +} DPDK_17.05; + EXPERIMENTAL { global: From patchwork Mon Jun 24 20:44:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55269 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 06F671BC84; Mon, 24 Jun 2019 22:44:52 +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 1E3C61BC7A for ; Mon, 24 Jun 2019 22:44:46 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id z19so4776644pgl.12 for ; Mon, 24 Jun 2019 13:44:45 -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=HT7fgvqo3DxGVdfkCgxmfvm3m5YXMqttimfnKXT3DRU=; b=DONk2/1xdZ/hCBVuRuomrkfB2gdccxo8dzfky72BY1/CWpYCyWWxi6of1DyYfTjDmq tP9FgDKcvnKS6xMn0Yt+++TJOWW1oXK/vG0gfZYOsJaUwkH1RYSbN7OlsI12zp6iPpOY zZtvUYCXkXAwYgPDpHYQZH1eAdWVPBRacT9cDrJO7dp+QZeGbSUZYaiyyo7lwBtyfmQq xlEi/ajw76MDT2Ng1gYT1RsFtxXAMRosVdd33JLnAnMOZEJ8lFW7sWJOa1H+2iaq4c7z v+A2jNlnG/D3BkhVlN9bE5ZMhYIb2qn402Vc9GxVQkmZ/A3dy5uIXjOC3frmHIuqtVca VKRw== 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=HT7fgvqo3DxGVdfkCgxmfvm3m5YXMqttimfnKXT3DRU=; b=BMdR61YOxUB5KAn3Z+M3kGLW6JJAe7csJMNOz0azKR4YQ/v1oCK+Od+0p/GKB6Scoc 7occCr7s91mQvsoPsGSyma+htU7iMEZt9O/3b8AgjXlyWlXD2uu5EtTfJ6k7jIWd1wvu J3Xiq/2byUezBJxqauqshrX8k/YHoI7eadUtqtW93VtIwU1TbyBDD7NI9u3++uWhcD1R Qh6Hxp88GFWg4dJlkmGQ/QPtn8KAuXSHuYf/+jO2bblF0dK4Uuk/UV04A8wuyJbRISYG AaQiXR3JEDN+VE5nZB0BXncKxv6YIFpBJPM8GO5oPO0m0t7atcdypvAQbbADDYS4aXhq F5NA== X-Gm-Message-State: APjAAAVThP9c/D663CFrOeinKoe8NHL93oCYDNIYpogPiwxrR4/evkE5 6dFzVrjXsstUObRdKniBHsiDxKlN9nc= X-Google-Smtp-Source: APXvYqwhxm5qqdabWoGD3RoCOcXT9PBRKAhAm8sJa8R2Kr25jBhHW451vtefJ2J94wpmnfIxhjFN/Q== X-Received: by 2002:a63:4f5b:: with SMTP id p27mr34220254pgl.273.1561409084869; Mon, 24 Jun 2019 13:44:44 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko Date: Mon, 24 Jun 2019 13:44:29 -0700 Message-Id: <20190624204435.29452-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 2/8] net/ether: add function to convert string to ethernet address 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 can be used in place of eth_aton_r to convert a string to rte_ether_addr. This function allows both byte (xx:xx:xx:xx:xx:xx) and word (XXXX:XXXX:XXXX) format and has the same lack of error handling as the original. This also allows ethdev to no longer have a hard dependency on the cmdline library. Signed-off-by: Stephen Hemminger Reviewed-by: Andrew Rybchenko --- lib/librte_net/rte_ether.c | 47 ++++++++++++++++++++++++++++++ lib/librte_net/rte_ether.h | 14 +++++++++ lib/librte_net/rte_net_version.map | 1 + 3 files changed, 62 insertions(+) diff --git a/lib/librte_net/rte_ether.c b/lib/librte_net/rte_ether.c index 974fe815b335..acc8a0e938c5 100644 --- a/lib/librte_net/rte_ether.c +++ b/lib/librte_net/rte_ether.c @@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size, eth_addr->addr_bytes[4], eth_addr->addr_bytes[5]); } + +/* + * Like ether_aton_r but can handle either + * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX + */ +int +rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea) +{ + unsigned int o0, o1, o2, o3, o4, o5; + int n; + + n = sscanf(s, "%x:%x:%x:%x:%x:%x", + &o0, &o1, &o2, &o3, &o4, &o5); + + if (n == 6) { + if (o0 > UINT8_MAX || o1 > UINT8_MAX || o2 > UINT8_MAX || + o3 > UINT8_MAX || o4 > UINT8_MAX || o5 > UINT8_MAX) + return -1; + + ea->addr_bytes[0] = o0; + ea->addr_bytes[1] = o1; + ea->addr_bytes[2] = o2; + ea->addr_bytes[3] = o3; + ea->addr_bytes[4] = o4; + ea->addr_bytes[5] = o5; + + return 0; + } + + /* Support the format XXXX:XXXX:XXXX */ + n = sscanf(s, "%x:%x:%x", &o0, &o1, &o2); + if (n == 3) { + if (o0 > UINT16_MAX || o1 > UINT16_MAX || o2 > UINT16_MAX) + return -1; + + ea->addr_bytes[0] = o0 >> 8; + ea->addr_bytes[1] = o0 & 0xff; + ea->addr_bytes[2] = o1 >> 8; + ea->addr_bytes[3] = o1 & 0xff; + ea->addr_bytes[4] = o2 >> 8; + ea->addr_bytes[5] = o2 & 0xff; + return 0; + } + /* unknown format */ + + return -1; +} diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 3caae0d98f6d..8edc7e217b25 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -250,6 +250,20 @@ static inline void rte_ether_addr_copy(const struct rte_ether_addr *ea_from, void rte_ether_format_addr(char *buf, uint16_t size, const struct rte_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 +rte_ether_unformat_addr(const char *str, struct rte_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 f1e1b84ab491..f4c915069d57 100644 --- a/lib/librte_net/rte_net_version.map +++ b/lib/librte_net/rte_net_version.map @@ -25,4 +25,5 @@ EXPERIMENTAL { rte_net_make_rarp_packet; rte_net_skip_ip6_ext; + rte_ether_unformat_addr; }; From patchwork Mon Jun 24 20:44:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55270 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 B9ACF1BC83; Mon, 24 Jun 2019 22:44:54 +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 922AF1BC7C for ; Mon, 24 Jun 2019 22:44:47 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id e5so7540408pls.13 for ; Mon, 24 Jun 2019 13:44:47 -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=LJP5NUGKYyva7BnvgS/UxCqLM/1j8w47JpFJi1u1tNU=; b=MaSM8ZNrqp7KXIPmszcqCBX36We101EWNHTWahFwU2tY7eKp76FHEpJUEn5jwF1Lq+ ClrVtxisGgSj7yi+jxeeGVfuOCOf1LZq8d0MJhTjXjdlDoDSc3wcqHoAuvmO5n8x5OC4 nzhLojCeQwsh3OPumnATVV8SKbvnYvQstAfNCVair5bpv3v5vgnxvGxTiIgCzwV9YbBT I4NZPD5W5n2ibuEywk48NA9AyRlJpP5PdRhGYGlIk7Ezho+a4lFB78t8v+M/ut5an9vl ok45RmX6DVvvEKg6R43GLRaDIaUbovLh1gYLjK4Ek3pVT5cahgt8dqw+UdnZSJx42AoD Ymvw== 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=LJP5NUGKYyva7BnvgS/UxCqLM/1j8w47JpFJi1u1tNU=; b=Mij4JRdfBAbNXZN1PwmajJglMAY2IQ7CgLoU3zgsaiGAhD37UvF8ILu8zJBEWSqymn T3+gkXcfUJfAEUV2FCgrXSP/vOnYQcTzVUYKHlkQIunOdPgn4xR2+0aDmuoLl9hdhNuM rfkMp3BDOFB+U7pHcuNRAKkY9IA5wX0bZElAuMVjygC2/v5LFtzTqa4nvyjcD99yrtA1 iWv+b/wz+eLiCbHxrr6gCrFol3cd4I1kixrEPJ03OL0ClGg4RNVXgkML98dCrbG2A3H4 S1gLQXGaDMJxd4z8s8jozKg9KbcF24QUXbsTlKsX9bDiwhNuIQX1nSi0kCwOr6TNp6Jm ZPnQ== X-Gm-Message-State: APjAAAUxGQ0zobJN0QtEbhZUcEdZJF3BYifX1osD218d+FzQU4+kFkv8 c32K/cPPTFos3WgKrmlwWlrEqFB6EFQ= X-Google-Smtp-Source: APXvYqwOUWbCgvkFw4UIKy9fGQuJMxzt8ayTJWlf/ME2brM4KEPLOopnIuOxRS+KFwd7WCjlu/RUsA== X-Received: by 2002:a17:902:2aa8:: with SMTP id j37mr104916610plb.316.1561409086485; Mon, 24 Jun 2019 13:44:46 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:45 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 24 Jun 2019 13:44:30 -0700 Message-Id: <20190624204435.29452-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 3/8] ethdev: use new ethernet parsing function 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" Use rte_eth_unformat_addr, so that ethdev can be built and work without the cmdline library. The dependency on cmdline was an arrangement of convenience anyway. Signed-off-by: Stephen Hemminger --- lib/Makefile | 1 - lib/librte_ethdev/Makefile | 2 +- lib/librte_ethdev/meson.build | 2 +- lib/librte_ethdev/rte_class_eth.c | 9 +-------- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 791e0d9911d6..82b2c4bfa8ea 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,7 +25,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring DEPDIRS-librte_ethdev += librte_mbuf DEPDIRS-librte_ethdev += librte_kvargs -DEPDIRS-librte_ethdev += librte_cmdline DEPDIRS-librte_ethdev += librte_meter DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index 8d4a02630c4f..60bcc2227878 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring -LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline -lrte_meter +LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter EXPORT_MAP := rte_ethdev_version.map diff --git a/lib/librte_ethdev/meson.build b/lib/librte_ethdev/meson.build index 8d6165b2a7dd..f75d428c96d0 100644 --- a/lib/librte_ethdev/meson.build +++ b/lib/librte_ethdev/meson.build @@ -26,4 +26,4 @@ headers = files('rte_ethdev.h', 'rte_tm.h', 'rte_tm_driver.h') -deps += ['net', 'kvargs', 'cmdline', 'meter'] +deps += ['net', 'kvargs', 'meter'] diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index 873a653532ad..6338355e2557 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -4,7 +4,6 @@ #include -#include #include #include #include @@ -43,19 +42,13 @@ static int eth_mac_cmp(const char *key __rte_unused, const char *value, void *opaque) { - int ret; struct rte_ether_addr mac; const struct rte_eth_dev_data *data = opaque; struct rte_eth_dev_info dev_info; uint32_t index; /* Parse devargs MAC address. */ - /* - * cannot use ether_aton_r(value, &mac) - * because of include conflict with rte_ether.h - */ - ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac)); - if (ret < 0) + if (rte_ether_unformat_addr(value, &mac) < 0) return -1; /* invalid devargs value */ /* Return 0 if devargs MAC is matching one of the device MACs. */ From patchwork Mon Jun 24 20:44:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55271 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 69F981BC8F; Mon, 24 Jun 2019 22:44:57 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id C39A31BC7D for ; Mon, 24 Jun 2019 22:44:48 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id m4so7124805pgk.0 for ; Mon, 24 Jun 2019 13:44:48 -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=8fFcBaPZKjQQPsKQQeFeSAG72mshjjR9mGZfTCJM/8s=; b=hmBA8dHimb4tNJBmjkb8RPJREgaQyxbOmWD39IWOu+4ahr2fLqcQQ0b0Eiw6GGAQMj sb4VPW3dNmjcJ1wkQPzrMUAsIv/IDb7NjAORirSNgEfwuVkeoHqdBNDwVbxqg4dau9l+ mzYMsZith9KJycKEq05aDA8vdfk1xXyA0XX+9KvHFHdnMOB5+Zc8rYJmutCOBnJT9IlS /VgV9lKXAy13cgU0WI6PV0CUpFLIn6KwAGjuSejXaOV5L22lkfjfrCneEXSuUscV2ufd sBh9U9DMrsIXBOcu5SscEcGCiFkOuM+J7QXDsEuDE4H1MuLbQgR36WyoG6nkNVqQW2/r 1GNQ== 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=8fFcBaPZKjQQPsKQQeFeSAG72mshjjR9mGZfTCJM/8s=; b=VOORtOzrS1a7EpuDuKhlWKyHBSa5yy8nSrBD6ixvqPpOeG0tN5DL2k3Ladk59Lgy2B az2XWpP009qpE+RrltYbtu5uVqyx+W+rCr37KDNHu8hMYMEnlamUcDrUIFtEs10kCScN yu+9hVgZw8RWua8VMNUefQhrHAdlBzfQNDLpkJ15KmDaYe1YV1h8ZyT+3+gvYlb+sAi+ ezar6udvolE95lj0KurlzuhQ7UOeuWPjsbDKDqtTpOHduoPOErDfeHBcHewzY8MbdVy9 FL6h2kGDgTB+4wcgIvfxXGNG/v3hMTOgLai+iQYUL3nuPpOr9ejDlcWQO0BlKdcNyGFR JxcA== X-Gm-Message-State: APjAAAXxwIoHBImPoYc/F9yoQKmD1DyQ0FvT2v/x19vRFRvMi92mimvv pp00zKYP9LcS1fH8jcZawTcAaI7UNQ4= X-Google-Smtp-Source: APXvYqzzmXlnGDHTEFf1FgTbD4rzdbBYCP6kF5+B6b1sE8ax4tLh0x8gK6JzPpPyWwqDfVIX4Po2Ng== X-Received: by 2002:a17:90a:9291:: with SMTP id n17mr26557795pjo.66.1561409087615; Mon, 24 Jun 2019 13:44:47 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Andrew Rybchenko Date: Mon, 24 Jun 2019 13:44:31 -0700 Message-Id: <20190624204435.29452-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 4/8] net/ether: use bitops to speedup comparison 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" Using bit operations like or and xor is faster than a loop on all architectures. Really just explicit unrolling. Similar cast to uint16 unaligned is already done in other functions here. Signed-off-by: Stephen Hemminger Reviewed-by: Andrew Rybchenko --- lib/librte_net/rte_ether.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 8edc7e217b25..feb35a33c94b 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -81,11 +81,10 @@ struct rte_ether_addr { static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, const struct rte_ether_addr *ea2) { - int i; - for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) - if (ea1->addr_bytes[i] != ea2->addr_bytes[i]) - return 0; - return 1; + const unaligned_uint16_t *w1 = (const uint16_t *)ea1; + const unaligned_uint16_t *w2 = (const uint16_t *)ea2; + + return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0; } /** @@ -100,11 +99,9 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, */ static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea) { - int i; - for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) - if (ea->addr_bytes[i] != 0x00) - return 0; - return 1; + const unaligned_uint16_t *w = (const uint16_t *)ea; + + return (w[0] | w[1] | w[2]) == 0; } /** From patchwork Mon Jun 24 20:44:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55272 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 E67921BC95; Mon, 24 Jun 2019 22:44:59 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 2485E1BC81 for ; Mon, 24 Jun 2019 22:44:50 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id q10so8173630pff.9 for ; Mon, 24 Jun 2019 13:44:50 -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=5jmpHlnhidg0ShQ7XItCpgaXpVK1xXtowoDpbYktXUk=; b=GL3Y7TILvVApPshoiWOe+0fwqEzpN45pEbaa7mUrWhV/+SYl9FJyVN4Yh//tu1MTcg HSi1IjqQU7ODIwM/n96cdZHJ6ZKNkLLs2/yuwD5Yj06cBwbDEQhmJeJXHuTBAwfM4Ccw qMx6nFgfF5K37TJOpaS5U35c912b3VdAUURhkBTyFsHICZl6eh4ihHi4ohjxMlTCDzWu 6idYPwVNie1lYsd7VN8F/PzBjxL3X65LiRThsEvLdbmqEPXNz9TkhA4TRYuVnsAGtcFP cvD0/EabKIVG7mZRCAQP6lV9UNV3XK95V2s5M8FwX1k5e1fbEaHHTRFJHm/fW5cxP7HB b+2g== 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=5jmpHlnhidg0ShQ7XItCpgaXpVK1xXtowoDpbYktXUk=; b=U2IknMB0qtKXdL+SwtbpnWC3Vusb1iFvogDg9Z4uTasoleMLTXHZbGoqQpTKInq+Cy 44vtox1xEDITEsw2ybDYOQlw9aYkOkLWK7XF1e/beZ6CfDzNPceLUfqstn1UTFcvaTyr EVx9r8hYcVbrqKo7fWn0Ip13hRPtokUZ3YqT9Ro2QbeRZTv2r/tosS64ZfEswkR4ecuq sTDvReaU9oLNxOf3AEMoM/y+WW+WYnhIaTz9ojmGGo5kGMGprm6WziYqQHCa9iZaQu9I As9IhVNT80p63d2pEHgwo5DKBp8Hsmtu/R3wargGWJiF6P6T5Mq7Q7RFt+jLLSLoG21m K/QQ== X-Gm-Message-State: APjAAAVkpFnrZEj4abLu3KjtvXNk1s9lsAvRvU9IcaFSMJ4ZtNV1f317 HkDUHBiV9e/kQIHyN6Duj3DlVwJMxF4= X-Google-Smtp-Source: APXvYqxK5/bM2216QGFMAaXuEE9Uh10KOqKIl3kziFuxr4q4zbEyyuh7hAmzbGsEGElmpvPRFU3iaA== X-Received: by 2002:a65:6210:: with SMTP id d16mr34460744pgv.180.1561409088884; Mon, 24 Jun 2019 13:44:48 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Bruce Richardson , Stephen Hemminger , Andrew Rybchenko Date: Mon, 24 Jun 2019 13:44:32 -0700 Message-Id: <20190624204435.29452-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 5/8] net/ether: mark ethernet addresses as being 2-byte aligned 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" From: Bruce Richardson When including the rte_ether.h header in applications with warnings enabled, a warning was given because of the assumption of 2-byte alignment of ethernet addresses when processing them. .../include/rte_ether.h:149:2: warning: converting a packed ‘const struct ether_addr’ pointer (alignment 1) to a ‘unaligned_uint16_t’ {aka ‘const short unsigned int’} pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member] 149 | const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea; | ^~~~~ Since ethernet addresses should always be aligned on a two-byte boundary, we can just inform the compiler of this assumption to remove the warnings and allow us to always access the addresses using 16-bit operations. Signed-off-by: Bruce Richardson Signed-off-by: Stephen Hemminger Reviewed-by: Andrew Rybchenko --- lib/librte_net/rte_ether.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index feb35a33c94b..d7b76ddf63eb 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -58,7 +58,8 @@ extern "C" { * See http://standards.ieee.org/regauth/groupmac/tutorial.html */ struct rte_ether_addr { - uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */ + uint8_t addr_bytes[RTE_ETHER_ADDR_LEN] __rte_aligned(2); + /**< Addr bytes in tx order */ } __attribute__((__packed__)); #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */ @@ -81,8 +82,8 @@ struct rte_ether_addr { static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, const struct rte_ether_addr *ea2) { - const unaligned_uint16_t *w1 = (const uint16_t *)ea1; - const unaligned_uint16_t *w2 = (const uint16_t *)ea2; + const uint16_t *w1 = (const uint16_t *)ea1; + const uint16_t *w2 = (const uint16_t *)ea2; return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0; } @@ -99,7 +100,7 @@ static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1, */ static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea) { - const unaligned_uint16_t *w = (const uint16_t *)ea; + const uint16_t *w = (const uint16_t *)ea; return (w[0] | w[1] | w[2]) == 0; } @@ -146,7 +147,7 @@ static inline int rte_is_multicast_ether_addr(const struct rte_ether_addr *ea) */ static inline int rte_is_broadcast_ether_addr(const struct rte_ether_addr *ea) { - const unaligned_uint16_t *ea_words = (const unaligned_uint16_t *)ea; + const uint16_t *ea_words = (const uint16_t *)ea; return (ea_words[0] == 0xFFFF && ea_words[1] == 0xFFFF && ea_words[2] == 0xFFFF); From patchwork Mon Jun 24 20:44:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55273 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 93D211BC9C; Mon, 24 Jun 2019 22:45:02 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 4CE6F1BC82 for ; Mon, 24 Jun 2019 22:44:51 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id j2so8178669pfe.6 for ; Mon, 24 Jun 2019 13:44:51 -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=NdwBPd1P8YYRNroEzzcDRMKmYiCZqIYYWQE22XVp4zA=; b=U8vG0zrr10RnBd7UE3AuvWMDgVQDWXHj1fxWik2NlUWdME7t3ybDWS632u6R64eal1 YM/gegjMsmN/vodzj8Tiuu/jYwvUq7sUnDUVr0WoxEWg4R9g2R4uhcMbz9Wwsll0ut71 4aKS7jdOM3ZOkSORO57cJALWmpn2d8XpPgaHOuO0n4r0HA7H+6N7KvEhKeSuwHt1dTT6 mu1k7a62fjHEzAFBbK+NFkVw+BDSbMt3bRh4Kqxx/S5Z0hhgdlusD7ZLpWX/ppDsZVRl ATok1oVtFj+39lZJBd4qJRLipiMVYCKa6DbAzb6RvJliqQL8nIxYNt3Fr+LBy6BYsWXV Pgeg== 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=NdwBPd1P8YYRNroEzzcDRMKmYiCZqIYYWQE22XVp4zA=; b=Mbtvqa/OONVLHRCqQDi8QJGCtnoiXqiqGBsTo6m47lmmI7jKBvFk1or70bBJNE/fwZ RPSMboYBvZPco9nehNFJ7av+8U/2BFBLvoFayulmHrqPatt9gho2wArPKh2kpJC+GsqL qX/1SA25MpH/MARhHut2WJClew4P+cg/PpLZmqSXfZPecZiYpcEhkUcvnz+gDyHrgUuS bnmVl/G/xcRbBUaipOgp1METUtNZ0iRV+NGPMJq+5KDKjIhtRV5DPAapAwt1NmusxaKT cJ6rfCE1IoUhj9t6/jlC7twmxgIFKaIQ++O0bCLwYU2n10xqcyF8IAWQMZy+M31yqw7S 11bQ== X-Gm-Message-State: APjAAAXeP5DaQcp9COPSXk3qWMKrEbm/BKcYq/pdINmfIyrIh72qUcry tS9+yfTMnBC13K5HeLE4sv9Lz/RqaQU= X-Google-Smtp-Source: APXvYqy1O6n2BjRcOQ3z7hiQTl21E52rZOap+ZcLqYQnN5JKBTGG95Uplr8QDxI5lQFiGmRrn/kACg== X-Received: by 2002:a63:fc5b:: with SMTP id r27mr35396321pgk.219.1561409090125; Mon, 24 Jun 2019 13:44:50 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 24 Jun 2019 13:44:33 -0700 Message-Id: <20190624204435.29452-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 6/8] cmdline: use new ethernet address parser 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. Note: ether_aton_r can not be used in cmdline because the old code would accept either bytes XX:XX:XX:XX:XX:XX or words XXXX:XXXX:XXXX and we need to keep compatiablity. 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 | 6 +- lib/meson.build | 2 +- 5 files changed, 15 insertions(+), 69 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..07334c1b0956 100644 --- a/lib/librte_cmdline/meson.build +++ b/lib/librte_cmdline/meson.build @@ -1,10 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -# This library is processed before EAL -includes = [global_inc] - version = 2 +allow_experimental_apis = true sources = files('cmdline.c', 'cmdline_cirbuf.c', 'cmdline_parse.c', @@ -28,3 +26,5 @@ headers = files('cmdline.h', 'cmdline_socket.h', 'cmdline_cirbuf.h', 'cmdline_parse_portlist.h') + +deps += ['net'] diff --git a/lib/meson.build b/lib/meson.build index 992091a9407e..5c892404e706 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -11,8 +11,8 @@ libraries = [ 'kvargs', # eal depends on kvargs 'eal', # everything depends on eal - 'cmdline', # ethdev depends on cmdline for parsing functions 'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core + 'cmdline', 'metrics', # bitrate/latency stats depends on this 'hash', # efd depends on this 'timer', # eventdev depends on this From patchwork Mon Jun 24 20:44:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55274 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 17A501BCA0; Mon, 24 Jun 2019 22:45:04 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by dpdk.org (Postfix) with ESMTP id 80F771BC00 for ; Mon, 24 Jun 2019 22:44:52 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id g4so7534955plb.5 for ; Mon, 24 Jun 2019 13:44:52 -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=i8sEf2BqVxRRW7Hf5r4EMIM/xDPKtZVL0Pik8O21io8=; b=LeEFFLCSvl0BIbMHmWZblM2v2I8Oy4QWcuD7n9WRsZ2caBuk1ogjkEAqE+E9+ogycM xCUA4CdQQ2XELQAbQwIAKeeZMyfBF1l4wChMcabICi4qpiWHRQst4j5mtPu/FmuvjBdm VbuIQ2HNiNti2OsBCtw9F9Zt2wugk8WsD8A2Xzqwam2YYrHG/IHtcTKwviAr7GkSw7TI eind4+3MYBFGpKVP6xpf7JJrVpJmsooyZChtwaBGjzN/aWUkNv8k50ZKpL/OYG7EYEBc nyrQxse1QBYywNzLD894S+OH75WUuBhdGw5V/LpGK7ifju/I1FBY4sOmpbPXFNXw9fdH rslA== 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=i8sEf2BqVxRRW7Hf5r4EMIM/xDPKtZVL0Pik8O21io8=; b=HBf6a/pVPX6t7upuT5+p1EX4aQbiBzgorcKFcSbGuQQx4YKuTT5Nc8GQzdWXWpHi0l KxiNr/E4eT+D7bAe0IAcGfMmePjnqVBj7Yb7ewumxPiZZs1xB4POorVOAFCPXcjvCsJ9 vycEPuhO69b1u08bJxpsas4q95H1QEH0/JhGjs2r5WFGmMqTwOR2GUk4+EpIBiU8uKsp U0CLQ+8Zmxc6kozvGdiIzyTuUK2o0HbuIKfTlSMVtHZXJH9LxiGapZGMJz5BFKHrWVYu v9urEpL+vtHlBg1uf12TNgJTPvfpJ/bTpTEvivf4MlwOlFtHfXHeP+i5muiDddHYjbOA ncQg== X-Gm-Message-State: APjAAAVB/ZsyoeWgqrfhAUfesd9DNtgbI5StveWQgSyjuJda13MI+1uh 3i0vehnwkkUJ9sLmqwkjU2KvmmivDFI= X-Google-Smtp-Source: APXvYqyEcI/97PaPqq1lAJ578BMBDL81LmFUZOScc02qE/hXPB+NbyRWiPm5GWcwKowWb3zZ1r1IAw== X-Received: by 2002:a17:902:704a:: with SMTP id h10mr41854781plt.337.1561409091399; Mon, 24 Jun 2019 13:44:51 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 24 Jun 2019 13:44:34 -0700 Message-Id: <20190624204435.29452-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 7/8] net/bonding: use new ethernet address parser 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 cmdline library used to be the only way to parse a mac address. Now there is rte_ether_unformat_addr. Signed-off-by: Stephen Hemminger --- drivers/net/bonding/Makefile | 2 +- drivers/net/bonding/meson.build | 2 +- drivers/net/bonding/rte_eth_bond_args.c | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/net/bonding/Makefile b/drivers/net/bonding/Makefile index 1893e3cad313..26c1782554cd 100644 --- a/drivers/net/bonding/Makefile +++ b/drivers/net/bonding/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring -LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_cmdline +LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs LDLIBS += -lrte_pci -lrte_bus_pci LDLIBS += -lrte_bus_vdev diff --git a/drivers/net/bonding/meson.build b/drivers/net/bonding/meson.build index 00374edb2a9d..6267210adf5f 100644 --- a/drivers/net/bonding/meson.build +++ b/drivers/net/bonding/meson.build @@ -8,6 +8,6 @@ sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', 'rte_eth_bond_flow.c 'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c') deps += 'sched' # needed for rte_bitmap.h -deps += ['ip_frag', 'cmdline'] +deps += ['ip_frag'] install_headers('rte_eth_bond.h', 'rte_eth_bond_8023ad.h') diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c index 01bbb06c1a84..936440fb8491 100644 --- a/drivers/net/bonding/rte_eth_bond_args.c +++ b/drivers/net/bonding/rte_eth_bond_args.c @@ -7,9 +7,6 @@ #include #include -#include -#include - #include "rte_eth_bond.h" #include "rte_eth_bond_private.h" @@ -281,8 +278,7 @@ bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused, return -1; /* Parse MAC */ - return cmdline_parse_etheraddr(NULL, value, extra_args, - sizeof(struct rte_ether_addr)); + return rte_ether_unformat_addr(value, extra_args); } int From patchwork Mon Jun 24 20:44:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 55275 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 8F4121BCA7; Mon, 24 Jun 2019 22:45:05 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id 9E76E1BC87 for ; Mon, 24 Jun 2019 22:44:53 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id y72so7721264pgd.8 for ; Mon, 24 Jun 2019 13:44:53 -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=xdUsjvA+XM/A8lvdK1H1mldU1CJ2JFzy3kElJGpilZc=; b=wt29F+Vs7PwP2fzJF/0ege9KZLZWVn+x2i57y4V7gjejDPA1KIfdB93YSXJEaOw26b mvhzSQx40Z1UThp74hz4e4FycqO1dJeskouLOP4ZJkn4hnio75gEr/BmgN2VYpH9q2Mc KbR47zzBpP5iPwlcPlPgt6twVbvwDj/wl3zifnuOkJeI781pyewpW3GSVZ2XmZcLLkbq p23TvBSFJWzEmv2gLxdSMWGvSxXBzcAVtZFFYPCKE+eW1Km5FecVp0Ws0GN1GASBRAr7 T0bt66IkfJs4Rfd7vJRsC7fplNUcsNvpBvB17pgfTK0RsRBk9DQt/41GCbPk/YzBbiJM aFnQ== 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=xdUsjvA+XM/A8lvdK1H1mldU1CJ2JFzy3kElJGpilZc=; b=E0ZZL/KJbK2wh82dD73d51MR6Mw4iYW8vTKfRj4SMmXbA8M3Y3WVEo/CtXknWCicJN y7Q95d5isxzRuGRImtes9hU8Z4RCs71gLkR3C/cZnQKOJxhmEY1ty5aGEqza4gKPfZ5d C4lJYf6bOuGrgSZordYZ7PR/yvopHMf6VqzgLvnx3iHaw8bpf67rueIIiotz+/7exFfj RNadSOJm/kaJDnzuuw1u/G8iFk1tWWMqnBjEtjxC5Y/uUqWxpmoGqgu6+7H9ry+ArCS0 b3sbCLRLmcAKMmXFCY/SU/TCCou96P+zihoz9gCpxzJtIxFwhjJgmorKzDnR/ncDkok4 xp+g== X-Gm-Message-State: APjAAAVxnR2IU8Pz2YvtvFYaA2mIR/Y+vbfyAel8PqLfFZbati4LiWXi eHtnEzX+mZf8PTnPzjsvxvqzyCWyXT0= X-Google-Smtp-Source: APXvYqxfIu5V1sdid/Jdrf9uaoB757/71YeCiOHXUGhDBVrRQtCmUjmV+Xy+K2EBVs8zkFlS4WaeNQ== X-Received: by 2002:a63:2258:: with SMTP id t24mr26360601pgm.236.1561409092541; Mon, 24 Jun 2019 13:44:52 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q144sm22061498pfc.103.2019.06.24.13.44.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 13:44:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 24 Jun 2019 13:44:35 -0700 Message-Id: <20190624204435.29452-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624204435.29452-1-stephen@networkplumber.org> References: <20190516180427.17270-1-stephen@networkplumber.org> <20190624204435.29452-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 8/8] app/testpmd: use new ethernet address parser 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 cmdline_parse_ether_addr does not need to be used everywhere in testpmd. Can use rte_ether_unformat_addr instead. As an added bonus it eliminates some code for copying. Signed-off-by: Stephen Hemminger --- app/test-pmd/cmdline_flow.c | 5 ++--- app/test-pmd/config.c | 10 +++------- app/test-pmd/parameters.c | 15 +++------------ 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 201bd9de56e0..2b02ca29b7ac 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include "testpmd.h" @@ -4627,8 +4626,8 @@ parse_mac_addr(struct context *ctx, const struct token *token, /* Only network endian is supported. */ if (!arg->hton) goto error; - ret = cmdline_parse_etheraddr(NULL, str, &tmp, size); - if (ret < 0 || (unsigned int)ret != len) + ret = rte_ether_unformat_addr(str, &tmp); + if (ret < 0) goto error; if (!ctx->object) return len; diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index ab458c8d2837..1d804705d96c 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -49,7 +49,6 @@ #include #endif #include -#include #include #include "testpmd.h" @@ -2278,19 +2277,16 @@ pkt_fwd_config_display(struct fwd_config *cfg) void set_fwd_eth_peer(portid_t port_id, char *peer_addr) { - uint8_t c, new_peer_addr[6]; + struct rte_ether_addr new_peer_addr; if (!rte_eth_dev_is_valid_port(port_id)) { printf("Error: Invalid port number %i\n", port_id); return; } - if (cmdline_parse_etheraddr(NULL, peer_addr, &new_peer_addr, - sizeof(new_peer_addr)) < 0) { + if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) { printf("Error: Invalid ethernet address: %s\n", peer_addr); return; } - for (c = 0; c < 6; c++) - peer_eth_addrs[port_id].addr_bytes[c] = - new_peer_addr[c]; + peer_eth_addrs[port_id] = new_peer_addr; } int diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 245b610641ee..975a97807009 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -39,10 +39,6 @@ #include #include #include -#ifdef RTE_LIBRTE_CMDLINE -#include -#include -#endif #ifdef RTE_LIBRTE_PMD_BOND #include #endif @@ -227,8 +223,7 @@ init_peer_eth_addrs(char *config_filename) if (fgets(buf, sizeof(buf), config_file) == NULL) break; - if (cmdline_parse_etheraddr(NULL, buf, &peer_eth_addrs[i], - sizeof(peer_eth_addrs[i])) < 0) { + if (rte_ether_unformat_addr(buf, &peer_eth_addrs[i]) < 0) { printf("Bad MAC address format on line %d\n", i+1); fclose(config_file); return -1; @@ -727,7 +722,6 @@ launch_args_parse(int argc, char** argv) } if (!strcmp(lgopts[opt_idx].name, "eth-peer")) { char *port_end; - uint8_t c, peer_addr[6]; errno = 0; n = strtoul(optarg, &port_end, 10); @@ -739,14 +733,11 @@ launch_args_parse(int argc, char** argv) "eth-peer: port %d >= RTE_MAX_ETHPORTS(%d)\n", n, RTE_MAX_ETHPORTS); - if (cmdline_parse_etheraddr(NULL, port_end, - &peer_addr, sizeof(peer_addr)) < 0) + if (rte_ether_unformat_addr(port_end, + &peer_eth_addrs[n]) < 0) rte_exit(EXIT_FAILURE, "Invalid ethernet address: %s\n", port_end); - for (c = 0; c < 6; c++) - peer_eth_addrs[n].addr_bytes[c] = - peer_addr[c]; nb_peer_eth_addrs++; } #endif