From patchwork Sun Feb 8 06:58:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadym Kochan X-Patchwork-Id: 437669 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 B529D1400DD for ; Sun, 8 Feb 2015 18:10:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752267AbbBHHJo (ORCPT ); Sun, 8 Feb 2015 02:09:44 -0500 Received: from mail-lb0-f177.google.com ([209.85.217.177]:65194 "EHLO mail-lb0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751744AbbBHHJn (ORCPT ); Sun, 8 Feb 2015 02:09:43 -0500 Received: by mail-lb0-f177.google.com with SMTP id p9so24596413lbv.8 for ; Sat, 07 Feb 2015 23:09:41 -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; bh=TqPyqPoIwKuQCB4rLZZ8yDoOnsfiaPLMle/1jiHApqg=; b=wz0Mb1Fbo0snkojVgfNZXYEvBLUkKJejry9Cr7EmRM8BgA6TbauoU8f8z35LrwhTsy zlMFRpSbFhUsdadyvevGXs4eevOVSxvnHUQuTYHBpyBAdBIRYPsua3K9Eq1A1i+g6hWM N6hRzBIqEthuFUOxmcooZvvTnNN1JLG4JxNq3aDsBJFwcvvCmbrcUGmCkOGGW7BlI5Ff 6PMZN3e+NGH7lxWpt+aJrpWbyyWWXEWbQH92iXSJxBx0p1E6F3NbXcjo2SKlD5HqkiEs 30OXfsqNJ3EICmJWQ1KiqmLeiiKS2GP3b480yVnB0Y3mwmvEISQNk3SP7B6svOPacYvk LA0A== X-Received: by 10.152.28.227 with SMTP id e3mr10388391lah.117.1423379381130; Sat, 07 Feb 2015 23:09:41 -0800 (PST) Received: from localhost.localdomain (121-43-207-82.ip.ukrtel.net. [82.207.43.121]) by mx.google.com with ESMTPSA id r3sm1296066lar.35.2015.02.07.23.09.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Feb 2015 23:09:40 -0800 (PST) From: Vadim Kochan To: netdev@vger.kernel.org Cc: Vadim Kochan Subject: [PATCH iproute2] ss: Show stats from specified network namespace Date: Sun, 8 Feb 2015 08:58:43 +0200 Message-Id: <1423378723-29449-1-git-send-email-vadim4j@gmail.com> X-Mailer: git-send-email 2.2.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vadim Kochan Added new '-N NSNAME, --net=NSNAME' option to show socket stats from the specified network namespace name. Signed-off-by: Vadim Kochan --- man/man8/ss.8 | 3 +++ misc/Makefile | 4 ++++ misc/ss.c | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/man/man8/ss.8 b/man/man8/ss.8 index 450649a..b7fbaef 100644 --- a/man/man8/ss.8 +++ b/man/man8/ss.8 @@ -84,6 +84,9 @@ context of the creating process, however the context shown will reflect any policy role, type and/or range transition rules applied, and is therefore a useful reference. .TP +.B \-N NSNAME, \-\-net=NSNAME +Switch to the specified network namespace name. +.TP .B \-b, \-\-bpf Show socket BPF filters (only administrators are allowed to get these information). .TP diff --git a/misc/Makefile b/misc/Makefile index 004bcc3..b7ecba9 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -10,6 +10,10 @@ ifeq ($(HAVE_SELINUX),y) CFLAGS += $(shell pkg-config --cflags libselinux) -DHAVE_SELINUX endif +ifeq ($(IP_CONFIG_SETNS),y) + CFLAGS += -DHAVE_SETNS +endif + all: $(TARGETS) ss: $(SSOBJ) diff --git a/misc/ss.c b/misc/ss.c index 7fc0a99..0a6a65e 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -31,6 +31,7 @@ #include "rt_names.h" #include "ll_map.h" #include "libnetlink.h" +#include "namespace.h" #include "SNAPSHOT.h" #include @@ -3246,6 +3247,7 @@ static void _usage(FILE *dest) " -b, --bpf show bpf filter socket information\n" " -Z, --context display process SELinux security contexts\n" " -z, --contexts display process and socket SELinux security contexts\n" +" -N, --net switch to the specified network namespace name\n" "\n" " -4, --ipv4 display only IP version 4 sockets\n" " -6, --ipv6 display only IP version 6 sockets\n" @@ -3345,6 +3347,7 @@ static const struct option long_opts[] = { { "help", 0, 0, 'h' }, { "context", 0, 0, 'Z' }, { "contexts", 0, 0, 'z' }, + { "net", 1, 0, 'N' }, { 0 } }; @@ -3360,7 +3363,7 @@ int main(int argc, char *argv[]) struct filter dbs_filter = {}; int state_filter = 0; - while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spbf:miA:D:F:vVzZ", + while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spbf:miA:D:F:vVzZN:", long_opts, NULL)) != EOF) { switch(ch) { case 'n': @@ -3532,6 +3535,10 @@ int main(int argc, char *argv[]) show_proc_ctx++; user_ent_hash_build(); break; + case 'N': + if (netns_switch(optarg)) + exit(1); + break; case 'h': case '?': help();