Hi,how can I call the ipv6_rcv() function in my own kernel module.
hi ,everyone. Recently I have writen a kernel module in redhat 2.6.8.1. I register a new packet_type "test" in module_init();
in the test.func:test_rcv() function ,at last I have call ipv6_rcv() function to put the skb to ipv6 protocol.below is my module and funtion:
the directory is as below:
test
|--src
| |--test.c
| |--receive.c
| |--Makefile
|
|--include
| |--receive.h
1.my test.c file is as below:
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <net/ipv6.h> /*define the ipv6_rcv() prototype*/
#include "receive.c" /*test_rcv()*/
extern int test_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt );
//register a new packet_type for rohc
static struct packet_type test=
{
.type=__constant_htons(ETH_P_IPV6),
.dev=NULL,
.func=test_rcv,
};
static int test_init(void)
{
printk("register a new network lay protocol for test");
dev_add_pack(&test);
return 0;
}
static void test_exit(void)
{
printk("remove network lay protocol test");
dev_remove_pack(&test);
}
MODULE_LICENSE("GPL");
module_init(test_init);
module_exit(test_exit);
2. my receive.c file is as below:
#include <net/ipv6.h>
#include "../include/receive.h"
int test_rcv(struct sk_buff *skb,struct net_device *dev, struct packet_type *pt)
{
printk("we have receive a ipv6 packet\n" );
return ipv6_rcv(skb,dev,NULL);
}
3. my receive.h file is as below:
#ifndef RECEIVE_H
#define RECEIVE_H
int test_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt);
#endif
4. my Makefile file is as below:
obj-m := test.o
test-obj :=receive.o
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
5. question:
when i was in test/src directory , i run make, but dont pass the compiler.the information is :
[y041138@302wan src]$ make
make -C /lib/modules/2.6.8.1/build M=/home/y041138/src modules
make[1]: Entering directory `/usr/src/linux-2.6.8.1'
CC [M] /home/y041138/src/test.o
Building modules, stage 2.
MODPOST
*** Warning: "ipv6_rcv" [/home/y041138/src/test.ko] undefined!
CC /home/y041138/src/test.mod.o
LD [M] /home/y041138/src/test.ko
make[1]: Leaving directory `/usr/src/linux-2.6.8.1'
[y041138@302wan src]$
the ipv6_rcv() function procotype is in /usr/src/linux-2.6.8.1/net/ipv6.h . I have include the ipv6.h file in test.c file.why can`t I use the ipv6_rcv() funtion?? can you help me?? now I was doing a software which I must put the "ipv6" skb to the ipv6 protocol when completed my own "test_rcv()" funtion; Do you have some idears that I can pass the ipv6 packet to the ipv6 protocol or ipv6_rcv function after completed my funtion test_rcv()??
can you give me your help and modify the test(test.c Makefile receive.c receive.h) file correctly that can pass the compiler and implement the function??
At last thank you very much!