hosts: adapt to new topology object

This commit is contained in:
Sukru Senli 2021-03-26 14:28:24 +01:00
parent 69e4416929
commit d4a9bc71e2
3 changed files with 45 additions and 60 deletions

View file

@ -79,7 +79,7 @@ DMOBJ tDeviceObj[] = {
{"PTM", &DMREAD, NULL, NULL, "file:/etc/config/dsl", NULL, NULL, NULL, tPTMObj, NULL, NULL, BBFDM_BOTH},
{"DHCPv4", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/dhcp.sh", NULL, NULL, NULL, tDHCPv4Obj, tDHCPv4Params, NULL, BBFDM_BOTH},
{"DHCPv6", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/dhcpv6.sh", NULL, NULL, NULL, tDHCPv6Obj, tDHCPv6Params, NULL, BBFDM_BOTH},
{"Hosts", &DMREAD, NULL, NULL, "ubus:router.network->hosts", NULL, NULL, NULL, tHostsObj, tHostsParams, NULL, BBFDM_BOTH},
{"Hosts", &DMREAD, NULL, NULL, "ubus:topology->hosts", NULL, NULL, NULL, tHostsObj, tHostsParams, NULL, BBFDM_BOTH},
{"NAT", &DMREAD, NULL, NULL, "file:/etc/config/firewall", NULL, NULL, NULL, tNATObj, tNATParams, NULL, BBFDM_BOTH},
{"PPP", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/ppp.sh", NULL, NULL, NULL, tPPPObj, tPPPParams, NULL, BBFDM_BOTH},
{"Routing", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tRoutingObj, tRoutingParams, NULL, BBFDM_BOTH},

View file

@ -14,14 +14,14 @@
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.Hosts.Host.{i}.!UBUS:router.network/hosts//hosts*/
/*#Device.Hosts.Host.{i}.!UBUS:topology/hosts//hosts*/
static int browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *host_obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
dmubus_call("router.network", "hosts", UBUS_ARGS{}, 0, &res);
dmubus_call("topology", "hosts", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, host_obj, i, 1, "hosts") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)host_obj, inst) == DM_STOP)
@ -30,7 +30,7 @@ static int browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
return 0;
}
/*#Device.Hosts.Host.{i}.IPv4Address.{i}.!UBUS:router.network/hosts//hosts[@i-1].ipv4addr*/
/*#Device.Hosts.Host.{i}.IPv4Address.{i}.!UBUS:topology/hosts//hosts[@i-1].ipv4addr*/
static int browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *ip_arr = NULL, *host_obj = (json_object *)prev_data;
@ -45,7 +45,7 @@ static int browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_no
return 0;
}
/*#Device.Hosts.Host.{i}.IPv6Address.{i}.!UBUS:router.network/hosts//hosts[@i-1].ipv6addr*/
/*#Device.Hosts.Host.{i}.IPv6Address.{i}.!UBUS:topology/hosts//hosts[@i-1].ipv6addr*/
static int browseHostsHostIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *ip_arr = NULL, *host_obj = (json_object *)prev_data;
@ -72,13 +72,13 @@ static int get_linker_host(char *refparam, struct dmctx *dmctx, void *data, char
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.Hosts.HostNumberOfEntries!UBUS:router.network/hosts//hosts*/
/*#Device.Hosts.HostNumberOfEntries!UBUS:topology/hosts//hosts*/
static int get_Hosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *hosts = NULL;
size_t nbre_hosts = 0;
dmubus_call("router.network", "hosts", UBUS_ARGS{}, 0, &res);
dmubus_call("topology", "hosts", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "0");
json_object_object_get_ex(res, "hosts", &hosts);
nbre_hosts = (hosts) ? json_object_array_length(hosts) : 0;
@ -86,14 +86,14 @@ static int get_Hosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void
return 0;
}
/*#Device.Hosts.Host.{i}.PhysAddress!UBUS:router.network/hosts//hosts[@i-1].macaddr*/
/*#Device.Hosts.Host.{i}.PhysAddress!UBUS:topology/hosts//hosts[@i-1].macaddr*/
static int get_HostsHost_PhysAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 1, "macaddr");
return 0;
}
/*#Device.Hosts.Host.{i}.IPAddress!UBUS:router.network/hosts//hosts[@i-1].ipaddr*/
/*#Device.Hosts.Host.{i}.IPAddress!UBUS:topology/hosts//hosts[@i-1].ipaddr*/
static int get_HostsHost_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 1, "ipaddr");
@ -121,8 +121,8 @@ static int get_HostsHost_AssociatedDevice(char *refparam, struct dmctx *ctx, voi
static int get_HostsHost_Layer1Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *linker = dmjson_get_value((json_object *)data, 1, "device");
char *type = dmjson_get_value((json_object *)data, 1, "type");
if (strcmp(type, "wifi") == 0)
char *type = dmjson_get_value((json_object *)data, 1, "interface_type");
if (strcmp(type, "Wi-Fi") == 0)
adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", linker, value);
else
adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value);
@ -140,50 +140,35 @@ static int get_HostsHost_Layer3Interface(char *refparam, struct dmctx *ctx, void
return 0;
}
/*#Device.Hosts.Host.{i}.InterfaceType!UBUS:router.network/hosts//hosts[@i-1].type*/
/*#Device.Hosts.Host.{i}.InterfaceType!UBUS:topology/hosts//hosts[@i-1].interface_type*/
static int get_HostsHost_InterfaceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 1, "type");
*value = (strcmp(*value, "ethernet") == 0) ? "Ethernet" : "Wi-Fi";
*value = dmjson_get_value((json_object *)data, 1, "interface_type");
return 0;
}
/*#Device.Hosts.Host.{i}.HostName!UBUS:router.network/hosts//hosts[@i-1].hostname*/
/*#Device.Hosts.Host.{i}.HostName!UBUS:topology/hosts//hosts[@i-1].hostname*/
static int get_HostsHost_HostName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 1, "hostname");
return 0;
}
/*#Device.Hosts.Host.{i}.Active!UBUS:router.network/hosts//hosts[@i-1].active*/
/*#Device.Hosts.Host.{i}.Active!UBUS:topology/hosts//hosts[@i-1].active*/
static int get_HostsHost_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 1, "active");
return 0;
}
/*#Device.Hosts.Host.{i}.ActiveLastChange!UBUS:router.network/hosts//hosts[@i-1].activelstch*/
/*#Device.Hosts.Host.{i}.ActiveLastChange!UBUS:topology/hosts//hosts[@i-1].active_last_change*/
static int get_HostsHost_ActiveLastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "0001-01-01T00:00:00Z";
char *lastchange = dmjson_get_value((json_object *)data, 1, "activelstch");
if (lastchange && *lastchange != '\0' && atoi(lastchange) > 0) {
time_t t_time = atoi(lastchange);
if (localtime(&t_time) == NULL)
return -1;
char local_time[32] = {0};
if (strftime(local_time, sizeof(local_time), "%Y-%m-%dT%H:%M:%SZ", localtime(&t_time)) == 0)
return -1;
*value = dmstrdup(local_time);
}
*value = dmjson_get_value((json_object *)data, 1, "active_last_change");
return 0;
}
/*#Device.Hosts.Host.{i}.IPv4AddressNumberOfEntries!UBUS:router.network/hosts//hosts[@i-1].ipv4addr*/
/*#Device.Hosts.Host.{i}.IPv4AddressNumberOfEntries!UBUS:topology/hosts//hosts[@i-1].ipv4addr*/
static int get_HostsHost_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *ipv4addr = NULL;
@ -195,7 +180,7 @@ static int get_HostsHost_IPv4AddressNumberOfEntries(char *refparam, struct dmctx
return 0;
}
/*#Device.Hosts.Host.{i}.IPv6AddressNumberOfEntries!UBUS:router.network/hosts//hosts[@i-1].ipv6addr*/
/*#Device.Hosts.Host.{i}.IPv6AddressNumberOfEntries!UBUS:topology/hosts//hosts[@i-1].ipv6addr*/
static int get_HostsHost_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *ipv6addr = NULL;
@ -207,42 +192,42 @@ static int get_HostsHost_IPv6AddressNumberOfEntries(char *refparam, struct dmctx
return 0;
}
/*#Device.Hosts.Host.{i}.IPv4Address.{i}.IPAddress!UBUS:router.network/hosts//hosts[@i-1].ipv4addr[@i-1]*/
/*#Device.Hosts.Host.{i}.IPv4Address.{i}.IPAddress!UBUS:topology/hosts//hosts[@i-1].ipv4addr[@i-1]*/
static int get_HostsHostIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = (char *)data;
return 0;
}
/*#Device.Hosts.Host.{i}.IPv6Address.{i}.IPAddress!UBUS:router.network/hosts//hosts[@i-1].ipv6addr[@i-1]*/
/*#Device.Hosts.Host.{i}.IPv6Address.{i}.IPAddress!UBUS:topology/hosts//hosts[@i-1].ipv6addr[@i-1]*/
static int get_HostsHostIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = (char *)data;
return 0;
}
/*#Device.Hosts.Host.{i}.WANStats.BytesSent!UBUS:router.network/hosts//hosts[@i-1].stats.tx_bytes*/
/*#Device.Hosts.Host.{i}.WANStats.BytesSent!UBUS:topology/hosts//hosts[@i-1].stats.tx_bytes*/
static int get_HostsHostWANStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 2, "stats", "tx_bytes");
return 0;
}
/*#Device.Hosts.Host.{i}.WANStats.BytesReceived!UBUS:router.network/hosts//hosts[@i-1].stats.rx_bytes*/
/*#Device.Hosts.Host.{i}.WANStats.BytesReceived!UBUS:topology/hosts//hosts[@i-1].stats.rx_bytes*/
static int get_HostsHostWANStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 2, "stats", "rx_bytes");
return 0;
}
/*#Device.Hosts.Host.{i}.WANStats.PacketsSent!UBUS:router.network/hosts//hosts[@i-1].stats.tx_packets*/
/*#Device.Hosts.Host.{i}.WANStats.PacketsSent!UBUS:topology/hosts//hosts[@i-1].stats.tx_packets*/
static int get_HostsHostWANStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 2, "stats", "tx_packets");
return 0;
}
/*#Device.Hosts.Host.{i}.WANStats.PacketsReceived!UBUS:router.network/hosts//hosts[@i-1].stats.rx_packets*/
/*#Device.Hosts.Host.{i}.WANStats.PacketsReceived!UBUS:topology/hosts//hosts[@i-1].stats.rx_packets*/
static int get_HostsHostWANStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value((json_object *)data, 2, "stats", "rx_packets");

