HAMNET-Access-Protocol / HNAP4PlutoSDR

Main transceiver application
GNU Lesser General Public License v3.0
29 stars 5 forks source link

Enable complex network settings #59

Open dl1com opened 4 years ago

dl1com commented 4 years ago

Description

This pull request enables the user to set up the Pluto to work in typical Hamnet network topologies. For this purpose, bridging, NAT and and iptables support have been enabled in the Kernel. For persistent configuration, the network settings are added to the config.txt architecture of the Pluto (persistent storage in uboot fw_env)

Supported network configurations

Basestation (via USB-Ethernet-Adapter + Lease from HAMNET-Router + Static Route from HAMNET-Router to HNAP-User-Network)

[NETWORK] hostname = master ipaddr = 192.168.2.1 netmask = 255.255.255.0 dhcp_server_first_ip = 192.168.2.10 # or: "ipaddr_host = 192.168.2.10" dhcp_server_leasetime = 600 # 10 minutes lease time dhcp_server_gateway = 192.168.2.1 # Usually "dhcp_server_gateway" equals to "ipaddr" (for me it is OK to type the IP twice)

[USB_ETHERNET] ipaddr_eth = # dhcp-client netmask_eth = 255.255.255.0 # will be ignored, since "ipaddr_eth = " (no value -> DHCP-Client)

[HNAP_NETWORK] ipaddr_tap = 44.128.0.17 # replaces the need for "fw_setenv hnap_tap_ip" netmask_tap = 255.255.255.240 dhcp_server_first_ip_tap = 44.128.0.21 # Starts DHCP-Server starting from .21 (max .30 due to netmask_tap) dhcp_server_leastime_tap = 600 # dhcp_server_gateway_tap = 44.128.0.17 # Configuration file for "udhcpd" reads like this:

start 44.128.0.21

                                    #    interface tap0
                                    #    option subnet 255.255.255.240
                                    #    option router 44.128.0.17
                                    #    option lease 600

Client (PC via USB + DHCP-Client on HNAP-User-Network + Masquerade packets to HNAP-User-Network)

[NETWORK] hostname = client ipaddr = 192.168.2.1 netmask = 255.255.255.0 dhcp_server_first_ip = 192.168.2.10 # or: "ipaddr_host = 192.168.2.10" dhcp_server_leasetime = 600 # 10 minutes lease time dhcp_server_gateway = 192.168.2.1 # Usually "dhcp_server_gateway" equals to "ipaddr" (for me it is OK to type the IP twice)

[USB_ETHERNET] ipaddr_eth = # dhcp-client netmask_eth = 255.255.255.0 # will be ignored, since "ipaddr_eth = " (no value -> DHCP-Client)

[HNAP_NETWORK] ipaddr_tap = # udhcpc running on "tap0" netmask_tap = 255.255.255.0 # see section [USB_ETHERNET]; I guess it is not required if ipaddr_eth/tap is empty

[NAT] nat_interface = HNAP_NETWORK # translates to "iptables -t nat -A POSTROUTING -o tap0 -j MASQUERADE"


Basestation (via USB-Ethernet-Adapter + Bridge USB_ETHERNET / HNAP_NETWORK + Lease from HAMNET-Router)

[BRIDGE] master_interface = USB_ETHERNET slave_interface_1 = HNAP_NETWORK

[NETWORK] hostname = master ipaddr = 192.168.2.1 netmask = 255.255.255.0 dhcp_server_first_ip = 192.168.2.10 # or: "ipaddr_host = 192.168.2.10" dhcp_server_leasetime = 600 # 10 minutes lease time dhcp_server_gateway = 192.168.2.1 # Usually "dhcp_server_gateway" equals to "ipaddr" (for me it is OK to type the IP twice)

[USB_ETHERNET] ipaddr_eth = # dhcp-client netmask_eth = 255.255.255.0 # will be ignored, since "ipaddr_eth = " (no value -> DHCP-Client)

[HNAP_NETWORK] ipaddr_tap = 44.128.0.17 # since HNAP_NETWORK is a "slave_interface" all settings are ignored netmask_tap = 255.255.255.240 # since HNAP_NETWORK is a "slave_interface" all settings are ignored


