From patchwork Thu Oct 22 17:28:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 534503 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 0FB13141302 for ; Fri, 23 Oct 2015 04:29:24 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 9B5601089C; Thu, 22 Oct 2015 10:29:22 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 4A2F010865 for ; Thu, 22 Oct 2015 10:29:21 -0700 (PDT) Received: from bar2.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 35B5E1E00B3 for ; Thu, 22 Oct 2015 11:29:20 -0600 (MDT) X-ASG-Debug-ID: 1445534958-03dc533d52e2890001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar2.cudamail.com with ESMTP id dVbzHjT9nqTAFfWo (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 22 Oct 2015 11:29:19 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 22 Oct 2015 17:29:18 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 76EC58EA37 for ; Thu, 22 Oct 2015 17:29:17 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-113-35.phx2.redhat.com [10.3.113.35]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9MHTEAU023789 for ; Thu, 22 Oct 2015 13:29:16 -0400 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org X-CudaMail-MID: CM-E2-1021059366 X-CudaMail-DTE: 102215 X-CudaMail-Originating-IP: 209.132.183.28 Date: Thu, 22 Oct 2015 15:28:54 -0200 X-ASG-Orig-Subj: [##CM-E2-1021059366##][PATCH 01/15] lib: add ipv6 helper functions for tnl_config Message-Id: <1445534948-10538-2-git-send-email-cascardo@redhat.com> In-Reply-To: <1445534948-10538-1-git-send-email-cascardo@redhat.com> References: <1445534948-10538-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-GBUdb-Analysis: 0, 209.132.183.28, Ugly c=0 p=0 Source New X-MessageSniffer-Rules: 0-0-0-6905-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1445534959 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.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=3.0 tests=BSF_SC5_MJ1963, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.23722 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 01/15] lib: add ipv6 helper functions for tnl_config 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: Jiri Benc These functions will be used by the next patches. Signed-off-by: Jiri Benc Signed-off-by: Thadeu Lima de Souza Cascardo --- lib/smap.c | 11 +++++++++++ lib/smap.h | 1 + lib/socket-util.c | 9 +++++++++ lib/socket-util.h | 1 + 4 files changed, 22 insertions(+) diff --git a/lib/smap.c b/lib/smap.c index 1d59f56..2c41013 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -95,6 +95,17 @@ smap_add_format(struct smap *smap, const char *key, const char *format, ...) hash_bytes(key, key_len, 0)); } +/* Adds 'key' paired with a string representation of 'addr'. It is the + * caller's responsibility to avoid duplicate keys if desirable. */ +void +smap_add_ipv6(struct smap *smap, const char *key, struct in6_addr *addr) +{ + char buf[INET6_ADDRSTRLEN]; + + inet_ntop(AF_INET6, addr, buf, sizeof buf); + smap_add(smap, key, buf); +} + /* Searches for 'key' in 'smap'. If it does not already exists, adds it. * Otherwise, changes its value to 'value'. */ void diff --git a/lib/smap.h b/lib/smap.h index 3bfbb71..489497a 100644 --- a/lib/smap.h +++ b/lib/smap.h @@ -66,6 +66,7 @@ struct smap_node *smap_add_nocopy(struct smap *, char *, char *); bool smap_add_once(struct smap *, const char *, const char *); void smap_add_format(struct smap *, const char *key, const char *, ...) OVS_PRINTF_FORMAT(3, 4); +void smap_add_ipv6(struct smap *, const char *, struct in6_addr *); void smap_replace(struct smap *, const char *, const char *); void smap_remove(struct smap *, const char *); diff --git a/lib/socket-util.c b/lib/socket-util.c index 206e17b..97ee01b 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -136,6 +136,15 @@ set_dscp(int fd, int family, uint8_t dscp) return retval ? sock_errno() : 0; } +/* Checks whether 'host_name' is an IPv4 or IPv6 address. It is assumed + * that 'host_name' is valid. Returns false if it is IPv4 address, true if + * it is IPv6 address. */ +bool +addr_is_ipv6(const char *host_name) +{ + return strchr(host_name, ':') != NULL; +} + /* Translates 'host_name', which must be a string representation of an IP * address, into a numeric IP address in '*addr'. Returns 0 if successful, * otherwise a positive errno value. */ diff --git a/lib/socket-util.h b/lib/socket-util.h index 8015c7f..c3c1224 100644 --- a/lib/socket-util.h +++ b/lib/socket-util.h @@ -32,6 +32,7 @@ void xset_nonblocking(int fd); void setsockopt_tcp_nodelay(int fd); int set_dscp(int fd, int family, uint8_t dscp); +bool addr_is_ipv6(const char *host_name); int lookup_ip(const char *host_name, struct in_addr *address); int lookup_ipv6(const char *host_name, struct in6_addr *address);