From patchwork Tue Sep 29 22:10:57 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: 524038 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 4E79C14016A for ; Wed, 30 Sep 2015 08:11:48 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 16040108F4; Tue, 29 Sep 2015 15:11:32 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 7E03D108F8 for ; Tue, 29 Sep 2015 15:11:30 -0700 (PDT) Received: from bar4.cudamail.com (bar2 [192.168.15.2]) by mx3v1.cudamail.com (Postfix) with ESMTP id 0796F618B6F for ; Tue, 29 Sep 2015 16:11:30 -0600 (MDT) X-ASG-Debug-ID: 1443564689-03dc2142474f770001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar4.cudamail.com with ESMTP id xNtzL9UtlLtTrsO1 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 29 Sep 2015 16:11:29 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 29 Sep 2015 22:11:19 -0000 Received-SPF: pass (mx3-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-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 740FA8E706 for ; Tue, 29 Sep 2015 22:11:18 +0000 (UTC) Received: from indiana.gru.redhat.com ([10.96.73.207]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8TMBEdI014409 for ; Tue, 29 Sep 2015 18:11:18 -0400 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org X-CudaMail-MID: CM-V2-928077512 X-CudaMail-DTE: 092915 X-CudaMail-Originating-IP: 209.132.183.28 Date: Tue, 29 Sep 2015 19:10:57 -0300 X-ASG-Orig-Subj: [##CM-V2-928077512##][RFC PATCH 6/7] tnl-arp-cache: add IPv6 Neighbor Discovery support Message-Id: <1443564658-12251-4-git-send-email-cascardo@redhat.com> In-Reply-To: <1443564658-12251-1-git-send-email-cascardo@redhat.com> References: <1443564658-12251-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-GBUdb-Analysis: 0, 209.132.183.28, Ugly c=0.279065 p=-0.2 Source Normal X-MessageSniffer-Rules: 0-0-0-18721-c X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1443564689 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.23025 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] [RFC PATCH 6/7] tnl-arp-cache: add IPv6 Neighbor Discovery support 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" Uses IPv4-mapped IPv6 addresses to store IPv4 addresses, and add support for Neighbor Discovery snooping. Signed-off-by: Thadeu Lima de Souza Cascardo --- lib/tnl-arp-cache.c | 97 ++++++++++++++++++++++++++++++++++++-------- lib/tnl-arp-cache.h | 5 +++ ofproto/ofproto-dpif-xlate.c | 1 + tests/tunnel-push-pop.at | 8 ++-- 4 files changed, 89 insertions(+), 22 deletions(-) diff --git a/lib/tnl-arp-cache.c b/lib/tnl-arp-cache.c index ddfd26f..0ced4f6 100644 --- a/lib/tnl-arp-cache.c +++ b/lib/tnl-arp-cache.c @@ -14,8 +14,11 @@ * limitations under the License. */ +#include "tnl-arp-cache.h" + #include #include +#include #include #include "bitmap.h" @@ -32,7 +35,6 @@ #include "seq.h" #include "socket-util.h" #include "timeval.h" -#include "tnl-arp-cache.h" #include "unaligned.h" #include "unixctl.h" #include "util.h" @@ -44,7 +46,7 @@ struct tnl_arp_entry { struct cmap_node cmap_node; - ovs_be32 ip; + struct in6_addr ip; struct eth_addr mac; time_t expires; /* Expiration time. */ char br_name[IFNAMSIZ]; @@ -53,13 +55,21 @@ struct tnl_arp_entry { static struct cmap table; static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; +static uint32_t +tnl_arp_hash(const struct in6_addr *ip) +{ + return hash_bytes(ip->s6_addr, 16, 0); +} + static struct tnl_arp_entry * -tnl_arp_lookup__(const char br_name[IFNAMSIZ], ovs_be32 dst) +tnl_arp_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst) { struct tnl_arp_entry *arp; + uint32_t hash; - CMAP_FOR_EACH_WITH_HASH (arp, cmap_node, (OVS_FORCE uint32_t) dst, &table) { - if (arp->ip == dst && !strcmp(arp->br_name, br_name)) { + hash = tnl_arp_hash(dst); + CMAP_FOR_EACH_WITH_HASH (arp, cmap_node, hash, &table) { + if (ipv6_addr_equals(&arp->ip, dst) && !strcmp(arp->br_name, br_name)) { arp->expires = time_now() + ARP_ENTRY_DEFAULT_IDLE_TIME; return arp; } @@ -73,8 +83,11 @@ tnl_arp_lookup(const char br_name[IFNAMSIZ], ovs_be32 dst, { struct tnl_arp_entry *arp; int res = ENOENT; + struct in6_addr dst6; - arp = tnl_arp_lookup__(br_name, dst); + in6_addr_set_mapped_ipv4(&dst6, dst); + + arp = tnl_arp_lookup__(br_name, &dst6); if (arp) { *mac = arp->mac; res = 0; @@ -83,6 +96,21 @@ tnl_arp_lookup(const char br_name[IFNAMSIZ], ovs_be32 dst, return res; } +int +tnl_nd_lookup(const char br_name[IFNAMSIZ], const struct in6_addr *dst, + struct eth_addr *mac) +{ + struct tnl_arp_entry *arp; + int res = ENOENT; + + arp = tnl_arp_lookup__(br_name, dst); + if (arp) { + *mac = arp->mac; + res = 0; + } + return res; +} + static void arp_entry_free(struct tnl_arp_entry *arp) { @@ -92,12 +120,14 @@ arp_entry_free(struct tnl_arp_entry *arp) static void tnl_arp_delete(struct tnl_arp_entry *arp) { - cmap_remove(&table, &arp->cmap_node, (OVS_FORCE uint32_t) arp->ip); + uint32_t hash = tnl_arp_hash(&arp->ip); + cmap_remove(&table, &arp->cmap_node, hash); ovsrcu_postpone(arp_entry_free, arp); } static void -tnl_arp_set(const char name[IFNAMSIZ], ovs_be32 dst, const struct eth_addr mac) +tnl_arp_set__(const char name[IFNAMSIZ], const struct in6_addr *dst, + const struct eth_addr mac) { ovs_mutex_lock(&mutex); struct tnl_arp_entry *arp = tnl_arp_lookup__(name, dst); @@ -113,14 +143,24 @@ tnl_arp_set(const char name[IFNAMSIZ], ovs_be32 dst, const struct eth_addr mac) arp = xmalloc(sizeof *arp); - arp->ip = dst; + arp->ip = *dst; arp->mac = mac; arp->expires = time_now() + ARP_ENTRY_DEFAULT_IDLE_TIME; ovs_strlcpy(arp->br_name, name, sizeof arp->br_name); - cmap_insert(&table, &arp->cmap_node, (OVS_FORCE uint32_t) arp->ip); + uint32_t hash = tnl_arp_hash(&arp->ip); + cmap_insert(&table, &arp->cmap_node, hash); ovs_mutex_unlock(&mutex); } +static void +tnl_arp_set(const char name[IFNAMSIZ], ovs_be32 dst, + const struct eth_addr mac) +{ + struct in6_addr dst6; + in6_addr_set_mapped_ipv4(&dst6, dst); + tnl_arp_set__(name, &dst6, mac); +} + int tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, const char name[IFNAMSIZ]) @@ -139,6 +179,26 @@ tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, return 0; } +int +tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc, + const char name[IFNAMSIZ]) +{ + if (flow->dl_type != htons(ETH_TYPE_IPV6) || + flow->nw_proto != IPPROTO_ICMPV6 || + flow->tp_dst != htons(0) || + flow->tp_src != htons(ND_NEIGHBOR_ADVERT)) { + return EINVAL; + } + + memset(&wc->masks.ipv6_src, 0xff, sizeof wc->masks.ipv6_src); + memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst); + memset(&wc->masks.nd_target, 0xff, sizeof wc->masks.nd_target); + memset(&wc->masks.arp_tha, 0xff, sizeof wc->masks.arp_tha); + + tnl_arp_set__(name, &flow->nd_target, flow->arp_tha); + return 0; +} + void tnl_arp_cache_run(void) { @@ -185,8 +245,11 @@ tnl_arp_cache_add(struct unixctl_conn *conn, int argc OVS_UNUSED, const char *br_name = argv[1]; struct eth_addr mac; struct in_addr ip; + struct in6_addr ip6; - if (lookup_ip(argv[2], &ip)) { + if (lookup_ip(argv[2], &ip) == 0) { + in6_addr_set_mapped_ipv4(&ip6, ip.s_addr); + } else if (lookup_ipv6(argv[2], &ip6) != 0) { unixctl_command_reply_error(conn, "bad IP address"); return; } @@ -196,12 +259,10 @@ tnl_arp_cache_add(struct unixctl_conn *conn, int argc OVS_UNUSED, return; } - tnl_arp_set(br_name, ip.s_addr, mac); + tnl_arp_set__(br_name, &ip6, mac); unixctl_command_reply(conn, "OK"); } -#define MAX_IP_ADDR_LEN 17 - static void tnl_arp_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED, const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) @@ -209,16 +270,16 @@ tnl_arp_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED, struct ds ds = DS_EMPTY_INITIALIZER; struct tnl_arp_entry *arp; - ds_put_cstr(&ds, "IP MAC Bridge\n"); - ds_put_cstr(&ds, "=============================================\n"); + ds_put_cstr(&ds, "IP MAC Bridge\n"); + ds_put_cstr(&ds, "==========================================================================\n"); ovs_mutex_lock(&mutex); CMAP_FOR_EACH(arp, cmap_node, &table) { int start_len, need_ws; start_len = ds.length; - ds_put_format(&ds, IP_FMT, IP_ARGS(arp->ip)); + print_ipv6_mapped(&ds, &arp->ip); - need_ws = MAX_IP_ADDR_LEN - (ds.length - start_len); + need_ws = INET6_ADDRSTRLEN - (ds.length - start_len); ds_put_char_multiple(&ds, ' ', need_ws); ds_put_format(&ds, ETH_ADDR_FMT" %s\n", diff --git a/lib/tnl-arp-cache.h b/lib/tnl-arp-cache.h index acc4ff7..7620c15 100644 --- a/lib/tnl-arp-cache.h +++ b/lib/tnl-arp-cache.h @@ -37,4 +37,9 @@ int tnl_arp_lookup(const char dev_name[], ovs_be32 dst, struct eth_addr *mac); void tnl_arp_cache_init(void); void tnl_arp_cache_run(void); +int tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc, + const char dev_name[]); +int tnl_nd_lookup(const char dev_name[], const struct in6_addr *dst, + struct eth_addr *mac); + #endif diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index bdb667f..7f8d5f9 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -4128,6 +4128,7 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len, if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) { tnl_arp_snoop(flow, wc, ctx->xbridge->name); + tnl_nd_snoop(flow, wc, ctx->xbridge->name); } /* dl_type already in the mask, not set below. */ diff --git a/tests/tunnel-push-pop.at b/tests/tunnel-push-pop.at index 98f22ea..507d4df 100644 --- a/tests/tunnel-push-pop.at +++ b/tests/tunnel-push-pop.at @@ -41,10 +41,10 @@ AT_CHECK([ovs-appctl netdev-dummy/receive br0 'recirc_id(0),in_port(100),eth(src AT_CHECK([ovs-appctl netdev-dummy/receive br0 'recirc_id(0),in_port(100),eth(src=f8:bc:12:44:34:b7,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0806),arp(sip=1.1.2.93,tip=1.1.2.88,op=1,sha=f8:bc:12:44:34:b7,tha=00:00:00:00:00:00)']) AT_CHECK([ovs-appctl tnl/arp/show], [0], [dnl -IP MAC Bridge -============================================= -1.1.2.92 f8:bc:12:44:34:b6 br0 -1.1.2.93 f8:bc:12:44:34:b7 br0 +IP MAC Bridge +========================================================================== +1.1.2.92 f8:bc:12:44:34:b6 br0 +1.1.2.93 f8:bc:12:44:34:b7 br0 ]) AT_CHECK([ovs-appctl tnl/ports/show |sort], [0], [dnl