View file

@ -57636,7 +57636,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts"
@ -57669,7 +57669,7 @@
"mapping": {
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts"
@ -57708,7 +57708,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].macaddr"
@ -57734,7 +57734,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipaddr"
@ -57857,10 +57857,10 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].type"
"key": "hosts[@i-1].interface_type"
}
}
]
@ -57928,7 +57928,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].hostname"
@ -57949,7 +57949,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].active"
@ -57970,10 +57970,10 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].activelstch"
"key": "hosts[@i-1].active_last_change"
}
}
]
@ -57991,7 +57991,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipv4addr"
@ -58012,7 +58012,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipv6addr"
@ -58034,7 +58034,7 @@
"mapping": {
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipv4addr"
@ -58062,7 +58062,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipv4addr[@i-1]"
@ -58085,7 +58085,7 @@
"mapping": {
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipv6addr"
@ -58109,7 +58109,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].ipv6addr[@i-1]"
@ -58139,7 +58139,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].stats.tx_bytes"
@ -58160,7 +58160,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].stats.rx_bytes"
@ -58181,7 +58181,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].stats.tx_packets"
@ -58202,7 +58202,7 @@
{
"type": "ubus",
"ubus": {
"object": "router.network",
"object": "topology",
"method": "hosts",
"args": {},
"key": "hosts[@i-1].stats.rx_packets"