linking multiple files kernel module programming
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 <linux/ip.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
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
I am getting following error -
WARNING: "amino"[/home/user1/Desktop/amin/sourceadd2.ko] undefined!
Thanks
|