From patchwork Mon Apr 17 15:12:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 751339 X-Patchwork-Delegate: guru@ovn.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w6BbN5qGxz9s0Z for ; Tue, 18 Apr 2017 01:13:04 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 29B6FB30; Mon, 17 Apr 2017 15:13:03 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 75907AB6 for ; Mon, 17 Apr 2017 15:13:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C58D6183 for ; Mon, 17 Apr 2017 15:13:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 431964AEBE for ; Mon, 17 Apr 2017 15:13:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 431964AEBE Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nusiddiq@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 431964AEBE Received: from nusiddiq.blr.redhat.com (dhcp-0-192.blr.redhat.com [10.70.1.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F75D18A68; Mon, 17 Apr 2017 15:12:57 +0000 (UTC) From: nusiddiq@redhat.com To: dev@openvswitch.org Date: Mon, 17 Apr 2017 20:42:15 +0530 Message-Id: <20170417151215.961-1-nusiddiq@redhat.com> In-Reply-To: <20170417151108.750-1-nusiddiq@redhat.com> References: <20170417151108.750-1-nusiddiq@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 17 Apr 2017 15:13:00 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v5 1/3] ovn-util: Add a new util function extract_ip_addresses X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Numan Siddique An upcoming commit will use this function to extract the IP (v4 and v6) addresses from a string without a preceding eth address. Signed-off-by: Numan Siddique Acked-by: Ben Pfaff --- ovn/lib/ovn-util.c | 72 ++++++++++++++++++++++++++++++++++++++---------------- ovn/lib/ovn-util.h | 1 + 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/ovn/lib/ovn-util.c b/ovn/lib/ovn-util.c index 644a5dc..8580391 100644 --- a/ovn/lib/ovn-util.c +++ b/ovn/lib/ovn-util.c @@ -82,19 +82,9 @@ is_dynamic_lsp_address(const char *address) ETH_ADDR_SCAN_ARGS(ea), &n) && address[n] == '\0')); } -/* Extracts the mac, IPv4 and IPv6 addresses from * 'address' which - * should be of the format "MAC [IP1 IP2 ..] .." where IPn should be a - * valid IPv4 or IPv6 address and stores them in the 'ipv4_addrs' and - * 'ipv6_addrs' fields of 'laddrs'. There may be additional content in - * 'address' after "MAC [IP1 IP2 .. ]". The value of 'ofs' that is - * returned indicates the offset where that additional content begins. - * - * Returns true if at least 'MAC' is found in 'address', false otherwise. - * - * The caller must call destroy_lport_addresses(). */ -bool -extract_addresses(const char *address, struct lport_addresses *laddrs, - int *ofs) +static bool +parse_and_store_addresses(const char *address, struct lport_addresses *laddrs, + int *ofs, bool extract_eth_addr) { memset(laddrs, 0, sizeof *laddrs); @@ -102,15 +92,18 @@ extract_addresses(const char *address, struct lport_addresses *laddrs, const char *const start = buf; int buf_index = 0; const char *buf_end = buf + strlen(address); - if (!ovs_scan_len(buf, &buf_index, ETH_ADDR_SCAN_FMT, - ETH_ADDR_SCAN_ARGS(laddrs->ea))) { - laddrs->ea = eth_addr_zero; - *ofs = 0; - return false; - } - snprintf(laddrs->ea_s, sizeof laddrs->ea_s, ETH_ADDR_FMT, - ETH_ADDR_ARGS(laddrs->ea)); + if (extract_eth_addr) { + if (!ovs_scan_len(buf, &buf_index, ETH_ADDR_SCAN_FMT, + ETH_ADDR_SCAN_ARGS(laddrs->ea))) { + laddrs->ea = eth_addr_zero; + *ofs = 0; + return false; + } + + snprintf(laddrs->ea_s, sizeof laddrs->ea_s, ETH_ADDR_FMT, + ETH_ADDR_ARGS(laddrs->ea)); + } ovs_be32 ip4; struct in6_addr ip6; @@ -145,6 +138,23 @@ extract_addresses(const char *address, struct lport_addresses *laddrs, } /* Extracts the mac, IPv4 and IPv6 addresses from * 'address' which + * should be of the format "MAC [IP1 IP2 ..] .." where IPn should be a + * valid IPv4 or IPv6 address and stores them in the 'ipv4_addrs' and + * 'ipv6_addrs' fields of 'laddrs'. There may be additional content in + * 'address' after "MAC [IP1 IP2 .. ]". The value of 'ofs' that is + * returned indicates the offset where that additional content begins. + * + * Returns true if at least 'MAC' is found in 'address', false otherwise. + * + * The caller must call destroy_lport_addresses(). */ +bool +extract_addresses(const char *address, struct lport_addresses *laddrs, + int *ofs) +{ + return parse_and_store_addresses(address, laddrs, ofs, true); +} + +/* Extracts the mac, IPv4 and IPv6 addresses from * 'address' which * should be of the format 'MAC [IP1 IP2 ..]" where IPn should be a * valid IPv4 or IPv6 address and stores them in the 'ipv4_addrs' and * 'ipv6_addrs' fields of 'laddrs'. @@ -166,6 +176,26 @@ extract_lsp_addresses(const char *address, struct lport_addresses *laddrs) return success; } +/* Extracts the IPv4 and IPv6 addresses from * 'address' which + * should be of the format 'IP1 IP2 .." where IPn should be a + * valid IPv4 or IPv6 address and stores them in the 'ipv4_addrs' and + * 'ipv6_addrs' fields of 'laddrs'. + * + * Return true if at least one IP address is found in 'address', + * false otherwise. + * + * The caller must call destroy_lport_addresses(). */ +bool +extract_ip_addresses(const char *address, struct lport_addresses *laddrs) +{ + int ofs; + if (parse_and_store_addresses(address, laddrs, &ofs, false)) { + return (laddrs->n_ipv4_addrs || laddrs->n_ipv6_addrs); + } + + return false; +} + /* Extracts the mac, IPv4 and IPv6 addresses from the * "nbrec_logical_router_port" parameter 'lrp'. Stores the IPv4 and * IPv6 addresses in the 'ipv4_addrs' and 'ipv6_addrs' fields of diff --git a/ovn/lib/ovn-util.h b/ovn/lib/ovn-util.h index 8252283..b3d2125 100644 --- a/ovn/lib/ovn-util.h +++ b/ovn/lib/ovn-util.h @@ -57,6 +57,7 @@ bool is_dynamic_lsp_address(const char *address); bool extract_addresses(const char *address, struct lport_addresses *, int *ofs); bool extract_lsp_addresses(const char *address, struct lport_addresses *); +bool extract_ip_addresses(const char *address, struct lport_addresses *); bool extract_lrp_networks(const struct nbrec_logical_router_port *, struct lport_addresses *); void destroy_lport_addresses(struct lport_addresses *);