Basestation (via USB-Ethernet-Adapter + Bridge USB_ETHERNET / HNAP_NETWORK + static IP)

[BRIDGE] master_interface = USB_ETHERNET slave_interface = HNAP_NETWORK

[NETWORK] hostname = master ipaddr = 192.168.2.1 netmask = 255.255.255.0 dhcp_server_first_ip = 192.168.2.10 # or: "ipaddr_host = 192.168.2.10" dhcp_server_leasetime = 600 # 10 minutes lease time dhcp_server_gateway = 192.168.2.1 # Usually "dhcp_server_gateway" equals to "ipaddr" (for me it is OK to type the IP twice)

[USB_ETHERNET] ipaddr_eth = 44.128.0.2 netmask_eth = 255.255.255.240 gateway_eth = 44.128.0.1 # set defaultroute

[HNAP_NETWORK] ipaddr_tap = 44.128.0.17 # since HNAP_NETWORK is a "slave_interface" all settings are ignored netmask_tap = 255.255.255.240 # since HNAP_NETWORK is a "slave_interface" all settings are ignored


Client (Integration into HomeLAN via USB-Ethernet-Adapter + DHCP-Client on HNAP-User-Network + Masquerade packets to HNAP-User-Network)

--> same as "normal client configuration (see first example)

[NETWORK] hostname = client ipaddr = 192.168.2.1 netmask = 255.255.255.0 dhcp_server_first_ip = 192.168.2.10 # or: "ipaddr_host = 192.168.2.10" dhcp_server_leasetime = 600 # 10 minutes lease time dhcp_server_gateway = 192.168.2.1 # Usually "dhcp_server_gateway" equals to "ipaddr" (for me it is OK to type the IP twice)

[USB_ETHERNET] ipaddr_eth = # dhcp-client netmask_eth = 255.255.255.0 # will be ignored, since "ipaddr_eth = " (no value -> DHCP-Client)

[HNAP_NETWORK] ipaddr_tap = # udhcpc running on "tap0" netmask_tap = 255.255.255.0 # see section [USB_ETHERNET]; I guess it is not required if ipaddr_eth/tap is empty

[NAT] nat_interface = HNAP_NETWORK # translates to "iptables -t nat -A POSTROUTING -o tap0 -j MASQUERADE"


Client (Integration into HomeLAN via USB-Ethernet-Adapter to Mikrotik-Router + Bridge USB_ETHERNET / HNAP_NETWORK + DHCP-Client on HNAP-User-Network)

[BRIDGE] master_interface = USB_ETHERNET slave_interface_1 = HNAP_NETWORK

[NETWORK] hostname = client ipaddr = 192.168.2.1 netmask = 255.255.255.0 dhcp_server_first_ip = 192.168.2.10 # or: "ipaddr_host = 192.168.2.10" dhcp_server_leasetime = 600 # 10 minutes lease time dhcp_server_gateway = 192.168.2.1 # Usually "dhcp_server_gateway" equals to "ipaddr" (for me it is OK to type the IP twice)

[USB_ETHERNET] ipaddr_eth = # udhcpc running on Bridge (master_interface) netmask_eth = 255.255.255.0

[HNAP_NETWORK] ipaddr_tap = # nothing - slave client netmask_tap = 255.255.255.0 #

dl1com commented 3 years ago

Current default settings:

[NETWORK]
hostname = pluto
ipaddr = 192.168.2.1
netmask = 255.255.255.0
dhcp_server_pool_start = 192.168.2.10
dhcp_server_leasetime = 600
dhcp_server_gateway = 192.168.2.1

[WLAN]
ssid_wlan = 
pwd_wlan = 
ipaddr_wlan = 

[USB_ETHERNET]
ipaddr_eth = 
netmask_eth = 255.255.255.0

[HNAP_NETWORK]
ipaddr_tap = 
netmask_tap = 255.255.255.240
dhcp_server_pool_start_tap = 
dhcp_server_leasetime_tap = 600
dhcp_server_gateway_tap = 

[NAT]
nat_interface = HNAP_NETWORK

[BRIDGE]
master_interface = 
slave_interface_1 = 
dl1com commented 3 years ago

