Skip to contentSkip to conversation

Brute force printk routines for looking at netfilter structures

DISCUSSION Ranjeet Shetye 2 participants 4 messages Dec 17, 2002 – Dec 18, 2002 netfilter

lore
Share & tools
lore
#0 lore raw

I was trying to understand how the various data values were being transferred within the connection tracking and the nat modules. Unfortunately, I dont have the brains of Einstein so I went for the brute force method.

I slit open Netfilter's guts and printk'd the whole damn thing out. Its gross, its not kernel-style or systems-style coding, but hey it let me figure out what was happening inside the netfilter mechanism. I wrote my own stuff instead of using the builtin print mechanisms cos I want to see and understand EVERY variable, every pointer, every data value, EVERYTHING!

Within one day, I have gained more confidence. Now you can too!!!! The Amazing nf_debug.c method by the Kernel Professor. :D (legal disclaimer:
Results not typical of regular users.)

The kernel works really slowly with all the printks, like its stuck in molasses. Since I am working with multiple kernel trees, I've put the original copy in my home directory, and linked to it in the netfilter dirs of every kernel I am interested in. Modify Makefile to add nf_debug.o to the list of nat objects, run make dep, make bzimage, and you should be set to observe a very slow kernel.

The way to use this file is to use it VERY sparingly, and you should trigger the debug code using a SINGLE packet. YOU HAVE BEEN WARNED!

I am still adding some routines and will post a complete copy once I am done.

Thanks,
Ranjeet Shetye
Senior Software Engineer
Zultys Technologies
771 Vaqueros Avenue
Sunnyvale CA 94085
USA
[email protected]
http://www.zultys.com/

#1 lore raw

Hello "Kernel Professor" :-)

some quick and dirty comments, after cursory reading of nf_debug.c:

Quoted 1 line

signed int nf_debug_indent = 0;

Why signed? Anyway, this will fall on its face on SMP systems.
Cure: use atomic_t.

I bet you can speed up your NF_DPF macro a lot. Try this:

#define NF_DPF(format, args...) \

{ \
	printk( \
		"%s() at %s:%d " \
		"%.*s" \
		format , \
		__FUNCTION__, __FILE__, __LINE__, \
		nf_debug_indent, "\t", \
		##args ); \
}

(Lightly tested; note that with that macro 'format' has to be a string constant)

best regards
Patrick

#2 lore raw
Quoted 4 lines
Quoted 1 line

signed int nf_debug_indent = 0;

Why signed? Anyway, this will fall on its face on SMP systems.
Cure: use atomic_t.

Ahem. Given the application, a per-cpu nf_debug_indent would be the proper cure, together with preventing preemption whenever nf_debug_indent is above 0. You can then also printk the CPU number along with the rest :-)

best regards
Patrick

#3 lore raw

nf_debug.c version 0.2

This code is more complete and works well enough for me. Let me know if you run into any problems.

If the interconnection complexity of the various NAT structs intimidates you, this code should help clear up the internal organization. As before, use it absolutely SPARINGLY.

Thanks to everyone for pointing out mistakes / corrections / improvements and helping me.

Ranjeet Shetye
Senior Software Engineer
Zultys Technologies
771 Vaqueros Avenue
Sunnyvale CA 94085
USA
[email protected]
http://www.zultys.com/