views:

391

answers:

0

I am just writing a test file and then i am trying to call a function inside my kernel.

Can somebody tell if i am making a mistake in my makefile or my code??

I wanted to call my int d = add(2, 4); function but the program does not seem to link test.c file with sourceadd2.c.

/* sourceadd2.c */

define KERNEL

define MODULE

include "test.h"

include

include

include

include

include

MODULE_LICENSE("GPL");

unsigned int hook_func(unsigned int hooknum, struct sk_buff **skb, const struct net_device *in, const struct net_device out, int (okfn) (struct sk_buff *)){

    int d = add(2, 4);

    printk(KERN_INFO " testing %d \n", d); 

    return NF_DROP;

}

int init_module() { /* Fill in our hook structure */

   nfho.hook     = hook_func;

  /* Handler function */

   nfho.hooknum  = NF_IP_PRE_ROUTING; /* First hook for IPv4 */

   nfho.pf       = PF_INET;

   nfho.priority = NF_IP_PRI_FIRST;   /* Make our function first */

   nf_register_hook(&nfho);

   return 0;

}

/* Cleanup routine */

void cleanup_module() { nf_unregister_hook(&nfho); }

/* test.c */

include "test.h"

int add(int a , int b) { return a+b; }

/* test.h */

ifndef TEST_H

define TEST_H

int add(int a, int b);

endif

---Makefile----

obj-m :=sourceadd2.o

sourceadd2-objs := test.o

KDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)

default:

$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Thanks