All of lore.kernel.org
 help / color / mirror / Atom feed
* Line numbering broken since bb34082d
@ 2008-06-13  9:14 Jan Engelhardt
  2008-06-13 10:59 ` [Patch] " Henrik Nordstrom
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Engelhardt @ 2008-06-13  9:14 UTC (permalink / raw)
  To: henrik; +Cc: Netfilter Developer Mailing List, kaber

Hi,


`iptables -nvL --lin`, starting with bb34082de, gives a wrong count:

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               
destination         
2        0     0 LOG        all  --  *      *       0.0.0.0/0            
0.0.0.0/0           LOG flags 0 level 4 


Yes, it starts with '2'. The offending part is 
because now you increased num before calling print_firewal.

-                       print_firewall(i,
-                                      ip6tc_get_target(i, handle),
-                                      num++,
-                                      format,
-                                      *handle);
+                       num++;
+                       if (!rulenum || num == rulenum)
+                               print_firewall(i,
+                                              ip6tc_get_target(i, handle),
+                                              num,
+                                              format,
+                                              *handle);

Moving down incrementing num solves the problem for me, but does it 
still do the right thing for num==rulenum? BTW, in the first iteration,
num==rulenum  is 1==0!

=====
commit 372dc8c92e1deae8d5942e889090347f415813d0
Author: Jan Engelhardt <jengelh@medozas.de>
Date:   Fri Jun 13 11:14:45 2008 +0200

    iptables: fix printing of line numbers with --line-numbers arg
    
    Commit bb34082d ("iptables --list chain rulenum") broke the line
    numbering, starting with printing an offset of 2.
    
    Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
 ip6tables.c |    2 +-
 iptables.c  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/ip6tables.c b/ip6tables.c
index 8e135f1..54b8c4d 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -1092,7 +1092,6 @@ list_entries(const ip6t_chainlabel chain, int rulenum, int verbose, int numeric,
 
 		num = 0;
 		while (i) {
-			num++;
 			if (!rulenum || num == rulenum)
 				print_firewall(i,
 					       ip6tc_get_target(i, handle),
@@ -1100,6 +1099,7 @@ list_entries(const ip6t_chainlabel chain, int rulenum, int verbose, int numeric,
 					       format,
 					       *handle);
 			i = ip6tc_next_rule(i, handle);
+			++num;
 		}
 		found = 1;
 	}
diff --git a/iptables.c b/iptables.c
index cff8cf4..6b113ad 100644
--- a/iptables.c
+++ b/iptables.c
@@ -1095,7 +1095,6 @@ list_entries(const ipt_chainlabel chain, int rulenum, int verbose, int numeric,
 
 		num = 0;
 		while (i) {
-			num++;
 			if (!rulenum || num == rulenum)
 				print_firewall(i,
 					       iptc_get_target(i, handle),
@@ -1103,6 +1102,7 @@ list_entries(const ipt_chainlabel chain, int rulenum, int verbose, int numeric,
 					       format,
 					       *handle);
 			i = iptc_next_rule(i, handle);
+			++num;
 		}
 		found = 1;
 	}

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Patch] Re: Line numbering broken since bb34082d
  2008-06-13  9:14 Line numbering broken since bb34082d Jan Engelhardt
@ 2008-06-13 10:59 ` Henrik Nordstrom
  2008-06-13 12:19   ` Jan Engelhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Henrik Nordstrom @ 2008-06-13 10:59 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Netfilter Developer Mailing List, kaber


[-- Attachment #1.1: Type: text/plain, Size: 560 bytes --]

On fre, 2008-06-13 at 11:14 +0200, Jan Engelhardt wrote:

> `iptables -nvL --lin`, starting with bb34082de, gives a wrong count:
> 
> Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
> num   pkts bytes target     prot opt in     out     source               
> destination         
> 2        0     0 LOG        all  --  *      *       0.0.0.0/0            
> 0.0.0.0/0           LOG flags 0 level 4 

Sorry about that. Never tested --line-numbers.

I think the best fix is to drop the +1 from print_firewall(). Patch attached.

Regards
Henrik

[-- Attachment #1.2: linenumbers.patch --]
[-- Type: text/x-patch, Size: 787 bytes --]

Index: iptables.c
===================================================================
--- iptables.c	(revision 7543)
+++ iptables.c	(working copy)
@@ -737,7 +737,7 @@
 	flags = fw->ip.flags;
 
 	if (format & FMT_LINENUMBERS)
-		printf(FMT("%-4u ", "%u "), num+1);
+		printf(FMT("%-4u ", "%u "), num);
 
 	if (!(format & FMT_NOCOUNTS)) {
 		print_num(fw->counters.pcnt, format);
Index: ip6tables.c
===================================================================
--- ip6tables.c	(revision 7543)
+++ ip6tables.c	(working copy)
@@ -737,7 +737,7 @@
 	flags = fw->ipv6.flags;
 
 	if (format & FMT_LINENUMBERS)
-		printf(FMT("%-4u ", "%u "), num+1);
+		printf(FMT("%-4u ", "%u "), num);
 
 	if (!(format & FMT_NOCOUNTS)) {
 		print_num(fw->counters.pcnt, format);

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 307 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch] Re: Line numbering broken since bb34082d
  2008-06-13 10:59 ` [Patch] " Henrik Nordstrom
