From patchwork Wed Oct 19 14:14:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shmulik Ladkani X-Patchwork-Id: 684237 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 3szclR3QYcz9s3s for ; Thu, 20 Oct 2016 03:26:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=d20YGPDz; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755171AbcJSQ0Z (ORCPT ); Wed, 19 Oct 2016 12:26:25 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:34097 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938717AbcJSOOU (ORCPT ); Wed, 19 Oct 2016 10:14:20 -0400 Received: by mail-qk0-f196.google.com with SMTP id n189so2043389qke.1 for ; Wed, 19 Oct 2016 07:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=iVtLDFk+8RVKK/69Poplg+/0VVOATtfOfQgeup5S+5Y=; b=d20YGPDzC9c6/qf3RZE7tsFXS9eLY0Xi4LCAPSKpxwBs/bxrUsYA5kq9IAxbd915hM dYxf1T5vEwVSfpH3wLG2yXVyHlUZBR2KRTrWNysm1vUyX8E7KY4TwGopF/no45V4fiXm 40eFJzZDSbwEs1lhx8nYxogKJxctSas2SQneJ+kHgWo8AMXfa350ZtrGtW1w1q0uRomo xp/2BFWJKkjFG5jbCrYLczBNm+ebfuror7YHHN4mTFOrX664B+UP2Ez7ObjbOA3L7qrM 6ZNxgGFN9OaTa//TZdTM7ja/oR6PyUoicdBUs0tC+J+CL/lQeTM+zd1tNf2gySR3EAEM jYxQ== 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=iVtLDFk+8RVKK/69Poplg+/0VVOATtfOfQgeup5S+5Y=; b=ZDHKZKiEkdk9d6xhF5ueuOapEssPFSUCfRhxgRv/xLr50YY0di2b+EFRffI5j/27VA UbB1wWwVjArJEbmoG7Qpk5ZGzmQIrsrrTNLnXxGuxr7ENo7vAxKYjV3yjR8a+bmhGcAt 6NUR91Ovokf1Wi0wA2rmuf05dd7CnnCmY0xHtrQ+mlF90UkKPdZT4YfArdjAYC9LucYV pcIG2T/3w8pt9rRLH4hl+AAhiNHKpdN05ArDGw2M0at5wuy0Ti68a+V1mEAAnLsNP+7D Lz5vdBUenOB6Kq0WHLDJiXA3pO64kzx1AryMLA/NB4OtBKqh6GvOIoTpmsNez+9bzCIz Dxug== X-Gm-Message-State: AA6/9RlzcOU9KzKusOkbJa8y+hxMvDek/myZx+dAtKVMye+Ulpj4meKct39dwJwBCOfPyA== X-Received: by 10.194.202.195 with SMTP id kk3mr4399530wjc.37.1476886459793; Wed, 19 Oct 2016 07:14:19 -0700 (PDT) Received: from pixies.home ([37.46.41.157]) by smtp.gmail.com with ESMTPSA id h3sm69549735wjp.45.2016.10.19.07.14.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 07:14:19 -0700 (PDT) From: Shmulik Ladkani To: Stephen Hemminger , Jamal Hadi Salim Cc: netdev@vger.kernel.org, Shmulik Ladkani Subject: [PATCH iproute2 net-next] tc: m_mirred: Add support for ingress redirect/mirror Date: Wed, 19 Oct 2016 17:14:09 +0300 Message-Id: <20161019141409.23172-1-shmulik.ladkani@gmail.com> X-Mailer: git-send-email 2.10.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org So far, only the 'egress' direction was implemented. Allow specifying 'ingress' as the direction packet appears on the target interface. For example, this takes incoming 802.1q frames on veth0 and redirects them for input on dummy0: # tc filter add dev veth0 parent ffff: pref 1 protocol 802.1q basic \ action mirred ingress redirect dev dummy0 Signed-off-by: Shmulik Ladkani --- man/man8/tc-mirred.8 | 4 +--- tc/m_mirred.c | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/man/man8/tc-mirred.8 b/man/man8/tc-mirred.8 index bba96e0..38833b4 100644 --- a/man/man8/tc-mirred.8 +++ b/man/man8/tc-mirred.8 @@ -30,9 +30,7 @@ receives. Mirroring is what is sometimes referred to as Switch Port Analyzer .TQ .B egress Specify the direction in which the packet shall appear on the destination -interface. Currently only -.B egress -is implemented. +interface. .TP .B mirror .TQ diff --git a/tc/m_mirred.c b/tc/m_mirred.c index 11f4c9b..01f916d 100644 --- a/tc/m_mirred.c +++ b/tc/m_mirred.c @@ -62,13 +62,13 @@ static const char *mirred_n2a(int action) } static int -parse_egress(struct action_util *a, int *argc_p, char ***argv_p, - int tca_id, struct nlmsghdr *n) +parse_direction(struct action_util *a, int *argc_p, char ***argv_p, + int tca_id, struct nlmsghdr *n) { int argc = *argc_p; char **argv = *argv_p; - int ok = 0, iok = 0, mirror = 0, redir = 0; + int ok = 0, iok = 0, mirror = 0, redir = 0, ingress = 0, egress = 0; struct tc_mirred p = {}; struct rtattr *tail; char d[16] = {}; @@ -77,7 +77,21 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, if (matches(*argv, "action") == 0) { break; - } else if (matches(*argv, "egress") == 0) { + } else if (!egress && matches(*argv, "egress") == 0) { + egress = 1; + if (ingress) { + fprintf(stderr, "Can't have both egress and ingress\n"); + return -1; + } + NEXT_ARG(); + ok++; + continue; + } else if (!ingress && matches(*argv, "ingress") == 0) { + ingress = 1; + if (egress) { + fprintf(stderr, "Can't have both ingress and egress\n"); + return -1; + } NEXT_ARG(); ok++; continue; @@ -96,7 +110,7 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, break; } } else if (!ok) { - fprintf(stderr, "was expecting egress (%s)\n", *argv); + fprintf(stderr, "was expecting egress or ingress (%s)\n", *argv); break; } else if (!mirror && matches(*argv, "mirror") == 0) { @@ -105,7 +119,8 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, fprintf(stderr, "Can't have both mirror and redir\n"); return -1; } - p.eaction = TCA_EGRESS_MIRROR; + p.eaction = egress ? TCA_EGRESS_MIRROR : + TCA_INGRESS_MIRROR; p.action = TC_ACT_PIPE; ok++; } else if (!redir && matches(*argv, "redirect") == 0) { @@ -114,7 +129,8 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, fprintf(stderr, "Can't have both mirror and redir\n"); return -1; } - p.eaction = TCA_EGRESS_REDIR; + p.eaction = egress ? TCA_EGRESS_REDIR : + TCA_INGRESS_REDIR; p.action = TC_ACT_STOLEN; ok++; } else if ((redir || mirror) && matches(*argv, "dev") == 0) { @@ -154,7 +170,8 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, } - if (argc && p.eaction == TCA_EGRESS_MIRROR + if (argc && + (p.eaction == TCA_EGRESS_MIRROR || p.eaction == TCA_INGRESS_MIRROR) && !action_a2n(*argv, &p.action, false)) NEXT_ARG(); @@ -207,8 +224,9 @@ parse_mirred(struct action_util *a, int *argc_p, char ***argv_p, } - if (matches(*argv, "egress") == 0 || matches(*argv, "index") == 0) { - int ret = parse_egress(a, &argc, &argv, tca_id, n); + if (matches(*argv, "egress") == 0 || matches(*argv, "ingress") == 0 || + matches(*argv, "index") == 0) { + int ret = parse_direction(a, &argc, &argv, tca_id, n); if (ret == 0) { *argc_p = argc; @@ -216,8 +234,6 @@ parse_mirred(struct action_util *a, int *argc_p, char ***argv_p, return 0; } - } else if (matches(*argv, "ingress") == 0) { - fprintf(stderr, "mirred ingress not supported at the moment\n"); } else if (matches(*argv, "help") == 0) { usage(); } else {