Error while adding network interface via uci

I am using OpenWrt 23.05 for my Intel based VM and I need to add the following interfaces via uci;

config interface 'lan0'
        option device 'port0'
        option proto 'static'
        option ipaddr '10.240.215.26'
        option netmask '255.255.255.0'
        option gateway '10.240.215.1'
 
config interface 'lan2'
        option device 'port2'
        option proto 'static'
        option ipaddr '192.168.200.1'
        option netmask '255.255.255.0'
 
config interface 'lan3'
        option device 'port3'
        option proto 'static'
        option ipaddr '192.168.20.1'
        option netmask '255.255.255.0'
 

But getting this "uci: Invalid argument" while adding the interfaces.

root@mcphost-test:/data/mcp/network-scripts# uci set network.lan0.device="port0"
uci: Invalid argument
root@mcphost-test:/data/mcp/network-scripts#
root@mcphost-test:/data/mcp/network-scripts# uci add network interface lan0
Usage: uci [<options>] <command> [<arguments>]

Commands:
        batch
        export     [<config>]
        import     [<config>]
        changes    [<config>]
        commit     [<config>]
        add        <config> <section-type>
        add_list   <config>.<section>.<option>=<string>
        del_list   <config>.<section>.<option>=<string>
        show       [<config>[.<section>[.<option>]]]
        get        <config>.<section>[.<option>]
        set        <config>.<section>[.<option>]=<value>
        delete     <config>[.<section>[[.<option>][=<id>]]]
        rename     <config>.<section>[.<option>]=<name>
        revert     <config>[.<section>[.<option>]]
        reorder    <config>.<section>=<position>

Options:
        -c <path>  set the search path for config files (default: /etc/config)
        -d <str>   set the delimiter for list values in uci show
        -f <file>  use <file> as input instead of stdin
        -m         when importing, merge data into an existing package
        -n         name unnamed sections on export (default)
        -N         don't name unnamed sections
        -p <path>  add a search path for config change files
        -P <path>  add a search path for config change files and use as default
        -t <path>  set save path for config change files
        -q         quiet mode (don't print error messages)
        -s         force strict mode (stop on parser errors, default)
        -S         disable strict mode
        -X         do not use extended syntax on 'show'

root@mcphost-test:/data/mcp/network-scripts# 

Did I miss anything else ?

The ports are likely named eth0, eth1, etc.

Try that instead of port0, port1.

Do we need to add only the ports defined ? If so where can I find all the port names ??

I just told you - eth0 to ethx where x = number of Ethernet ports - 1

2 Likes

or just edit the /etc/config/network file you posted, and replace port with eth.

1 Like

I am still getting that invalid uci entry error though I added the correct interface name.

root@mcphost-test:/data/mcp/network-scripts# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: port0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br-lan state UP group default qlen 1000
    link/ether 00:0c:29:29:a2:64 brd ff:ff:ff:ff:ff:ff
3: port1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:b2:6a:c7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.17.200/24 brd 192.168.17.255 scope global port1
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:feb2:6ac7/64 scope link
       valid_lft forever preferred_lft forever
37: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:29:a2:64 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan
       valid_lft forever preferred_lft forever
root@mcphost-test:/data/mcp/network-scripts# uci show network
network.loopback=interface
network.loopback.device='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='fd84:4dd9:a16d::/48'
network.@device[0]=device
network.@device[0].name='br-lan'
network.@device[0].type='bridge'
network.@device[0].ports='port0'
network.lan=interface
network.lan.device='br-lan'
network.lan.proto='static'
network.lan.ipaddr='192.168.1.1'
network.lan.netmask='255.255.255.0'
network.lan.ip6assign='60'
network.wan=interface
network.wan.device='port1'
network.wan.proto='static'
network.wan.ipaddr='192.168.17.200'
network.wan.netmask='255.255.255.0'
network.wan.gateway='192.168.17.1'
network.route_wan_def=route
network.route_wan_def.interface='wan'
network.route_wan_def.target='0.0.0.0/0'
network.route_wan_def.table='default'
network.route_wan_def.gateway='192.168.17.1'
network.@interface[3]=interface
network.@interface[4]=interface
root@mcphost-test:/data/mcp/network-scripts# uci add network interface port0
Usage: uci [<options>] <command> [<arguments>]

Commands:
        batch
        export     [<config>]
        import     [<config>]
        changes    [<config>]
        commit     [<config>]
        add        <config> <section-type>
        add_list   <config>.<section>.<option>=<string>
        del_list   <config>.<section>.<option>=<string>
        show       [<config>[.<section>[.<option>]]]
        get        <config>.<section>[.<option>]
        set        <config>.<section>[.<option>]=<value>
        delete     <config>[.<section>[[.<option>][=<id>]]]
        rename     <config>.<section>[.<option>]=<name>
        revert     <config>[.<section>[.<option>]]
        reorder    <config>.<section>=<position>

Options:
        -c <path>  set the search path for config files (default: /etc/config)
        -d <str>   set the delimiter for list values in uci show
        -f <file>  use <file> as input instead of stdin
        -m         when importing, merge data into an existing package
        -n         name unnamed sections on export (default)
        -N         don't name unnamed sections
        -p <path>  add a search path for config change files
        -P <path>  add a search path for config change files and use as default
        -t <path>  set save path for config change files
        -q         quiet mode (don't print error messages)
        -s         force strict mode (stop on parser errors, default)
        -S         disable strict mode
        -X         do not use extended syntax on 'show'

root@mcphost-test:/data/mcp/network-scripts# uci set network.port0.name="port0"
uci: Invalid argument
root@mcphost-test:/data/mcp/network-scripts# uci set network.port0.name='port0'
uci: Invalid argument
root@mcphost-test:/data/mcp/network-scripts#
root@mcphost-test:/data/mcp/network-scripts# uci set network.port0.name='port0'
uci: Invalid argument
root@mcphost-test:/data/mcp/network-scripts# uci set network.eth0.name='port0'
uci: Invalid argument
root@mcphost-test:/data/mcp/network-scripts# uci set network.eth1.name='port1'
uci: Invalid argument
root@mcphost-test:/data/mcp/network-scripts#

what part of "don't use portX" was hard to understand, twice ?

I renamed the existing interfaces eth0 and eth1 to port0 and port1. But using both the older and newer names are working as expected - why ?

Sorry typo - I renamed the existing interfaces eth0 and eth1 to port0 and port1. But using both the older and newer names are not working as expected - why ?

Are you willing to show that to us?

Everything I see says portx.

You could have edited your post instead of posting twice with a correction.

1 Like

Yes we have the hotplug script - /etc/hotplug.d/iface/30-intf-rename which will rename existing interface names.

INTF1=port0
INTF2=port1
INTF3=port2



intf_rename() {
   PCI_ID=$1
   PCI_SLOT_NAME=$2
   INTF_NAME=$3

   case "$PCI_ID" in
      ## Rule set for:
      ##   * Following are the config rules for ESXi vMCP
      ##   * Note: vendor id 0x15ad is VMware
      "15AD")
      case "$PCI_SLOT_NAME" in
         "0000:03:00.0")
            echo "Interface name $INTF_NAME will be renamed as $INTF1" > /dev/kmsg
            uci set network.@device[0].ports=$INTF1
            intf_set_network "$INTF_NAME" $INTF1
            ;;
          "0000:0b:00.0")
             echo "Interface name $INTF_NAME will be renamed as $INTF2" > /dev/kmsg
             uci set network.wan.device=$INTF2
             intf_set_network "$INTF_NAME" $INTF2
             ;;
...
}

if [ "$ACTION" = ifup ]; then
   list=$(find /sys/class/net/*/device/uevent)

   for file in $list
   do
      INTF_NAME="$(echo "$file" | awk -F '/' '{print $5}')"
      ## No need to rename interface if its already renamed.
      if [ "$INTF_NAME" = "port0" ] || [ "$INTF_NAME" = "port1" ] || [ "$INTF_NAME" = "port2" ]; then
         continue
      fi

      PCI_ID="$(grep "PCI_ID" "$file" | awk -F '=' '{print $2}'  | awk -F ':' '{print $1}')"
      PCI_SLOT_NAME="$(grep "PCI_SLOT_NAME" "$file" | awk -F '=' '{print $2}')"
      intf_rename "$PCI_ID" "$PCI_SLOT_NAME" "$INTF_NAME"
   done
fi

I must have misunderstood the discussion until now.

Is there a reason you're still attempting to rename the interfaces after being told the issue (mutiple times)?

I dont have any issues in renaming interfaces. Its working fine. When I tried to add entries for that interface (port0 and port1), am getting invalid uci entry. So seeking help for setting the values for interface using uci. Can we add uci entry for the renamed interfaces ?

Any updates for me regarding this "uci: Invalid argument" issue ?

Are you willing to answer the inquiry:

?

There may be another method to solve your issue.

We have some 4/5 LAN interfaces which we already renamed to port0 to port4 and we need this renaming to use this renamed interfaces in some of the modules.

I guess there's a language barrier. I'm sure someone else will see the thread and be able to assist.

This means that there is currently no interface named lan0.

The correct way to add a new interface named lan0 is

uci set network.lan0='interface'

Then use that name to set everything else

uci set network.lan0.device='eth0'
uci set network.lan0.proto='static'
...

To rename an interface

uci rename network.lan0='port0'

You should then start using the new name if you want to modify or add interface options.

3 Likes

Thanks a bunch @pavelgl , you resolved my query. This is what I inquired right from the beginning. thanks once again.