From patchwork Sun May 8 14:44:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 619659 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 3r2pFg1Jl4z9t0r for ; Mon, 9 May 2016 00:44:52 +1000 (AEST) 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=UBx8/aH9; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750823AbcEHOoq (ORCPT ); Sun, 8 May 2016 10:44:46 -0400 Received: from mail-ig0-f196.google.com ([209.85.213.196]:33108 "EHLO mail-ig0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750715AbcEHOoq (ORCPT ); Sun, 8 May 2016 10:44:46 -0400 Received: by mail-ig0-f196.google.com with SMTP id rc4so9298181igc.0 for ; Sun, 08 May 2016 07:44:45 -0700 (PDT) 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; bh=30UC8TS7bqrbU5JBhevQpkltpjXT+BwMHIrwcVotRe8=; b=UBx8/aH9v8cv0YNHb+hUpC9SZz1zwyvkFKm4J2AAsKhLMshA5/kSOOK2jk0L+XdNkx LUFsyqz8ePRN4qkOHj6r3DujbiNVBuNRGJcfRLj3sdae9r0ppgkMf01L4r26uAti4BCE SajiZpGU1NMzzuPBr+N5Uyhmh+astWNaFGZcxXaqBSNbCYl6ayQjMGslFa6ydZuvVhPY N9xHG8FyqCW7ORhe7ax13vGHh6IDlUZQuzn+QObbgjVrQZf7vZ4ONOcIqrrVWinqK1Hp pPwdk6VtV48Mu7u7IvKgy4k51IhpW5gA5sY575NkSpKMFfOCaHHGNOxkojvn7BifQx4G nHsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=30UC8TS7bqrbU5JBhevQpkltpjXT+BwMHIrwcVotRe8=; b=OynxfYUAu/vHeYegVji2iRHYw+SQ7NL35GKPTEbnjfhJBZLQzhUcdMEU+P+XuXfGBM kB1KtYRArLoO1+J8slLKjv6LDZxXEJC8O3l5IbD2EPc6RolFBdluLOZZl1kLiwb40eqv 9b1jv8a5BhMqt+6KTq0Xt6eUXQuW8kaKG73iIUTKeeFQ5qyFaWWtfeIFa7VSd+A3knjF kop3BDl+89jP1p/3RU7CHXmDcsxgL4E0w4uaUYpMd9yxpIFRQrBNXI175eQ0gwCwuANI 8nlYmchYsDEwvE362LERrqraq/wir7D3l9RWPRcr9SbpQxSB+ZT+vYV77daAEzqb9iok hBFQ== X-Gm-Message-State: AOPr4FVpQ7g1QapUrYT95AkxjKIHn119Bs5QQp9t2l9XhxdX2vkbCaXhMoMpRaC8SxUioQ== X-Received: by 10.50.13.106 with SMTP id g10mr6733326igc.65.1462718684891; Sun, 08 May 2016 07:44:44 -0700 (PDT) Received: from jhs-UX303LB.lan ([23.233.30.50]) by smtp.gmail.com with ESMTPSA id vf17sm9075457igb.22.2016.05.08.07.44.43 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 08 May 2016 07:44:44 -0700 (PDT) From: Jamal Hadi Salim X-Google-Original-From: Jamal Hadi Salim To: stephen@networkplumber.org Cc: netdev@vger.kernel.org, Jamal Hadi Salim Subject: [iproute2 PATCH 1/1] tc simple action update and breakage Date: Sun, 8 May 2016 10:44:35 -0400 Message-Id: <1462718675-7083-1-git-send-email-jhs@emojatatu.com> X-Mailer: git-send-email 1.9.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim Brings it closer to more serious actions (adding branching and allowing for late binding) Unfortunately this breaks old syntax of the simple action. But because simple is a pedagogical example unlikely to be used in production environments (i.e its role is to serve as an example on how to write actions), then this is ok. New syntax for simple has new keyword "sdata". Example usage is: sudo tc actions add action simple sdata "foobar" index 1 or tc filter add dev $DEV parent ffff: protocol ip prio 1 u32\ match ip dst 17.0.0.1/32 flowid 1:10 action simple sdata "foobar" Signed-off-by: Jamal Hadi Salim --- tc/m_simple.c | 64 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/tc/m_simple.c b/tc/m_simple.c index e167cca..8e85f99 100644 --- a/tc/m_simple.c +++ b/tc/m_simple.c @@ -81,9 +81,10 @@ #endif static void explain(void) { - fprintf(stderr, "Usage: ... simple STRING\n" - "STRING being an arbitrary string\n" - "example: \"simple blah\"\n"); + fprintf(stderr, "Usage:... simple [sdata STRING] [CONTROL] [index INDEX]\n"); + fprintf(stderr, "\tSTRING being an arbitrary string\n" + "\tCONTROL := reclassify|pipe|drop|continue|ok\n" + "\tINDEX := optional index value used\n"); } static void usage(void) @@ -99,56 +100,87 @@ parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct tc_defact sel = {}; int argc = *argc_p; char **argv = *argv_p; - int ok = 0; + int ok = 0, maybe_bind = 0; struct rtattr *tail; char *simpdata = NULL; - while (argc > 0) { if (matches(*argv, "simple") == 0) { NEXT_ARG(); - simpdata = *argv; - ok = 1; - argc--; - argv++; break; + } else if (matches(*argv, "sdata") == 0) { + NEXT_ARG(); + ok += 1; + simpdata = *argv; } else if (matches(*argv, "help") == 0) { usage(); } else { break; } - + argc--; + argv++; } - if (!ok) { - explain(); - return -1; + + if (argc) { + if (matches(*argv, "reclassify") == 0) { + sel.action = TC_ACT_RECLASSIFY; + argc--; + argv++; + } else if (matches(*argv, "pipe") == 0) { + sel.action = TC_ACT_PIPE; + argc--; + argv++; + } else if (matches(*argv, "drop") == 0 || + matches(*argv, "shot") == 0) { + sel.action = TC_ACT_SHOT; + argc--; + argv++; + } else if (matches(*argv, "continue") == 0) { + sel.action = TC_ACT_UNSPEC; + argc--; + argv++; + } else if (matches(*argv, "pass") == 0 || + matches(*argv, "ok") == 0) { + sel.action = TC_ACT_OK; + argc--; + argv++; + } } if (argc) { if (matches(*argv, "index") == 0) { NEXT_ARG(); if (get_u32(&sel.index, *argv, 10)) { - fprintf(stderr, "simple: Illegal \"index\"\n"); + fprintf(stderr, "simple: Illegal \"index\"\n", + *argv); return -1; } + ok += 1; argc--; argv++; } } - if (strlen(simpdata) > (SIMP_MAX_DATA - 1)) { + if (!ok) { + explain(); + return -1; + } + + if (simpdata && (strlen(simpdata) > (SIMP_MAX_DATA - 1))) { fprintf(stderr, "simple: Illegal string len %zu <%s>\n", strlen(simpdata), simpdata); return -1; } + sel.action = TC_ACT_PIPE; tail = NLMSG_TAIL(n); addattr_l(n, MAX_MSG, tca_id, NULL, 0); addattr_l(n, MAX_MSG, TCA_DEF_PARMS, &sel, sizeof(sel)); - addattr_l(n, MAX_MSG, TCA_DEF_DATA, simpdata, SIMP_MAX_DATA); + if (simpdata) + addattr_l(n, MAX_MSG, TCA_DEF_DATA, simpdata, SIMP_MAX_DATA); tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; *argc_p = argc;