Skip to contentSkip to conversation

easy questions about matches implementation

DISCUSSION Juan Torres 2 participants 2 messages Jun 4, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

Hello, maybe it's a very easy question, but I'm studying the
match ipt_multiport.c and I don't understand one thing:

Why, in the last lines, it registers the match with
ipt_register_match (&multiport_match) and, in the next line, it unregisters the match with ipt_unregister_match (&multiport_match)? How it works?

Is it because we only register when we read a rule that uses the
multiport module, and just after we unregister again the match?

What is the function of the last line MODULE_LINE ("GPL");?

Where can I find more information about these questions? (I have
read the Netfilter Hacking HOWTO)

Thank you very much for your help

Now I write the last lines of the file ipt_multiport.c:

static struct ipt_match multiport_match
= { { NULL, NULL }, "multiport", &match, &checkentry, NULL,

THIS_MODULE };
       
       static int __init init(void)
       {
       	return ipt_register_match(&multiport_match);
       }
       
       static void __exit fini(void)
       {
       	ipt_unregister_match(&multiport_match);
       }
       
       module_init(init);
       module_exit(fini);
       MODULE_LICENSE("GPL");
#1 lore raw
Quoted 26 lines · Juan Torres

Hello, maybe it's a very easy question, but I'm studying the
match ipt_multiport.c and I don't understand one thing:

Why, in the last lines, it registers the match with
ipt_register_match (&multiport_match) and, in the next line, it unregisters the match with ipt_unregister_match (&multiport_match)? How it works?

Is it because we only register when we read a rule that uses the
multiport module, and just after we unregister again the match?

What is the function of the last line MODULE_LINE ("GPL");?

Where can I find more information about these questions? (I have
read the Netfilter Hacking HOWTO)

Thank you very much for your help

Now I write the last lines of the file ipt_multiport.c:

static struct ipt_match multiport_match
= { { NULL, NULL }, "multiport", &match, &checkentry, NULL,

Quoted 19 lines
THIS_MODULE };
      
      static int __init init(void)
      {
      	return ipt_register_match(&multiport_match);
      }
      
      static void __exit fini(void)
      {
      	ipt_unregister_match(&multiport_match);
      }
      
      module_init(init);
      module_exit(fini);
      MODULE_LICENSE("GPL");

Read the Kernel Module Programming Guide.

When you load the module the function init is called (or another function you specify with module_init(some_function_name); ). In this function you register your match with iptables by calling ipt_register_match(); . When you unload the module the function fini is called (or another function you specify with module_exit(some_function_name); ). In this function you unregister your match with iptables by calling ipt_unregister_match(); .

MODULE_LICENSE("GPL"); is a macro wich sets the module license, GPL in this case.

Regards,
Tim

PS: I'm not a kernel guru so correct me if I'm wrong.