Data Communication Between Ethernet and WiFi in OpenWRT System

The OpenWRT system achieves data transmission between Ethernet (wired) and WiFi (wireless) through a multi-layer network architecture design and inter-process communication (IPC) mechanisms. Its core design includes network interface bridging, inter-process communication framework (ubus), firewall and routing rules, and unified configuration management system. The following are the specific implementation principles and key components:

1. Network Interface Bridging and Grouping

OpenWRT abstracts physical devices (such as network cards and wireless radios) as <span>device</span>, and achieves logical grouping and bridging through <span>interface</span> and <span>network</span>:

  • Device Layer such as <span>eth0</span> (wired Ethernet), <span>radio0</span> (wireless network card), and other physical devices.
  • Interface Layer virtual interfaces (such as <span>wlan0</span> for WiFi clients, <span>wlan1</span> for AP mode), supporting various network roles (such as STA, AP).
  • Network Layer merges multiple interfaces into a single logical network through bridging (<span>bridge</span>). For example, bridging <span>eth0</span> (LAN port) and <span>wlan0</span> (WiFi) into <span>br-lan</span> allows wired and wireless devices to be on the same local area network, enabling direct communication.
    • Configuration example: Define bridging in <span>/etc/config/network</span>, or bind the LAN port to the wireless interface through the LUCI interface.

2. Inter-Process Communication Framework (ubus)

OpenWRT uses a lightweight IPC framework ubus to coordinate data exchange between different services:

  • Object and Method Calls services (such as <span>network.interface.lan</span>) register objects and methods through ubus, allowing other processes to call these methods to obtain or modify network status (such as getting IP addresses, restarting interfaces).
    • For example: The WiFi service notifies the network interface to update configuration through ubus, triggering synchronization between wired and wireless.
  • Event Notifications ubus supports broadcasting events (such as changes in WiFi connection status), and related services (such as DHCP, firewall) can subscribe and respond.
  • Efficiency based on Unix domain sockets and TLV message format, suitable for low resource consumption in embedded devices.

3. Firewall and Routing Rules

Data forwarding relies on iptables rules and routing table configuration:

  • Zone Division OpenWRT divides the network into different security zones (such as <span>lan</span>, <span>wan</span>), defining traffic forwarding policies.
    • For example: Allow <span>lan</span> to <span>wan</span> NAT forwarding, enabling wireless devices to access the internet through the wired WAN port.
  • MASQUERADE Rules implement NAT conversion, allowing internal network devices to share a public IP.
  • IP Forwarding Enablement must be set in <span>/etc/sysctl.conf</span> as <span>net.ipv4.ip_forward=1</span>.

4. Unified Configuration Management System

OpenWRT manages network configurations centrally through UCI (Unified Configuration Interface):

  • Configuration Files such as <span>/etc/config/network</span> (interfaces), <span>/etc/config/wireless</span> (WiFi), <span>/etc/config/firewall</span> (rules).
  • Dynamic Effectiveness After modifying configurations, reload services through <span>ubus</span> or <span>/etc/init.d/network restart</span>.

5. Practical Application Scenarios

  • Wireless to Wired Use WiFi as a WAN port, bridging the LAN port to the wireless network, allowing wired devices to connect to the internet through the upstream WiFi.
    • Key Steps: Disable DHCP on LAN, bridge LAN and WiFi interfaces, manage devices through the WAN port.
  • Multi-Port Load Balancing Combine routing policies and ubus calls to achieve traffic distribution.

OpenWRT achieves physical layer interoperability through bridging technology, ensures efficient communication between services through the ubus framework, controls data flow through firewall and routing rules, and unifies configuration management through the UCI system. This modular design allows flexible and efficient data transmission between Ethernet and WiFi, suitable for embedded scenarios such as routers and gateways.

Leave a Comment