(ipq40xx) Why do the initially configured interfaces use anonymous sections?

Hello,

I'm trying to build a mesh of access points with batman, and among other things that I think I've already figured out, I need to set the following options on first boot:

  • Set the MTU of the automatically generated WAN device
  • Rename br-lan to br-net
  • Modify the IP/DNS configuration of the lan interface and attach it to a VLAN device

Unfortunately these options are in anonymous sections, so I can't think of a way to access them without resorting to negative-indexing. I considered just blowing away every anonymous section and starting over, but this makes a huge mess and it's not practical without re-implementing tons of board-specific code to pull the MAC addresses from /dev/mtd, rebuild br-lan with the appropriate switch ports, etc.

This dilemma left me with 3 questions:

  1. Why are these default sections anonymous?
  2. Is it possible to modify the build so they are named without having to re-implement the logic in uci-defaults.sh?
  3. If I can't make them named somehow, is it possible to access/set options in the anonymous sections explicitly without using negative-indexing? I have an idea in my head that somehow I could retrieve their auto-generated CFGID by searching the name option in each section, but I don't know where I'd start with practically implementing this. Is it even possible? I want to avoid negative-indexing by any means necessary because it feels too fragile/hacky for comfort.

Thanks,
--tyami94

i think you are after the foreach function ...

save this script some place on the router and play with it

/tmp/uci-test.sh

#!/bin/sh
. /lib/functions.sh

# Callback function to execute for each section
find_interfaces() {
    local section="$1"
    config_get name "$section" name
    echo "Interface section: $section, Network name: $name"
}

# Iterate over all sections of ["type"]  in /etc/config/network
config_load network
config_foreach find_interfaces $1

then you can fiddle with it like so

root@OpenWrt:~# cd /tmp
root@OpenWrt:/tmp# chmod +x uci-test.sh

root@OpenWrt:/tmp# ./uci-test.sh interface
Interface section: loopback, Network name: 
Interface section: lan, Network name: 
Interface section: wan, Network name: 
Interface section: wan6, Network name: 
Interface section: wwan, Network name: 

root@OpenWrt:/tmp# ./uci-test.sh device
Interface section: cfg030f15, Network name: br-lan

notice the config_get function aswell :wink: then you have the section name and can access like you requested

root@OpenWrt:/tmp# uci get network.cfg030f15
device

root@OpenWrt:/tmp# uci get network.cfg030f15.name
br-lan

root@OpenWrt:/tmp# uci get network.cfg030f15.ports
lan1 lan2

1 Like

Oooooh thats fancy! I'll have to give that a shot, because I think that's exactly what I need. I'll try it and report back. Thanks!

1 Like