From patchwork Sat Dec 13 17:55:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadym Kochan X-Patchwork-Id: 420778 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 77F731400E9 for ; Sun, 14 Dec 2014 05:05:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753508AbaLMSFj (ORCPT ); Sat, 13 Dec 2014 13:05:39 -0500 Received: from mail-lb0-f180.google.com ([209.85.217.180]:33324 "EHLO mail-lb0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751220AbaLMSFh (ORCPT ); Sat, 13 Dec 2014 13:05:37 -0500 Received: by mail-lb0-f180.google.com with SMTP id l4so7268811lbv.39 for ; Sat, 13 Dec 2014 10:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J6uj/a159CRJVwaWYDJpXXZiTgIe1lbU9dK1ykURIzM=; b=Wu7LiJaoW9BK6H4Mgp9nWal+ZgZs78RXciOrDXA7EKfeAsbc2CMwaresadl/9vSLhC w9vCNnHTlz96Uk/HoG9SbtDXA+gPQxO34CF8Ul2VBWWp3sHLjah21zqhQxSuZIuwwgs1 tKgETj1upF8s9YBT1IYcMddhfRleM1ojFSSXB6Y0WS2HsAhW2K35qVK1yOYoAziYIye4 OIT5tZ51Xxqe3z22WoA/6VcN6tr/Y1gavEQjvUwK1bca7WskB8dKUMe+KVMVRhWIfhMJ S2ZFt2ELB9UMNqTMQisHcu1+MiXg6yFgQi3mV20lbm+zs4ymE/x3IwcDWEX1vXt0r6yy 6wsA== X-Received: by 10.112.211.130 with SMTP id nc2mr2980125lbc.0.1418493935640; Sat, 13 Dec 2014 10:05:35 -0800 (PST) Received: from localhost.localdomain (121-43-207-82.ip.ukrtel.net. [82.207.43.121]) by mx.google.com with ESMTPSA id i2sm1314449lae.40.2014.12.13.10.05.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 13 Dec 2014 10:05:35 -0800 (PST) From: Vadim Kochan To: netdev@vger.kernel.org Cc: Vadim Kochan Subject: [PATCH iproute2 4/4] tc: Allow to easy change network namespace Date: Sat, 13 Dec 2014 19:55:34 +0200 Message-Id: <1418493334-23142-5-git-send-email-vadim4j@gmail.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418493334-23142-1-git-send-email-vadim4j@gmail.com> References: <1418493334-23142-1-git-send-email-vadim4j@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vadim Kochan Added new '-netns' option to simplify executing following cmd: ip netns exec NETNS tc OPTIONS COMMAND OBJECT to tc -n[etns] NETNS OPTIONS COMMAND OBJECT e.g.: tc -net vnet0 qdisc Signed-off-by: Vadim Kochan Signed-off-by: Jiri Pirko --- man/man8/tc.8 | 65 +++++++++++++++++++++++++++++++++++++++++++++-------------- tc/Makefile | 5 +++++ tc/tc.c | 8 +++++++- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/man/man8/tc.8 b/man/man8/tc.8 index 8d794de..d8f974f 100644 --- a/man/man8/tc.8 +++ b/man/man8/tc.8 @@ -2,7 +2,9 @@ .SH NAME tc \- show / manipulate traffic control settings .SH SYNOPSIS -.B tc qdisc [ add | change | replace | link | delete ] dev +.B tc +.RI "[ " OPTIONS " ]" +.B qdisc [ add | change | replace | link | delete ] dev DEV .B [ parent @@ -13,7 +15,9 @@ qdisc-id ] qdisc [ qdisc specific parameters ] .P -.B tc class [ add | change | replace | delete ] dev +.B tc +.RI "[ " OPTIONS " ]" +.B class [ add | change | replace | delete ] dev DEV .B parent qdisc-id @@ -22,7 +26,9 @@ class-id ] qdisc [ qdisc specific parameters ] .P -.B tc filter [ add | change | replace | delete ] dev +.B tc +.RI "[ " OPTIONS " ]" +.B filter [ add | change | replace | delete ] dev DEV .B [ parent qdisc-id @@ -35,21 +41,28 @@ priority filtertype flow-id .B tc +.RI "[ " OPTIONS " ]" .RI "[ " FORMAT " ]" .B qdisc show [ dev DEV .B ] .P .B tc +.RI "[ " OPTIONS " ]" .RI "[ " FORMAT " ]" .B class show dev DEV .P -.B tc filter show dev +.B tc +.RI "[ " OPTIONS " ]" +.B filter show dev DEV .P -.B tc [ -force ] -b\fR[\fIatch\fR] \fB[ filename ] +.ti 8 +.IR OPTIONS " := {" +\fB[ -force ] -b\fR[\fIatch\fR] \fB[ filename ] \fR| +\fB[ \fB-n\fR[\fIetns\fR] name \fB] \fR} .ti 8 .IR FORMAT " := {" @@ -407,6 +420,38 @@ link Only available for qdiscs and performs a replace where the node must exist already. +.SH OPTIONS + +.TP +.BR "\-b", " \-b filename", " \-batch", " \-batch filename" +read commands from provided file or standard input and invoke them. +First failure will cause termination of tc. + +.TP +.BR "\-force" +don't terminate tc on errors in batch mode. +If there were any errors during execution of the commands, the application return code will be non zero. + +.TP +.BR "\-n" , " \-net" , " \-netns " +switches +.B tc +to the specified network namespace +.IR NETNS . +Actually it just simplifies executing of: + +.B ip netns exec +.IR NETNS +.B tc +.RI "[ " OPTIONS " ] " OBJECT " { " COMMAND " | " +.BR help " }" + +to + +.B tc +.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | " +.BR help " }" + .SH FORMAT The show command has additional formatting options: @@ -430,16 +475,6 @@ decode filter offset and mask values to equivalent filter commands based on TCP/ .BR "\-iec" print rates in IEC units (ie. 1K = 1024). -.TP -.BR "\-b", " \-b filename", " \-batch", " \-batch filename" -read commands from provided file or standard input and invoke them. -First failure will cause termination of tc. - -.TP -.BR "\-force" -don't terminate tc on errors in batch mode. -If there were any errors during execution of the commands, the application return code will be non zero. - .SH HISTORY .B tc was written by Alexey N. Kuznetsov and added in Linux 2.2. diff --git a/tc/Makefile b/tc/Makefile index 1ab36c6..536ed88 100644 --- a/tc/Makefile +++ b/tc/Makefile @@ -3,6 +3,11 @@ TCOBJ= tc.o tc_qdisc.o tc_class.o tc_filter.o tc_util.o \ m_ematch.o emp_ematch.yacc.o emp_ematch.lex.o include ../Config + +ifeq ($(IP_CONFIG_SETNS),y) + CFLAGS += -DHAVE_SETNS +endif + SHARED_LIBS ?= y TCMODULES := diff --git a/tc/tc.c b/tc/tc.c index 9b50e74..ea4ba10 100644 --- a/tc/tc.c +++ b/tc/tc.c @@ -29,6 +29,7 @@ #include "utils.h" #include "tc_util.h" #include "tc_common.h" +#include "namespace.h" int show_stats = 0; int show_details = 0; @@ -185,7 +186,8 @@ static void usage(void) fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n" " tc [-force] -batch filename\n" "where OBJECT := { qdisc | class | filter | action | monitor }\n" - " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] }\n"); + " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | " + "-n[etns] name }\n"); } static int do_cmd(int argc, char **argv) @@ -293,6 +295,10 @@ int main(int argc, char **argv) if (argc <= 1) usage(); batch_file = argv[1]; + } else if (matches(argv[1], "-netns") == 0) { + NEXT_ARG(); + if (netns_switch(argv[1])) + return -1; } else { fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]); return -1;