Linux Packet dropper -



Hi

I m trying a packet dropper program(KERNEL MODULE) in Linux 2.4 (I got
this from a site),

I m getting some unusal erros in the Linux Header files itself.

please help me in solving the erros.

The code goes like this:



/* packet_dropper.c
*
* This program provides an example of how to install a module into a
* slightly modified kernel that will randomly drop packets for a
specific
* (hard-coded) host.
* See linux/drivers/char/random.c for details of get_random_bytes().
* Usage (must be root to use):
* /sbin/insmod packet_dropper
* /sbin/rmmod packet_dropper
*/

#define MODULE
#define MAX_UNSIGNED_SHORT 65535

#include <linux/module.h>
#include <linux/skbuff.h> /* for struct sk_buff */
#include <linux/ip.h> /* for struct iphdr */

extern int (*test_function)(struct sk_buff *); /* calling
function */
extern void get_random_bytes(void *buf, int nbytes); /* random function
*/
unsigned short cutoff; /* drop cutoff */
float rate = 0.050; /* drop percentage
*/
__u32 target = 0x220010AC; /* 172.16.0.34 */

/************************************************************
packet_dropper
* this is what dev_queue_xmit will call while this module is installed
*/
int packet_dropper(struct sk_buff *skb) {
unsigned short t;
if (skb->nh.iph->daddr == target) {
get_random_bytes(&t,2);
if (t <= cutoff) return 1; /* drop this packet */
}
return 0; /* continue with normal routine */
} /* packet_dropper */

/***************************************************************
init_module
* this function replaces the null pointer with a real one */
int init_module() {
EXPORT_NO_SYMBOLS;
cutoff = rate * MAX_UNSIGNED_SHORT;
test_function = packet_dropper;
printk("<1> packet_dropper: now dropping packets\n");
return 0;
} /* init_module */

/************************************************************
cleanup_module
* this function resets the function pointer back to null */
void cleanup_module() {
test_function = 0;
printk("<1> packet_dropper: uninstalled\n");
} /* cleanup_module */




i m compiling it like this
gcc -D __KERNEL__ -D MODULE -O2 -Wall -Isystem/lib/modules/'uname
-r'/build/include -o packet_dropper.o -c packet_dropper.c
(there is no problem with the flags ..i checked it with a sample module
...its working fine)


STRANGE ERROS THAT I GOT:

[ROOT@LOCALHOST] #gcc -D __KERNEL__ -D MODULE -O2 -Wall
-Isystem/lib/modules/'uname -r'/build/include -o packet_dropper.o -c
packet_dropper.c
packet_dropper.c:14:1: warning: "MODULE" redefined
packet_dropper.c:1:1: warning: this is the location of the previous
definition
In file included from /usr/include/linux/fs.h:23,
from /usr/include/linux/capability.h:17,
from /usr/include/linux/binfmts.h:5,
from /usr/include/linux/sched.h:9,
from /usr/include/linux/skbuff.h:19,
from packet_dropper.c:18:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header
in userland!
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/skbuff.h:19,
from packet_dropper.c:18:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from /usr/include/linux/skbuff.h:19,
from packet_dropper.c:18:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is
not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers
in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/skbuff.h:19,
from packet_dropper.c:18:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
from /usr/include/linux/skbuff.h:19,
from packet_dropper.c:18:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete
type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete
type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete
type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete
type
In file included from /usr/include/linux/highmem.h:5,
from /usr/include/linux/skbuff.h:26,
from packet_dropper.c:18:
/usr/include/asm/pgalloc.h:6:24: asm/fixmap.h: No such file or
directory
In file included from /usr/include/linux/highmem.h:5,
from /usr/include/linux/skbuff.h:26,
from packet_dropper.c:18:
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:57: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `get_pgd_slow':
/usr/include/asm/pgalloc.h:59: `pgd_t' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:59: (Each undeclared identifier is reported
only once
/usr/include/asm/pgalloc.h:59: for each function it appears in.)
/usr/include/asm/pgalloc.h:59: `pgd' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:59: parse error before ')' token
/usr/include/asm/pgalloc.h:62: `USER_PTRS_PER_PGD' undeclared (first
use in this function)
/usr/include/asm/pgalloc.h:63: `swapper_pg_dir' undeclared (first use
in this function)
/usr/include/asm/pgalloc.h:63: `PTRS_PER_PGD' undeclared (first use in
this function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:70: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `get_pgd_fast':
/usr/include/asm/pgalloc.h:80: `pgd_t' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:80: parse error before ')' token
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:83: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `free_pgd_fast':
/usr/include/asm/pgalloc.h:85: `pgd' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:90: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `free_pgd_slow':
/usr/include/asm/pgalloc.h:99: `pgd' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:103: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_alloc_one':
/usr/include/asm/pgalloc.h:105: `pte_t' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:105: `pte' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:109: parse error before ')' token
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:118: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_alloc_one_fast':
/usr/include/asm/pgalloc.h:127: `pte_t' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:127: parse error before ')' token
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:130: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_free_fast':
/usr/include/asm/pgalloc.h:132: `pte' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:137: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_free_slow':
/usr/include/asm/pgalloc.h:139: `pte' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h: In function `flush_tlb_mm':
/usr/include/asm/pgalloc.h:183: `current' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h: In function `flush_tlb_page':
/usr/include/asm/pgalloc.h:190: dereferencing pointer to incomplete
type
/usr/include/asm/pgalloc.h:190: `current' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h: In function `flush_tlb_range':
/usr/include/asm/pgalloc.h:197: `current' undeclared (first use in this
function)
In file included from packet_dropper.c:18:
/usr/include/linux/skbuff.h: At top level:
/usr/include/linux/skbuff.h:100: parse error before "spinlock_t"
/usr/include/linux/skbuff.h:120: parse error before "atomic_t"
/usr/include/linux/skbuff.h:124: parse error before '}' token
/usr/include/linux/skbuff.h:183: parse error before "atomic_t"
/usr/include/linux/skbuff.h:215: parse error before '}' token
packet_dropper.c: In function `packet_dropper':
packet_dropper.c:31: dereferencing pointer to incomplete type
packet_dropper.c: In function `init_module':
packet_dropper.c:44: warning: implicit declaration of function `printk'

I have given all the relevant info.
if you need any other info. do infom me.

Any help is appreciated.

Thanks,
SaranJothy.
Saranjothy (at) gmail (dot) com

.



Relevant Pages

  • packet dropper module...problem includign skbuff.h
    ... I m trying a packet dropper programin Linux 2.4 ... I m getting some unusal erros in the Linux Header files itself. ...
    (comp.os.linux.development.system)
  • Re: Outlook 07 and spell checker
    ... out withoug errors, but there are erros. ... Any pointer as to where to look at? ... You might want to edit your Custom Dictionary in Word. ...
    (microsoft.public.outlook)
  • Re: Outlook 07 and spell checker
    ... withoug errors, but there are erros. ... Any pointer as to where to look at? ... Are you using Word as your e-mail editor? ...
    (microsoft.public.outlook)
  • Re: Outlook 07 and spell checker
    ... withoug errors, but there are erros. ... Any pointer as to where to look at? ... Are you using Word as your e-mail editor? ...
    (microsoft.public.outlook)
  • Outlook 07 and spell checker
    ... Spell checking doesn't seem to work for me. ... withoug errors, but there are erros. ... Any pointer as to where to look at? ...
    (microsoft.public.outlook)