LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   sending a packet to another machine from a kernel module. (https://www.linuxquestions.org/questions/linux-networking-3/sending-a-packet-to-another-machine-from-a-kernel-module-286066/)

Sridhar Kumar K 02-04-2005 12:37 AM

sending a packet to another machine from a kernel module.
 
I have two machines.

Machine 1 (IP 172.27.22.201) has two IP Aliases. 10.0.1.1 and 10.0.1.2.
Machine 2 (IP 172.27.22.232) has a IP alias 10.0.2.1.
(IP Alias is created using cmd #ifconfig eth0:1 10.0.0.1)

I want to send a packet from 10.0.1.1 (m/c 1) --> 10.0.2.1 (m/c 2) --> 10.0.1.2 (m/c 3).

In Machine 1, Iam capturing a packet from 10.0.1.1 to 10.0.1.2 at netfilter hook NF_IP_LOCAL_OUT. First to send the packet to 10.0.2.1 (m/c 2), I need to send the packet to Machine 2.
For sending the packet to machine 2 Iam doing the following changes in sk_buff structure of the packet.

sb->dev = dev_get_by_name("eth0");

Previously I captured the object of struct dst_entry * from a skbuffer of a packet going to Machine 2(for m/c 2 IP. Not to its alias) . Now, for the currently outgoing packet to m/c 2 IP Alias, Iam filling the sk_buff field struct dst_entry * with the previously captured dst_entry * object.

sb->dst = my_dst_entry; // previously captured dst_entry

Next Iam doing the following changes in the packet Header.

Iam adding another IP Header (i.e. IP-over-IP) with src IP 10.0.1.1 and dst IP 10.0.2.1. Iam changing the protocol field in the outer IP Header to IP-over-IP value. I changed the total len field and calculated the new checksum.
Next Iam filling the MAC Header fields. src MAC as the MAC address of m/c 1 and dst MAC as the MAC address of m/c 2 and type of packet to IP.
Now iam returning NF_ACCEPT.

Iam receiving the packet at machine 2. Now I captured the packet at netfilter-hook NF_IP_PRE_ROUTING. Now I want to send the packet to 10.0.1.2 (m/c 1). For this Iam changing the sk_buff fields, outer IP Header fileds and MAC Header fields as before.
Next Iam calling the dev_queue_xmit() to send the packet to machine 1.

Iam receiving the packet at m/c 1 netfilter hook NF_IP_PRE_ROUTING. But the packet is *not* reaching the Application.
Why it is not reaching the application ? Whether I need to fill any other fields in the sk_buff structure.
Iam using i) ping command ii) udp sockets to send packets at the application layer.

Thanks n Regards,
Sridhar.


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