@ 2008-06-13 12:19   ` Jan Engelhardt
  2008-06-13 15:58     ` Patrick McHardy
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Engelhardt @ 2008-06-13 12:19 UTC (permalink / raw)
  To: Henrik Nordstrom; +Cc: Netfilter Developer Mailing List, kaber


On Friday 2008-06-13 12:59, Henrik Nordstrom wrote:
>On fre, 2008-06-13 at 11:14 +0200, Jan Engelhardt wrote:
>
>> `iptables -nvL --lin`, starting with bb34082de, gives a wrong count:
>> 
>> Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
>> num   pkts bytes target     prot opt in     out     source               
>> destination         
>> 2        0     0 LOG        all  --  *      *       0.0.0.0/0            
>> 0.0.0.0/0           LOG flags 0 level 4 
>
>Sorry about that. Never tested --line-numbers.
>
>I think the best fix is to drop the +1 from print_firewall(). Patch attached.

Indeed, that is the right thing to do, since with my patch,
iptables -nvL INPUT 1  would still show the 2nd rule.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch] Re: Line numbering broken since bb34082d
  2008-06-13 12:19   ` Jan Engelhardt
@ 2008-06-13 15:58     ` Patrick McHardy
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick McHardy @ 2008-06-13 15:58 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Henrik Nordstrom, Netfilter Developer Mailing List

Jan Engelhardt wrote:
> On Friday 2008-06-13 12:59, Henrik Nordstrom wrote:
>> On fre, 2008-06-13 at 11:14 +0200, Jan Engelhardt wrote:
>>
>>> `iptables -nvL --lin`, starting with bb34082de, gives a wrong count:
>>>
>>> Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
>>> num   pkts bytes target     prot opt in     out     source               
>>> destination         
>>> 2        0     0 LOG        all  --  *      *       0.0.0.0/0            
>>> 0.0.0.0/0           LOG flags 0 level 4 
>> Sorry about that. Never tested --line-numbers.
>>
>> I think the best fix is to drop the +1 from print_firewall(). Patch attached.
> 
> Indeed, that is the right thing to do, since with my patch,
> iptables -nvL INPUT 1  would still show the 2nd rule.


Thanks, I applied Henrik's patch with your description.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-13 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-13  9:14 Line numbering broken since bb34082d Jan Engelhardt
2008-06-13 10:59 ` [Patch] " Henrik Nordstrom
2008-06-13 12:19   ` Jan Engelhardt
2008-06-13 15:58     ` Patrick McHardy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.