Skip to contentSkip to conversation

netfilter kernel modules question

DISCUSSION Tobias Koeck 2 participants 6 messages Dec 14, 2009 netfilter

lore
Share & tools
lore
#0 lore raw

I have two netfilter kernel modules (xt_RQS.c, xt_RQD.c, both include a header file with a data structure in it).

Does both kernel modules use the same datastructures or do they use seperate ones (in normal C programming I know that but I'm not sure about the kernel scopes).

If I want to use one datastructure how can I do that (export? - concurrency issues left aside)?

Greetings and thanks

#1 lore raw
Quoted 6 lines · Tobias Koeck

I have two netfilter kernel modules (xt_RQS.c, xt_RQD.c, both include a header file with a data structure in it).

Does both kernel modules use the same datastructures or do they use seperate ones (in normal C programming I know that but I'm not sure about the kernel scopes).

You decide whether they do. This does not change just because you are in kernel space.

Jan

#2 lore raw
Quoted 11 lines · Jan Engelhardt
Quoted 6 lines · Tobias Koeck

I have two netfilter kernel modules (xt_RQS.c, xt_RQD.c, both include a header file with a data structure in it).

Does both kernel modules use the same datastructures or do they use seperate ones (in normal C programming I know that but I'm not sure about the kernel scopes).

You decide whether they do. This does not change just because you are in kernel space.

Can you please give a short example how to to it?

Let's say you've got one data structure (int a) in the header file. How can you access it in both c-files? Do you have to export it?

Is there a deeper information how the kernel scope is structured?

#3 lore raw
Quoted 8 lines · Tobias Koeck
Quoted 8 lines
Quoted 7 lines

I have two netfilter kernel modules (xt_RQS.c, xt_RQD.c, both include a header
file with a data structure in it).

Does both kernel modules use the same datastructures or do they use seperate ones (in normal C programming I know that but I'm not sure about the kernel scopes).

Quoted 7 lines
Quoted 2 lines

You decide whether they do. This does not change just because you are in kernel space.

Can you please give a short example how to to it?

Let's say you've got one data structure (int a) in the header file. How can you access it in both c-files? Do you have to export it?

You can argue what a data structure is or what it is not; a header file should not include any definitions, only declarations. (And perhaps static-inlines, but that's probably too expert for you at this stage.) Various C-related forums or IRC channels can enlighten you towards the reasoning for that.

#4 lore raw
Quoted 6 lines

You can argue what a data structure is or what it is not; a header file should not include any definitions, only declarations. (And perhaps static-inlines, but that's probably too expert for you at this stage.) Various C-related forums or IRC channels can enlighten you towards the reasoning for that.

'int a' is declaration (only used in a function it's a definition).

Does that mean if I define a (nonstatic) variable in a kernel module and it's accessible in the whole kernel?

Don't worry - last kernel newbie question from myself ;=).

Greetings
tk

#5 lore raw
Quoted 8 lines · Tobias Koeck
Quoted 6 lines

You can argue what a data structure is or what it is not; a header file should not include any definitions, only declarations. (And perhaps static-inlines, but that's probably too expert for you at this stage.) Various C-related forums or IRC channels can enlighten you towards the reasoning for that.

'int a' is declaration (only used in a function it's a definition).

"int a" is always a definition. Inside a function it makes for an automatic variable, and outside a function it makes for one with static linkage.