From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) by dpdk.org (Postfix) with ESMTP id D2BBE374E for ; Mon, 18 Dec 2017 21:21:51 +0100 (CET) Received: by mail-wr0-f169.google.com with SMTP id u19so9181820wrc.3 for ; Mon, 18 Dec 2017 12:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dqepmq5b3AwLDWOzE2qKpZu/jfVgA2ZG43lTi01Fat4=; b=vy873EQZqWGrZKt/OZQAAcUb2KPPFHx/iX06GLF6mRkqgP2P/X39LVhe914+RcfNM9 bgdkgoFnr4DZjxlx804duJXXecMNuXugVPa5e+Z15osQytR904CXwsLXutxPbzWdNHBu kvxboaKJtcYT+V1cq6jnc//pxcfy/157PI+dS+tNgxBBMStyFr+LbGVZeupAS5Puw3V4 548KWykhJ5f5+IwjCxK7vuYqu6Ufe+oUJvNkMnKSLWY1wzXl7pgBBqCgTQ9coSAWmMCp 3epJFQkOIQ2jd7Kq/REAsVDw3fR0Q32O9ybtlSZgtfdkXQRRPRJem+zxj0BUzTgrw6// n56A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dqepmq5b3AwLDWOzE2qKpZu/jfVgA2ZG43lTi01Fat4=; b=ZnWNWrgGCKGQomL76CxR3H+nINuBqb9V0GRCC2lMObLvLdHFb4sbkuQz1cDUZfGEO8 cYKTFnPt0HLd4ZdWQdMQEkCPJGU2oukIXCRsQZPg8Clbg1eT4HTcJyfxoOXmjuZVuYEH TUfx8eKoVIEckl/JOo84Yq7AN0aHLwkEQZTs9ArK+3cnMLkPMjJrhkDYbehPWJ8HQCuZ ZE1NC5OuGJgwJPdgihJWm1azC3vvMAhuee8UkKVPPN1FJORVuv0ex2x2Oj50DcSJYNlO dX9W3FPZDArYhjEkmyVBhuqbTUdHttZkC0FT83VRR73qBwloy/qJfYvDfNqO4E31FAIP Cofg== X-Gm-Message-State: AKGB3mJNZ3srNwY/oUHwALt/Oeoo4lnPuIBjHlROt5rcsKBxp9kj370g VgKoCG5gyqh6fLJphmYO0/epHJBJ X-Google-Smtp-Source: ACJfBoumEbu+PURgy3zUoadBKkFhRppVfEpjY8Og2T3RbzBjJ46J4Jc3Q24wiMJClAw/Iml7EVOOLA== X-Received: by 10.223.182.73 with SMTP id i9mr1303825wre.113.1513628511532; Mon, 18 Dec 2017 12:21:51 -0800 (PST) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id d10sm163193wmh.15.2017.12.18.12.21.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Dec 2017 12:21:50 -0800 (PST) Date: Mon, 18 Dec 2017 21:21:39 +0100 From: Adrien Mazarguil To: Stephen Hemminger Cc: Ferruh Yigit , dev@dpdk.org Message-ID: <20171218202139.GE4062@6wind.com> References: <20171124172132.GW4062@6wind.com> <20171218162443.12971-1-adrien.mazarguil@6wind.com> <20171218162443.12971-3-adrien.mazarguil@6wind.com> <20171218102629.43798de2@xeon-e3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171218102629.43798de2@xeon-e3> Subject: Re: [dpdk-dev] [PATCH v1 2/3] net/hyperv: implement core functionality 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: , X-List-Received-Date: Mon, 18 Dec 2017 20:21:52 -0000 On Mon, Dec 18, 2017 at 10:26:29AM -0800, Stephen Hemminger wrote: > On Mon, 18 Dec 2017 17:46:23 +0100 > Adrien Mazarguil wrote: > > > +static int > > +ether_addr_from_str(struct ether_addr *eth_addr, const char *str) > > +{ > > + static const uint8_t conv[0x100] = { > > + ['0'] = 0x80, ['1'] = 0x81, ['2'] = 0x82, ['3'] = 0x83, > > + ['4'] = 0x84, ['5'] = 0x85, ['6'] = 0x86, ['7'] = 0x87, > > + ['8'] = 0x88, ['9'] = 0x89, ['a'] = 0x8a, ['b'] = 0x8b, > > + ['c'] = 0x8c, ['d'] = 0x8d, ['e'] = 0x8e, ['f'] = 0x8f, > > + ['A'] = 0x8a, ['B'] = 0x8b, ['C'] = 0x8c, ['D'] = 0x8d, > > + ['E'] = 0x8e, ['F'] = 0x8f, [':'] = 0x40, ['-'] = 0x40, > > + ['\0'] = 0x60, > > + }; > > + uint64_t addr = 0; > > + uint64_t buf = 0; > > + unsigned int i = 0; > > + unsigned int n = 0; > > + uint8_t tmp; > > + > > + do { > > + tmp = conv[(int)*(str++)]; > > + if (!tmp) > > + return -EINVAL; > > + if (tmp & 0x40) { > > + i += (i & 1) + (!i << 1); > > + addr = (addr << (i << 2)) | buf; > > + n += i; > > + buf = 0; > > + i = 0; > > + } else { > > + buf = (buf << 4) | (tmp & 0xf); > > + ++i; > > + } > > + } while (!(tmp & 0x20)); > > + if (n > 12) > > + return -EINVAL; > > + i = RTE_DIM(eth_addr->addr_bytes); > > + while (i) { > > + eth_addr->addr_bytes[--i] = addr & 0xff; > > + addr >>= 8; > > + } > > + return 0; > > +} > > + > > > Why not ether_ntoa? Good question. For the following reasons: - I forgot about the existence of ether_ntoa() and didn't look it up seeing struct ether_addr is (re-)defined by rte_ether.h. What happens when one includes netinet/ether.h together with that file results in various conflicts that trigger a compilation error. This problem should be addressed first. - ether_ntoa() returns a static buffer and is not reentrant, ether_ntoa_r() is but as a GNU extension, I'm not sure it exists on other OSes. Even if this driver is currently targeted at Linux, this is likely not the case for other DPDK code relying on rte_ether.h. - I had ether_addr_from_str()'s code already ready and lying around for a future update in testpmd's flow command parser. No other MAC-48 conversion function I know of is as flexible as this version. The ability to omit ":" and entering partial addresses is a big plus IMO. I think both can coexist on their own merits. Since rte_ether.h needs to be fixed either way, how about I move this function in a separate commit and address the conflict with netinet/ether.h while there? -- Adrien Mazarguil 6WIND