Current default settings:

[NETWORK]
hostname = pluto
ipaddr = 192.168.2.1
netmask = 255.255.255.0
dhcp_server_pool_start = 192.168.2.10
dhcp_server_leasetime = 600
dhcp_server_gateway = 192.168.2.1
dhcp_server_dns = 192.168.2.1

[WLAN]
ssid_wlan = 
pwd_wlan = 
ipaddr_wlan = 

[USB_ETHERNET]
ipaddr_eth = 
netmask_eth = 255.255.255.0

[HNAP_NETWORK]
ipaddr_tap = 
netmask_tap = 255.255.255.240
dhcp_server_pool_start_tap = 
dhcp_server_leasetime_tap = 600
dhcp_server_gateway_tap = 
dhcp_server_dns_tap = 

[NAT]
nat_interface = HNAP_NETWORK

[BRIDGE]
bridge_master_interface = 
bridge_slave_interface_1 = 

Known issues:

dl1com commented 3 years ago

After some discussion with @dg8ngn, we'll do some changes to optimize bridge config:

[NETWORK]
nat = yes       --> "pre-up iptables -t nat -A POSTROUTING -o usb -j MASQUERADE"
[WLAN]
nat_wlan = yes  --> "pre-up iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE"
[USB_ETHERNET]
nat_eth = yes   --> "pre-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE"
[HNAP_NETWORK]
nat_tap = yes   --> "pre-up iptables -t nat -A POSTROUTING -o tap0 -j MASQUERADE"
dl1com commented 3 years ago

Current config.txt default settings:

[NETWORK]
hostname = pluto
ipaddr = 192.168.2.1
netmask = 255.255.255.0
nat = 
bridge = 
dhcp_server_pool_start = 192.168.2.10
dhcp_server_leasetime = 600
dhcp_server_gateway = 192.168.2.1
dhcp_server_dns = 192.168.2.1

[WLAN]
ssid_wlan = 
pwd_wlan = 
ipaddr_wlan = 
nat_wlan = 
bridge_wlan = 

[USB_ETHERNET]
ipaddr_eth = 
netmask_eth = 255.255.255.0
nat_eth = 
bridge_eth = 
dhcp_server_pool_start_eth = 
dhcp_server_leasetime_eth = 600
dhcp_server_gateway_eth = 
dhcp_server_dns_eth = 

[HNAP_NETWORK]
ipaddr_tap = 
netmask_tap = 255.255.255.240
nat_tap = 
bridge_tap = 
dhcp_server_pool_start_tap = 
dhcp_server_leasetime_tap = 600
dhcp_server_gateway_tap = 
dhcp_server_dns_tap = 

Bridging Example:

config.txt:

[NETWORK]
hostname = pluto
ipaddr = 192.168.2.1
netmask = 255.255.255.0
nat =
bridge = 
dhcp_server_pool_start = 192.168.2.10
dhcp_server_leasetime = 600
dhcp_server_gateway = 192.168.2.1
dhcp_server_dns = 192.168.2.1

[WLAN]
ssid_wlan = 
pwd_wlan = 
ipaddr_wlan = 
nat_wlan = 
bridge_wlan = 

[USB_ETHERNET]
ipaddr_eth = 
netmask_eth = 255.255.255.0
nat_eth = 
bridge_eth = master
dhcp_server_pool_start_eth = 
dhcp_server_leasetime_eth = 600
dhcp_server_gateway_eth = 
dhcp_server_dns_eth = 

[HNAP_NETWORK]
ipaddr_tap = 
netmask_tap = 255.255.255.240
nat_tap = 
bridge_tap = slave
dhcp_server_pool_start_tap = 
dhcp_server_leasetime_tap = 600
dhcp_server_gateway_tap = 
dhcp_server_dns_tap = 

-> /etc/network/interfaces:

auto lo
iface lo inet loopback

auto usb0
iface usb0 inet static
        address 192.168.2.1
        netmask 255.255.255.0

auto br0
iface br0 inet dhcp
    pre-up tunctl -t tap0
    pre-up brctl addbr br0
    pre-up brctl addif br0 eth0
    pre-up brctl addif br0 tap0

Known issues: