Networking Forums

Networking Forums > Computer Networking > Linux Networking > Linux Packet dropper -

Reply
Thread Tools Display Modes

Linux Packet dropper -

 
 
SaranJothy
Guest
Posts: n/a

 
      12-21-2005, 03:00 PM
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

 
Reply With Quote
 
 
 
 
Allen McIntosh
Guest
Posts: n/a

 
      12-22-2005, 01:35 AM
> I m trying a packet dropper program(KERNEL MODULE) in Linux 2.4 (I got
> this from a site),


If you are doing this to learn about the kernel, stop reading now.
If you are doing this to run experiments with dropped packets, check out
NISTNET.
 
Reply With Quote
 
SaranJothy
Guest
Posts: n/a

 
      12-22-2005, 03:52 AM
thanks for your reply.


NIST Net is a network emulation package that runs on Linux. NIST Net
allows a single Linux box set up as a router to emulate a wide variety
of network conditions, such as packet loss, duplication, delay and
jitter, bandwidth limitations, and network congestion. This allows
testing of network-adaptive protocols and applications (or those which
aren't, but maybe should be) in a lab setting.

ref:http://www-x.antd.nist.gov/nistnet/

I have got much info about nist from the above site.

But my actual solution required is to create a module which gets called
from kernel and hence dropping packets belonging to particular IP
address(given in hexa in the module)

So , i only require a solution for this problem.

Anyway thanks for the info. given.
It is also useful for me.

I will appreciate your efforts in sorting the problem.
As per the suggestion given by my collegue, the problem is very simple
one.
But as i dont have much experience with module programming in LInux
....i m unable to.

please do help.

regards
Saranjothy (at) gmail (dot) com

 
Reply With Quote
 
SaranJothy
Guest
Posts: n/a

 
      12-22-2005, 05:37 AM

To add some more details,
I m getting the erros only due to inclusion of skbuff.h
i have verified the erros.


IS THERE ANY PROBLEM IN INCLUDING SKBUFF.H HEADER FILE??

CAN BE INCLUDE IN A KERNEL MODUEL OR NOT??

when i 've included skbuff.h in a simple hello world application also
it IS SHOWING ERROS.


please help regarding this.

regards

Saranjothy (at) gmail (dot) com



SaranJothy wrote:

> thanks for your reply.
>
>
> NIST Net is a network emulation package that runs on Linux. NIST Net
> allows a single Linux box set up as a router to emulate a wide variety
> of network conditions, such as packet loss, duplication, delay and
> jitter, bandwidth limitations, and network congestion. This allows
> testing of network-adaptive protocols and applications (or those which
> aren't, but maybe should be) in a lab setting.
>
> ref:http://www-x.antd.nist.gov/nistnet/
>
> I have got much info about nist from the above site.
>
> But my actual solution required is to create a module which gets called
> from kernel and hence dropping packets belonging to particular IP
> address(given in hexa in the module)
>
> So , i only require a solution for this problem.
>
> Anyway thanks for the info. given.
> It is also useful for me.
>
> I will appreciate your efforts in sorting the problem.
> As per the suggestion given by my collegue, the problem is very simple
> one.
> But as i dont have much experience with module programming in LInux
> ...i m unable to.
>
> please do help.
>
> regards
> Saranjothy (at) gmail (dot) com


 
Reply With Quote
 
SaranJothy
Guest
Posts: n/a

 
      12-22-2005, 06:28 AM
I myself got the solution for this problem.

i have missed flags for compiling which created the headache.

Its best to use Make for this program.


It goes like this.

TARGET := pktdrop
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC := gcc

${TARGET}.o: ${TARGET}.c

..PHONY: clean

clean:
rm -rf ${TARGET}.o



But as i have used simple compilation iike gcc - in the command line
itself with limited flags.
it created problems.....


HAPPY CODING.

SaranJothy

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to capture and change packet using linux? quakewang@mail.whut.edu.cn Linux Networking 0 06-23-2007 03:15 AM
Packet Forwarding in Linux. rramesh1@gmail.com Linux Networking 1 10-30-2006 11:26 PM
TCP/IP packet monitoring on linux joker Linux Networking 2 12-22-2005 07:52 PM
linux kernel 2.6 packet travel Giacomo Linux Networking 1 07-01-2005 03:47 PM
Linux/WEP packet routing. Ian Stirling Wireless Internet 0 02-20-2004 03:11 PM



1 2 3 4 5 6 7 8 9 10 11