]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
Allow 'ip addr flush' to loop more than 10 times
authorBen Greear <greearb@candelatech.com>
Wed, 1 Dec 2010 19:13:51 +0000 (11:13 -0800)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Wed, 1 Dec 2010 19:13:51 +0000 (11:13 -0800)
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 <greearb@candelatech.com>
include/utils.h
ip/ip.c
ip/ipaddress.c
man/man8/ip.8

index f7ef939b37841383944644001eafb7d9a85dceb9..3da699858eac66330ef43937f10bee464513d8ef 100644 (file)
@@ -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 9f295334da211c1716082efe861313867d9c2cfb..b127d5708045e29de21ac18a846b2a5b21be6694 100644 (file)
--- 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)
index fc306e65df6b8ee15d1fbdbd219b64e4eb528dfe..a775ecd38c4443517fe95d555b929d788e91cb1a 100644 (file)
@@ -33,7 +33,6 @@
 #include "ll_map.h"
 #include "ip_common.h"
 
-#define MAX_ROUNDS 10
 
 static struct
 {
@@ -819,7 +818,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,
@@ -877,7 +876,8 @@ flush_done:
                        if (!(filter.flags & IFA_F_SECONDARY) && (filter.flagmask & IFA_F_SECONDARY))
                                goto flush_done;
                }
-               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;
        }
 
index c1e03f3fc1a16d5890329e07361a88daa9db9ba0..d8044724a14973c41df572dd0c5a0b31c1184547 100644 (file)
@@ -735,6 +735,12 @@ output more information.  If the option
 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: