-PATCH 2/3] Call directly from Conntrack to NAT helpers: others
Subsystems (2)
Name: Fix Up IRC, AMANDA and TFTP Helpers
Status: Compiled on 2.6.10-rc2-bk6
Signed-off-by Rusty Russell <[email protected]>
Fixes up the other helpers for direct conntrack->NAT helper calling.
net/ipv4/netfilter/ip_conntrack_amanda.c +31 -19
@@ -44,14 +44,22 @@static char amanda_buffer[65536 ];static DECLARE_LOCK (amanda_buffer_lock); -static int help (struct sk_buff *skb, +unsigned int (*ip_nat_amanda_hook)(struct sk_buff **pskb, +struct ip_conntrack *ct, +enum ip_conntrack_info ctinfo, +unsigned int matchoff, +unsigned int matchlen, +struct ip_conntrack_expect *exp); +EXPORT_SYMBOL_GPL (ip_nat_amanda_hook); + +static int help (struct sk_buff **pskb,struct ip_conntrack *ct,enum ip_conntrack_info ctinfo) {struct ip_conntrack_expect *exp; -struct ip_ct_amanda_expect *exp_amanda_info;char *data, *data_limit, *tmp;unsigned int dataoff, i;u_int16_t port, len; +int ret =NF_ACCEPT ;/* Only look at packets from the Amanda server */ if (CTINFO2DIR (ctinfo) ==IP_CT_DIR_ORIGINAL )
@@ -62,17 +70,17 @@ip_ct_refresh_acct (ct, ctinfo,NULL , master_timeout *HZ );/* No data? */ - dataoff = skb->nh.iph->ihl*4 +sizeof (struct udphdr ); -if (dataoff >= skb->len) { + dataoff = (*pskb)->nh.iph->ihl*4 +sizeof (struct udphdr ); +if (dataoff >= (*pskb)->len) {if (net_ratelimit ()) -printk ("amanda_help: skblen = %u\n" , skb->len); +printk ("amanda_help: skblen = %u\n" , (*pskb)->len);return NF_ACCEPT ; }LOCK_BH (&amanda_buffer_lock); -skb_copy_bits (skb, dataoff, amanda_buffer, skb->len - dataoff); +skb_copy_bits (*pskb, dataoff, amanda_buffer, (*pskb)->len - dataoff); data = amanda_buffer; - data_limit = amanda_buffer + skb->len - dataoff; + data_limit = amanda_buffer + (*pskb)->len - dataoff; *data_limit ='\0' ;/* Search for the CONNECT string */
@@ -96,36 +104,41 @@break ; exp =ip_conntrack_expect_alloc (); -if (exp ==NULL ) +if (exp ==NULL ) { + ret =NF_DROP ; goto out; + } + + exp->expectfn =NULL ; exp->tuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.ip; + exp->tuple.src.u.tcp.port =0 ; exp->tuple.dst.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.ip; exp->tuple.dst.protonum =IPPROTO_TCP ; + exp->tuple.dst.u.tcp.port =htons (port); + exp->mask.src.ip =0xFFFFFFFF ; + exp->mask.src.u.tcp.port =0 ; exp->mask.dst.ip =0xFFFFFFFF ; exp->mask.dst.protonum =0xFFFF ; exp->mask.dst.u.tcp.port =0xFFFF ; - exp_amanda_info = &exp->help.exp_amanda_info; - exp_amanda_info->offset = tmp - amanda_buffer; - exp_amanda_info->port = port; - exp_amanda_info->len = len; - - exp->tuple.dst.u.tcp.port =htons (port); - -ip_conntrack_expect_related (exp, ct); +if (ip_nat_amanda_hook) + ret =ip_nat_amanda_hook (pskb, ct, ctinfo, + tmp - amanda_buffer, + len, exp); +else if (ip_conntrack_expect_related (exp, ct) !=0 ) + ret =NF_DROP ; } out:UNLOCK_BH (&amanda_buffer_lock); -return NF_ACCEPT ; +return ret; }static struct ip_conntrack_helper amanda_helper = { .max_expected =ARRAY_SIZE (conns), .timeout =180 , - .flags =IP_CT_HELPER_F_REUSE_EXPECT , .me =THIS_MODULE , .help = help, .name ="amanda" ,
@@ -148,6 +161,5 @@return ip_conntrack_helper_register (&amanda_helper); } -PROVIDES_CONNTRACK (amanda);module_init (init);module_exit (fini);
net/ipv4/netfilter/ip_nat_snmp_basic.c +16 -18
@@ -1309,26 +1309,24 @@ }static struct ip_nat_helper snmp = { - {NULL ,NULL }, -"snmp" , -0 , -THIS_MODULE , - { {0 , { .udp = {__constant_htons (SNMP_PORT ) } } }, - {0 , {0 },IPPROTO_UDP } }, - { {0 , { .udp = {0xFFFF } } }, - {0 , {0 },0xFFFF } }, - nat_help,NULL }; + .name ="snmp" , + .me =THIS_MODULE , + .tuple = { {0 , { .udp = {__constant_htons (SNMP_PORT ) } } }, + {0 , {0 },IPPROTO_UDP } }, + .mask = { {0 , { .udp = {0xFFFF } } }, + {0 , {0 },0xFFFF } }, + .help = nat_help, +};static struct ip_nat_helper snmp_trap = { - {NULL ,NULL }, -"snmp_trap" , -0 , -THIS_MODULE , - { {0 , { .udp = {__constant_htons (SNMP_TRAP_PORT ) } } }, - {0 , {0 },IPPROTO_UDP } }, - { {0 , { .udp = {0xFFFF } } }, - {0 , {0 },0xFFFF } }, - nat_help,NULL }; + .name ="snmp_trap" , + .me =THIS_MODULE , + .tuple = { {0 , { .udp = {__constant_htons (SNMP_TRAP_PORT ) } } }, + {0 , {0 },IPPROTO_UDP } }, + .mask = { {0 , { .udp = {0xFFFF } } }, + {0 , {0 },0xFFFF } }, + .help = nat_help, +};/***************************************************************************** *
include/linux/netfilter_ipv4/ip_conntrack.h +0 -10
@@ -303,15 +303,5 @@#define CONNTRACK_STAT_INC (count) (__get_cpu_var(ip_conntrack_stat).count++) -/* eg. PROVIDES_CONNTRACK(ftp); */ -#define PROVIDES_CONNTRACK (name) \ - int needs_ip_conntrack_##name; \ - EXPORT_SYMBOL(needs_ip_conntrack_##name) - -/*. eg. NEEDS_CONNTRACK(ftp); */ -#define NEEDS_CONNTRACK (name) \ - extern int needs_ip_conntrack_##name; \ - static int *need_ip_conntrack_##name __attribute_used__ = &needs_ip_conntrack_##name -#endif /* __KERNEL__ */ #endif /* _IP_CONNTRACK_H */
net/ipv4/netfilter/ip_conntrack_tftp.c +15 -8
@@ -38,15 +38,22 @@ #define DEBUGP(format, args...)#endif -static int tftp_help (struct sk_buff *skb, +unsigned int (*ip_nat_tftp_hook)(struct sk_buff **pskb, +struct ip_conntrack *ct, +enum ip_conntrack_info ctinfo, +struct ip_conntrack_expect *exp); +EXPORT_SYMBOL_GPL (ip_nat_tftp_hook); + +static int tftp_help (struct sk_buff **pskb,struct ip_conntrack *ct,enum ip_conntrack_info ctinfo) {struct tftphdr _tftph, *tfh;struct ip_conntrack_expect *exp; +unsigned int ret =NF_ACCEPT ; - tfh =skb_header_pointer (skb, - skb->nh.iph->ihl *4 +sizeof (struct udphdr ), + tfh =skb_header_pointer (*pskb, + (*pskb)->nh.iph->ihl*4 +sizeof (struct udphdr ),sizeof (_tftph), &_tftph);if (tfh ==NULL )return NF_ACCEPT ;
@@ -61,7 +68,7 @@ exp =ip_conntrack_expect_alloc ();if (exp ==NULL ) -return NF_ACCEPT ; +return NF_DROP ; exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY ].tuple; exp->mask.src.ip =0xffffffff ;
@@ -73,7 +80,10 @@DEBUGP ("expect: " );DUMP_TUPLE (&exp->tuple);DUMP_TUPLE (&exp->mask); -ip_conntrack_expect_related (exp, ct); +if (ip_nat_tftp_hook) + ret =ip_nat_tftp_hook (pskb, ct, ctinfo, exp); +else if (ip_conntrack_expect_related (exp, ct) !=0 ) + ret =NF_DROP ;break ;case TFTP_OPCODE_DATA :case TFTP_OPCODE_ACK :
@@ -120,7 +130,6 @@ tftp[i].mask.src.u.udp.port =0xFFFF ; tftp[i].max_expected =1 ; tftp[i].timeout =0 ; - tftp[i].flags =IP_CT_HELPER_F_REUSE_EXPECT ; tftp[i].me =THIS_MODULE ; tftp[i].help = tftp_help;
@@ -144,7 +153,5 @@return (0 ); } -PROVIDES_CONNTRACK (tftp); -module_init (init);module_exit (fini);
net/ipv4/netfilter/ip_nat_amanda.c +39 -94
157 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_tftp.c +16 -152
184 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_irc.c +44 -185
279 lines not on this page · raw message
include/linux/netfilter_ipv4/ip_conntrack_tftp.h +5 -0
@@ -13,4 +13,9 @@#define TFTP_OPCODE_ACK 4#define TFTP_OPCODE_ERROR 5 +unsigned int (*ip_nat_tftp_hook)(struct sk_buff **pskb, +struct ip_conntrack *ct, +enum ip_conntrack_info ctinfo, +struct ip_conntrack_expect *exp); +#endif /* _IP_CT_TFTP */
net/ipv4/netfilter/ip_conntrack_irc.c +29 -32
133 lines not on this page · raw message
include/linux/netfilter_ipv4/ip_conntrack_irc.h +6 -13
@@ -14,24 +14,17 @@#ifndef _IP_CONNTRACK_IRC_H#define _IP_CONNTRACK_IRC_H -/* We record seq number and length of irc ip/port text here: all in -host order. */ - -/* This structure is per expected connection */ -struct ip_ct_irc_expect -{ -/* length of IP address */ -u_int32_t len; -/* Port that was to be used */ -u_int16_t port; -}; -/* This structure exists only once per master */ struct ip_ct_irc_master { }; -#ifdef __KERNEL__ +extern unsigned int (*ip_nat_irc_hook)(struct sk_buff **pskb, +struct ip_conntrack *ct, +enum ip_conntrack_info ctinfo, +unsigned int matchoff, +unsigned int matchlen, +struct ip_conntrack_expect *exp);#define IRC_PORT 6667
include/linux/netfilter_ipv4/ip_conntrack_amanda.h +7 -7
@@ -2,11 +2,11 @@#define _IP_CONNTRACK_AMANDA_H/* AMANDA tracking. */ -struct ip_ct_amanda_expect -{ -u_int16_t port;/* port number of this expectation */ -u_int16_t offset;/* offset of port in ctrl packet */ -u_int16_t len;/* length of the port number string */ -}; - +struct ip_conntrack_expect ; +extern unsigned int (*ip_nat_amanda_hook)(struct sk_buff **pskb, +struct ip_conntrack *ct, +enum ip_conntrack_info ctinfo, +unsigned int matchoff, +unsigned int matchlen, +struct ip_conntrack_expect *exp);#endif /* _IP_CONNTRACK_AMANDA_H */
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman