Hello all,
I did SNAT test as below and found it's strange:

Server-A with ip, with kernel 2.6.9-42.EL. An other server-B with ip

run below command on Server-A, to SNAT all source ip to
iptables -t nat -A POSTROUTING -s -j SNAT --to-source

when I tried to ping on server-A, as expected, it failed. because server-B returned ping reply to

but when I tried ping on server-B, it successed. that means the echo-reply to was NOT SNATed to (it's confirmed as I have done tcpdump on server-B and saw the source ip of echo-reply was

I tried TCP connection, it was the same as icmp.

I checked the kernel source code, in "ip_output.c":
280 ip_finish_output,
281 !(IPCB(skb)->flags & IPSKB_REROUTED));

so if !(IPCB(skb)->flags & IPSKB_REROUTED) == 0, then ip_finish_output() is excuted, i.e. NF_IP_POST_ROUTING
is not checked. Details is in "include/linux/netfilter.h":
249 #define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \
250 ({int __ret; \
251 if ((__ret=nf_hook_thresh(pf, hook, &(skb), indev, outdev, okfn, INT_MIN, cond)) == 1)\
252 __ret = (okfn)(skb); \
253 __ret;})

198 static inline int nf_hook_thresh(int pf, unsigned int hook,
199 struct sk_buff **pskb,
200 struct net_device *indev,
201 struct net_device *outdev,
202 int (*okfn)(struct sk_buff *), int thresh,
203 int cond)
204 {
205 if (!cond)
206 return 1;
212 }

IPCB() is defined in include/net/ip.h: #define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))

so when !(((struct inet_skb_parm*)((skb)->cb))->flags & IPSKB_REROUTED) == 0, NF_IP_POST_ROUTING is skipped.

It looks like that the local initiative packet(like ping on works as expected, i.e. it's SNATed, or saying the IPCB(skb)->flags is not set as IPSKB_REROUTED. But the echo replied packet is with IPCB(skb)->flags set to IPSKB_REROUTED, thus it skips being SNATed.

I guess the local initiative packet using a fresh allocated skb_buff, so its flag is not set. but the replied packet uses the skb_buff of received packet, which has gone through PREROUTING chain, so the flag is set.

So what's the purpose of doing !(IPCB(skb)->flags & IPSKB_REROUTED) check?(for IPSEC?) and is the above sympton a bug of netfilter?