From patchwork Wed Jul 19 03:44:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 790734 X-Patchwork-Delegate: blp@nicira.com 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aHYLK2Lv"; 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 3xC2wx6q3Jz9s82 for ; Wed, 19 Jul 2017 13:45:21 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4D41CB0A; Wed, 19 Jul 2017 03:44:42 +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 4EC69B2E for ; Wed, 19 Jul 2017 03:44:40 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4E833F1 for ; Wed, 19 Jul 2017 03:44:39 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id y129so5218920pgy.3 for ; Tue, 18 Jul 2017 20:44:39 -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:in-reply-to:references; bh=d/AXb3VAv2dTQqKg4mIxAT6ht/vi3X6b9eu3ZR2JUII=; b=aHYLK2Lv8dcNyCmJyP76t1/OY2C5T9gYpbd4bawomouIgEjnNL1xb+H5zKx2uV1ohL jcaOeoKsot+MvwWlW4d29jopP2ACfCGcNENbyFd0mO7MRgNQ6gHt+QXHuBUW0EvGtzfX pbT9Am2EHWP4KJ+nL7KHhh/4LJWrTFwoJrfpcQhlHOaZMBK3Dw/Qg4xnI1D0A/dgeGXI 1ugKmYvqo/6VsFDXIkX1j36PbsoPfaMTdWxEpt5h4dw22iqkR9gmzbr/ClNpMorb8Pqd /E52mVd3dmbrPW6xDL8BosT8KEnjLyp9PGVYAp5nS69F2hN3LyL+jjbK0rMTnsOyaLOV U7nQ== 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:in-reply-to :references; bh=d/AXb3VAv2dTQqKg4mIxAT6ht/vi3X6b9eu3ZR2JUII=; b=T7wvYRbvetdiwRSVK5odYID5XMMyNLt+dbYSH99Z/1NfpwKUbLr74Y8xpcXr87SWwN pjMg3yG7hp8nIrdYKqNbbV+w4mAaVWV3gRndyrGbQy89JlrEZ+8oL60RGj9u6WgN+6TG a5wEEDhlQAdryshB/mf6uDyGTZFpBgvPNy4jVFMrQmiHZshsGZqvPBlmDrH1M/lcbbXE Cx6jq3PPXXKaUfYV+wOswMBhUCdWMmeE575de/4Do4DPgjIg8+wKAS/JrzPht81KcvK6 2ctLQ7+IRI5GUw4AZchmgvhZWA7jFktvgq1IrD6LN4K2FSuLCFGwCdk1kF4/8Gbqp28r IcSg== X-Gm-Message-State: AIVw110CnR2RB0qtd74zRMfEHHc7VJRs5dMDybB6Ol5ajjV98p/669g/ /+aOctD+pUhbPdd4xHg= X-Received: by 10.84.210.130 with SMTP id a2mr889686pli.301.1500435878694; Tue, 18 Jul 2017 20:44:38 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([106.120.127.10]) by smtp.gmail.com with ESMTPSA id b8sm9100612pfd.65.2017.07.18.20.44.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 20:44:38 -0700 (PDT) From: Tonghao Zhang To: dev@openvswitch.org Date: Tue, 18 Jul 2017 20:44:15 -0700 Message-Id: <1500435856-4120-2-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500435856-4120-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1500435856-4120-1-git-send-email-xiangxia.m.yue@gmail.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 2/3] ovs-router: Set suitable type to netdev_open(). 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 ovs-router module uses the netdev_open() to get routes. But this module always calls the netdev_open() with type which is NULL. This module may open the eth0, vethx, vxlan_sys_4789, br0 if these network devices exist. And these device will be opened as 'system' type. When debugging, somewhere netdev_ref it. After reverting "netdev: Fix netdev_open() to adhere to class type if given", and when we call the 'ovs-appctl dpctl/show' or 'ovs-dpctl show', the info is shown as below. the vxlan_sys_4789 is up (eg. ifconfig vxlan_sys_4789 up). $ ovs-dpctl show system@ovs-system: lookups: hit:4053 missed:118 lost:3 flows: 0 masks: hit:4154 total:1 hit/pkt:1.00 port 0: ovs-system (internal) port 1: user-ovs-vm (internal) port 2: vxlan_sys_4789 (vxlan) But the info should be as below. $ ovs-dpctl show system@ovs-system: lookups: hit:4053 missed:118 lost:3 flows: 0 masks: hit:4154 total:1 hit/pkt:1.00 port 0: ovs-system (internal) port 1: user-ovs-vm (internal) port 2: vxlan_sys_4789 (vxlan: packet_type=ptap) Because the netdev-class of 'system' type does not have the 'get_config', and tunnel vports have 'get_config', then we can get the config info(eg. packet_type=ptap) of tunnel vports. If we only revert the patch, there is a bug all the time. The patch which Eelco support is fine to me. That patch avoid issue. URL: https://mail.openvswitch.org/pipermail/ovs-dev/2017-July/335560.html But without it, the patch I support also avoid the problem. However we should check the type in the ovs-router module, this patch works well with the patch Eelco support. Signed-off-by: Tonghao Zhang --- v2: fix memory leak. --- lib/ovs-router.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- lib/route-table.c | 1 - 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/ovs-router.c b/lib/ovs-router.c index ce2f80b..7db03f2 100644 --- a/lib/ovs-router.c +++ b/lib/ovs-router.c @@ -45,6 +45,7 @@ #include "util.h" #include "unaligned.h" #include "openvswitch/vlog.h" +#include "sset.h" VLOG_DEFINE_THIS_MODULE(ovs_router); @@ -138,6 +139,47 @@ static void rt_init_match(struct match *match, uint32_t mark, match->flow.pkt_mark = mark; } +/* Return the network device type of the specified + * 'netdev_name' if successful, otherwise null. + * + * The caller should free it. + * */ +static char * +get_netdev_type(const char *netdev_name) +{ + struct sset dpif_names = SSET_INITIALIZER(&dpif_names), + dpif_types = SSET_INITIALIZER(&dpif_types); + struct dpif_port dpif_port; + const char *dpif_type, *dpif_name; + char *netdev_type = NULL; + + dp_enumerate_types(&dpif_types); + + SSET_FOR_EACH (dpif_type, &dpif_types) { + if (dp_enumerate_names(dpif_type, &dpif_names)) { + continue; + } + + SSET_FOR_EACH (dpif_name, &dpif_names) { + struct dpif *dpif; + if (!dpif_open(dpif_name, dpif_type, &dpif)) { + if (!dpif_port_query_by_name(dpif, netdev_name, &dpif_port)) { + netdev_type = xstrdup(dpif_port.type); + dpif_close(dpif); + goto out; + } + dpif_close(dpif); + } + } + } + +out: + sset_destroy(&dpif_names); + sset_destroy(&dpif_types); + + return netdev_type; +} + static int get_src_addr(const struct in6_addr *ip6_dst, const char output_bridge[], struct in6_addr *psrc) @@ -146,9 +188,11 @@ get_src_addr(const struct in6_addr *ip6_dst, int err, n_in6, i, max_plen = -1; struct netdev *dev; bool is_ipv4; + char *netdev_type = get_netdev_type(output_bridge); - err = netdev_open(output_bridge, NULL, &dev); + err = netdev_open(output_bridge, netdev_type, &dev); if (err) { + free(netdev_type); return err; } @@ -182,6 +226,7 @@ get_src_addr(const struct in6_addr *ip6_dst, out: free(addr6); free(mask); + free(netdev_type); netdev_close(dev); return err; } diff --git a/lib/route-table.c b/lib/route-table.c index 67fda31..fc6845f 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -112,7 +112,6 @@ route_table_init(void) nln_notifier_create(nln, RTNLGRP_IPV6_ROUTE, (nln_notify_func *) route_table_change, NULL); - route_table_reset(); name_table_init(); ovs_mutex_unlock(&route_table_mutex);