Netfilter: Use ct_extend for helper pointer
Subsystems (2)
PATCH 5/8 Netfilter: Use ct_extend for helper pointer
Name: Use ct_extend for helper pointer
Status: Tested lightly under nfsim
Signed-off-by Rusty Russell <[email protected]>
Most connections don't have a connection tracking helper. So that pointer is a good candidate to put in ct_extend.
net/ipv4/netfilter/ip_nat_core.c +2 -1
@@ -283,7 +283,8 @@/* Alter conntrack table so will recognize replies. */ invert_tuplepr (&reply, &new_tuple); -ip_conntrack_alter_reply (conntrack, &reply); +if (ip_conntrack_alter_reply (conntrack, &reply) !=0 ) +return NF_DROP ;/* Non-atomic: we own this at the moment. */ if (maniptype ==IP_NAT_MANIP_SRC )
net/ipv4/netfilter/ip_conntrack_standalone.c +11 -5
@@ -385,11 +385,17 @@/* This is where we call the helper: as the packet goes out. */ ct =ip_conntrack_get (*pskb, &ctinfo); -if (ct && ct->helper) { -unsigned int ret; - ret = ct->helper->help (pskb, ct, ctinfo); -if (ret !=NF_ACCEPT ) -return ret; +if (ct) { +struct ip_conntrack_helper **helpp; + +/* Don't need lock: ct not in hash yet. */ + helpp =ct_extend_find (ct->ext,CTE_CT_HELPER ); +if (helpp) { +unsigned int ret; + ret = (*helpp)->help (pskb, ct, ctinfo); +if (ret !=NF_ACCEPT ) +return ret; + } }/* We've seen it coming out the other side: confirm it */
include/linux/netfilter_ipv4/ip_nat.h +0 -3
@@ -57,9 +57,6 @@ {struct list_head bysource; -/* Helper (NULL if none). */ -struct ip_nat_helper *helper; -struct ip_nat_seq seq[IP_CT_DIR_MAX ]; };
include/linux/netfilter_ipv4/ip_conntrack.h +2 -5
@@ -172,9 +172,6 @@/* Current number of expected connections */ unsigned int expecting; -/* Helper, if any. */ -struct ip_conntrack_helper *helper; -/* Storage reserved for other modules: */ union ip_conntrack_proto proto;
@@ -202,8 +199,8 @@/* get master conntrack via master expectation */ #define master_ct (conntr) (conntr->master) -/* Alter reply tuple (maybe alter helper). */ -extern void +/* Alter reply tuple (maybe alter helper). Returns 0 or -errno. */ +extern int ip_conntrack_alter_reply (struct ip_conntrack *conntrack,const struct ip_conntrack_tuple *newreply);
net/ipv4/netfilter/ipt_helper.c +7 -4
@@ -18,6 +18,7 @@#include <linux/netfilter_ipv4/ip_conntrack_helper.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv4/ipt_helper.h> +#include <linux/netfilter_ipv4/ct_extend.h> MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Martin Josefsson <[email protected]>" );
@@ -40,6 +41,7 @@const struct ipt_helper_info *info = matchinfo;struct ip_conntrack *ct;enum ip_conntrack_info ctinfo; +struct ip_conntrack_helper **helpp;int ret = info->invert; ct =ip_conntrack_get ((struct sk_buff *)skb, &ctinfo);
@@ -54,20 +56,21 @@ }READ_LOCK (&ip_conntrack_lock); -if (!ct->master->helper) { + helpp =ct_extend_find (ct->master->ext,CTE_CT_HELPER ); +if (!helpp) {DEBUGP ("ipt_helper: master ct %p has no helper\n" , exp->expectant); goto out_unlock; }DEBUGP ("master's name = %s , info->name = %s\n" , - ct->master->helper->name, info->name); + (*helpp)->name, info->name);if (info->name[0 ] =='\0' ) ret ^=1 ;else - ret ^= !strncmp (ct->master->helper->name, info->name, -strlen (ct->master->helper->name)); + ret ^= !strncmp ((*helpp)->name, info->name, +strlen ((*helpp)->name)); out_unlock:READ_UNLOCK (&ip_conntrack_lock);return ret;
include/linux/netfilter_ipv4/ct_extend.h +2 -0
@@ -7,12 +7,14 @@CTE_MASQ ,CTE_FTP_CONN ,CTE_MARK , +CTE_CT_HELPER ,CTE_MAX , } __attribute__((packed));#define CTE_MASQ_TYPE char/* Actually char[IFNAMSIZ] */ #define CTE_FTP_CONN_TYPE struct ip_ct_ftp_master#define CTE_MARK_TYPE unsigned long +#define CTE_CT_HELPER_TYPE struct ip_conntrack_helper */* Extensions: optional stuff which isn't permanently in struct. */ struct ct_extend {
net/ipv4/netfilter/ip_conntrack_core.c +69 -18
186 lines not on this page · raw message