Skip to contentSkip to conversation

newbie: writing custom target, need help with getting it to work

DISCUSSION Yossi Weihs 2 participants 7 messages Aug 8, 2010 – Aug 9, 2010 netfilter

lore
Share & tools
lore
#0 lore raw

Hi List,

I have been working on a custom netfilter target to help with some in-house testing. I’m running Fedora 13 and building within xtables-addons v 1.2.6 ; I have gotten both the kernel module and library to build correctly within the xtables-addons build enviroment, and am inserting the kernel module with no errors. When trying to create a rule with my target, I get the cryptic error:

iptables --verbose --table filter --insert INPUT --protocol TCP -m state --state ESTABLISHED --jump TAP --device TAPPY
TAP  tcp opt -- in * out *  0.0.0.0/0  -> 0.0.0.0/0  state ESTABLISHED TAP dev:TAPPY
iptables: No chain/target/match by that name.

I’m seeing dev:TAPPY, which I think means the user space library correctly parsed the parameters. Since I manually inserted the module, I know it’s there, although I did not see the module initialization kernel info message... Any ideas on where to look next? I have attached my target code.

Thanks!

Joseph "Yossi" Weihs, CTO

SeaFire Micros, Inc.
39 Dodge St, #319
Beverly, MA 01915

http://www.seafire.com
[email protected]
http://twitter.com/SeaFireMicros

****************************************************************************
*********************************************
This message is a PRIVATE communication. This message and all attachments are a private communication sent by SeaFire and may be confidential or protected by privilege. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the information contained in or attached to this message is strictly prohibited.  Please notify the sender of the delivery error by replying to this message, and then delete it from your system.  Thank you.
****************************************************************************
*********************************************

#1 lore raw
Quoted 9 lines · Yossi Weihs

Hi List,

I have been working on a custom netfilter target to help with some in-house testing. I?m running Fedora 13 and building within xtables-addons v 1.2.6 ; I have gotten both the kernel module and library to build correctly within the xtables-addons build enviroment, and am inserting the kernel module with no errors. When trying to create a rule with my target, I get the cryptic error:

Quoted 5 lines

iptables --verbose --table filter --insert INPUT --protocol TCP -m state --state ESTABLISHED --jump TAP --device TAPPY
TAP  tcp opt -- in * out *  0.0.0.0/0  -> 0.0.0.0/0  state ESTABLISHED TAP dev:TAPPY
iptables: No chain/target/match by that name.

When you want iptables to recognize (the user portion) of Xt-a's extra modules, you need to point to it via the XTABLES_LIBDIR environment variable.

XTABLES_LIBDIR=$HOME/xta/extensions:/usr/lib(64)/xtables iptables -S

Don't forget usr/lib/xtables otherwise it won't find the tcp match and all the ones that already ship with iptables.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to Yossi Weihs
Quoted 12 lines · Yossi Weihs

I?m seeing dev:TAPPY, which I think means the user space library correctly parsed the parameters. Since I manually inserted the module, I know it?s there, although I did not see the module initialization kernel info message... Any ideas on where to look next? I have attached my target code.

#include "compat_xtables.h"
#include "seabatch.h"
#include "xt_TAP.h"

static unsigned int
tap_tg4(struct sk_buff **pskb, const struct xt_target_param *par) {

...

Quoted 2 lines
	// Time to grab mutex
	if (down_interruptible(private_info->tap_filter[fidx].lock)) {

Your tap makes for water damage. You must not sleep in Xtables kernel code, that is, anythiing higher of a class than a spinlock_bh is a no-no.

Quoted 14 lines
		printk(KERN_CRIT "TAP down_interruptible %s %d\n",__FILE__,__LINE__);
		return XT_CONTINUE;
	}

	// snip some code removed
	
	// Fall out
	fallout:
	// Release Mutex
	up(private_info->tap_filter[fidx].lock);
	// done
	return XT_CONTINUE;
}
#2 lore raw
In reply to Jan Engelhardt

Thanks Jan!

I have added the env variable, but saw no change. My libxt_TAP.so is getting found as it is checking my parameter. I have tried a different xtables_addons target such as TEE, and the rule gets inserted fine. I had SELinux block my libxt_TAP.so and had added it to the SELinux rules, so that shouldn't be a problem. Any other idea what might be going on? I know my module is calling xt_register_targets(), is there a way for me to check the contents of its tables?

Thanks for looking at my code! I'll switch my mutex to a spinlock - I'd be wasting a lot of time once I get running with this without your help.

Yossi Weihs

-----Original Message-----
From: Jan Engelhardt [mailto:[email protected]]
Sent: Sunday, August 08, 2010 4:29 PM
To: Yossi Weihs
Cc: [email protected]
Subject: Re: newbie: writing custom target, need help with getting it to work

Quoted 9 lines · Yossi Weihs

Hi List,

I have been working on a custom netfilter target to help with some in-house testing. I?m running Fedora 13 and building within xtables-addons v 1.2.6 ; I have gotten both the kernel module and library to build correctly within the xtables-addons build enviroment, and am inserting the kernel module with no errors. When trying to create a rule with my target, I get the cryptic error:

Quoted 5 lines

iptables --verbose --table filter --insert INPUT --protocol TCP -m state --state ESTABLISHED --jump TAP --device TAPPY
TAP tcp opt -- in * out * 0.0.0.0/0 -> 0.0.0.0/0 state ESTABLISHED TAP dev:TAPPY
iptables: No chain/target/match by that name.

When you want iptables to recognize (the user portion) of Xt-a's extra modules, you need to point to it via the XTABLES_LIBDIR environment variable.

XTABLES_LIBDIR=$HOME/xta/extensions:/usr/lib(64)/xtables iptables -S

Don't forget usr/lib/xtables otherwise it won't find the tcp match and all the ones that already ship with iptables.

#3 lore raw
Quoted 1 line · Yossi Weihs

I have added the env variable, but saw no change.

Make sure that xt_TAP.ko is then actually loaded.

Quoted 2 lines

going on? I know my module is calling xt_register_targets(), is there a way for me to check the contents of its tables?

iptables -vvL

should print the semi-raw dump of the table before trying to resolve targets.

#4 lore raw

OK - xt_TAP.ko is not getting loaded by iptables. I can modprobe it manually, but iptables won't load it. Trying telling iptables which modprobe to use, but no luck. xt_TEE.ko is getting loaded fine, and I cloned my module off it ... I feel we're getting close.

-YW

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jan Engelhardt
Sent: Sunday, August 08, 2010 5:13 PM
To: Yossi Weihs
Cc: [email protected]
Subject: RE: newbie: writing custom target, need help with getting it to work

Quoted 1 line · Yossi Weihs

I have added the env variable, but saw no change.

Make sure that xt_TAP.ko is then actually loaded.

Quoted 2 lines

going on? I know my module is calling xt_register_targets(), is there a way for me to check the contents of its tables?

iptables -vvL

should print the semi-raw dump of the table before trying to resolve targets.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 4 lines · Yossi Weihs

OK - xt_TAP.ko is not getting loaded by iptables. I can modprobe it manually, but iptables won't load it. Trying telling iptables which modprobe to use, but no luck. xt_TEE.ko is getting loaded fine, and I cloned my module off it ... I feel we're getting close.

iptables just calls modprobe. And modprobe only looks in /lib/modules.