'Execute Openwrt UCI add_list through ubus call

I am trying to add a new interface to the network.lan.ifname using the "ubus call uci add_list .."

The syntax used to run it directly is (which is working):

uci add_list network.lan.ifname="new_iface_name"

I have tried using the following shell commands to add the interface to the list using the ubus call:

  1. with option defined separately
ubus call uci add_list '{"config" : "network", "section" : "lan", "option" : "ifname", "values" : "new_iface_name"}}'

this results with following error message:

Command failed: Method not found
  1. without option (section and then values)
ubus call uci add_list '{"config" : "network", "section" : "lan", "values" : {"ifname"="new_iface_name"}}'

this results with the same error message:

Command failed: Method not found
  1. improvisation
ubus call uci add_list '{"config" : "network", "section" : "lan", "valures" : {"ifname"="adam"}}

this results with failure to parse message:

Failed to parse message data

thanks in advance to anyone who can shed some light on the right syntax required



Solution 1:[1]

You need to make sure that there is "add_list" on the ubus.

ubus -v list uci
'uci' @387e9297
        "configs":{}
        "get":{"config":"String","section":"String","option":"String","type":"String","match":"Table","ubus_rpc_session":"String"}
        "state":{"config":"String","section":"String","option":"String","type":"String","match":"Table","ubus_rpc_session":"String"}
        "add":{"config":"String","type":"String","name":"String","values":"Table","ubus_rpc_session":"String"}
        "set":{"config":"String","section":"String","type":"String","match":"Table","values":"Table","ubus_rpc_session":"String"}
        "delete":{"config":"String","section":"String","type":"String","match":"Table","option":"String","options":"Array","ubus_rpc_session":"String"}
        "rename":{"config":"String","section":"String","option":"String","name":"String","ubus_rpc_session":"String"}
        "order":{"config":"String","sections":"Array","ubus_rpc_session":"String"}
        "changes":{"config":"String","ubus_rpc_session":"String"}
        "revert":{"config":"String","ubus_rpc_session":"String"}
        "commit":{"config":"String","ubus_rpc_session":"String"}
        "apply":{"rollback":"Boolean","timeout":"Integer","ubus_rpc_session":"String"}
        "confirm":{"ubus_rpc_session":"String"}
        "rollback":{"ubus_rpc_session":"String"}
        "reload_config":{}

Here is the code in rpcd.

static const struct ubus_method uci_methods[] = {
        { .name = "configs", .handler = rpc_uci_configs },
        UBUS_METHOD("get",      rpc_uci_get,      rpc_uci_get_policy),
        UBUS_METHOD("state",    rpc_uci_state,    rpc_uci_get_policy),
        UBUS_METHOD("add",      rpc_uci_add,      rpc_uci_add_policy),
        UBUS_METHOD("set",      rpc_uci_set,      rpc_uci_set_policy),
        UBUS_METHOD("delete",   rpc_uci_delete,   rpc_uci_delete_policy),
        UBUS_METHOD("rename",   rpc_uci_rename,   rpc_uci_rename_policy),
        UBUS_METHOD("order",    rpc_uci_order,    rpc_uci_order_policy),
        UBUS_METHOD("changes",  rpc_uci_changes,  rpc_uci_config_policy),
        UBUS_METHOD("revert",   rpc_uci_revert,   rpc_uci_config_policy),
        UBUS_METHOD("commit",   rpc_uci_commit,   rpc_uci_config_policy),
        UBUS_METHOD("apply",    rpc_uci_apply,    rpc_uci_apply_policy),
        UBUS_METHOD("confirm",  rpc_uci_confirm,  rpc_uci_rollback_policy),
        UBUS_METHOD("rollback", rpc_uci_rollback, rpc_uci_rollback_policy),
        UBUS_METHOD_NOARG("reload_config", rpc_uci_reload),
    };

Solution 2:[2]

Use "set" or "add" methods depending on your use cases: Using the system ntp server as example:

ubus call uci set '{"config":"system","type":"timeserver","section":"ntp","values":{"enabled":"1","server":["0.openwrt.pool.ntp.org","1.openwrt.pool.ntp.org"]}}'

uci show system.ntp.server
system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org'

Using set you should pass in the list option value as an array object with all the entries you want to set. It re-write the whole list option with the new values.

If you just want to add a single value, use "add", but note the you must provide the "name", otherwise a new unnamed section will get created.

ubus call uci add '{"config":"system","type":"timeserver","name":"ntp","values":{"server":["add4.openwrt.pool.ntp.org"]}}'

uci show system.ntp.server
system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' 'add4.openwrt.pool.ntp.org'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2