2 * iptables module to match on related connections
3 * (c) 2001 Martin Josefsson <gandalf@wlug.westbo.se>
5 * Released under the terms of GNU GPLv2.
7 * 19 Mar 2002 Harald Welte <laforge@gnumonks.org>:
8 * - Port to newnat infrastructure
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/netfilter_ipv4/ip_conntrack.h>
13 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
14 #include <linux/netfilter_ipv4/ip_tables.h>
15 #include <linux/netfilter_ipv4/ipt_helper.h>
17 MODULE_LICENSE("GPL");
19 #define DEBUGP(format, args...)
22 match(const struct sk_buff
*skb
,
23 const struct net_device
*in
,
24 const struct net_device
*out
,
25 const void *matchinfo
,
31 const struct ipt_helper_info
*info
= matchinfo
;
32 struct ip_conntrack_expect
*exp
;
33 struct ip_conntrack
*ct
;
34 enum ip_conntrack_info ctinfo
;
36 ct
= ip_conntrack_get((struct sk_buff
*)skb
, &ctinfo
);
38 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
43 DEBUGP("ipt_helper: conntrack %p has no master\n", ct
);
48 if (!exp
->expectant
) {
49 DEBUGP("ipt_helper: expectation %p without expectant !?!\n",
54 if (!exp
->expectant
->helper
) {
55 DEBUGP("ipt_helper: master ct %p has no helper\n",
60 DEBUGP("master's name = %s , info->name = %s\n",
61 exp
->expectant
->helper
->name
, info
->name
);
63 return !strncmp(exp
->expectant
->helper
->name
, info
->name
,
64 strlen(exp
->expectant
->helper
->name
)) ^ info
->invert
;
67 static int check(const char *tablename
,
68 const struct ipt_ip
*ip
,
70 unsigned int matchsize
,
71 unsigned int hook_mask
)
73 struct ipt_helper_info
*info
= matchinfo
;
75 info
->name
[29] = '\0';
78 if (matchsize
!= IPT_ALIGN(sizeof(struct ipt_helper_info
)))
81 /* verify that we actually should match anything */
82 if ( strlen(info
->name
) == 0 )
88 static struct ipt_match helper_match
89 = { { NULL
, NULL
}, "helper", &match
, &check
, NULL
, THIS_MODULE
};
91 static int __init
init(void)
93 /* NULL if ip_conntrack not a module */
94 if (ip_conntrack_module
)
95 __MOD_INC_USE_COUNT(ip_conntrack_module
);
96 return ipt_register_match(&helper_match
);
99 static void __exit
fini(void)
101 ipt_unregister_match(&helper_match
);
102 if (ip_conntrack_module
)
103 __MOD_DEC_USE_COUNT(ip_conntrack_module
);