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 C4CF4A00E6 for ; Fri, 17 May 2019 09:09:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C0E6B2BAF; Fri, 17 May 2019 09:09:01 +0200 (CEST) Received: from mail-vk1-f196.google.com (mail-vk1-f196.google.com [209.85.221.196]) by dpdk.org (Postfix) with ESMTP id C62D82B86 for ; Fri, 17 May 2019 09:09:00 +0200 (CEST) Received: by mail-vk1-f196.google.com with SMTP id l199so1758629vke.3 for ; Fri, 17 May 2019 00:09:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b5R2PceuxaqkEFVW4RX6D9AQDpW3VlLL42CWsdCfB0o=; b=WyfzCzdKSKUKf4iiKG9NVTfP3w1uUmitYOHCSaFX3rn5HdWeDKXm1gzpf2IVGgdC86 2CmgeuG9pFOyePoJK0zG3x7oKsbvZ6SglIW1JUju1z/ryp5C4cOkQ+B1E2GCOJGdBr6J Y5mJogdg/KV7mCXCUu4Zjf3J9/9uh/KVhwr5R93A4wwX8r8lvoe5FSUb9txFf8N/iKdR kRT2tgVWybYZy9xZqDa/hfPEQ369SwuX/VOxU+0yNwxkHN7K3Kb5jhxLkX90DwHZjlW1 uEP91cMlQHOsZIJkQBQMDb7UVQCiYONHQTaw+jSPG9K3nQAOkaJD9qq4DQvysJHiXkhy 4fBA== X-Gm-Message-State: APjAAAUXxcWzQP9SC5QX1uz3gh7szJ2uL4l22OM77yTInRflCfkuADil nUKaEG+FONwQjrj5pnv4426+Id97NKBbjHiMNrhSSGXF X-Google-Smtp-Source: APXvYqxXB0KTsBo5PYk8ld7RI8hzcjyEpAC8z5PT77F606w2Drq7oMLV88r7jIa/3WQzdAH98IExDoV9pPb5dBqNVns= X-Received: by 2002:a1f:4907:: with SMTP id w7mr1524792vka.85.1558076940087; Fri, 17 May 2019 00:09:00 -0700 (PDT) MIME-Version: 1.0 References: <20190516180427.17270-1-stephen@networkplumber.org> <20190516180427.17270-5-stephen@networkplumber.org> In-Reply-To: <20190516180427.17270-5-stephen@networkplumber.org> From: David Marchand Date: Fri, 17 May 2019 09:08:48 +0200 Message-ID: To: Stephen Hemminger Cc: dev Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH v2 4/7] 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" On Thu, May 16, 2019 at 8:05 PM Stephen Hemminger < stephen@networkplumber.org> wrote: > Make a function that coresponds with eth_aton_r which can > corresponds 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 | 47 ++++++++++++++++++++++++++++++ > lib/librte_net/rte_ether.h | 14 +++++++++ > lib/librte_net/rte_net_version.map | 2 +- > 3 files changed, 62 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_net/rte_ether.c b/lib/librte_net/rte_ether.c > index d4b41f122a16..12d9af58b5c3 100644 > --- a/lib/librte_net/rte_ether.c > +++ b/lib/librte_net/rte_ether.c > @@ -27,3 +27,50 @@ 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 > +ether_unformat_addr(const char *s, struct 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); > + > Still weak to trailing characters. + 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); > Idem trailing characters. + 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 ed178a1f1736..0fa4481d266b 100644 > --- a/lib/librte_net/rte_ether.h > +++ b/lib/librte_net/rte_ether.h > @@ -249,6 +249,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..41d6a5943515 100644 > --- a/lib/librte_net/rte_net_version.map > +++ b/lib/librte_net/rte_net_version.map > @@ -20,10 +20,10 @@ DPDK_19.08 { > eth_format_addr; > } DPDK_17.05; > > - > And same comment on the function name than in the rfc patch. EXPERIMENTAL { > global: > > rte_net_make_rarp_packet; > rte_net_skip_ip6_ext; > + eth_unformat_addr; > }; > -- > 2.20.1 > > -- David Marchand