LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2004, 09:33 PM   #1
Lite
LQ Newbie
 
Registered: Jul 2004
Posts: 1

Rep: Reputation: 0
Question 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Forwarding packets with Iptables DrunkenDisciple Linux - Software 2 07-24-2005 11:00 PM
Not forwarding packets meadensi Linux - Networking 0 02-08-2005 07:02 PM
forwarding packets to multiple computers for different ports laxy_m Linux - Networking 7 11-11-2004 08:15 AM
Forwarding ACK Packets snufferz Linux - Newbie 0 05-12-2004 02:10 AM
pardon the silly question: forwarding packets FROM certain ports? FallenHero Linux - Networking 7 06-18-2002 07:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration