From patchwork Wed Sep 2 06:42:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 513318 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 4B1C51401E7 for ; Wed, 2 Sep 2015 16:43:26 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 3685B10A6D; Tue, 1 Sep 2015 23:43:03 -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 E92B010A64 for ; Tue, 1 Sep 2015 23:43:01 -0700 (PDT) Received: from bar4.cudamail.com (bar2 [192.168.15.2]) by mx3v1.cudamail.com (Postfix) with ESMTP id 5F4CA61857D for ; Wed, 2 Sep 2015 00:43:01 -0600 (MDT) X-ASG-Debug-ID: 1441176180-03dc211ad74140f0001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar4.cudamail.com with ESMTP id X0gyDITsu2TmeCSI (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 02 Sep 2015 00:43:00 -0600 (MDT) X-Barracuda-Envelope-From: blp@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO mail-pa0-f41.google.com) (209.85.220.41) by mx3-pf3.cudamail.com with ESMTPS (RC4-SHA encrypted); 2 Sep 2015 06:42:59 -0000 Received-SPF: unknown (mx3-pf3.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.41 Received: by pacwi10 with SMTP id wi10so949976pac.3 for ; Tue, 01 Sep 2015 23:42:59 -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=XEipBuJ2DndhFlJwUn5rjNO8YYvEzBCOCac7kCpC69+AIx9FFRy9qozvN++wI2xpdX gKHXFD1KoVCr0Do97HtMUyOAgOmK2O2EQKe1Z3vbMSl+9m0sRSnpNNSxli+QIvN+QhrM uSQNsP9ZOJcKky6R2kd59KGE867+PbD7MzvySlS2wdcHbkk3FQv+Xeeqv36KIicFdGvS KkSHJj4ijL5fysoUuR+dx+70ijGVl7F5Cglvg+SgFEqSobADBRC5XfbQxtEpX0VckSh2 LX1g5tEokvn2EpgnKg4krnL0x9b1QsAuJenkZATPVeCf1x9NEFenf914MBLo/EokX5PU Do+w== X-Gm-Message-State: ALoCoQlQc5napGgbWtqv+33kFYTLrJRac0SA6QUY7USXJvG2ReDGGnbDRAqnKPpGnBeUeGcQdqho X-Received: by 10.67.15.36 with SMTP id fl4mr51957126pad.152.1441176179330; Tue, 01 Sep 2015 23:42:59 -0700 (PDT) Received: from sigabrt.benpfaff.org (173-228-112-192.dsl.dynamic.fusionbroadband.com. [173.228.112.192]) by smtp.gmail.com with ESMTPSA id pt3sm20317992pbb.38.2015.09.01.23.42.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Sep 2015 23:42:58 -0700 (PDT) X-CudaMail-Envelope-Sender: blp@nicira.com X-Barracuda-Apparent-Source-IP: 173.228.112.192 From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V3-901000627 X-CudaMail-DTE: 090215 X-CudaMail-Originating-IP: 209.85.220.41 Date: Tue, 1 Sep 2015 23:42:46 -0700 X-ASG-Orig-Subj: [##CM-V3-901000627##][PATCH 4/6] tnl-arp-cache: Add a command to add or modify an ARP cache entry. Message-Id: <1441176168-27960-4-git-send-email-blp@nicira.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1441176168-27960-1-git-send-email-blp@nicira.com> References: <1441176168-27960-1-git-send-email-blp@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1441176180 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 4/6] 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 --- 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. .