{"id":833410,"url":"http://patchwork.ozlabs.org/api/1.2/patches/833410/?format=json","web_url":"http://patchwork.ozlabs.org/project/openvswitch/patch/20171102161359.7344-2-mmichels@redhat.com/","project":{"id":47,"url":"http://patchwork.ozlabs.org/api/1.2/projects/47/?format=json","name":"Open vSwitch","link_name":"openvswitch","list_id":"ovs-dev.openvswitch.org","list_email":"ovs-dev@openvswitch.org","web_url":"http://openvswitch.org/","scm_url":"git@github.com:openvswitch/ovs.git","webscm_url":"https://github.com/openvswitch/ovs","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20171102161359.7344-2-mmichels@redhat.com>","list_archive_url":null,"date":"2017-11-02T16:13:56","name":"[ovs-dev,v3,1/4] Add general-purpose IP/port parsing function.","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"1562627bef20ca724bca4b6175470c46749b9a0a","submitter":{"id":71978,"url":"http://patchwork.ozlabs.org/api/1.2/people/71978/?format=json","name":"Mark Michelson","email":"mmichels@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/openvswitch/patch/20171102161359.7344-2-mmichels@redhat.com/mbox/","series":[{"id":11537,"url":"http://patchwork.ozlabs.org/api/1.2/series/11537/?format=json","web_url":"http://patchwork.ozlabs.org/project/openvswitch/list/?series=11537","date":"2017-11-02T16:13:56","name":"Add support for IPv6 load balancers","version":3,"mbox":"http://patchwork.ozlabs.org/series/11537/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/833410/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/833410/checks/","tags":{},"related":[],"headers":{"Return-Path":"<ovs-dev-bounces@openvswitch.org>","X-Original-To":["incoming@patchwork.ozlabs.org","dev@openvswitch.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","ovs-dev@mail.linuxfoundation.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=openvswitch.org\n\t(client-ip=140.211.169.12; helo=mail.linuxfoundation.org;\n\tenvelope-from=ovs-dev-bounces@openvswitch.org;\n\treceiver=<UNKNOWN>)","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=mmichels@redhat.com"],"Received":["from mail.linuxfoundation.org (mail.linuxfoundation.org\n\t[140.211.169.12])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySVWz1ctHz9t34\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 03:14:06 +1100 (AEDT)","from mail.linux-foundation.org (localhost [127.0.0.1])\n\tby mail.linuxfoundation.org (Postfix) with ESMTP id 87D0EAE1;\n\tThu,  2 Nov 2017 16:14:03 +0000 (UTC)","from smtp1.linuxfoundation.org (smtp1.linux-foundation.org\n\t[172.17.192.35])\n\tby mail.linuxfoundation.org (Postfix) with ESMTPS id 174A69F8\n\tfor <dev@openvswitch.org>; Thu,  2 Nov 2017 16:14:02 +0000 (UTC)","from mx1.redhat.com (mx1.redhat.com [209.132.183.28])\n\tby smtp1.linuxfoundation.org (Postfix) with ESMTPS id 770A64CE\n\tfor <dev@openvswitch.org>; Thu,  2 Nov 2017 16:14:01 +0000 (UTC)","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id F119361D0A\n\tfor <dev@openvswitch.org>; Thu,  2 Nov 2017 16:14:00 +0000 (UTC)","from monae.redhat.com (ovpn-123-202.rdu2.redhat.com\n\t[10.10.123.202])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id A664660BE5\n\tfor <dev@openvswitch.org>; Thu,  2 Nov 2017 16:14:00 +0000 (UTC)"],"X-Greylist":["domain auto-whitelisted by SQLgrey-1.7.6","Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.39]);\n\tThu, 02 Nov 2017 16:14:01 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com F119361D0A","From":"Mark Michelson <mmichels@redhat.com>","To":"dev@openvswitch.org","Date":"Thu,  2 Nov 2017 11:13:56 -0500","Message-Id":"<20171102161359.7344-2-mmichels@redhat.com>","In-Reply-To":"<20171102161359.7344-1-mmichels@redhat.com>","References":"<20171102161359.7344-1-mmichels@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Spam-Status":"No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,\n\tRP_MATCHES_RCVD autolearn=disabled version=3.3.1","X-Spam-Checker-Version":"SpamAssassin 3.3.1 (2010-03-16) on\n\tsmtp1.linux-foundation.org","Subject":"[ovs-dev] [PATCH v3 1/4] Add general-purpose IP/port parsing\n\tfunction.","X-BeenThere":"ovs-dev@openvswitch.org","X-Mailman-Version":"2.1.12","Precedence":"list","List-Id":"<ovs-dev.openvswitch.org>","List-Unsubscribe":"<https://mail.openvswitch.org/mailman/options/ovs-dev>,\n\t<mailto:ovs-dev-request@openvswitch.org?subject=unsubscribe>","List-Archive":"<http://mail.openvswitch.org/pipermail/ovs-dev/>","List-Post":"<mailto:ovs-dev@openvswitch.org>","List-Help":"<mailto:ovs-dev-request@openvswitch.org?subject=help>","List-Subscribe":"<https://mail.openvswitch.org/mailman/listinfo/ovs-dev>,\n\t<mailto:ovs-dev-request@openvswitch.org?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"ovs-dev-bounces@openvswitch.org","Errors-To":"ovs-dev-bounces@openvswitch.org"},"content":"OVS has functions for parsing IPv4 addresses, parsing IPv4 addresses\nwith a port, and parsing IPv6 addresses. What is lacking though is a\nfunction that can take an IPv4 or IPv6 address, with or without a port.\n\nThis commit adds ipv46_parse(), which breaks the given input string into\nits component parts and stores them in a sockaddr_storage structure. The\nfunction accepts flags that determine how it should behave if a port is\npresent in the input string.\n\nSigned-off-by: Mark Michelson <mmichels@redhat.com>\n---\n lib/packets.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n lib/packets.h | 10 ++++++++\n 2 files changed, 88 insertions(+)","diff":"diff --git a/lib/packets.c b/lib/packets.c\nindex 74d87eda8..51044df4c 100644\n--- a/lib/packets.c\n+++ b/lib/packets.c\n@@ -22,6 +22,8 @@\n #include <netinet/ip6.h>\n #include <netinet/icmp6.h>\n #include <stdlib.h>\n+#include <sys/types.h>\n+#include <netdb.h>\n #include \"byte-order.h\"\n #include \"csum.h\"\n #include \"crc32c.h\"\n@@ -656,6 +658,82 @@ ip_parse_cidr(const char *s, ovs_be32 *ip, unsigned int *plen)\n     return error;\n }\n \n+/* Parses the string into an IPv4 or IPv6 address.\n+ * The port flags act as follows:\n+ * * PORT_OPTIONAL: A port may be present but is not required\n+ * * PORT_REQUIRED: A port must be present\n+ * * PORT_FORBIDDEN: A port must not be present\n+ */\n+char * OVS_WARN_UNUSED_RESULT\n+ipv46_parse(const char *s, enum port_flags flags, struct sockaddr_storage *ss)\n+{\n+    char *error = NULL;\n+\n+    char *copy;\n+    copy = xstrdup(s);\n+\n+    char *addr;\n+    char *port;\n+    if (*copy == '[') {\n+        char *end;\n+\n+        addr = copy + 1;\n+        end = strchr(addr, ']');\n+        if (!end) {\n+            error = xasprintf(\"No closing bracket on address %s\", s);\n+            goto finish;\n+        }\n+        *end++ = '\\0';\n+        if (*end == ':') {\n+            port = end + 1;\n+        } else {\n+            port = NULL;\n+        }\n+    } else {\n+        addr = copy;\n+        port = strchr(copy, ':');\n+        if (port) {\n+            if (strchr(port + 1, ':')) {\n+                port = NULL;\n+            } else {\n+                *port++ = '\\0';\n+            }\n+        }\n+    }\n+\n+    if (port && !*port) {\n+        error = xasprintf(\"Port is an empty string\");\n+        goto finish;\n+    }\n+\n+    if (port && flags == PORT_FORBIDDEN) {\n+        error = xasprintf(\"Port forbidden in address %s\", s);\n+        goto finish;\n+    } else if (!port && flags == PORT_REQUIRED) {\n+        error = xasprintf(\"Port required in address %s\", s);\n+        goto finish;\n+    }\n+\n+    struct addrinfo hints = {\n+        .ai_flags = AI_NUMERICHOST | AI_NUMERICSERV,\n+        .ai_family = AF_UNSPEC,\n+    };\n+    struct addrinfo *res;\n+    int status;\n+    status = getaddrinfo(addr, port, &hints, &res);\n+    if (status) {\n+        error = xasprintf(\"Error parsing address %s: %s\",\n+                s, gai_strerror(status));\n+        goto finish;\n+    }\n+    memcpy(ss, res->ai_addr, res->ai_addrlen);\n+    freeaddrinfo(res);\n+\n+finish:\n+    free(copy);\n+    return error;\n+}\n+\n /* Parses string 's', which must be an IPv6 address.  Stores the IPv6 address\n  * into '*ip'.  Returns true if successful, otherwise false. */\n bool\ndiff --git a/lib/packets.h b/lib/packets.h\nindex 057935cbf..c5915a0f8 100644\n--- a/lib/packets.h\n+++ b/lib/packets.h\n@@ -1339,6 +1339,16 @@ struct in6_addr ipv6_create_mask(int mask);\n int ipv6_count_cidr_bits(const struct in6_addr *netmask);\n bool ipv6_is_cidr(const struct in6_addr *netmask);\n \n+enum port_flags {\n+    PORT_OPTIONAL,\n+    PORT_REQUIRED,\n+    PORT_FORBIDDEN,\n+};\n+\n+char *ipv46_parse(const char *s, enum port_flags flags,\n+                  struct sockaddr_storage *ss)\n+    OVS_WARN_UNUSED_RESULT;\n+\n bool ipv6_parse(const char *s, struct in6_addr *ip);\n char *ipv6_parse_masked(const char *s, struct in6_addr *ipv6,\n                         struct in6_addr *mask);\n","prefixes":["ovs-dev","v3","1/4"]}