Skip to contentSkip to conversation

iptables-save counters on builtin chains not restored?

DISCUSSION Herve Eychenne 3 participants 6 messages Aug 17, 2004 – Aug 22, 2004 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

Seems like I'm studying iptables-save too much tonight...

When fed with the result of iptables-save -c, iptables-restore -c does not seem to restore counters on chains (I'm not talking about rules), as I simply cannot find any parsing code for that.

Note that it would make sense only on builtin chains, but not user-chains, because only builtin chains have a policy, and the counters are about packets that hit the policy.

Anyway, it doesn't seem to be restored at all, and I suspect an omission, so... a bug. Can someone confirm?

Herve

Signature · 4 lines
 _
(°=  Hervé Eychenne
//)
v_/_ WallFire project:  http://www.wallfire.org/
#1 lore raw
Quoted 10 lines · Herve Eychenne

When fed with the result of iptables-save -c, iptables-restore -c does not seem to restore counters on chains (I'm not talking about rules), as I simply cannot find any parsing code for that.

Note that it would make sense only on builtin chains, but not user-chains, because only builtin chains have a policy, and the counters are about packets that hit the policy.

Anyway, it doesn't seem to be restored at all, and I suspect an omission, so... a bug. Can someone confirm?

Yes, now that you say it, I don't remember having written that code ;)

Please put it in bugzilla... and patches are obviously always welcome.

Quoted 1 line

Herve

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#2 lore raw
Quoted 6 lines · Harald Welte
Quoted 4 lines · Herve Eychenne

When fed with the result of iptables-save -c, iptables-restore -c does not seem to restore counters on chains (I'm not talking about rules), as I simply cannot find any parsing code for that.

Quoted 8 lines
Quoted 6 lines

Note that it would make sense only on builtin chains, but not user-chains, because only builtin chains have a policy, and the counters are about packets that hit the policy.

Anyway, it doesn't seem to be restored at all, and I suspect an omission, so... a bug. Can someone confirm?

Yes, now that you say it, I don't remember having written that code ;)

Did you ask your pet as well? ;-)

Quoted 1 line

Please put it in bugzilla... and patches are obviously always welcome.

I'm currently writing it, at least partly:
- for now iptables-save (with or without -c) used to dump counters for builtin-chains, which is wrong (useless when not called with -c). I'll fix that.
- iptables-save (also with or without -c) used to dump dummy counters (always [0:0]) for user-chains, which is also wrong (never needed, as it makes no sense for user-chains, right?). I'll fix that too.

The side effect of this change will be that dump files created by new iptables-save command (without -c) won't be restorable with old iptables-restore (without -c). But i think it's acceptable, as:
- people should not want to do that, as they should use iptables-restore.new, then
- if people really have to use iptables-restore.old, they can use iptables-save.new dumps, but with -c
- a very simple sed line fixes that

One thing that puzzles me is that old iptables-restore -c used to restore old iptables-save (without -c) dumps without any complaints about missing counters (for rules, as counters for builtin-chains were dumped anyway).
So I guess new iptables-restore -c should act likewise, that is restore new iptables-save dumps (without -c) without error, but shouldn't it at least issue a warning about the lack of the expected counters?

Thanks for commenting everything above.

Herve

Signature · 4 lines
 _
(°=  Hervé Eychenne
//)
v_/_ WallFire project:  http://www.wallfire.org/
#3 lore raw
Quoted 12 lines · Herve Eychenne
Quoted 1 line · Harald Welte

Please put it in bugzilla... and patches are obviously always welcome.

I'm currently writing it, at least partly:
- for now iptables-save (with or without -c) used to dump counters for builtin-chains, which is wrong (useless when not called with -c). I'll fix that.
- iptables-save (also with or without -c) used to dump dummy counters (always [0:0]) for user-chains, which is also wrong (never needed, as it makes no sense for user-chains, right?). I'll fix that too.

Quoted 3 lines

The side effect of this change will be that dump files created by new iptables-save command (without -c) won't be restorable with old iptables-restore (without -c).

Sorry... you should have read:
dump files created by new iptables-save command (without -c) won't be restorable with old iptables-restore -c
So,

# iptables-save.new | iptables-restore.old
works well. That's even less harmful.
Quoted 15 lines

But i think it's acceptable, as:
- people should not want to do that, as they should use iptables-restore.new, then
- if people really have to use iptables-restore.old, they can use iptables-save.new dumps, but with -c
- a very simple sed line fixes that

One thing that puzzles me is that old iptables-restore -c used to restore old iptables-save (without -c) dumps without any complaints about missing counters (for rules, as counters for builtin-chains were dumped anyway).
So I guess new iptables-restore -c should act likewise, that is restore new iptables-save dumps (without -c) without error, but shouldn't it at least issue a warning about the lack of the expected counters?

Quoted 1 line

Thanks for commenting everything above.

Herve

Signature · 4 lines
 _
(°=  Hervé Eychenne
//)
v_/_ WallFire project:  http://www.wallfire.org/
#4 lore raw
In reply to Herve Eychenne
Quoted 3 lines · Herve Eychenne

The side effect of this change will be that dump files created by new iptables-save command (without -c) won't be restorable with old iptables-restore (without -c).

Are you sure? From what I can see this should work. I never specify counters in my iptables-restore input from what I can tell.. not on policies, not in rules. And it works just fine.

iptables-restore -c without having counters specified in policies or custom chains complains, but I never use this so I don't care, and what would the point be?

What would break is reading in output from new iptables-save (with or without -c) using old iptables-restore -c.

Quoted 4 lines

One thing that puzzles me is that old iptables-restore -c used to restore old iptables-save (without -c) dumps without any complaints about missing counters (for rules, as counters for builtin-chains were dumped anyway).

This is due to the parser nor caring if -c is specified or not when parsing the rules. It always parse the counters if there is any (in_table block), it then discards the result if -c is not specified.

Quoted 3 lines

So I guess new iptables-restore -c should act likewise, that is restore new iptables-save dumps (without -c) without error, but shouldn't it at least issue a warning about the lack of the expected counters?

Why? Is there a problem with reading a missing counter as an implicit zero?

Regards
Henrik

#5 lore raw
Quoted 9 lines · Henrik Nordstrom
Quoted 3 lines · Herve Eychenne

The side effect of this change will be that dump files created by new iptables-save command (without -c) won't be restorable with old iptables-restore (without -c).

Are you sure? From what I can see this should work. I never specify counters in my iptables-restore input from what I can tell.. not on policies, not in rules. And it works just fine.

Probably you missed my rectification (sorry again) :
dump files created by new iptables-save command (without -c) won't be restorable with old iptables-restore -c

                                    ^^^^

So there is no problem for the case you describe, right.

Quoted 2 lines

iptables-restore -c without having counters specified in policies or custom chains complains,

According to me, it does not only complain, it crashes, because we did not check the return of strtok and tried to parse counters whether they are actually present or not. I fixed it already in my tree (patch will be sent soon).

Quoted 4 lines

but I never use this so I don't care, and what would the point be?

What would break is reading in output from new iptables-save (with or without -c) using old iptables-restore -c.

Yes.

Quoted 8 lines
Quoted 4 lines

One thing that puzzles me is that old iptables-restore -c used to restore old iptables-save (without -c) dumps without any complaints about missing counters (for rules, as counters for builtin-chains were dumped anyway).

This is due to the parser nor caring if -c is specified or not when parsing the rules. It always parse the counters if there is any (in_table block), it then discards the result if -c is not specified.

I'm talking about chain counters (not rules), and IIRC these counters were only parsed if -c was specified (memset of the struct to 0 otherwise). Like I said, the issue was more that counters were tried to be parsed even if they were lacking (->coredump).
But there is not much point in discussing this very longer... :-)

Quoted 6 lines
Quoted 3 lines

So I guess new iptables-restore -c should act likewise, that is restore new iptables-save dumps (without -c) without error, but shouldn't it at least issue a warning about the lack of the expected counters?

Why? Is there a problem with reading a missing counter as an implicit zero?

It depends on your personnal policies. When I specify something like -c, it is hardly by chance, and I tend to consider that trying (on purpose) to restore something that actually does not exist is at least strange. So I would personally go for a warning message (median solution), but that's only a matter of how rigorous you expect the tools to be.

Herve

Signature · 4 lines
 _
(°=  Hervé Eychenne
//)
v_/_ WallFire project:  http://www.wallfire.org/