From patchwork Fri Jan 12 11:20:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 859772 X-Patchwork-Delegate: shemminger@vyatta.com 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=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zJ0fg6jMFz9t3B for ; Fri, 12 Jan 2018 22:20:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933432AbeALLUi (ORCPT ); Fri, 12 Jan 2018 06:20:38 -0500 Received: from orbyte.nwl.cc ([151.80.46.58]:36018 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932740AbeALLUf (ORCPT ); Fri, 12 Jan 2018 06:20:35 -0500 Received: from localhost ([::1]:58786 helo=xsao) by orbyte.nwl.cc with esmtp (Exim 4.89) (envelope-from ) id 1eZxNw-0006lk-47; Fri, 12 Jan 2018 12:20:32 +0100 From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org, Jiri Pirko , Jamal Hadi Salim , David Ahern Subject: [iproute PATCH] tc: Optimize gact action lookup Date: Fri, 12 Jan 2018 12:20:21 +0100 Message-Id: <20180112112021.20253-1-phil@nwl.cc> X-Mailer: git-send-email 2.15.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When adding a filter with a gact action such as 'drop', tc first tries to open a shared object with equivalent name (m_drop.so in this case) before trying gact. Avoid this by matching the action name against those handled by gact prior to calling get_action_kind(). Cc: Jiri Pirko Cc: Jamal Hadi Salim Cc: David Ahern Signed-off-by: Phil Sutter --- tc/m_action.c | 5 ++++- tc/tc_util.c | 10 ++++++---- tc/tc_util.h | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tc/m_action.c b/tc/m_action.c index fc4223648e8cf..d3df93c066a89 100644 --- a/tc/m_action.c +++ b/tc/m_action.c @@ -194,7 +194,10 @@ int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) } else { struct action_util *a = NULL; - strncpy(k, *argv, sizeof(k) - 1); + if (!action_a2n(*argv, NULL, false)) + strncpy(k, "gact", sizeof(k) - 1); + else + strncpy(k, *argv, sizeof(k) - 1); eap = 0; if (argc > 0) { a = get_action_kind(k); diff --git a/tc/tc_util.c b/tc/tc_util.c index ee9a70aa6830c..10e5aa91168a1 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -511,7 +511,7 @@ static const char *action_n2a(int action) * * In error case, returns -1 and does not touch @result. Otherwise returns 0. */ -static int action_a2n(char *arg, int *result, bool allow_num) +int action_a2n(char *arg, int *result, bool allow_num) { int n; char dummy; @@ -535,13 +535,15 @@ static int action_a2n(char *arg, int *result, bool allow_num) for (iter = a2n; iter->a; iter++) { if (matches(arg, iter->a) != 0) continue; - *result = iter->n; - return 0; + n = iter->n; + goto out_ok; } if (!allow_num || sscanf(arg, "%d%c", &n, &dummy) != 1) return -1; - *result = n; +out_ok: + if (result) + *result = n; return 0; } diff --git a/tc/tc_util.h b/tc/tc_util.h index 1218610d77092..e354765ff1ed0 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -132,4 +132,6 @@ int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt); int cls_names_init(char *path); void cls_names_uninit(void); +int action_a2n(char *arg, int *result, bool allow_num); + #endif