Mailing List Archive

conntrack module development problem
Hi!

I'm trying to make a new conntrack module, but it doesn't seem to be
receiving packets that I've set the tuple for. See code below.

As you can see, at this point it's very similar to the sample code in the
netfilter howtos, and it compiles cleanly. I've included the compile
options specified at the end of the source. It's not supposed to do
anything useful yet, just print debug messages.

It should printk an "ICQ packet received" whenever an icq packet goes by,
but it doesn't. It does print the "I'm in!" and "I'm out!" printk's at
module load and release, though.

What am I missing here? Any assistance would be greatly appreciated.

Cheers,
Scott <sshore@escape.ca>



#include <linux/version.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/ip.h>
#include <linux/ctype.h>
#include <net/checksum.h>
#include <net/udp.h>
#include <linux/netfilter_ipv4/ip_conntrack_helper.h>

#define ICQ_PORT 4000
#define DEBUGP(format, args...) printk(KERN_DEBUG __FILE__ ":" __FUNCTION__ \
":" format, ## args)

static int icq_help(const struct iphdr *iph, size_t len,
struct ip_conntrack *ct,
enum ip_conntrack_info ct_info)
{
DEBUGP("ICQ packet received\n");

return NF_ACCEPT;
}

static struct ip_conntrack_helper icq;

static int __init init(void)
{
memset(&icq, 0, sizeof(struct ip_conntrack_helper));

icq.tuple.dst.protonum = IPPROTO_UDP;
icq.tuple.dst.u.udp.port = htons(ICQ_PORT);
icq.mask.dst.protonum = 0xFFFF;
icq.mask.dst.u.udp.port = 0xFFFF;
icq.help = icq_help;

DEBUGP("I'm in!\n");

return ip_conntrack_helper_register(&icq);
}

static void __exit fini(void)
{
DEBUGP("I'm out!\n");
ip_conntrack_helper_unregister(&icq);
}

module_init(init);
module_exit(fini);

/* gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2
-fomit-frame-pointer -fno-strict-aliasing -pipe -march=i486 -DMODULE -c -o
test.o test.c */
Re: conntrack module development problem [ In reply to ]
Mr. Shore,

Change the helper init function to read like this:

int ret;

/* rest of function */

ret = ip_conntrack_helper_register(&icq);
if (ret < 0) {
DEBUGP("KABOOM! Aiee, I'm not in!\n"); ;-)
return ret;
}
DEBUGP("Ahhh, I'm in at last\n"); ;-)

Maybe you have bugs initializing the helper; this will detect that. If it
works, then you initialized it incorrectly in some fashion. BTW will
this actually
become a `real' conntrack helper for ICQ? IIRC, no one else has worked
on it.....

Brad

S. Shore wrote:

> Hi!
>
> I'm trying to make a new conntrack module, but it doesn't seem to be
> receiving packets that I've set the tuple for. See code below.
>
> As you can see, at this point it's very similar to the sample code in the
> netfilter howtos, and it compiles cleanly. I've included the compile
> options specified at the end of the source. It's not supposed to do
> anything useful yet, just print debug messages.
>
> It should printk an "ICQ packet received" whenever an icq packet goes by,
> but it doesn't. It does print the "I'm in!" and "I'm out!" printk's at
> module load and release, though.
>
> What am I missing here? Any assistance would be greatly appreciated.
>
> Cheers,
> Scott <sshore@escape.ca>
>
>
>
> #include <linux/version.h>
> #include <linux/module.h>
> #include <linux/netfilter.h>
> #include <linux/ip.h>
> #include <linux/ctype.h>
> #include <net/checksum.h>
> #include <net/udp.h>
> #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
>
> #define ICQ_PORT 4000
> #define DEBUGP(format, args...) printk(KERN_DEBUG __FILE__ ":" __FUNCTION__ \
> ":" format, ## args)
>
> static int icq_help(const struct iphdr *iph, size_t len,
> struct ip_conntrack *ct,
> enum ip_conntrack_info ct_info)
> {
> DEBUGP("ICQ packet received\n");
>
> return NF_ACCEPT;
> }
>
> static struct ip_conntrack_helper icq;
>
> static int __init init(void)
> {
> memset(&icq, 0, sizeof(struct ip_conntrack_helper));
>
> icq.tuple.dst.protonum = IPPROTO_UDP;
> icq.tuple.dst.u.udp.port = htons(ICQ_PORT);
> icq.mask.dst.protonum = 0xFFFF;
> icq.mask.dst.u.udp.port = 0xFFFF;
> icq.help = icq_help;
>
> DEBUGP("I'm in!\n");
>
> return ip_conntrack_helper_register(&icq);
> }
>
> static void __exit fini(void)
> {
> DEBUGP("I'm out!\n");
> ip_conntrack_helper_unregister(&icq);
> }
>
> module_init(init);
> module_exit(fini);
>
> /* gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2
> -fomit-frame-pointer -fno-strict-aliasing -pipe -march=i486 -DMODULE -c -o
> test.o test.c */
>
>
>
>
Re: conntrack module development problem [ In reply to ]
On Sat, 28 Jul 2001, Brad Chapman wrote:

> ret = ip_conntrack_helper_register(&icq);
> if (ret < 0) {
> DEBUGP("KABOOM! Aiee, I'm not in!\n"); ;-)
> return ret;
> }
> DEBUGP("Ahhh, I'm in at last\n"); ;-)

I tried your suggestion, but I get the same effect.
ip_conntrack_helper_register returns a 0, no error.

Actually, the existing code would have done the same, as it returns with
the return code from ip_conntrack_helper_register.

I'm open to any other suggestions.

Scott <sshore@escape.ca>
Re: conntrack module development problem [ In reply to ]
On Fri, Jul 27, 2001 at 11:04:00PM -0500, S. Shore wrote:
> Hi!
>

hi!

first of all: please send development questions to the development mailinglist.
Lots of developers don't even read the user mailinglist, so you have a higher
chance of receiving an answer fast if you post development questions there.

> I'm trying to make a new conntrack module, but it doesn't seem to be
> receiving packets that I've set the tuple for. See code below.

strange, really strange. I can't see anything wrong in that code
(apart from the error checking, but as you pointed out in a later mail
this didn't show any difference).

There are lots of existing helpers (also for UDP based protocols like talk),
and they don't do anything else.

Are you sure that your box is really receiving the UDP packets on port
4000 ?

> Cheers,
> Scott <sshore@escape.ca>

--
Live long and prosper
- Harald Welte / laforge@gnumonks.org http://www.gnumonks.org
============================================================================
GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M-
V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)