LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Sending Ethernet Frames using dev_queue_xmit (https://www.linuxquestions.org/questions/linux-kernel-70/sending-ethernet-frames-using-dev_queue_xmit-895275/)

Sekhar417 08-03-2011 06:46 AM

Sending Ethernet Frames using dev_queue_xmit
 
Hi,

I have written a sample code to receive and send the Ethernet Packets from/to another machine.

I am able to receive the packet successfully from another machine, but sending packet is not seen on another machine. Even i checked the tcpdump in both machines after sending, i don't see any packet dumps. I even checked the frame drops, but nothing was there.

I am sending the packet the using dev_queue_xmit(skb), with proper dev name setting as eth0.

After receiving the packet, i am just changing the MAC address and sending.

Please correct my code, what is wrong here.

#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/fcntl.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>

int mpls_packet_recv (struct sk_buff *skb, struct net_device *dev );

static struct packet_type my_packet_type;

int SendData(struct sk_buff *skb, struct net_device *dev);

/* Recieve Packet */
int mpls_packet_recv (struct sk_buff *skb,
struct net_device *dev);

{
struct sk_buff *sk = skb;
dev = sk->dev;
/* send the Data */
SendData(skb, dev);
return 0;
}
int SendData(struct sk_buff *skb, struct net_device *dev)
{
int ret;
int i;

skb->pkt_type = PACKET_OUTGOING;
skb->dev = dev; //eth0

/*changing Mac address */
unsigned char srcaddr[6];
struct ethhdr *eth = eth_hdr(skb);
memcpy(srcaddr, eth->h_source, ETH_ALEN);
memcpy(eth->h_source, eth->h_dest, ETH_ALEN);
memcpy(eth->h_dest, srcaddr, ETH_ALEN);

/* send the packet */
ret = dev_queue_xmit(skb);
printk(KERN_DEBUG "\ndev_queue_xmit returned %d\n", ret);

return ret;

}
static int __init nf_init(void)
{
my_packet_type.type = htons(ETH_P_ALL);
my_packet_type.func = mpls_packet_recv;
my_packet_type.dev = NULL;
dev_add_pack(&my_packet_type);

return 0;
}
static void __exit nf_exit(void)
{
dev_remove_pack(&my_packet_type);
}


Thanks
--sekhar

Mara 08-04-2011 02:55 PM

You need to debug deeper. Is the source address the address compatible with the MAC address associated with the interface?

lazarobankini 05-29-2013 06:35 PM

Have you solved this? i'm having the same problem.. it seems that when i'm using the broadcast address everything is fine, but unicast is not, the receiver does not receive the data... I'm stuck.


All times are GMT -5. The time now is 01:09 PM.