Kernel Module Chaning destination mac address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hello there!
I am working on a project to create a kernel module which directs all
outgoing traffic from my machine to different computer in my LAN. So I
am starting with just trying to send the traffic to just one computer.
I am using the NF_BR_LOCAL_OUT hook. Along with the NFPROTO_IPV4
family. But every time i run the module, my machine hangs. And I need
to reboot.  Please see what is the problem.

Here is the code:

#include <generated/autoconf.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/types.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_bridge.h>
#include <linux/socket.h>
#include <linux/netfilter.h>

struct nf_hook_ops hook_ex;

unsigned int function_hook( unsigned int hook, struct sk_buff **pskb, const
struct net_device *in,
    const struct net_device *out, int (*okfn)(struct sk_buff *))

char a[] = { 0x00, 0x24, 0x21, 0x03, 0xd4, 0x31};
printk("changing IP dst address in %s\n", __FUNCTION__);
if (skb_shared(*pskb) || skb_cloned(*pskb)) {
struct sk_buff *nskb;
 printk("in if if (skb_shared(*pskb) || skb_cloned(*pskb)) \n");

nskb = skb_copy(*pskb, GFP_ATOMIC);
if (!nskb)
return NF_DROP;
if ((*pskb)->sk)
skb_set_owner_w(nskb, (*pskb)->sk);
*pskb = nskb;
memcpy(eth_hdr(*pskb)->h_dest, a, ETH_ALEN);

return NF_ACCEPT;

static int __init init(void)
   // hook = NULL;
   hook_ex.list.prev = NULL;
   hook_ex.hook = function_hook;
   //  hook_ex.list.flush = NULL; = NFPROTO_IPV4;
   hook_ex.hooknum = NF_BR_LOCAL_OUT;
printk(KERN_INFO "[CCD] Successfully inserted module into kernel.\n");
   return nf_register_hook(&hook_ex);

static void __exit fini(void)
printk(KERN_INFO "[CCD] Successfully unloaded module.\n");



PS: I am noob at kernel programming
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Linux Netfilter Development]     [Linux Kernel Networking Development]     [Linux Networking Development]     [Linux Kernel Development]     [Linux Resources]     [LARTC]     [Bugtraq]     [Consulting]     [Free Internet Dating]     [Yosemite Forum]     [Photo]

Add to Google Powered by Linux