Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, i'm designening a simple router for a customized network. in this network there is a LAN behind my router which wants to send their TCP/IP packets through me. but ...
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    3

    fragmenting network packet

    Hi, i'm designening a simple router for a customized network. in this network there is a LAN behind my router which wants to send their TCP/IP packets through me. but this special networl doesn't allow sending 1500 bytes sized packets, so i need to fragment network packets. now i have two thoughts in my mind but don't know how these thoughts can be implemented in c++.
    1. to fragment packets inside my router which make my router so busy
    2. somehow inform computers in the LAN to fragment their packets before sending them to me

    is each of these thoughts possible? and if yes how?

    Thanks

  2. #2
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    Should be done by the computers. Read RFC4821 on PMTU discovery, which references prior RFCs on the subject also.
    Last edited by Mudgen; 06-14-2011 at 01:42 AM. Reason: add

  3. #3
    Linux Newbie
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    243
    So your "customized" network uses TCP/IP, but the packet size is different? I believe all you need to do is set the MTU for the interface that connects to the "customized" network using Ifconfig. For example, if your router has two ethernet interfaces Eth0 at 111.111.111.0, and the "customized" network is Eth1 at 222.222.222.0, then you can do this:
    Code:
    ifconfig eth1 down
    ifconfig eth1 mtu 1200 address 222.222.222.0 netmask 255.255.255.0 up
    Then set your routing table using Route:
    Code:
    route add -net 222.222.222.0 netmask 255.255.255.0 gw 111.111.111.0
    Where 111 is your ordinary network, and 222 is your customized network.

    If your "customized" network is does not allow TCP packets, your router must translate all data from the TCP/IP network into the protocol used by the "customized" network. If your router must translate all packets, then it is best to fragment packets in the router as part of the translation phase. TCP sockets can be read as a stream, and it is very easy to create a buffer of the correct fragment size and read bytes from the socket into the buffer. Then, the router can translate the buffer and transmit it to the special network segment using the correct fragment size.

    If you wish to encapsulate TCP packets for use in the "customized" network, you will need to retrieve packets before they are presented to the socket, store them in a large buffer, and then read data fragments from the buffer to encapsulate them for the protocol on your special network. The Tcpdump program can capture all incoming TCP packets and store them into a file or fifo. You can then read this file or fifo for encapsulation.

  4. #4
    Just Joined!
    Join Date
    Jan 2011
    Location
    Fairfax, Virginia, USA
    Posts
    94
    Hi ehsanen77,
    For a router, its probably best if you use a Linux kernel to accomplish what you want to do. It sounds like your developing code to work with a TUN or TAP and reading/writing to and from a user application? If you want to tunnel packets, then openvpn is really good. In the later openvpn case, fragmentation and reassembly is handled by the kernels at each end of openvpn and not inside openvpn itself as far as I know. Its really difficult to handle a TCP stack in userspace.

  5. #5
    Just Joined!
    Join Date
    Feb 2011
    Posts
    3
    Thank you all my friends, these are good aproaches.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...