From patchwork Wed Sep 2 23:44:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 513697 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 2968A1401F0 for ; Thu, 3 Sep 2015 09:44:42 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id C203A106C0; Wed, 2 Sep 2015 16:44:25 -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 5549810703 for ; Wed, 2 Sep 2015 16:44:24 -0700 (PDT) Received: from bar4.cudamail.com (bar2 [192.168.15.2]) by mx3v1.cudamail.com (Postfix) with ESMTP id D5479618DF1 for ; Wed, 2 Sep 2015 17:44:23 -0600 (MDT) X-ASG-Debug-ID: 1441237463-03dc211ad645c600001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar4.cudamail.com with ESMTP id yjK6wIHwCYMIF6b2 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 02 Sep 2015 17:44:23 -0600 (MDT) X-Barracuda-Envelope-From: blp@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mail-pa0-f44.google.com) (209.85.220.44) by mx3-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 2 Sep 2015 23:44:22 -0000 Received-SPF: unknown (mx3-pf2.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.44 Received: by pacfv12 with SMTP id fv12so26686175pac.2 for ; Wed, 02 Sep 2015 16:44:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yL9mg4p2wiyzaChcLSOlSqyF7yo6rV7iZJdbOKEZxcA=; b=NrRXXIyH8JO6YurmlBzW5OvM4V1vhgG6FRFpY4Ancwcrwr1SqFhLxWYZKapg6fnUUU j0PXUOhMw05oWNadwSxSreJ0A8Er7u9Qqo2YmeKCRXSc/+R14A8twHsVe33BiCmxWxqQ A4hXmy7UAIrKhrCa1riqYonFJysxF6JJontPXf5x7Al1S9kf5nHrGDwIJ0ea+LFYf/gP QjY2LGruYWMqicJeEHy3e4eP/Bos78Am7IUZLOWrDo5kQ1XVoTVG5HCTwijAdBUiCL63 GhLdiQTkytsjJ2VV2VBnaKW8hVjfb/GNuDBNeVxrTMDUoCASNTrfJE4wLmH91qATSm4y lFfw== X-Gm-Message-State: ALoCoQmuh7aX3p2PfgzcLB5LZtWerwPAjRR5UZK1o12oaJHXZK8C7Nb60XGLZelsMKqcnXYIsqsO X-Received: by 10.66.147.131 with SMTP id tk3mr61648273pab.104.1441237462529; Wed, 02 Sep 2015 16:44:22 -0700 (PDT) Received: from sigabrt.benpfaff.org ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id f5sm23046151pas.23.2015.09.02.16.44.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Sep 2015 16:44:21 -0700 (PDT) X-CudaMail-Envelope-Sender: blp@nicira.com X-Barracuda-Apparent-Source-IP: 208.91.2.4 From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-901063288 X-CudaMail-DTE: 090215 X-CudaMail-Originating-IP: 209.85.220.44 Date: Wed, 2 Sep 2015 16:44:01 -0700 X-ASG-Orig-Subj: [##CM-V2-901063288##][PATCH v2 04/14] tnl-arp-cache: Add a command to add or modify an ARP cache entry. Message-Id: <1441237451-17940-4-git-send-email-blp@nicira.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1441237451-17940-1-git-send-email-blp@nicira.com> References: <1441237451-17940-1-git-send-email-blp@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1441237463 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2 04/14] tnl-arp-cache: Add a command to add or modify an ARP cache entry. 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" This allows the ARP cache to be prepopulated for testing purposes, so that tests don't lose the first packet to each destination. (I guess this feature could have other uses too.) Signed-off-by: Ben Pfaff Acked-by: Andy Zhou --- lib/tnl-arp-cache.c | 67 +++++++++++++++++++++++++++++------------ ofproto/ofproto-tnl-unixctl.man | 4 +++ 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/lib/tnl-arp-cache.c b/lib/tnl-arp-cache.c index 3107631..ddfd26f 100644 --- a/lib/tnl-arp-cache.c +++ b/lib/tnl-arp-cache.c @@ -30,6 +30,7 @@ #include "packets.h" #include "poll-loop.h" #include "seq.h" +#include "socket-util.h" #include "timeval.h" #include "tnl-arp-cache.h" #include "unaligned.h" @@ -95,28 +96,16 @@ tnl_arp_delete(struct tnl_arp_entry *arp) ovsrcu_postpone(arp_entry_free, arp); } -int -tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, - const char name[IFNAMSIZ]) +static void +tnl_arp_set(const char name[IFNAMSIZ], ovs_be32 dst, const struct eth_addr mac) { - struct tnl_arp_entry *arp; - - if (flow->dl_type != htons(ETH_TYPE_ARP)) { - return EINVAL; - } - - /* Exact Match on all ARP flows. */ - memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto); - memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src); - memset(&wc->masks.arp_sha, 0xff, sizeof wc->masks.arp_sha); - ovs_mutex_lock(&mutex); - arp = tnl_arp_lookup__(name, flow->nw_src); + struct tnl_arp_entry *arp = tnl_arp_lookup__(name, dst); if (arp) { - if (eth_addr_equals(arp->mac, flow->arp_sha)) { + if (eth_addr_equals(arp->mac, mac)) { arp->expires = time_now() + ARP_ENTRY_DEFAULT_IDLE_TIME; ovs_mutex_unlock(&mutex); - return 0; + return; } tnl_arp_delete(arp); seq_change(tnl_conf_seq); @@ -124,12 +113,29 @@ tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, arp = xmalloc(sizeof *arp); - arp->ip = flow->nw_src; - arp->mac = flow->arp_sha; + 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); ovs_mutex_unlock(&mutex); +} + +int +tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc, + const char name[IFNAMSIZ]) +{ + if (flow->dl_type != htons(ETH_TYPE_ARP)) { + return EINVAL; + } + + /* Exact Match on all ARP flows. */ + memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto); + memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src); + memset(&wc->masks.arp_sha, 0xff, sizeof wc->masks.arp_sha); + + tnl_arp_set(name, flow->nw_src, flow->arp_sha); + return 0; } @@ -172,6 +178,28 @@ tnl_arp_cache_flush(struct unixctl_conn *conn, int argc OVS_UNUSED, unixctl_command_reply(conn, "OK"); } +static void +tnl_arp_cache_add(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + const char *br_name = argv[1]; + struct eth_addr mac; + struct in_addr ip; + + if (lookup_ip(argv[2], &ip)) { + unixctl_command_reply_error(conn, "bad IP address"); + return; + } + + if (!eth_addr_from_string(argv[3], &mac)) { + unixctl_command_reply_error(conn, "bad MAC address"); + return; + } + + tnl_arp_set(br_name, ip.s_addr, mac); + unixctl_command_reply(conn, "OK"); +} + #define MAX_IP_ADDR_LEN 17 static void @@ -208,5 +236,6 @@ tnl_arp_cache_init(void) cmap_init(&table); unixctl_command_register("tnl/arp/show", "", 0, 0, tnl_arp_cache_show, NULL); + unixctl_command_register("tnl/arp/set", "BRIDGE IP MAC", 3, 3, tnl_arp_cache_add, NULL); unixctl_command_register("tnl/arp/flush", "", 0, 0, tnl_arp_cache_flush, NULL); } diff --git a/ofproto/ofproto-tnl-unixctl.man b/ofproto/ofproto-tnl-unixctl.man index 853b3f0..f9eb354 100644 --- a/ofproto/ofproto-tnl-unixctl.man +++ b/ofproto/ofproto-tnl-unixctl.man @@ -18,6 +18,10 @@ Delete ipv4_address/plen route from OVS routing table. OVS builds ARP cache by snooping are messages. This command shows ARP cache table. . +.IP "\fBtnl/arp/set \fIbridge ip mac\fR" +Adds or modifies an ARP cache entry in \fIbridge\fR, mapping \fIip\fR +to \fImac\fR. +. .IP "\fBtnl/arp/flush\fR" Flush ARP table. .