From patchwork Tue Jun 29 05:55:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: greearb@gmail.com X-Patchwork-Id: 57242 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 56E4DB6EEC for ; Tue, 29 Jun 2010 15:56:14 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751810Ab0F2F4J (ORCPT ); Tue, 29 Jun 2010 01:56:09 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:38714 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390Ab0F2F4H (ORCPT ); Tue, 29 Jun 2010 01:56:07 -0400 Received: by pvg2 with SMTP id 2so2292455pvg.19 for ; Mon, 28 Jun 2010 22:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=ndhNcKnbymi9fJpZxrLPYMYKujuipm4KLGudjqMikE4=; b=P4f79K26so0iiLPyM1+K1qWRqnHosBlw9R1zQo0Q1apFX7DTS7QiSYCX6ZTlNrEgSB kMTFO4R2BSfOiaVANHpSaQ0eG0jk0Fz45oVpXOaKd7cre32JX85RD4v8tSHyvAE/AxyI ayX6+oFW3VsEgZMInhHs04MAemln/Ba/FPcas= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=gUjPHOx1Lhwn8zxdMbiMsyRH+4YYGTSYMwX2k380kkb7e4c2G45+Nz0YwBrkx1shg/ f52d9G1WF6BkIt3a97fseZgyc+bx0VsN1r6DmiKZL4Cfp+Ie5bmTJfGqMRpm/2Nxro+V clQNDWZ5wdEOKuHIIUHyfR2StyPXNteZDyEzE= Received: by 10.142.177.6 with SMTP id z6mr228325wfe.68.1277790965843; Mon, 28 Jun 2010 22:56:05 -0700 (PDT) Received: from localhost.localdomain (pool-71-117-12-23.sttlwa.dsl-w.verizon.net [71.117.12.23]) by mx.google.com with ESMTPS id r23sm4095878rvq.14.2010.06.28.22.56.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 28 Jun 2010 22:56:04 -0700 (PDT) From: greearb@gmail.com To: netdev@vger.kernel.org Cc: Ben Greear Subject: [iproute2] iproute2: Allow 'ip addr flush' to loop more than 10 times. Date: Mon, 28 Jun 2010 22:55:59 -0700 Message-Id: <1277790959-28075-1-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 1.7.0.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ben Greear The default remains at 10 for backwards compatibility. For instance: # ip addr flush dev eth2 *** Flush remains incomplete after 10 rounds. *** # ip -l 20 addr flush dev eth2 *** Flush remains incomplete after 20 rounds. *** # ip -loops 0 addr flush dev eth2 # This is useful for getting rid of large numbers of IP addresses in scripts. Signed-off-by: Ben Greear --- :100644 100644 f7ef939... 3da6998... M include/utils.h :100644 100644 9f29533... b127d57... M ip/ip.c :100644 100644 3a411b1... 5f0789c... M ip/ipaddress.c :100644 100644 1a73efa... d0146a5... M man/man8/ip.8 include/utils.h | 1 + ip/ip.c | 11 ++++++++++- ip/ipaddress.c | 6 +++--- man/man8/ip.8 | 6 ++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/utils.h b/include/utils.h index f7ef939..3da6998 100644 --- a/include/utils.h +++ b/include/utils.h @@ -17,6 +17,7 @@ extern int resolve_hosts; extern int oneline; extern int timestamp; extern char * _SL_; +extern int max_flush_loops; #ifndef IPPROTO_ESP #define IPPROTO_ESP 50 diff --git a/ip/ip.c b/ip/ip.c index 9f29533..b127d57 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -32,6 +32,8 @@ int timestamp = 0; char * _SL_ = NULL; char *batch_file = NULL; int force = 0; +int max_flush_loops = 10; + struct rtnl_handle rth = { .fd = -1 }; static void usage(void) __attribute__((noreturn)); @@ -45,6 +47,7 @@ static void usage(void) " tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " -f[amily] { inet | inet6 | ipx | dnet | link } |\n" +" -l[oops] { maximum-addr-flush-attempts } |\n" " -o[neline] | -t[imestamp] | -b[atch] [filename] |\n" " -rc[vbuf] [size]}\n"); exit(-1); @@ -157,7 +160,13 @@ int main(int argc, char **argv) break; if (opt[1] == '-') opt++; - if (matches(opt, "-family") == 0) { + if (matches(opt, "-loops") == 0) { + argc--; + argv++; + if (argc <= 1) + usage(); + max_flush_loops = atoi(argv[1]); + } else if (matches(opt, "-family") == 0) { argc--; argv++; if (argc <= 1) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 3a411b1..5f0789c 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -33,7 +33,6 @@ #include "ll_map.h" #include "ip_common.h" -#define MAX_ROUNDS 10 static struct { @@ -818,7 +817,7 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush) filter.flushp = 0; filter.flushe = sizeof(flushb); - while (round < MAX_ROUNDS) { + while ((max_flush_loops == 0) || (round < max_flush_loops)) { const struct rtnl_dump_filter_arg a[3] = { { .filter = print_addrinfo_secondary, @@ -867,7 +866,8 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush) fflush(stdout); } } - fprintf(stderr, "*** Flush remains incomplete after %d rounds. ***\n", MAX_ROUNDS); fflush(stderr); + fprintf(stderr, "*** Flush remains incomplete after %d rounds. ***\n", max_flush_loops); + fflush(stderr); return 1; } diff --git a/man/man8/ip.8 b/man/man8/ip.8 index 1a73efa..d0146a5 100644 --- a/man/man8/ip.8 +++ b/man/man8/ip.8 @@ -730,6 +730,12 @@ appears twice or more, the amount of information increases. As a rule, the information is statistics or some time values. .TP +.BR "\-l" , " \-loops" +Specify maximum number of loops the 'ip addr flush' logic +will attempt before giving up. The default is 10. +Zero (0) means loop until all addresses are removed. + +.TP .BR "\-f" , " \-family" followed by protocol family identifier: .BR "inet" , " inet6"