From patchwork Wed Jun 8 23:16:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Samudrala, Sridhar" X-Patchwork-Id: 632571 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rQ4Fn0d2Nz9t3t for ; Thu, 9 Jun 2016 09:21:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754630AbcFHXVp (ORCPT ); Wed, 8 Jun 2016 19:21:45 -0400 Received: from mga01.intel.com ([192.55.52.88]:23956 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751049AbcFHXVo (ORCPT ); Wed, 8 Jun 2016 19:21:44 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 08 Jun 2016 16:21:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,441,1459839600"; d="scan'208";a="998165843" Received: from sri02.jf.intel.com ([10.166.39.21]) by fmsmga002.fm.intel.com with ESMTP; 08 Jun 2016 16:21:43 -0700 From: Sridhar Samudrala To: john.r.fastabend@intel.com, jakub.kicinski@netronome.com, netdev@vger.kernel.org, shemming@brocade.com Subject: [PATCH v2 iproute2] tc: f_u32: Add support for skip_hw and skip_sw flags Date: Wed, 8 Jun 2016 16:16:01 -0700 Message-Id: <1465427761-7038-1-git-send-email-sridhar.samudrala@intel.com> X-Mailer: git-send-email 2.1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On devices that support TC U32 offloads, these flags enable a filter to be added only to HW or only to SW. skip_sw and skip_hw are mutually exclusive flags. By default without any flags, the filter is added to both HW and SW, but no error checks are done in case of failure to add to HW. With skip-sw, failure to add to HW is treated as an error. Here is a sample script that adds 2 filters, one with skip_sw and the other with skip_hw flag. # add ingress qdisc tc qdisc add dev p4p1 ingress # enable hw tc offload. ethtool -K p4p1 hw-tc-offload on # add u32 filter with skip-sw flag. tc filter add dev p4p1 parent ffff: protocol ip prio 99 \ handle 800:0:1 u32 ht 800: flowid 800:1 \ skip-sw \ match ip src 192.168.1.0/24 \ action drop # add u32 filter with skip-hw flag. tc filter add dev p4p1 parent ffff: protocol ip prio 99 \ handle 800:0:2 u32 ht 800: flowid 800:2 \ skip-hw \ match ip src 192.168.2.0/24 \ action drop Signed-off-by: Sridhar Samudrala --- v2: - updated to latest iproute2 git tc/f_u32.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tc/f_u32.c b/tc/f_u32.c index 9424dc3..b6ae4d2 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -30,7 +30,7 @@ extern int show_pretty; static void explain(void) { - fprintf(stderr, "Usage: ... u32 [ match SELECTOR ... ] [ link HTID ] [ classid CLASSID ]\n"); + fprintf(stderr, "Usage: ... u32 [ match SELECTOR ... ] [ link HTID ] [ classid CLASSID ] [skip-hw | skip-sw]\n"); fprintf(stderr, " [ action ACTION_SPEC ] [ offset OFFSET_SPEC ]\n"); fprintf(stderr, " [ ht HTID ] [ hashkey HASHKEY_SPEC ]\n"); fprintf(stderr, " [ sample SAMPLE ]\n"); @@ -993,6 +993,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, int sample_ok = 0; __u32 htid = 0; __u32 order = 0; + __u32 flags = 0; memset(&sel, 0, sizeof(sel)); @@ -1152,6 +1153,14 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, } terminal_ok++; continue; + } else if (strcmp(*argv, "skip_hw") == 0) { + NEXT_ARG(); + flags |= TCA_CLS_FLAGS_SKIP_HW; + continue; + } else if (strcmp(*argv, "skip_sw") == 0) { + NEXT_ARG(); + flags |= TCA_CLS_FLAGS_SKIP_SW; + continue; } else if (strcmp(*argv, "help") == 0) { explain(); return -1; @@ -1182,6 +1191,15 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel.sel) + sel.sel.nkeys * sizeof(struct tc_u32_key)); + if (flags) { + if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW))) { + fprintf(stderr, "skip_hw and skip_sw are mutually " + "exclusive flags. Only one can be set\n"); + return -1; + } + addattr_l(n, MAX_MSG, TCA_U32_FLAGS, &flags, 4); + } + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; return 0; } @@ -1240,6 +1258,15 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, b1)); } + if (tb[TCA_U32_FLAGS]) { + __u32 flags = rta_getattr_u32(tb[TCA_U32_FLAGS]); + + if (flags & TCA_CLS_FLAGS_SKIP_HW) + fprintf(f, "skip_hw "); + if (flags & TCA_CLS_FLAGS_SKIP_SW) + fprintf(f, "skip_sw "); + } + if (tb[TCA_U32_PCNT]) { if (RTA_PAYLOAD(tb[TCA_U32_PCNT]) < sizeof(*pf)) { fprintf(f, "Broken perf counters\n");