Skip to contentSkip to conversation

Multiple calls of check functions

DISCUSSION Patrick McHardy 2 participants 2 messages Apr 2, 2007 1 message not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 10 lines · johnpeng

Dear all:
When I issue the command with debug version of the SAME target (I am
using kernel 2.6.17.7 and iptables 1.3.5)
"iptables -t nat -A PREROUTING -d 10.10.10.1 -j SAME -to 172.31.0.1-172.31.0.3"
I find that the check function of SAME target would be called multiple times, any following SNAT,DNAT rules would call the check function of the SAME
Target , however, I didn't see the same situation in kernel 2.4 , is that due to some framework change in kernel 2.6 ?

No, that has always been the case. Every rule you add results in an entire new ruleset from the kernels POV, so each rule is completely validated again.

Quoted 7 lines

And
When we issue the removal "iptables -t nat -D PREROUTING -d 10.10.10.1 -j SAME -to 172.31.0.1-172.31.0.3",
Iptables get reply of "iptables: No chain/target/match by that name",
it seems the memory comparison is not equal with user level and kernel
level passed target info data structure,
Any solution?

Unfortunately no, the SAME target is unfixable broken in this regard:

struct ipt_same_info

{
        unsigned char info;
        u_int32_t rangesize;
        u_int32_t ipnum;
        u_int32_t *iparray;


        /* hangs off end. */
        struct ip_nat_range range[IPT_SAME_MAX_RANGE];
};

The pointer contains random content when dumping the rules from the kernel, so we can't compare it. The usual way to deal with this is to only compare the first n bytes, but that doesn't work in case of SAME since we have data that must be compared following the pointer.

The SAME target is obsolete and SNAT should also uses the same IPs for the same source nowadays, so I'd suggest you simply use SNAT.

#2 lore raw

Thanks for the help, and..

Quoted 7 lines

-----Original Message-----
From: Patrick McHardy [mailto:[email protected]]
Sent: Monday, April 02, 2007 7:28 PM
To: johnpeng
Cc: [email protected]
Subject: Re: Multiple calls of check functions

Quoted 8 lines
Quoted 7 lines · johnpeng

Dear all:
When I issue the command with debug version of the SAME target (I am
using kernel 2.6.17.7 and iptables 1.3.5)
"iptables -t nat -A PREROUTING -d 10.10.10.1 -j SAME -to 172.31.0.1-172.31.0.3"
I find that the check function of SAME target would be called multiple times, any following SNAT,DNAT rules would call the check function of

the

Quoted 2 lines
Quoted 2 lines

SAME
Target , however, I didn't see the same situation in kernel 2.4 , is

that

Quoted 6 lines
Quoted 1 line

due to some framework change in kernel 2.6 ?

No, that has always been the case. Every rule you add results in an entire new ruleset from the kernels POV, so each rule is completely validated again.

This means that we need use some flag (in the targetinfo) in the check function to block the process of some code-flow if we want to the code-flow to be processed only one time?

Quoted 2 lines
Quoted 2 lines

And
When we issue the removal "iptables -t nat -D PREROUTING -d 10.10.10.1

-j

Quoted 21 lines
Quoted 5 lines

SAME -to 172.31.0.1-172.31.0.3",
Iptables get reply of "iptables: No chain/target/match by that name",
it seems the memory comparison is not equal with user level and kernel
level passed target info data structure,
Any solution?

Unfortunately no, the SAME target is unfixable broken in this regard:

struct ipt_same_info

{
        unsigned char info;
        u_int32_t rangesize;
        u_int32_t ipnum;
        u_int32_t *iparray;


        /* hangs off end. */
        struct ip_nat_range range[IPT_SAME_MAX_RANGE];
};
Quoted 9 lines

The pointer contains random content when dumping the rules from the kernel, so we can't compare it. The usual way to deal with this is to only compare the first n bytes, but that doesn't work in case of SAME since we have data that must be compared following the pointer.

The SAME target is obsolete and SNAT should also uses the same IPs for the same source nowadays, so I'd suggest you simply use SNAT.

Because I want to use multiple ranges of SAME, however, multiple range has been removed from 2.6 ... any solution, thanks!!