Skip to contentSkip to conversation

The module I write seems to have conflict with iptables

DISCUSSION Zheng Da 2 participants 4 messages Jul 28, 2007 – Jul 30, 2007 4 messages not in the archive netfilter

lore
Share & tools
lore

Zheng Da

author
#0 lore raw

Hi,

I write a module based on netfilter.
It is proposed to be used in the filter router, is hooked on FORWARD point, and has the lowest priority, NF_IP_PRI_LAST.
It does the following things:
When it finds TCP connection from the client to the server, it will pretend as the server to build the connection with the client. It blocks the SYN and ACK packets from the client, and sends a UDP packet to the server, which can force the server build the TCP connection with the client. It works as follow:
Client Router
Server

         -----------SYN--------->
         <-------SYN,ACK----
         -----------ACK--------->

----------UDP-------------->
The UDP packet sent by Router contains all information about the TCP connection, and can force Server build the TCP connection with Client. Suppose the topology is as follow:
Client ----------(eth0) Router (eth1) --------- Server
eth1 of Router and Server can't see the SYN and ACK packet from the client because of the module in Router.
I want this module to work with iptables, and the configuration of iptables in Router is:
iptables -F
iptables -X
iptables -P FORWARD DROP
iptables -A FORWARD -i eth1 -j ACCEPT
iptables -A FORWARD -i eth0 -m state --state ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -p tcp --dport 22 -m state --state ESTABLISHED,NEW -j ACCEPT
I want the client can only access SSH service on Server.
After I insert my module into the kernel, Client can build TCP connection with Server, and they can communicate with each other. But after a few minutes, Server can't receive the packets from the client any more. So is my module.
If I clear iptables' rules, the module can work well.
So I guess the module I write may have conflict with iptables.
I don't know how the connection track of iptables works.
Is it possible that my module may make the connection track not work.

Best,
Zheng jDa

#1 lore raw
Quoted 9 lines · Zheng Da

I write a module based on netfilter.
It is proposed to be used in the filter router, is hooked on FORWARD point, and has the lowest priority, NF_IP_PRI_LAST.
It does the following things:
When it finds TCP connection from the client to the server, it will pretend as the server to build the connection with the client. It blocks the SYN and ACK packets from the client, and sends a UDP packet to the server, which can force the server build the TCP connection with the client.

It is almost impossible to help without seeing code.

Jan

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

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

author
#4 lore raw
Quoted 23 lines · Jan Engelhardt
Quoted 12 lines · Zheng Da
Quoted 12 lines
Quoted 12 lines

I write a module based on netfilter. It is proposed to be used in the filter router, is hooked on FORWARD point, and has the lowest priority, NF_IP_PRI_LAST. It does the following things:
When it finds TCP connection from the client to the server, it will pretend as the server to build the connection with the client. It blocks the SYN and ACK packets from the client, and sends a UDP packet to the server, which can force the server build the TCP connection with the client.

Quoted 8 lines
Quoted 4 lines

It is almost impossible to help without seeing code.

Sorry, I'm just thinking whether the way of my module working may make connection track not work correctly. OK. This is my code. A little big.

Quoted 8 lines

Quite a lot of code, I'd say, so I could not look through all of it.
I suspect that NF_IP_PRI_LAST and NF_IP_PRI_FIRST may have problematic effects. You could try NF_IP_PRI_FILTER+1 (instead of LAST), and NF_IP_PRI_FILTER-1 (instead of FIRST).

Jan

I finally find the problem. The problem is not caused by my module, but my configuration of iptables. The original configuration is:
iptables -F
iptables -X
iptables -P FORWARD DROP
iptables -A FORWARD -i eth1 -j ACCEPT <------------------change this line
iptables -A FORWARD -i eth0 -m state --state ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -p tcp --dport 22 -m state --state ESTABLISHED,NEW -j ACCEPT
If I change the line for the device of eth1 to
iptables -A FORWARD -i eth1 -j ACCEPT -m state --state ESTABLISHED,RELATED,NEW
It works.
The problem is what is the difference between
iptables -A FORWARD -i eth1 -j ACCEPT
and
iptables -A FORWARD -i eth1 -j ACCEPT -m state --state ESTABLISHED,RELATED,NEW.
I check ip_conntrack in Router, the connections between Client and Server are assured in both configurations. I use Wireshark to capture the packets when in the original configuration. I put the result in the attachment.
externel: the packets between Client and Router
internal: the packets between Router and Server
Does anyone have any idea?

Best,
Zheng Da

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

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

author
#7 lore raw
Quoted 28 lines · Jan Engelhardt
Quoted 18 lines · Zheng Da

I finally find the problem. The problem is not caused by my module, but my configuration of iptables.
The original configuration is:
iptables -F
iptables -X
iptables -P FORWARD DROP
iptables -A FORWARD -i eth1 -j ACCEPT <------------------change this line
iptables -A FORWARD -i eth0 -m state --state ESTABLISHED -j ACCEPT iptables -A FORWARD -i eth0 -p tcp --dport 22 -m state --state ESTABLISHED,NEW -j ACCEPT

If I change the line for the device of eth1 to

	iptables -A FORWARD -i eth1 -j ACCEPT -m state --state
	ESTABLISHED,RELATED,NEW
Quoted 7 lines

It works.
The problem is what is the difference between
iptables -A FORWARD -i eth1 -j ACCEPT
and

	iptables -A FORWARD -i eth1 -j ACCEPT -m state --state
	ESTABLISHED,RELATED,NEW.
Quoted 8 lines

The first one accepts all packets from eth1, the second only EST,REL,NEW -- which excludes INVALID.

INVALID connections do not show up in ip_conntrack I believe, but you can make them visible using LOG for example:

	-i eth1 -m conntrack --ctstate INVALID -j LOG

But it doesn't explain why the change of the configuration can make my module work correctly. I think there should be more difference

Quoted 19 lines
Quoted 10 lines

I check ip_conntrack in Router, the connections between Client and Server are assured in both configurations.
I use Wireshark to capture the packets when in the original configuration. I put the result in the attachment.
externel: the packets between Client and Router
internal: the packets between Router and Server

Quoted 2 lines

Does anyone have any idea?

Post to the mailing list, there are more people to answer.

Jan