From patchwork Mon Mar 14 19:25:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Moats X-Patchwork-Id: 597233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qP7525p5Qz9snk for ; Tue, 15 Mar 2016 06:25:42 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 0B8BB102A2; Mon, 14 Mar 2016 12:25:41 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 28BF81029E for ; Mon, 14 Mar 2016 12:25:40 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id C1D57161C88 for ; Mon, 14 Mar 2016 13:25:38 -0600 (MDT) X-ASG-Debug-ID: 1457983538-0b32372fb12d5b80001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar6.cudamail.com with ESMTP id EhHEryUJToWvd2Cl (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 14 Mar 2016 13:25:38 -0600 (MDT) X-Barracuda-Envelope-From: rmoats@oc7146733065.ibm.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO eastrmfepo101.cox.net) (68.230.241.213) by mx3-pf1.cudamail.com with SMTP; 14 Mar 2016 19:25:37 -0000 Received-SPF: none (mx3-pf1.cudamail.com: domain at oc7146733065.ibm.com does not designate permitted sender hosts) X-Barracuda-Apparent-Source-IP: 68.230.241.213 X-Barracuda-RBL-IP: 68.230.241.213 Received: from eastrmimpo306.cox.net ([68.230.241.238]) by eastrmfepo101.cox.net (InterMail vM.8.01.05.15 201-2260-151-145-20131218) with ESMTP id <20160314192536.FWFF10784.eastrmfepo101.cox.net@eastrmimpo306.cox.net> for ; Mon, 14 Mar 2016 15:25:36 -0400 Received: from oc7146733065.ibm.com ([68.13.99.247]) by eastrmimpo306.cox.net with cox id VvRb1s00D5LF6cs01vRbkh; Mon, 14 Mar 2016 15:25:35 -0400 X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020205.56E7102F.0345, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=2.1 cv=EtVcrEsA c=1 sm=1 tr=0 a=Jmqd6mthTashISSy/JkQqg==:117 a=Jmqd6mthTashISSy/JkQqg==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=7OsogOcEt9IA:10 a=VnNF1IyMAAAA:8 a=zr4aLUhDEVPzQj_-BmMA:9 X-CM-Score: 0.00 Authentication-Results: cox.net; none Received: by oc7146733065.ibm.com (Postfix, from userid 500) id E57FD1880676; Mon, 14 Mar 2016 14:25:34 -0500 (CDT) X-CudaMail-Envelope-Sender: rmoats@oc7146733065.ibm.com From: Ryan Moats To: dev@openvswitch.org X-CudaMail-MID: CM-V1-313047630 X-CudaMail-DTE: 031416 X-CudaMail-Originating-IP: 68.230.241.213 Date: Mon, 14 Mar 2016 14:25:33 -0500 X-ASG-Orig-Subj: [##CM-V1-313047630##][PATCH] Change TCP connections to support DNS names Message-Id: <1457983533-13440-1-git-send-email-rmoats@us.ibm.com> X-Mailer: git-send-email 1.7.1 X-GBUdb-Analysis: 0, 68.230.241.213, Ugly c=0.323114 p=-0.217391 Source Normal X-MessageSniffer-Rules: 0-0-0-9231-c X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1457983538 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.27840 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Subject: [ovs-dev] [PATCH] Change TCP connections to support DNS names X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" From: RYAN D. MOATS Allow TCP connection strings to also use DNS names in addition to IPv4 and IPv6 addresses. Updated test case "ovsdb-client get-schema-version - tcp socket" to verify. Signed-off-by: RYAN D. MOATS --- lib/stream-tcp.c | 66 +++++++++++++++++++++++++++++++++++++++++++++--- tests/ovsdb-server.at | 2 + 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c index fc5a606..483ff77 100644 --- a/lib/stream-tcp.c +++ b/lib/stream-tcp.c @@ -15,6 +15,7 @@ */ #include +#include #include "stream.h" #include #include @@ -48,17 +49,72 @@ new_tcp_stream(const char *name, int fd, int connect_status, return new_fd_stream(name, fd, connect_status, AF_INET, streamp); } +static bool +is_name_dns(char *suffix) +{ + char *c = suffix; + if (*c == '[') { + return false; + } + while (*c && *c != ':') { + if (isalpha(*c) || *c == '-') { + return true; + } + c++; + } + return false; +} + static int tcp_open(const char *name, char *suffix, struct stream **streamp, uint8_t dscp) { int fd, error; - error = inet_open_active(SOCK_STREAM, suffix, 0, NULL, &fd, dscp); - if (fd >= 0) { - return new_tcp_stream(name, fd, error, streamp); - } else { - VLOG_ERR("%s: connect: %s", name, ovs_strerror(error)); + /* if suffix begins with a domain name, rather than either an IPv4 + * or IPv6 address, then make a call to getaddrinfo to get the IP + * addresses for this call. we'll loop through trying to connect + * to each one and fail if we get through all of them without a + * successful connection. */ + if (is_name_dns(suffix)) { + char *c = strchr(suffix, ':'); + *c = 0; + struct addrinfo hints; + struct addrinfo *servinfo, *p; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; //TODO: make this work with IPv6 + hints.ai_socktype = SOCK_STREAM; + int status = getaddrinfo(suffix, c+1, &hints, &servinfo); + *c = ':'; + if (status != 0) { + VLOG_ERR("%s: getaddrinfo: %s", name, ovs_strerror(status)); + return status; + } + for (p = servinfo; p != NULL; p = p->ai_next) { + char ipv4str[15]; + struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr; + void *addr = &(ipv4->sin_addr); + inet_ntop(p->ai_family, addr, ipv4str, sizeof ipv4str); + char *new_suffix = xasprintf("%s:%s", ipv4str, c+1); + error = inet_open_active(SOCK_STREAM, new_suffix, 0, NULL, &fd, + dscp); + free(new_suffix); + if (fd >= 0) { + freeaddrinfo(servinfo); + return new_tcp_stream(name, fd, error, streamp); + } + } + freeaddrinfo(servinfo); + VLOG_ERR("%s: can not connect, last error: %s", name, + ovs_strerror(error)); return error; + } else { + error = inet_open_active(SOCK_STREAM, suffix, 0, NULL, &fd, dscp); + if (fd >= 0) { + return new_tcp_stream(name, fd, error, streamp); + } else { + VLOG_ERR("%s: connect: %s", name, ovs_strerror(error)); + return error; + } } } diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index c869d6f..44c93b8 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -854,6 +854,8 @@ AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --un PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT]) AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3 ]) +AT_CHECK([ovsdb-client get-schema-version tcp:localhost:$TCP_PORT ordinals], [0], [5.1.3 +]) OVSDB_SERVER_SHUTDOWN AT_CLEANUP])