All of lore.kernel.org
 help / color / mirror / Atom feed
* how to discard a netfilter rule
@ 2013-02-28  6:26 Donghua Liu
  2013-02-28  9:02 ` Neal Murphy
  2013-02-28 14:37 ` Rob Sterenborg (lists)
  0 siblings, 2 replies; 5+ messages in thread
From: Donghua Liu @ 2013-02-28  6:26 UTC (permalink / raw)
  To: netfilter

Hi,

Say if I set a netfilter rule by "iptables -t nat -A custom_chain -p
tcp -dport 80 -j DNAT --to-destination 127.0.0.1:1234" for some
requirement.

I also have a LKM which will check the availablity of service
"127.0.0.1:1234" and how can I cancel the rule's operation(Do NOT
delete this rule), let the packet go as usual ignore the nat.

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to discard a netfilter rule
  2013-02-28  6:26 how to discard a netfilter rule Donghua Liu
@ 2013-02-28  9:02 ` Neal Murphy
  2013-02-28 14:37 ` Rob Sterenborg (lists)
  1 sibling, 0 replies; 5+ messages in thread
From: Neal Murphy @ 2013-02-28  9:02 UTC (permalink / raw)
  To: netfilter

On Thursday, February 28, 2013 01:26:52 AM Donghua Liu wrote:
> Hi,
> 
> Say if I set a netfilter rule by "iptables -t nat -A custom_chain -p
> tcp -dport 80 -j DNAT --to-destination 127.0.0.1:1234" for some
> requirement.
> 
> I also have a LKM which will check the availablity of service
> "127.0.0.1:1234" and how can I cancel the rule's operation(Do NOT
> delete this rule), let the packet go as usual ignore the nat.

Assuimg '-j RETURN' is valid, put the rule in chain 'custchainNAT' by itself 
and add a jump to that chain from custom_chain. To disable the nat, insert 
(via -I 1) a '-j RETURN' rule in 'custchainNAT' before the NAT rule. To re-
enable it, delete the RETURN rule.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to discard a netfilter rule
@ 2013-02-28 10:55 Donghua Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Donghua Liu @ 2013-02-28 10:55 UTC (permalink / raw)
  To: netfilter

>On Thursday, February 28, 2013 01:26:52 AM Donghua Liu wrote:
>> Hi,
>>
>> Say if I set a netfilter rule by "iptables -t nat -A custom_chain -p
>> tcp -dport 80 -j DNAT --to-destination 127.0.0.1:1234" for some
>> requirement.
>>
>> I also have a LKM which will check the availablity of service
>> "127.0.0.1:1234" and how can I cancel the rule's operation(Do NOT
>> delete this rule), let the packet go as usual ignore the nat.
>
>Assuimg '-j RETURN' is valid, put the rule in chain 'custchainNAT' by itself
>and add a jump to that chain from custom_chain. To disable the nat, insert
>(via -I 1) a '-j RETURN' rule in 'custchainNAT' before the NAT rule. To re-
>enable it, delete the RETURN rule.

I couldn't get the reply so I have to write a new email(I do not know
why, that's really strange)
Thanks for your reply, Neal Murphy.
But what I want to do is how to implement in the kernel module not command line.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to discard a netfilter rule
  2013-02-28  6:26 how to discard a netfilter rule Donghua Liu
  2013-02-28  9:02 ` Neal Murphy
@ 2013-02-28 14:37 ` Rob Sterenborg (lists)
  2013-03-01  3:19   ` Donghua Liu
  1 sibling, 1 reply; 5+ messages in thread
From: Rob Sterenborg (lists) @ 2013-02-28 14:37 UTC (permalink / raw)
  To: Donghua Liu; +Cc: netfilter

On 02/28/2013 07:26 AM, Donghua Liu wrote:
> Hi,
>
> Say if I set a netfilter rule by "iptables -t nat -A custom_chain -p
> tcp -dport 80 -j DNAT --to-destination 127.0.0.1:1234" for some
> requirement.
>
> I also have a LKM which will check the availablity of service
> "127.0.0.1:1234" and how can I cancel the rule's operation(Do NOT
> delete this rule), let the packet go as usual ignore the nat.

man iptables says there is a -R command to replace rules:

----
        -R, --replace chain rulenum rule-specification
               Replace a rule in the selected chain.  If the source 
and/or destination names resolve to multiple addresses, the command will 
fail.  Rules are numbered starting at 1.
----

Assuming you know which rulenum must be changed, you can do this:

iptables -t nat -R custom_chain 1 -p tcp -dport 80

IOW, lose the -j parameter from the rule, keeping the others. The result 
is that the rule will still be there, but effectively won't do anything 
except for matching and updating packet/byte counting.


--
Rob


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to discard a netfilter rule
  2013-02-28 14:37 ` Rob Sterenborg (lists)
@ 2013-03-01  3:19   ` Donghua Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Donghua Liu @ 2013-03-01  3:19 UTC (permalink / raw)
  To: netfilter

2013/2/28 Rob Sterenborg (lists) <lists@sterenborg.info>
>
> On 02/28/2013 07:26 AM, Donghua Liu wrote:
>>
>> Hi,
>>
>> Say if I set a netfilter rule by "iptables -t nat -A custom_chain -p
>> tcp -dport 80 -j DNAT --to-destination 127.0.0.1:1234" for some
>> requirement.
>>
>> I also have a LKM which will check the availablity of service
>> "127.0.0.1:1234" and how can I cancel the rule's operation(Do NOT
>> delete this rule), let the packet go as usual ignore the nat.
>
>
> man iptables says there is a -R command to replace rules:
>
> ----
>        -R, --replace chain rulenum rule-specification
>               Replace a rule in the selected chain.  If the source and/or
> destination names resolve to multiple addresses, the command will fail.
> Rules are numbered starting at 1.
> ----
>
> Assuming you know which rulenum must be changed, you can do this:
>
> iptables -t nat -R custom_chain 1 -p tcp -dport 80
>
> IOW, lose the -j parameter from the rule, keeping the others. The result
> is that the rule will still be there, but effectively won't do anything
> except for matching and updating packet/byte counting.
>
>
> --
> Rob
>

Replace rules maybe solve my problem, but I must do it in kernelspace.
Now I have some ideas
Maybe I should extend the netfilter/xtables like
    iptables -t nat -A custom_chain -p tcp -dport 80 -m
process_available --process_name some_process_name -j DNAT
--to-destination 127.0.0.1:1234
    or
    iptables -t nat -A custom_chain -p tcp -dport 80 -j SAFE_DNAT
--to-destination 127.0.0.1:1234
But how can I implement these.
Can anyone provide me some tutorial or write a small example to explain this.
Thanks in advance!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-03-01  3:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-28  6:26 how to discard a netfilter rule Donghua Liu
2013-02-28  9:02 ` Neal Murphy
2013-02-28 14:37 ` Rob Sterenborg (lists)
2013-03-01  3:19   ` Donghua Liu
  -- strict thread matches above, loose matches on Subject: below --
2013-02-28 10:55 Donghua Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.