'raw' table
Subsystems (2)
PATCH 1/1 'raw' table
Hi Dave!
This is a patch adding a 'raw' table. This table is iterated in NF_IP[6]_PRE_ROUTING before anything else happens (esp. before conntrack).
The idea is to call the 'NOTRACK' target from within the 'raw' table to prevent certain packets from being connection tracked.
This 'raw' table is also neccessarry for the upcoming 'TRACE' target that would allow you to mark those packets that you want to have traced while iterating through all netfilter/iptables modules.
Author: Jozsef Kadlecsik
Please submit,
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
include/linux/netfilter_ipv4/ip_conntrack.h +3 -0
@@ -251,6 +251,9 @@/* Call me when a conntrack is destroyed. */ extern void (*ip_conntrack_destroyed)(struct ip_conntrack *conntrack); +/* Fake conntrack entry for untracked connections */ +extern struct ip_conntrack ip_conntrack_untracked; +/* Returns new sk_buff, or NULL */ struct sk_buff *ip_ct_gather_frags (struct sk_buff *skb);
include/linux/netfilter_ipv4/ipt_conntrack.h +1 -0
@@ -10,6 +10,7 @@#define IPT_CONNTRACK_STATE_SNAT (1 << (IP_CT_NUMBER + 1))#define IPT_CONNTRACK_STATE_DNAT (1 << (IP_CT_NUMBER + 2)) +#define IPT_CONNTRACK_STATE_UNTRACKED (1 << (IP_CT_NUMBER + 3))/* flags, invflags: */ #define IPT_CONNTRACK_STATE 0x01
include/linux/netfilter_ipv4/ipt_state.h +2 -0
@@ -4,6 +4,8 @@#define IPT_STATE_BIT (ctinfo) (1 << ((ctinfo)%IP_CT_IS_REPLY+1))#define IPT_STATE_INVALID (1 << 0) +#define IPT_STATE_UNTRACKED (1 << (IP_CT_NUMBER + 1)) +struct ipt_state_info {unsigned int statemask;
include/linux/netfilter_ipv4.h +2 -0
@@ -51,6 +51,8 @@enum nf_ip_hook_priorities {NF_IP_PRI_FIRST =INT_MIN , +NF_IP_PRI_CONNTRACK_DEFRAG =-400 , +NF_IP_PRI_RAW =-300 ,NF_IP_PRI_SELINUX_FIRST =-225 ,NF_IP_PRI_CONNTRACK =-200 ,NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD =-175 ,
net/ipv4/netfilter/Kconfig +24 -0
@@ -579,5 +579,29 @@ To compile it as a module, choose M here. If unsure, say N. +config IP_NF_TARGET_NOTRACK + tristate 'NOTRACK target support' + depends on IP_NF_RAW + help + The NOTRACK target allows a select rule to specify + which packets *not* to enter the conntrack/NAT + subsystem with all the consequences (no ICMP error tracking, + no protocol helpers for the selected packets). + + If you want to compile it as a module, say M here and read + <file:Documentation/modules.txt>. If unsure, say `N'. + +config IP_NF_RAW + tristate 'raw table support (required for NOTRACK/TRACE)' + depends on IP_NF_IPTABLES + help + This option adds a `raw' table to iptables. This table is the very + first in the netfilter framework and hooks in at the PREROUTING + and OUTPUT chains. + + If you want to compile it as a module, say M here and read + <file:Documentation/modules.txt>. If unsure, say `N'. + help + endmenu
net/ipv4/netfilter/Makefile +2 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_IP_NF_FILTER) += iptable_filter.o obj-$(CONFIG_IP_NF_MANGLE) += iptable_mangle.o obj-$(CONFIG_IP_NF_NAT) += iptable_nat.o +obj-$(CONFIG_IP_NF_RAW) += iptable_raw.o # matches obj-$(CONFIG_IP_NF_MATCH_HELPER) += ipt_helper.o
@@ -81,6 +82,7 @@ obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o +obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o # generic ARP tables obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o
net/ipv4/netfilter/ip_conntrack_core.c +23 -9
@@ -67,6 +67,7 @@static atomic_t ip_conntrack_count =ATOMIC_INIT (0 );struct list_head *ip_conntrack_hash;static kmem_cache_t *ip_conntrack_cachep; +struct ip_conntrack ip_conntrack_untracked;extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
@@ -794,6 +795,15 @@int set_reply;int ret; +/* Never happen */ +if ((*pskb)->nh.iph->frag_off &htons (IP_OFFSET )) { +if (net_ratelimit ()) { +printk (KERN_ERR "ip_conntrack_in: Frag of proto %u (hook=%u)\n" , + (*pskb)->nh.iph->protocol, hooknum); + } +return NF_DROP ; + } +/* FIXME: Do this right please. --RR */ (*pskb)->nfcache |=NFC_UNKNOWN ;
@@ -812,18 +822,10 @@ }#endif -/* Previously seen (loopback)? Ignore. Do this before -fragment check. */ +/* Previously seen (loopback or untracked)? Ignore. */ if ((*pskb)->nfct)return NF_ACCEPT ; -/* Gather fragments. */ -if ((*pskb)->nh.iph->frag_off &htons (IP_MF |IP_OFFSET )) { - *pskb =ip_ct_gather_frags (*pskb); -if (!*pskb) -return NF_STOLEN ; - } - proto =ip_ct_find_proto ((*pskb)->nh.iph->protocol);/* It may be an icmp error... */
@@ -1422,6 +1424,18 @@/* For use by ipt_REJECT */ ip_ct_attach = ip_conntrack_attach; + +/* Set up fake conntrack: +- to never be deleted, not in any hashes */ +atomic_set (&ip_conntrack_untracked.ct_general.use,1 ); +/* - and look it like as a confirmed connection */ +set_bit (IPS_CONFIRMED_BIT , &ip_conntrack_untracked.status); +/* - and prepare the ctinfo field for REJECT & NAT. */ + ip_conntrack_untracked.infos[IP_CT_NEW ].master = + ip_conntrack_untracked.infos[IP_CT_RELATED ].master = + ip_conntrack_untracked.infos[IP_CT_RELATED +IP_CT_IS_REPLY ].master = + &ip_conntrack_untracked.ct_general; +return ret; err_free_hash:
net/ipv4/netfilter/ip_conntrack_standalone.c +52 -1
91 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_core.c +4 -0
@@ -1016,6 +1016,10 @@/* FIXME: Man, this is a hack. <SIGH> */ IP_NF_ASSERT (ip_conntrack_destroyed ==NULL ); ip_conntrack_destroyed = &ip_nat_cleanup_conntrack; + +/* Initialize fake conntrack so that NAT will skip it */ + ip_conntrack_untracked.nat.info.initialized |= + (1 <<IP_NAT_MANIP_SRC ) | (1 <<IP_NAT_MANIP_DST );return 0 ; }
net/ipv4/netfilter/ipt_NOTRACK.c +75 -0
75 lines not on this page · raw message
net/ipv4/netfilter/ipt_conntrack.c +7 -5
@@ -35,11 +35,13 @@#define FWINV (bool,invflg) ((bool) ^ !!(sinfo->invflags & invflg)) -if (ct) - statebit =IPT_CONNTRACK_STATE_BIT (ctinfo); -else - statebit =IPT_CONNTRACK_STATE_INVALID ; - +if (skb->nfct == &ip_conntrack_untracked.infos[IP_CT_NEW ]) + statebit =IPT_CONNTRACK_STATE_UNTRACKED ; +else if (ct) + statebit =IPT_CONNTRACK_STATE_BIT (ctinfo); +else + statebit =IPT_CONNTRACK_STATE_INVALID ; +if (sinfo->flags &IPT_CONNTRACK_STATE ) {if (ct) { if(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip !=
net/ipv4/netfilter/ipt_state.c +3 -1
@@ -30,7 +30,9 @@enum ip_conntrack_info ctinfo;unsigned int statebit; -if (!ip_conntrack_get ((struct sk_buff *)skb, &ctinfo)) +if (skb->nfct == &ip_conntrack_untracked.infos[IP_CT_NEW ]) + statebit =IPT_STATE_UNTRACKED ; +else if (!ip_conntrack_get ((struct sk_buff *)skb, &ctinfo)) statebit =IPT_STATE_INVALID ;else statebit =IPT_STATE_BIT (ctinfo);
net/ipv4/netfilter/iptable_raw.c +149 -0
149 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +12 -0
@@ -218,5 +218,17 @@ To compile it as a module, choose M here. If unsure, say N. #dep_tristate ' LOG target support' CONFIG_IP6_NF_TARGET_LOG $CONFIG_IP6_NF_IPTABLES +config IP6_NF_RAW + tristate 'raw table support (required for TRACE)' + depends on IP6_NF_IPTABLES + help + This option adds a `raw' table to ip6tables. This table is the very + first in the netfilter framework and hooks in at the PREROUTING + and OUTPUT chains. + + If you want to compile it as a module, say M here and read + <file:Documentation/modules.txt>. If unsure, say `N'. + help + endmenu
net/ipv6/netfilter/Makefile +1 -0
@@ -21,4 +21,5 @@ obj-$(CONFIG_IP6_NF_TARGET_MARK) += ip6t_MARK.o obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o +obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
net/ipv6/netfilter/ip6table_raw.c +154 -0
154 lines not on this page · raw message
David S. Miller
AppliedApplied to 2.6.6, thanks.