Find the answer to your Linux question:
Results 1 to 4 of 4
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() ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    7

    Smile 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!

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    It's not a compilation problem but a linking one...

    You included the needed file, but kernel modules are linked only against kernel.
    Make a grep ipv6_rcv /boot/System.map to know if the symbol that you need is declared and exported.

    Best regards

  3. #3
    Just Joined!
    Join Date
    May 2006
    Posts
    7

    Smile

    Quote Originally Posted by fernape
    It's not a compilation problem but a linking one...

    You included the needed file, but kernel modules are linked only against kernel.
    Make a grep ipv6_rcv /boot/System.map to know if the symbol that you need is declared and exported.

    Best regards
    HI, when i run grep ipv6_rcv /boot/System.map ,i get the information .i think i can call the ipv6_rcv funtion ,but why in my module the function is undifined??
    c03beb90 T ipv6_rcv
    c03c0a19 T ipv6_rcv_saddr_equal

  4. #4
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    If it is exported, you should declare it as "extern" in order to use it.

    Best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •