From patchwork Mon Nov 13 10:21:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoshuai Li X-Patchwork-Id: 837413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yb6B42MG7z9sNr for ; Mon, 13 Nov 2017 21:21:31 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 784369C0; Mon, 13 Nov 2017 10:21:29 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 47C2495D for ; Mon, 13 Nov 2017 10:21:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2203-239.mail.aliyun.com (smtp2203-239.mail.aliyun.com [121.197.203.239]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C805AE6 for ; Mon, 13 Nov 2017 10:21:26 +0000 (UTC) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.07445297|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03296; MF=ligs@dtdream.com; NM=1; PH=DS; RN=3; RT=3; SR=0; TI=SMTPD_---.9Oo9.FT_1510568481; Received: from localhost.localdomain(mailfrom:ligs@dtdream.com ip:222.128.6.202) by smtp.aliyun-inc.com(10.147.40.26); Mon, 13 Nov 2017 18:21:22 +0800 From: Guoshuai Li To: dev@openvswitch.org Date: Mon, 13 Nov 2017 18:21:11 +0800 Message-Id: <20171113102111.5716-1-ligs@dtdream.com> X-Mailer: git-send-email 2.13.2.windows.1 X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] ovn: Fix remote not receive GARP, when localnet Port has vlan tag. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When sending a localnet port with vlan, the GARP packet needs push_vlan. Signed-off-by: Guoshuai Li Signed-off-by: Ben Pfaff --- This patch is to resolve the conflicts for cherry-pick to branch-2.7/branch-2.6 https://mail.openvswitch.org/pipermail/ovs-dev/2017-November/340562.html --- ovn/controller/pinctrl.c | 16 +++++++++++++--- tests/ovn.at | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c index dc5279a87..bdf5f1cee 100644 --- a/ovn/controller/pinctrl.c +++ b/ovn/controller/pinctrl.c @@ -1001,6 +1001,7 @@ struct garp_data { long long int announce_time; /* Next announcement in ms. */ int backoff; /* Backoff for the next announcement. */ ofp_port_t ofport; /* ofport used to output this GARP. */ + int tag; /* VLAN tag of this GARP packet, or -1. */ }; /* Contains GARPs to be sent. */ @@ -1023,7 +1024,7 @@ destroy_send_garps(void) } static void -add_garp(const char *name, ofp_port_t ofport, +add_garp(const char *name, ofp_port_t ofport, int tag, const struct eth_addr ea, ovs_be32 ip) { struct garp_data *garp = xmalloc(sizeof *garp); @@ -1032,6 +1033,7 @@ add_garp(const char *name, ofp_port_t ofport, garp->announce_time = time_msec() + 1000; garp->backoff = 1; garp->ofport = ofport; + garp->tag = tag; shash_add(&send_garp_data, name, garp); } @@ -1050,6 +1052,7 @@ send_garp_update(const struct sbrec_port_binding *binding_rec, } ofp_port_t ofport = u16_to_ofp(simap_get(localnet_ofports, ld->localnet_port->logical_port)); + int tag = ld->localnet_port->n_tag ? *ld->localnet_port->tag : -1; volatile struct garp_data *garp = NULL; /* Update GARP for NAT IP if it exists. */ @@ -1066,8 +1069,10 @@ send_garp_update(const struct sbrec_port_binding *binding_rec, garp = shash_find_data(&send_garp_data, name); if (garp) { garp->ofport = ofport; + garp->tag = tag; } else { - add_garp(name, ofport, laddrs->ea, laddrs->ipv4_addrs[i].addr); + add_garp(name, ofport, tag, laddrs->ea, + laddrs->ipv4_addrs[i].addr); } free(name); } @@ -1090,7 +1095,7 @@ send_garp_update(const struct sbrec_port_binding *binding_rec, continue; } - add_garp(binding_rec->logical_port, ofport, + add_garp(binding_rec->logical_port, ofport, tag, laddrs.ea, laddrs.ipv4_addrs[0].addr); destroy_lport_addresses(&laddrs); @@ -1120,6 +1125,11 @@ send_garp(struct garp_data *garp, long long int current_time) compose_arp(&packet, ARP_OP_REQUEST, garp->ea, eth_addr_zero, true, garp->ipv4, garp->ipv4); + /* Compose a GARP request packet's vlan if exist. */ + if (garp->tag >= 0) { + eth_push_vlan(&packet, htons(ETH_TYPE_VLAN), htons(garp->tag)); + } + /* Compose actions. The garp request is output on localnet ofport. */ uint64_t ofpacts_stub[4096 / 8]; struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub); diff --git a/tests/ovn.at b/tests/ovn.at index 43b33c72a..48474a8a3 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -5332,6 +5332,40 @@ echo $expected > expout AT_CHECK([sort packets], [0], [expout]) cat packets +# change localnet port tag. +AT_CHECK([ovn-nbctl set Logical_Switch_Port ln_port tag=2014]) + +# wait for earlier changes to take effect +AT_CHECK([ovn-nbctl --timeout=3 --wait=sb sync], [0], [ignore]) + +# update nat-addresses option +ovn-nbctl --wait=sb lsp-set-options lrp0-rp router-port=lrp0 +ovn-nbctl lsp-set-options lrp0-rp router-port=lrp0 nat-addresses="f0:00:00:00:00:01 192.168.0.2" + +reset_pcap_file() { + local iface=$1 + local pcap_file=$2 + ovs-vsctl -- set Interface $iface options:tx_pcap=dummy-tx.pcap \ +options:rxq_pcap=dummy-rx.pcap + rm -f ${pcap_file}*.pcap + ovs-vsctl -- set Interface $iface options:tx_pcap=${pcap_file}-tx.pcap \ +options:rxq_pcap=${pcap_file}-rx.pcap +} + +as hv1 reset_pcap_file snoopvif hv1/snoopvif + +# Wait for packets to be received. +OVS_WAIT_UNTIL([test `wc -c < "hv1/snoopvif-tx.pcap"` -ge 100]) +trim_zeros() { + sed 's/\(00\)\{1,\}$//' +} + +garp="fffffffffffff00000000001810007de08060001080006040001f00000000001c0a80002000000000000c0a80002" +echo $garp > expout + +$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/snoopvif-tx.pcap | trim_zeros | uniq > hv1_snoopvif_tx +AT_CHECK([sort hv1_snoopvif_tx], [0], [expout]) + OVN_CLEANUP([hv1]) AT_CLEANUP