* [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order
@ 2010-09-02 14:15 Changli Gao
2010-09-15 17:32 ` Patrick McHardy
0 siblings, 1 reply; 5+ messages in thread
From: Changli Gao @ 2010-09-02 14:15 UTC (permalink / raw)
To: Patrick McHardy; +Cc: David S. Miller, netfilter-devel, netdev, Changli Gao
Since we register nf hooks, matches and targets in order, we'd better
unregister them in the reverse order.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
net/netfilter/core.c | 6 ++----
net/netfilter/x_tables.c | 12 ++++--------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 78b505d..8f014f2 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -105,10 +105,8 @@ EXPORT_SYMBOL(nf_register_hooks);
void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)
{
- unsigned int i;
-
- for (i = 0; i < n; i++)
- nf_unregister_hook(®[i]);
+ while (n-- > 0)
+ nf_unregister_hook(®[n]);
}
EXPORT_SYMBOL(nf_unregister_hooks);
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index e34622f..8046350 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -116,10 +116,8 @@ EXPORT_SYMBOL(xt_register_targets);
void
xt_unregister_targets(struct xt_target *target, unsigned int n)
{
- unsigned int i;
-
- for (i = 0; i < n; i++)
- xt_unregister_target(&target[i]);
+ while (n-- > 0)
+ xt_unregister_target(&target[n]);
}
EXPORT_SYMBOL(xt_unregister_targets);
@@ -174,10 +172,8 @@ EXPORT_SYMBOL(xt_register_matches);
void
xt_unregister_matches(struct xt_match *match, unsigned int n)
{
- unsigned int i;
-
- for (i = 0; i < n; i++)
- xt_unregister_match(&match[i]);
+ while (n-- > 0)
+ xt_unregister_match(&match[n]);
}
EXPORT_SYMBOL(xt_unregister_matches);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order
2010-09-02 14:15 [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order Changli Gao
@ 2010-09-15 17:32 ` Patrick McHardy
2010-09-19 5:58 ` Changli Gao
0 siblings, 1 reply; 5+ messages in thread
From: Patrick McHardy @ 2010-09-15 17:32 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, netfilter-devel, netdev
Am 02.09.2010 16:15, schrieb Changli Gao:
> Since we register nf hooks, matches and targets in order, we'd better
> unregister them in the reverse order.
Why? Is there a specific bug you've noticed?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order
2010-09-15 17:32 ` Patrick McHardy
@ 2010-09-19 5:58 ` Changli Gao
2010-10-01 23:57 ` Jan Engelhardt
0 siblings, 1 reply; 5+ messages in thread
From: Changli Gao @ 2010-09-19 5:58 UTC (permalink / raw)
To: Patrick McHardy; +Cc: David S. Miller, netfilter-devel, netdev
On Thu, Sep 16, 2010 at 1:32 AM, Patrick McHardy <kaber@trash.net> wrote:
> Am 02.09.2010 16:15, schrieb Changli Gao:
>> Since we register nf hooks, matches and targets in order, we'd better
>> unregister them in the reverse order.
>
> Why? Is there a specific bug you've noticed?
>
No, there isn't any bug. I just think unregistering them in the
reverse order is more resonable, like the rollback when failing. And
the code patched generates less object:
The original:
00000000000009c9 <xt_unregister_matches>:
9c9: 55 push %rbp
9ca: 48 89 e5 mov %rsp,%rbp
9cd: 41 55 push %r13
9cf: 41 89 f5 mov %esi,%r13d
9d2: 41 54 push %r12
9d4: 49 89 fc mov %rdi,%r12
9d7: 53 push %rbx
9d8: 31 db xor %ebx,%ebx
9da: 48 83 ec 08 sub $0x8,%rsp
9de: eb 0e jmp 9ee <xt_unregister_matches+0x25>
9e0: 4c 89 e7 mov %r12,%rdi
9e3: ff c3 inc %ebx
9e5: 49 83 c4 78 add $0x78,%r12
9e9: e8 00 00 00 00 callq 9ee <xt_unregister_matches+0x25>
9ee: 44 39 eb cmp %r13d,%ebx
9f1: 72 ed jb 9e0 <xt_unregister_matches+0x17>
9f3: 41 59 pop %r9
9f5: 5b pop %rbx
9f6: 41 5c pop %r12
9f8: 41 5d pop %r13
9fa: c9 leaveq
9fb: c3 retq
The patched:
00000000000009c9 <xt_unregister_matches>:
9c9: 55 push %rbp
9ca: 48 89 e5 mov %rsp,%rbp
9cd: 41 54 push %r12
9cf: 41 89 f4 mov %esi,%r12d
9d2: 53 push %rbx
9d3: 48 89 fb mov %rdi,%rbx
9d6: eb 13 jmp 9eb <xt_unregister_matches+0x22>
9d8: 41 ff cc dec %r12d
9db: 44 89 e7 mov %r12d,%edi
9de: 48 6b ff 78 imul $0x78,%rdi,%rdi
9e2: 48 8d 3c 3b lea (%rbx,%rdi,1),%rdi
9e6: e8 00 00 00 00 callq 9eb <xt_unregister_matches+0x22>
9eb: 45 85 e4 test %r12d,%r12d
9ee: 75 e8 jne 9d8 <xt_unregister_matches+0xf>
9f0: 5b pop %rbx
9f1: 41 5c pop %r12
9f3: c9 leaveq
9f4: c3 retq
--
Regards,
Changli Gao(xiaosuo@gmail.com)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order
2010-09-19 5:58 ` Changli Gao
@ 2010-10-01 23:57 ` Jan Engelhardt
2010-10-04 20:26 ` Patrick McHardy
0 siblings, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2010-10-01 23:57 UTC (permalink / raw)
To: Changli Gao; +Cc: Patrick McHardy, David S. Miller, netfilter-devel, netdev
On Sunday 2010-09-19 07:58, Changli Gao wrote:
>On Thu, Sep 16, 2010 at 1:32 AM, Patrick McHardy <kaber@trash.net> wrote:
>> Am 02.09.2010 16:15, schrieb Changli Gao:
>>> Since we register nf hooks, matches and targets in order, we'd better
>>> unregister them in the reverse order.
>>
>> Why? Is there a specific bug you've noticed?
>>
>
>No, there isn't any bug. I just think unregistering them in the
>reverse order is more resonable, like the rollback when failing. And
>the code patched generates less object:
I support this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order
2010-10-01 23:57 ` Jan Engelhardt
@ 2010-10-04 20:26 ` Patrick McHardy
0 siblings, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2010-10-04 20:26 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Changli Gao, David S. Miller, netfilter-devel, netdev
Am 02.10.2010 01:57, schrieb Jan Engelhardt:
> On Sunday 2010-09-19 07:58, Changli Gao wrote:
>
>> On Thu, Sep 16, 2010 at 1:32 AM, Patrick McHardy <kaber@trash.net> wrote:
>>> Am 02.09.2010 16:15, schrieb Changli Gao:
>>>> Since we register nf hooks, matches and targets in order, we'd better
>>>> unregister them in the reverse order.
>>>
>>> Why? Is there a specific bug you've noticed?
>>>
>>
>> No, there isn't any bug. I just think unregistering them in the
>> reverse order is more resonable, like the rollback when failing. And
>> the code patched generates less object:
>
> I support this.
Yeah, it seems reasonable, although I don't like changing things
without a concrete reason. Anyways, applied, thanks everyone.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-10-04 20:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-02 14:15 [PATCH] netfilter: unregister nf hooks, matches and targets in the reverse order Changli Gao
2010-09-15 17:32 ` Patrick McHardy
2010-09-19 5:58 ` Changli Gao
2010-10-01 23:57 ` Jan Engelhardt
2010-10-04 20:26 ` Patrick McHardy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).