From patchwork Thu Jan 18 16:20:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 863005 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="AKM4ujox"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zMq2s3rLSz9s81 for ; Fri, 19 Jan 2018 03:21:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933481AbeARQVX (ORCPT ); Thu, 18 Jan 2018 11:21:23 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:40249 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932735AbeARQVS (ORCPT ); Thu, 18 Jan 2018 11:21:18 -0500 Received: by mail-it0-f67.google.com with SMTP id 196so14180465iti.5 for ; Thu, 18 Jan 2018 08:21:18 -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=fPUv21tCjxFAmeWhdf555cXa2i3FH7izC3yCnJv6AJ0=; b=AKM4ujoxHuAnEkgkWAh9R7DMRZLVx8eH5FHmPqI+6rZHY7aOg5KlqbRQEppKbQBkd/ 5cn8oCgTaNjfhSFJ8/rPod36830QTZeNpeKCWs+ZaVv9GPWRgFS1p6C+S25DBaB2mJkV Sngs3MqU++bVO+FBOKR52iWB5H2p5wy9kJP2g57pfqCHorYn3rzCeQr0FqVERavuYVOI /dvj2M+UMeLLMrfjpoDFHdvuJJ8O/SbgSAnqkVhdYE6xZfs6AnD3TYTRjjf4OH02go7N n6sPY9FWXhNI4OUBNjHJqPXQ14cguzbWePJ+Y96TnV3bi421GZhaPN/QWNeygT14f/El K0Kg== 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=fPUv21tCjxFAmeWhdf555cXa2i3FH7izC3yCnJv6AJ0=; b=FUtXuZM3yrAcAgx5p1dClbCN/+pcK5C/wsT2LysdmqlaCJYckinNLZD0PvgKr78VNu VmuO+1ck4lf228SNzIyBequFiKK/6fujYnxQr2HGmUIbeIzKKaL3n2cxIjVciQXBWjaG s3TknVJ+TpGr+rcB22d6Y0RKcqkfOlSkUgwU3swqzyzryvXw2b27exrl7wnq7tfgbm4d Hu75Nae2jFcPzUgjp6XwxqEvJZ8Fz0V4IPmdLGhmXVk83n4jtTeR1GD0DmiGjwYSCIlz HwYeSRZNtNuYrXt06s3F+J7i8LKY4pCLHZQqQcnd8BUjN/DFMnuy1u+Xfovk3YBCfnAs ngxw== X-Gm-Message-State: AKwxyteVwTWbk/IM3ZBDfGh24mx/yvMLHum/NuGn8AyIP7ipKBz8WvP9 NGwa2+v+iiNRv+glI1YW9LpdTQ== X-Google-Smtp-Source: ACJfBotwSfOo0HLHdRibz3B/ctXWOngTHdyAAJPZiDD2vslFrUwMQoOV4drL5gwGf/PWyQfP8Wre1g== X-Received: by 10.36.29.142 with SMTP id 136mr14522090itj.126.1516292477992; Thu, 18 Jan 2018 08:21:17 -0800 (PST) Received: from x220t.lan ([64.26.149.125]) by smtp.gmail.com with ESMTPSA id k185sm3831890iok.39.2018.01.18.08.21.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 08:21:17 -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: [PATCHv3 net-next 7/7] net: sched: cls_u32: add extack support Date: Thu, 18 Jan 2018 11:20:55 -0500 Message-Id: <20180118162055.31587-8-aring@mojatatu.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180118162055.31587-1-aring@mojatatu.com> References: <20180118162055.31587-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 Acked-by: Jiri Pirko --- net/sched/cls_u32.c | 58 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index e8963ed35899..57113e936155 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -689,13 +689,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_MOD(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_MOD(extack, "Can not delete in-use filter"); return -EBUSY; } @@ -779,14 +782,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_MOD(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_MOD(extack, "Link hash table not found"); return -EINVAL; + } ht_down->refcnt++; } @@ -910,28 +917,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_MOD(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_MOD(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_MOD(extack, "Key node id cannot be zero"); return -EINVAL; + } - if (n->flags != flags) + if (n->flags != flags) { + NL_SET_ERR_MSG_MOD(extack, "Key node flags do not match passed flags"); return -EINVAL; + } new = u32_init_knode(tp, n); if (!new) @@ -965,10 +984,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_MOD(extack, "Exceeded maximum 256 hash buckets"); return -EINVAL; - if (TC_U32_KEY(handle)) + } + if (TC_U32_KEY(handle)) { + NL_SET_ERR_MSG_MOD(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; @@ -1014,20 +1037,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_MOD(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_MOD(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_MOD(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, @@ -1038,6 +1067,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_MOD(extack, "Selector not specified"); err = -EINVAL; goto erridr; }