From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Bogdan DUMITRIU" Subject: can't compile simple netfilter hook Date: Sat, 26 Oct 2002 12:03:02 +0300 Sender: netfilter-admin@lists.netfilter.org Message-ID: <000801c27cce$7e4d5660$0100a8c0@blackwizard> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0005_01C27CE7.A2754840" Return-path: Errors-To: netfilter-admin@lists.netfilter.org List-Help: List-Post: List-Subscribe: , List-Id: List-Unsubscribe: , List-Archive: To: netfilter@lists.netfilter.org This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C27CE7.A2754840 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have tried to compile the following netfilter hook (found in one of = the documents listed in the documentation area at www.netfilter.org) and = I just can't make it. Here's how I tried to compile it: gcc -c -I/lib/modules/`uname -r`/build/include ./netmod.c -Wall Here's the error I got: In file included from ./netfmod.c:4: /lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h:53: = `INT_MIN' undeclared here (not in a function) /lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h:53: = enumerator value for `NF_IP_PRI_FIRST' not integer constant /lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h:59: = `INT_MAX' undeclared here (not in a function) /lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h:59: = enumerator value for `NF_IP_PRI_LAST' not integer constant ./netfmod.c:12: warning: `struct net_device' declared inside parameter = list ./netfmod.c:12: warning: its scope is only this definition or = declaration, which is probably not what you want. ./netfmod.c:12: warning: `struct sk_buff' declared inside parameter list ./netfmod.c: In function `stupid_hook': ./netfmod.c:14: dereferencing pointer to incomplete type ./netfmod.c: At top level: ./netfmod.c:21: variable `stupid_ops' has initializer but incomplete = type ./netfmod.c:21: extra brace group at end of initializer ./netfmod.c:21: (near initialization for `stupid_ops') ./netfmod.c:21: `NULL' undeclared here (not in a function) ./netfmod.c:21: `NULL' undeclared here (not in a function) ./netfmod.c:21: warning: excess elements in struct initializer ./netfmod.c:21: warning: (near initialization for `stupid_ops') ./netfmod.c:21: warning: excess elements in struct initializer ./netfmod.c:21: warning: (near initialization for `stupid_ops') ./netfmod.c:21: `PF_INET' undeclared here (not in a function) ./netfmod.c:21: warning: excess elements in struct initializer ./netfmod.c:21: warning: (near initialization for `stupid_ops') ./netfmod.c:21: warning: excess elements in struct initializer ./netfmod.c:21: warning: (near initialization for `stupid_ops') ./netfmod.c:21: warning: excess elements in struct initializer ./netfmod.c:21: warning: (near initialization for `stupid_ops') ./netfmod.c:23: parse error before `init' ./netfmod.c:24: warning: return-type defaults to `int' ./netfmod.c: In function `init': ./netfmod.c:25: warning: implicit declaration of function = `nf_register_hook' ./netfmod.c: At top level: ./netfmod.c:28: parse error before `fini' ./netfmod.c:29: warning: return-type defaults to `int' ./netfmod.c: In function `fini': ./netfmod.c:30: warning: implicit declaration of function = `nf_unregister_hook' ./netfmod.c:30: `linuxmag_ops' undeclared (first use in this function) ./netfmod.c:30: (Each undeclared identifier is reported only once ./netfmod.c:30: for each function it appears in.) ./netfmod.c:31: warning: control reaches end of non-void function ./netfmod.c: At top level: ./netfmod.c:33: warning: type defaults to `int' in declaration of = `module_init' ./netfmod.c:33: warning: parameter names (without types) in function = declaration ./netfmod.c:33: warning: data definition has no type or storage class ./netfmod.c:34: warning: type defaults to `int' in declaration of = `module_exit' ./netfmod.c:34: warning: parameter names (without types) in function = declaration ./netfmod.c:34: warning: data definition has no type or storage class=20 Here is the code in netmod.c: /* Rusty's Dumb netfilter hook example */ #include #include #include #include /* The work comes in here from netfilter.c. */ static unsigned int stupid_hook(unsigned int hook, struct sk_buff **pskb, const struct net_device *indev, const struct net_device *outdev, int (*okfn)(struct sk_buff *)) { if ((*pskb)->len =3D=3D 200) return NF_DROP; return NF_ACCEPT; } static struct nf_hook_ops stupid_ops =3D { { NULL, NULL }, stupid_hook, PF_INET, NF_IP_POST_ROUTING, 0 }; static int __init init(void) { return nf_register_hook(&stupid_ops); } static void __exit fini(void) { nf_unregister_hook(&linuxmag_ops); } module_init(init); module_exit(fini); I run a SuSE 8.0 Linux, kernel version 2.4.18, gcc version 2.95.3. Please help with this as I need it for a school project and I can't get = to actually doing what I have to do because I just can't make this work. Thanks. Bogdan. ------=_NextPart_000_0005_01C27CE7.A2754840 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I have tried to compile the following = netfilter=20 hook (found in one of the documents listed in the documentation area at = www.netfilter.org) and I just = can't make=20 it.
 
Here's how I tried to compile = it:
 
gcc -c -I/lib/modules/`uname = -r`/build/include=20 ./netmod.c -Wall
 
Here's the error I got:
 
In file included from=20 ./netfmod.c:4:
/lib/modules/2.4.18-4GB/build/include/linux/netfilter_i= pv4.h:53:=20 `INT_MIN' undeclared here (not in a=20 function)
/lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h= :53:=20 enumerator value for `NF_IP_PRI_FIRST' not integer=20 constant
/lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h:= 59:=20 `INT_MAX' undeclared here (not in a=20 function)
/lib/modules/2.4.18-4GB/build/include/linux/netfilter_ipv4.h= :59:=20 enumerator value for `NF_IP_PRI_LAST' not integer = constant
./netfmod.c:12:=20 warning: `struct net_device' declared inside parameter = list
./netfmod.c:12:=20 warning: its scope is only this definition or declaration, which is = probably not=20 what you want.
./netfmod.c:12: warning: `struct sk_buff' declared = inside=20 parameter list
./netfmod.c: In function = `stupid_hook':
./netfmod.c:14:=20 dereferencing pointer to incomplete type
./netfmod.c: At top=20 level:
./netfmod.c:21: variable `stupid_ops' has initializer but = incomplete=20 type
./netfmod.c:21: extra brace group at end of=20 initializer
./netfmod.c:21: (near initialization for=20 `stupid_ops')
./netfmod.c:21: `NULL' undeclared here (not in a=20 function)
./netfmod.c:21: `NULL' undeclared here (not in a=20 function)
./netfmod.c:21: warning: excess elements in struct=20 initializer
./netfmod.c:21: warning: (near initialization for=20 `stupid_ops')
./netfmod.c:21: warning: excess elements in struct=20 initializer
./netfmod.c:21: warning: (near initialization for=20 `stupid_ops')
./netfmod.c:21: `PF_INET' undeclared here (not in a=20 function)
./netfmod.c:21: warning: excess elements in struct=20 initializer
./netfmod.c:21: warning: (near initialization for=20 `stupid_ops')
./netfmod.c:21: warning: excess elements in struct=20 initializer
./netfmod.c:21: warning: (near initialization for=20 `stupid_ops')
./netfmod.c:21: warning: excess elements in struct=20 initializer
./netfmod.c:21: warning: (near initialization for=20 `stupid_ops')
./netfmod.c:23: parse error before = `init'
./netfmod.c:24:=20 warning: return-type defaults to `int'
./netfmod.c: In function=20 `init':
./netfmod.c:25: warning: implicit declaration of function=20 `nf_register_hook'
./netfmod.c: At top level:
./netfmod.c:28: = parse error=20 before `fini'
./netfmod.c:29: warning: return-type defaults to=20 `int'
./netfmod.c: In function `fini':
./netfmod.c:30: warning: = implicit=20 declaration of function `nf_unregister_hook'
./netfmod.c:30: = `linuxmag_ops'=20 undeclared (first use in this function)
./netfmod.c:30: (Each = undeclared=20 identifier is reported only once
./netfmod.c:30: for each function it = appears=20 in.)
./netfmod.c:31: warning: control reaches end of non-void=20 function
./netfmod.c: At top level:
./netfmod.c:33: warning: type = defaults=20 to `int' in declaration of `module_init'
./netfmod.c:33: warning: = parameter=20 names (without types) in function declaration
./netfmod.c:33: = warning: data=20 definition has no type or storage class
./netfmod.c:34: warning: type = defaults to `int' in declaration of `module_exit'
./netfmod.c:34: = warning:=20 parameter names (without types) in function = declaration
./netfmod.c:34:=20 warning: data definition has no type or storage class
 
Here is the code in = netmod.c:
 
/* Rusty's Dumb netfilter hook example */
#include=20 <linux/config.h>
#include <linux/module.h>
#include=20 <linux/netfilter_ipv4.h>
#include <linux/ip.h>

/* = The work=20 comes in here from netfilter.c. */
static unsigned=20 int
stupid_hook(unsigned int=20 hook,
           = struct=20 sk_buff = **pskb,
          =20 const struct net_device=20 *indev,
           = const=20 struct net_device=20 *outdev,
           = int=20 (*okfn)(struct sk_buff *))
{
       = if=20 ((*pskb)->len =3D=3D=20 200)
           = ;   =20 return NF_DROP;

       return=20 NF_ACCEPT;
}

static struct nf_hook_ops stupid_ops
=3D { { = NULL, NULL=20 }, stupid_hook, PF_INET, NF_IP_POST_ROUTING, 0 };

static int = __init=20 init(void)
{
        return=20 nf_register_hook(&stupid_ops);
}

static void __exit=20 fini(void)
{
       =20 nf_unregister_hook(&linuxmag_ops);
}

module_init(init);
= module_exit(fini);
 
I run a SuSE 8.0 Linux, kernel version = 2.4.18, gcc=20 version 2.95.3.
 
Please help with this as I need it for = a school=20 project and I can't get to actually doing what I have to do because I = just can't=20 make this work.
 
Thanks.
Bogdan.
------=_NextPart_000_0005_01C27CE7.A2754840--