Problem about forwarding packets in kernel
The following codes is used to receive packets from eth1 and forward them through eth0.
/*
* USAGE: gcc -O2 -DDEBUG -c splitter.c -I/usr/src/linux-2.4/include
* insmod splitter.o
*/
#define MODULE
#define __KERNEL__
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/kernel.h>
uint32_t count = 0;
struct packet_type bounce_proto;
/* inicial function declarations */
int process_pkt_in(struct sk_buff *skb, struct net_device *dv, struct packet_type *pt)
{
count++;
skb->dev = dev_base->next;
skb->pkt_type = PACKET_OUTGOING;
dev_queue_xmit(skb);
return 0;
}
static unsigned short flags;
static unsigned short gflags;
static int null_pkt_rcv(struct sk_buff *skb,
struct net_device *dev,struct packet_type *pt)
{
__kfree_skb(skb);
return 0;
}
struct packet_type null_pkt_type =
{
__constant_htons(ETH_P_ALL),NULL,null_pkt_rcv,NULL,NULL,
};
struct packet_type *old_type;
/* init_module */
int init_module(void)
{
int i;
struct packet_type *ptype;
struct net_device *dev = dev_base->next->next;
dev_add_pack(&null_pkt_type);
ptype = null_pkt_type.next;
old_type = ptype;
while(ptype){
dev_remove_pack(ptype);
ptype = null_pkt_type.next;
}
dev_remove_pack(&null_pkt_type);
bounce_proto.type = htons(ETH_P_ALL);
bounce_proto.func = process_pkt_in;
dev_add_pack(&bounce_proto);
printk( "Init OK\n" );
return(0);
}
void cleanup_module(void) {
struct packet_type *ptype;
struct net_device *dev = dev_base->next->next;
printk("total packet is %d\n",count);
ptype = old_type;
dev_remove_pack(&bounce_proto);
while(ptype){
old_type = old_type->next;
dev_add_pack(ptype);
ptype = old_type;
}
}
However, the packets observed on eth0 are different with those on eth0. It seems that the program has changed the packets. Can anyone help me to fix the problem?
Pakcets observed using tcpdump on eth1:
08:58:19.593099 arp who-has 192.168.60.7 tell 192.168.60.254
08:58:19.633948 192.168.60.212.netbios-dgm > 192.168.60.255.netbios-dgm: NBT UDP PACKET(138)
Pakcets observed using tcpdump on eth0:
08:58:19.593107 0:1:0:3:e3:7 0:1:8:0:6:4 5207 46:
c0a8 3cfe 0000 0000 0000 c0a8 3c07 0000
0000 0000 0000 0000 0000 0000 0000 0000
08:58:19.633956 0:0:80:11:ca:62 45:0:0:ed:74:79 c0a8 237:
3cd4 c0a8 3cff 008a 008a 00d9 10d8 1102
b245 c0a8 3cd4 008a 00c3 0000 2046 4445
5045 4746 4545 4f45 4a45 4546 4443 4143
4143 4143 4143 4143 4143 4141 4100 2041
4241 4346 5046 5045 4e46 4445 4346 4345
5046
|