From patchwork Tue Jul 16 17:55:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Sun X-Patchwork-Id: 1132892 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ao2/a157"; dkim-atps=neutral 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 45p7NC3nWDz9s8m for ; Wed, 17 Jul 2019 03:55:22 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 0FAF7E1F; Tue, 16 Jul 2019 17:55:17 +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 D2B4DCAA for ; Tue, 16 Jul 2019 17:55:15 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 339508A5 for ; Tue, 16 Jul 2019 17:55:15 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id b7so10502708pls.6 for ; Tue, 16 Jul 2019 10:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=n7xh4pQtCfBaMclDkTHlPai2L9NTQAQKR5PvxzzJs+Q=; b=ao2/a157EDSt9ajULvkE2JVCgKLNDWAs972aDdJipgugZXozbzdOGc2zy2Z23t2Mn0 8k8BsPl44vu88Tb/tVdF2zIZyE2HU4E3SY/GG4yVjLOwVh/J2DlzuDogNNTty1+s6xYh /tMNv8w12Kbzn0wRz9C2DDF25HvIdPjMUb+q4kXXbWq2z9AT2ld0XR3hH0IR4pVZhT8t tzc68ENUqLfWlUGb4vV3r7UQgtLoFxuyXMyGWlPRBwZYo3jpWFJT6pwAYywSW3O194LG YoD53XtwaGWp3irpI8RMwvOvMxq2WtWfRFpx4uT9dG35TTuumAlOKeV+fdl3m6nDo9p9 oojA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=n7xh4pQtCfBaMclDkTHlPai2L9NTQAQKR5PvxzzJs+Q=; b=k5rbAsP4DPJqgrQ7jivMO/dDknqGbHSv5kK3BRBsDWh54qWMxriig74v81XgzXsfEp CLN4nK5KXUeTSR17fv6hJ1c4iqCcUfV0f01R3RUPVq95xLqpRt7wEebVkfE07Z4tk8CN MvxGLaR7oe5RNzIR7jHY6e/S+2dzkV2k3rWlwt0vW26J/Ku8R6a5CFBA1x276H1zqmV1 6bir5bepNrRLHDcr7WJpMn81Q8vHl4yTzZYxhvGIErLpqkFLJ1nGjCVD/5e10UyXqUPc pCMVNO81nkBe2YKWIE7YkCNQh56/ZIvvESyv2kC+Keow3liUU2WOaV8H2GLdvrIGwkNy J2+g== X-Gm-Message-State: APjAAAUkcj3SQUbX9DMx2AmX90XMIHK1JIm+7pyYcBFcEz986b8fH3cs k728pqPCqVh+SCyT84j8Y7sSPEjoyM4= X-Google-Smtp-Source: APXvYqwTSaOBf4O6M+/6qzZrlQGk4MhQQUwcFryNw19L5ecpF86Uxx3qVOUtR5epdasqmWQxB6Og1w== X-Received: by 2002:a17:902:16f:: with SMTP id 102mr36071986plb.94.1563299714448; Tue, 16 Jul 2019 10:55:14 -0700 (PDT) Received: from kern417.eng.vmware.com ([66.170.99.2]) by smtp.gmail.com with ESMTPSA id q24sm19107570pjp.14.2019.07.16.10.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Jul 2019 10:55:13 -0700 (PDT) From: Yifeng Sun To: dev@openvswitch.org, u9012063@gmail.com Date: Tue, 16 Jul 2019 10:55:08 -0700 Message-Id: <1563299708-17693-1-git-send-email-pkusunyifeng@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] userspace: Enable non-bridge port as tunnel endpoint. 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 For userspace datapath, currently only the bridge itself, the LOCAL port, can be the tunnel endpoint to encap/decap tunnel packets. This patch enables non-bridge port as tunnel endpoint. One use case is for users to create a bridge and a vtep port as tap, and configure underlay IP at vtep port as the tunnel endpoint. Signed-off-by: Yifeng Sun Signed-off-by: William Tu --- ofproto/ofproto-dpif-xlate.c | 56 ++++++++++++++++++++++++++++++++++++++------ tests/tunnel-push-pop.at | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 7 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 73966a4e83ca..6fd9539c894b 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -3403,6 +3403,19 @@ tnl_route_lookup_flow(const struct xlate_ctx *ctx, } } } + + /* If tunnel IP isn't configured on bridges, then we search all ports. */ + HMAP_FOR_EACH (xbridge, hmap_node, &ctx->xcfg->xbridges) { + struct xport *port; + + HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) { + if (!strncmp(netdev_get_name(port->netdev), + out_dev, IFNAMSIZ)) { + *out_port = port; + return 0; + } + } + } return -ENOENT; } @@ -3975,10 +3988,11 @@ is_neighbor_reply_correct(const struct xlate_ctx *ctx, const struct flow *flow) bool ret = false; int i; struct xbridge_addr *xbridge_addr = xbridge_addr_ref(ctx->xbridge->addr); + struct in6_addr *ip_addr, *mask; /* Verify if 'nw_dst' of ARP or 'ipv6_dst' of ICMPV6 is in the list. */ for (i = 0; xbridge_addr && i < xbridge_addr->n_addr; i++) { - struct in6_addr *ip_addr = &xbridge_addr->addr[i]; + ip_addr = &xbridge_addr->addr[i]; if ((IN6_IS_ADDR_V4MAPPED(ip_addr) && flow->dl_type == htons(ETH_TYPE_ARP) && in6_addr_get_mapped_ipv4(ip_addr) == flow->nw_dst) || @@ -3991,20 +4005,48 @@ is_neighbor_reply_correct(const struct xlate_ctx *ctx, const struct flow *flow) } xbridge_addr_unref(xbridge_addr); + + /* If not found in bridge's IPs, search in its ports. */ + if (flow->dl_type == htons(ETH_TYPE_ARP) && !ret) { + struct xport *port; + int error, n_in6; + HMAP_FOR_EACH (port, ofp_node, &ctx->xbridge->xports) { + error = netdev_get_addr_list(port->netdev, &ip_addr, + &mask, &n_in6); + if (error) { + continue; + } + if (IN6_IS_ADDR_V4MAPPED(ip_addr)) { + ovs_be32 ip4_mask = in6_addr_get_mapped_ipv4(mask); + if ((flow->nw_dst & ip4_mask) == + (in6_addr_get_mapped_ipv4(ip_addr) & ip4_mask)) { + ret = true; + break; + } + } else { + struct in6_addr masked_dst, masked_addr; + masked_dst = ipv6_addr_bitand(&flow->ipv6_dst, mask); + masked_addr = ipv6_addr_bitand(ip_addr, mask); + if (ipv6_addr_equals(&masked_dst, &masked_addr)) { + ret = true; + break; + } + } + } + + } return ret; } static bool -terminate_native_tunnel(struct xlate_ctx *ctx, ofp_port_t ofp_port, - struct flow *flow, struct flow_wildcards *wc, - odp_port_t *tnl_port) +terminate_native_tunnel(struct xlate_ctx *ctx, struct flow *flow, + struct flow_wildcards *wc, odp_port_t *tnl_port) { *tnl_port = ODPP_NONE; /* XXX: Write better Filter for tunnel port. We can use in_port * in tunnel-port flow to avoid these checks completely. */ - if (ofp_port == OFPP_LOCAL && - ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) { + if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) { *tnl_port = tnl_port_map_lookup(flow, wc); /* If no tunnel port was found and it's about an ARP or ICMPv6 packet, @@ -4148,7 +4190,7 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port, native_tunnel_output(ctx, xport, flow, odp_port, truncate); flow->tunnel = flow_tnl; /* Restore tunnel metadata */ - } else if (terminate_native_tunnel(ctx, ofp_port, flow, wc, + } else if (terminate_native_tunnel(ctx, flow, wc, &odp_tnl_port)) { /* Intercept packet to be received on native tunnel port. */ nl_msg_put_odp_port(ctx->odp_actions, OVS_ACTION_ATTR_TUNNEL_POP, diff --git a/tests/tunnel-push-pop.at b/tests/tunnel-push-pop.at index f7172433ee63..5056b971256a 100644 --- a/tests/tunnel-push-pop.at +++ b/tests/tunnel-push-pop.at @@ -601,3 +601,58 @@ NXST_FLOW reply: OVS_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([tunnel_push_pop - use non-local port as tunnel endpoint]) + +OVS_VSWITCHD_START([add-port br0 p0 -- set Interface p0 type=dummy ofport_request=1]) +AT_CHECK([ovs-vsctl add-port br0 vtep0 -- set int vtep0 type=dummy], [0]) +AT_CHECK([ovs-vsctl add-br int-br -- set bridge int-br datapath_type=dummy], [0]) +AT_CHECK([ovs-vsctl add-port int-br t1 -- set Interface t1 type=gre \ + options:remote_ip=1.1.2.92 ofport_request=3], [0]) + +AT_CHECK([ovs-appctl dpif/show], [0], [dnl +dummy@ovs-dummy: hit:0 missed:0 + br0: + br0 65534/100: (dummy-internal) + p0 1/1: (dummy) + vtep0 2/2: (dummy) + int-br: + int-br 65534/3: (dummy-internal) + t1 3/4: (gre: remote_ip=1.1.2.92) +]) + +AT_CHECK([ovs-appctl netdev-dummy/ip4addr vtep0 1.1.2.88/24], [0], [OK +]) +AT_CHECK([ovs-appctl ovs/route/add 1.1.2.92/24 vtep0], [0], [OK +]) +AT_CHECK([ovs-ofctl add-flow br0 action=normal]) +AT_CHECK([ovs-ofctl add-flow int-br action=normal]) + +dnl Use arp request and reply to achieve tunnel next hop mac binding +dnl By default, vtep0's MAC address is aa:55:aa:55:00:03 +AT_CHECK([ovs-appctl netdev-dummy/receive vtep0 'recirc_id(0),in_port(2),eth(dst=ff:ff:ff:ff:ff:ff,src=aa:55:aa:55:00:03),eth_type(0x0806),arp(tip=1.1.2.92,sip=1.1.2.88,op=1,sha=aa:55:aa:55:00:03,tha=00:00:00:00:00:00)']) +AT_CHECK([ovs-appctl netdev-dummy/receive p0 'recirc_id(0),in_port(1),eth(src=f8:bc:12:44:34:b6,dst=aa:55:aa:55:00:03),eth_type(0x0806),arp(sip=1.1.2.92,tip=1.1.2.88,op=2,sha=f8:bc:12:44:34:b6,tha=aa:55:aa:55:00:03)']) + +AT_CHECK([ovs-appctl tnl/neigh/show | tail -n+3 | sort], [0], [dnl +1.1.2.92 f8:bc:12:44:34:b6 br0 +]) + +AT_CHECK([ovs-appctl ovs/route/show | tail -n+2 | sort], [0], [dnl +User: 1.1.2.0/24 dev vtep0 SRC 1.1.2.88 +]) + +dnl Check GRE tunnel pop +AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=f8:bc:12:44:34:b6,dst=aa:55:aa:55:00:03),eth_type(0x0800),ipv4(src=1.1.2.92,dst=1.1.2.88,proto=47,tos=0,ttl=64,frag=no)'], [0], [stdout]) + +AT_CHECK([tail -1 stdout], [0], + [Datapath actions: tnl_pop(4) +]) + +dnl Check GRE tunnel push +AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(3),eth(dst=f9:bc:12:44:34:b6,src=af:55:aa:55:00:03),eth_type(0x0800),ipv4(src=1.1.3.88,dst=1.1.3.92,proto=1,tos=0,ttl=64,frag=no)'], [0], [stdout]) +AT_CHECK([tail -1 stdout], [0], + [Datapath actions: clone(tnl_push(tnl_port(4),header(size=38,type=3,eth(dst=f8:bc:12:44:34:b6,src=aa:55:aa:55:00:03,dl_type=0x0800),ipv4(src=1.1.2.88,dst=1.1.2.92,proto=47,tos=0,ttl=64,frag=0x4000),gre((flags=0x0,proto=0x6558))),out_port(2)),1) +]) + +OVS_VSWITCHD_STOP +AT_CLEANUP