Feature #11626: ports uci deprecated

This commit is contained in:
Amin Ben Romdhane 2023-08-10 11:55:38 +00:00
parent 70a0917cc4
commit 260bdc099a
10 changed files with 232 additions and 185 deletions

View file

@ -133,6 +133,7 @@ extern char *RateAdjAlgorithm[];
#define DHCP_LEASES_FILE "/tmp/dhcp.leases"
#define DHCP_CLIENT_OPTIONS_FILE "/var/dhcp.client.options"
#define SYSTEM_CERT_PATH "/etc/ssl/certs"
#define BOARD_JSON_FILE "/etc/board.json"
#define DMMAP "dmmap"
#define LIST_KEY (const char *[])
#define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)

View file

@ -930,6 +930,18 @@ bool dmuci_string_to_boolean(char *value)
return false;
}
bool dmuci_is_option_value_empty(struct uci_section *s, char *option_name)
{
char *option_value = NULL;
if (!s || !option_name)
return false;
dmuci_get_value_by_section_string(s, option_name, &option_value);
return (DM_STRLEN(option_value) == 0) ? true : false;
}
int dmuci_get_section_name(char *sec_name, char **value)
{
if (!sec_name)

View file

@ -393,6 +393,7 @@ int dmuci_set_value_varstate(char *package, char *section, char *option, char *v
int dmuci_get_section_name(char *sec_name, char **value);
int dmuci_set_section_name(char *sec_name, char *str, size_t size);
bool dmuci_string_to_boolean(char *value);
bool dmuci_is_option_value_empty(struct uci_section *s, char *option_name);
#endif

View file

@ -20321,9 +20321,9 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport"
"type": "device"
}
}
}
@ -20401,11 +20401,11 @@
"mapping": {
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport"
"type": "device"
},
"dmmapfile": "dmmap_ports"
"dmmapfile": "dmmap_ethernet"
}
},
"Enable": {
@ -20422,9 +20422,9 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
@ -20479,13 +20479,13 @@
{
"type": "uci",
"uci": {
"file": "dmmap_ports",
"file": "dmmap_network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
"name": "eth_port_alias"
"name": "eth_iface_alias"
}
}
}
@ -20510,13 +20510,13 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
"name": "ifname"
"name": "name"
}
}
}
@ -20570,22 +20570,7 @@
"usp"
],
"description": "Indicates whether the interface points towards the Internet (<<true>>) or towards End Devices (<<false>>). For example: * For an Internet Gateway Device, <<param>> will be <<true>> for all WAN interfaces and <<false>> for all LAN interfaces. * For a standalone WiFi Access Point that is connected via Ethernet to an Internet Gateway Device, <<param>> will be <<true>> for the Ethernet interface and <<false>> for the WiFi Radio interface. * For an End Device, <<param>> will be <<true>> for all interfaces.",
"datatype": "boolean",
"mapping": [
{
"type": "uci",
"uci": {
"file": "ports",
"section": {
"type": "ethport",
"index": "@i-1"
},
"option": {
"name": "uplink"
}
}
}
]
"datatype": "boolean"
},
"MACAddress": {
"type": "string",
@ -20646,9 +20631,9 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
@ -20702,9 +20687,9 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
@ -20739,9 +20724,9 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
@ -21838,9 +21823,9 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
@ -21889,7 +21874,7 @@
"uci": {
"file": "dmmap_eth_rmon",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
@ -21918,13 +21903,13 @@
{
"type": "uci",
"uci": {
"file": "ports",
"file": "network",
"section": {
"type": "ethport",
"type": "device",
"index": "@i-1"
},
"option": {
"name": "ifname"
"name": "name"
}
}
}
@ -41796,11 +41781,11 @@
"uci": {
"file": "dmmap_wireless",
"section": {
"type": "wifi-iface",
"type": "ssid",
"index": "@i-1"
},
"option": {
"name": "ssidalias"
"name": "ssid_alias"
}
}
}

View file

@ -196,6 +196,10 @@ static void bridge_remove_related_device_section(struct uci_section *bridge_s)
struct uci_section *s = NULL, *stmp = NULL;
uci_foreach_option_eq_safe("network", "device", "name", e->name, stmp, s) {
if (dmuci_is_option_value_empty(s, "type"))
continue;
dmuci_delete_by_section(s, NULL, NULL);
}
}
@ -355,6 +359,9 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi
if (s == NULL)
continue;
if (dmuci_is_option_value_empty(s, "type"))
continue;
dmuci_get_value_by_section_string(s, "ifname", &dev_ifname);
if (DM_STRLEN(dev_ifname) == 0)
continue;
@ -658,10 +665,13 @@ static void dmmap_synchronizeBridgingBridgeVLAN(struct dmctx *dmctx, DMNODE *par
uci_foreach_option_eq("network", "device", "name", e->name, s) {
char *vid = NULL;
if (dmuci_is_option_value_empty(s, "type"))
continue;
dmuci_get_value_by_section_string(s, "vid", &vid);
if (vid && vid[0] == '\0') {
char *ifname = (!ethernet___is_ethernet_interface_inst(e->name)) ? DM_STRRCHR(e->name, '.') : NULL;
char *ifname = (!ethernet___get_ethernet_interface_section(e->name)) ? DM_STRRCHR(e->name, '.') : NULL;
if (ifname) vid = dmstrdup(ifname+1);
}
@ -720,6 +730,9 @@ static void dmmap_synchronizeBridgingBridgeVLANPort(struct dmctx *dmctx, DMNODE
uci_foreach_option_eq("network", "device", "name", e->name, s) {
if (dmuci_is_option_value_empty(s, "type"))
continue;
if (is_section_exist("dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", args->br_inst, "name", e->name))
break;
@ -892,8 +905,8 @@ static void get_bridge_port_device_section(struct uci_section *bridge_port_dmmap
if (DM_STRLEN(port) == 0)
return;
/* Find the ethport ports section corresponding to this device */
uci_foreach_option_eq("ports", "ethport", "ifname", port, s) {
/* Find the device port section corresponding to this device */
if ((s = ethernet___get_ethernet_interface_section(port))) {
*device_section = s;
return;
}
@ -924,7 +937,7 @@ static void remove_vlanid_from_bridge_secions(struct uci_section *bridge_sec, st
return;
uci_foreach_element_safe(device_ports, tmp, e) {
char *vid = (!ethernet___is_ethernet_interface_inst(e->name)) ? DM_STRRCHR(e->name, '.') : NULL;
char *vid = (!ethernet___get_ethernet_interface_section(e->name)) ? DM_STRRCHR(e->name, '.') : NULL;
if (vid && curr_vid && DM_STRCMP(vid+1, curr_vid) == 0) {
struct uci_section *s = NULL;
@ -932,9 +945,14 @@ static void remove_vlanid_from_bridge_secions(struct uci_section *bridge_sec, st
char *enable = NULL;
s = get_dup_section_in_config_opt("network", "device", "name", e->name);
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (!s)
continue;
if (!s || DM_STRLEN(ifname) == 0)
if (dmuci_is_option_value_empty(s, "type"))
continue;
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (DM_STRLEN(ifname) == 0)
continue;
/* Update vid and name of device section */
@ -985,7 +1003,7 @@ static void remove_vlanport_section(struct uci_section *bridge_vlanport_sec, str
dmuci_get_value_by_section_string(port_s, "port", &port);
if (DM_STRLEN(port)) {
char *vid = (!ethernet___is_ethernet_interface_inst(port)) ? DM_STRRCHR(port, '.') : NULL;
char *vid = (!ethernet___get_ethernet_interface_section(port)) ? DM_STRRCHR(port, '.') : NULL;
if (vid) {
if (DM_STRCMP(enable, "1") == 0) {
@ -1390,8 +1408,12 @@ static int delObjBridgingBridgePort(char *refparam, struct dmctx *ctx, void *dat
// Remove ifname from device section
s = get_dup_section_in_config_opt("network", "device", "name", port);
dmuci_set_value_by_section(s, "ifname", "");
dmuci_set_value_by_section(s, "name", "");
if (s) {
if (!dmuci_is_option_value_empty(s, "type")) {
dmuci_set_value_by_section(s, "ifname", "");
dmuci_set_value_by_section(s, "name", "");
}
}
// Remove port from vlan port section
s = get_dup_section_in_dmmap_opt("dmmap_bridge_vlanport", "bridge_vlanport", "name", port);
@ -1417,8 +1439,12 @@ static int delObjBridgingBridgePort(char *refparam, struct dmctx *ctx, void *dat
// Remove ifname from device section
ss = get_dup_section_in_config_opt("network", "device", "name", port);
dmuci_set_value_by_section(ss, "ifname", "");
dmuci_set_value_by_section(ss, "name", "");
if (ss) {
if (!dmuci_is_option_value_empty(ss, "type")) {
dmuci_set_value_by_section(ss, "ifname", "");
dmuci_set_value_by_section(ss, "name", "");
}
}
// Remove ifname from vlan port section
ss = get_dup_section_in_dmmap_opt("dmmap_bridge_vlanport", "bridge_vlanport", "name", port);
@ -2092,7 +2118,7 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx,
remove_port_from_bridge_sections(args->bridge_sec, args->bridge_dmmap_sec, port_device);
}
char *tag = (!ethernet___is_ethernet_interface_inst(port_device)) ? DM_STRRCHR(port_device, '.') : NULL;
char *tag = (!ethernet___get_ethernet_interface_section(port_device)) ? DM_STRRCHR(port_device, '.') : NULL;
if (tag && !is_wireless_config) {
char new_name[32] = {0};
@ -2181,7 +2207,6 @@ static int get_BridgingBridgePort_PriorityRegeneration(char *refparam, struct dm
static int set_BridgingBridgePort_PriorityRegeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct bridge_port_args *args = ((struct bridge_port_args *)data);
char *type = NULL;
switch (action) {
case VALUECHECK:
@ -2191,8 +2216,7 @@ static int set_BridgingBridgePort_PriorityRegeneration(char *refparam, struct dm
if (args->is_management_port)
return 0;
dmuci_get_value_by_section_string(args->bridge_port_sec, "type", &type);
if (DM_STRLEN(type) == 0)
if (dmuci_is_option_value_empty(args->bridge_port_sec, "type"))
return FAULT_9007;
break;
@ -2508,7 +2532,7 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void
uci_foreach_element_safe(device_ports, tmp, e) {
char *vid = (!ethernet___is_ethernet_interface_inst(e->name)) ? DM_STRRCHR(e->name, '.') : NULL;
char *vid = (!ethernet___get_ethernet_interface_section(e->name)) ? DM_STRRCHR(e->name, '.') : NULL;
if (vid && curr_vid && DM_STRCMP(vid+1, curr_vid) == 0) {
struct uci_section *s = NULL;
@ -2517,9 +2541,14 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void
char name[16] = {0};
s = get_dup_section_in_config_opt("network", "device", "name", e->name);
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (!s)
continue;
if (!s || DM_STRLEN(ifname) == 0)
if (dmuci_is_option_value_empty(s, "type"))
continue;
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (DM_STRLEN(ifname) == 0)
continue;
snprintf(name, sizeof(name), "%s.%s", ifname, value);
@ -2767,7 +2796,7 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo
}
if (DM_STRCMP(type, "34984") != 0) { // type:34984=>'8021ad'
if (!ethernet___is_ethernet_interface_inst(port)) {
if (!ethernet___get_ethernet_interface_section(port)) {
char *tag = DM_STRRCHR(port, '.');
if (tag) tag[0] = '\0';
}

View file

@ -63,20 +63,23 @@ bool ethernet___check_vlan_termination_section(const char *name)
return true;
}
bool ethernet___is_ethernet_interface_inst(const char *device_name)
struct uci_section *ethernet___get_ethernet_interface_section(const char *device_name)
{
struct uci_section *s = NULL;
uci_foreach_sections("ports", "ethport", s) {
char *ifname = NULL;
uci_foreach_sections("network", "device", s) {
char *name = NULL;
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (!dmuci_is_option_value_empty(s, "type"))
continue;
if (DM_STRCMP(ifname, device_name) == 0)
return true;
dmuci_get_value_by_section_string(s, "name", &name);
if (DM_STRCMP(name, device_name) == 0)
return s;
}
return false;
return NULL;
}
static int eth_iface_sysfs(const struct uci_section *data, const char *name, char **value)
@ -177,10 +180,25 @@ static void dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_no
DM_STRNCPY(dev_name, device, sizeof(dev_name));
if (!ethernet___is_ethernet_interface_inst(dev_name)) {
if (!ethernet___get_ethernet_interface_section(dev_name)) {
struct uci_section *dev_s = NULL;
dev_s = get_dup_section_in_config_opt("network", "device", "name", dev_name);
char *has_vid = DM_STRRCHR(dev_name, '.');
if (has_vid)
*has_vid = '\0';
if (dev_s) { // Verify if the device has dual tags
char *type = NULL;
dmuci_get_value_by_section_string(dev_s, "type", &type);
if (DM_STRCMP(type, "8021ad") == 0) {
char *has_vid = DM_STRRCHR(dev_name, '.');
if (has_vid)
*has_vid = '\0';
}
}
}
if (is_mac_vlan_interface(dev_name)) {
@ -200,22 +218,26 @@ static void dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_no
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.Ethernet.Interface.{i}.!UCI:ports/ethport/dmmap_ports*/
/*#Device.Ethernet.Interface.{i}.!UCI:network/device/dmmap_ethernet*/
static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *ifname;
char *inst = NULL;
struct eth_port_args curr_eth_port_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ports", "ethport", "dmmap_ports", &dup_list);
synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_ethernet", &dup_list);
list_for_each_entry(p, &dup_list, list) {
char *name = NULL;
dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname);
if (!dmuci_is_option_value_empty(p->config_section, "type"))
continue;
init_eth_port(&curr_eth_port_args, p, ifname);
dmuci_get_value_by_section_string(p->config_section, "name", &name);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "eth_port_instance", "eth_port_alias");
init_eth_port(&curr_eth_port_args, p, name);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "eth_iface_instance", "eth_iface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, inst) == DM_STOP)
break;
@ -252,7 +274,8 @@ static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent
dmuci_get_value_by_section_string(p->config_section, "type", &type);
dmuci_get_value_by_section_string(p->config_section, "name", &name);
if (DM_LSTRCMP(type, "bridge") == 0 ||
if (DM_STRLEN(type) == 0 ||
DM_LSTRCMP(type, "bridge") == 0 ||
DM_LSTRCMP(type, "macvlan") == 0 ||
(*name != 0 && !ethernet___check_vlan_termination_section(name)) ||
(*name == 0 && strncmp(section_name(p->config_section), "br_", 3) == 0))
@ -269,19 +292,24 @@ static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent
static int browseEthernetRMONStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *ifname;
struct eth_rmon_args curr_eth_rmon_args = {0};
struct dmmap_dup *p = NULL;
json_object *res = NULL;
char *inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ports", "ethport", "dmmap_eth_rmon", &dup_list);
synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_eth_rmon", &dup_list);
list_for_each_entry(p, &dup_list, list) {
json_object *res = NULL;
char *name = NULL;
dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname);
if (!dmuci_is_option_value_empty(p->config_section, "type"))
continue;
dmubus_call("ethernet", "rmonstats", UBUS_ARGS{{"ifname", ifname, String}}, 1, &res);
if (!res) continue;
dmuci_get_value_by_section_string(p->config_section, "name", &name);
dmubus_call("ethernet", "rmonstats", UBUS_ARGS{{"ifname", name, String}}, 1, &res);
if (!res)
continue;
init_eth_rmon(&curr_eth_rmon_args, p, res);
@ -424,7 +452,9 @@ static int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void
dmuci_get_value_by_section_string(s_dev, "type", &type);
dmuci_get_value_by_section_string(s_dev, "name", &name);
if (DM_LSTRCMP(type, "bridge") == 0 ||
if (DM_STRLEN(type) == 0 ||
DM_LSTRCMP(type, "bridge") == 0 ||
DM_LSTRCMP(type, "macvlan") == 0 ||
(*name != 0 && !ethernet___check_vlan_termination_section(name)) ||
(*name == 0 && strncmp(section_name(s_dev), "br_", 3) == 0))
continue;
@ -449,7 +479,7 @@ static int get_Ethernet_FlowControlSupported(char *refparam, struct dmctx *ctx,
return 0;
}
/*#Device.Ethernet.InterfaceNumberOfEntries!UCI:ports/ethport/*/
/*#Device.Ethernet.InterfaceNumberOfEntries!UCI:network/device/*/
static int get_Ethernet_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int cnt = get_number_of_entries(ctx, data, instance, browseEthernetInterfaceInst);
@ -479,7 +509,7 @@ static int get_Ethernet_RMONStatsNumberOfEntries(char *refparam, struct dmctx *c
return 0;
}
/*#Device.Ethernet.Interface.{i}.Enable!UCI:ports/ethport,@i-1/enabled*/
/*#Device.Ethernet.Interface.{i}.Enable!UCI:network/device,@i-1/enabled*/
static int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((((struct eth_port_args *)data)->sections)->config_section, "enabled", "1");
@ -509,13 +539,13 @@ static int get_EthernetInterface_Status(char *refparam, struct dmctx *ctx, void
return get_net_device_status(((struct eth_port_args *)data)->ifname, value);
}
/*#Device.Ethernet.Interface.{i}.Alias!UCI:dmmap_ports/ethport,@i-1/eth_port_alias*/
/*#Device.Ethernet.Interface.{i}.Alias!UCI:dmmap_ethernet/device,@i-1/eth_port_alias*/
static int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_port_alias", value);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_iface_alias", value);
if ((*value)[0] == '\0') {
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "name", value);
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_port_alias", *value);
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_iface_alias", *value);
}
return 0;
}
@ -528,16 +558,16 @@ static int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_port_alias", value);
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_iface_alias", value);
return 0;
}
return 0;
}
/*#Device.Ethernet.Interface.{i}.Name!UCI:ports/ethport,@i-1/ifname*/
/*#Device.Ethernet.Interface.{i}.Name!UCI:network/device,@i-1/ifname*/
static int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "ifname", value);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "name", value);
return 0;
}
@ -606,10 +636,25 @@ static int set_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx,
return 0;
}
/*#Device.Ethernet.Interface.{i}.Upstream!UCI:ports/ethport,@i-1/uplink*/
static int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((((struct eth_port_args *)data)->sections)->config_section, "uplink", "0");
*value = "0";
if (!file_exists(BOARD_JSON_FILE))
return 0;
json_object *json_obj = json_object_from_file(BOARD_JSON_FILE);
if (!json_obj)
return 0;
char *device = dmjson_get_value(json_obj, 3, "network", "wan", "device");
if (DM_STRLEN(device) == 0)
goto end;
*value = (DM_STRCMP(device, ((struct eth_port_args *)data)->ifname) == 0) ? "1" : "0";
end:
json_object_put(json_obj);
return 0;
}
@ -619,7 +664,7 @@ static int get_EthernetInterface_MACAddress(char *refparam, struct dmctx *ctx, v
return eth_port_sysfs(data, "address", value);
}
/*#Device.Ethernet.Interface.{i}.MaxBitRate!UCI:ports/ethport,@i-1/speed*/
/*#Device.Ethernet.Interface.{i}.MaxBitRate!UCI:network/device,@i-1/speed*/
static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *autoneg = NULL;
@ -667,7 +712,7 @@ static int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ct
return 0;
}
/*#Device.Ethernet.Interface.{i}.DuplexMode!UCI:ports/ethport,@i-1/duplex*/
/*#Device.Ethernet.Interface.{i}.DuplexMode!UCI:network/device,@i-1/duplex*/
static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *autoneg = NULL;
@ -710,7 +755,7 @@ static int get_EthernetInterface_EEECapability(char *refparam, struct dmctx *ctx
return 0;
}
/*#Device.Ethernet.Interface.{i}.EEEEnable!UCI:ports/ethport,@i-1/eee*/
/*#Device.Ethernet.Interface.{i}.EEEEnable!UCI:network/device,@i-1/eee*/
static int get_EthernetInterface_EEEEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((((struct eth_port_args *)data)->sections)->config_section, "eee", "1");
@ -1015,13 +1060,13 @@ static int get_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void
DM_STRNCPY(buf, e->name, sizeof(buf));
if (!ethernet___is_ethernet_interface_inst(buf)) {
if (!ethernet___get_ethernet_interface_section(buf)) {
char *is_tagged = DM_STRRCHR(buf, '.');
if (is_tagged)
*is_tagged = 0;
}
port_s = get_dup_section_in_config_opt("ports", "ethport", "ifname", buf);
port_s = ethernet___get_ethernet_interface_section(buf);
char *pause = port_s ? dmuci_get_value_by_section_fallback_def(port_s, "pause", "0") : "0";
char *curr_value = dmuci_string_to_boolean(pause) ? "1" : "0";
@ -1037,7 +1082,7 @@ static int get_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void
} else {
/* Ethernet.Link.{i}. ---> Ethernet.Interface.{i}. */
port_s = get_dup_section_in_config_opt("ports", "ethport", "ifname", device);
port_s = ethernet___get_ethernet_interface_section(device);
char *pause = port_s ? dmuci_get_value_by_section_fallback_def(port_s, "pause", "0") : "0";
*value = dmuci_string_to_boolean(pause) ? "1" : "0";
return 0;
@ -1087,13 +1132,13 @@ static int set_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void
DM_STRNCPY(buf, e->name, sizeof(buf));
if (!ethernet___is_ethernet_interface_inst(buf)) {
if (!ethernet___get_ethernet_interface_section(buf)) {
char *is_tagged = DM_STRRCHR(buf, '.');
if (is_tagged)
*is_tagged = 0;
}
port_s = get_dup_section_in_config_opt("ports", "ethport", "ifname", buf);
port_s = ethernet___get_ethernet_interface_section(buf);
if (port_s)
dmuci_set_value_by_section(port_s, "pause", b ? "1" : "0");
}
@ -1102,7 +1147,7 @@ static int set_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void
} else {
/* Ethernet.Link.{i}. ---> Ethernet.Interface.{i}. */
port_s = get_dup_section_in_config_opt("ports", "ethport", "ifname", device);
port_s = ethernet___get_ethernet_interface_section(device);
if (port_s)
dmuci_set_value_by_section(port_s, "pause", b ? "1" : "0");
}
@ -1535,7 +1580,7 @@ static int get_EthernetVLANTerminationStats_MulticastPacketsReceived(char *refpa
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/multicast", value);
}
/*#Device.Ethernet.RMONStats.{i}.Enable!UCI:ports/ethport,@i-1/rmon*/
/*#Device.Ethernet.RMONStats.{i}.Enable!UCI:network/device,@i-1/rmon*/
static int get_EthernetRMONStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((((struct eth_rmon_args *)data)->sections)->config_section, "rmon", "1");
@ -1561,10 +1606,10 @@ static int set_EthernetRMONStats_Enable(char *refparam, struct dmctx *ctx, void
static int get_EthernetRMONStats_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifname = NULL, *status = NULL;
char *name = NULL, *status = NULL;
dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->config_section, "ifname", &ifname);
get_net_device_status(ifname, &status);
dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->config_section, "name", &name);
get_net_device_status(name, &status);
if (strncmp(status, "Up", 2) == 0) {
*value = "Enabled";
@ -1576,7 +1621,7 @@ static int get_EthernetRMONStats_Status(char *refparam, struct dmctx *ctx, void
return 0;
}
/*#Device.Ethernet.RMONStats.{i}.Alias!UCI:dmmap_eth_rmon/ethport,@i-1/eth_rmon_alias*/
/*#Device.Ethernet.RMONStats.{i}.Alias!UCI:dmmap_eth_rmon/device,@i-1/eth_rmon_alias*/
static int get_EthernetRMONStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return bbf_get_alias(ctx, (((struct eth_rmon_args *)data)->sections)->dmmap_section, "eth_rmon_alias", instance, value);
@ -1587,7 +1632,7 @@ static int set_EthernetRMONStats_Alias(char *refparam, struct dmctx *ctx, void *
return bbf_set_alias(ctx, (((struct eth_rmon_args *)data)->sections)->dmmap_section, "eth_rmon_alias", instance, value);
}
/*#Device.Ethernet.RMONStats.{i}.Name!UCI:ports/ethport,@i-1/ifname*/
/*#Device.Ethernet.RMONStats.{i}.Name!UCI:network/device,@i-1/ifname*/
static int get_EthernetRMONStats_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value(((struct eth_rmon_args *)data)->eth_rmon_obj, 1, "ifname");
@ -1598,7 +1643,7 @@ static int get_EthernetRMONStats_Interface(char *refparam, struct dmctx *ctx, vo
{
char *linker = NULL;
dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->config_section, "ifname", &linker);
dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->config_section, "name", &linker);
adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value);
return 0;
}
@ -1754,7 +1799,7 @@ DMOBJ tEthernetObj[] = {
{"Interface", &DMREAD, NULL, NULL, NULL, browseEthernetInterfaceInst, NULL, NULL, tEthernetInterfaceObj, tEthernetInterfaceParams, get_linker_interface, BBFDM_BOTH, LIST_KEY{"Name", "Alias", NULL}},
{"Link", &DMWRITE, addObjEthernetLink, delObjEthernetLink, NULL, browseEthernetLinkInst, NULL, NULL, tEthernetLinkObj, tEthernetLinkParams, get_linker_link, BBFDM_BOTH, LIST_KEY{"Name", "Alias", "MACAddress", NULL}},
{"VLANTermination", &DMWRITE, addObjEthernetVLANTermination, delObjEthernetVLANTermination, NULL, browseEthernetVLANTerminationInst, NULL, NULL, tEthernetVLANTerminationObj, tEthernetVLANTerminationParams, get_linker_vlan_term, BBFDM_BOTH, LIST_KEY{"Name", "Alias", NULL}},
{"RMONStats", &DMREAD, NULL, NULL, "file:/etc/config/ports;ubus:ethernet->rmonstats", browseEthernetRMONStatsInst, NULL, NULL, NULL, tEthernetRMONStatsParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "Interface", "VLANID", NULL}},
{"RMONStats", &DMREAD, NULL, NULL, "ubus:ethernet->rmonstats", browseEthernetRMONStatsInst, NULL, NULL, NULL, tEthernetRMONStatsParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "Interface", "VLANID", NULL}},
{0}
};

View file

@ -28,7 +28,7 @@ extern DMLEAF tEthernetVLANTerminationParams[];
extern DMLEAF tEthernetVLANTerminationStatsParams[];
extern DMLEAF tEthernetRMONStatsParams[];
struct uci_section *ethernet___get_ethernet_interface_section(const char *device_name);
bool ethernet___check_vlan_termination_section(const char *name);
bool ethernet___is_ethernet_interface_inst(const char *device_name);
#endif //__ETHERNET_H

View file

@ -303,7 +303,8 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
dmuci_get_value_by_section_string(s, "type", &type);
dmuci_get_value_by_section_string(s, "name", &name);
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (DM_LSTRCMP(type, "bridge") == 0 ||
if (DM_STRLEN(type) == 0 ||
DM_LSTRCMP(type, "bridge") == 0 ||
DM_LSTRCMP(type, "macvlan") == 0 ||
(*name != 0 && !ethernet___check_vlan_termination_section(name)) ||
(*name == 0 && strncmp(section_name(s), "br_", 3) == 0))
@ -372,9 +373,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
// The lower layer is Device.Ethernet.Interface.{i}.
if (found == false) {
adm_entry_get_linker_param(dmctx, "Device.Ethernet.Interface.", linker, &value);
struct uci_section *port_s = get_dup_section_in_config_opt("ports", "ethport", "ifname", linker);
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");
layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_ports", "ethport", "section_name", section_name(port_s), "eth_port_instance", "eth_port_alias");
struct uci_section *port_s = ethernet___get_ethernet_interface_section(linker);
loweralias = get_alias_by_section("dmmap_ethernet", "device", port_s, "eth_iface_alias");
layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_ethernet", "device", "section_name", section_name(port_s), "eth_iface_instance", "eth_iface_alias");
}
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value ? value : "");
@ -442,11 +443,10 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
adm_entry_get_linker_param(dmctx, "Device.Ethernet.Interface.", device, &value);
if (value != NULL) {
DM_STRNCPY(package, "ports", sizeof(package));
struct uci_section *port_s = NULL;
uci_foreach_option_eq("ports", "ethport", "ifname", device, port_s) {
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_ports", "ethport", "section_name", section_name(port_s), "eth_port_instance", "eth_port_alias");
break;
struct uci_section *port_s = ethernet___get_ethernet_interface_section(device);
if (port_s) {
loweralias = get_alias_by_section("dmmap_ethernet", "device", port_s, "eth_iface_alias");
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_ethernet", "device", "section_name", section_name(port_s), "eth_iface_instance", "eth_iface_alias");
}
found = 1;
}
@ -457,12 +457,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (!found && value != NULL) {
DM_STRNCPY(package, "wireless", sizeof(package));
struct uci_section *wl_s = NULL;
uci_foreach_option_eq("wireless", "wifi-iface", "ifname", device, wl_s) {
loweralias = get_alias_by_section("dmmap_wireless", "wifi-iface", wl_s, "ssidalias");
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_wireless", "wifi-iface", "section_name", section_name(wl_s), "ssidinstance", "ssidalias");
break;
}
struct uci_section *wl_s = get_dup_section_in_dmmap_opt("dmmap_wireless", "ssid", "ifname", device);
dmuci_get_value_by_section_string(wl_s, "ssid_alias", &loweralias);
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_wireless", "ssid", "ifname", device, "ssid_instance", "ssid_alias");
found = 1;
}
@ -511,11 +508,10 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (!found && value != NULL) {
DM_STRNCPY(package, "ports", sizeof(package));
struct uci_section *port_s = NULL;
uci_foreach_option_eq("ports", "ethport", "ifname", device, port_s) {
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_ports", "ethport", "section_name", section_name(port_s), "eth_port_instance", "eth_port_alias");
break;
struct uci_section *port_s = ethernet___get_ethernet_interface_section(device);
if (port_s) {
loweralias = get_alias_by_section("dmmap_ethernet", "device", port_s, "eth_iface_alias");
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_ethernet", "device", "section_name", section_name(port_s), "eth_iface_instance", "eth_iface_alias");
}
}

View file

@ -114,4 +114,34 @@ config route 'tunnel'
option interface 'mygre_static'
option target '172.16.2.0'
option netmask '255.255.255.0'
option gateway '172.16.12.2'
option gateway '172.16.12.2'
config device 'dev_eth1'
option enabled '1'
option ifname 'eth1'
option name 'eth1'
option macaddr '44:D4:37:71:B8:11'
config device 'dev_eth2'
option enabled '1'
option ifname 'eth2'
option name 'eth2'
option macaddr '44:D4:37:71:B8:11'
config device 'dev_eth3'
option enabled '1'
option ifname 'eth3'
option name 'eth3'
option macaddr '44:D4:37:71:B8:11'
config device 'dev_eth4'
option enabled '1'
option ifname 'eth4'
option name 'eth4'
option macaddr '44:D4:37:71:B8:11'
config device 'dev_eth0'
option enabled '1'
option ifname 'eth0'
option name 'eth0'
option macaddr '44:D4:37:71:B8:12'

View file

@ -1,52 +0,0 @@
config ethport 'LAN1'
option enabled '1'
option name 'LAN1'
option ifname 'eth1'
option speed '1000'
option duplex 'full'
option autoneg '1'
option eee '0'
option pause '0'
config ethport 'LAN2'
option enabled '1'
option name 'LAN2'
option ifname 'eth2'
option speed '1000'
option duplex 'full'
option autoneg '1'
option eee '0'
option pause '0'
config ethport 'LAN3'
option enabled '1'
option name 'LAN3'
option ifname 'eth3'
option speed '1000'
option duplex 'full'
option autoneg '1'
option eee '0'
option pause '0'
config ethport 'LAN4'
option enabled '1'
option name 'LAN4'
option ifname 'eth4'
option speed '1000'
option duplex 'full'
option autoneg '1'
option eee '0'
option pause '0'
config ethport 'WAN'
option enabled '1'
option name 'WAN'
option ifname 'eth0'
option speed '1000'
option duplex 'full'
option autoneg '1'
option eee '0'
option pause '1'
option uplink '1'