From patchwork Thu Jun 28 16:03:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hurley X-Patchwork-Id: 936226 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=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="dFZCtA4I"; 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 41Gl2L3s8Bz9s1B for ; Fri, 29 Jun 2018 02:03:54 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 91BB9D9E; Thu, 28 Jun 2018 16:03:19 +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 6CA85D90 for ; Thu, 28 Jun 2018 16:03:18 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 0C399334 for ; Thu, 28 Jun 2018 16:03:16 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id m15-v6so5486787edr.7 for ; Thu, 28 Jun 2018 09:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L8tlcc+rB/cDXBTQnE+guo1RdZ/WrtZL/B5+wn/7Qok=; b=dFZCtA4IIhDhcS04Oi3+6pli344ywhxe2irRwjtdZaLy3WvKSLHiQRfl+WpnREtD2q 2+Sm9LB8w+/uEXVJtQeLa7o8ep+2bZcgHTL/ow6cQZf4dhb4etdR4f2F1RkgRmHDO5PO zcqNIjd/kNznw6E3POqyJliMLYvtCL6heXbxRCOH6mHtJc5/ax85cju6r81zyXhxqSYs j3ZyA/l2hnoL4ne6hO2V8Lw3p86zVLryD9YobRkhIkc0xnqnNPfGgDPvTYkcJQ4I2z/5 8qhr55UsxaJbUJbUtTiPQIeysurmpmrCyaadjPHVGChsYsxYAvuJz+dQ92axMJhljZ9f pvuA== 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=L8tlcc+rB/cDXBTQnE+guo1RdZ/WrtZL/B5+wn/7Qok=; b=akBZVQ3to6ZjnimTqYOCpRZ/n9hRde9L3BzBCzz/Ynxa03ZsLfBLvbFEr6MCQoSjVH xtI9NCoYvEFGH6BLvzW3rKkxDrrThjZOiByz2aX6OfHwnsVp5B9La9UpjuLDbGR1vnT+ nST6DM0UCF8edHbJrdXbbDbl8HG3ldNEiwx4vqBs0r7hE01zNvSi7VU4GVsVHxhkIGM7 cdzp7itZARz6Wu0Oj7EiO/ijD0ji/JfDEBmgItY9fUYNb0N45Yfs3ZP4Tofzbs9I6NdH T+Y0x1CaVOcFUfCbr9hZl7ZrvIcNhP5H0fPLGER6HLRC4NCQYZm3/7AZGhKacFYGhg0M KCFA== X-Gm-Message-State: APt69E0YQJsV1z6y9dfixk8klxosVIeSwYOvrLb9bYC31ELMRB7nPFCM DSOVUyEel661FkSpBKbED/3xIxDW X-Google-Smtp-Source: AAOMgpfOBjk5vRMqytZtCoeRv5ltpGZ6vs88n0ZHaP6Eo3Ce+Bpjp4WLj2dqrJ2QeWrRgw4I8spGQA== X-Received: by 2002:a50:d8ca:: with SMTP id y10-v6mr2860645edj.62.1530201795347; Thu, 28 Jun 2018 09:03:15 -0700 (PDT) Received: from jhurley-Precision-Tower-3420.netronome.com ([80.76.204.157]) by smtp.gmail.com with ESMTPSA id l54-v6sm4574079edb.13.2018.06.28.09.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 09:03:14 -0700 (PDT) From: John Hurley To: dev@openvswitch.org, roid@mellanox.com, gavi@mellanox.com, paulb@mellanox.com, fbl@sysclose.org, simon.horman@netronome.com Date: Thu, 28 Jun 2018 17:03:02 +0100 Message-Id: <1530201787-7071-2-git-send-email-john.hurley@netronome.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> References: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Cc: Jakub Kicinski Subject: [ovs-dev] [PATCH v3 1/6] tc: allow offloading of block ids 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 Blocks, in tc classifiers, allow the grouping of multiple qdiscs with an associated block id. Whenever a filter is added to/removed from this block, the filter is added to/removed from all associated qdiscs. Extend TC offload functions to take a block id as a parameter. If the id is zero then the dqisc is not considered part of a block. Signed-off-by: John Hurley Reviewed-by: Simon Horman Reviewed-by: Dirk van der Merwe Signed-off-by: Jakub Kicinski --- lib/netdev-linux.c | 4 +-- lib/netdev-tc-offloads.c | 64 +++++++++++++++++++++++++++++++++++------------- lib/tc.c | 60 ++++++++++++++++++++++++++++++++------------- lib/tc.h | 12 ++++----- 4 files changed, 98 insertions(+), 42 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 054a9b6..d89a0fb 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2275,7 +2275,7 @@ netdev_linux_set_policing(struct netdev *netdev_, COVERAGE_INC(netdev_set_policing); /* Remove any existing ingress qdisc. */ - error = tc_add_del_ingress_qdisc(ifindex, false); + error = tc_add_del_ingress_qdisc(ifindex, false, 0); if (error) { VLOG_WARN_RL(&rl, "%s: removing policing failed: %s", netdev_name, ovs_strerror(error)); @@ -2283,7 +2283,7 @@ netdev_linux_set_policing(struct netdev *netdev_, } if (kbits_rate) { - error = tc_add_del_ingress_qdisc(ifindex, true); + error = tc_add_del_ingress_qdisc(ifindex, true, 0); if (error) { VLOG_WARN_RL(&rl, "%s: adding policing qdisc failed: %s", netdev_name, ovs_strerror(error)); diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 0d8cc2c..14558ad 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -44,6 +44,7 @@ static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(60, 5); static struct hmap ufid_tc = HMAP_INITIALIZER(&ufid_tc); static bool multi_mask_per_prio = false; +static bool block_support = false; struct netlink_field { int offset; @@ -307,6 +308,7 @@ int netdev_tc_flow_flush(struct netdev *netdev) { int ifindex = netdev_get_ifindex(netdev); + uint32_t block_id = 0; if (ifindex < 0) { VLOG_ERR_RL(&error_rl, "flow_flush: failed to get ifindex for %s: %s", @@ -314,7 +316,7 @@ netdev_tc_flow_flush(struct netdev *netdev) return -ifindex; } - return tc_flush(ifindex); + return tc_flush(ifindex, block_id); } int @@ -322,6 +324,7 @@ netdev_tc_flow_dump_create(struct netdev *netdev, struct netdev_flow_dump **dump_out) { struct netdev_flow_dump *dump; + uint32_t block_id = 0; int ifindex; ifindex = netdev_get_ifindex(netdev); @@ -334,7 +337,7 @@ netdev_tc_flow_dump_create(struct netdev *netdev, dump = xzalloc(sizeof *dump); dump->nl_dump = xzalloc(sizeof *dump->nl_dump); dump->netdev = netdev_ref(netdev); - tc_dump_flower_start(ifindex, dump->nl_dump); + tc_dump_flower_start(ifindex, dump->nl_dump, block_id); *dump_out = dump; @@ -890,6 +893,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, struct flow *mask = &match->wc.masks; const struct flow_tnl *tnl = &match->flow.tunnel; struct tc_action *action; + uint32_t block_id = 0; struct nlattr *nla; size_t left; int prio = 0; @@ -1097,7 +1101,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, handle = get_ufid_tc_mapping(ufid, &prio, NULL); if (handle && prio) { VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d", handle, prio); - tc_del_filter(ifindex, prio, handle); + tc_del_filter(ifindex, prio, handle, block_id); } if (!prio) { @@ -1111,7 +1115,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, flower.act_cookie.data = ufid; flower.act_cookie.len = sizeof *ufid; - err = tc_replace_flower(ifindex, prio, handle, &flower); + err = tc_replace_flower(ifindex, prio, handle, &flower, block_id); if (!err) { add_ufid_tc_mapping(ufid, flower.prio, flower.handle, netdev, ifindex); } @@ -1131,6 +1135,7 @@ netdev_tc_flow_get(struct netdev *netdev OVS_UNUSED, static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); struct netdev *dev; struct tc_flower flower; + uint32_t block_id = 0; odp_port_t in_port; int prio = 0; int ifindex; @@ -1152,7 +1157,7 @@ netdev_tc_flow_get(struct netdev *netdev OVS_UNUSED, VLOG_DBG_RL(&rl, "flow get (dev %s prio %d handle %d)", netdev_get_name(dev), prio, handle); - err = tc_get_flower(ifindex, prio, handle, &flower); + err = tc_get_flower(ifindex, prio, handle, &flower, block_id); netdev_close(dev); if (err) { VLOG_ERR_RL(&error_rl, "flow get failed (dev %s prio %d handle %d): %s", @@ -1175,6 +1180,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, struct dpif_flow_stats *stats) { struct tc_flower flower; + uint32_t block_id = 0; struct netdev *dev; int prio = 0; int ifindex; @@ -1196,14 +1202,14 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, if (stats) { memset(stats, 0, sizeof *stats); - if (!tc_get_flower(ifindex, prio, handle, &flower)) { + if (!tc_get_flower(ifindex, prio, handle, &flower, block_id)) { stats->n_packets = get_32aligned_u64(&flower.stats.n_packets); stats->n_bytes = get_32aligned_u64(&flower.stats.n_bytes); stats->used = flower.lastused; } } - error = tc_del_filter(ifindex, prio, handle); + error = tc_del_filter(ifindex, prio, handle, block_id); del_ufid_tc_mapping(ufid); netdev_close(dev); @@ -1212,7 +1218,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, } static void -probe_multi_mask_per_prio(int ifindex) +probe_multi_mask_per_prio(int ifindex, uint32_t block_id) { struct tc_flower flower; int error; @@ -1224,7 +1230,7 @@ probe_multi_mask_per_prio(int ifindex) memset(&flower.key.dst_mac, 0x11, sizeof flower.key.dst_mac); memset(&flower.mask.dst_mac, 0xff, sizeof flower.mask.dst_mac); - error = tc_replace_flower(ifindex, 1, 1, &flower); + error = tc_replace_flower(ifindex, 1, 1, &flower, block_id); if (error) { return; } @@ -1232,23 +1238,42 @@ probe_multi_mask_per_prio(int ifindex) memset(&flower.key.src_mac, 0x11, sizeof flower.key.src_mac); memset(&flower.mask.src_mac, 0xff, sizeof flower.mask.src_mac); - error = tc_replace_flower(ifindex, 1, 2, &flower); - tc_del_filter(ifindex, 1, 1); + error = tc_replace_flower(ifindex, 1, 2, &flower, block_id); + tc_del_filter(ifindex, 1, 1, block_id); if (error) { return; } - tc_del_filter(ifindex, 1, 2); + tc_del_filter(ifindex, 1, 2, block_id); multi_mask_per_prio = true; VLOG_INFO("probe tc: multiple masks on single tc prio is supported."); } +static void +probe_tc_block_support(int ifindex) +{ + uint32_t block_id = 1; + int error; + + error = tc_add_del_ingress_qdisc(ifindex, true, block_id); + if (error) { + return; + } + + tc_add_del_ingress_qdisc(ifindex, false, block_id); + + block_support = true; + VLOG_INFO("probe tc: block offload is supported."); +} + int netdev_tc_init_flow_api(struct netdev *netdev) { - static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + static struct ovsthread_once multi_mask_once = OVSTHREAD_ONCE_INITIALIZER; + static struct ovsthread_once block_once = OVSTHREAD_ONCE_INITIALIZER; + uint32_t block_id = 0; int ifindex; int error; @@ -1259,7 +1284,12 @@ netdev_tc_init_flow_api(struct netdev *netdev) return -ifindex; } - error = tc_add_del_ingress_qdisc(ifindex, true); + if (ovsthread_once_start(&block_once)) { + probe_tc_block_support(ifindex); + ovsthread_once_done(&block_once); + } + + error = tc_add_del_ingress_qdisc(ifindex, true, block_id); if (error && error != EEXIST) { VLOG_ERR("failed adding ingress qdisc required for offloading: %s", @@ -1269,9 +1299,9 @@ netdev_tc_init_flow_api(struct netdev *netdev) VLOG_INFO("added ingress qdisc to %s", netdev_get_name(netdev)); - if (ovsthread_once_start(&once)) { - probe_multi_mask_per_prio(ifindex); - ovsthread_once_done(&once); + if (ovsthread_once_start(&multi_mask_once)) { + probe_multi_mask_per_prio(ifindex, block_id); + ovsthread_once_done(&multi_mask_once); } return 0; diff --git a/lib/tc.c b/lib/tc.c index 7133486..7a71036 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -43,6 +43,14 @@ #define MAX_PEDIT_OFFSETS 32 +#ifndef TCM_IFINDEX_MAGIC_BLOCK +#define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU) +#endif + +#if TCA_MAX < 14 +#define TCA_INGRESS_BLOCK 13 +#endif + VLOG_DEFINE_THIS_MODULE(tc); static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(60, 5); @@ -173,10 +181,14 @@ tc_transact(struct ofpbuf *request, struct ofpbuf **replyp) * The configuration and stats may be seen with the following command: * /sbin/tc -s qdisc show dev * + * If block_id is greater than 0, then the ingress qdisc is added to a block. + * In this case, it is equivalent to running (when 'add' is true): + * /sbin/tc qdisc add dev ingress_block ingress + * * Returns 0 if successful, otherwise a positive errno value. */ int -tc_add_del_ingress_qdisc(int ifindex, bool add) +tc_add_del_ingress_qdisc(int ifindex, bool add, uint32_t block_id) { struct ofpbuf request; struct tcmsg *tcmsg; @@ -189,6 +201,9 @@ tc_add_del_ingress_qdisc(int ifindex, bool add) tcmsg->tcm_parent = TC_H_INGRESS; nl_msg_put_string(&request, TCA_KIND, "ingress"); nl_msg_put_unspec(&request, TCA_OPTIONS, NULL, 0); + if (block_id) { + nl_msg_put_u32(&request, TCA_INGRESS_BLOCK, block_id); + } error = tc_transact(&request, NULL); if (error) { @@ -1007,13 +1022,15 @@ parse_netlink_to_tc_flower(struct ofpbuf *reply, struct tc_flower *flower) } int -tc_dump_flower_start(int ifindex, struct nl_dump *dump) +tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id) { struct ofpbuf request; struct tcmsg *tcmsg; + int index; - tcmsg = tc_make_request(ifindex, RTM_GETTFILTER, NLM_F_DUMP, &request); - tcmsg->tcm_parent = TC_INGRESS_PARENT; + index = block_id ? TCM_IFINDEX_MAGIC_BLOCK : ifindex; + tcmsg = tc_make_request(index, RTM_GETTFILTER, NLM_F_DUMP, &request); + tcmsg->tcm_parent = block_id ? : TC_INGRESS_PARENT; tcmsg->tcm_info = TC_H_UNSPEC; tcmsg->tcm_handle = 0; @@ -1024,28 +1041,32 @@ tc_dump_flower_start(int ifindex, struct nl_dump *dump) } int -tc_flush(int ifindex) +tc_flush(int ifindex, uint32_t block_id) { struct ofpbuf request; struct tcmsg *tcmsg; + int index; - tcmsg = tc_make_request(ifindex, RTM_DELTFILTER, NLM_F_ACK, &request); - tcmsg->tcm_parent = TC_INGRESS_PARENT; + index = block_id ? TCM_IFINDEX_MAGIC_BLOCK : ifindex; + tcmsg = tc_make_request(index, RTM_DELTFILTER, NLM_F_ACK, &request); + tcmsg->tcm_parent = block_id ? : TC_INGRESS_PARENT; tcmsg->tcm_info = TC_H_UNSPEC; return tc_transact(&request, NULL); } int -tc_del_filter(int ifindex, int prio, int handle) +tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id) { struct ofpbuf request; struct tcmsg *tcmsg; struct ofpbuf *reply; int error; + int index; - tcmsg = tc_make_request(ifindex, RTM_DELTFILTER, NLM_F_ECHO, &request); - tcmsg->tcm_parent = TC_INGRESS_PARENT; + index = block_id ? TCM_IFINDEX_MAGIC_BLOCK : ifindex; + tcmsg = tc_make_request(index, RTM_DELTFILTER, NLM_F_ECHO, &request); + tcmsg->tcm_parent = block_id ? : TC_INGRESS_PARENT; tcmsg->tcm_info = tc_make_handle(prio, 0); tcmsg->tcm_handle = handle; @@ -1057,15 +1078,18 @@ tc_del_filter(int ifindex, int prio, int handle) } int -tc_get_flower(int ifindex, int prio, int handle, struct tc_flower *flower) +tc_get_flower(int ifindex, int prio, int handle, struct tc_flower *flower, + uint32_t block_id) { struct ofpbuf request; struct tcmsg *tcmsg; struct ofpbuf *reply; int error; + int index; - tcmsg = tc_make_request(ifindex, RTM_GETTFILTER, NLM_F_ECHO, &request); - tcmsg->tcm_parent = TC_INGRESS_PARENT; + index = block_id ? TCM_IFINDEX_MAGIC_BLOCK : ifindex; + tcmsg = tc_make_request(index, RTM_GETTFILTER, NLM_F_ECHO, &request); + tcmsg->tcm_parent = block_id ? : TC_INGRESS_PARENT; tcmsg->tcm_info = tc_make_handle(prio, 0); tcmsg->tcm_handle = handle; @@ -1625,7 +1649,7 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower) int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle, - struct tc_flower *flower) + struct tc_flower *flower, uint32_t block_id) { struct ofpbuf request; struct tcmsg *tcmsg; @@ -1633,10 +1657,12 @@ tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle, int error = 0; size_t basic_offset; uint16_t eth_type = (OVS_FORCE uint16_t) flower->key.eth_type; + int index; - tcmsg = tc_make_request(ifindex, RTM_NEWTFILTER, - NLM_F_CREATE | NLM_F_ECHO, &request); - tcmsg->tcm_parent = TC_INGRESS_PARENT; + index = block_id ? TCM_IFINDEX_MAGIC_BLOCK : ifindex; + tcmsg = tc_make_request(index, RTM_NEWTFILTER, NLM_F_CREATE | NLM_F_ECHO, + &request); + tcmsg->tcm_parent = block_id ? : TC_INGRESS_PARENT; tcmsg->tcm_info = tc_make_handle(prio, eth_type); tcmsg->tcm_handle = handle; diff --git a/lib/tc.h b/lib/tc.h index cc19374..80505f0 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -63,7 +63,7 @@ tc_get_minor(unsigned int handle) struct tcmsg *tc_make_request(int ifindex, int type, unsigned int flags, struct ofpbuf *); int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp); -int tc_add_del_ingress_qdisc(int ifindex, bool add); +int tc_add_del_ingress_qdisc(int ifindex, bool add, uint32_t block_id); struct tc_cookie { const void *data; @@ -198,12 +198,12 @@ BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite) + sizeof(uint32_t) - 2 < sizeof(struct tc_flower)); int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle, - struct tc_flower *flower); -int tc_del_filter(int ifindex, int prio, int handle); + struct tc_flower *flower, uint32_t block_id); +int tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id); int tc_get_flower(int ifindex, int prio, int handle, - struct tc_flower *flower); -int tc_flush(int ifindex); -int tc_dump_flower_start(int ifindex, struct nl_dump *dump); + struct tc_flower *flower, uint32_t block_id); +int tc_flush(int ifindex, uint32_t block_id); +int tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id); int parse_netlink_to_tc_flower(struct ofpbuf *reply, struct tc_flower *flower); void tc_set_policy(const char *policy); From patchwork Thu Jun 28 16:03:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hurley X-Patchwork-Id: 936227 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=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="R8MY53ol"; 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 41Gl350Tzqz9s1B for ; Fri, 29 Jun 2018 02:04:32 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AFC06DBC; Thu, 28 Jun 2018 16:03:21 +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 0C7D0D7D for ; Thu, 28 Jun 2018 16:03:19 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 185EF1A0 for ; Thu, 28 Jun 2018 16:03:18 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id c1-v6so5499182edt.2 for ; Thu, 28 Jun 2018 09:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dS0mZjNiC0mNFqmt/iZ9RdCvWwXIoy/OVnleBZ2IiRA=; b=R8MY53olZHQTe+Yvu1K5pLuZi0cXTgyMo58ZGy+YO11IcFHCTUHNXNQT0JPOysWm0n 0vqq5ssg8HDWgs8k/rs4sqsjwozKKgON1FBksObhwkl+RZj0hgG8lkaJP7rf9VKR09PZ /yKGNQxs0Oht/oNlp9z2F0TnNdhlvmIpndL/Tu37rkLYWZD2mvaUVuE0Jd6RwHkc/Txj HQRBVch83oKXGSjLJvWmOY3XBcOo9zZVCZt0gLqaSXfjf9TbLYuUc9OKjLL7ZKEtnpE7 oWw51Ed/0Yt6H9WjqJNsLJ7AWc1JVgBKQLMTspRbII0EkmQUXwcaCmbYLjyH+ALIqalx Humw== 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=dS0mZjNiC0mNFqmt/iZ9RdCvWwXIoy/OVnleBZ2IiRA=; b=G77rnvzO0o8JBLsAD2vq4j/9gkU1TbtI2cmPIL9RKoDG27LIqk35Q0iDdzQvc9T3se fsn8bWlYp+zqT96CrvON3yuCGqwtmUzpHarg59LhVpZ8DlblcALpGCxYxjl6A0DBm1Wg AU98ClUyOS4ChxxyVmkBqo3jGPqdp+g40P74dTmGlD8v4HC34IUTI9rJMiB1RdaIXDPJ OqVIQ7Kfa1Qb5pXjtF6YWaR5M+2+2HegVEJ/zP85f3RKevsZ4DCTPUcL/Zz8NquZtOI1 IYIqjuwHtdea85Lu3VizeMpyFbu+2QJGGwzEdMxq66HrEqu1IhOwh8PjOBtZFq4gNmSj cCeg== X-Gm-Message-State: APt69E26LL7ByE9ZX1JxWCNAkBXQqgH9RKdgmIlY2G29UffTOKHuOCw7 2svZ/hy4ZGpR7iW+kRoIUWiICNLH X-Google-Smtp-Source: AAOMgpfbdo/HkUL55iKA3VN8VyBHMQGA9tbGMXJq9IoXM/eMzq0jit2HvBeCJrHk0o2lbrTiyooHBQ== X-Received: by 2002:aa7:d5d2:: with SMTP id d18-v6mr2441517eds.130.1530201796482; Thu, 28 Jun 2018 09:03:16 -0700 (PDT) Received: from jhurley-Precision-Tower-3420.netronome.com ([80.76.204.157]) by smtp.gmail.com with ESMTPSA id l54-v6sm4574079edb.13.2018.06.28.09.03.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 09:03:15 -0700 (PDT) From: John Hurley To: dev@openvswitch.org, roid@mellanox.com, gavi@mellanox.com, paulb@mellanox.com, fbl@sysclose.org, simon.horman@netronome.com Date: Thu, 28 Jun 2018 17:03:03 +0100 Message-Id: <1530201787-7071-3-git-send-email-john.hurley@netronome.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> References: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Cc: Jakub Kicinski Subject: [ovs-dev] [PATCH v3 2/6] netdev-provider: add class op to get block_id 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 Add a new class op for netdevs to get the block_id if one exists. The block_id is used in offload ops to group multiple qdiscs together. Stub calls are made to the new class op (implementation to follow in further patches). The default block_id of 0 (no block) will be used in these cases. Signed-off-by: John Hurley Reviewed-by: Dirk van der Merwe Reviewed-by: Simon Horman Signed-off-by: Jakub Kicinski --- lib/netdev-bsd.c | 3 ++- lib/netdev-dpdk.c | 3 ++- lib/netdev-dummy.c | 3 ++- lib/netdev-linux.c | 3 ++- lib/netdev-provider.h | 4 ++++ lib/netdev-tc-offloads.c | 18 ++++++++++++++++++ lib/netdev-vport.c | 3 ++- lib/netdev.c | 10 ++++++++++ lib/netdev.h | 1 + 9 files changed, 43 insertions(+), 5 deletions(-) diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c index b70f327..c6946f9 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -1553,7 +1553,8 @@ netdev_bsd_update_flags(struct netdev *netdev_, enum netdev_flags off, netdev_bsd_rxq_wait, \ netdev_bsd_rxq_drain, \ \ - NO_OFFLOAD_API \ + NO_OFFLOAD_API, \ + NULL /* get_block_id */ \ } const struct netdev_class netdev_bsd_class = diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 1bde9cf..c223e5b 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -3957,7 +3957,8 @@ unlock: RXQ_RECV, \ NULL, /* rx_wait */ \ NULL, /* rxq_drain */ \ - NO_OFFLOAD_API \ + NO_OFFLOAD_API, \ + NULL /* get_block_id */ \ } static const struct netdev_class dpdk_class = diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index fbc98dd..d498467 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -1464,7 +1464,8 @@ netdev_dummy_update_flags(struct netdev *netdev_, netdev_dummy_rxq_wait, \ netdev_dummy_rxq_drain, \ \ - NO_OFFLOAD_API \ + NO_OFFLOAD_API, \ + NULL /* get_block_id */ \ } static const struct netdev_class dummy_class = diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index d89a0fb..8feab98 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -3115,7 +3115,8 @@ exit: netdev_linux_rxq_wait, \ netdev_linux_rxq_drain, \ \ - FLOW_OFFLOAD_API \ + FLOW_OFFLOAD_API, \ + NULL /* get_block_id */ \ } const struct netdev_class netdev_linux_class = diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h index 4da579c..1a572f5 100644 --- a/lib/netdev-provider.h +++ b/lib/netdev-provider.h @@ -870,6 +870,10 @@ struct netdev_class { /* Initializies the netdev flow api. * Return 0 if successful, otherwise returns a positive errno value. */ int (*init_flow_api)(struct netdev *); + + /* Get a block_id from the netdev. + * Returns the block_id or 0 if none exists for netdev. */ + uint32_t (*get_block_id)(struct netdev *); }; int netdev_register_provider(const struct netdev_class *); diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 14558ad..86dbeec 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -304,6 +304,16 @@ get_prio_for_tc_flower(struct tc_flower *flower) return new_data->prio; } +static uint32_t +get_block_id_from_netdev(struct netdev *netdev) +{ + if (block_support) { + return netdev_get_block_id(netdev); + } + + return 0; +} + int netdev_tc_flow_flush(struct netdev *netdev) { @@ -316,6 +326,8 @@ netdev_tc_flow_flush(struct netdev *netdev) return -ifindex; } + block_id = get_block_id_from_netdev(netdev); + return tc_flush(ifindex, block_id); } @@ -334,6 +346,7 @@ netdev_tc_flow_dump_create(struct netdev *netdev, return -ifindex; } + block_id = get_block_id_from_netdev(netdev); dump = xzalloc(sizeof *dump); dump->nl_dump = xzalloc(sizeof *dump->nl_dump); dump->netdev = netdev_ref(netdev); @@ -1098,6 +1111,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, } } + block_id = get_block_id_from_netdev(netdev); handle = get_ufid_tc_mapping(ufid, &prio, NULL); if (handle && prio) { VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d", handle, prio); @@ -1157,6 +1171,7 @@ netdev_tc_flow_get(struct netdev *netdev OVS_UNUSED, VLOG_DBG_RL(&rl, "flow get (dev %s prio %d handle %d)", netdev_get_name(dev), prio, handle); + block_id = get_block_id_from_netdev(netdev); err = tc_get_flower(ifindex, prio, handle, &flower, block_id); netdev_close(dev); if (err) { @@ -1200,6 +1215,8 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, return -ifindex; } + block_id = get_block_id_from_netdev(netdev); + if (stats) { memset(stats, 0, sizeof *stats); if (!tc_get_flower(ifindex, prio, handle, &flower, block_id)) { @@ -1289,6 +1306,7 @@ netdev_tc_init_flow_api(struct netdev *netdev) ovsthread_once_done(&block_once); } + block_id = get_block_id_from_netdev(netdev); error = tc_add_del_ingress_qdisc(ifindex, true, block_id); if (error && error != EEXIST) { diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index 1dae7e0..2290de9 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -1050,7 +1050,8 @@ netdev_vport_get_ifindex(const struct netdev *netdev_) NULL, /* rx_wait */ \ NULL, /* rx_drain */ \ \ - NETDEV_FLOW_OFFLOAD_API + NETDEV_FLOW_OFFLOAD_API, \ + NULL /* get_block_id */ #define TUNNEL_CLASS(NAME, DPIF_PORT, BUILD_HEADER, PUSH_HEADER, POP_HEADER, \ diff --git a/lib/netdev.c b/lib/netdev.c index 83614f5..82ffeb9 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2225,6 +2225,16 @@ netdev_init_flow_api(struct netdev *netdev) : EOPNOTSUPP); } +uint32_t +netdev_get_block_id(struct netdev *netdev) +{ + const struct netdev_class *class = netdev->netdev_class; + + return (class->get_block_id + ? class->get_block_id(netdev) + : 0); +} + bool netdev_is_flow_api_enabled(void) { diff --git a/lib/netdev.h b/lib/netdev.h index 490b346..c941f1e 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -220,6 +220,7 @@ int netdev_flow_get(struct netdev *, struct match *, struct nlattr **actions, int netdev_flow_del(struct netdev *, const ovs_u128 *, struct dpif_flow_stats *); int netdev_init_flow_api(struct netdev *); +uint32_t netdev_get_block_id(struct netdev *); bool netdev_is_flow_api_enabled(void); void netdev_set_flow_api_enabled(const struct smap *ovs_other_config); From patchwork Thu Jun 28 16:03:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hurley X-Patchwork-Id: 936228 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=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="lduCo4Zh"; 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 41Gl3v4xdCz9s1B for ; Fri, 29 Jun 2018 02:05:15 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 879AEDC8; Thu, 28 Jun 2018 16:03:22 +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 D3C76CFC for ; Thu, 28 Jun 2018 16:03:19 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2451063D for ; Thu, 28 Jun 2018 16:03:19 +0000 (UTC) Received: by mail-ed1-f45.google.com with SMTP id g12-v6so5491556edi.9 for ; Thu, 28 Jun 2018 09:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MhGcE/QwWQoKc/6MhUZVAQxUz2YpRqFv+vzxec2vcn4=; b=lduCo4Zh8ZpyEuxF9RoBXHlaDqwV3eQeSNa4O5cl3etSyrOXQ6sfaAqJ4vIS+a9+1c QhzthCY6lbRtUM7tHOD+yvxgnwvNgdB2GxZyPFS9i6c57Be7N1bsVYun/7HkmtvIpsWs u54UCTlCdNwpFOQtrYcy49U6aAETk45oYMLgstp08Jgzoyd9gZUgk7FI83/ecJhh1gxX l9IMZpDW6ZD2tnhDe5tgwfgfVK2/Ya70jlZvwkFgJM85HvjNud1+SJvu2ei8kfgLiuGE mG4jWTkHme17DBBcqqGMmJPlJme9aD9PXBxgQV9U4+P17UYes3GQNzjHt1U5JGA9OwYl n6Xw== 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=MhGcE/QwWQoKc/6MhUZVAQxUz2YpRqFv+vzxec2vcn4=; b=JV7nUut3uGYl+Von/6G3GRvT6xOndY+nZXWrD2JFBwEuKXZJYVA0X1uIdcpYJu/0II hk16ubeolpAzhr78cjXRdFjpXBAB/w7TUl4PLhCEEwdxbiP0QghQP3KOLW+p020X+p9T c05/NajKpjOGjB4+nxOpHdwjs6OLY28p6rxV7tvlRBqJUak3AGzb1APSZoztQ3Yjk/i7 0dbg4KkXqGAax9gJN9SZ6k2UK1of0qaMk4PZqLV0bmg3e7XVJtJmR4O7TuOhltjTveWe LzxAd3VIxyZ7cKB9GDPzjDF+lpoxn2psa6FYQx9P62qnLVikMkDKycAhMjmwF+AxJ1fz 836w== X-Gm-Message-State: APt69E2CMvZJcVPxCGFkhO/RE49JIVAmvHZLa5FR4zuPHoCPp/x1nhR0 G+X1fglbQzL9d7lM9q2NYfVnI0ml X-Google-Smtp-Source: AAOMgpcibdPI5vi26hjnNnNhXQMNBQ2MJ1d8jL6I2926z8wJjzY7omE7/PARceK2Dr55OHinfU+P+A== X-Received: by 2002:a50:d303:: with SMTP id g3-v6mr10243818edh.208.1530201797534; Thu, 28 Jun 2018 09:03:17 -0700 (PDT) Received: from jhurley-Precision-Tower-3420.netronome.com ([80.76.204.157]) by smtp.gmail.com with ESMTPSA id l54-v6sm4574079edb.13.2018.06.28.09.03.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 09:03:16 -0700 (PDT) From: John Hurley To: dev@openvswitch.org, roid@mellanox.com, gavi@mellanox.com, paulb@mellanox.com, fbl@sysclose.org, simon.horman@netronome.com Date: Thu, 28 Jun 2018 17:03:04 +0100 Message-Id: <1530201787-7071-4-git-send-email-john.hurley@netronome.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> References: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Cc: Jakub Kicinski Subject: [ovs-dev] [PATCH v3 3/6] rtnetlink: extend parser to include kind of master and slave 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 Extend the rtnetlink_parse function to look for linkinfo attributes and, in turn, store pointers to the master and slave kinds (if any) in the rtnetlink_change struct. Signed-off-by: John Hurley Reviewed-by: Simon Horman Reviewed-by: Dirk van der Merwe Signed-off-by: Jakub Kicinski --- lib/rtnetlink.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/rtnetlink.h | 4 ++++ 2 files changed, 47 insertions(+) mode change 100644 => 100755 lib/rtnetlink.h diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c index 4d9003b..f822dff 100644 --- a/lib/rtnetlink.c +++ b/lib/rtnetlink.c @@ -27,6 +27,10 @@ #include "openvswitch/ofpbuf.h" #include "packets.h" +#if IFLA_INFO_MAX < 5 +#define IFLA_INFO_SLAVE_KIND 4 +#endif + static struct nln *nln = NULL; static struct rtnetlink_change rtn_change; @@ -45,6 +49,36 @@ rtnetlink_type_is_rtnlgrp_addr(uint16_t type) return type == RTM_NEWADDR || type == RTM_DELADDR; } +/* Parses nested nlattr for link info. Returns false if unparseable, else + * populates 'change' and returns true. */ +static bool +rtnetlink_parse_link_info(const struct nlattr *nla, + struct rtnetlink_change *change) +{ + bool parsed = false; + + static const struct nl_policy linkinfo_policy[] = { + [IFLA_INFO_KIND] = { .type = NL_A_STRING, .optional = true }, + [IFLA_INFO_SLAVE_KIND] = { .type = NL_A_STRING, .optional = true }, + }; + + struct nlattr *linkinfo[ARRAY_SIZE(linkinfo_policy)]; + + parsed = nl_parse_nested(nla, linkinfo_policy, linkinfo, + ARRAY_SIZE(linkinfo_policy)); + + if (parsed) { + change->master = (linkinfo[IFLA_INFO_KIND] + ? nl_attr_get_string(linkinfo[IFLA_INFO_KIND]) + : NULL); + change->slave = (linkinfo[IFLA_INFO_SLAVE_KIND] + ? nl_attr_get_string(linkinfo[IFLA_INFO_SLAVE_KIND]) + : NULL); + } + + return parsed; +} + /* Parses a rtnetlink message 'buf' into 'change'. If 'buf' is unparseable, * leaves 'change' untouched and returns false. Otherwise, populates 'change' * and returns true. */ @@ -64,6 +98,7 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) [IFLA_MASTER] = { .type = NL_A_U32, .optional = true }, [IFLA_MTU] = { .type = NL_A_U32, .optional = true }, [IFLA_ADDRESS] = { .type = NL_A_UNSPEC, .optional = true }, + [IFLA_LINKINFO] = { .type = NL_A_NESTED, .optional = true }, }; struct nlattr *attrs[ARRAY_SIZE(policy)]; @@ -94,6 +129,14 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) } else { memset(&change->mac, 0, ETH_ADDR_LEN); } + + if (attrs[IFLA_LINKINFO]) { + parsed = rtnetlink_parse_link_info(attrs[IFLA_LINKINFO], + change); + } else { + change->master = NULL; + change->slave = NULL; + } } } else if (rtnetlink_type_is_rtnlgrp_addr(nlmsg->nlmsg_type)) { /* Policy for RTNLGRP_IPV4_IFADDR/RTNLGRP_IPV6_IFADDR messages. diff --git a/lib/rtnetlink.h b/lib/rtnetlink.h old mode 100644 new mode 100755 index 518320f..422d1db --- a/lib/rtnetlink.h +++ b/lib/rtnetlink.h @@ -48,6 +48,10 @@ struct rtnetlink_change { /* Network device address status. */ /* xxx To be added when needed. */ + + /* Link info. */ + const char *master; /* Kind of master (NULL if not master). */ + const char *slave; /* Kind of slave (NULL if not slave). */ }; /* Function called to report that a netdev has changed. 'change' describes the From patchwork Thu Jun 28 16:03:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hurley X-Patchwork-Id: 936229 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=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="x8gNbj/f"; 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 41Gl4h0Rwhz9s1B for ; Fri, 29 Jun 2018 02:05:56 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 6C43DDD0; Thu, 28 Jun 2018 16:03:23 +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 E56CDD90 for ; Thu, 28 Jun 2018 16:03:20 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2B0FC1A0 for ; Thu, 28 Jun 2018 16:03:20 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id m21-v6so786430eds.10 for ; Thu, 28 Jun 2018 09:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HMqQZug89z9/TU8xmrELXDQfwnIqlzguhiPCGyXxp24=; b=x8gNbj/fYcsDrokYY6EuZcvo2cHPrzEnIdjbRf8vUdsNAWBghxlUga+NBTOWi0EdH4 D1C51dlcx7bwfLF9OmiB0CBJImNw1I7LgdUf2x5NlTFNPVsSNtwU7w1wCCi4ABQaKZLo TP4NTmWr8sXgQ6eRPGSvWGW4OKZ85bz3OEfxAMyOewrdLMLy0u8ZzuFjm83d/iHkiPpr zAaw8aDCMr70E+asoSqAiibcblm/4I19vSKpV1n169FqNcknb1KKcJjAXGgYnXAojeKH rTWc3f2MKKjzVib6vsVRvuSpYDaF0Xlwoa1oQajHt0Y1g/B3SKQwYXrYNErINxdVcmuu BEXg== 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=HMqQZug89z9/TU8xmrELXDQfwnIqlzguhiPCGyXxp24=; b=a9X3vHllr96jaeEARRkjJqUYQDGjjmzNglDt8sECM8LaxXqj/gYeX2l+ZHQ/E/CT+S 3jLbpYLUcuFtyy4qLSlSEdMWiHSECywZCR56Nt+Jas080UY0X4d5H8osHQ5AaCmDyIGH XoP+dwJfUAo6gkTmAe5LFNXe781kzOvaSes+taPEPzR095QbWBVitXqCr0++scZrePcw qqx0RWbIVfZHsFt5HIH+nfRb9Jc7pInJOY1zC/TrUE4jJTyacz2SyL5SGE4ViUERF6aO /Kza1IZ+QCIWmuYpOmEwkklgsx8S3ASJmudxE/vG639ZNDRdiLjugHd0pTu8202IUoho GPmA== X-Gm-Message-State: APt69E1SN0qTY8LRq9Qr6f7xifj73Q8wVTcuiwYJj2w1tbUyHd5bV7vb NKKM3qlxpAmtzWBm3f3cnfwvwCkH X-Google-Smtp-Source: AAOMgpeGeMS0LzcrIWCNq3ZDXAti3Fd6QS5ecVP/TJ5s8Jha2imvafrfeCzSznzKs5YWLyKSXwBgiw== X-Received: by 2002:aa7:c48d:: with SMTP id m13-v6mr10067184edq.266.1530201798535; Thu, 28 Jun 2018 09:03:18 -0700 (PDT) Received: from jhurley-Precision-Tower-3420.netronome.com ([80.76.204.157]) by smtp.gmail.com with ESMTPSA id l54-v6sm4574079edb.13.2018.06.28.09.03.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 09:03:18 -0700 (PDT) From: John Hurley To: dev@openvswitch.org, roid@mellanox.com, gavi@mellanox.com, paulb@mellanox.com, fbl@sysclose.org, simon.horman@netronome.com Date: Thu, 28 Jun 2018 17:03:05 +0100 Message-Id: <1530201787-7071-5-git-send-email-john.hurley@netronome.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> References: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Cc: Jakub Kicinski Subject: [ovs-dev] [PATCH v3 4/6] netdev-linux: indicate if netdev is a LAG master 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 If a linux netdev is added to OvS that is a LAG master (for example, a bond or team netdev) then record this in bool form in the dev struct. Use the link info extracted from rtnetlink calls to determine this. Signed-off-by: John Hurley Reviewed-by: Dirk van der Merwe Reviewed-by: Simon Horman Signed-off-by: Jakub Kicinski --- lib/netdev-linux.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 8feab98..6ed2f05 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -509,6 +509,9 @@ struct netdev_linux { int tap_fd; bool present; /* If the device is present in the namespace */ uint64_t tx_dropped; /* tap device can drop if the iface is down */ + + /* LAG information. */ + bool is_lag_master; /* True if the netdev is a LAG master. */ }; struct netdev_rxq_linux { @@ -678,6 +681,16 @@ netdev_linux_miimon_enabled(void) return atomic_count_get(&miimon_cnt) > 0; } +static bool +netdev_linux_kind_is_lag(const char *kind) +{ + if (!strcmp(kind, "bond") || !strcmp(kind, "team")) { + return true; + } + + return false; +} + static void netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) { @@ -812,6 +825,10 @@ netdev_linux_update__(struct netdev_linux *dev, rtnetlink_report_link(); } + if (change->master && netdev_linux_kind_is_lag(change->master)) { + dev->is_lag_master = true; + } + dev->ifindex = change->if_index; dev->cache_valid |= VALID_IFINDEX; dev->get_ifindex_error = 0; @@ -5764,6 +5781,9 @@ netdev_linux_update_via_netlink(struct netdev_linux *netdev) netdev->get_ifindex_error = 0; changed = true; } + if (change->master && netdev_linux_kind_is_lag(change->master)) { + netdev->is_lag_master = true; + } if (changed) { netdev_change_seq_changed(&netdev->up); } From patchwork Thu Jun 28 16:03:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hurley X-Patchwork-Id: 936230 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=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="aLmE8V8q"; 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 41Gl5h58Tnz9s1B for ; Fri, 29 Jun 2018 02:06:48 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7A601DF2; Thu, 28 Jun 2018 16:03:25 +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 CFC68D1B for ; Thu, 28 Jun 2018 16:03:21 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3DA20619 for ; Thu, 28 Jun 2018 16:03:21 +0000 (UTC) Received: by mail-ed1-f44.google.com with SMTP id m21-v6so786462eds.10 for ; Thu, 28 Jun 2018 09:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2V8YSgBkh0HyjzQdM7996TuqFoCW3nZxSW/9Vwi5Yj4=; b=aLmE8V8qhfaumbzv2JfLb6O6j18mUjDgtChzB4bnUtPilQwGLjZy+5kle01NmR6cvQ yMNDYmHkLw2Pr/hR8kqQJxxeHmXY8tC+123UkQiCjgiqvT2uHjnI1o9Iyv1vrEFXx5rS zdZfkOvJY4Ce8st45tWUTHgiTgbeFIO4TODPxzxPLPMLjeWoEDogiwfD+ZHLASYaAzjn I29B8DGLOSF/ZYxLCtsXHJnBB/g2EexKpdCtcg1dSArgbRkfYA/LVQT5+AyPV3J+Sl2V h0DAf8lYE/quVjSW7Z8T/Q8Rcciob2tEQtJhFm/+NrDrJHBqFYkk2nROJgw/fDtVPk/M KviQ== 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=2V8YSgBkh0HyjzQdM7996TuqFoCW3nZxSW/9Vwi5Yj4=; b=hO26i5hBcRVwxgLHc4ccTSkmZ+6FAtX+lqWxUFv1Rt6MOm0PdUjx/Ju1Ug5cq9L7Ck jjbfgJerSPdcNTwN13l1Z/gqmW1QOQKE5sCfHW5wfPO1pFk3Xf8SJoL7WslZ7qNQJsY6 N9i1mJH0oVdyWbmJm2Y3vIU24vtUpy4NRQjx8KSeZ83PwQLbskU//krmaFjxpegAHvzW 4Qg8M3fvGrDcO+Ix2pkx9ZYSU3bllO7pmBL5yVDxC1JBGJ7apepWimUvosJNMR1udDaD vfc8FxdS1mBm9AqSdWtbv/zYhfNXFFgWABW2yWqdP/uy1W8g2wk7AdtSY7WwKEeG1BVO xPxw== X-Gm-Message-State: APt69E25QcOYWRzGXMAYS3Vk4yAdBcfGiMyYWOeqCy4V7c3jXLnAbS8j VIeqAsLVZ7kTdcp0sZxHWVDN1pIQ X-Google-Smtp-Source: AAOMgpeNX5WNbBFMxrfWFfnixc7Nm4M2XGE8PEmSFfCH3sy08QYBt5g2t+gaOfuOkPS08XmWHsP+vQ== X-Received: by 2002:a50:9069:: with SMTP id z38-v6mr6367776edz.79.1530201799660; Thu, 28 Jun 2018 09:03:19 -0700 (PDT) Received: from jhurley-Precision-Tower-3420.netronome.com ([80.76.204.157]) by smtp.gmail.com with ESMTPSA id l54-v6sm4574079edb.13.2018.06.28.09.03.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 09:03:19 -0700 (PDT) From: John Hurley To: dev@openvswitch.org, roid@mellanox.com, gavi@mellanox.com, paulb@mellanox.com, fbl@sysclose.org, simon.horman@netronome.com Date: Thu, 28 Jun 2018 17:03:06 +0100 Message-Id: <1530201787-7071-6-git-send-email-john.hurley@netronome.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> References: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Cc: Jakub Kicinski Subject: [ovs-dev] [PATCH v3 5/6] netdev-linux: assign LAG devs to tc blocks 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 Assign block ids to LAG masters that are added to OvS as linux-netdevs and offloaded via offload API calls. Only LAG masters are assigned to blocks. To ensure uniqueness, the block ids are determined by the netdev ifindex. Implement a get_block_id op for linux netdevs to achieve this. Signed-off-by: John Hurley Reviewed-by: Dirk van der Merwe Reviewed-by: Simon Horman Signed-off-by: Jakub Kicinski --- lib/netdev-linux.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 6ed2f05..81de3b1 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2945,6 +2945,27 @@ netdev_internal_get_status(const struct netdev *netdev OVS_UNUSED, return 0; } +static uint32_t +netdev_linux_get_block_id(struct netdev *netdev_) +{ + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + uint32_t block_id = 0; + + ovs_mutex_lock(&netdev->mutex); + /* Ensure the linux netdev has had its fields populated. */ + if (!(netdev->cache_valid & VALID_IFINDEX)) { + netdev_linux_update_via_netlink(netdev); + } + + /* Only assigning block ids to linux netdevs that are LAG masters. */ + if (netdev->is_lag_master) { + block_id = netdev->ifindex; + } + ovs_mutex_unlock(&netdev->mutex); + + return block_id; +} + /* Looks up the ARP table entry for 'ip' on 'netdev'. If one exists and can be * successfully retrieved, it stores the corresponding MAC address in 'mac' and * returns 0. Otherwise, it returns a positive errno value; in particular, @@ -3060,7 +3081,7 @@ exit: #define NETDEV_LINUX_CLASS(NAME, CONSTRUCT, GET_STATS, \ GET_FEATURES, GET_STATUS, \ - FLOW_OFFLOAD_API) \ + FLOW_OFFLOAD_API, GET_BLOCK_ID) \ { \ NAME, \ false, /* is_pmd */ \ @@ -3133,7 +3154,7 @@ exit: netdev_linux_rxq_drain, \ \ FLOW_OFFLOAD_API, \ - NULL /* get_block_id */ \ + GET_BLOCK_ID \ } const struct netdev_class netdev_linux_class = @@ -3143,7 +3164,8 @@ const struct netdev_class netdev_linux_class = netdev_linux_get_stats, netdev_linux_get_features, netdev_linux_get_status, - LINUX_FLOW_OFFLOAD_API); + LINUX_FLOW_OFFLOAD_API, + netdev_linux_get_block_id); const struct netdev_class netdev_tap_class = NETDEV_LINUX_CLASS( @@ -3152,7 +3174,8 @@ const struct netdev_class netdev_tap_class = netdev_tap_get_stats, netdev_linux_get_features, netdev_linux_get_status, - NO_OFFLOAD_API); + NO_OFFLOAD_API, + NULL); const struct netdev_class netdev_internal_class = NETDEV_LINUX_CLASS( @@ -3161,7 +3184,8 @@ const struct netdev_class netdev_internal_class = netdev_internal_get_stats, NULL, /* get_features */ netdev_internal_get_status, - NO_OFFLOAD_API); + NO_OFFLOAD_API, + NULL); #define CODEL_N_QUEUES 0x0000 From patchwork Thu Jun 28 16:03:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hurley X-Patchwork-Id: 936231 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=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="rbPc5igZ"; 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 41Gl6M27bTz9s1B for ; Fri, 29 Jun 2018 02:07:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 76BB7E04; Thu, 28 Jun 2018 16:03:26 +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 7C333DD6 for ; Thu, 28 Jun 2018 16:03:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 481366CF for ; Thu, 28 Jun 2018 16:03:22 +0000 (UTC) Received: by mail-ed1-f67.google.com with SMTP id g12-v6so5491674edi.9 for ; Thu, 28 Jun 2018 09:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EnFU6ORTwpaxWNF0KeFtDq8FJok0huU5pXm6vykPTps=; b=rbPc5igZ+Maeeiuq98+gCq7zaU9pdnMhWay3l/MN3CKjXj8PmFd+roXxyxjYfcUUN9 UpxgYvhttzNWCMDQzExt0sTa571Nz78TG4P3EfSAQIAWKGqCr3I8nvtG9RDf47DEro4r nLfIySPlSWqYeQ+NAyfP2MKv+yCgP7CbyufWdtdiUmm5GbnDm/E6LHGCoSHKE1UE7MNg mnPmBzLPw9jzuQpzxnSo1sEHsFaw0vp/eMOnq6eJ3j2iK3Sg0mupU6VZUPbgSqhp0h1E 9I5JCfha+aqIUSCdht8iJjqc6iJrGNy8Qi/Zelu+0DArYwQvjZivej9m0djnUTNkHoKT C5rw== 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=EnFU6ORTwpaxWNF0KeFtDq8FJok0huU5pXm6vykPTps=; b=nv5R1X7l81SnC9JO8LacTLaifcYHS4ZOFipKfsUc4ryIMDzxNGzOlBGCNSk9dBv+2x Hban7sURBO/X5Yek17wIMZ4QHisdX50S37P2HXPgxr9BIuG2Hg7cCKonrGXDrTOifKfy Tb4ltPCMhNAjVYGnuDfGMb9BG0f/n5pqrqfQxnRfRwV1m5MpxxSdiNyQQ5t1W55fu6+X uS0TIYyG2i4EjaxArYdm+AUnVqSR46cHEqIAxSPng6mlrrs4acINeT3ObUpluNDWjMUN G3HC4hLWFg4ZQ34rRfbtsCatCQMj5RV0ouTmFkEK5s7vabP7FgCQRcdT6gtBjhU8Jrcd H+Kw== X-Gm-Message-State: APt69E1vG5QUjz/Vg+T2FfXqPS8AjJxH7q1rEEWWNFFioH1pb+nnRDsm aWNJEZ+GqA7I3wQyIBQSuoStaWkH X-Google-Smtp-Source: AAOMgpdn+O7HHkswwmFXuRrMXKYghMRvrPgr+8RlE0iny86r2PJxcngkG0gSA0i4ws14DsaKGPJVCw== X-Received: by 2002:aa7:d30c:: with SMTP id p12-v6mr9942781edq.181.1530201800667; Thu, 28 Jun 2018 09:03:20 -0700 (PDT) Received: from jhurley-Precision-Tower-3420.netronome.com ([80.76.204.157]) by smtp.gmail.com with ESMTPSA id l54-v6sm4574079edb.13.2018.06.28.09.03.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 09:03:20 -0700 (PDT) From: John Hurley To: dev@openvswitch.org, roid@mellanox.com, gavi@mellanox.com, paulb@mellanox.com, fbl@sysclose.org, simon.horman@netronome.com Date: Thu, 28 Jun 2018 17:03:07 +0100 Message-Id: <1530201787-7071-7-git-send-email-john.hurley@netronome.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> References: <1530201787-7071-1-git-send-email-john.hurley@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Cc: Jakub Kicinski Subject: [ovs-dev] [PATCH v3 6/6] netdev-linux: monitor and offload LAG slaves to TC 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 A LAG slave cannot be added directly to an OvS bridge, nor can a OvS bridge port be added to a LAG dev. However, LAG masters can be added to OvS. Use TC blocks to indirectly offload slaves when their master is attached as a linux-netdev to an OvS bridge. In the kernel TC datapath, blocks link together netdevs in a similar way to LAG devices. For example, if a filter is added to a block then it is added to all block devices, or if stats are incremented on 1 device then the stats on the entire block are incremented. This mimics LAG devices in that if a rule is applied to the LAG master then it should be applied to all slaves etc. Monitor LAG slaves via the netlink socket in netdev-linux and, if their master is attached to the OvS bridge and has a block id, add the slave's qdisc to the same block. Similarly, if a slave is freed from a master, remove the qdisc from the masters block. Signed-off-by: John Hurley Reviewed-by: Simon Horman Reviewed-by: Dirk van der Merwe Signed-off-by: Jakub Kicinski --- lib/netdev-linux.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 81de3b1..8e6c637 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -233,6 +233,18 @@ enum { VALID_FEATURES = 1 << 7, }; +struct linux_lag_slave { + uint32_t block_id; + struct shash_node *node; +}; + +/* Protects 'lag_shash' and the mutable members of struct linux_lag_slave. */ +static struct ovs_mutex lag_mutex = OVS_MUTEX_INITIALIZER; + +/* All slaves whose LAG masters are network devices in OvS. */ +static struct shash lag_shash OVS_GUARDED_BY(lag_mutex) + = SHASH_INITIALIZER(&lag_shash); + /* Traffic control. */ /* An instance of a traffic control class. Always associated with a particular @@ -692,6 +704,61 @@ netdev_linux_kind_is_lag(const char *kind) } static void +netdev_linux_update_lag(struct rtnetlink_change *change) + OVS_REQUIRES(lag_mutex) +{ + struct linux_lag_slave *lag; + + if (!rtnetlink_type_is_rtnlgrp_link(change->nlmsg_type)) { + return; + } + + if (change->slave && netdev_linux_kind_is_lag(change->slave)) { + lag = shash_find_data(&lag_shash, change->ifname); + + if (!lag) { + struct netdev *master_netdev; + char master_name[IFNAMSIZ]; + uint32_t block_id; + int error = 0; + + if_indextoname(change->master_ifindex, master_name); + master_netdev = netdev_from_name(master_name); + + if (is_netdev_linux_class(master_netdev->netdev_class)) { + block_id = netdev_get_block_id(master_netdev); + if (!block_id) { + return; + } + + lag = xmalloc(sizeof *lag); + lag->block_id = block_id; + lag->node = shash_add(&lag_shash, change->ifname, lag); + + /* LAG master is linux netdev so add slave to same block. */ + error = tc_add_del_ingress_qdisc(change->if_index, true, + block_id); + if (error) { + VLOG_WARN("failed to bind LAG slave to master's block"); + shash_delete(&lag_shash, lag->node); + free(lag); + } + } + } + } else if (change->master_ifindex == 0) { + /* Check if this was a lag slave that has been freed. */ + lag = shash_find_data(&lag_shash, change->ifname); + + if (lag) { + tc_add_del_ingress_qdisc(change->if_index, false, + lag->block_id); + shash_delete(&lag_shash, lag->node); + free(lag); + } + } +} + +static void netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) { struct nl_sock *sock; @@ -734,6 +801,12 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) netdev_linux_update(netdev, nsid, &change); ovs_mutex_unlock(&netdev->mutex); } + else if (!netdev_ && change.ifname) { + /* Netdev is not present in OvS but its master could be. */ + ovs_mutex_lock(&lag_mutex); + netdev_linux_update_lag(&change); + ovs_mutex_unlock(&lag_mutex); + } netdev_close(netdev_); } } else if (error == ENOBUFS) {