Skip to content

test setup

Kazuho Oku edited this page Jan 10, 2023 · 5 revisions

reflector.rb

This program reflects packets sent to FAKE_ADDR (10.1.2.4) back to TRUE_ADDR (10.1.2.254); i.e., when the packet contains (source_address, destination_address) = (TRUE_ADDR, FAKE_ADDR), it rewrites the tuple to (FAKE_ADDR, TRUE_ADDR).

Setup:

# sysctl -w net.ipv4.ip_forward=1
# ip tuntap add dev rat mode tun $USER
# ip addr add 10.1.2.254/24 dev rat
# ip link set dev rat up

Benchmark:

% ./reflector.rb &
% iperf3 -p 5555 -s &
% iperf3 -p 5555 -c 10.1.2.4

iperf3 client sends packets from 10.1.2.254 (the address assigned to the tuntap device) to 10.1.2.4:5555. The packets are routed to the tuntap device, and gets read by reflector.rb. reflector.rb rewrites the address tuple and sends them back to the iperf server. Packets being sent from the server are rewritten and sent back the same way.

rat.rb

This program is a NAPT (network address and port translator). The NAT global address being used is 192.168.0.139 ($nat.global_addr).

Assume networks like follows.

            localnet (192.168.0.0/24)
       +----------------+-----------------+
       |                |                 |
       |                |                eth0
+------+------+  +------+------+  +-------+-------+  +-------------+
|   router    |  |   server    |  |   testnode    |  |    client   |
| 192.168.0.1 |  | 192.168.0.2 |  | 192.168.0.138 |  | 192.168.1.2 |
+------+------+  +-------------+  |  192.168.1.1  |  +------+------+
       |                          +-------+-------+         |
       |                                 eth1               |
  (internet)                              |                 |
                                          +-----------------+
                                        testnet (192.168.1.0/24)      

eth0 and eth1 of testnode should be configured as ordinary. Then, in addition, following setup should be applied. This setup forwards all packets arriving from testnet to the tuntap device. Packets to 192.168.0.139 are forwarded to the tuntap device as well.

# echo '100 RAT' >> /etc/iproute2/rt_table   # run this only once
# sysctl -w net.ipv4.ip_forward=1
# ip tuntap add dev rat mode tun user $USER
# ip link set rat up
# ip route add default dev rat table RAT
# ip rule add from 192.168.1.0/24 iif eth1 table RAT
# ip route add 192.168.0.139 dev rat

Default route of client should point to 192.168.1.1.

server should have the following route setup so that it would send packets with destination address of 192.168.0.139 to testnode.

# ip route add 192.168.0.139 via 192.168.0.138

You may add this route to the router; by doing so, the client can connect to the Internet.

Benchmark:

On testnode:
% ./rat.rb

On server:
% iperf3 -p 5555 -s

On client:
% iperf3 -p 5555 -c 192.168.0.2
Clone this wiki locally