From patchwork Wed Jan 17 22:40:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 862623 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mojatatu-com.20150623.gappssmtp.com header.i=@mojatatu-com.20150623.gappssmtp.com header.b="OQyOqYkI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zMMWC4xTXz9t1t for ; Thu, 18 Jan 2018 09:40:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753621AbeAQWkw (ORCPT ); Wed, 17 Jan 2018 17:40:52 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:36921 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753337AbeAQWkt (ORCPT ); Wed, 17 Jan 2018 17:40:49 -0500 Received: by mail-io0-f194.google.com with SMTP id f89so14613232ioj.4 for ; Wed, 17 Jan 2018 14:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=N6LOeIj2qx3GLTxOxoqkxnV2wLrdx+boqKkyzqA6ejI=; b=OQyOqYkI35gBnGTu23MA+Nf/L1J6GGEtzn6Lv7JdxhMKv5zMlDx51/zB1+B52QQENP rJhV/DAkfDjNFyagCADbRFFzPj2OsaVl96THxT9xAf45xu020lBYy7PrevGiuFdU0Oka V8BrVtit0NwcSxHmT6P+TAnErFQoL5/jLW7r69jk0K3d+Xy9nfWc712wzXlXAGx71T9w TciJ1PxPAFvO8WIvjuxV0hG67a7oL+fUFJovXZnEDkKbI+s4ew+zOzCqABToxz/lPImB q7Bw/0iGJYDNmlAkfdxkdSky3KRCz90BhJaLpXOBo7jUD2W5Cu+S6OLB+nDDtNXjEDl4 AXqw== 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=N6LOeIj2qx3GLTxOxoqkxnV2wLrdx+boqKkyzqA6ejI=; b=HGPyw7Tl4+f0wVMaK7X98N3lopBMCqDsGQEPJeRD6dlxKH+Tct4FZWYnf2WmOAaQVq bchS/DOH2JwBM7N1RQHvIP1g+fJdxaFNAj8fM4P/iFRksoXMzXGkqFYPKKupPtQA6fmy jDnSu8dYk4HB3cr+bTE41XbOaPChJBmtuaAU3SP7qxoRVtB06LzEL4lpiUmv5PeLQOCC dON3WzbG6ENP+GOk6pcqRzK3DrBR+ke+ifwtAbkeU9kSf4o5dhb8u1dBkTnHh4zqfQLC f/5H2++TneTpqBQuLui7hf+sH2TxTY/tniT+oDlOHxBrqg9whIfxnjcQZ9QkAfZy9vo5 RVtw== X-Gm-Message-State: AKwxytdJyANL4EjX8ZC4MwxbUNPYUDQz27Z812eoLzQ5X72mRpH2LlOU vS+kMtCdwXO4yLHVdXUpQU53gw== X-Google-Smtp-Source: ACJfBovbdprW14yv7LqhnVSngM0UeE+ykVLtvQ4lryTaBCGH4PVYa7hqYReiGNGb38JgjJ+7KPojCQ== X-Received: by 10.107.167.136 with SMTP id q130mr13334066ioe.173.1516228848751; Wed, 17 Jan 2018 14:40:48 -0800 (PST) Received: from x220t.lan ([64.26.149.125]) by smtp.gmail.com with ESMTPSA id p68sm2908729itc.26.2018.01.17.14.40.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 14:40:48 -0800 (PST) From: Alexander Aring To: jhs@mojatatu.com Cc: xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, netdev@vger.kernel.org, kernel@mojatatu.com, kubakici@wp.pl, Alexander Aring , David Ahern Subject: [PATCHv2 net-next 8/8] net: sched: cls_u32: add extack support Date: Wed, 17 Jan 2018 17:40:27 -0500 Message-Id: <20180117224027.24049-9-aring@mojatatu.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180117224027.24049-1-aring@mojatatu.com> References: <20180117224027.24049-1-aring@mojatatu.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds extack support for the u32 classifier as example for delete and init callback. Cc: David Ahern Signed-off-by: Alexander Aring --- net/sched/cls_u32.c | 66 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 8840baa1b9b4..daeac7282387 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -524,8 +524,10 @@ static int u32_replace_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h, offloaded = true; } - if (skip_sw && !offloaded) + if (skip_sw && !offloaded) { + NL_SET_ERR_MSG(extack, "Failed to offload filter requested with skip sw"); return -EINVAL; + } return 0; } @@ -576,8 +578,10 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, tcf_block_offload_inc(block, &n->flags); } - if (skip_sw && !(n->flags & TCA_CLS_FLAGS_IN_HW)) + if (skip_sw && !(n->flags & TCA_CLS_FLAGS_IN_HW)) { + NL_SET_ERR_MSG(extack, "Failed to offload filter requested with skip sw"); return -EINVAL; + } return 0; } @@ -691,13 +695,16 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last, goto out; } - if (root_ht == ht) + if (root_ht == ht) { + NL_SET_ERR_MSG(extack, "Not allowed to delete root node"); return -EINVAL; + } if (ht->refcnt == 1) { ht->refcnt--; u32_destroy_hnode(tp, ht); } else { + NL_SET_ERR_MSG(extack, "Can not delete in-use filter"); return -EBUSY; } @@ -781,14 +788,18 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, u32 handle = nla_get_u32(tb[TCA_U32_LINK]); struct tc_u_hnode *ht_down = NULL, *ht_old; - if (TC_U32_KEY(handle)) + if (TC_U32_KEY(handle)) { + NL_SET_ERR_MSG(extack, "u32 Link handle must be a hash table"); return -EINVAL; + } if (handle) { ht_down = u32_lookup_ht(ht->tp_c, handle); - if (!ht_down) + if (!ht_down) { + NL_SET_ERR_MSG(extack, "Link hash table not found"); return -EINVAL; + } ht_down->refcnt++; } @@ -912,28 +923,40 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, size_t size; #endif - if (!opt) - return handle ? -EINVAL : 0; + if (!opt) { + if (handle) { + NL_SET_ERR_MSG(extack, "Filter handle requires options"); + return -EINVAL; + } else { + return 0; + } + } - err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, NULL); + err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, extack); if (err < 0) return err; if (tb[TCA_U32_FLAGS]) { flags = nla_get_u32(tb[TCA_U32_FLAGS]); - if (!tc_flags_valid(flags)) + if (!tc_flags_valid(flags)) { + NL_SET_ERR_MSG(extack, "Invalid filter flags"); return -EINVAL; + } } n = *arg; if (n) { struct tc_u_knode *new; - if (TC_U32_KEY(n->handle) == 0) + if (TC_U32_KEY(n->handle) == 0) { + NL_SET_ERR_MSG(extack, "Key node id cannot be zero"); return -EINVAL; + } - if (n->flags != flags) + if (n->flags != flags) { + NL_SET_ERR_MSG(extack, "Key node flags do not match passed flags"); return -EINVAL; + } new = u32_init_knode(tp, n); if (!new) @@ -967,10 +990,14 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, if (tb[TCA_U32_DIVISOR]) { unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]); - if (--divisor > 0x100) + if (--divisor > 0x100) { + NL_SET_ERR_MSG(extack, "Exceeded maximum 256 hash buckets"); return -EINVAL; - if (TC_U32_KEY(handle)) + } + if (TC_U32_KEY(handle)) { + NL_SET_ERR_MSG(extack, "Divisor can only be used on a hash table"); return -EINVAL; + } ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL); if (ht == NULL) return -ENOBUFS; @@ -1016,20 +1043,26 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, htid = ht->handle; } else { ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid)); - if (!ht) + if (!ht) { + NL_SET_ERR_MSG(extack, "Specified hash table not found"); return -EINVAL; + } } } else { ht = rtnl_dereference(tp->root); htid = ht->handle; } - if (ht->divisor < TC_U32_HASH(htid)) + if (ht->divisor < TC_U32_HASH(htid)) { + NL_SET_ERR_MSG(extack, "Specified hash table buckets exceed configured value"); return -EINVAL; + } if (handle) { - if (TC_U32_HTID(handle) && TC_U32_HTID(handle ^ htid)) + if (TC_U32_HTID(handle) && TC_U32_HTID(handle ^ htid)) { + NL_SET_ERR_MSG(extack, "Handle specified hash table address mismatch"); return -EINVAL; + } handle = htid | TC_U32_NODE(handle); err = idr_alloc_ext(&ht->handle_idr, NULL, NULL, handle, handle + 1, @@ -1040,6 +1073,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, handle = gen_new_kid(ht, htid); if (tb[TCA_U32_SEL] == NULL) { + NL_SET_ERR_MSG(extack, "Selector not specified"); err = -EINVAL; goto erridr; }