[Click] help: for the userlevel tohost

heyeast zhd5408 at gmail.com
Wed Jul 4 00:24:42 EDT 2012


hi Huiqing,

It's similar with my work. This function is handled by the kernel click
easily, but the reason I use userlevel click is that I can't compile
patchless click on OpenWRT. I guess the same to you.

I tried to set the fake0 device the same as eth0, including ip address and
mac address. So that fake0 device could read packet from eth0 normally.
Kernel was success to read packets from fake0 device but failed to send out
packets from device eth0.



2012/7/4 Huiqing Fu <huiqingfu2012 at gmail.com>

> hi,
> I am trying to read packets from device eth0 to fake0 device, and add some
> delay to the packets.
> But, now the server can not get the packets from kernel, I guess maybe the
> tohost fails returning the packets or the kernel drops the packets.
> Can anyone help me to deal the problem?
> My target is that:client send packets to eth0, but server listen to fake0.
> So the click should read the packets from eth0 and change the packets then
> return them to kernel, so that server
> can get the packets.
> The codes are below:
>
> // fromhost-tunnel.click
>
>
>
> // This configuration demonstrates the use of FromHost, by tunneling all
>
> // packets for TEST_NETWORK via the kernel Click configuration. To adapt
>
> // for your own use, change the AddressInfo element and replace device
>
> // "eth0" with your relevant device.
>
>
>
> AddressInfo(
>
>         // The address of a machine and a network segment.
>
>         // This machine will route packets for the network via FromHost,
>
>         // using the host address as source.
>
>         TEST_NETWORK 192.168.2.3/24,
>
>         TEST_MAC 1e:b2:02:2f:6a:0c,
>
>
>
>         // This host's real address.
>
>         MY_ADDR 192.168.1.1,
>
>
>
>         // The gateway machine this host really uses to send to
> TEST_NETWORK.
>
>         MY_GATEWAY 192.150.187.1)
>
>
>
> elementclass FixChecksums {
>
>     // fix the IP checksum, and any embedded checksums that include data
>
>     // from the IP header (TCP and UDP in particular)
>
>     input -> SetIPChecksum
>
>         -> ipc :: IPClassifier(tcp, udp, -)
>
>         -> SetTCPChecksum
>
>         -> output;
>
>     ipc[1] -> SetUDPChecksum -> output;
>
>     ipc[2] -> output
>
> }
>
>
>
> th :: ToHost(fake0);
>
>
>
> FromHost(fake0, TEST_NETWORK, ETHER TEST_MAC)
>
>         // Respond to ARP requests
>
>         -> fh_cl :: Classifier(12/0806, 12/0800)
>
>         -> ARPResponder(0/0 1:1:1:1:1:1)
>
>         ->Print(fharp,60)
>
>         -> th
>
>
>
> // Forward IP packets from the fake device to the real Internet
>
> fh_cl[1] -> Strip(14)                           // remove crap Ether header
>
>          ->Print(fhip,60)
>
>          -> MarkIPHeader(0)
>
>         -> StoreIPAddress(MY_ADDR, 12)          // store real address as
> source
>
>         -> FixChecksums                         // recalculate checksum
>
>         -> SetIPAddress(MY_GATEWAY)             // route via gateway
>
>         ->Print(iparpq)
>
>         -> aq :: ARPQuerier(MY_ADDR, eth0)
>
>         -> Queue
>
>         -> ToDevice(eth0)
>
>
>
> // listen for ARP responses
>
> fd :: FromDevice(eth0,SNIFFER false)
>
>         -> fd_cl :: Classifier(12/0806 20/0002, 12/0800, -)
>
>         ->Print(fdeth0arpr,60)
>
>         -> t::Tee
>
>         -> Print(arpq)
>
>          -> [1]aq;
>
>          t[1]
>
>              ->Print(arpdup)
>
>               -> th             // ARP responses to us and host
>
> fd_cl[2]
>
>        -> Print(fdeth0other,60)
>
>         -> th
>
>
>
>
>
> // Packets arriving from the Internet from the test network must have their
>
> // destination addresses changed, to our fake address
>
> fd_cl[1] -> CheckIPHeader(14)
>
>         // check for responses from the test network
>
>         -> ipc :: IPClassifier(udp port 5500, -)
>
>         ->Print(fdeth0ip,60)
>
>         // replace the real destination address with the fake address
>
>         ->StoreEtherAddress(TEST_MAC,0)
>
>         -> StoreIPAddress(TEST_NETWORK, 30)
>
>         -> FixChecksums
>
>         ->Print(udpdstfake,60)
>
>         -> th
>
> ipc[1]
>
>         ->CheckIPHeader(14)
>
>         // check for responses from the test network
>
>         ->Print(otherip,60)
>
>         // replace the real destination address with the fake address
>
>         ->StoreEtherAddress(TEST_MAC,0)
>
>         -> StoreIPAddress(TEST_NETWORK, 30)
>
>         -> FixChecksums
>
>         ->CheckIPHeader(14)
>
>         ->Print(dstfake,60)
>
>         -> th
>
>
> Thank you.
>
> Huiqing Fu
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>


More information about the click mailing list