iopsys-feed/netmode
2025-10-20 17:45:57 +02:00
..
files netmode: set default netmode 2025-10-20 17:45:57 +02:00
bbfdm_service.json netmode: datamodel vendor extension 2025-05-02 18:00:07 +05:30
Makefile netmode: 1.1.5 2025-06-20 12:43:21 +05:30
README.md netmode: Add README 2024-08-13 11:57:32 +02:00

Creating Custom Netmodes in IOWRT

This guide provides developers with detailed instructions on how to create and manage custom network modes (netmodes) in IOWRT. The netmode script allows for flexible network configuration, and developers can define their own modes by structuring the necessary files and scripts within the /etc/netmodes/ directory.

Table of Contents

  1. Overview of Netmodes
  2. Directory Structure
  3. Creating a Custom Netmode
  4. Enabling and Switching Netmodes

Overview of Netmodes

Netmodes in IOWRT provide a way to switch between different network configurations based on the needs of the environment. Developers can create custom netmodes by organizing scripts and configuration files in specific directories under /etc/netmodes/<NETMODE_NAME>.

Directory Structure

A custom netmode is defined within the /etc/netmodes/<NETMODE_NAME> directory, which should contain the following subdirectories:

  • /lib/netmode/pre/: Generic scripts executed before the netmode-specific configurations are applied.
  • /etc/netmodes/<NETMODE_NAME>/uci/: Contains UCI configuration files that will be copied to /etc/config/ during the application of the netmode.
  • /etc/netmodes/<NETMODE_NAME>/scripts/: Custom scripts specific to the netmode that are executed after the UCI configurations are applied.
  • /lib/netmode/post/: Generic scripts executed after the netmode-specific configurations are completed.

Creating a Custom Netmode

To create a new netmode, follow these steps:

Step 1: Pre-Execution Scripts

Scripts located in /lib/netmode/pre/ are executed before any mode-specific actions. These are typically used for preparing the system or cleaning up configurations from the previous netmode.

  • Create Pre-Execution Scripts:
    • Place your generic pre-execution scripts in /lib/netmode/pre/.
    • Example script (/lib/netmode/pre/cleanup.sh):
      #!/bin/sh
      echo "Cleaning up old network configurations..."
      # Add commands here
      

Step 2: UCI Configuration Files

The UCI configuration files stored in /etc/netmodes/<NETMODE_NAME>/uci/ will be copied to /etc/config/, effectively applying the desired network configuration.

  • Place UCI Config Files:
    • Create UCI configuration files under /etc/netmodes/<NETMODE_NAME>/uci/.
    • Example (/etc/netmodes/bridge/uci/network):
config device 'br_lan'
        option name 'br-lan'
        option type 'bridge'
        option multicast_to_unicast '0'
        option bridge_empty '1'
        list ports 'eth1'
        list ports 'eth3'
        list ports 'eth4'

config interface 'lan'
        option proto 'dhcp'
        option device 'br-lan'
        option force_link '1'
        option reqopts '43 125'

Step 3: Custom Execution Scripts

After the UCI files are applied, any scripts in /etc/netmodes/<NETMODE_NAME>/scripts/ are executed. These can be used to perform additional configuration tasks that are specific to the netmode.

  • Create Custom Scripts:
    • Add scripts to /etc/netmodes/<NETMODE_NAME>/scripts/.
    • Example (/etc/netmodes/bridge/scripts/setup_bridge.sh):
      #!/bin/sh
      echo "Setting up bridge mode..."
      # Additional configuration commands here
      

Step 4: Post-Execution Scripts

Finally, the generic scripts in /lib/netmode/post/ are executed. These scripts typically finalize the setup or perform any necessary cleanups.

  • Create Post-Execution Scripts:
    • Place scripts in /lib/netmode/post/.
    • Example script (/lib/netmode/post/restart_services.sh):
      #!/bin/sh
      echo "Restarting network services..."
      # Add commands here
      

Enabling and Switching Netmodes

The netmode mechanism can be enabled or disabled via the UCI configuration, and you can switch between netmodes using UCI commands.

  • Enable Netmode:

    uci set netmode.global.enabled=1
    uci commit netmode
    
  • Switch Netmode:

    uci set netmode.global.mode='<NETMODE_NAME>'
    uci commit netmode